Changeset 2ab8ab3 in mainline for uspace/lib/memgfx
- Timestamp:
- 2021-02-16T18:12:05Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 68a552f
- Parents:
- ef734b7
- Location:
- uspace/lib/memgfx
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/memgfx/include/memgfx/memgc.h
ref734b7 r2ab8ab3 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 46 46 47 47 extern errno_t mem_gc_create(gfx_rect_t *, gfx_bitmap_alloc_t *, 48 mem_gc_ update_cb_t, void *, mem_gc_t **);48 mem_gc_invalidate_cb_t, mem_gc_update_cb_t, void *, mem_gc_t **); 49 49 extern errno_t mem_gc_delete(mem_gc_t *); 50 50 extern void mem_gc_retarget(mem_gc_t *, gfx_rect_t *, gfx_bitmap_alloc_t *); -
uspace/lib/memgfx/include/types/memgfx/memgc.h
ref734b7 r2ab8ab3 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 42 42 typedef struct mem_gc mem_gc_t; 43 43 44 typedef void (*mem_gc_update_cb_t)(void *, gfx_rect_t *); 44 typedef void (*mem_gc_invalidate_cb_t)(void *, gfx_rect_t *); 45 typedef void (*mem_gc_update_cb_t)(void *); 45 46 46 47 #endif -
uspace/lib/memgfx/private/memgc.h
ref734b7 r2ab8ab3 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 51 51 /** Allocation info */ 52 52 gfx_bitmap_alloc_t alloc; 53 /** Invalidate callback */ 54 mem_gc_invalidate_cb_t invalidate; 53 55 /** Update callback */ 54 56 mem_gc_update_cb_t update; -
uspace/lib/memgfx/src/memgc.c
ref734b7 r2ab8ab3 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 50 50 static errno_t mem_gc_set_color(void *, gfx_color_t *); 51 51 static errno_t mem_gc_fill_rect(void *, gfx_rect_t *); 52 static errno_t mem_gc_update(void *); 52 53 static errno_t mem_gc_bitmap_create(void *, gfx_bitmap_params_t *, 53 54 gfx_bitmap_alloc_t *, void **); … … 60 61 .set_color = mem_gc_set_color, 61 62 .fill_rect = mem_gc_fill_rect, 63 .update = mem_gc_update, 62 64 .bitmap_create = mem_gc_bitmap_create, 63 65 .bitmap_destroy = mem_gc_bitmap_destroy, … … 119 121 } 120 122 123 /** Update memory GC. 124 * 125 * @param arg Memory GC 126 * 127 * @return EOK on success or an error code 128 */ 129 static errno_t mem_gc_update(void *arg) 130 { 131 mem_gc_t *mgc = (mem_gc_t *) arg; 132 133 mgc->update(mgc->cb_arg); 134 return EOK; 135 } 136 121 137 /** Create memory GC. 122 138 * … … 132 148 */ 133 149 errno_t mem_gc_create(gfx_rect_t *rect, gfx_bitmap_alloc_t *alloc, 134 mem_gc_update_cb_t update_cb, void *cb_arg, mem_gc_t **rgc) 150 mem_gc_invalidate_cb_t invalidate_cb, mem_gc_update_cb_t update_cb, 151 void *cb_arg, mem_gc_t **rgc) 135 152 { 136 153 mem_gc_t *mgc = NULL; … … 152 169 mgc->alloc = *alloc; 153 170 171 mgc->invalidate = invalidate_cb; 154 172 mgc->update = update_cb; 155 173 mgc->cb_arg = cb_arg; … … 205 223 static void mem_gc_invalidate_rect(mem_gc_t *mgc, gfx_rect_t *rect) 206 224 { 207 mgc-> update(mgc->cb_arg, rect);225 mgc->invalidate(mgc->cb_arg, rect); 208 226 } 209 227 -
uspace/lib/memgfx/test/memgfx.c
ref734b7 r2ab8ab3 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 42 42 PCUT_TEST_SUITE(memgfx); 43 43 44 static void test_update_rect(void *arg, gfx_rect_t *rect); 44 static void test_invalidate_rect(void *arg, gfx_rect_t *rect); 45 static void test_update(void *arg); 45 46 46 47 typedef struct { 48 /** True if invalidate was called */ 49 bool invalidate_called; 50 /** Invalidate rectangle */ 51 gfx_rect_t inv_rect; 47 52 /** True if update was called */ 48 53 bool update_called; 49 /** Update rectangle */ 50 gfx_rect_t rect; 51 } test_update_t; 54 } test_resp_t; 52 55 53 56 /** Test creating and deleting a memory GC */ … … 69 72 PCUT_ASSERT_NOT_NULL(alloc.pixels); 70 73 71 rc = mem_gc_create(&rect, &alloc, NULL, NULL, &mgc);74 rc = mem_gc_create(&rect, &alloc, NULL, NULL, NULL, &mgc); 72 75 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 73 76 … … 89 92 pixel_t pixel; 90 93 pixel_t expected; 91 test_ update_t update;94 test_resp_t resp; 92 95 errno_t rc; 93 96 … … 103 106 PCUT_ASSERT_NOT_NULL(alloc.pixels); 104 107 105 rc = mem_gc_create(&rect, &alloc, test_update_rect, &update, &mgc); 108 rc = mem_gc_create(&rect, &alloc, test_invalidate_rect, 109 test_update, &resp, &mgc); 106 110 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 107 111 … … 122 126 frect.p1.y = 5; 123 127 124 memset(& update, 0, sizeof(update));128 memset(&resp, 0, sizeof(resp)); 125 129 126 130 rc = gfx_fill_rect(gc, &frect); … … 141 145 } 142 146 143 /* Check that the update rect is equal to the filled rect */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);147 /* Check that the invalidate rect is equal to the filled rect */ 148 PCUT_ASSERT_TRUE(resp.invalidate_called); 149 PCUT_ASSERT_INT_EQUALS(frect.p0.x, resp.inv_rect.p0.x); 150 PCUT_ASSERT_INT_EQUALS(frect.p0.y, resp.inv_rect.p0.y); 151 PCUT_ASSERT_INT_EQUALS(frect.p1.x, resp.inv_rect.p1.x); 152 PCUT_ASSERT_INT_EQUALS(frect.p1.y, resp.inv_rect.p1.y); 149 153 150 154 /* TODO: Check clipping once memgc can support pitch != width etc. */ … … 169 173 pixel_t pixel; 170 174 pixel_t expected; 171 test_ update_t update;175 test_resp_t resp; 172 176 errno_t rc; 173 177 … … 183 187 PCUT_ASSERT_NOT_NULL(alloc.pixels); 184 188 185 rc = mem_gc_create(&rect, &alloc, test_update_rect, &update, &mgc); 189 rc = mem_gc_create(&rect, &alloc, test_invalidate_rect, 190 test_update, &resp, &mgc); 186 191 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 187 192 … … 191 196 /* Create bitmap */ 192 197 198 gfx_bitmap_params_init(¶ms); 193 199 params.rect.p0.x = 0; 194 200 params.rect.p0.y = 0; … … 219 225 dpmap.data = alloc.pixels; 220 226 221 memset(& update, 0, sizeof(update));227 memset(&resp, 0, sizeof(resp)); 222 228 223 229 /* Render the bitmap */ … … 237 243 } 238 244 239 /* Check that the update rect is equal to the filled rect */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);245 /* Check that the invalidate rect is equal to the filled rect */ 246 PCUT_ASSERT_TRUE(resp.invalidate_called); 247 PCUT_ASSERT_INT_EQUALS(params.rect.p0.x, resp.inv_rect.p0.x); 248 PCUT_ASSERT_INT_EQUALS(params.rect.p0.y, resp.inv_rect.p0.y); 249 PCUT_ASSERT_INT_EQUALS(params.rect.p1.x, resp.inv_rect.p1.x); 250 PCUT_ASSERT_INT_EQUALS(params.rect.p1.y, resp.inv_rect.p1.y); 245 251 246 252 /* TODO: Check clipping once memgc can support pitch != width etc. */ … … 250 256 } 251 257 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; 258 /** Test gfx_update() on a memory GC */ 259 PCUT_TEST(gfx_update) 260 { 261 mem_gc_t *mgc; 262 gfx_rect_t rect; 263 gfx_bitmap_alloc_t alloc; 264 gfx_context_t *gc; 265 test_resp_t resp; 266 errno_t rc; 267 268 /* Bounding rectangle for memory GC */ 269 rect.p0.x = 0; 270 rect.p0.y = 0; 271 rect.p1.x = 10; 272 rect.p1.y = 10; 273 274 alloc.pitch = (rect.p1.x - rect.p0.x) * sizeof(uint32_t); 275 alloc.off0 = 0; 276 alloc.pixels = calloc(1, alloc.pitch * (rect.p1.y - rect.p0.y)); 277 PCUT_ASSERT_NOT_NULL(alloc.pixels); 278 279 rc = mem_gc_create(&rect, &alloc, test_invalidate_rect, 280 test_update, &resp, &mgc); 281 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 282 283 gc = mem_gc_get_ctx(mgc); 284 PCUT_ASSERT_NOT_NULL(gc); 285 286 memset(&resp, 0, sizeof(resp)); 287 PCUT_ASSERT_FALSE(resp.update_called); 288 289 gfx_update(gc); 290 PCUT_ASSERT_TRUE(resp.update_called); 291 292 mem_gc_delete(mgc); 293 free(alloc.pixels); 294 } 295 296 /** Called by memory GC when a rectangle is modified. */ 297 static void test_invalidate_rect(void *arg, gfx_rect_t *rect) 298 { 299 test_resp_t *resp = (test_resp_t *)arg; 300 301 resp->invalidate_called = true; 302 resp->inv_rect = *rect; 303 } 304 305 /** Called by memory GC when update is called. */ 306 static void test_update(void *arg) 307 { 308 test_resp_t *resp = (test_resp_t *)arg; 309 310 resp->update_called = true; 259 311 } 260 312
Note:
See TracChangeset
for help on using the changeset viewer.