source: mainline/uspace/srv/hid/display/window.c@ 6af4b4f

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

Introduce ds_display_t, ds_window_t

  • Property mode set to 100644
File size: 3.6 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/color.h>
39#include <gfx/context.h>
40#include <gfx/render.h>
41#include <io/log.h>
42#include <stdlib.h>
43#include "display.h"
44#include "window.h"
45
46static errno_t ds_window_set_color(void *, gfx_color_t *);
47static errno_t ds_window_fill_rect(void *, gfx_rect_t *);
48
49gfx_context_ops_t ds_window_ops = {
50 .set_color = ds_window_set_color,
51 .fill_rect = ds_window_fill_rect
52};
53
54/** Set color on window GC.
55 *
56 * Set drawing color on window GC.
57 *
58 * @param arg Console GC
59 * @param color Color
60 *
61 * @return EOK on success or an error code
62 */
63static errno_t ds_window_set_color(void *arg, gfx_color_t *color)
64{
65 ds_window_t *wnd = (ds_window_t *) arg;
66
67 (void) wnd;
68 log_msg(LOG_DEFAULT, LVL_NOTE, "gc_set_color");
69 return EOK;
70}
71
72/** Fill rectangle on window GC.
73 *
74 * @param arg Window GC
75 * @param rect Rectangle
76 *
77 * @return EOK on success or an error code
78 */
79static errno_t ds_window_fill_rect(void *arg, gfx_rect_t *rect)
80{
81 ds_window_t *wnd = (ds_window_t *) arg;
82
83 (void) wnd;
84 log_msg(LOG_DEFAULT, LVL_NOTE, "gc_fill_rect");
85 return EOK;
86}
87
88/** Create window.
89 *
90 * Create graphics context for rendering into a window.
91 *
92 * @param disp Display to create window on
93 * @param rgc Place to store pointer to new GC.
94 *
95 * @return EOK on success or an error code
96 */
97errno_t ds_window_create(ds_display_t *disp, ds_window_t **rgc)
98{
99 ds_window_t *wnd = NULL;
100 gfx_context_t *gc = NULL;
101 errno_t rc;
102
103 wnd = calloc(1, sizeof(ds_window_t));
104 if (wnd == NULL) {
105 rc = ENOMEM;
106 goto error;
107 }
108
109 rc = gfx_context_new(&ds_window_ops, wnd, &gc);
110 if (rc != EOK)
111 goto error;
112
113 ds_display_add_window(disp, wnd);
114
115 wnd->gc = gc;
116 *rgc = wnd;
117 return EOK;
118error:
119 if (wnd != NULL)
120 free(wnd);
121 gfx_context_delete(gc);
122 return rc;
123}
124
125/** Delete window GC.
126 *
127 * @param wnd Window GC
128 */
129errno_t ds_window_delete(ds_window_t *wnd)
130{
131 errno_t rc;
132
133 rc = gfx_context_delete(wnd->gc);
134 if (rc != EOK)
135 return rc;
136
137 free(wnd);
138 return EOK;
139}
140
141/** Get generic graphic context from window.
142 *
143 * @param wnd Window
144 * @return Graphic context
145 */
146gfx_context_t *ds_window_get_ctx(ds_window_t *wnd)
147{
148 return wnd->gc;
149}
150
151/** @}
152 */
Note: See TracBrowser for help on using the repository browser.