From c923d881aa8ecdb04d5f296bc3e6ea5d4dcff289 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Sat, 2 May 2020 10:55:33 +0900 Subject: [PATCH] test: added testUpdate this shows a moving shape: how to update canvas every frames. Change-Id: I373e39757f4511d4e676f36d76e468d03b185a0c --- .gitignore | 1 + inc/tizenvg.h | 1 + src/lib/tvgSwCanvas.cpp | 11 +++++ test/makefile | 1 + test/testUpdate.cpp | 107 ++++++++++++++++++++++++++-------------- 5 files changed, 85 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index c26c55d2..06f90992 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ testBoundary testPath testPathCopy testBlending +testUpdate diff --git a/inc/tizenvg.h b/inc/tizenvg.h index 87086957..f3252765 100644 --- a/inc/tizenvg.h +++ b/inc/tizenvg.h @@ -179,6 +179,7 @@ class TIZENVG_EXPORT SwCanvas final : public Canvas public: ~SwCanvas(); + int clear() noexcept override; int target(uint32_t* buffer, size_t stride, size_t w, size_t h) noexcept; int sync() noexcept override; static std::unique_ptr gen() noexcept; diff --git a/src/lib/tvgSwCanvas.cpp b/src/lib/tvgSwCanvas.cpp index 668c377a..cc26cbd8 100644 --- a/src/lib/tvgSwCanvas.cpp +++ b/src/lib/tvgSwCanvas.cpp @@ -45,6 +45,17 @@ SwCanvas::~SwCanvas() } +int SwCanvas::clear() noexcept +{ + auto renderer = dynamic_cast(engine()); + assert(renderer); + + if (!renderer->clear()) return -1; + + return Canvas::clear(); +} + + int SwCanvas::target(uint32_t* buffer, size_t stride, size_t w, size_t h) noexcept { auto renderer = dynamic_cast(engine()); diff --git a/test/makefile b/test/makefile index f455654a..e12fb317 100644 --- a/test/makefile +++ b/test/makefile @@ -6,3 +6,4 @@ all: gcc -o testPath testPath.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg` gcc -o testPathCopy testPathCopy.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg` gcc -o testBlending testBlending.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg` + gcc -o testUpdate testUpdate.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg` diff --git a/test/testUpdate.cpp b/test/testUpdate.cpp index 3a812897..c4250fbf 100644 --- a/test/testUpdate.cpp +++ b/test/testUpdate.cpp @@ -1,4 +1,5 @@ #include +#include using namespace std; @@ -6,50 +7,84 @@ using namespace std; #define HEIGHT 800 static uint32_t buffer[WIDTH * HEIGHT]; +unique_ptr canvas = nullptr; + +void tvgtest() +{ + //Create a Canvas + canvas = tvg::SwCanvas::gen(); + canvas->target(buffer, WIDTH, WIDTH, HEIGHT); + + //Shape + auto shape = tvg::ShapeNode::gen(); + shape->appendRect(-100, -100, 200, 200, 0); + shape->fill(255, 255, 255, 255); + canvas->push(move(shape)); + + //Draw first frame + canvas->draw(); + canvas->sync(); +} + +void transit_cb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress) +{ + //Explicitly clear all retained paint nodes. + canvas->clear(); + + //Shape + auto shape = tvg::ShapeNode::gen(); + shape->appendRect(-100 + (800 * progress), -100 + (800 * progress), 200, 200, (100 * progress)); + shape->fill(rand()%255, rand()%255, rand()%255, 255); + canvas->push(move(shape)); + + //Draw Next frames + canvas->draw(); + canvas->sync(); + + //Update Efl Canvas + Eo* img = (Eo*) effect; + evas_object_image_data_update_add(img, 0, 0, WIDTH, HEIGHT); +} + +void +win_del(void *data, Evas_Object *o, void *ev) +{ + elm_exit(); +} int main(int argc, char **argv) { - //Initialize TizenVG Engine - tvg::Engine::init(); + //Initialize TizenVG Engine + tvg::Engine::init(); - //Create a Canvas - auto canvas = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT); + tvgtest(); - //Create a Scene - auto scene = tvg::SceneNode::gen(); + //Show the result using EFL... + elm_init(argc, argv); - //Shape1 - auto shape1 = tvg::ShapeNode::gen(); + Eo* win = elm_win_util_standard_add(NULL, "TizenVG Test"); + evas_object_smart_callback_add(win, "delete,request", win_del, 0); - /* Acquire shape1 pointer to access directly later. - instead, you should consider not to interrupt this pointer life-cycle. */ - auto pshape1 = shape1->get(); + Eo* img = evas_object_image_filled_add(evas_object_evas_get(win)); + evas_object_image_size_set(img, WIDTH, HEIGHT); + evas_object_image_data_set(img, buffer); + evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_show(img); - shape1->rect(0, 0, 400, 400, 0.1); - shape1->fill(255, 0, 0, 255); - shape1->rotate(0, 0, 45); //axis x, y, z + elm_win_resize_object_add(win, img); + evas_object_geometry_set(win, 0, 0, WIDTH, HEIGHT); + evas_object_show(win); - scene->push(move(shape1)); - canvas->push(move(scene)); + Elm_Transit *transit = elm_transit_add(); + elm_transit_effect_add(transit, transit_cb, img, nullptr); + elm_transit_duration_set(transit, 2); + elm_transit_repeat_times_set(transit, -1); + elm_transit_auto_reverse_set(transit, EINA_TRUE); + elm_transit_go(transit); - //Draw first frame - canvas->draw(); - canvas->sync(); + elm_run(); + elm_shutdown(); - /* Clear the previous shape path and Prepare a new shape path. - You can call clear() to explicitly clear path data. */ - pshape1->rect(0, 0, 300, 300, 0.1); - - //Prepapre for drawing (this may work asynchronously) - pshape1->update(); - - //Draw second frame - canvas->draw(); - canvas->sync(); - - //Explicitly clear all retained paint nodes. - canvas->clear(); - - //Terminate TizenVG Engine - tvg::Engine::term(); -} + //Terminate TizenVG Engine + tvg::Engine::term(); +} \ No newline at end of file