source: mainline/uspace/srv/hid/display/ddev.c@ 5271e4c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5271e4c was 5271e4c, checked in by Jiri Svoboda <jiri@…>, 5 years ago

Duplicate rendering to additional output devices using a cloning GC

This gives the display server a pretty good illusion of rendering to just
one output device, while supporting multiple. This makes RFB work properly.

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Copyright (c) 2019 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup display
30 * @{
31 */
32/**
33 * @file Display server display device
34 */
35
36#include <adt/list.h>
37#include <ddev.h>
38#include <errno.h>
39#include <io/log.h>
40#include <stdio.h>
41#include <stdlib.h>
42#include "display.h"
43#include "ddev.h"
44
45/** Create display device object.
46 *
47 * @param display Parent display
48 * @param dd Display device
49 * @param info Display device info
50 * @param svc_id Display device service ID
51 * @param svc_name Display device service name
52 * @param gc Display device GC
53 * @param rddev Place to store pointer to new display device.
54 * @return EOK on success, ENOMEM if out of memory
55 */
56errno_t ds_ddev_create(ds_display_t *display, ddev_t *dd,
57 ddev_info_t *info, char *svc_name, service_id_t svc_id,
58 gfx_context_t *gc, ds_ddev_t **rddev)
59{
60 ds_ddev_t *ddev;
61 errno_t rc;
62
63 ddev = calloc(1, sizeof(ds_ddev_t));
64 if (ddev == NULL)
65 return ENOMEM;
66
67 ddev->svc_name = svc_name;
68 ddev->svc_id = svc_id;
69 ddev->dd = dd;
70 ddev->gc = gc;
71 ddev->info = *info;
72
73 rc = ds_display_add_ddev(display, ddev);
74 if (rc != EOK) {
75 free(ddev);
76 return rc;
77 }
78
79 *rddev = ddev;
80 return EOK;
81}
82
83/** Open display device.
84 *
85 * @param display Parent display
86 * @param svc_id Service ID
87 * @param rddev Place to store pointer to new display device.
88 * @return EOK on success, ENOMEM if out of memory
89 */
90errno_t ds_ddev_open(ds_display_t *display, service_id_t svc_id,
91 ds_ddev_t **rddev)
92{
93 ds_ddev_t *ddev;
94 ddev_info_t info;
95 gfx_context_t *gc;
96 ddev_t *dd = NULL;
97 char *name = NULL;
98 errno_t rc;
99
100 rc = loc_service_get_name(svc_id, &name);
101 if (rc != EOK) {
102 printf("Error resolving name of service %lu.\n",
103 (unsigned long) svc_id);
104 return rc;
105 }
106
107 rc = ddev_open(name, &dd);
108 if (rc != EOK) {
109 printf("Error opening display device '%s'.\n", name);
110 free(name);
111 return rc;
112 }
113
114 rc = ddev_get_info(dd, &info);
115 if (rc != EOK) {
116 printf("Error getting information for display device '%s'.\n",
117 name);
118 free(name);
119 ddev_close(dd);
120 return rc;
121 }
122
123 log_msg(LOG_DEFAULT, LVL_NOTE, "Device rectangle for '%s': "
124 "%d,%d,%d,%d\n", name, info.rect.p0.x, info.rect.p0.y,
125 info.rect.p1.x, info.rect.p1.y);
126
127 rc = ddev_get_gc(dd, &gc);
128 if (rc != EOK) {
129 printf("Error getting device context for '%s'.\n", name);
130 ddev_close(dd);
131 free(name);
132 return rc;
133 }
134
135 rc = ds_ddev_create(display, dd, &info, name, svc_id, gc, &ddev);
136 if (rc != EOK) {
137 free(name);
138 ddev_close(dd);
139 gfx_context_delete(gc);
140 return rc;
141 }
142
143 rc = ds_display_paint(display, NULL);
144 if (rc != EOK)
145 return rc;
146
147 *rddev = ddev;
148 return EOK;
149}
150
151/** Destroy display device.
152 *
153 * @param ddev Display device
154 */
155void ds_ddev_close(ds_ddev_t *ddev)
156{
157 ds_display_remove_ddev(ddev);
158 free(ddev);
159}
160
161/** @}
162 */
Note: See TracBrowser for help on using the repository browser.