Changeset 7470d97 in mainline


Ignore:
Timestamp:
2021-04-30T15:05:06Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
051349b
Parents:
252d03c
Message:

Add GC operation to set clipping rectangle

The number of changed files is due to the proliferation of GC
implementations, mostly these are just dummies in unit tests.
Definitely need to tame those in the future.

Location:
uspace
Files:
33 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/fb/amdm37x_dispc/amdm37x_dispc.c

    r252d03c r7470d97  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * Copyright (c) 2013 Jan Vesely
    44 * All rights reserved.
     
    6767static errno_t amdm37x_ddev_get_info(void *, ddev_info_t *);
    6868
     69static errno_t amdm37x_gc_set_clip_rect(void *, gfx_rect_t *);
    6970static errno_t amdm37x_gc_set_color(void *, gfx_color_t *);
    7071static errno_t amdm37x_gc_fill_rect(void *, gfx_rect_t *);
     
    8182
    8283gfx_context_ops_t amdm37x_gc_ops = {
     84        .set_clip_rect = amdm37x_gc_set_clip_rect,
    8385        .set_color = amdm37x_gc_set_color,
    8486        .fill_rect = amdm37x_gc_fill_rect,
     
    291293        dispc->rect.p1.x = x;
    292294        dispc->rect.p1.y = y;
     295        dispc->clip_rect = dispc->rect;
    293296        dispc->size = size;
    294297
     
    321324}
    322325
     326/** Set clipping rectangle on AMDM37x display controller.
     327 *
     328 * @param arg AMDM37x display controller
     329 * @param rect Rectangle
     330 *
     331 * @return EOK on success or an error code
     332 */
     333static errno_t amdm37x_gc_set_clip_rect(void *arg, gfx_rect_t *rect)
     334{
     335        amdm37x_dispc_t *dispc = (amdm37x_dispc_t *) arg;
     336
     337        if (rect != NULL)
     338                gfx_rect_clip(rect, &dispc->rect, &dispc->clip_rect);
     339        else
     340                dispc->clip_rect = dispc->rect;
     341
     342        return EOK;
     343}
     344
    323345/** Set color on AMDM37x display controller.
    324346 *
     
    354376
    355377        /* Make sure we have a sorted, clipped rectangle */
    356         gfx_rect_clip(rect, &dispc->rect, &crect);
     378        gfx_rect_clip(rect, &dispc->clip_rect, &crect);
    357379
    358380        for (y = crect.p0.y; y < crect.p1.y; y++) {
     
    479501        pbm.data = dcbm->alloc.pixels;
    480502
    481         /* Transform AMDM37x bounding rectangle back to bitmap coordinate system */
    482         gfx_rect_rtranslate(&offs, &dispc->rect, &skfbrect);
     503        /* Transform AMDM37x clipping rectangle back to bitmap coordinate system */
     504        gfx_rect_rtranslate(&offs, &dispc->clip_rect, &skfbrect);
    483505
    484506        /*
  • uspace/drv/fb/amdm37x_dispc/amdm37x_dispc.h

    r252d03c r7470d97  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * Copyright (c) 2013 Jan Vesely
    44 * All rights reserved.
     
    6363        pixel_t color;
    6464        gfx_rect_t rect;
     65        gfx_rect_t clip_rect;
    6566        size_t size;
    6667        void *fb_data;
  • uspace/drv/fb/kfb/port.c

    r252d03c r7470d97  
    11/*
    2  * Copyright (c) 2019 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * Copyright (c) 2006 Jakub Vana
    44 * Copyright (c) 2006 Ondrej Palkovsky
     
    6969        sysarg_t paddr;
    7070        gfx_rect_t rect;
     71        gfx_rect_t clip_rect;
    7172        size_t offset;
    7273        size_t scanline;
     
    9798static errno_t kfb_ddev_get_info(void *, ddev_info_t *);
    9899
     100static errno_t kfb_gc_set_clip_rect(void *, gfx_rect_t *);
    99101static errno_t kfb_gc_set_color(void *, gfx_color_t *);
    100102static errno_t kfb_gc_fill_rect(void *, gfx_rect_t *);
     
    111113
    112114static gfx_context_ops_t kfb_gc_ops = {
     115        .set_clip_rect = kfb_gc_set_clip_rect,
    113116        .set_color = kfb_gc_set_color,
    114117        .fill_rect = kfb_gc_fill_rect,
     
    134137        ddev_info_init(info);
    135138        info->rect = kfb->rect;
     139        return EOK;
     140}
     141
     142/** Set clipping rectangle on KFB.
     143 *
     144 * @param arg KFB
     145 * @param rect Rectangle or @c NULL
     146 *
     147 * @return EOK on success or an error code
     148 */
     149static errno_t kfb_gc_set_clip_rect(void *arg, gfx_rect_t *rect)
     150{
     151        kfb_t *kfb = (kfb_t *) arg;
     152
     153        if (rect != NULL)
     154                gfx_rect_clip(rect, &kfb->rect, &kfb->clip_rect);
     155        else
     156                kfb->clip_rect = kfb->rect;
     157
    136158        return EOK;
    137159}
     
    361383}
    362384
    363 #include <stdio.h>
    364385static void kfb_client_conn(ipc_call_t *icall, void *arg)
    365386{
     
    372393        kfb = (kfb_t *) ddf_fun_data_get((ddf_fun_t *) arg);
    373394
    374         printf("kfb_client_conn arg2=%lu arg3=%lu arg4=%lu\n",
    375             (unsigned long) ipc_get_arg2(icall),
    376             (unsigned long) ipc_get_arg3(icall),
    377             (unsigned long) ipc_get_arg4(icall));
    378 
    379395        gc_id = ipc_get_arg3(icall);
    380396
     
    500516        kfb->rect.p1.x = width;
    501517        kfb->rect.p1.y = height;
     518
     519        kfb->clip_rect = kfb->rect;
    502520
    503521        kfb->paddr = paddr;
  • uspace/lib/congfx/private/console.h

    r252d03c r7470d97  
    5555        /** Console bounding rectangle */
    5656        gfx_rect_t rect;
     57        /** Clipping rectangle */
     58        gfx_rect_t clip_rect;
    5759        /** File for printing characters */
    5860        FILE *fout;
  • uspace/lib/congfx/src/console.c

    r252d03c r7470d97  
    4848#include "../private/color.h"
    4949
     50static errno_t console_gc_set_clip_rect(void *, gfx_rect_t *);
    5051static errno_t console_gc_set_color(void *, gfx_color_t *);
    5152static errno_t console_gc_fill_rect(void *, gfx_rect_t *);
     
    5859
    5960gfx_context_ops_t console_gc_ops = {
     61        .set_clip_rect = console_gc_set_clip_rect,
    6062        .set_color = console_gc_set_color,
    6163        .fill_rect = console_gc_fill_rect,
     
    6769};
    6870
     71/** Set clipping rectangle on console GC.
     72 *
     73 * @param arg Console GC
     74 * @param rect Rectangle
     75 *
     76 * @return EOK on success or an error code
     77 */
     78static errno_t console_gc_set_clip_rect(void *arg, gfx_rect_t *rect)
     79{
     80        console_gc_t *cgc = (console_gc_t *) arg;
     81
     82        if (rect != NULL)
     83                gfx_rect_clip(rect, &cgc->rect, &cgc->clip_rect);
     84        else
     85                cgc->clip_rect = cgc->rect;
     86
     87        return EOK;
     88}
     89
    6990/** Set color on console GC.
    7091 *
     
    100121
    101122        /* Make sure rectangle is clipped and sorted */
    102         gfx_rect_clip(rect, &cgc->rect, &crect);
     123        gfx_rect_clip(rect, &cgc->clip_rect, &crect);
    103124
    104125        cols = cgc->rect.p1.x - cgc->rect.p0.x;
     
    188209        cgc->rect.p1.x = cols;
    189210        cgc->rect.p1.y = rows;
     211        cgc->clip_rect = cgc->rect;
    190212        cgc->buf = buf;
    191213
     
    330352
    331353        gfx_rect_translate(&offs, &srect, &drect);
    332         gfx_rect_clip(&drect, &cbm->cgc->rect, &crect);
     354        gfx_rect_clip(&drect, &cbm->cgc->clip_rect, &crect);
    333355
    334356        pixelmap.width = cbm->rect.p1.x - cbm->rect.p0.x;
  • uspace/lib/gfx/include/gfx/render.h

    r252d03c r7470d97  
    4242#include <types/gfx/context.h>
    4343
     44extern errno_t gfx_set_clip_rect(gfx_context_t *, gfx_rect_t *);
    4445extern errno_t gfx_set_color(gfx_context_t *, gfx_color_t *);
    4546extern errno_t gfx_fill_rect(gfx_context_t *, gfx_rect_t *);
  • uspace/lib/gfx/include/types/gfx/ops/context.h

    r252d03c r7470d97  
    4747/** Graphics context ops */
    4848typedef struct {
     49        /** Set clipping rectangle */
     50        errno_t (*set_clip_rect)(void *, gfx_rect_t *);
    4951        /** Set drawing color */
    5052        errno_t (*set_color)(void *, gfx_color_t *);
  • uspace/lib/gfx/src/render.c

    r252d03c r7470d97  
    3636#include <gfx/render.h>
    3737#include "../private/context.h"
     38
     39/** Set clipping rectangle.
     40 *
     41 * @param gc Graphic context
     42 * @param rect Rectangle or @c NULL (no extra clipping)
     43 *
     44 * @return EOK on success, ENOMEM if insufficient resources,
     45 *         EIO if grahic device connection was lost
     46 */
     47errno_t gfx_set_clip_rect(gfx_context_t *gc, gfx_rect_t *rect)
     48{
     49        return gc->ops->set_clip_rect(gc->arg, rect);
     50}
    3851
    3952/** Set drawing color.
  • uspace/lib/gfx/test/render.c

    r252d03c r7470d97  
    3838PCUT_TEST_SUITE(render);
    3939
     40static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    4041static errno_t testgc_set_color(void *, gfx_color_t *);
    4142static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     
    4344
    4445static gfx_context_ops_t ops = {
     46        .set_clip_rect = testgc_set_clip_rect,
    4547        .set_color = testgc_set_color,
    4648        .fill_rect = testgc_fill_rect,
     
    5052/** Test graphics context data */
    5153typedef struct {
     54        errno_t rc;
     55
     56        bool set_clip_rect;
     57        gfx_rect_t crect;
     58        bool do_clip;
     59
     60        bool set_color;
    5261        gfx_color_t *dclr;
    53         gfx_rect_t *rect;
    54         bool updated;
     62
     63        bool fill_rect;
     64        gfx_rect_t frect;
     65
     66        bool update;
    5567} test_gc_t;
    5668
     69/** Set clipping rectangle */
     70PCUT_TEST(set_clip_rect)
     71{
     72        errno_t rc;
     73        gfx_rect_t rect;
     74        gfx_context_t *gc = NULL;
     75        test_gc_t tgc;
     76
     77        memset(&tgc, 0, sizeof(tgc));
     78
     79        rc = gfx_context_new(&ops, &tgc, &gc);
     80        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     81
     82        rect.p0.x = 1;
     83        rect.p0.y = 2;
     84        rect.p1.x = 3;
     85        rect.p1.y = 4;
     86
     87        tgc.rc = EOK;
     88
     89        rc = gfx_set_clip_rect(gc, &rect);
     90        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     91
     92        PCUT_ASSERT_TRUE(tgc.set_clip_rect);
     93        PCUT_ASSERT_TRUE(tgc.do_clip);
     94        PCUT_ASSERT_INT_EQUALS(rect.p0.x, tgc.crect.p0.x);
     95        PCUT_ASSERT_INT_EQUALS(rect.p0.y, tgc.crect.p0.y);
     96        PCUT_ASSERT_INT_EQUALS(rect.p1.x, tgc.crect.p1.x);
     97        PCUT_ASSERT_INT_EQUALS(rect.p1.y, tgc.crect.p1.y);
     98
     99        rc = gfx_context_delete(gc);
     100        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     101}
     102
     103/** Set null clipping rectangle */
     104PCUT_TEST(set_clip_rect_null)
     105{
     106        errno_t rc;
     107        gfx_context_t *gc = NULL;
     108        test_gc_t tgc;
     109
     110        memset(&tgc, 0, sizeof(tgc));
     111
     112        rc = gfx_context_new(&ops, &tgc, &gc);
     113        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     114
     115        tgc.rc = EOK;
     116
     117        rc = gfx_set_clip_rect(gc, NULL);
     118        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     119
     120        PCUT_ASSERT_TRUE(tgc.set_clip_rect);
     121        PCUT_ASSERT_FALSE(tgc.do_clip);
     122
     123        rc = gfx_context_delete(gc);
     124        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     125}
     126
     127/** Set clipping rectangle with error return */
     128PCUT_TEST(set_clip_rect_failure)
     129{
     130        errno_t rc;
     131        gfx_rect_t rect;
     132        gfx_context_t *gc = NULL;
     133        test_gc_t tgc;
     134
     135        memset(&tgc, 0, sizeof(tgc));
     136
     137        rc = gfx_context_new(&ops, &tgc, &gc);
     138        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     139
     140        tgc.rc = EIO;
     141
     142        rc = gfx_set_clip_rect(gc, &rect);
     143        PCUT_ASSERT_ERRNO_VAL(EIO, rc);
     144
     145        rc = gfx_context_delete(gc);
     146        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     147}
     148
     149/** Set drawing color */
    57150PCUT_TEST(set_color)
    58151{
     
    60153        gfx_color_t *color;
    61154        gfx_context_t *gc = NULL;
     155        uint16_t r, g, b;
    62156        test_gc_t tgc;
    63157
     
    70164        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    71165
     166        PCUT_ASSERT_FALSE(tgc.set_color);
     167
     168        tgc.rc = EOK;
     169
    72170        rc = gfx_set_color(gc, color);
    73171        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    74         PCUT_ASSERT_EQUALS(color, tgc.dclr);
    75         PCUT_ASSERT_NULL(tgc.rect);
     172
     173        PCUT_ASSERT_TRUE(tgc.set_color);
     174
     175        gfx_color_get_rgb_i16(tgc.dclr, &r, &g, &b);
     176
     177        PCUT_ASSERT_INT_EQUALS(0xffff, r);
     178        PCUT_ASSERT_INT_EQUALS(0xffff, g);
     179        PCUT_ASSERT_INT_EQUALS(0xffff, b);
     180
     181        rc = gfx_context_delete(gc);
     182        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     183}
     184
     185/** Set drawing color with error return */
     186PCUT_TEST(set_color_failure)
     187{
     188        errno_t rc;
     189        gfx_color_t *color;
     190        gfx_context_t *gc = NULL;
     191        test_gc_t tgc;
     192
     193        memset(&tgc, 0, sizeof(tgc));
     194
     195        rc = gfx_context_new(&ops, &tgc, &gc);
     196        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     197
     198        rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
     199        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     200
     201        PCUT_ASSERT_FALSE(tgc.set_color);
     202
     203        tgc.rc = EIO;
     204
     205        rc = gfx_set_color(gc, color);
     206        PCUT_ASSERT_ERRNO_VAL(EIO, rc);
    76207
    77208        gfx_color_delete(color);
     
    81212}
    82213
     214/** Fill rectangle */
    83215PCUT_TEST(fill_rect)
    84216{
    85217        errno_t rc;
    86         gfx_color_t *color;
    87218        gfx_rect_t rect;
    88219        gfx_context_t *gc = NULL;
     
    94225        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    95226
    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);
    101         PCUT_ASSERT_EQUALS(color, tgc.dclr);
     227        rect.p0.x = 1;
     228        rect.p0.y = 2;
     229        rect.p1.x = 3;
     230        rect.p1.y = 4;
     231
     232        PCUT_ASSERT_FALSE(tgc.fill_rect);
     233
     234        tgc.rc = EOK;
    102235
    103236        rc = gfx_fill_rect(gc, &rect);
    104237        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    105         PCUT_ASSERT_EQUALS(&rect, tgc.rect);
    106 
    107         gfx_color_delete(color);
    108 
    109         rc = gfx_context_delete(gc);
    110         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    111 }
    112 
     238
     239        PCUT_ASSERT_TRUE(tgc.fill_rect);
     240        PCUT_ASSERT_INT_EQUALS(rect.p0.x, tgc.frect.p0.x);
     241        PCUT_ASSERT_INT_EQUALS(rect.p0.y, tgc.frect.p0.y);
     242        PCUT_ASSERT_INT_EQUALS(rect.p1.x, tgc.frect.p1.x);
     243        PCUT_ASSERT_INT_EQUALS(rect.p1.y, tgc.frect.p1.y);
     244
     245        rc = gfx_context_delete(gc);
     246        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     247}
     248
     249/** Fill rectangle with error return */
     250PCUT_TEST(fill_rect_failure)
     251{
     252        errno_t rc;
     253        gfx_rect_t rect;
     254        gfx_context_t *gc = NULL;
     255        test_gc_t tgc;
     256
     257        memset(&tgc, 0, sizeof(tgc));
     258
     259        rc = gfx_context_new(&ops, &tgc, &gc);
     260        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     261
     262        rect.p0.x = 1;
     263        rect.p0.y = 2;
     264        rect.p1.x = 3;
     265        rect.p1.y = 4;
     266
     267        PCUT_ASSERT_FALSE(tgc.fill_rect);
     268
     269        tgc.rc = EIO;
     270
     271        rc = gfx_fill_rect(gc, &rect);
     272        PCUT_ASSERT_ERRNO_VAL(EIO, rc);
     273
     274        rc = gfx_context_delete(gc);
     275        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     276}
     277
     278/** Update GC */
    113279PCUT_TEST(update)
    114280{
     
    122288        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    123289
    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);
     290        tgc.rc = EOK;
     291
     292        PCUT_ASSERT_FALSE(tgc.update);
     293        rc = gfx_update(gc);
     294        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     295        PCUT_ASSERT_TRUE(tgc.update);
     296
     297        rc = gfx_context_delete(gc);
     298        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     299}
     300
     301/** Update GC with error return */
     302PCUT_TEST(update_failure)
     303{
     304        errno_t rc;
     305        gfx_context_t *gc = NULL;
     306        test_gc_t tgc;
     307
     308        memset(&tgc, 0, sizeof(tgc));
     309
     310        rc = gfx_context_new(&ops, &tgc, &gc);
     311        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     312
     313        tgc.rc = EIO;
     314        rc = gfx_update(gc);
     315
     316        PCUT_ASSERT_ERRNO_VAL(EIO, rc);
     317
     318        rc = gfx_context_delete(gc);
     319        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     320}
     321
     322static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     323{
     324        test_gc_t *tgc = (test_gc_t *) arg;
     325
     326        tgc->set_clip_rect = true;
     327        if (rect != NULL) {
     328                tgc->do_clip = true;
     329                tgc->crect = *rect;
     330        } else {
     331                tgc->do_clip = false;
     332        }
     333
     334        return tgc->rc;
    130335}
    131336
     
    133338{
    134339        test_gc_t *tgc = (test_gc_t *) arg;
     340
     341        tgc->set_color = true;
    135342
    136343        /* Technically we should copy the data */
    137344        tgc->dclr = color;
    138         return EOK;
     345        return tgc->rc;
    139346}
    140347
     
    143350        test_gc_t *tgc = (test_gc_t *) arg;
    144351
    145         /* Technically we should copy the data */
    146         tgc->rect = rect;
    147         return EOK;
     352        tgc->fill_rect = true;
     353        tgc->frect = *rect;
     354        return tgc->rc;
    148355}
    149356
     
    152359        test_gc_t *tgc = (test_gc_t *) arg;
    153360
    154         tgc->updated = true;
    155         return EOK;
     361        tgc->update = true;
     362        return tgc->rc;
    156363}
    157364
  • uspace/lib/gfxfont/test/font.c

    r252d03c r7470d97  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3939PCUT_TEST_SUITE(font);
    4040
     41static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    4142static errno_t testgc_set_color(void *, gfx_color_t *);
    4243static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     
    4849
    4950static gfx_context_ops_t test_ops = {
     51        .set_clip_rect = testgc_set_clip_rect,
    5052        .set_color = testgc_set_color,
    5153        .fill_rect = testgc_fill_rect,
     
    568570                }
    569571        }
     572}
     573
     574static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     575{
     576        return EOK;
    570577}
    571578
  • uspace/lib/gfxfont/test/glyph.c

    r252d03c r7470d97  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4343PCUT_TEST_SUITE(glyph);
    4444
     45static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    4546static errno_t testgc_set_color(void *, gfx_color_t *);
    4647static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     
    5253
    5354static gfx_context_ops_t test_ops = {
     55        .set_clip_rect = testgc_set_clip_rect,
    5456        .set_color = testgc_set_color,
    5557        .fill_rect = testgc_fill_rect,
     
    567569        rc = gfx_context_delete(gc);
    568570        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     571}
     572
     573static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     574{
     575        return EOK;
    569576}
    570577
  • uspace/lib/gfxfont/test/glyph_bmp.c

    r252d03c r7470d97  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3939PCUT_TEST_SUITE(glyph_bmp);
    4040
     41static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    4142static errno_t testgc_set_color(void *, gfx_color_t *);
    4243static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     
    4849
    4950static gfx_context_ops_t test_ops = {
     51        .set_clip_rect = testgc_set_clip_rect,
    5052        .set_color = testgc_set_color,
    5153        .fill_rect = testgc_fill_rect,
     
    581583        rc = gfx_context_delete(gc);
    582584        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     585}
     586
     587static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     588{
     589        return EOK;
    583590}
    584591
  • uspace/lib/gfxfont/test/text.c

    r252d03c r7470d97  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4040PCUT_TEST_SUITE(text);
    4141
     42static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    4243static errno_t testgc_set_color(void *, gfx_color_t *);
    4344static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     
    4950
    5051static gfx_context_ops_t test_ops = {
     52        .set_clip_rect = testgc_set_clip_rect,
    5153        .set_color = testgc_set_color,
    5254        .fill_rect = testgc_fill_rect,
     
    145147        rc = gfx_context_delete(gc);
    146148        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     149}
     150
     151static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     152{
     153        return EOK;
    147154}
    148155
  • uspace/lib/gfxfont/test/tpf.c

    r252d03c r7470d97  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4141PCUT_TEST_SUITE(tpf);
    4242
     43static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    4344static errno_t testgc_set_color(void *, gfx_color_t *);
    4445static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     
    5051
    5152static gfx_context_ops_t test_ops = {
     53        .set_clip_rect = testgc_set_clip_rect,
    5254        .set_color = testgc_set_color,
    5355        .fill_rect = testgc_fill_rect,
     
    208210}
    209211
     212static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     213{
     214        return EOK;
     215}
     216
    210217static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    211218{
  • uspace/lib/gfxfont/test/typeface.c

    r252d03c r7470d97  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3737PCUT_TEST_SUITE(typeface);
    3838
     39static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    3940static errno_t testgc_set_color(void *, gfx_color_t *);
    4041static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     
    4647
    4748static gfx_context_ops_t test_ops = {
     49        .set_clip_rect = testgc_set_clip_rect,
    4850        .set_color = testgc_set_color,
    4951        .fill_rect = testgc_fill_rect,
     
    9496{
    9597        // TODO
     98}
     99
     100static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     101{
     102        return EOK;
    96103}
    97104
  • uspace/lib/ipcgfx/include/ipcgfx/ipc/gc.h

    r252d03c r7470d97  
    3939
    4040typedef enum {
    41         GC_SET_RGB_COLOR = IPC_FIRST_USER_METHOD,
     41        GC_SET_CLIP_RECT = IPC_FIRST_USER_METHOD,
     42        GC_SET_CLIP_RECT_NULL,
     43        GC_SET_RGB_COLOR,
    4244        GC_FILL_RECT,
    4345        GC_UPDATE,
  • uspace/lib/ipcgfx/src/client.c

    r252d03c r7470d97  
    4545#include "../private/client.h"
    4646
     47static errno_t ipc_gc_set_clip_rect(void *, gfx_rect_t *);
    4748static errno_t ipc_gc_set_color(void *, gfx_color_t *);
    4849static errno_t ipc_gc_fill_rect(void *, gfx_rect_t *);
     
    5556
    5657gfx_context_ops_t ipc_gc_ops = {
     58        .set_clip_rect = ipc_gc_set_clip_rect,
    5759        .set_color = ipc_gc_set_color,
    5860        .fill_rect = ipc_gc_fill_rect,
     
    6365        .bitmap_get_alloc = ipc_gc_bitmap_get_alloc
    6466};
     67
     68/** Set clipping rectangle on IPC GC.
     69 *
     70 * @param arg IPC GC
     71 * @param rect Rectangle
     72 *
     73 * @return EOK on success or an error code
     74 */
     75static errno_t ipc_gc_set_clip_rect(void *arg, gfx_rect_t *rect)
     76{
     77        ipc_gc_t *ipcgc = (ipc_gc_t *) arg;
     78        async_exch_t *exch;
     79        errno_t rc;
     80
     81        exch = async_exchange_begin(ipcgc->sess);
     82        if (rect != NULL) {
     83                rc = async_req_4_0(exch, GC_SET_CLIP_RECT, rect->p0.x, rect->p0.y,
     84                    rect->p1.x, rect->p1.y);
     85        } else {
     86                rc = async_req_0_0(exch, GC_SET_CLIP_RECT_NULL);
     87        }
     88
     89        async_exchange_end(exch);
     90
     91        return rc;
     92}
    6593
    6694/** Set color on IPC GC.
  • uspace/lib/ipcgfx/src/server.c

    r252d03c r7470d97  
    5252static ipc_gc_srv_bitmap_t *gc_bitmap_lookup(ipc_gc_srv_t *, sysarg_t);
    5353
     54static void gc_set_clip_rect_srv(ipc_gc_srv_t *srvgc, ipc_call_t *call)
     55{
     56        gfx_rect_t rect;
     57        errno_t rc;
     58
     59        rect.p0.x = ipc_get_arg1(call);
     60        rect.p0.y = ipc_get_arg2(call);
     61        rect.p1.x = ipc_get_arg3(call);
     62        rect.p1.y = ipc_get_arg4(call);
     63
     64        rc = gfx_set_clip_rect(srvgc->gc, &rect);
     65        async_answer_0(call, rc);
     66}
     67
     68static void gc_set_clip_rect_null_srv(ipc_gc_srv_t *srvgc, ipc_call_t *call)
     69{
     70        errno_t rc;
     71
     72        rc = gfx_set_clip_rect(srvgc->gc, NULL);
     73        async_answer_0(call, rc);
     74}
     75
    5476static void gc_set_rgb_color_srv(ipc_gc_srv_t *srvgc, ipc_call_t *call)
    5577{
     
    361383
    362384                switch (method) {
     385                case GC_SET_CLIP_RECT:
     386                        gc_set_clip_rect_srv(&srvgc, &call);
     387                        break;
     388                case GC_SET_CLIP_RECT_NULL:
     389                        gc_set_clip_rect_null_srv(&srvgc, &call);
     390                        break;
    363391                case GC_SET_RGB_COLOR:
    364392                        gc_set_rgb_color_srv(&srvgc, &call);
  • uspace/lib/ipcgfx/test/ipcgfx.c

    r252d03c r7470d97  
    5050static void test_ipcgc_conn(ipc_call_t *, void *);
    5151
     52static errno_t test_gc_set_clip_rect(void *, gfx_rect_t *);
    5253static errno_t test_gc_set_color(void *, gfx_color_t *);
    5354static errno_t test_gc_fill_rect(void *, gfx_rect_t *);
     
    6061
    6162static gfx_context_ops_t test_gc_ops = {
     63        .set_clip_rect = test_gc_set_clip_rect,
    6264        .set_color = test_gc_set_color,
    6365        .fill_rect = test_gc_fill_rect,
     
    7577        errno_t rc;
    7678
     79        bool set_clip_rect_called;
     80        bool do_clip;
     81        gfx_rect_t set_clip_rect_rect;
     82
    7783        bool set_color_called;
    7884        uint16_t set_color_r;
     
    103109        gfx_bitmap_alloc_t alloc;
    104110} test_bitmap_t;
     111
     112/** gfx_set_clip_rect with server returning failure */
     113PCUT_TEST(set_clip_rect_failure)
     114{
     115        errno_t rc;
     116        service_id_t sid;
     117        test_response_t resp;
     118        gfx_context_t *gc;
     119        gfx_rect_t rect;
     120        async_sess_t *sess;
     121        ipc_gc_t *ipcgc;
     122
     123        async_set_fallback_port_handler(test_ipcgc_conn, &resp);
     124
     125        // FIXME This causes this test to be non-reentrant!
     126        rc = loc_server_register(test_ipcgfx_server);
     127        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     128
     129        rc = loc_service_register(test_ipcgfx_svc, &sid);
     130        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     131
     132        sess = loc_service_connect(sid, INTERFACE_GC, 0);
     133        PCUT_ASSERT_NOT_NULL(sess);
     134
     135        rc = ipc_gc_create(sess, &ipcgc);
     136        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     137
     138        gc = ipc_gc_get_ctx(ipcgc);
     139        PCUT_ASSERT_NOT_NULL(gc);
     140
     141        resp.rc = ENOMEM;
     142        resp.set_clip_rect_called = false;
     143        rect.p0.x = 1;
     144        rect.p0.y = 2;
     145        rect.p1.x = 3;
     146        rect.p1.y = 4;
     147        rc = gfx_set_clip_rect(gc, &rect);
     148        PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
     149        PCUT_ASSERT_TRUE(resp.set_clip_rect_called);
     150        PCUT_ASSERT_EQUALS(rect.p0.x, resp.set_clip_rect_rect.p0.x);
     151        PCUT_ASSERT_EQUALS(rect.p0.y, resp.set_clip_rect_rect.p0.y);
     152        PCUT_ASSERT_EQUALS(rect.p1.x, resp.set_clip_rect_rect.p1.x);
     153        PCUT_ASSERT_EQUALS(rect.p1.y, resp.set_clip_rect_rect.p1.y);
     154
     155        ipc_gc_delete(ipcgc);
     156        async_hangup(sess);
     157
     158        rc = loc_service_unregister(sid);
     159        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     160}
     161
     162/** gfx_set_clip_rect with server returning success */
     163PCUT_TEST(set_clip_rect_success)
     164{
     165        errno_t rc;
     166        service_id_t sid;
     167        test_response_t resp;
     168        gfx_context_t *gc;
     169        gfx_rect_t rect;
     170        async_sess_t *sess;
     171        ipc_gc_t *ipcgc;
     172
     173        async_set_fallback_port_handler(test_ipcgc_conn, &resp);
     174
     175        // FIXME This causes this test to be non-reentrant!
     176        rc = loc_server_register(test_ipcgfx_server);
     177        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     178
     179        rc = loc_service_register(test_ipcgfx_svc, &sid);
     180        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     181
     182        sess = loc_service_connect(sid, INTERFACE_GC, 0);
     183        PCUT_ASSERT_NOT_NULL(sess);
     184
     185        rc = ipc_gc_create(sess, &ipcgc);
     186        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     187
     188        gc = ipc_gc_get_ctx(ipcgc);
     189        PCUT_ASSERT_NOT_NULL(gc);
     190
     191        resp.rc = EOK;
     192        resp.set_clip_rect_called = false;
     193        rect.p0.x = 1;
     194        rect.p0.y = 2;
     195        rect.p1.x = 3;
     196        rect.p1.y = 4;
     197        rc = gfx_set_clip_rect(gc, &rect);
     198        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     199        PCUT_ASSERT_TRUE(resp.set_clip_rect_called);
     200        PCUT_ASSERT_TRUE(resp.do_clip);
     201        PCUT_ASSERT_EQUALS(rect.p0.x, resp.set_clip_rect_rect.p0.x);
     202        PCUT_ASSERT_EQUALS(rect.p0.y, resp.set_clip_rect_rect.p0.y);
     203        PCUT_ASSERT_EQUALS(rect.p1.x, resp.set_clip_rect_rect.p1.x);
     204        PCUT_ASSERT_EQUALS(rect.p1.y, resp.set_clip_rect_rect.p1.y);
     205
     206        ipc_gc_delete(ipcgc);
     207        async_hangup(sess);
     208
     209        rc = loc_service_unregister(sid);
     210        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     211}
     212
     213/** gfx_set_clip_rect with null rectangle, server returning success */
     214PCUT_TEST(set_clip_rect_null_success)
     215{
     216        errno_t rc;
     217        service_id_t sid;
     218        test_response_t resp;
     219        gfx_context_t *gc;
     220        async_sess_t *sess;
     221        ipc_gc_t *ipcgc;
     222
     223        async_set_fallback_port_handler(test_ipcgc_conn, &resp);
     224
     225        // FIXME This causes this test to be non-reentrant!
     226        rc = loc_server_register(test_ipcgfx_server);
     227        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     228
     229        rc = loc_service_register(test_ipcgfx_svc, &sid);
     230        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     231
     232        sess = loc_service_connect(sid, INTERFACE_GC, 0);
     233        PCUT_ASSERT_NOT_NULL(sess);
     234
     235        rc = ipc_gc_create(sess, &ipcgc);
     236        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     237
     238        gc = ipc_gc_get_ctx(ipcgc);
     239        PCUT_ASSERT_NOT_NULL(gc);
     240
     241        resp.rc = EOK;
     242        resp.set_clip_rect_called = false;
     243
     244        rc = gfx_set_clip_rect(gc, NULL);
     245        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     246        PCUT_ASSERT_TRUE(resp.set_clip_rect_called);
     247        PCUT_ASSERT_FALSE(resp.do_clip);
     248
     249        ipc_gc_delete(ipcgc);
     250        async_hangup(sess);
     251
     252        rc = loc_service_unregister(sid);
     253        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     254}
    105255
    106256/** gfx_set_color with server returning failure */
     
    234384
    235385        resp.rc = ENOMEM;
    236         resp.set_color_called = false;
     386        resp.fill_rect_called = false;
    237387        rect.p0.x = 1;
    238388        rect.p0.y = 2;
     
    284434
    285435        resp.rc = EOK;
    286         resp.set_color_called = false;
     436        resp.fill_rect_called = false;
    287437        rect.p0.x = 1;
    288438        rect.p0.y = 2;
     
    8981048}
    8991049
     1050/** Set clipping rectangle in test GC.
     1051 *
     1052 * @param arg Test GC
     1053 * @param rect Rectangle
     1054 *
     1055 * @return EOK on success or an error code
     1056 */
     1057static errno_t test_gc_set_clip_rect(void *arg, gfx_rect_t *rect)
     1058{
     1059        test_response_t *resp = (test_response_t *) arg;
     1060
     1061        resp->set_clip_rect_called = true;
     1062        if (rect != NULL) {
     1063                resp->do_clip = true;
     1064                resp->set_clip_rect_rect = *rect;
     1065        } else {
     1066                resp->do_clip = false;
     1067        }
     1068
     1069        return resp->rc;
     1070}
     1071
    9001072/** Set color in test GC.
    9011073 *
  • uspace/lib/memgfx/private/memgc.h

    r252d03c r7470d97  
    4949        /** Bounding rectangle */
    5050        gfx_rect_t rect;
     51        /** Clipping rectangle */
     52        gfx_rect_t clip_rect;
    5153        /** Allocation info */
    5254        gfx_bitmap_alloc_t alloc;
  • uspace/lib/memgfx/src/memgc.c

    r252d03c r7470d97  
    4848#include "../private/memgc.h"
    4949
     50static errno_t mem_gc_set_clip_rect(void *, gfx_rect_t *);
    5051static errno_t mem_gc_set_color(void *, gfx_color_t *);
    5152static errno_t mem_gc_fill_rect(void *, gfx_rect_t *);
     
    5960
    6061gfx_context_ops_t mem_gc_ops = {
     62        .set_clip_rect = mem_gc_set_clip_rect,
    6163        .set_color = mem_gc_set_color,
    6264        .fill_rect = mem_gc_fill_rect,
     
    6870};
    6971
     72/** Set clipping rectangle on memory GC.
     73 *
     74 * @param arg Memory GC
     75 * @param rect Rectangle
     76 *
     77 * @return EOK on success or an error code
     78 */
     79static errno_t mem_gc_set_clip_rect(void *arg, gfx_rect_t *rect)
     80{
     81        mem_gc_t *mgc = (mem_gc_t *) arg;
     82
     83        if (rect != NULL)
     84                gfx_rect_clip(rect, &mgc->rect, &mgc->clip_rect);
     85        else
     86                mgc->clip_rect = mgc->rect;
     87
     88        return EOK;
     89}
     90
    7091/** Set color on memory GC.
    7192 *
     
    102123
    103124        /* Make sure we have a sorted, clipped rectangle */
    104         gfx_rect_clip(rect, &mgc->rect, &crect);
     125        gfx_rect_clip(rect, &mgc->clip_rect, &crect);
    105126
    106127        assert(mgc->rect.p0.x == 0);
     
    167188        mgc->gc = gc;
    168189        mgc->rect = *rect;
     190        mgc->clip_rect = *rect;
    169191        mgc->alloc = *alloc;
    170192
     
    208230{
    209231        mgc->rect = *rect;
     232        mgc->clip_rect = *rect;
    210233        mgc->alloc = *alloc;
    211234}
     
    370393        gfx_rect_translate(&offs, &srect, &drect);
    371394
     395        /* XXX Clip destination rectangle?! */
     396
    372397        assert(mbm->alloc.pitch == (mbm->rect.p1.x - mbm->rect.p0.x) *
    373398            (int)sizeof(uint32_t));
  • uspace/lib/ui/src/dummygc.c

    r252d03c r7470d97  
    4141#include "../private/dummygc.h"
    4242
     43static errno_t dummygc_set_clip_rect(void *, gfx_rect_t *);
    4344static errno_t dummygc_set_color(void *, gfx_color_t *);
    4445static errno_t dummygc_fill_rect(void *, gfx_rect_t *);
     
    5253/** Dummy GC operations */
    5354gfx_context_ops_t dummygc_ops = {
     55        .set_clip_rect = dummygc_set_clip_rect,
    5456        .set_color = dummygc_set_color,
    5557        .fill_rect = dummygc_fill_rect,
     
    105107{
    106108        return dgc->gc;
     109}
     110
     111/** Set clipping rectangle on dummy GC
     112 *
     113 * @param arg Argument (dummy_gc_t)
     114 * @param rect Rectangle
     115 * @return EOK on success or an error code
     116 */
     117static errno_t dummygc_set_clip_rect(void *arg, gfx_rect_t *rect)
     118{
     119        (void) arg;
     120        (void) rect;
     121        return EOK;
    107122}
    108123
  • uspace/lib/ui/test/checkbox.c

    r252d03c r7470d97  
    4141PCUT_TEST_SUITE(checkbox);
    4242
     43static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    4344static errno_t testgc_set_color(void *, gfx_color_t *);
    4445static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     
    5152
    5253static gfx_context_ops_t ops = {
     54        .set_clip_rect = testgc_set_clip_rect,
    5355        .set_color = testgc_set_color,
    5456        .fill_rect = testgc_fill_rect,
     
    481483        rc = gfx_context_delete(gc);
    482484        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     485}
     486
     487static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     488{
     489        (void) arg;
     490        (void) rect;
     491        return EOK;
    483492}
    484493
  • uspace/lib/ui/test/entry.c

    r252d03c r7470d97  
    4141PCUT_TEST_SUITE(entry);
    4242
     43static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    4344static errno_t testgc_set_color(void *, gfx_color_t *);
    4445static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     
    5152
    5253static gfx_context_ops_t ops = {
     54        .set_clip_rect = testgc_set_clip_rect,
    5355        .set_color = testgc_set_color,
    5456        .fill_rect = testgc_fill_rect,
     
    209211        rc = gfx_context_delete(gc);
    210212        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     213}
     214
     215static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     216{
     217        (void) arg;
     218        (void) rect;
     219        return EOK;
    211220}
    212221
  • uspace/lib/ui/test/label.c

    r252d03c r7470d97  
    4141PCUT_TEST_SUITE(label);
    4242
     43static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    4344static errno_t testgc_set_color(void *, gfx_color_t *);
    4445static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     
    5152
    5253static gfx_context_ops_t ops = {
     54        .set_clip_rect = testgc_set_clip_rect,
    5355        .set_color = testgc_set_color,
    5456        .fill_rect = testgc_fill_rect,
     
    209211        rc = gfx_context_delete(gc);
    210212        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     213}
     214
     215static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     216{
     217        (void) arg;
     218        (void) rect;
     219        return EOK;
    211220}
    212221
  • uspace/lib/ui/test/paint.c

    r252d03c r7470d97  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3939PCUT_TEST_SUITE(paint);
    4040
     41static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    4142static errno_t testgc_set_color(void *, gfx_color_t *);
    4243static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     
    4849
    4950static gfx_context_ops_t ops = {
     51        .set_clip_rect = testgc_set_clip_rect,
    5052        .set_color = testgc_set_color,
    5153        .fill_rect = testgc_fill_rect,
     
    165167        rc = gfx_context_delete(gc);
    166168        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     169}
     170
     171static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     172{
     173        (void) arg;
     174        (void) rect;
     175        return EOK;
    167176}
    168177
  • uspace/lib/ui/test/pbutton.c

    r252d03c r7470d97  
    4141PCUT_TEST_SUITE(pbutton);
    4242
     43static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    4344static errno_t testgc_set_color(void *, gfx_color_t *);
    4445static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     
    5152
    5253static gfx_context_ops_t ops = {
     54        .set_clip_rect = testgc_set_clip_rect,
    5355        .set_color = testgc_set_color,
    5456        .fill_rect = testgc_fill_rect,
     
    488490        rc = gfx_context_delete(gc);
    489491        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     492}
     493
     494static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     495{
     496        (void) arg;
     497        (void) rect;
     498        return EOK;
    490499}
    491500
  • uspace/lib/ui/test/rbutton.c

    r252d03c r7470d97  
    4141PCUT_TEST_SUITE(rbutton);
    4242
     43static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    4344static errno_t testgc_set_color(void *, gfx_color_t *);
    4445static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     
    5152
    5253static gfx_context_ops_t ops = {
     54        .set_clip_rect = testgc_set_clip_rect,
    5355        .set_color = testgc_set_color,
    5456        .fill_rect = testgc_fill_rect,
     
    553555        rc = gfx_context_delete(gc);
    554556        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     557}
     558
     559static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     560{
     561        (void) arg;
     562        (void) rect;
     563        return EOK;
    555564}
    556565
  • uspace/lib/ui/test/slider.c

    r252d03c r7470d97  
    4141PCUT_TEST_SUITE(slider);
    4242
     43static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    4344static errno_t testgc_set_color(void *, gfx_color_t *);
    4445static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     
    5152
    5253static gfx_context_ops_t ops = {
     54        .set_clip_rect = testgc_set_clip_rect,
    5355        .set_color = testgc_set_color,
    5456        .fill_rect = testgc_fill_rect,
     
    428430        rc = gfx_context_delete(gc);
    429431        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     432}
     433
     434static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     435{
     436        (void) arg;
     437        (void) rect;
     438        return EOK;
    430439}
    431440
  • uspace/lib/ui/test/wdecor.c

    r252d03c r7470d97  
    4141PCUT_TEST_SUITE(wdecor);
    4242
     43static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    4344static errno_t testgc_set_color(void *, gfx_color_t *);
    4445static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     
    5152
    5253static gfx_context_ops_t ops = {
     54        .set_clip_rect = testgc_set_clip_rect,
    5355        .set_color = testgc_set_color,
    5456        .fill_rect = testgc_fill_rect,
     
    845847}
    846848
     849static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     850{
     851        (void) arg;
     852        (void) rect;
     853        return EOK;
     854}
     855
    847856static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    848857{
  • uspace/srv/hid/display/clonegc.c

    r252d03c r7470d97  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4444#include "clonegc.h"
    4545
     46static errno_t ds_clonegc_set_clip_rect(void *, gfx_rect_t *);
    4647static errno_t ds_clonegc_set_color(void *, gfx_color_t *);
    4748static errno_t ds_clonegc_fill_rect(void *, gfx_rect_t *);
     
    6566
    6667gfx_context_ops_t ds_clonegc_ops = {
     68        .set_clip_rect = ds_clonegc_set_clip_rect,
    6769        .set_color = ds_clonegc_set_color,
    6870        .fill_rect = ds_clonegc_fill_rect,
     
    7375};
    7476
     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 */
     84static 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
    75102/** Set color on clone GC.
    76103 *
  • uspace/srv/hid/display/test/clonegc.c

    r252d03c r7470d97  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3939PCUT_TEST_SUITE(clonegc);
    4040
     41static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    4142static errno_t testgc_set_color(void *, gfx_color_t *);
    4243static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     
    4849
    4950static gfx_context_ops_t ops = {
     51        .set_clip_rect = testgc_set_clip_rect,
    5052        .set_color = testgc_set_color,
    5153        .fill_rect = testgc_fill_rect,
     
    5961        /** Error code to return */
    6062        errno_t rc;
     63
     64        bool set_clip_rect_called;
     65        gfx_rect_t *set_clip_rect_rect;
    6166
    6267        bool set_color_called;
     
    95100        rc = ds_clonegc_create(NULL, &cgc);
    96101        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 */
     108PCUT_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);
    97172
    98173        rc = ds_clonegc_delete(cgc);
     
    628703}
    629704
     705static 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
    630715static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    631716{
  • uspace/srv/hid/rfb/main.c

    r252d03c r7470d97  
    11/*
     2 * Copyright (c) 2021 Jiri Svoboda
    23 * Copyright (c) 2013 Martin Sucha
    34 * All rights reserved.
     
    5051static errno_t rfb_ddev_get_info(void *, ddev_info_t *);
    5152
     53static errno_t rfb_gc_set_clip_rect(void *, gfx_rect_t *);
    5254static errno_t rfb_gc_set_color(void *, gfx_color_t *);
    5355static errno_t rfb_gc_fill_rect(void *, gfx_rect_t *);
     
    6668        rfb_t rfb;
    6769        pixel_t color;
     70        gfx_rect_t rect;
     71        gfx_rect_t clip_rect;
    6872} rfb_gc_t;
    6973
     
    7882
    7983static gfx_context_ops_t rfb_gc_ops = {
     84        .set_clip_rect = rfb_gc_set_clip_rect,
    8085        .set_color = rfb_gc_set_color,
    8186        .fill_rect = rfb_gc_fill_rect,
     
    134139}
    135140
     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 */
     146static 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 */
     162static 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 */
     174static 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
    136186/** Set color on RFB.
    137187 *
     
    163213{
    164214        rfb_gc_t *rfb = (rfb_gc_t *) arg;
     215        gfx_rect_t crect;
    165216        gfx_coord_t x, y;
    166217
    167         // XXX We should handle p0.x > p1.x and p0.y > p1.y
    168 
    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++) {
    171222                        pixelmap_put_pixel(&rfb->rfb.framebuffer, x, y,
    172223                            rfb->color);
     
    174225        }
    175226
    176         rfb_gc_invalidate_rect(rfb, rect);
     227        rfb_gc_invalidate_rect(rfb, &crect);
    177228
    178229        return EOK;
     
    258309        gfx_rect_t srect;
    259310        gfx_rect_t drect;
     311        gfx_rect_t crect;
    260312        gfx_coord2_t offs;
    261313        gfx_coord2_t bmdim;
     
    279331        /* Destination rectangle */
    280332        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);
    282335        gfx_coord2_subtract(&rfbbm->rect.p1, &rfbbm->rect.p0, &bmdim);
    283336
     
    320373        }
    321374
    322         rfb_gc_invalidate_rect(rfbbm->rfb, &drect);
     375        rfb_gc_invalidate_rect(rfbbm->rfb, &crect);
    323376
    324377        return EOK;
     
    346399{
    347400        rfb_t *rfb = (rfb_t *) arg;
     401        rfb_gc_t *rfbgc;
    348402        ddev_srv_t srv;
    349403        sysarg_t svc_id;
     
    362416                ddev_conn(icall, &srv);
    363417        } else {
    364                 rc = gfx_context_new(&rfb_gc_ops, (void *) rfb, &gc);
     418                rc = rgb_gc_create(&rfbgc);
    365419                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);
    366433                        async_answer_0(icall, ENOMEM);
    367434                        return;
Note: See TracChangeset for help on using the changeset viewer.