mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
test: added testUpdate
this shows a moving shape: how to update canvas every frames. Change-Id: I373e39757f4511d4e676f36d76e468d03b185a0c
This commit is contained in:
parent
11e070d167
commit
c923d881aa
5 changed files with 85 additions and 36 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -8,3 +8,4 @@ testBoundary
|
||||||
testPath
|
testPath
|
||||||
testPathCopy
|
testPathCopy
|
||||||
testBlending
|
testBlending
|
||||||
|
testUpdate
|
||||||
|
|
|
@ -179,6 +179,7 @@ class TIZENVG_EXPORT SwCanvas final : public Canvas
|
||||||
public:
|
public:
|
||||||
~SwCanvas();
|
~SwCanvas();
|
||||||
|
|
||||||
|
int clear() noexcept override;
|
||||||
int target(uint32_t* buffer, size_t stride, size_t w, size_t h) noexcept;
|
int target(uint32_t* buffer, size_t stride, size_t w, size_t h) noexcept;
|
||||||
int sync() noexcept override;
|
int sync() noexcept override;
|
||||||
static std::unique_ptr<SwCanvas> gen() noexcept;
|
static std::unique_ptr<SwCanvas> gen() noexcept;
|
||||||
|
|
|
@ -45,6 +45,17 @@ SwCanvas::~SwCanvas()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int SwCanvas::clear() noexcept
|
||||||
|
{
|
||||||
|
auto renderer = dynamic_cast<SwRenderer*>(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
|
int SwCanvas::target(uint32_t* buffer, size_t stride, size_t w, size_t h) noexcept
|
||||||
{
|
{
|
||||||
auto renderer = dynamic_cast<SwRenderer*>(engine());
|
auto renderer = dynamic_cast<SwRenderer*>(engine());
|
||||||
|
|
|
@ -6,3 +6,4 @@ all:
|
||||||
gcc -o testPath testPath.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg`
|
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 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 testBlending testBlending.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg`
|
||||||
|
gcc -o testUpdate testUpdate.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg`
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include <tizenvg.h>
|
#include <tizenvg.h>
|
||||||
|
#include <Elementary.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -6,49 +7,83 @@ using namespace std;
|
||||||
#define HEIGHT 800
|
#define HEIGHT 800
|
||||||
|
|
||||||
static uint32_t buffer[WIDTH * HEIGHT];
|
static uint32_t buffer[WIDTH * HEIGHT];
|
||||||
|
unique_ptr<tvg::SwCanvas> 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)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
//Initialize TizenVG Engine
|
//Initialize TizenVG Engine
|
||||||
tvg::Engine::init();
|
tvg::Engine::init();
|
||||||
|
|
||||||
//Create a Canvas
|
tvgtest();
|
||||||
auto canvas = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT);
|
|
||||||
|
|
||||||
//Create a Scene
|
//Show the result using EFL...
|
||||||
auto scene = tvg::SceneNode::gen();
|
elm_init(argc, argv);
|
||||||
|
|
||||||
//Shape1
|
Eo* win = elm_win_util_standard_add(NULL, "TizenVG Test");
|
||||||
auto shape1 = tvg::ShapeNode::gen();
|
evas_object_smart_callback_add(win, "delete,request", win_del, 0);
|
||||||
|
|
||||||
/* Acquire shape1 pointer to access directly later.
|
Eo* img = evas_object_image_filled_add(evas_object_evas_get(win));
|
||||||
instead, you should consider not to interrupt this pointer life-cycle. */
|
evas_object_image_size_set(img, WIDTH, HEIGHT);
|
||||||
auto pshape1 = shape1->get();
|
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);
|
elm_win_resize_object_add(win, img);
|
||||||
shape1->fill(255, 0, 0, 255);
|
evas_object_geometry_set(win, 0, 0, WIDTH, HEIGHT);
|
||||||
shape1->rotate(0, 0, 45); //axis x, y, z
|
evas_object_show(win);
|
||||||
|
|
||||||
scene->push(move(shape1));
|
Elm_Transit *transit = elm_transit_add();
|
||||||
canvas->push(move(scene));
|
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
|
elm_run();
|
||||||
canvas->draw();
|
elm_shutdown();
|
||||||
canvas->sync();
|
|
||||||
|
|
||||||
/* 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
|
//Terminate TizenVG Engine
|
||||||
tvg::Engine::term();
|
tvg::Engine::term();
|
||||||
|
|
Loading…
Add table
Reference in a new issue