Update sample prototypes. 35/229235/2
authorHermet Park <chuneon.park@samsung.com>
Mon, 30 Mar 2020 11:51:26 +0000 (20:51 +0900)
committerHermet Park <chuneon.park@samsung.com>
Mon, 30 Mar 2020 11:51:44 +0000 (20:51 +0900)
This is still a hard work and under the intensive settle up stage.

Change-Id: Ibfbeaabe8a51dc5edeeccf8fe75e65e60b91f703

inc/tizenvg.h
src/lib/tvgSwCanvas.cpp
test/tvgComposition.cpp [new file with mode: 0644]
test/tvgDrawShape.cpp
test/tvgGradient.cpp
test/tvgMultipleShapes.cpp
test/tvgPath.cpp
test/tvgScene.cpp
test/tvgStroke.cpp
test/tvgUpdate.cpp

index cc334e0..e790ea1 100644 (file)
@@ -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;
 
index 05296cd..13e91f3 100644 (file)
@@ -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 (file)
index 0000000..cf5ed26
--- /dev/null
@@ -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();
+}
index 34f4dc9..7aaba5b 100644 (file)
@@ -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();
 
index 2bf2824..a696839 100644 (file)
@@ -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();
 
index fd7ea81..feeb964 100644 (file)
@@ -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();
index 68f0998..e260682 100644 (file)
@@ -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
index 56a9a6c..f3010dc 100644 (file)
@@ -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();
index 6b90cda..6a51412 100644 (file)
@@ -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
index 5bef2b9..3a81289 100644 (file)
@@ -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();
 }