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 | #include <async.h>
|
---|
30 | #include <display.h>
|
---|
31 | #include <errno.h>
|
---|
32 | #include <ipc/display.h>
|
---|
33 | #include <ipc/services.h>
|
---|
34 | #include <ipcgfx/client.h>
|
---|
35 | #include <loc.h>
|
---|
36 | #include <stdlib.h>
|
---|
37 |
|
---|
38 | /** Open display service.
|
---|
39 | *
|
---|
40 | * @param dsname Display service name or @c NULL to use default display
|
---|
41 | * @param rdisplay Place to store pointer to display session
|
---|
42 | * @return EOK on success or an error code
|
---|
43 | */
|
---|
44 | errno_t display_open(const char *dsname, display_t **rdisplay)
|
---|
45 | {
|
---|
46 | service_id_t display_svc;
|
---|
47 | display_t *display;
|
---|
48 | errno_t rc;
|
---|
49 |
|
---|
50 | display = calloc(1, sizeof(display_t));
|
---|
51 | if (display == NULL)
|
---|
52 | return ENOMEM;
|
---|
53 |
|
---|
54 | if (dsname == NULL)
|
---|
55 | dsname = SERVICE_NAME_DISPLAY;
|
---|
56 |
|
---|
57 | rc = loc_service_get_id(dsname, &display_svc, IPC_FLAG_BLOCKING);
|
---|
58 | if (rc != EOK) {
|
---|
59 | free(display);
|
---|
60 | return ENOENT;
|
---|
61 | }
|
---|
62 |
|
---|
63 | display->sess = loc_service_connect(display_svc, INTERFACE_DISPLAY,
|
---|
64 | IPC_FLAG_BLOCKING);
|
---|
65 | if (display->sess == NULL) {
|
---|
66 | free(display);
|
---|
67 | return ENOENT;
|
---|
68 | }
|
---|
69 |
|
---|
70 | *rdisplay = display;
|
---|
71 | return EOK;
|
---|
72 | }
|
---|
73 |
|
---|
74 | /** Close display service.
|
---|
75 | *
|
---|
76 | * @param display Display session
|
---|
77 | */
|
---|
78 | void display_close(display_t *display)
|
---|
79 | {
|
---|
80 | async_hangup(display->sess);
|
---|
81 | free(display);
|
---|
82 | }
|
---|
83 |
|
---|
84 | /** Create a display window.
|
---|
85 | *
|
---|
86 | * @param display Display
|
---|
87 | * @param rwindow Place to store pointer to new window
|
---|
88 | * @return EOK on success or an error code
|
---|
89 | */
|
---|
90 | errno_t display_window_create(display_t *display, display_window_t **rwindow)
|
---|
91 | {
|
---|
92 | display_window_t *window;
|
---|
93 | async_exch_t *exch;
|
---|
94 | sysarg_t wnd_id;
|
---|
95 | errno_t rc;
|
---|
96 |
|
---|
97 | window = calloc(1, sizeof(display_window_t));
|
---|
98 | if (window == NULL)
|
---|
99 | return ENOMEM;
|
---|
100 |
|
---|
101 | exch = async_exchange_begin(display->sess);
|
---|
102 | rc = async_req_0_1(exch, DISPLAY_WINDOW_CREATE, &wnd_id);
|
---|
103 |
|
---|
104 | async_exchange_end(exch);
|
---|
105 |
|
---|
106 | if (rc != EOK) {
|
---|
107 | free(window);
|
---|
108 | return rc;
|
---|
109 | }
|
---|
110 |
|
---|
111 | window->display = display;
|
---|
112 | window->id = wnd_id;
|
---|
113 | *rwindow = window;
|
---|
114 | return EOK;
|
---|
115 | }
|
---|
116 |
|
---|
117 | /** Destroy display window.
|
---|
118 | *
|
---|
119 | * @param window Window
|
---|
120 | * @return EOK on success or an error code. In both cases @a window must
|
---|
121 | * not be accessed anymore
|
---|
122 | */
|
---|
123 | errno_t display_window_destroy(display_window_t *window)
|
---|
124 | {
|
---|
125 | async_exch_t *exch;
|
---|
126 | errno_t rc;
|
---|
127 |
|
---|
128 | exch = async_exchange_begin(window->display->sess);
|
---|
129 | rc = async_req_1_0(exch, DISPLAY_WINDOW_DESTROY, window->id);
|
---|
130 |
|
---|
131 | async_exchange_end(exch);
|
---|
132 |
|
---|
133 | free(window);
|
---|
134 | return rc;
|
---|
135 | }
|
---|
136 |
|
---|
137 | /** Create graphics context for drawing into a window.
|
---|
138 | *
|
---|
139 | * @param window Window
|
---|
140 | * @param rgc Place to store pointer to new graphics context
|
---|
141 | */
|
---|
142 | errno_t display_window_get_gc(display_window_t *window, gfx_context_t **rgc)
|
---|
143 | {
|
---|
144 | async_sess_t *sess;
|
---|
145 | async_exch_t *exch;
|
---|
146 | ipc_gc_t *gc;
|
---|
147 | errno_t rc;
|
---|
148 |
|
---|
149 | exch = async_exchange_begin(window->display->sess);
|
---|
150 | sess = async_connect_me_to(exch, INTERFACE_GC, 0, window->id);
|
---|
151 | if (sess == NULL) {
|
---|
152 | async_exchange_end(exch);
|
---|
153 | return EIO;
|
---|
154 | }
|
---|
155 |
|
---|
156 | async_exchange_end(exch);
|
---|
157 |
|
---|
158 | rc = ipc_gc_create(sess, &gc);
|
---|
159 | if (rc != EOK) {
|
---|
160 | async_hangup(sess);
|
---|
161 | return ENOMEM;
|
---|
162 | }
|
---|
163 |
|
---|
164 | *rgc = ipc_gc_get_ctx(gc);
|
---|
165 | return EOK;
|
---|
166 | }
|
---|
167 |
|
---|
168 | /** @}
|
---|
169 | */
|
---|