Changeset 7470d97 in mainline for uspace/srv
- Timestamp:
- 2021-04-30T15:05:06Z (4 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 051349b
- Parents:
- 252d03c
- Location:
- uspace/srv/hid
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/display/clonegc.c
r252d03c r7470d97 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 44 44 #include "clonegc.h" 45 45 46 static errno_t ds_clonegc_set_clip_rect(void *, gfx_rect_t *); 46 47 static errno_t ds_clonegc_set_color(void *, gfx_color_t *); 47 48 static errno_t ds_clonegc_fill_rect(void *, gfx_rect_t *); … … 65 66 66 67 gfx_context_ops_t ds_clonegc_ops = { 68 .set_clip_rect = ds_clonegc_set_clip_rect, 67 69 .set_color = ds_clonegc_set_color, 68 70 .fill_rect = ds_clonegc_fill_rect, … … 73 75 }; 74 76 77 /** Set clipping rectangle on clone GC. 78 * 79 * @param arg Clone GC 80 * @param rect Rectangle 81 * 82 * @return EOK on success or an error code 83 */ 84 static errno_t ds_clonegc_set_clip_rect(void *arg, gfx_rect_t *rect) 85 { 86 ds_clonegc_t *cgc = (ds_clonegc_t *)arg; 87 ds_clonegc_output_t *output; 88 errno_t rc; 89 90 output = ds_clonegc_first_output(cgc); 91 while (output != NULL) { 92 rc = gfx_set_clip_rect(output->gc, rect); 93 if (rc != EOK) 94 return rc; 95 96 output = ds_clonegc_next_output(output); 97 } 98 99 return EOK; 100 } 101 75 102 /** Set color on clone GC. 76 103 * -
uspace/srv/hid/display/test/clonegc.c
r252d03c r7470d97 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 39 39 PCUT_TEST_SUITE(clonegc); 40 40 41 static errno_t testgc_set_clip_rect(void *, gfx_rect_t *); 41 42 static errno_t testgc_set_color(void *, gfx_color_t *); 42 43 static errno_t testgc_fill_rect(void *, gfx_rect_t *); … … 48 49 49 50 static gfx_context_ops_t ops = { 51 .set_clip_rect = testgc_set_clip_rect, 50 52 .set_color = testgc_set_color, 51 53 .fill_rect = testgc_fill_rect, … … 59 61 /** Error code to return */ 60 62 errno_t rc; 63 64 bool set_clip_rect_called; 65 gfx_rect_t *set_clip_rect_rect; 61 66 62 67 bool set_color_called; … … 95 100 rc = ds_clonegc_create(NULL, &cgc); 96 101 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 102 103 rc = ds_clonegc_delete(cgc); 104 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 105 } 106 107 /** Set clipping rectangle with two output GCs */ 108 PCUT_TEST(set_clip_rect) 109 { 110 ds_clonegc_t *cgc; 111 gfx_context_t *gc; 112 test_gc_t tgc1; 113 gfx_context_t *gc1; 114 test_gc_t tgc2; 115 gfx_context_t *gc2; 116 gfx_rect_t rect; 117 errno_t rc; 118 119 /* Create clone GC */ 120 rc = ds_clonegc_create(NULL, &cgc); 121 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 122 123 gc = ds_clonegc_get_ctx(cgc); 124 PCUT_ASSERT_NOT_NULL(gc); 125 126 /* Add two output GCs */ 127 128 rc = gfx_context_new(&ops, &tgc1, &gc1); 129 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 130 131 rc = ds_clonegc_add_output(cgc, gc1); 132 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 133 134 rc = gfx_context_new(&ops, &tgc2, &gc2); 135 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 136 137 rc = ds_clonegc_add_output(cgc, gc2); 138 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 139 140 rect.p0.x = 1; 141 rect.p0.y = 2; 142 rect.p1.x = 3; 143 rect.p1.y = 4; 144 145 /* Set clipping rectangle returning error */ 146 147 tgc1.set_clip_rect_called = false; 148 tgc2.set_clip_rect_called = false; 149 tgc1.rc = EINVAL; 150 tgc2.rc = EINVAL; 151 152 rc = gfx_set_clip_rect(gc, &rect); 153 PCUT_ASSERT_ERRNO_VAL(EINVAL, rc); 154 155 PCUT_ASSERT_TRUE(tgc1.set_clip_rect_called); 156 PCUT_ASSERT_EQUALS(&rect, tgc1.set_clip_rect_rect); 157 PCUT_ASSERT_FALSE(tgc2.set_clip_rect_called); 158 159 /* Set clipping rectangle returning success for all outputs */ 160 tgc1.set_clip_rect_called = false; 161 tgc2.set_clip_rect_called = false; 162 tgc1.rc = EOK; 163 tgc2.rc = EOK; 164 165 rc = gfx_set_clip_rect(gc, &rect); 166 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 167 168 PCUT_ASSERT_TRUE(tgc1.set_clip_rect_called); 169 PCUT_ASSERT_EQUALS(&rect, tgc1.set_clip_rect_rect); 170 PCUT_ASSERT_TRUE(tgc2.set_clip_rect_called); 171 PCUT_ASSERT_EQUALS(&rect, tgc2.set_clip_rect_rect); 97 172 98 173 rc = ds_clonegc_delete(cgc); … … 628 703 } 629 704 705 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect) 706 { 707 test_gc_t *tgc = (test_gc_t *) arg; 708 709 tgc->set_clip_rect_called = true; 710 tgc->set_clip_rect_rect = rect; 711 712 return tgc->rc; 713 } 714 630 715 static errno_t testgc_set_color(void *arg, gfx_color_t *color) 631 716 { -
uspace/srv/hid/rfb/main.c
r252d03c r7470d97 1 1 /* 2 * Copyright (c) 2021 Jiri Svoboda 2 3 * Copyright (c) 2013 Martin Sucha 3 4 * All rights reserved. … … 50 51 static errno_t rfb_ddev_get_info(void *, ddev_info_t *); 51 52 53 static errno_t rfb_gc_set_clip_rect(void *, gfx_rect_t *); 52 54 static errno_t rfb_gc_set_color(void *, gfx_color_t *); 53 55 static errno_t rfb_gc_fill_rect(void *, gfx_rect_t *); … … 66 68 rfb_t rfb; 67 69 pixel_t color; 70 gfx_rect_t rect; 71 gfx_rect_t clip_rect; 68 72 } rfb_gc_t; 69 73 … … 78 82 79 83 static gfx_context_ops_t rfb_gc_ops = { 84 .set_clip_rect = rfb_gc_set_clip_rect, 80 85 .set_color = rfb_gc_set_color, 81 86 .fill_rect = rfb_gc_fill_rect, … … 134 139 } 135 140 141 /** Create RFB GC. 142 * 143 * @param rrgb Place to store pointer to new RFB GC 144 * @return EOK on success, ENOMEM if out of memory 145 */ 146 static errno_t rgb_gc_create(rfb_gc_t **rrfb) 147 { 148 rfb_gc_t *rfb; 149 150 rfb = calloc(1, sizeof(rfb_gc_t)); 151 if (rfb == NULL) 152 return ENOMEM; 153 154 *rrfb = rfb; 155 return EOK; 156 } 157 158 /** Destroy RFB GC. 159 * 160 * @param rfb RFB GC 161 */ 162 static void rfb_gc_destroy(rfb_gc_t *rfb) 163 { 164 free(rfb); 165 } 166 167 /** Set clipping rectangle on RFB. 168 * 169 * @param arg RFB 170 * @param rect Rectangle or @c NULL 171 * 172 * @return EOK on success or an error code 173 */ 174 static errno_t rfb_gc_set_clip_rect(void *arg, gfx_rect_t *rect) 175 { 176 rfb_gc_t *rfb = (rfb_gc_t *) arg; 177 178 if (rect != NULL) 179 gfx_rect_clip(rect, &rfb->rect, &rfb->clip_rect); 180 else 181 rfb->clip_rect = rfb->rect; 182 183 return EOK; 184 } 185 136 186 /** Set color on RFB. 137 187 * … … 163 213 { 164 214 rfb_gc_t *rfb = (rfb_gc_t *) arg; 215 gfx_rect_t crect; 165 216 gfx_coord_t x, y; 166 217 167 // XXX We should handle p0.x > p1.x and p0.y > p1.y168 169 for (y = rect->p0.y; y < rect->p1.y; y++) {170 for (x = rect->p0.x; x < rect->p1.x; x++) {218 gfx_rect_clip(rect, &rfb->clip_rect, &crect); 219 220 for (y = crect.p0.y; y < crect.p1.y; y++) { 221 for (x = crect.p0.x; x < crect.p1.x; x++) { 171 222 pixelmap_put_pixel(&rfb->rfb.framebuffer, x, y, 172 223 rfb->color); … … 174 225 } 175 226 176 rfb_gc_invalidate_rect(rfb, rect);227 rfb_gc_invalidate_rect(rfb, &crect); 177 228 178 229 return EOK; … … 258 309 gfx_rect_t srect; 259 310 gfx_rect_t drect; 311 gfx_rect_t crect; 260 312 gfx_coord2_t offs; 261 313 gfx_coord2_t bmdim; … … 279 331 /* Destination rectangle */ 280 332 gfx_rect_translate(&offs, &srect, &drect); 281 gfx_coord2_subtract(&drect.p1, &drect.p0, &dim); 333 gfx_rect_clip(&drect, &rfbbm->rfb->clip_rect, &crect); 334 gfx_coord2_subtract(&crect.p1, &crect.p0, &dim); 282 335 gfx_coord2_subtract(&rfbbm->rect.p1, &rfbbm->rect.p0, &bmdim); 283 336 … … 320 373 } 321 374 322 rfb_gc_invalidate_rect(rfbbm->rfb, & drect);375 rfb_gc_invalidate_rect(rfbbm->rfb, &crect); 323 376 324 377 return EOK; … … 346 399 { 347 400 rfb_t *rfb = (rfb_t *) arg; 401 rfb_gc_t *rfbgc; 348 402 ddev_srv_t srv; 349 403 sysarg_t svc_id; … … 362 416 ddev_conn(icall, &srv); 363 417 } else { 364 rc = gfx_context_new(&rfb_gc_ops, (void *) rfb, &gc);418 rc = rgb_gc_create(&rfbgc); 365 419 if (rc != EOK) { 420 async_answer_0(icall, ENOMEM); 421 return; 422 } 423 424 rfbgc->rect.p0.x = 0; 425 rfbgc->rect.p0.y = 0; 426 rfbgc->rect.p1.x = rfb->width; 427 rfbgc->rect.p1.y = rfb->height; 428 rfbgc->clip_rect = rfbgc->rect; 429 430 rc = gfx_context_new(&rfb_gc_ops, (void *) rfbgc, &gc); 431 if (rc != EOK) { 432 rfb_gc_destroy(rfbgc); 366 433 async_answer_0(icall, ENOMEM); 367 434 return;
Note:
See TracChangeset
for help on using the changeset viewer.