From: Hermet Park Date: Mon, 30 Mar 2020 11:51:26 +0000 (+0900) Subject: Update sample prototypes. X-Git-Tag: accepted/tizen/unified/20200806.062539~197 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F35%2F229235%2F2;p=platform%2Fcore%2Fgraphics%2Ftizenvg.git Update sample prototypes. This is still a hard work and under the intensive settle up stage. Change-Id: Ibfbeaabe8a51dc5edeeccf8fe75e65e60b91f703 --- diff --git a/inc/tizenvg.h b/inc/tizenvg.h index cc334e0..e790ea1 100644 --- a/inc/tizenvg.h +++ b/inc/tizenvg.h @@ -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 gen() noexcept; diff --git a/src/lib/tvgSwCanvas.cpp b/src/lib/tvgSwCanvas.cpp index 05296cd..13e91f3 100644 --- a/src/lib/tvgSwCanvas.cpp +++ b/src/lib/tvgSwCanvas.cpp @@ -55,7 +55,7 @@ int SwCanvas::draw(bool async) noexcept } -int SwCanvas::drawSync() noexcept +int SwCanvas::sync() noexcept { return 0; } diff --git a/test/tvgComposition.cpp b/test/tvgComposition.cpp new file mode 100644 index 0000000..cf5ed26 --- /dev/null +++ b/test/tvgComposition.cpp @@ -0,0 +1,35 @@ +#include + +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(); +} diff --git a/test/tvgDrawShape.cpp b/test/tvgDrawShape.cpp index 34f4dc9..7aaba5b 100644 --- a/test/tvgDrawShape.cpp +++ b/test/tvgDrawShape.cpp @@ -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(); diff --git a/test/tvgGradient.cpp b/test/tvgGradient.cpp index 2bf2824..a696839 100644 --- a/test/tvgGradient.cpp +++ b/test/tvgGradient.cpp @@ -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(); diff --git a/test/tvgMultipleShapes.cpp b/test/tvgMultipleShapes.cpp index fd7ea81..feeb964 100644 --- a/test/tvgMultipleShapes.cpp +++ b/test/tvgMultipleShapes.cpp @@ -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(); diff --git a/test/tvgPath.cpp b/test/tvgPath.cpp index 68f0998..e260682 100644 --- a/test/tvgPath.cpp +++ b/test/tvgPath.cpp @@ -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 diff --git a/test/tvgScene.cpp b/test/tvgScene.cpp index 56a9a6c..f3010dc 100644 --- a/test/tvgScene.cpp +++ b/test/tvgScene.cpp @@ -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(); diff --git a/test/tvgStroke.cpp b/test/tvgStroke.cpp index 6b90cda..6a51412 100644 --- a/test/tvgStroke.cpp +++ b/test/tvgStroke.cpp @@ -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 diff --git a/test/tvgUpdate.cpp b/test/tvgUpdate.cpp index 5bef2b9..3a81289 100644 --- a/test/tvgUpdate.cpp +++ b/test/tvgUpdate.cpp @@ -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(); }