Changeset 045186b in mainline


Ignore:
Timestamp:
2019-04-15T15:45:04Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9259d20
Parents:
d6dc9a12
Message:

Gfxdemo application stub, Gfx context virtual method dispatch

Files:
6 added
7 edited

Legend:

Unmodified
Added
Removed
  • .gitignore

    rd6dc9a12 r045186b  
    105105uspace/app/fontviewer/fontviewer
    106106uspace/app/getterm/getterm
     107uspace/app/gfxdemo/gfxdemo
    107108uspace/app/gunzip/gunzip
    108109uspace/app/hbench/hbench
     
    386387uspace/lib/c/arch/sparc64/_link.ld
    387388uspace/lib/c/test-libc
     389uspace/lib/gfx/test-libgfx
    388390uspace/lib/label/test-liblabel
    389391uspace/lib/math/test-libmath
  • boot/Makefile.common

    rd6dc9a12 r045186b  
    191191        edit \
    192192        fdisk \
     193        gfxdemo \
    193194        gunzip \
    194195        hbench \
  • uspace/Makefile

    rd6dc9a12 r045186b  
    4949        app/fontviewer \
    5050        app/getterm \
     51        app/gfxdemo \
    5152        app/gunzip \
    5253        app/hbench \
  • uspace/lib/gfx/Makefile

    rd6dc9a12 r045186b  
    3333SOURCES = \
    3434        src/color.c \
     35        src/context.c \
    3536        src/render.c
    3637
  • uspace/lib/gfx/include/gfx/context.h

    rd6dc9a12 r045186b  
    4141#define _GFX_CONTEXT_H
    4242
     43#include <errno.h>
    4344#include <types/gfx/context.h>
     45#include <types/gfx/ops/context.h>
     46
     47extern errno_t gfx_context_new(gfx_context_ops_t *, void *,
     48    gfx_context_t **);
     49extern errno_t gfx_context_delete(gfx_context_t *);
    4450
    4551#endif
  • uspace/lib/gfx/src/render.c

    rd6dc9a12 r045186b  
    3535
    3636#include <gfx/render.h>
     37#include "../private/context.h"
    3738
    3839/** Set drawing color.
     
    4647errno_t gfx_set_color(gfx_context_t *gc, gfx_color_t *color)
    4748{
    48         return EOK;
     49        return gc->ops->set_color(gc->arg, color);
    4950}
    5051
     
    5960errno_t gfx_fill_rect(gfx_context_t *gc, gfx_rect_t *rect)
    6061{
    61         return EOK;
     62        return gc->ops->fill_rect(gc->arg, rect);
    6263}
    6364
  • uspace/lib/gfx/test/render.c

    rd6dc9a12 r045186b  
    2828
    2929#include <gfx/color.h>
     30#include <gfx/context.h>
    3031#include <gfx/render.h>
    3132#include <pcut/pcut.h>
     33#include <mem.h>
    3234
    3335PCUT_INIT;
    3436
    3537PCUT_TEST_SUITE(render);
     38
     39static errno_t testgc_set_color(void *, gfx_color_t *);
     40static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     41
     42static gfx_context_ops_t ops = {
     43        .set_color = testgc_set_color,
     44        .fill_rect = testgc_fill_rect
     45};
     46
     47/** Test graphics context data */
     48typedef struct {
     49        gfx_color_t *dclr;
     50        gfx_rect_t *rect;
     51} test_gc_t;
    3652
    3753PCUT_TEST(set_color)
     
    4056        gfx_color_t *color;
    4157        gfx_context_t *gc = NULL;
     58        test_gc_t tgc;
     59
     60        memset(&tgc, 0, sizeof(tgc));
     61
     62        rc = gfx_context_new(&ops, &tgc, &gc);
     63        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    4264
    4365        rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
     
    4668        rc = gfx_set_color(gc, color);
    4769        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     70        PCUT_ASSERT_EQUALS(color, tgc.dclr);
     71        PCUT_ASSERT_NULL(tgc.rect);
    4872
    4973        gfx_color_delete(color);
     74
     75        rc = gfx_context_delete(gc);
     76        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    5077}
    5178
     
    5683        gfx_rect_t rect;
    5784        gfx_context_t *gc = NULL;
     85        test_gc_t tgc;
     86
     87        memset(&tgc, 0, sizeof(tgc));
     88
     89        rc = gfx_context_new(&ops, &tgc, &gc);
     90        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    5891
    5992        rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
     
    6295        rc = gfx_set_color(gc, color);
    6396        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     97        PCUT_ASSERT_EQUALS(color, tgc.dclr);
    6498
    6599        rc = gfx_fill_rect(gc, &rect);
    66100        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     101        PCUT_ASSERT_EQUALS(&rect, tgc.rect);
    67102
    68103        gfx_color_delete(color);
     104
     105        rc = gfx_context_delete(gc);
     106        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     107}
     108
     109errno_t testgc_set_color(void *arg, gfx_color_t *color)
     110{
     111        test_gc_t *tgc = (test_gc_t *) arg;
     112
     113        /* Technically we should copy the data */
     114        tgc->dclr = color;
     115        return EOK;
     116}
     117
     118errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
     119{
     120        test_gc_t *tgc = (test_gc_t *) arg;
     121
     122        /* Technically we should copy the data */
     123        tgc->rect = rect;
     124        return EOK;
    69125}
    70126
Note: See TracChangeset for help on using the changeset viewer.