132001f49Smrg#include "eglcommon.h"
232001f49Smrg
332001f49Smrg#include <VG/openvg.h>
432001f49Smrg
532001f49Smrg#include <stdio.h>
632001f49Smrg#include <stdlib.h>
732001f49Smrg#include <string.h>
832001f49Smrg#include <assert.h>
932001f49Smrg
1032001f49Smrgfloat red_color[4] = {1.0, 0.0, 0.0, 1.0};
1132001f49Smrgfloat blue_color[4] = {0.0, 0.0, 1.0, 1.0};
1232001f49SmrgVGint *data;
1332001f49Smrg
1432001f49Smrgstatic void
1532001f49Smrginit(void)
1632001f49Smrg{
1732001f49Smrg   data = malloc(sizeof(VGint)*2048*2048);
1832001f49Smrg}
1932001f49Smrg
2032001f49Smrg/* new window size or exposure */
2132001f49Smrgstatic void
2232001f49Smrgreshape(int w, int h)
2332001f49Smrg{
2432001f49Smrg   vgLoadIdentity();
2532001f49Smrg}
2632001f49Smrg
2732001f49Smrgstatic void
2832001f49Smrgdraw(void)
2932001f49Smrg{
3032001f49Smrg   static const VGint red_pixel  = 255 << 24 | 255 << 16 | 0 << 8 |   0;
3132001f49Smrg   static const VGint blue_pixel = 255 << 24 |   0 << 16 | 0 << 8 | 255;
3232001f49Smrg   VGint i;
3332001f49Smrg
3432001f49Smrg   vgSetfv(VG_CLEAR_COLOR, 4, red_color);
3532001f49Smrg   vgClear(0, 0, window_width(), window_height());
3632001f49Smrg   vgFlush();
3732001f49Smrg
3832001f49Smrg   memset(data, 0, window_width() * window_height() * sizeof(VGint));
3932001f49Smrg
4032001f49Smrg   vgReadPixels(data, window_width() * sizeof(VGint),
4132001f49Smrg                VG_lARGB_8888,
4232001f49Smrg                0, 0, window_width(), window_height());
4332001f49Smrg
4432001f49Smrg   fprintf(stderr, "Red 0 = 0x%x and at 600 = 0x%x\n",
4532001f49Smrg           data[0], data[600]);
4632001f49Smrg   for (i = 0; i < window_width() * window_height(); ++i) {
4732001f49Smrg      assert(data[i] == red_pixel);
4832001f49Smrg   }
4932001f49Smrg
5032001f49Smrg   vgSetfv(VG_CLEAR_COLOR, 4, blue_color);
5132001f49Smrg   vgClear(50, 50, 50, 50);
5232001f49Smrg   vgFlush();
5332001f49Smrg
5432001f49Smrg   memset(data, 0, window_width() * window_height() * sizeof(VGint));
5532001f49Smrg
5632001f49Smrg   vgReadPixels(data, 50 * sizeof(VGint),
5732001f49Smrg                VG_lARGB_8888,
5832001f49Smrg                50, 50, 50, 50);
5932001f49Smrg
6032001f49Smrg   fprintf(stderr, "Blue 0 = 0x%x and at 100 = 0x%x\n",
6132001f49Smrg           data[0], data[100]);
6232001f49Smrg   for (i = 0; i < 50 * 50; ++i) {
6332001f49Smrg      assert(data[i] == blue_pixel);
6432001f49Smrg   }
6532001f49Smrg}
6632001f49Smrg
6732001f49Smrg
6832001f49Smrgint main(int argc, char **argv)
6932001f49Smrg{
7032001f49Smrg   int ret = run(argc, argv, init, reshape,
7132001f49Smrg                 draw, 0);
7232001f49Smrg
7332001f49Smrg   free(data);
7432001f49Smrg   return ret;
7532001f49Smrg}
76