source: mainline/uspace/srv/hid/display/window.c@ 23e86c6

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

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.

  • Property mode set to 100644
File size: 6.3 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 GFX window backend
34 *
35 * This implements a graphics context over display server window.
36 */
37
38#include <gfx/bitmap.h>
39#include <gfx/color.h>
40#include <gfx/coord.h>
41#include <gfx/context.h>
42#include <gfx/render.h>
43#include <io/log.h>
44#include <stdlib.h>
45#include "client.h"
46#include "display.h"
47#include "window.h"
48
49static errno_t ds_window_set_color(void *, gfx_color_t *);
50static errno_t ds_window_fill_rect(void *, gfx_rect_t *);
51static errno_t ds_window_bitmap_create(void *, gfx_bitmap_params_t *,
52 gfx_bitmap_alloc_t *, void **);
53static errno_t ds_window_bitmap_destroy(void *);
54static errno_t ds_window_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
55static errno_t ds_window_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
56
57gfx_context_ops_t ds_window_ops = {
58 .set_color = ds_window_set_color,
59 .fill_rect = ds_window_fill_rect,
60 .bitmap_create = ds_window_bitmap_create,
61 .bitmap_destroy = ds_window_bitmap_destroy,
62 .bitmap_render = ds_window_bitmap_render,
63 .bitmap_get_alloc = ds_window_bitmap_get_alloc
64};
65
66/** Set color on window GC.
67 *
68 * Set drawing color on window GC.
69 *
70 * @param arg Console GC
71 * @param color Color
72 *
73 * @return EOK on success or an error code
74 */
75static errno_t ds_window_set_color(void *arg, gfx_color_t *color)
76{
77 ds_window_t *wnd = (ds_window_t *) arg;
78
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);
82}
83
84/** Fill rectangle on window GC.
85 *
86 * @param arg Window GC
87 * @param rect Rectangle
88 *
89 * @return EOK on success or an error code
90 */
91static errno_t ds_window_fill_rect(void *arg, gfx_rect_t *rect)
92{
93 ds_window_t *wnd = (ds_window_t *) arg;
94 gfx_rect_t drect;
95
96 log_msg(LOG_DEFAULT, LVL_NOTE, "gc_fill_rect");
97 gfx_rect_translate(&wnd->dpos, rect, &drect);
98 return gfx_fill_rect(ds_display_get_gc(wnd->display), &drect);
99}
100
101/** Create bitmap in canvas GC.
102 *
103 * @param arg Canvas GC
104 * @param params Bitmap params
105 * @param alloc Bitmap allocation info or @c NULL
106 * @param rbm Place to store pointer to new bitmap
107 * @return EOK on success or an error code
108 */
109errno_t ds_window_bitmap_create(void *arg, gfx_bitmap_params_t *params,
110 gfx_bitmap_alloc_t *alloc, void **rbm)
111{
112 ds_window_t *wnd = (ds_window_t *) arg;
113 ds_window_bitmap_t *cbm = NULL;
114 errno_t rc;
115
116 cbm = calloc(1, sizeof(ds_window_bitmap_t));
117 if (cbm == NULL)
118 return ENOMEM;
119
120 rc = gfx_bitmap_create(ds_display_get_gc(wnd->display), params, alloc,
121 &cbm->bitmap);
122 if (rc != EOK)
123 goto error;
124
125 cbm->wnd = wnd;
126 *rbm = (void *)cbm;
127 return EOK;
128error:
129 if (cbm != NULL)
130 free(cbm);
131 return rc;
132}
133
134/** Destroy bitmap in canvas GC.
135 *
136 * @param bm Bitmap
137 * @return EOK on success or an error code
138 */
139static errno_t ds_window_bitmap_destroy(void *bm)
140{
141 ds_window_bitmap_t *cbm = (ds_window_bitmap_t *)bm;
142
143 gfx_bitmap_destroy(cbm->bitmap);
144 free(cbm);
145 return EOK;
146}
147
148/** Render bitmap in canvas GC.
149 *
150 * @param bm Bitmap
151 * @param srect0 Source rectangle or @c NULL
152 * @param offs0 Offset or @c NULL
153 * @return EOK on success or an error code
154 */
155static errno_t ds_window_bitmap_render(void *bm, gfx_rect_t *srect0,
156 gfx_coord2_t *offs0)
157{
158 ds_window_bitmap_t *cbm = (ds_window_bitmap_t *)bm;
159 gfx_coord2_t doffs;
160
161 if (offs0 != NULL)
162 gfx_coord2_add(&cbm->wnd->dpos, offs0, &doffs);
163 else
164 doffs = cbm->wnd->dpos;
165
166 return gfx_bitmap_render(cbm->bitmap, srect0, &doffs);
167}
168
169/** Get allocation info for bitmap in canvas GC.
170 *
171 * @param bm Bitmap
172 * @param alloc Place to store allocation info
173 * @return EOK on success or an error code
174 */
175static errno_t ds_window_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
176{
177 ds_window_bitmap_t *cbm = (ds_window_bitmap_t *)bm;
178
179 return gfx_bitmap_get_alloc(cbm->bitmap, alloc);
180}
181
182/** Create window.
183 *
184 * Create graphics context for rendering into a window.
185 *
186 * @param client Client owning the window
187 * @param rgc Place to store pointer to new GC.
188 *
189 * @return EOK on success or an error code
190 */
191errno_t ds_window_create(ds_client_t *client, ds_window_t **rgc)
192{
193 ds_window_t *wnd = NULL;
194 gfx_context_t *gc = NULL;
195 errno_t rc;
196
197 wnd = calloc(1, sizeof(ds_window_t));
198 if (wnd == NULL) {
199 rc = ENOMEM;
200 goto error;
201 }
202
203 rc = gfx_context_new(&ds_window_ops, wnd, &gc);
204 if (rc != EOK)
205 goto error;
206
207 ds_client_add_window(client, wnd);
208 ds_display_add_window(client->display, wnd);
209
210 wnd->gc = gc;
211 *rgc = wnd;
212 return EOK;
213error:
214 if (wnd != NULL)
215 free(wnd);
216 gfx_context_delete(gc);
217 return rc;
218}
219
220/** Delete window GC.
221 *
222 * @param wnd Window GC
223 */
224void ds_window_destroy(ds_window_t *wnd)
225{
226 ds_client_remove_window(wnd);
227 ds_display_remove_window(wnd);
228 (void) gfx_context_delete(wnd->gc);
229
230 free(wnd);
231}
232
233/** Get generic graphic context from window.
234 *
235 * @param wnd Window
236 * @return Graphic context
237 */
238gfx_context_t *ds_window_get_ctx(ds_window_t *wnd)
239{
240 return wnd->gc;
241}
242
243/** @}
244 */
Note: See TracBrowser for help on using the repository browser.