Demos (master): egl/openvg: Add demos for VGMaskLayer functions.

Chia-I Wu olv at kemper.freedesktop.org
Mon Nov 29 10:41:22 UTC 2010


Module: Demos
Branch: master
Commit: a9f806156d76684f1c2a7ab3e2bfd12643312268
URL:    http://cgit.freedesktop.org/mesa/demos/commit/?id=a9f806156d76684f1c2a7ab3e2bfd12643312268

Author: Chia-I Wu <olvaffe at gmail.com>
Date:   Sun Nov 28 23:18:59 2010 +0800

egl/openvg: Add demos for VGMaskLayer functions.

---

 src/egl/openvg/trivial/Makefile.am   |    4 +
 src/egl/openvg/trivial/layer.c       |  109 +++++++++++++++++++++++++++
 src/egl/openvg/trivial/mask_render.c |  134 ++++++++++++++++++++++++++++++++++
 3 files changed, 247 insertions(+), 0 deletions(-)

diff --git a/src/egl/openvg/trivial/Makefile.am b/src/egl/openvg/trivial/Makefile.am
index d694b67..9e2b57e 100644
--- a/src/egl/openvg/trivial/Makefile.am
+++ b/src/egl/openvg/trivial/Makefile.am
@@ -53,11 +53,13 @@ noinst_PROGRAMS = \
 	filter \
 	gradorigin \
 	image \
+	layer \
 	lineto \
 	lingrad \
 	lookup \
 	mask4 \
 	mask \
+	mask_render \
 	path3 \
 	radialgrad \
 	readpixels \
@@ -79,11 +81,13 @@ ellipse_LDADD = libcommon.la
 filter_LDADD = libcommon.la
 gradorigin_LDADD = libcommon.la
 image_LDADD = libcommon.la
+layer_LDADD = libcommon.la
 lineto_LDADD = libcommon.la
 lingrad_LDADD = libcommon.la
 lookup_LDADD = libcommon.la
 mask4_LDADD = libcommon.la
 mask_LDADD = libcommon.la
+mask_render_LDADD = libcommon.la
 path3_LDADD = libcommon.la
 radialgrad_LDADD = libcommon.la
 readpixels_LDADD = libcommon.la
diff --git a/src/egl/openvg/trivial/layer.c b/src/egl/openvg/trivial/layer.c
new file mode 100644
index 0000000..81cbb74
--- /dev/null
+++ b/src/egl/openvg/trivial/layer.c
@@ -0,0 +1,109 @@
+#include "eglcommon.h"
+
+#include <VG/openvg.h>
+
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#ifdef OPENVG_VERSION_1_1
+
+#define NUM_LAYERS 2
+
+static VGMaskLayer layers[NUM_LAYERS];
+static VGint current_layer;
+static VGPath path;
+
+static void
+init(void)
+{
+   vgSeti(VG_MASKING, VG_TRUE);
+}
+
+static void ellipse(VGPath vgPath, VGfloat rx, VGfloat ry, VGfloat angle)
+{
+    static const VGubyte cmd[] =
+    { VG_MOVE_TO_ABS, VG_SCCWARC_TO_REL, VG_SCCWARC_TO_REL, VG_CLOSE_PATH };
+
+    VGfloat val[12];
+    VGfloat c = cos(angle) * rx;
+    VGfloat s = sin(angle) * rx;
+
+    val[0] = c;
+    val[1] = s;
+    val[2] = rx;
+    val[3] = ry;
+    val[4] = angle;
+    val[5] = -2.0f * c;
+    val[6] = -2.0f * s;
+    val[7] = rx;
+    val[8] = ry;
+    val[9] = angle;
+    val[10] = 2.0f * c;
+    val[11] = 2.0f * s;
+
+    vgClearPath(vgPath, VG_PATH_CAPABILITY_ALL);
+    vgAppendPathData(vgPath, sizeof(cmd), cmd, val);
+}
+
+/* new window size or exposure */
+static void
+reshape(int w, int h)
+{
+   int i;
+
+   if (path)
+      vgDestroyPath(path);
+   path = vgCreatePath(VG_PATH_FORMAT_STANDARD,
+                       VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0,
+                       VG_PATH_CAPABILITY_ALL);
+
+   for (i = 0; i < NUM_LAYERS; i++) {
+      if (layers[i])
+         vgDestroyMaskLayer(layers[i]);
+      layers[i] = vgCreateMaskLayer(w, h);
+   }
+
+   vgLoadIdentity();
+   vgTranslate(w / 2.0f, h / 2.0f);
+   ellipse(path, w / 3.0f, h / 3.0f, 0.0f);
+
+   /* test vgFillMaskLayer and vgCopyMask */
+   vgFillMaskLayer(layers[0], 0, 0, w, h / 2, 0.8f);
+   vgFillMaskLayer(layers[0], 0, h / 2, w, h / 2, 0.4f);
+   vgMask(layers[0], VG_SET_MASK, 0, 0, w, h);
+   vgCopyMask(layers[1], 0, 0, 0, 0, w, h);
+}
+
+static const VGfloat white[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
+
+static void
+draw(void)
+{
+   vgSetfv(VG_CLEAR_COLOR, 4, white);
+   vgClear(0, 0, window_width(), window_height());
+
+   vgDrawPath(path, VG_FILL_PATH);
+
+   current_layer = (current_layer + 1) % NUM_LAYERS;
+   vgMask(layers[current_layer], VG_SET_MASK,
+         0, 0, window_width(), window_height());
+}
+
+
+int main(int argc, char **argv)
+{
+   set_window_size(300, 300);
+   return run(argc, argv, init, reshape,
+              draw, 0);
+}
+
+#else /* OPENVG_VERSION_1_1 */
+
+int main(int argc, char **argv)
+{
+   printf("This demo requires OpenVG 1.1\n");
+   return 0;
+}
+
+#endif /* OPENVG_VERSION_1_1 */
diff --git a/src/egl/openvg/trivial/mask_render.c b/src/egl/openvg/trivial/mask_render.c
new file mode 100644
index 0000000..0fcceeb
--- /dev/null
+++ b/src/egl/openvg/trivial/mask_render.c
@@ -0,0 +1,134 @@
+#include "eglcommon.h"
+
+#include <VG/openvg.h>
+
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#ifdef OPENVG_VERSION_1_1
+
+static VGPath rect;
+
+static void
+init(void)
+{
+   VGPaint paint;
+
+   VGubyte cmd[] = {
+      VG_MOVE_TO_ABS,
+      VG_LINE_TO_ABS,
+      VG_LINE_TO_ABS,
+      VG_LINE_TO_ABS,
+      VG_CLOSE_PATH
+   };
+   VGfloat val[] = {
+      0.0f, 0.0f,
+      1.0f, 0.0f,
+      1.0f, 1.0f,
+      0.0f, 1.0f
+   };
+
+   rect = vgCreatePath(VG_PATH_FORMAT_STANDARD,
+                       VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0,
+                       VG_PATH_CAPABILITY_ALL);
+   vgAppendPathData(rect, sizeof(cmd), cmd, val);
+
+   paint = vgCreatePaint();
+   vgSetColor(paint, 0xff0000ff);
+   vgSetPaint(paint, VG_FILL_PATH);
+
+   vgSeti(VG_MASKING, VG_TRUE);
+}
+
+static void ellipse(VGPath vgPath, VGfloat rx, VGfloat ry, VGfloat angle)
+{
+    static const VGubyte cmd[] =
+    { VG_MOVE_TO_ABS, VG_SCCWARC_TO_REL, VG_SCCWARC_TO_REL, VG_CLOSE_PATH };
+
+    VGfloat val[12];
+    VGfloat c = cos(angle) * rx;
+    VGfloat s = sin(angle) * rx;
+
+    val[0] = c;
+    val[1] = s;
+    val[2] = rx;
+    val[3] = ry;
+    val[4] = angle;
+    val[5] = -2.0f * c;
+    val[6] = -2.0f * s;
+    val[7] = rx;
+    val[8] = ry;
+    val[9] = angle;
+    val[10] = 2.0f * c;
+    val[11] = 2.0f * s;
+
+    vgClearPath(vgPath, VG_PATH_CAPABILITY_ALL);
+    vgAppendPathData(vgPath, sizeof(cmd), cmd, val);
+}
+
+/* new window size or exposure */
+static void
+reshape(int w, int h)
+{
+   VGMaskLayer layer;
+   VGPath path;
+   int i;
+
+   /* test vgFillMaskLayer */
+   layer = vgCreateMaskLayer(w, h);
+   vgFillMaskLayer(layer, 0, 0, w, h, 0.8f);
+   vgMask(layer, VG_SET_MASK, 0, 0, w, h);
+   vgDestroyMaskLayer(layer);
+
+   /* test vgRenderToMask */
+   path = vgCreatePath(VG_PATH_FORMAT_STANDARD,
+                       VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0,
+                       VG_PATH_CAPABILITY_ALL);
+   vgLoadIdentity();
+   vgTranslate(w / 2.0f, h / 3.0f);
+   ellipse(path, w / 3.0f, h / 3.0f, 0.0f);
+
+   vgRenderToMask(path, VG_FILL_PATH, VG_UNION_MASK);
+
+   vgDestroyPath(path);
+}
+
+static const VGfloat white[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
+
+static void
+rectangle(VGint x, VGint y, VGint width, VGint height)
+{
+   vgLoadIdentity();
+   vgTranslate(x, y);
+   vgScale(width, height);
+   vgDrawPath(rect, VG_FILL_PATH);
+}
+
+static void
+draw(void)
+{
+   vgSetfv(VG_CLEAR_COLOR, 4, white);
+   vgClear(0, 0, window_width(), window_height());
+
+   if (window_width() > 10 && window_height() > 10)
+      rectangle(5, 5, window_width() - 10, window_height() - 10);
+}
+
+
+int main(int argc, char **argv)
+{
+   set_window_size(300, 300);
+   return run(argc, argv, init, reshape,
+              draw, 0);
+}
+
+#else /* OPENVG_VERSION_1_1 */
+
+int main(int argc, char **argv)
+{
+   printf("This demo requires OpenVG 1.1\n");
+   return 0;
+}
+
+#endif /* OPENVG_VERSION_1_1 */




More information about the mesa-commit mailing list