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 | |
| 18 | #define LOG_TAG "fillrate" |
| 19 | |
| 20 | #include <unistd.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <stdio.h> |
| 23 | |
| 24 | #include <EGL/egl.h> |
| 25 | #include <GLES/gl.h> |
| 26 | #include <GLES/glext.h> |
| 27 | |
| 28 | #include <utils/StopWatch.h> |
| 29 | #include <ui/FramebufferNativeWindow.h> |
| 30 | #include <ui/EGLUtils.h> |
| 31 | |
| 32 | using namespace android; |
| 33 | |
| 34 | int main(int argc, char** argv) |
| 35 | { |
| 36 | EGLint configAttribs[] = { |
| 37 | EGL_DEPTH_SIZE, 0, |
| 38 | EGL_NONE |
| 39 | }; |
| 40 | |
| 41 | EGLint majorVersion; |
| 42 | EGLint minorVersion; |
| 43 | EGLContext context; |
| 44 | EGLConfig config; |
| 45 | EGLSurface surface; |
| 46 | EGLint w, h; |
| 47 | EGLDisplay dpy; |
| 48 | |
| 49 | EGLNativeWindowType window = android_createDisplaySurface(); |
| 50 | |
| 51 | dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 52 | eglInitialize(dpy, &majorVersion, &minorVersion); |
| 53 | |
| 54 | status_t err = EGLUtils::selectConfigForNativeWindow( |
| 55 | dpy, configAttribs, window, &config); |
| 56 | if (err) { |
| 57 | fprintf(stderr, "couldn't find an EGLConfig matching the screen format\n"); |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | surface = eglCreateWindowSurface(dpy, config, window, NULL); |
| 62 | context = eglCreateContext(dpy, config, NULL, NULL); |
| 63 | eglMakeCurrent(dpy, surface, surface, context); |
| 64 | eglQuerySurface(dpy, surface, EGL_WIDTH, &w); |
| 65 | eglQuerySurface(dpy, surface, EGL_HEIGHT, &h); |
| 66 | |
| 67 | printf("w=%d, h=%d\n", w, h); |
| 68 | |
| 69 | glBindTexture(GL_TEXTURE_2D, 0); |
| 70 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
Mathias Agopian | 6c7d04b | 2009-10-30 16:32:52 -0700 | [diff] [blame] | 71 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
Mathias Agopian | 3810c2b | 2009-10-29 15:47:12 -0700 | [diff] [blame] | 72 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 73 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
Mathias Agopian | 3221616 | 2009-10-28 02:09:21 -0700 | [diff] [blame] | 74 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 75 | glDisable(GL_DITHER); |
| 76 | glDisable(GL_BLEND); |
| 77 | glEnable(GL_TEXTURE_2D); |
| 78 | glColor4f(1,1,1,1); |
| 79 | |
Mathias Agopian | 6c7d04b | 2009-10-30 16:32:52 -0700 | [diff] [blame] | 80 | |
| 81 | // default pack-alignment is 4 |
| 82 | 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] | 83 | |
| 84 | const GLfloat vertices[4][2] = { |
Mathias Agopian | 3810c2b | 2009-10-29 15:47:12 -0700 | [diff] [blame] | 85 | { w/2, 0 }, |
| 86 | { w/2, h } |
Mathias Agopian | 3221616 | 2009-10-28 02:09:21 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | const GLfloat texCoords[4][2] = { |
| 90 | { 0, 0 }, |
Mathias Agopian | 3810c2b | 2009-10-29 15:47:12 -0700 | [diff] [blame] | 91 | { 1, 1 } |
Mathias Agopian | 3221616 | 2009-10-28 02:09:21 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
Mathias Agopian | 3810c2b | 2009-10-29 15:47:12 -0700 | [diff] [blame] | 94 | 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] | 95 | |
| 96 | glViewport(0, 0, w, h); |
| 97 | glMatrixMode(GL_PROJECTION); |
| 98 | glLoadIdentity(); |
| 99 | glOrthof(0, w, 0, h, 0, 1); |
| 100 | |
| 101 | glEnableClientState(GL_VERTEX_ARRAY); |
| 102 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 103 | glVertexPointer(2, GL_FLOAT, 0, vertices); |
| 104 | glTexCoordPointer(2, GL_FLOAT, 0, texCoords); |
| 105 | |
| 106 | glClearColor(0,0,0,0); |
| 107 | glClear(GL_COLOR_BUFFER_BIT); |
| 108 | glDrawArrays(GL_LINES, 0, 2); |
| 109 | eglSwapBuffers(dpy, surface); |
| 110 | |
| 111 | usleep(5*1000000); |
| 112 | |
| 113 | eglTerminate(dpy); |
| 114 | |
| 115 | return 0; |
| 116 | } |