filter.cpp revision cba73d3210c18f0fbcac2e9b5b95a717d4a6d977
18c4953c6f176469ad287c3270ab146e292b23badcommit-bot@chromium.org#include <stdlib.h>
28c4953c6f176469ad287c3270ab146e292b23badcommit-bot@chromium.org#include <stdio.h>
38c4953c6f176469ad287c3270ab146e292b23badcommit-bot@chromium.org
48c4953c6f176469ad287c3270ab146e292b23badcommit-bot@chromium.org#include <EGL/egl.h>
58c4953c6f176469ad287c3270ab146e292b23badcommit-bot@chromium.org#include <GLES/gl.h>
68c4953c6f176469ad287c3270ab146e292b23badcommit-bot@chromium.org#include <GLES/glext.h>
78c4953c6f176469ad287c3270ab146e292b23badcommit-bot@chromium.org
8c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org#include <ui/FramebufferNativeWindow.h>
9c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org#include <ui/EGLUtils.h>
10c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org
116419a5edb8af999623e018b09c3dd88ec371d2e6commit-bot@chromium.orgusing namespace android;
12c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org
13c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.orgint main(int argc, char** argv)
14c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org{
15c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org    if (argc!=2 && argc!=3) {
16c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org        printf("usage: %s <0-6> [pbuffer]\n", argv[0]);
17c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org        return 0;
18c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org    }
19c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org
20c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org    const int test = atoi(argv[1]);
21c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org    int usePbuffer = argc==3 && !strcmp(argv[2], "pbuffer");
22c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org    EGLint s_configAttribs[] = {
23c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org         EGL_SURFACE_TYPE, EGL_PBUFFER_BIT|EGL_WINDOW_BIT,
24c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org         EGL_RED_SIZE,       5,
25c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org         EGL_GREEN_SIZE,     6,
26c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org         EGL_BLUE_SIZE,      5,
27c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org         EGL_NONE
2854299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     };
2954299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org
3054299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     EGLint numConfigs = -1;
3154299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     EGLint majorVersion;
3254299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     EGLint minorVersion;
3354299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     EGLConfig config;
3454299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     EGLContext context;
3554299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     EGLSurface surface;
3654299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     EGLint w, h;
3705764d2f77892217ddead7f62586c1a3f5c02d36commit-bot@chromium.org
3805764d2f77892217ddead7f62586c1a3f5c02d36commit-bot@chromium.org     EGLDisplay dpy;
3905764d2f77892217ddead7f62586c1a3f5c02d36commit-bot@chromium.org
4005764d2f77892217ddead7f62586c1a3f5c02d36commit-bot@chromium.org     EGLNativeWindowType window = 0;
4105764d2f77892217ddead7f62586c1a3f5c02d36commit-bot@chromium.org     if (!usePbuffer) {
4205764d2f77892217ddead7f62586c1a3f5c02d36commit-bot@chromium.org         window = android_createDisplaySurface();
4305764d2f77892217ddead7f62586c1a3f5c02d36commit-bot@chromium.org     }
4405764d2f77892217ddead7f62586c1a3f5c02d36commit-bot@chromium.org
4505764d2f77892217ddead7f62586c1a3f5c02d36commit-bot@chromium.org     dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
4605764d2f77892217ddead7f62586c1a3f5c02d36commit-bot@chromium.org     eglInitialize(dpy, &majorVersion, &minorVersion);
4705764d2f77892217ddead7f62586c1a3f5c02d36commit-bot@chromium.org     if (!usePbuffer) {
48c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org         EGLUtils::selectConfigForNativeWindow(
49c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org                 dpy, s_configAttribs, window, &config);
50c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org         surface = eglCreateWindowSurface(dpy, config, window, NULL);
51c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org     } else {
52c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org         printf("using pbuffer\n");
53c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org         eglChooseConfig(dpy, s_configAttribs, &config, 1, &numConfigs);
54c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org         EGLint attribs[] = { EGL_WIDTH, 320, EGL_HEIGHT, 480, EGL_NONE };
55c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org         surface = eglCreatePbufferSurface(dpy, config, attribs);
56c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org         if (surface == EGL_NO_SURFACE) {
57c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org             printf("eglCreatePbufferSurface error %x\n", eglGetError());
58c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org         }
59c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org     }
60c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org     context = eglCreateContext(dpy, config, NULL, NULL);
61c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org     eglMakeCurrent(dpy, surface, surface, context);
62c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org     eglQuerySurface(dpy, surface, EGL_WIDTH, &w);
63c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org     eglQuerySurface(dpy, surface, EGL_HEIGHT, &h);
64c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org     GLint dim = w<h ? w : h;
65c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org
66c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org     glViewport(0, 0, w, h);
67c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org     glMatrixMode(GL_PROJECTION);
68c524e98f1edf06b53e65543f5f28217fa13b7aa9commit-bot@chromium.org     glLoadIdentity();
6954299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     glOrthof(0, w, h, 0, 0, 1);
7054299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org
7154299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     glClearColor(0,0,0,0);
7254299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     glClear(GL_COLOR_BUFFER_BIT);
7354299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org
7454299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     GLint crop[4] = { 0, 4, 4, -4 };
7554299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     glBindTexture(GL_TEXTURE_2D, 0);
7654299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
7754299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
7854299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
7954299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
8054299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     glEnable(GL_TEXTURE_2D);
8154299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     glColor4f(1,1,1,1);
8254299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org
8354299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     // packing is always 4
8454299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     uint8_t t8[]  = {
8554299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             0x00, 0x55, 0x00, 0x55,
8654299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             0xAA, 0xFF, 0xAA, 0xFF,
8754299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             0x00, 0x55, 0x00, 0x55,
8854299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             0xAA, 0xFF, 0xAA, 0xFF  };
8954299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org
9054299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     uint16_t t16[]  = {
9154299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             0x0000, 0x5555, 0x0000, 0x5555,
9254299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             0xAAAA, 0xFFFF, 0xAAAA, 0xFFFF,
9354299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             0x0000, 0x5555, 0x0000, 0x5555,
9454299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             0xAAAA, 0xFFFF, 0xAAAA, 0xFFFF  };
9554299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org
9654299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     uint16_t t5551[]  = {
9754299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             0x0000, 0xFFFF, 0x0000, 0xFFFF,
9854299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             0xFFFF, 0x0000, 0xFFFF, 0x0000,
9954299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             0x0000, 0xFFFF, 0x0000, 0xFFFF,
10054299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             0xFFFF, 0x0000, 0xFFFF, 0x0000  };
10154299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org
10254299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     uint32_t t32[]  = {
10354299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             0xFF000000, 0xFF0000FF, 0xFF00FF00, 0xFFFF0000,
10454299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             0xFF00FF00, 0xFFFF0000, 0xFF000000, 0xFF0000FF,
10554299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             0xFF00FFFF, 0xFF00FF00, 0x00FF00FF, 0xFFFFFF00,
10654299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             0xFF000000, 0xFFFF00FF, 0xFF00FFFF, 0xFFFFFFFF
10754299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     };
10854299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org
10954299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     switch(test)
11054299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     {
11154299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     case 1:
11254299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE,
11354299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org                 4, 4, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, t8);
11454299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         break;
11554299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     case 2:
11654299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
11754299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org                 4, 4, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, t16);
11854299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         break;
11954299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     case 3:
12054299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
12154299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org                 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, t16);
12254299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         break;
12354299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     case 4:
12454299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA,
12554299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org                 4, 4, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, t16);
12654299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         break;
12754299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     case 5:
12854299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
12954299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org                 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, t5551);
13054299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         break;
13154299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     case 6:
13254299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
13354299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org                 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, t32);
13454299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         break;
13554299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     }
13654299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org
13754299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     //glDrawTexiOES(0, 0, 0, dim, dim);
13854299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org
13954299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     const GLfloat vertices[4][2] = {
14054299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             { 0,    0   },
14154299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             { 0,    dim },
14254299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             { dim,  dim },
14354299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             { dim,  0   }
14454299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     };
14554299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org
14654299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     const GLfloat texCoords[4][2] = {
14754299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             { 0,  0 },
14854299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             { 0,  1 },
14954299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             { 1,  1 },
15054299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             { 1,  0 }
15154299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     };
15254299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org
15354299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     if (!usePbuffer) {
15454299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         eglSwapBuffers(dpy, surface);
15554299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     }
15654299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org
15754299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     glMatrixMode(GL_MODELVIEW);
15854299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     //glEnable(GL_SCISSOR_TEST);
15954299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     //glScissor(0,dim,dim,h-dim);
16054299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org
16154299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     for (int y=0 ; y<dim ; y++) {
16254299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         glLoadIdentity();
16354299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         glTranslatef(0, -y, 0);
16454299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org
16554299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         glClear(GL_COLOR_BUFFER_BIT);
16654299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         glEnableClientState(GL_VERTEX_ARRAY);
16754299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         glEnableClientState(GL_TEXTURE_COORD_ARRAY);
16854299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         glVertexPointer(2, GL_FLOAT, 0, vertices);
16954299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
17054299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
17154299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org
17254299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org
17354299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         if (!usePbuffer) {
17454299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             eglSwapBuffers(dpy, surface);
17554299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         } else {
17654299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org             glFinish();
17754299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org         }
17854299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     }
17954299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org
18054299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org
18154299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     eglTerminate(dpy);
18254299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org     return 0;
18354299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org}
18454299654e964ab53189f774e30bce2adebbdc857commit-bot@chromium.org