source: mainline/uspace/srv/hid/display/display.c@ 22faaf2

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

A little bit of tiling support

  • Property mode set to 100644
File size: 4.9 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 management
34 */
35
36#include <disp_srv.h>
37#include <errno.h>
38#include <gfx/context.h>
39#include <io/log.h>
40#include <stdlib.h>
41#include "display.h"
42#include "window.h"
43
44static errno_t disp_window_create(void *, sysarg_t *);
45static errno_t disp_window_destroy(void *, sysarg_t);
46
47display_ops_t display_srv_ops = {
48 .window_create = disp_window_create,
49 .window_destroy = disp_window_destroy
50};
51
52static errno_t disp_window_create(void *arg, sysarg_t *rwnd_id)
53{
54 errno_t rc;
55 ds_display_t *disp = (ds_display_t *) arg;
56 ds_window_t *wnd;
57
58 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create()");
59
60 rc = ds_window_create(disp, &wnd);
61 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() - ds_window_create -> %d", rc);
62 if (rc != EOK)
63 return rc;
64
65 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() -> EOK, id=%zu",
66 wnd->id);
67
68 wnd->dpos.x = ((wnd->id - 1) & 1) * 400;
69 wnd->dpos.y = ((wnd->id - 1) & 2) / 2 * 300;
70
71 *rwnd_id = wnd->id;
72 return EOK;
73}
74
75static errno_t disp_window_destroy(void *arg, sysarg_t wnd_id)
76{
77 ds_display_t *disp = (ds_display_t *) arg;
78 ds_window_t *wnd;
79
80 wnd = ds_display_find_window(disp, wnd_id);
81 if (wnd == NULL)
82 return ENOENT;
83
84 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_destroy()");
85 ds_display_remove_window(wnd);
86 ds_window_delete(wnd);
87 return EOK;
88}
89
90/** Create display.
91 *
92 * @param gc Graphics context for displaying output
93 * @param rdisp Place to store pointer to new display.
94 * @return EOK on success, ENOMEM if out of memory
95 */
96errno_t ds_display_create(gfx_context_t *gc, ds_display_t **rdisp)
97{
98 ds_display_t *disp;
99
100 disp = calloc(1, sizeof(ds_display_t));
101 if (disp == NULL)
102 return ENOMEM;
103
104 list_initialize(&disp->windows);
105 disp->next_wnd_id = 1;
106 disp->gc = gc;
107 *rdisp = disp;
108 return EOK;
109}
110
111/** Destroy display.
112 *
113 * @param disp Display
114 */
115void ds_display_destroy(ds_display_t *disp)
116{
117 assert(list_empty(&disp->windows));
118 free(disp);
119}
120
121/** Add window to display.
122 *
123 * @param disp Display
124 * @param wnd Window
125 * @return EOK on success, ENOMEM if there are no free window identifiers
126 */
127errno_t ds_display_add_window(ds_display_t *disp, ds_window_t *wnd)
128{
129 assert(wnd->display == NULL);
130 assert(!link_used(&wnd->lwindows));
131
132 wnd->display = disp;
133 wnd->id = disp->next_wnd_id++;
134 list_append(&wnd->lwindows, &disp->windows);
135
136 return EOK;
137}
138
139/** Remove window from display.
140 *
141 * @param wnd Window
142 */
143void ds_display_remove_window(ds_window_t *wnd)
144{
145 list_remove(&wnd->lwindows);
146 wnd->display = NULL;
147}
148
149/** Find window by ID.
150 *
151 * @param disp Display
152 * @param id Window ID
153 */
154ds_window_t *ds_display_find_window(ds_display_t *disp, ds_wnd_id_t id)
155{
156 ds_window_t *wnd;
157
158 // TODO Make this faster
159 wnd = ds_display_first_window(disp);
160 while (wnd != NULL) {
161 if (wnd->id == id)
162 return wnd;
163 wnd = ds_display_next_window(wnd);
164 }
165
166 return NULL;
167}
168
169/** Get first window in display.
170 *
171 * @param disp Display
172 * @return First window or @c NULL if there is none
173 */
174ds_window_t *ds_display_first_window(ds_display_t *disp)
175{
176 link_t *link = list_first(&disp->windows);
177
178 if (link == NULL)
179 return NULL;
180
181 return list_get_instance(link, ds_window_t, lwindows);
182}
183
184/** Get next window in display.
185 *
186 * @param wnd Current window
187 * @return Next window or @c NULL if there is none
188 */
189ds_window_t *ds_display_next_window(ds_window_t *wnd)
190{
191 link_t *link = list_next(&wnd->lwindows, &wnd->display->windows);
192
193 if (link == NULL)
194 return NULL;
195
196 return list_get_instance(link, ds_window_t, lwindows);
197}
198
199/** @}
200 */
Note: See TracBrowser for help on using the repository browser.