132216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian/*
232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian**
332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** Copyright 2006, The Android Open Source Project
432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian**
532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** Licensed under the Apache License, Version 2.0 (the "License");
632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** you may not use this file except in compliance with the License.
732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** You may obtain a copy of the License at
832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian**
932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian**     http://www.apache.org/licenses/LICENSE-2.0
1032216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian**
1132216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** Unless required by applicable law or agreed to in writing, software
1232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** distributed under the License is distributed on an "AS IS" BASIS,
1332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** See the License for the specific language governing permissions and
1532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** limitations under the License.
1632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian*/
1732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
1832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian#define LOG_TAG "fillrate"
1932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
2032216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian#include <unistd.h>
2132216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian#include <stdlib.h>
2232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian#include <stdio.h>
2332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
2432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian#include <EGL/egl.h>
2532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian#include <GLES/gl.h>
2632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian#include <GLES/glext.h>
2732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
2832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian#include <utils/StopWatch.h>
2932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian#include <ui/FramebufferNativeWindow.h>
30870b8aa15cb5c722b5d8eb7726eaa5f1a7c23d69Mathias Agopian#include "EGLUtils.h"
3132216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
3232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopianusing namespace android;
3332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
3432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopianint main(int argc, char** argv)
3532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian{
3632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian    EGLint configAttribs[] = {
3732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian         EGL_DEPTH_SIZE, 0,
3832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian         EGL_NONE
3932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     };
4032216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
4132216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     EGLint majorVersion;
4232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     EGLint minorVersion;
4332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     EGLContext context;
4432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     EGLConfig config;
4532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     EGLSurface surface;
4632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     EGLint w, h;
4732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     EGLDisplay dpy;
4832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
4932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     EGLNativeWindowType window = android_createDisplaySurface();
5032216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
5132216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
5232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     eglInitialize(dpy, &majorVersion, &minorVersion);
5332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
5432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     status_t err = EGLUtils::selectConfigForNativeWindow(
5532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian             dpy, configAttribs, window, &config);
5632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     if (err) {
5732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian         fprintf(stderr, "couldn't find an EGLConfig matching the screen format\n");
5832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian         return 0;
5932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     }
6032216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
6132216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     surface = eglCreateWindowSurface(dpy, config, window, NULL);
6232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     context = eglCreateContext(dpy, config, NULL, NULL);
6332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     eglMakeCurrent(dpy, surface, surface, context);
6432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     eglQuerySurface(dpy, surface, EGL_WIDTH, &w);
6532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     eglQuerySurface(dpy, surface, EGL_HEIGHT, &h);
6632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
6732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     printf("w=%d, h=%d\n", w, h);
6832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
6932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     glBindTexture(GL_TEXTURE_2D, 0);
7032216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
716c7d04b1d038318a9fe3ba59ce2a748bd00578ebMathias Agopian     glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
723810c2b6c6216211a67f6240a8c520b1de4e409dMathias Agopian     glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
733810c2b6c6216211a67f6240a8c520b1de4e409dMathias Agopian     glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
7432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
7532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     glDisable(GL_DITHER);
7632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     glDisable(GL_BLEND);
7732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     glEnable(GL_TEXTURE_2D);
7832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     glColor4f(1,1,1,1);
7932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
806c7d04b1d038318a9fe3ba59ce2a748bd00578ebMathias Agopian
816c7d04b1d038318a9fe3ba59ce2a748bd00578ebMathias Agopian     // default pack-alignment is 4
826c7d04b1d038318a9fe3ba59ce2a748bd00578ebMathias Agopian     const uint16_t t16[64] = { 0xFFFF, 0, 0xF800, 0, 0x07E0, 0, 0x001F, 0 };
8332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
8432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     const GLfloat vertices[4][2] = {
853810c2b6c6216211a67f6240a8c520b1de4e409dMathias Agopian             { w/2,  0 },
863810c2b6c6216211a67f6240a8c520b1de4e409dMathias Agopian             { w/2,  h }
8732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     };
8832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
8932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     const GLfloat texCoords[4][2] = {
9032216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian             { 0,  0 },
913810c2b6c6216211a67f6240a8c520b1de4e409dMathias Agopian             { 1,  1 }
9232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     };
9332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
943810c2b6c6216211a67f6240a8c520b1de4e409dMathias Agopian     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 4, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, t16);
9532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
9632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     glViewport(0, 0, w, h);
9732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     glMatrixMode(GL_PROJECTION);
9832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     glLoadIdentity();
9932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     glOrthof(0, w, 0, h, 0, 1);
10032216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
10132216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     glEnableClientState(GL_VERTEX_ARRAY);
10232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     glEnableClientState(GL_TEXTURE_COORD_ARRAY);
10332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     glVertexPointer(2, GL_FLOAT, 0, vertices);
10432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
10532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
10632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     glClearColor(0,0,0,0);
10732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     glClear(GL_COLOR_BUFFER_BIT);
10832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     glDrawArrays(GL_LINES, 0, 2);
10932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     eglSwapBuffers(dpy, surface);
11032216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
11132216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     usleep(5*1000000);
11232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
11332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     eglTerminate(dpy);
11432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian
11532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian     return 0;
11632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian}
117