Changeset f8375f7 in mainline for uspace/lib/memgfx
- Timestamp:
- 2020-05-30T17:16:39Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- dbef30f
- Parents:
- cea9f0c
- Location:
- uspace/lib/memgfx
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/memgfx/include/memgfx/memgc.h
rcea9f0c rf8375f7 40 40 #include <types/gfx/bitmap.h> 41 41 #include <types/gfx/context.h> 42 #include <types/gfx/coord.h>43 42 #include <types/gfx/ops/context.h> 44 43 #include <types/memgfx/memgc.h> … … 46 45 extern gfx_context_ops_t mem_gc_ops; 47 46 48 extern errno_t mem_gc_create(gfx_rect_t *, gfx_bitmap_alloc_t *, mem_gc_t **); 47 extern errno_t mem_gc_create(gfx_rect_t *, gfx_bitmap_alloc_t *, 48 mem_gc_update_cb_t, void *, mem_gc_t **); 49 49 extern errno_t mem_gc_delete(mem_gc_t *); 50 50 extern gfx_context_t *mem_gc_get_ctx(mem_gc_t *); 51 extern void mem_gc_get_update_rect(mem_gc_t *, gfx_rect_t *);52 extern void mem_gc_clear_update_rect(mem_gc_t *);53 51 54 52 #endif -
uspace/lib/memgfx/include/types/memgfx/memgc.h
rcea9f0c rf8375f7 37 37 #define _MEMGFX_TYPES_MEMGC_H 38 38 39 #include <types/gfx/coord.h> 40 39 41 struct mem_gc; 40 42 typedef struct mem_gc mem_gc_t; 43 44 typedef void (*mem_gc_update_cb_t)(void *, gfx_rect_t *); 41 45 42 46 #endif -
uspace/lib/memgfx/private/memgc.h
rcea9f0c rf8375f7 49 49 /** Bounding rectangle */ 50 50 gfx_rect_t rect; 51 /** Update rectangle */52 gfx_rect_t upd_rect;53 51 /** Allocation info */ 54 52 gfx_bitmap_alloc_t alloc; 53 /** Update callback */ 54 mem_gc_update_cb_t update; 55 /** Argument to callback */ 56 void *cb_arg; 55 57 /** Current drawing color */ 56 58 pixel_t color; -
uspace/lib/memgfx/src/memgc.c
rcea9f0c rf8375f7 123 123 * @param rect Bounding rectangle 124 124 * @param alloc Allocation info 125 * @param update_cb Function called to update a rectangle 126 * @param cb_arg Argument to callback function 125 127 * @param rgc Place to store pointer to new memory GC 126 128 * … … 128 130 */ 129 131 errno_t mem_gc_create(gfx_rect_t *rect, gfx_bitmap_alloc_t *alloc, 130 mem_gc_ t **rgc)132 mem_gc_update_cb_t update_cb, void *cb_arg, mem_gc_t **rgc) 131 133 { 132 134 mem_gc_t *mgc = NULL; … … 159 161 assert(alloc->pitch == rect->p1.x * (int)sizeof(uint32_t)); 160 162 161 mem_gc_clear_update_rect(mgc); 163 mgc->update = update_cb; 164 mgc->cb_arg = cb_arg; 162 165 163 166 *rgc = mgc; … … 198 201 static void mem_gc_invalidate_rect(mem_gc_t *mgc, gfx_rect_t *rect) 199 202 { 200 gfx_rect_t nrect; 201 202 gfx_rect_envelope(&mgc->upd_rect, rect, &nrect); 203 mgc->upd_rect = nrect; 204 } 205 206 void mem_gc_get_update_rect(mem_gc_t *mgc, gfx_rect_t *rect) 207 { 208 *rect = mgc->upd_rect; 209 } 210 211 void mem_gc_clear_update_rect(mem_gc_t *mgc) 212 { 213 mgc->upd_rect.p0.x = 0; 214 mgc->upd_rect.p0.y = 0; 215 mgc->upd_rect.p1.x = 0; 216 mgc->upd_rect.p1.y = 0; 203 mgc->update(mgc->cb_arg, rect); 217 204 } 218 205 -
uspace/lib/memgfx/test/memgfx.c
rcea9f0c rf8375f7 34 34 #include <gfx/render.h> 35 35 #include <io/pixelmap.h> 36 #include <mem.h> 36 37 #include <memgfx/memgc.h> 37 38 #include <pcut/pcut.h> … … 40 41 41 42 PCUT_TEST_SUITE(memgfx); 43 44 static void test_update_rect(void *arg, gfx_rect_t *rect); 45 46 typedef struct { 47 /** True if update was called */ 48 bool update_called; 49 /** Update rectangle */ 50 gfx_rect_t rect; 51 } test_update_t; 42 52 43 53 /** Test creating and deleting a memory GC */ … … 59 69 PCUT_ASSERT_NOT_NULL(alloc.pixels); 60 70 61 rc = mem_gc_create(&rect, &alloc, &mgc);71 rc = mem_gc_create(&rect, &alloc, NULL, NULL, &mgc); 62 72 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 63 73 … … 72 82 gfx_rect_t rect; 73 83 gfx_rect_t frect; 74 gfx_rect_t urect;75 84 gfx_bitmap_alloc_t alloc; 76 85 gfx_context_t *gc; … … 80 89 pixel_t pixel; 81 90 pixel_t expected; 91 test_update_t update; 82 92 errno_t rc; 83 93 … … 93 103 PCUT_ASSERT_NOT_NULL(alloc.pixels); 94 104 95 rc = mem_gc_create(&rect, &alloc, &mgc);105 rc = mem_gc_create(&rect, &alloc, test_update_rect, &update, &mgc); 96 106 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 97 107 … … 111 121 frect.p1.x = 5; 112 122 frect.p1.y = 5; 123 124 memset(&update, 0, sizeof(update)); 113 125 114 126 rc = gfx_fill_rect(gc, &frect); … … 130 142 131 143 /* Check that the update rect is equal to the filled rect */ 132 mem_gc_get_update_rect(mgc, &urect); 133 PCUT_ASSERT_INT_EQUALS(frect.p0.x, urect.p0.x); 134 PCUT_ASSERT_INT_EQUALS(frect.p0.y, urect.p0.y); 135 PCUT_ASSERT_INT_EQUALS(frect.p1.x, urect.p1.x); 136 PCUT_ASSERT_INT_EQUALS(frect.p1.y, urect.p1.y); 137 138 /* Check that mem_gc_clear_update_rect() clears the update rect */ 139 mem_gc_clear_update_rect(mgc); 140 mem_gc_get_update_rect(mgc, &urect); 141 PCUT_ASSERT_TRUE(gfx_rect_is_empty(&urect)); 144 PCUT_ASSERT_TRUE(update.update_called); 145 PCUT_ASSERT_INT_EQUALS(frect.p0.x, update.rect.p0.x); 146 PCUT_ASSERT_INT_EQUALS(frect.p0.y, update.rect.p0.y); 147 PCUT_ASSERT_INT_EQUALS(frect.p1.x, update.rect.p1.x); 148 PCUT_ASSERT_INT_EQUALS(frect.p1.y, update.rect.p1.y); 142 149 143 150 /* TODO: Check clipping once memgc can support pitch != width etc. */ … … 152 159 mem_gc_t *mgc; 153 160 gfx_rect_t rect; 154 gfx_rect_t urect;155 161 gfx_bitmap_alloc_t alloc; 156 162 gfx_context_t *gc; … … 163 169 pixel_t pixel; 164 170 pixel_t expected; 171 test_update_t update; 165 172 errno_t rc; 166 173 … … 176 183 PCUT_ASSERT_NOT_NULL(alloc.pixels); 177 184 178 rc = mem_gc_create(&rect, &alloc, &mgc);185 rc = mem_gc_create(&rect, &alloc, test_update_rect, &update, &mgc); 179 186 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 180 187 … … 211 218 dpmap.height = rect.p1.y - rect.p0.y; 212 219 dpmap.data = alloc.pixels; 220 221 memset(&update, 0, sizeof(update)); 213 222 214 223 /* Render the bitmap */ … … 229 238 230 239 /* Check that the update rect is equal to the filled rect */ 231 mem_gc_get_update_rect(mgc, &urect); 232 PCUT_ASSERT_INT_EQUALS(params.rect.p0.x, urect.p0.x); 233 PCUT_ASSERT_INT_EQUALS(params.rect.p0.y, urect.p0.y); 234 PCUT_ASSERT_INT_EQUALS(params.rect.p1.x, urect.p1.x); 235 PCUT_ASSERT_INT_EQUALS(params.rect.p1.y, urect.p1.y); 236 237 /* Check that mem_gc_clear_update_rect() clears the update rect */ 238 mem_gc_clear_update_rect(mgc); 239 mem_gc_get_update_rect(mgc, &urect); 240 PCUT_ASSERT_TRUE(gfx_rect_is_empty(&urect)); 240 PCUT_ASSERT_TRUE(update.update_called); 241 PCUT_ASSERT_INT_EQUALS(params.rect.p0.x, update.rect.p0.x); 242 PCUT_ASSERT_INT_EQUALS(params.rect.p0.y, update.rect.p0.y); 243 PCUT_ASSERT_INT_EQUALS(params.rect.p1.x, update.rect.p1.x); 244 PCUT_ASSERT_INT_EQUALS(params.rect.p1.y, update.rect.p1.y); 241 245 242 246 /* TODO: Check clipping once memgc can support pitch != width etc. */ … … 246 250 } 247 251 252 /** Called by memory GC when a rectangle is updated. */ 253 static void test_update_rect(void *arg, gfx_rect_t *rect) 254 { 255 test_update_t *update = (test_update_t *)arg; 256 257 update->update_called = true; 258 update->rect = *rect; 259 } 260 248 261 PCUT_EXPORT(memgfx);
Note:
See TracChangeset
for help on using the changeset viewer.