1#include "eglcommon.h" 2 3#include <VG/openvg.h> 4 5#include <math.h> 6#include <stdlib.h> 7#include <stdio.h> 8 9#ifdef OPENVG_VERSION_1_1 10 11static VGPath rect; 12 13static void 14init(void) 15{ 16 VGPaint paint; 17 18 VGubyte cmd[] = { 19 VG_MOVE_TO_ABS, 20 VG_LINE_TO_ABS, 21 VG_LINE_TO_ABS, 22 VG_LINE_TO_ABS, 23 VG_CLOSE_PATH 24 }; 25 VGfloat val[] = { 26 0.0f, 0.0f, 27 1.0f, 0.0f, 28 1.0f, 1.0f, 29 0.0f, 1.0f 30 }; 31 32 rect = vgCreatePath(VG_PATH_FORMAT_STANDARD, 33 VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, 34 VG_PATH_CAPABILITY_ALL); 35 vgAppendPathData(rect, sizeof(cmd), cmd, val); 36 37 paint = vgCreatePaint(); 38 vgSetColor(paint, 0xff0000ff); 39 vgSetPaint(paint, VG_FILL_PATH); 40 41 vgSeti(VG_MASKING, VG_TRUE); 42} 43 44static void ellipse(VGPath vgPath, VGfloat rx, VGfloat ry, VGfloat angle) 45{ 46 static const VGubyte cmd[] = 47 { VG_MOVE_TO_ABS, VG_SCCWARC_TO_REL, VG_SCCWARC_TO_REL, VG_CLOSE_PATH }; 48 49 VGfloat val[12]; 50 VGfloat c = cos(angle) * rx; 51 VGfloat s = sin(angle) * rx; 52 53 val[0] = c; 54 val[1] = s; 55 val[2] = rx; 56 val[3] = ry; 57 val[4] = angle; 58 val[5] = -2.0f * c; 59 val[6] = -2.0f * s; 60 val[7] = rx; 61 val[8] = ry; 62 val[9] = angle; 63 val[10] = 2.0f * c; 64 val[11] = 2.0f * s; 65 66 vgClearPath(vgPath, VG_PATH_CAPABILITY_ALL); 67 vgAppendPathData(vgPath, sizeof(cmd), cmd, val); 68} 69 70/* new window size or exposure */ 71static void 72reshape(int w, int h) 73{ 74 VGMaskLayer layer; 75 VGPath path; 76 int i; 77 78 /* test vgFillMaskLayer */ 79 layer = vgCreateMaskLayer(w, h); 80 vgFillMaskLayer(layer, 0, 0, w, h, 0.8f); 81 vgMask(layer, VG_SET_MASK, 0, 0, w, h); 82 vgDestroyMaskLayer(layer); 83 84 /* test vgRenderToMask */ 85 path = vgCreatePath(VG_PATH_FORMAT_STANDARD, 86 VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, 87 VG_PATH_CAPABILITY_ALL); 88 vgLoadIdentity(); 89 vgTranslate(w / 2.0f, h / 3.0f); 90 ellipse(path, w / 3.0f, h / 3.0f, 0.0f); 91 92 vgRenderToMask(path, VG_FILL_PATH, VG_UNION_MASK); 93 94 vgDestroyPath(path); 95} 96 97static const VGfloat white[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; 98 99static void 100rectangle(VGint x, VGint y, VGint width, VGint height) 101{ 102 vgLoadIdentity(); 103 vgTranslate(x, y); 104 vgScale(width, height); 105 vgDrawPath(rect, VG_FILL_PATH); 106} 107 108static void 109draw(void) 110{ 111 vgSetfv(VG_CLEAR_COLOR, 4, white); 112 vgClear(0, 0, window_width(), window_height()); 113 114 if (window_width() > 10 && window_height() > 10) 115 rectangle(5, 5, window_width() - 10, window_height() - 10); 116} 117 118 119int main(int argc, char **argv) 120{ 121 set_window_size(300, 300); 122 return run(argc, argv, init, reshape, 123 draw, 0); 124} 125 126#else /* OPENVG_VERSION_1_1 */ 127 128int main(int argc, char **argv) 129{ 130 printf("This demo requires OpenVG 1.1\n"); 131 return 0; 132} 133 134#endif /* OPENVG_VERSION_1_1 */ 135