132001f49Smrg#include "eglcommon.h"
232001f49Smrg
332001f49Smrg#include <VG/openvg.h>
432001f49Smrg
532001f49Smrg#include <stdio.h>
632001f49Smrg#include <string.h>
732001f49Smrg
832001f49Smrgstatic const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0};
932001f49Smrg
1032001f49Smrgstatic VGPath path;
1132001f49Smrgstatic VGPaint fill;
1232001f49Smrg
1332001f49SmrgVGColorRampSpreadMode spread = VG_COLOR_RAMP_SPREAD_PAD;
1432001f49Smrg
1532001f49Smrgstatic void
1632001f49Smrginit(void)
1732001f49Smrg{
1832001f49Smrg   VGubyte commands[5] =  {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, VG_CLOSE_PATH};
1932001f49Smrg   VGfloat coords[8] =    {0.0f,0.0f, 32.0f,0.0f, 32.0f,32.0f, 0.0f,32.0f };
2032001f49Smrg
2132001f49Smrg   VGfloat rampStop[20] = {-0.5f,  1.0f, 1.0f, 1.0f, 1.0f,
2232001f49Smrg                           0.25f, 1.0f, 0.0f, 0.0f, 1.0f,
2332001f49Smrg                           0.75f, 0.0f, 0.0f, 1.0f, 1.0f,
2432001f49Smrg                           1.5f,  0.0f, 0.0f, 0.0f, 0.0f};
2532001f49Smrg
2632001f49Smrg   VGfloat defaultColor[] = {1.0f, 1.0f, 1.0f, 1.0f};
2732001f49Smrg   VGfloat linearGradient[4] = {0.0f, 0.0f, 0.0f, 32.0f};
2832001f49Smrg
2932001f49Smrg   path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
3032001f49Smrg                       1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL);
3132001f49Smrg   if (path == VG_INVALID_HANDLE)
3232001f49Smrg      return;
3332001f49Smrg
3432001f49Smrg   fill = vgCreatePaint();
3532001f49Smrg   if (fill == VG_INVALID_HANDLE) {
3632001f49Smrg      vgDestroyPath(path);
3732001f49Smrg      return;
3832001f49Smrg   }
3932001f49Smrg
4032001f49Smrg   vgSetfv(VG_CLEAR_COLOR, 4, defaultColor);
4132001f49Smrg   vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_NONANTIALIASED);
4232001f49Smrg
4332001f49Smrg   vgAppendPathData(path, 5, commands, coords);
4432001f49Smrg
4532001f49Smrg   vgSetPaint(fill, VG_FILL_PATH);
4632001f49Smrg   vgSetParameteri(fill, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT);
4732001f49Smrg   vgSetParameteri(fill, VG_PAINT_COLOR_RAMP_SPREAD_MODE,
4832001f49Smrg                   VG_COLOR_RAMP_SPREAD_REPEAT);
4932001f49Smrg   vgSetParameterfv(fill, VG_PAINT_LINEAR_GRADIENT, 4, linearGradient);
5032001f49Smrg   vgSetParameterfv(fill, VG_PAINT_COLOR_RAMP_STOPS, 20, rampStop);
5132001f49Smrg}
5232001f49Smrg
5332001f49Smrg/* new window size or exposure */
5432001f49Smrgstatic void
5532001f49Smrgreshape(int w, int h)
5632001f49Smrg{
5732001f49Smrg   vgLoadIdentity();
5832001f49Smrg}
5932001f49Smrg
6032001f49Smrgstatic void
6132001f49Smrgdraw(void)
6232001f49Smrg{
6332001f49Smrg   vgClear(0, 0, window_width(), window_height());
6432001f49Smrg
6532001f49Smrg   vgDrawPath(path, VG_FILL_PATH);
6632001f49Smrg
6732001f49Smrg   vgFlush();
6832001f49Smrg}
6932001f49Smrg
7032001f49Smrg
7132001f49Smrgint main(int argc, char **argv)
7232001f49Smrg{
7332001f49Smrg   if (argc > 1) {
7432001f49Smrg      const char *arg = argv[1];
7532001f49Smrg      if (!strcmp("-pad", arg))
7632001f49Smrg         spread = VG_COLOR_RAMP_SPREAD_PAD;
7732001f49Smrg      else if (!strcmp("-repeat", arg))
7832001f49Smrg         spread = VG_COLOR_RAMP_SPREAD_REPEAT;
7932001f49Smrg      else if (!strcmp("-reflect", arg))
8032001f49Smrg         spread = VG_COLOR_RAMP_SPREAD_REFLECT;
8132001f49Smrg   }
8232001f49Smrg
8332001f49Smrg   switch(spread) {
8432001f49Smrg   case VG_COLOR_RAMP_SPREAD_PAD:
8532001f49Smrg      printf("Using spread mode: pad\n");
8632001f49Smrg      break;
8732001f49Smrg   case VG_COLOR_RAMP_SPREAD_REPEAT:
8832001f49Smrg      printf("Using spread mode: repeat\n");
8932001f49Smrg      break;
9032001f49Smrg   case VG_COLOR_RAMP_SPREAD_REFLECT:
9132001f49Smrg      printf("Using spread mode: reflect\n");
9232001f49Smrg   }
9332001f49Smrg
9432001f49Smrg   set_window_size(200, 200);
9532001f49Smrg
9632001f49Smrg   return run(argc, argv, init, reshape,
9732001f49Smrg              draw, 0);
9832001f49Smrg}
99