mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-07 21:23:32 +00:00
Update sample prototypes.
This is still a hard work and under the intensive settle up stage. Change-Id: Ibfbeaabe8a51dc5edeeccf8fe75e65e60b91f703
This commit is contained in:
parent
df94be1d9d
commit
bf05660666
10 changed files with 67 additions and 23 deletions
|
@ -129,7 +129,7 @@ public:
|
|||
int clear() noexcept;
|
||||
|
||||
int draw(bool async = true) noexcept;
|
||||
int drawSync() noexcept;
|
||||
int sync() noexcept;
|
||||
|
||||
int target(uint32_t* buffer, size_t stride, size_t height) noexcept;
|
||||
|
||||
|
@ -157,7 +157,7 @@ public:
|
|||
|
||||
//TODO: Gl Specific methods. Need gl backend configuration methods as well.
|
||||
int draw(bool async = true) noexcept { return 0; }
|
||||
int drawSync() noexcept { return 0; }
|
||||
int sync() noexcept { return 0; }
|
||||
|
||||
static std::unique_ptr<GlCanvas> gen() noexcept;
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ int SwCanvas::draw(bool async) noexcept
|
|||
}
|
||||
|
||||
|
||||
int SwCanvas::drawSync() noexcept
|
||||
int SwCanvas::sync() noexcept
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
35
test/tvgComposition.cpp
Normal file
35
test/tvgComposition.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include <tizenvg.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define WIDTH 800
|
||||
#define HEIGHT 800
|
||||
|
||||
static uint32_t buffer[WIDTH * HEIGHT];
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
//Initialize TizenVG Engine
|
||||
tvg::Engine::init();
|
||||
|
||||
//Create a Composition Source Canvas
|
||||
auto canvas1 = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT);
|
||||
|
||||
//Draw something onto the Canvas and leaving sync to the target.
|
||||
canvas1->draw();
|
||||
|
||||
//Create a Main Canvas
|
||||
auto canvas2 = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT);
|
||||
|
||||
//Create a Shape
|
||||
auto shape = tvg::ShapeNode::gen();
|
||||
shape->composite(canvas, tvg::CompMaskAdd);
|
||||
|
||||
//Draw the Scene onto the Canvas
|
||||
canvas2->push(move(shape));
|
||||
canvas2->draw();
|
||||
canvas2->sync();
|
||||
|
||||
//Terminate TizenVG Engine
|
||||
tvg::Engine::term();
|
||||
}
|
|
@ -15,13 +15,17 @@ int main(int argc, char **argv)
|
|||
//Create a Canvas
|
||||
auto canvas = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT);
|
||||
|
||||
//Prepare a Shape
|
||||
//Prepare a Shape (Rectangle)
|
||||
auto shape1 = tvg::ShapeNode::gen();
|
||||
shape1->rect(0, 0, 400, 400, 0.1); //x, y, w, h, corner_radius
|
||||
shape1->fill(0, 255, 0, 255);
|
||||
// shape1->rect(0, 0, 400, 400, 0.1); //x, y, w, h, corner_radius
|
||||
// shape1->fill(0, 255, 0, 255); //r, g, b, a
|
||||
|
||||
//Draw the Shape onto the Canvas
|
||||
/* Push the shape into the Canvas drawing list
|
||||
When this shape is into the canvas list, the shape could update & prepare
|
||||
internal data asynchronously for coming rendering.
|
||||
Canvas keeps this shape node unless user call canvas->clear() */
|
||||
canvas->push(move(shape1));
|
||||
|
||||
canvas->draw();
|
||||
canvas->sync();
|
||||
|
||||
|
|
|
@ -27,14 +27,11 @@ int main(int argc, char **argv)
|
|||
fill1->color(1, 0, 0, 255, 255); //color Stop 2: Blue
|
||||
shape1.fill(fill1);
|
||||
|
||||
//Draw the Shape onto the Canvas
|
||||
canvas->push(move(shape1));
|
||||
|
||||
//Prepare Circle
|
||||
auto shape2 = tvg::ShapeNode::gen();
|
||||
shape2->circle(400, 400, 200); //cx, cy, radius
|
||||
shape2->fill(255, 255, 0, 255); //r, g, b, a
|
||||
canvas->push(move(shape2));
|
||||
|
||||
//Radial Gradient Fill
|
||||
auto fill2 = tvg::RadialFill::gen();
|
||||
|
@ -44,9 +41,9 @@ int main(int argc, char **argv)
|
|||
fill2->color(1, 0, 0, 255, 255); //color Stop 2: Blue
|
||||
shape2.fill(fill2);
|
||||
|
||||
//Draw the Shape onto the Canvas
|
||||
canvas->push(move(shape2));
|
||||
|
||||
//Draw the Shapes onto the Canvas
|
||||
canvas->draw();
|
||||
canvas->sync();
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ int main(int argc, char **argv)
|
|||
|
||||
//Create a Canvas
|
||||
auto canvas = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT);
|
||||
canvas->reserve(2); //reserve 2 shape nodes (optional)
|
||||
|
||||
//Prepare Rectangle
|
||||
auto shape1 = tvg::ShapeNode::gen();
|
||||
|
|
|
@ -25,8 +25,8 @@ int main(int argc, char **argv)
|
|||
|
||||
//Prepare a Shape
|
||||
auto shape1 = tvg::ShapeNode::gen();
|
||||
shape1->path(move(path)); //propagate owner
|
||||
shape1->path(path.get()); //copy data directly
|
||||
shape1->path(move(path)); //migrate owner otherwise,
|
||||
shape1->path(path.get()); //copy raw data directly for performance
|
||||
shape1->fill(0, 255, 0, 255);
|
||||
|
||||
//Draw the Shape onto the Canvas
|
||||
|
|
|
@ -16,7 +16,8 @@ int main(int argc, char **argv)
|
|||
auto canvas = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT);
|
||||
|
||||
//Create a Scene
|
||||
auto scene = tvg::SceneNode::gen(3); //reserve 3 shape nodes (optional)
|
||||
auto scene = tvg::SceneNode::gen();
|
||||
scene->reserve(3); //reserve 3 shape nodes (optional)
|
||||
|
||||
//Shape1
|
||||
auto shape1 = tvg::ShapeNode::gen();
|
||||
|
|
|
@ -26,7 +26,7 @@ int main(int argc, char **argv)
|
|||
shape1->strokeJoin(tvg::StrokeJoin::Miter);
|
||||
shape1->strokeLineCap(tvg::StrokeLineCap::Butt);
|
||||
|
||||
uint32_t dash[] = {3, 1, 5, 1};
|
||||
uint32_t dash[] = {3, 1, 5, 1}; //dash pattern
|
||||
shape1->strokeDash(dash, 4);
|
||||
|
||||
//Draw the Shape onto the Canvas
|
||||
|
|
|
@ -20,30 +20,36 @@ int main(int argc, char **argv)
|
|||
|
||||
//Shape1
|
||||
auto shape1 = tvg::ShapeNode::gen();
|
||||
auto pshape1 = shape1->get(); //acquire shape1 pointer to access directly
|
||||
|
||||
/* Acquire shape1 pointer to access directly later.
|
||||
instead, you should consider not to interrupt this pointer life-cycle. */
|
||||
auto pshape1 = shape1->get();
|
||||
|
||||
shape1->rect(0, 0, 400, 400, 0.1);
|
||||
shape1->fill(255, 0, 0, 255);
|
||||
shape1->rotate(0, 0, 45); //axis x, y, z
|
||||
scene->push(move(shape1));
|
||||
|
||||
//Draw the Scene onto the Canvas
|
||||
scene->push(move(shape1));
|
||||
canvas->push(move(scene));
|
||||
|
||||
//Draw frame 1
|
||||
//Draw first frame
|
||||
canvas->draw();
|
||||
canvas->sync();
|
||||
|
||||
//Clear previous shape path
|
||||
pshape1->clear();
|
||||
/* 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
|
||||
//Prepapre for drawing (this may work asynchronously)
|
||||
pshape1->update();
|
||||
|
||||
//Draw frame 2
|
||||
//Draw second frame
|
||||
canvas->draw();
|
||||
canvas->sync();
|
||||
|
||||
//Explicitly clear all retained paint nodes.
|
||||
canvas->clear();
|
||||
|
||||
//Terminate TizenVG Engine
|
||||
tvg::Engine::term();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue