This is still a hard work and under the intensive settle up stage.
Change-Id: Ibfbeaabe8a51dc5edeeccf8fe75e65e60b91f703
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;
//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;
}
-int SwCanvas::drawSync() noexcept
+int SwCanvas::sync() noexcept
{
return 0;
}
--- /dev/null
+#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();
+}
//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();
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();
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();
//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();
//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
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();
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
//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();
}