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