Changeset 87a7cdb in mainline for uspace/srv/hid/display


Ignore:
Timestamp:
2019-12-05T19:35:12Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
71cbe5c
Parents:
973efd36
Message:

Enumerate display devices for output, RFB conversion (WIP)

Currently we can only have one active output device. Bitmaps
do not work as ipcgfx does not accept alloc != NULL.
Need to fill in tests.

Location:
uspace/srv/hid/display
Files:
4 added
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/display/display.c

    r973efd36 r87a7cdb  
    5858
    5959        list_initialize(&disp->clients);
    60         disp->gc = gc;
    6160        disp->next_wnd_id = 1;
     61        list_initialize(&disp->ddevs);
    6262        list_initialize(&disp->seats);
    6363        list_initialize(&disp->windows);
     
    347347}
    348348
     349/** Add display device to display.
     350 *
     351 * @param disp Display
     352 * @param ddev Display device
     353 */
     354void ds_display_add_ddev(ds_display_t *disp, ds_ddev_t *ddev)
     355{
     356        assert(ddev->display == NULL);
     357        assert(!link_used(&ddev->lddevs));
     358
     359        ddev->display = disp;
     360        list_append(&ddev->lddevs, &disp->ddevs);
     361}
     362
     363/** Remove display device from display.
     364 *
     365 * @param ddev Display device
     366 */
     367void ds_display_remove_ddev(ds_ddev_t *ddev)
     368{
     369        list_remove(&ddev->lddevs);
     370        ddev->display = NULL;
     371}
     372
     373/** Get first display device in display.
     374 *
     375 * @param disp Display
     376 * @return First display device or @c NULL if there is none
     377 */
     378ds_ddev_t *ds_display_first_ddev(ds_display_t *disp)
     379{
     380        link_t *link = list_first(&disp->ddevs);
     381
     382        if (link == NULL)
     383                return NULL;
     384
     385        return list_get_instance(link, ds_ddev_t, lddevs);
     386}
     387
     388/** Get next display device in display.
     389 *
     390 * @param ddev Current display device
     391 * @return Next display device or @c NULL if there is none
     392 */
     393ds_ddev_t *ds_display_next_ddev(ds_ddev_t *ddev)
     394{
     395        link_t *link = list_next(&ddev->lddevs, &ddev->display->ddevs);
     396
     397        if (link == NULL)
     398                return NULL;
     399
     400        return list_get_instance(link, ds_ddev_t, lddevs);
     401}
     402
     403// XXX
     404gfx_context_t *ds_display_get_gc(ds_display_t *display)
     405{
     406        ds_ddev_t *ddev;
     407
     408        ddev = ds_display_first_ddev(display);
     409        if (ddev == NULL)
     410                abort();
     411
     412        return ddev->gc;
     413}
     414
    349415/** @}
    350416 */
  • uspace/srv/hid/display/display.h

    r973efd36 r87a7cdb  
    4242#include <io/pos_event.h>
    4343#include "types/display/client.h"
     44#include "types/display/ddev.h"
    4445#include "types/display/display.h"
    4546#include "types/display/seat.h"
     
    6364extern ds_seat_t *ds_display_first_seat(ds_display_t *);
    6465extern ds_seat_t *ds_display_next_seat(ds_seat_t *);
     66extern void ds_display_add_ddev(ds_display_t *, ds_ddev_t *);
     67extern void ds_display_remove_ddev(ds_ddev_t *);
     68extern ds_ddev_t *ds_display_first_ddev(ds_display_t *);
     69extern ds_ddev_t *ds_display_next_ddev(ds_ddev_t *);
     70extern gfx_context_t *ds_display_get_gc(ds_display_t *);
    6571
    6672#endif
  • uspace/srv/hid/display/main.c

    r973efd36 r87a7cdb  
    8484
    8585/** Initialize display server */
    86 static errno_t display_srv_init(void)
     86static errno_t display_srv_init(ds_output_t **routput)
    8787{
    8888        ds_display_t *disp = NULL;
    8989        ds_seat_t *seat = NULL;
     90        ds_output_t *output = NULL;
    9091        gfx_context_t *gc = NULL;
    9192        errno_t rc;
     
    101102                goto error;
    102103
    103         rc = output_init(display_kbd_event, (void *) disp,
    104             display_pos_event, (void *) disp, &gc);
    105         if (rc != EOK)
    106                 goto error;
    107 
    108         disp->gc = gc;
    109104#if 0
    110105        rc = ds_input_open(disp);
     
    112107                goto error;
    113108#endif
     109        rc = ds_output_create(display_kbd_event, (void *) disp,
     110            display_pos_event, (void *) disp, &output);
     111        if (rc != EOK)
     112                goto error;
     113
     114        output->def_display = disp;
     115        rc = ds_output_start_discovery(output);
     116        if (rc != EOK)
     117                goto error;
     118
    114119        async_set_fallback_port_handler(display_client_conn, disp);
    115120
     
    128133        }
    129134
     135        *routput = output;
    130136        return EOK;
    131137error:
     
    134140                ds_input_close(disp);
    135141#endif
     142        if (output != NULL)
     143                ds_output_destroy(output);
    136144        if (gc != NULL)
    137145                gfx_context_delete(gc);
     
    199207{
    200208        errno_t rc;
     209        ds_output_t *output;
    201210
    202211        printf("%s: Display server\n", NAME);
     
    207216        }
    208217
    209         rc = display_srv_init();
     218        rc = display_srv_init(&output);
    210219        if (rc != EOK)
    211220                return 1;
  • uspace/srv/hid/display/meson.build

    r973efd36 r87a7cdb  
    2727#
    2828
    29 deps = [ 'ipcgfx', 'display', 'guigfx' ]
     29deps = [ 'ipcgfx', 'display', 'ddev' ]
    3030
    3131src = files(
    3232        'client.c',
     33        'ddev.c',
    3334        'display.c',
    3435        'dsops.c',
  • uspace/srv/hid/display/output.c

    r973efd36 r87a7cdb  
    3434 */
    3535
     36#include <assert.h>
    3637#include <errno.h>
    37 #include <gfx/context.h>
    38 #include <guigfx/canvas.h>
     38#include <fibril_synch.h>
    3939#include <io/kbd_event.h>
    4040#include <io/pos_event.h>
     41#include <loc.h>
    4142#include <stdio.h>
    4243#include <stdlib.h>
    43 #include <window.h>
     44#include "ddev.h"
    4445#include "output.h"
    4546
     47#if 0
    4648static void (*kbd_ev_handler)(void *, kbd_event_t *);
    4749static void *kbd_ev_arg;
     
    5961        pos_ev_handler(pos_ev_arg, (pos_event_t *) data);
    6062}
     63#endif
    6164
    62 errno_t output_init(void (*kbd_event_handler)(void *, kbd_event_t *),
    63     void *karg, void (*pos_event_handler)(void *, pos_event_t *),
    64     void *parg, gfx_context_t **rgc)
     65/** Check for new display devices.
     66 *
     67 * @param output Display server output
     68 */
     69static errno_t ds_output_check_new_devs(ds_output_t *output)
    6570{
    66         canvas_gc_t *cgc = NULL;
    67         window_t *window = NULL;
    68         pixel_t *pixbuf = NULL;
    69         surface_t *surface = NULL;
    70         canvas_t *canvas = NULL;
    71         gfx_coord_t vw, vh;
     71        category_id_t ddev_cid;
     72        service_id_t *svcs;
     73        size_t count, i;
     74        bool already_known;
     75        ds_ddev_t *nddev;
    7276        errno_t rc;
    7377
    74         printf("Init canvas..\n");
    75         kbd_ev_handler = kbd_event_handler;
    76         kbd_ev_arg = karg;
     78        assert(fibril_mutex_is_locked(&output->lock));
    7779
    78         pos_ev_handler = pos_event_handler;
    79         pos_ev_arg = parg;
    80 
    81         window = window_open("comp:0/winreg", NULL,
    82             WINDOW_MAIN | WINDOW_DECORATED, "Display Server");
    83         if (window == NULL) {
    84                 printf("Error creating window.\n");
    85                 return -1;
    86         }
    87 
    88         vw = 800;
    89         vh = 600;
    90 
    91         pixbuf = calloc(vw * vh, sizeof(pixel_t));
    92         if (pixbuf == NULL) {
    93                 printf("Error allocating memory for pixel buffer.\n");
    94                 return ENOMEM;
    95         }
    96 
    97         surface = surface_create(vw, vh, pixbuf, 0);
    98         if (surface == NULL) {
    99                 printf("Error creating surface.\n");
     80        rc = loc_category_get_id("display-device", &ddev_cid,
     81            IPC_FLAG_BLOCKING);
     82        if (rc != EOK) {
     83                printf("Error looking up category 'display-device'.\n");
    10084                return EIO;
    10185        }
    10286
    103         canvas = create_canvas(window_root(window), NULL, vw, vh,
    104             surface);
    105         if (canvas == NULL) {
    106                 printf("Error creating canvas.\n");
     87        /*
     88         * Check for new dispay devices
     89         */
     90        rc = loc_category_get_svcs(ddev_cid, &svcs, &count);
     91        if (rc != EOK) {
     92                printf("Error getting list of display devices.\n");
    10793                return EIO;
    10894        }
    10995
    110         sig_connect(&canvas->keyboard_event, NULL, on_keyboard_event);
    111         sig_connect(&canvas->position_event, NULL, on_position_event);
     96        for (i = 0; i < count; i++) {
     97                already_known = false;
    11298
    113         window_resize(window, 0, 0, vw + 10, vh + 30, WINDOW_PLACEMENT_ANY);
    114         window_exec(window);
     99                /* Determine whether we already know this device. */
     100                list_foreach(output->ddevs, loutdevs, ds_ddev_t, ddev) {
     101                        if (ddev->svc_id == svcs[i]) {
     102                                already_known = true;
     103                                break;
     104                        }
     105                }
    115106
    116         printf("Create canvas GC\n");
    117         rc = canvas_gc_create(canvas, surface, &cgc);
    118         if (rc != EOK)
     107                if (!already_known) {
     108                        rc = ds_ddev_open(output->def_display, svcs[i], &nddev);
     109                        if (rc != EOK) {
     110                                printf("Error adding display device.\n");
     111                                continue;
     112                        }
     113
     114                        list_append(&nddev->loutdevs, &output->ddevs);
     115
     116                        printf("Added display device '%lu'\n",
     117                            (unsigned long) svcs[i]);
     118                }
     119        }
     120
     121        free(svcs);
     122
     123        return EOK;
     124}
     125
     126/** Display device category change callback.
     127 *
     128 * @param arg Display server output (cast to void *)
     129 */
     130static void ds_ddev_change_cb(void *arg)
     131{
     132        ds_output_t *output = (ds_output_t *) arg;
     133
     134        printf("ds_ddev_change_cb\n");
     135        fibril_mutex_lock(&output->lock);
     136        (void) ds_output_check_new_devs(output);
     137        fibril_mutex_unlock(&output->lock);
     138}
     139
     140/** Create display server output.
     141 *
     142 * @param kbd_event_handler
     143 * @param karg
     144 * @param pos_event_handler
     145 * @param parg
     146 * @param routput Place to store pointer to display server output object.
     147 * @return EOK on success or an error code
     148 */
     149errno_t ds_output_create(void (*kbd_event_handler)(void *, kbd_event_t *),
     150    void *karg, void (*pos_event_handler)(void *, pos_event_t *),
     151    void *parg, ds_output_t **routput)
     152{
     153        ds_output_t *output;
     154
     155        output = calloc(1, sizeof(ds_output_t));
     156        if (output == NULL)
     157                return ENOMEM;
     158
     159        fibril_mutex_initialize(&output->lock);
     160        list_initialize(&output->ddevs);
     161
     162        *routput = output;
     163        return EOK;
     164}
     165
     166/** Start display device discovery.
     167 *
     168 * @param output Display server output
     169 * @return EOK on success or an error code
     170 */
     171errno_t ds_output_start_discovery(ds_output_t *output)
     172{
     173        errno_t rc;
     174
     175        rc = loc_register_cat_change_cb(ds_ddev_change_cb, output);
     176        if (rc != EOK) {
     177                printf("Failed registering callback for device discovery.\n");
    119178                return rc;
     179        }
    120180
    121         *rgc = canvas_gc_get_ctx(cgc);
    122         return EOK;
     181        fibril_mutex_lock(&output->lock);
     182        rc = ds_output_check_new_devs(output);
     183        fibril_mutex_unlock(&output->lock);
     184
     185        return rc;
     186}
     187
     188/** Destroy display server output.
     189 *
     190 * @param output Display server output
     191 */
     192void ds_output_destroy(ds_output_t *output)
     193{
     194        free(output);
    123195}
    124196
  • uspace/srv/hid/display/output.h

    r973efd36 r87a7cdb  
    4040#include <io/kbd_event.h>
    4141#include <io/pos_event.h>
     42#include "types/display/output.h"
    4243
    43 extern errno_t output_init(void (*)(void *, kbd_event_t *), void *,
    44     void (*)(void *, pos_event_t *), void *,
    45     gfx_context_t **);
     44extern errno_t ds_output_create(void (*)(void *, kbd_event_t *),
     45    void *, void (*)(void *, pos_event_t *), void *, ds_output_t **);
     46extern errno_t ds_output_start_discovery(ds_output_t *);
     47extern void ds_output_destroy(ds_output_t *);
    4648
    4749#endif
  • uspace/srv/hid/display/types/display/display.h

    r973efd36 r87a7cdb  
    3838
    3939#include <adt/list.h>
    40 #include <gfx/context.h>
    4140#include <io/input.h>
    4241#include "window.h"
     
    4645        /** Clients (of ds_client_t) */
    4746        list_t clients;
    48         /** Output GC */
    49         gfx_context_t *gc;
    5047
    5148        /** Next ID to assign to a window.
     
    6562        /** Windows (of ds_window_t) in stacking order */
    6663        list_t windows;
     64
     65        /** Display devices (of ds_ddev_t) */
     66        list_t ddevs;
    6767} ds_display_t;
    6868
  • uspace/srv/hid/display/window.c

    r973efd36 r87a7cdb  
    7777        ds_window_t *wnd = (ds_window_t *) arg;
    7878
    79         log_msg(LOG_DEFAULT, LVL_NOTE, "gc_set_color gc=%p", wnd->display->gc);
    80         return gfx_set_color(wnd->display->gc, color);
     79        log_msg(LOG_DEFAULT, LVL_NOTE, "gc_set_color gc=%p",
     80            ds_display_get_gc(wnd->display));
     81        return gfx_set_color(ds_display_get_gc(wnd->display), color);
    8182}
    8283
     
    9596        log_msg(LOG_DEFAULT, LVL_NOTE, "gc_fill_rect");
    9697        gfx_rect_translate(&wnd->dpos, rect, &drect);
    97         return gfx_fill_rect(wnd->display->gc, &drect);
     98        return gfx_fill_rect(ds_display_get_gc(wnd->display), &drect);
    9899}
    99100
     
    117118                return ENOMEM;
    118119
    119         rc = gfx_bitmap_create(wnd->display->gc, params, alloc,
     120        rc = gfx_bitmap_create(ds_display_get_gc(wnd->display), params, alloc,
    120121            &cbm->bitmap);
    121122        if (rc != EOK)
Note: See TracChangeset for help on using the changeset viewer.