source: mainline/uspace/lib/gfx/test/render.c@ 252d03c

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

Client-side UI rendering

It is possible to turn on and off and if turned on, one can also
enable or disable window double buffering (currently both options
are build-time).

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[d6dc9a12]1/*
[2ab8ab3]2 * Copyright (c) 2021 Jiri Svoboda
[d6dc9a12]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 <gfx/color.h>
[045186b]30#include <gfx/context.h>
[d6dc9a12]31#include <gfx/render.h>
32#include <pcut/pcut.h>
[045186b]33#include <mem.h>
[2ab8ab3]34#include <stdbool.h>
[d6dc9a12]35
36PCUT_INIT;
37
38PCUT_TEST_SUITE(render);
39
[045186b]40static errno_t testgc_set_color(void *, gfx_color_t *);
41static errno_t testgc_fill_rect(void *, gfx_rect_t *);
[2ab8ab3]42static errno_t testgc_update(void *);
[045186b]43
44static gfx_context_ops_t ops = {
45 .set_color = testgc_set_color,
[2ab8ab3]46 .fill_rect = testgc_fill_rect,
47 .update = testgc_update
[045186b]48};
49
50/** Test graphics context data */
51typedef struct {
52 gfx_color_t *dclr;
53 gfx_rect_t *rect;
[2ab8ab3]54 bool updated;
[045186b]55} test_gc_t;
56
[d6dc9a12]57PCUT_TEST(set_color)
58{
59 errno_t rc;
60 gfx_color_t *color;
61 gfx_context_t *gc = NULL;
[045186b]62 test_gc_t tgc;
63
64 memset(&tgc, 0, sizeof(tgc));
65
66 rc = gfx_context_new(&ops, &tgc, &gc);
67 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
[d6dc9a12]68
69 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
70 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
71
72 rc = gfx_set_color(gc, color);
73 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
[045186b]74 PCUT_ASSERT_EQUALS(color, tgc.dclr);
75 PCUT_ASSERT_NULL(tgc.rect);
[d6dc9a12]76
77 gfx_color_delete(color);
[045186b]78
79 rc = gfx_context_delete(gc);
80 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
[d6dc9a12]81}
82
83PCUT_TEST(fill_rect)
84{
85 errno_t rc;
86 gfx_color_t *color;
87 gfx_rect_t rect;
88 gfx_context_t *gc = NULL;
[045186b]89 test_gc_t tgc;
90
91 memset(&tgc, 0, sizeof(tgc));
92
93 rc = gfx_context_new(&ops, &tgc, &gc);
94 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
[d6dc9a12]95
96 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
97 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
98
99 rc = gfx_set_color(gc, color);
100 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
[045186b]101 PCUT_ASSERT_EQUALS(color, tgc.dclr);
[d6dc9a12]102
103 rc = gfx_fill_rect(gc, &rect);
104 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
[045186b]105 PCUT_ASSERT_EQUALS(&rect, tgc.rect);
[d6dc9a12]106
107 gfx_color_delete(color);
[045186b]108
109 rc = gfx_context_delete(gc);
110 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
111}
112
[2ab8ab3]113PCUT_TEST(update)
114{
115 errno_t rc;
116 gfx_context_t *gc = NULL;
117 test_gc_t tgc;
118
119 memset(&tgc, 0, sizeof(tgc));
120
121 rc = gfx_context_new(&ops, &tgc, &gc);
122 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
123
124 PCUT_ASSERT_FALSE(tgc.updated);
125 gfx_update(gc);
126 PCUT_ASSERT_TRUE(tgc.updated);
127
128 rc = gfx_context_delete(gc);
129 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
130}
131
[9259d20]132static errno_t testgc_set_color(void *arg, gfx_color_t *color)
[045186b]133{
134 test_gc_t *tgc = (test_gc_t *) arg;
135
136 /* Technically we should copy the data */
137 tgc->dclr = color;
138 return EOK;
139}
140
[9259d20]141static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
[045186b]142{
143 test_gc_t *tgc = (test_gc_t *) arg;
144
145 /* Technically we should copy the data */
146 tgc->rect = rect;
147 return EOK;
[d6dc9a12]148}
149
[2ab8ab3]150static errno_t testgc_update(void *arg)
151{
152 test_gc_t *tgc = (test_gc_t *) arg;
153
154 tgc->updated = true;
155 return EOK;
156}
157
[d6dc9a12]158PCUT_EXPORT(render);
Note: See TracBrowser for help on using the repository browser.