| Mathias Agopian | 3221616 | 2009-10-28 02:09:21 -0700 | [diff] [blame] | 1 | /* | 
 | 2 | ** | 
 | 3 | ** Copyright 2006, The Android Open Source Project | 
 | 4 | ** | 
 | 5 | ** Licensed under the Apache License, Version 2.0 (the "License");  | 
 | 6 | ** you may not use this file except in compliance with the License.  | 
 | 7 | ** You may obtain a copy of the License at  | 
 | 8 | ** | 
 | 9 | **     http://www.apache.org/licenses/LICENSE-2.0  | 
 | 10 | ** | 
 | 11 | ** Unless required by applicable law or agreed to in writing, software  | 
 | 12 | ** distributed under the License is distributed on an "AS IS" BASIS,  | 
 | 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
 | 14 | ** See the License for the specific language governing permissions and  | 
 | 15 | ** limitations under the License. | 
 | 16 | */ | 
 | 17 |  | 
| Mathias Agopian | 3221616 | 2009-10-28 02:09:21 -0700 | [diff] [blame] | 18 | #include <unistd.h> | 
 | 19 | #include <stdlib.h> | 
 | 20 | #include <stdio.h> | 
 | 21 |  | 
 | 22 | #include <EGL/egl.h> | 
 | 23 | #include <GLES/gl.h> | 
 | 24 | #include <GLES/glext.h> | 
 | 25 |  | 
 | 26 | #include <utils/StopWatch.h> | 
| Andy McFadden | 6ef57d7 | 2014-03-05 15:06:53 -0800 | [diff] [blame] | 27 | #include <WindowSurface.h> | 
 | 28 | #include <EGLUtils.h> | 
| Mathias Agopian | 3221616 | 2009-10-28 02:09:21 -0700 | [diff] [blame] | 29 |  | 
 | 30 | using namespace android; | 
 | 31 |  | 
 | 32 | int main(int argc, char** argv) | 
 | 33 | { | 
 | 34 |     EGLint configAttribs[] = { | 
 | 35 |          EGL_DEPTH_SIZE, 0, | 
 | 36 |          EGL_NONE | 
 | 37 |      }; | 
 | 38 |       | 
 | 39 |      EGLint majorVersion; | 
 | 40 |      EGLint minorVersion; | 
 | 41 |      EGLContext context; | 
 | 42 |      EGLConfig config; | 
 | 43 |      EGLSurface surface; | 
 | 44 |      EGLint w, h; | 
 | 45 |      EGLDisplay dpy; | 
 | 46 |  | 
| Andy McFadden | 6ef57d7 | 2014-03-05 15:06:53 -0800 | [diff] [blame] | 47 |      WindowSurface windowSurface; | 
 | 48 |      EGLNativeWindowType window = windowSurface.getSurface(); | 
| Mathias Agopian | 3221616 | 2009-10-28 02:09:21 -0700 | [diff] [blame] | 49 |       | 
 | 50 |      dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); | 
 | 51 |      eglInitialize(dpy, &majorVersion, &minorVersion); | 
 | 52 |            | 
 | 53 |      status_t err = EGLUtils::selectConfigForNativeWindow( | 
 | 54 |              dpy, configAttribs, window, &config); | 
 | 55 |      if (err) { | 
 | 56 |          fprintf(stderr, "couldn't find an EGLConfig matching the screen format\n"); | 
 | 57 |          return 0; | 
 | 58 |      } | 
 | 59 |  | 
 | 60 |      surface = eglCreateWindowSurface(dpy, config, window, NULL); | 
 | 61 |      context = eglCreateContext(dpy, config, NULL, NULL); | 
 | 62 |      eglMakeCurrent(dpy, surface, surface, context);    | 
 | 63 |      eglQuerySurface(dpy, surface, EGL_WIDTH, &w); | 
 | 64 |      eglQuerySurface(dpy, surface, EGL_HEIGHT, &h); | 
 | 65 |       | 
 | 66 |      printf("w=%d, h=%d\n", w, h); | 
 | 67 |       | 
 | 68 |      glBindTexture(GL_TEXTURE_2D, 0); | 
 | 69 |      glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 
| Mathias Agopian | 6c7d04b | 2009-10-30 16:32:52 -0700 | [diff] [blame] | 70 |      glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 
| Mathias Agopian | 3810c2b | 2009-10-29 15:47:12 -0700 | [diff] [blame] | 71 |      glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); | 
 | 72 |      glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); | 
| Mathias Agopian | 3221616 | 2009-10-28 02:09:21 -0700 | [diff] [blame] | 73 |      glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); | 
 | 74 |      glDisable(GL_DITHER); | 
 | 75 |      glDisable(GL_BLEND); | 
 | 76 |      glEnable(GL_TEXTURE_2D); | 
 | 77 |      glColor4f(1,1,1,1); | 
 | 78 |  | 
| Mathias Agopian | 6c7d04b | 2009-10-30 16:32:52 -0700 | [diff] [blame] | 79 |  | 
 | 80 |      // default pack-alignment is 4 | 
 | 81 |      const uint16_t t16[64] = { 0xFFFF, 0, 0xF800, 0, 0x07E0, 0, 0x001F, 0 }; | 
| Mathias Agopian | 3221616 | 2009-10-28 02:09:21 -0700 | [diff] [blame] | 82 |  | 
| Chih-Hung Hsieh | 3bded91 | 2014-12-11 10:39:59 -0800 | [diff] [blame] | 83 |      const GLfloat fh = h; | 
 | 84 |      const GLfloat fw2 = w/2; | 
| Mathias Agopian | 3221616 | 2009-10-28 02:09:21 -0700 | [diff] [blame] | 85 |      const GLfloat vertices[4][2] = { | 
| Chih-Hung Hsieh | 3bded91 | 2014-12-11 10:39:59 -0800 | [diff] [blame] | 86 |              { fw2,  0  }, | 
 | 87 |              { fw2,  fh } | 
| Mathias Agopian | 3221616 | 2009-10-28 02:09:21 -0700 | [diff] [blame] | 88 |      }; | 
 | 89 |  | 
 | 90 |      const GLfloat texCoords[4][2] = { | 
 | 91 |              { 0,  0 }, | 
| Mathias Agopian | 3810c2b | 2009-10-29 15:47:12 -0700 | [diff] [blame] | 92 |              { 1,  1 } | 
| Mathias Agopian | 3221616 | 2009-10-28 02:09:21 -0700 | [diff] [blame] | 93 |      }; | 
 | 94 |  | 
| Mathias Agopian | 3810c2b | 2009-10-29 15:47:12 -0700 | [diff] [blame] | 95 |      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 4, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, t16); | 
| Mathias Agopian | 3221616 | 2009-10-28 02:09:21 -0700 | [diff] [blame] | 96 |  | 
 | 97 |      glViewport(0, 0, w, h); | 
 | 98 |      glMatrixMode(GL_PROJECTION); | 
 | 99 |      glLoadIdentity(); | 
 | 100 |      glOrthof(0, w, 0, h, 0, 1); | 
 | 101 |  | 
 | 102 |      glEnableClientState(GL_VERTEX_ARRAY); | 
 | 103 |      glEnableClientState(GL_TEXTURE_COORD_ARRAY); | 
 | 104 |      glVertexPointer(2, GL_FLOAT, 0, vertices); | 
 | 105 |      glTexCoordPointer(2, GL_FLOAT, 0, texCoords); | 
 | 106 |  | 
 | 107 |      glClearColor(0,0,0,0); | 
 | 108 |      glClear(GL_COLOR_BUFFER_BIT); | 
 | 109 |      glDrawArrays(GL_LINES, 0, 2); | 
 | 110 |      eglSwapBuffers(dpy, surface); | 
 | 111 |  | 
 | 112 |      usleep(5*1000000); | 
 | 113 |  | 
 | 114 |      eglTerminate(dpy); | 
 | 115 |       | 
 | 116 |      return 0; | 
 | 117 | } |