diff options
Diffstat (limited to 'opengl/tests')
-rw-r--r-- | opengl/tests/angeles/Android.mk | 2 | ||||
-rw-r--r-- | opengl/tests/angeles/app-linux.cpp (renamed from opengl/tests/angeles/app-linux.c) | 52 | ||||
-rw-r--r-- | opengl/tests/copybits/Android.mk | 18 | ||||
-rw-r--r-- | opengl/tests/copybits/copybits.cpp | 726 | ||||
-rw-r--r-- | opengl/tests/fillrate/Android.mk | 17 | ||||
-rw-r--r-- | opengl/tests/fillrate/fillrate.cpp | 161 | ||||
-rw-r--r-- | opengl/tests/filter/Android.mk | 4 | ||||
-rw-r--r-- | opengl/tests/filter/filter.cpp (renamed from opengl/tests/filter/filter.c) | 72 | ||||
-rw-r--r-- | opengl/tests/finish/Android.mk | 4 | ||||
-rw-r--r-- | opengl/tests/finish/finish.cpp (renamed from opengl/tests/finish/finish.c) | 40 | ||||
-rw-r--r-- | opengl/tests/swapinterval/Android.mk | 17 | ||||
-rw-r--r-- | opengl/tests/swapinterval/swapinterval.cpp | 121 | ||||
-rw-r--r-- | opengl/tests/textures/Android.mk | 4 | ||||
-rw-r--r-- | opengl/tests/textures/textures.cpp (renamed from opengl/tests/textures/textures.c) | 29 |
14 files changed, 1197 insertions, 70 deletions
diff --git a/opengl/tests/angeles/Android.mk b/opengl/tests/angeles/Android.mk index e193483..d0c3221 100644 --- a/opengl/tests/angeles/Android.mk +++ b/opengl/tests/angeles/Android.mk @@ -2,7 +2,7 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) -LOCAL_SRC_FILES:= app-linux.c demo.c.arm +LOCAL_SRC_FILES:= app-linux.cpp demo.c.arm LOCAL_SHARED_LIBRARIES := libEGL libGLESv1_CM libui LOCAL_MODULE:= angeles LOCAL_MODULE_TAGS := optional diff --git a/opengl/tests/angeles/app-linux.c b/opengl/tests/angeles/app-linux.cpp index 7d0d320..06fa0c2 100644 --- a/opengl/tests/angeles/app-linux.c +++ b/opengl/tests/angeles/app-linux.cpp @@ -52,6 +52,11 @@ #include <EGL/egl.h> #include <GLES/gl.h> +#include <ui/FramebufferNativeWindow.h> +#include <ui/EGLUtils.h> + +using namespace android; + #include "app.h" @@ -115,48 +120,33 @@ static void checkEGLErrors() static int initGraphics() { - EGLint s_configAttribs[] = { - EGL_RED_SIZE, 5, - EGL_GREEN_SIZE, 6, - EGL_BLUE_SIZE, 5, - #if 1 - EGL_DEPTH_SIZE, 16, - EGL_STENCIL_SIZE, 0, - #else - EGL_ALPHA_SIZE, EGL_DONT_CARE, - EGL_DEPTH_SIZE, EGL_DONT_CARE, - EGL_STENCIL_SIZE, EGL_DONT_CARE, - EGL_SURFACE_TYPE, EGL_DONT_CARE, - #endif + EGLint configAttribs[] = { + EGL_DEPTH_SIZE, 16, EGL_NONE }; - EGLint numConfigs = -1; EGLint majorVersion; EGLint minorVersion; - EGLConfig config; EGLContext context; + EGLConfig config; EGLSurface surface; - + EGLint w, h; EGLDisplay dpy; - dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); - egl_error("eglGetDisplay"); - fprintf(stderr,"dpy = 0x%08x\n", (unsigned) dpy); + EGLNativeWindowType window = android_createDisplaySurface(); + dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglInitialize(dpy, &majorVersion, &minorVersion); - egl_error("eglInitialize"); - - eglGetConfigs(dpy, NULL, 0, &numConfigs); - egl_error("eglGetConfigs"); - fprintf(stderr,"num configs %d\n", numConfigs); - - eglChooseConfig(dpy, s_configAttribs, &config, 1, &numConfigs); - egl_error("eglChooseConfig"); - - surface = eglCreateWindowSurface(dpy, config, - android_createDisplaySurface(), NULL); - egl_error("eglMapWindowSurface"); + + status_t err = EGLUtils::selectConfigForNativeWindow( + dpy, configAttribs, window, &config); + if (err) { + fprintf(stderr, "couldn't find an EGLConfig matching the screen format\n"); + return 0; + } + + surface = eglCreateWindowSurface(dpy, config, window, NULL); + egl_error("eglCreateWindowSurface"); fprintf(stderr,"surface = %p\n", surface); diff --git a/opengl/tests/copybits/Android.mk b/opengl/tests/copybits/Android.mk new file mode 100644 index 0000000..d5ded42 --- /dev/null +++ b/opengl/tests/copybits/Android.mk @@ -0,0 +1,18 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= \ + copybits.cpp + +LOCAL_SHARED_LIBRARIES := \ + libcutils \ + libEGL \ + libGLESv1_CM \ + libui + +LOCAL_MODULE:= test-opengl-copybits + +LOCAL_MODULE_TAGS := tests + +include $(BUILD_EXECUTABLE) + diff --git a/opengl/tests/copybits/copybits.cpp b/opengl/tests/copybits/copybits.cpp new file mode 100644 index 0000000..11dfb6e --- /dev/null +++ b/opengl/tests/copybits/copybits.cpp @@ -0,0 +1,726 @@ +// Test software OpenGL hardware accelleration using copybits. + +#define LOG_TAG "copybits_test" + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <sys/types.h> +#include <stdlib.h> +#include <string.h> +#include <sys/time.h> + +#include <ui/PixelFormat.h> + +#include <cutils/log.h> +#include <cutils/native_handle.h> + +#include <utils/Atomic.h> + +#include <private/ui/SurfaceBuffer.h> +#include <pixelflinger/pixelflinger.h> + +#include <hardware/gralloc.h> +#include <hardware/hardware.h> + +#include <ui/FramebufferNativeWindow.h> +#include <ui/EGLUtils.h> + +#define EGL_EGLEXT_PROTOTYPES +#define GL_GLEXT_PROTOTYPES + +#include <EGL/egl.h> +#include <EGL/eglext.h> + +#include <GLES/gl.h> +#include <GLES/glext.h> + +using namespace android; + +EGLDisplay eglDisplay; +EGLSurface eglSurface; +EGLContext eglContext; +GLuint texture; + +hw_module_t const* gralloc_module; +alloc_device_t *sAllocDev; + +#define FIXED_ONE 0x10000 /* 1.0 in 16.16 fixed point. */ + +int init_gl_surface(); +void free_gl_surface(); +void init_scene(); + +int create_physical_texture(); +int readTimer(); + +// =========================================================================== +// Buffer an implementation of android_native_buffer_t +// =========================================================================== + +class NativeBuffer; + +class Buffer : public android::SurfaceBuffer +{ +public: + // creates w * h buffer + Buffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage); + + // return status + status_t initCheck() const; + + uint32_t getWidth() const { return width; } + uint32_t getHeight() const { return height; } + uint32_t getStride() const { return stride; } + uint32_t getUsage() const { return usage; } + PixelFormat getPixelFormat() const { return format; } + + + android_native_buffer_t* getNativeBuffer() const; + + void setPixel(int x, int y, int r, int g, int b, int a); + + status_t lock(GGLSurface* surface, uint32_t usage); + void lock() { + GGLSurface s; + lock(&s, GRALLOC_USAGE_SW_WRITE_OFTEN); + mData = (void*)s.data; + } + +private: + friend class LightRefBase<Buffer>; + Buffer(const Buffer& rhs); + virtual ~Buffer(); + Buffer& operator = (const Buffer& rhs); + const Buffer& operator = (const Buffer& rhs) const; + + status_t initSize(uint32_t w, uint32_t h); + + ssize_t mInitCheck; + void* mData; +}; + +Buffer::Buffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage) + : SurfaceBuffer(), mInitCheck(NO_INIT) +{ + this->usage = usage; + this->format = format; + if (w>0 && h>0) { + mInitCheck = initSize(w, h); + } +} + +Buffer::~Buffer() +{ + if (handle) { + sAllocDev->free(sAllocDev, handle); + } +} + +status_t Buffer::initCheck() const { + return mInitCheck; +} + +android_native_buffer_t* Buffer::getNativeBuffer() const +{ + return static_cast<android_native_buffer_t*>(const_cast<Buffer*>(this)); +} + +status_t Buffer::initSize(uint32_t w, uint32_t h) +{ + status_t err = NO_ERROR; + + err = sAllocDev->alloc(sAllocDev, w, h, format, usage, &handle, &stride); + + if (err == NO_ERROR) { + if (err == NO_ERROR) { + width = w; + height = h; + } + } + + return err; +} + +status_t Buffer::lock(GGLSurface* sur, uint32_t usage) +{ + void* vaddr; + status_t res = SurfaceBuffer::lock(usage, &vaddr); + if (res == NO_ERROR && sur) { + sur->version = sizeof(GGLSurface); + sur->width = width; + sur->height = height; + sur->stride = stride; + sur->format = format; + sur->data = static_cast<GGLubyte*>(vaddr); + } + return res; +} + + +void Buffer::setPixel(int x, int y, int r, int g, int b, int a) { + if (x < 0 || (unsigned int) x >= width + || y < 0 || (unsigned int) y >= height) { + // clipped + return; + } + int index = stride * y + x; + switch (format) { + case HAL_PIXEL_FORMAT_RGB_565: { + unsigned short val = (unsigned short) ( + ((0x1f & (r >> 3)) << 11) + | ((0x3f & (g >> 2)) << 5) + | (0x1f & (b >> 3))); + ((unsigned short*) mData)[index]= val; + } + break; + case HAL_PIXEL_FORMAT_RGBA_8888: { // ABGR + unsigned int val = (unsigned int) + (((a & 0xff) << 24) + | ((b & 0xff) << 16) + | ((g & 0xff) << 8) + | (r & 0xff)); + ((unsigned int*) mData)[index] = val; + } + break; + default: + // Unsupported pixel format + break; + } +} + + +static void gluLookAt(float eyeX, float eyeY, float eyeZ, + float centerX, float centerY, float centerZ, float upX, float upY, + float upZ) +{ + // See the OpenGL GLUT documentation for gluLookAt for a description + // of the algorithm. We implement it in a straightforward way: + + float fx = centerX - eyeX; + float fy = centerY - eyeY; + float fz = centerZ - eyeZ; + + // Normalize f + float rlf = 1.0f / sqrtf(fx*fx + fy*fy + fz*fz); + fx *= rlf; + fy *= rlf; + fz *= rlf; + + // Normalize up + float rlup = 1.0f / sqrtf(upX*upX + upY*upY + upZ*upZ); + upX *= rlup; + upY *= rlup; + upZ *= rlup; + + // compute s = f x up (x means "cross product") + + float sx = fy * upZ - fz * upY; + float sy = fz * upX - fx * upZ; + float sz = fx * upY - fy * upX; + + // compute u = s x f + float ux = sy * fz - sz * fy; + float uy = sz * fx - sx * fz; + float uz = sx * fy - sy * fx; + + float m[16] ; + m[0] = sx; + m[1] = ux; + m[2] = -fx; + m[3] = 0.0f; + + m[4] = sy; + m[5] = uy; + m[6] = -fy; + m[7] = 0.0f; + + m[8] = sz; + m[9] = uz; + m[10] = -fz; + m[11] = 0.0f; + + m[12] = 0.0f; + m[13] = 0.0f; + m[14] = 0.0f; + m[15] = 1.0f; + + glMultMatrixf(m); + glTranslatef(-eyeX, -eyeY, -eyeZ); +} + +int init_gralloc() { + int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &gralloc_module); + LOGE_IF(err, "FATAL: can't find the %s module", GRALLOC_HARDWARE_MODULE_ID); + + if (err == 0) { + gralloc_open(gralloc_module, &sAllocDev); + } + return err; +} + +int init_gl_surface(void) +{ + EGLint numConfigs = 1; + EGLConfig myConfig = {0}; + EGLint attrib[] = + { + EGL_DEPTH_SIZE, 16, + EGL_NONE + }; + + EGLNativeWindowType window = android_createDisplaySurface(); + + printf("init_gl_surface\n"); + if ( (eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY ) + { + printf("eglGetDisplay failed\n"); + return 0; + } + + if ( eglInitialize(eglDisplay, NULL, NULL) != EGL_TRUE ) + { + printf("eglInitialize failed\n"); + return 0; + } + + if ( EGLUtils::selectConfigForNativeWindow(eglDisplay, attrib, window, &myConfig) != 0) + { + printf("EGLUtils::selectConfigForNativeWindow failed\n"); + return 0; + } + + + if ( (eglSurface = eglCreateWindowSurface(eglDisplay, myConfig, + window, 0)) == EGL_NO_SURFACE ) + { + printf("eglCreateWindowSurface failed\n"); + return 0; + } + + if ( (eglContext = eglCreateContext(eglDisplay, myConfig, 0, 0)) == EGL_NO_CONTEXT ) + { + printf("eglCreateContext failed\n"); + return 0; + } + + if ( eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext) != EGL_TRUE ) + { + printf("eglMakeCurrent failed\n"); + return 0; + } + +#if EGL_ANDROID_swap_rectangle + eglSetSwapRectangleANDROID(eglDisplay, eglSurface, 0, 0, 320, 480); +#endif + + return 1; +} + +void free_gl_surface(void) +{ + if (eglDisplay != EGL_NO_DISPLAY) + { + eglMakeCurrent( eglDisplay, EGL_NO_SURFACE, + EGL_NO_SURFACE, EGL_NO_CONTEXT ); + eglDestroyContext( eglDisplay, eglContext ); + eglDestroySurface( eglDisplay, eglSurface ); + eglTerminate( eglDisplay ); + eglDisplay = EGL_NO_DISPLAY; + } +} + +void init_scene(void) +{ + glDisable(GL_DITHER); + glEnable(GL_CULL_FACE); + float ratio = 320.0f / 480.0f; + glViewport(0, 0, 320, 480); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustumf(-ratio, ratio, -1, 1, 1, 10); + + glMatrixMode(GL_MODELVIEW); + + glLoadIdentity(); + gluLookAt( + 0, 0, 3, // eye + 0, 0, 0, // center + 0, 1, 0); // up + + glEnable(GL_TEXTURE_2D); +} + +// #define USE_ALPHA_COLOR + +#define USE_GL_REPLACE +//#define USE_GL_MODULATE + +// #define USE_BLEND + +#define USE_565 +// #define USE_8888 + +// #define USE_NEAREST +#define USE_LINEAR + +#define USE_SCALE + +void setSmoothGradient(Buffer* bufferObject) { + int pixels = bufferObject->getHeight() * bufferObject->getWidth(); + int step = 0; + for (unsigned int y = 0; y < bufferObject->getHeight(); y++) { + for(unsigned int x = 0; x < bufferObject->getWidth() ; x++) { + int grey = step * 255 / pixels; + bufferObject->setPixel(x, y, grey, grey, grey, 255); + ++step; + } + } +} + +void setSmoothAlphaGradient(Buffer* bufferObject) { + int pixels = bufferObject->getHeight() * bufferObject->getWidth(); + int step = 0; + for (unsigned int y = 0; y < bufferObject->getHeight(); y++) { + for(unsigned int x = 0; x < bufferObject->getWidth() ; x++) { + int grey = step * 255 / pixels; + bufferObject->setPixel(x, y, 255, 255, 255, grey); + ++step; + } + } +} + +void setOrientedCheckerboard(Buffer* bufferObject) { + bufferObject->setPixel(0, 0, 0, 0, 0, 255); + for(unsigned int x = 1; x < bufferObject->getWidth() ; x++) { + bufferObject->setPixel(x, 0, 0, 255, 0, 255); + } + for (unsigned int y = 1; y < bufferObject->getHeight(); y++) { + for(unsigned int x = 0; x < bufferObject->getWidth() ; x++) { + if ((x ^ y ) & 1) { + bufferObject->setPixel(x, y, 255, 255, 255, 255); + } else { + bufferObject->setPixel(x, y, 255, 0, 0, 255); + } + } + } +} + +int create_physical_texture(unsigned int w, unsigned int h) +{ + +#ifdef USE_565 + PixelFormat format = HAL_PIXEL_FORMAT_RGB_565; +#else + PixelFormat format = HAL_PIXEL_FORMAT_RGBA_8888; +#endif + int usage = GRALLOC_USAGE_SW_READ_OFTEN | + GRALLOC_USAGE_SW_WRITE_OFTEN | + GRALLOC_USAGE_HW_TEXTURE | + GRALLOC_USAGE_HW_2D; /* This is the key to allocating the texture in pmem. */ + int32_t stride; + buffer_handle_t handle; + + // Allocate the hardware buffer + Buffer* bufferObject = new Buffer(w, h, format, usage); + + android_native_buffer_t* buffer = bufferObject->getNativeBuffer(); + + buffer->common.incRef(&buffer->common); + + // create the new EGLImageKHR + EGLint attrs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_NONE }; + EGLDisplay dpy = eglGetCurrentDisplay(); + EGLImageKHR image = eglCreateImageKHR(dpy, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, + (EGLClientBuffer)buffer, attrs); + if (image == EGL_NO_IMAGE_KHR) { + printf("Could not create an image %d\n", eglGetError()); + return -1; + } + + bufferObject->lock(); + setOrientedCheckerboard(bufferObject); + // setSmoothGradient(bufferObject); + // setSmoothAlphaGradient(bufferObject); + bufferObject->unlock(); + + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); + glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image); +#ifdef USE_LINEAR + glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +#elif defined(USE_NEAREST) + glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); +#endif + +#ifdef USE_GL_REPLACE + glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); +#elif defined(USE_GL_MODULATE) + glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +#endif + +#ifdef USE_ALPHA_COLOR + glColor4f(1.0f, 1.0f, 1.0f, 0.4f); +#else + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); +#endif + +#ifdef USE_BLEND + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +#endif + return 0; +} + +static const int SCALE_COUNT = 12; + +int scale(int base, int factor) { + static const float kTable[SCALE_COUNT] = { + 0.24f, 0.25f, 0.5f, 0.75f, 1.0f, + 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 5.0f + }; + return base * kTable[factor]; +} + +class Timer { + struct timeval first; + double elapsedSeconds; + +public: + Timer() {} + void start() { + gettimeofday(&first, NULL); + } + + void stop() { + struct timeval second, + elapsed; + gettimeofday(&second, NULL); + + if (first.tv_usec > second.tv_usec) { + second.tv_usec += 1000000; + second.tv_sec--; + } + + elapsedSeconds = (second.tv_sec - first.tv_sec) + + (second.tv_usec - first.tv_usec) / 1000000.0; + } + + double getElapsedSeconds() { + return elapsedSeconds; + } + + double getElapsedMs() { + return elapsedSeconds* 1000.0f; + } +}; + +int testTime() +{ + static const int WIDTH = 320; + static const int HEIGHT = 480; + static const int SCALE = 8; + + if (create_physical_texture(WIDTH, HEIGHT) != 0) { + return -1; + } + // Need to do a dummy eglSwapBuffers first. Don't know why. + glClearColor(0.4, 1.0, 0.4, 0.4); + glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); + eglSwapBuffers(eglDisplay, eglSurface); + + glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); + +#if defined(USE_SCALE) + static const int scaleOffset = 0; +#else + static const int scaleOffset = 1; +#endif + printf("ms\n"); + for(int j = 0; j < SCALE; j++) { + int w = WIDTH >> (j + scaleOffset); + int h = HEIGHT >> j; + int cropRect[4] = {0,h,w,-h}; // Left bottom width height. Width and Height can be neg to flip. + glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect); + Timer timer; + timer.start(); + + int copyCount = 1000; + for (int i = 0; i < copyCount; i++) { + glDrawTexiOES(0, 0, 0, w, h); + } + + timer.stop(); + printf("%g\n", timer.getElapsedMs() / copyCount); + } + + eglSwapBuffers(eglDisplay, eglSurface); + return 0; +} + +int testStretch() +{ + static const int WIDTH = 8; + static const int HEIGHT = 8; + + if (create_physical_texture(WIDTH, HEIGHT) != 0) { + return -1; + } + // Need to do a dummy eglSwapBuffers first. Don't know why. + glClearColor(0.4, 1.0, 0.4, 1.0); + glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); + eglSwapBuffers(eglDisplay, eglSurface); + + int cropRect[4] = {0,HEIGHT,WIDTH,-HEIGHT}; // Left bottom width height. Width and Height can be neg to flip. + glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect); + + for(int frame = 0; frame < 2; frame++) { + glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); + int baseX = 10; + for (int x = 0; x < SCALE_COUNT; x++) { + int baseY = 10; + int width = scale(WIDTH, x); + for (int y = 0; y < SCALE_COUNT; y++) { + int height = scale(HEIGHT, y); + glDrawTexxOES(baseX << 16, baseY << 16, 0, width << 16, height << 16); + baseY += height + 10; + } + baseX += width + 10; + } + + eglSwapBuffers(eglDisplay, eglSurface); + LOGD("wait 1s"); + usleep(1000000); + } + return 0; +} + +int testRot90() +{ + static const int WIDTH = 8; + static const int HEIGHT = 8; + + if (create_physical_texture(WIDTH, HEIGHT) != 0) { + return -1; + } + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrthof(0, 320, 480, 0, 0, 1); + + glMatrixMode(GL_MODELVIEW); + + glLoadIdentity(); + + // Need to do a dummy eglSwapBuffers first. Don't know why. + glClearColor(0.4, 0.4, 0.4, 0.4); + glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); + eglSwapBuffers(eglDisplay, eglSurface); + + glEnable(GL_TEXTURE_2D); + glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glColor4x(0x10000, 0x10000, 0x10000, 0x10000); + glDisable(GL_BLEND); + glShadeModel(GL_FLAT); + glDisable(GL_DITHER); + glDisable(GL_CULL_FACE); + + for(int frame = 0; frame < 2; frame++) { + LOGD("frame = %d", frame); + glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); + int baseX = 10; + for (int x = 0; x < SCALE_COUNT; x++) { + int baseY = 10; + int width = scale(WIDTH, x); + for (int y = 0; y < SCALE_COUNT; y++) { + int height = scale(HEIGHT, y); + + // Code copied from SurfaceFlinger LayerBase.cpp + + const GLfixed texCoords[4][2] = { + { 0, 0 }, + { 0, 0x10000 }, + { 0x10000, 0x10000 }, + { 0x10000, 0 } + }; + + GLfixed fx = baseX << 16; + GLfixed fy = baseY << 16; + GLfixed fw = width << 16; + GLfixed fh = height << 16; + + /* + * Vertex pattern: + * (2)--(3) + * |\ | + * | \ | + * | \ | + * | \| + * (1)--(0) + * + */ + + const GLfixed vertices[4][2] = { + {fx + fw, fy}, + {fx, fy}, + {fx, fy + fh}, + {fx + fw, fy + fh} + }; + + static const bool rotate90 = true; + + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glVertexPointer(2, GL_FIXED, 0, vertices); + glTexCoordPointer(2, GL_FIXED, 0, texCoords); + + LOGD("testRot90 %d, %d %d, %d", baseX, baseY, width, height); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + baseY += height + 10; + } + baseX += width + 10; + } + + eglSwapBuffers(eglDisplay, eglSurface); + } + return 0; +} + +int main(int argc, char **argv) +{ + + int q; + int start, end; + + if (init_gralloc()) { + printf("gralloc initialization failed - exiting\n"); + return 0; + } + + printf("Initializing EGL...\n"); + + if(!init_gl_surface()) + { + printf("GL initialisation failed - exiting\n"); + return 0; + } + + init_scene(); + + printf("Start test...\n"); + // testTime(); + testStretch(); + //testRot90(); + free_gl_surface(); + + return 0; +} diff --git a/opengl/tests/fillrate/Android.mk b/opengl/tests/fillrate/Android.mk new file mode 100644 index 0000000..a7d30c2 --- /dev/null +++ b/opengl/tests/fillrate/Android.mk @@ -0,0 +1,17 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= \ + fillrate.cpp + +LOCAL_SHARED_LIBRARIES := \ + libcutils \ + libEGL \ + libGLESv1_CM \ + libui + +LOCAL_MODULE:= test-opengl-fillrate + +LOCAL_MODULE_TAGS := optional + +include $(BUILD_EXECUTABLE) diff --git a/opengl/tests/fillrate/fillrate.cpp b/opengl/tests/fillrate/fillrate.cpp new file mode 100644 index 0000000..911d354 --- /dev/null +++ b/opengl/tests/fillrate/fillrate.cpp @@ -0,0 +1,161 @@ +/* +** +** Copyright 2006, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +#define LOG_TAG "fillrate" + +#include <stdlib.h> +#include <stdio.h> + +#include <EGL/egl.h> +#include <GLES/gl.h> +#include <GLES/glext.h> + +#include <utils/StopWatch.h> +#include <ui/FramebufferNativeWindow.h> +#include <ui/EGLUtils.h> + +using namespace android; + +int main(int argc, char** argv) +{ + EGLint configAttribs[] = { + EGL_DEPTH_SIZE, 0, + EGL_NONE + }; + + EGLint majorVersion; + EGLint minorVersion; + EGLContext context; + EGLConfig config; + EGLSurface surface; + EGLint w, h; + EGLDisplay dpy; + + EGLNativeWindowType window = android_createDisplaySurface(); + + dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); + eglInitialize(dpy, &majorVersion, &minorVersion); + + status_t err = EGLUtils::selectConfigForNativeWindow( + dpy, configAttribs, window, &config); + if (err) { + fprintf(stderr, "couldn't find an EGLConfig matching the screen format\n"); + return 0; + } + + surface = eglCreateWindowSurface(dpy, config, window, NULL); + context = eglCreateContext(dpy, config, NULL, NULL); + eglMakeCurrent(dpy, surface, surface, context); + eglQuerySurface(dpy, surface, EGL_WIDTH, &w); + eglQuerySurface(dpy, surface, EGL_HEIGHT, &h); + + printf("w=%d, h=%d\n", w, h); + + glBindTexture(GL_TEXTURE_2D, 0); + glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_DITHER); + glEnable(GL_BLEND); + glEnable(GL_TEXTURE_2D); + glColor4f(1,1,1,1); + + uint32_t* t32 = (uint32_t*)malloc(512*512*4); + for (int y=0 ; y<512 ; y++) { + for (int x=0 ; x<512 ; x++) { + int u = x-256; + int v = y-256; + if (u*u+v*v < 256*256) { + t32[x+y*512] = 0x10FFFFFF; + } else { + t32[x+y*512] = 0x20FF0000; + } + } + } + + const GLfloat vertices[4][2] = { + { 0, 0 }, + { 0, h }, + { w, h }, + { w, 0 } + }; + + const GLfloat texCoords[4][2] = { + { 0, 0 }, + { 0, 1 }, + { 1, 1 }, + { 1, 0 } + }; + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, t32); + + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrthof(0, w, 0, h, 0, 1); + + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glVertexPointer(2, GL_FLOAT, 0, vertices); + glTexCoordPointer(2, GL_FLOAT, 0, texCoords); + + eglSwapInterval(dpy, 1); + + glClearColor(1,0,0,0); + glClear(GL_COLOR_BUFFER_BIT); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + eglSwapBuffers(dpy, surface); + + + nsecs_t times[32]; + + for (int c=1 ; c<32 ; c++) { + glClear(GL_COLOR_BUFFER_BIT); + for (int i=0 ; i<c ; i++) { + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + } + eglSwapBuffers(dpy, surface); + } + + + // for (int c=31 ; c>=1 ; c--) { + int j=0; + for (int c=1 ; c<32 ; c++) { + glClear(GL_COLOR_BUFFER_BIT); + nsecs_t now = systemTime(); + for (int i=0 ; i<c ; i++) { + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + } + eglSwapBuffers(dpy, surface); + nsecs_t t = systemTime() - now; + times[j++] = t; + } + + for (int c=1, j=0 ; c<32 ; c++, j++) { + nsecs_t t = times[j]; + printf("%lld\t%d\t%f\n", t, c, (double(t)/c)/1000000.0); + } + + + + eglTerminate(dpy); + + return 0; +} diff --git a/opengl/tests/filter/Android.mk b/opengl/tests/filter/Android.mk index 31b7d9a..a254127 100644 --- a/opengl/tests/filter/Android.mk +++ b/opengl/tests/filter/Android.mk @@ -2,7 +2,7 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ - filter.c + filter.cpp LOCAL_SHARED_LIBRARIES := \ libcutils \ @@ -14,4 +14,6 @@ LOCAL_MODULE:= test-opengl-filter LOCAL_MODULE_TAGS := optional +LOCAL_CFLAGS := -DGL_GLEXT_PROTOTYPES + include $(BUILD_EXECUTABLE) diff --git a/opengl/tests/filter/filter.c b/opengl/tests/filter/filter.cpp index de97119..2351909 100644 --- a/opengl/tests/filter/filter.c +++ b/opengl/tests/filter/filter.cpp @@ -5,6 +5,13 @@ #include <GLES/gl.h> #include <GLES/glext.h> +#include <ui/FramebufferNativeWindow.h> +#include <ui/EGLUtils.h> + +using namespace android; + +#define USE_DRAW_TEXTURE 1 + int main(int argc, char** argv) { if (argc!=2 && argc!=3) { @@ -32,14 +39,20 @@ int main(int argc, char** argv) EGLDisplay dpy; + EGLNativeWindowType window = 0; + if (!usePbuffer) { + window = android_createDisplaySurface(); + } + dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglInitialize(dpy, &majorVersion, &minorVersion); - eglChooseConfig(dpy, s_configAttribs, &config, 1, &numConfigs); if (!usePbuffer) { - surface = eglCreateWindowSurface(dpy, config, - android_createDisplaySurface(), NULL); + EGLUtils::selectConfigForNativeWindow( + dpy, s_configAttribs, window, &config); + surface = eglCreateWindowSurface(dpy, config, window, NULL); } else { printf("using pbuffer\n"); + eglChooseConfig(dpy, s_configAttribs, &config, 1, &numConfigs); EGLint attribs[] = { EGL_WIDTH, 320, EGL_HEIGHT, 480, EGL_NONE }; surface = eglCreatePbufferSurface(dpy, config, attribs); if (surface == EGL_NO_SURFACE) { @@ -52,6 +65,12 @@ int main(int argc, char** argv) eglQuerySurface(dpy, surface, EGL_HEIGHT, &h); GLint dim = w<h ? w : h; + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrthof(0, w, 0, h, 0, 1); + + glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT); GLint crop[4] = { 0, 4, 4, -4 }; @@ -117,14 +136,55 @@ int main(int argc, char** argv) break; } - glDrawTexiOES(0, 0, 0, dim, dim); + //glDrawTexiOES(0, 0, 0, dim, dim); + + const GLfloat vertices[4][2] = { + { 0, 0 }, + { 0, dim }, + { dim, dim }, + { dim, 0 } + }; + const GLfloat texCoords[4][2] = { + { 0, 0 }, + { 0, 1 }, + { 1, 1 }, + { 1, 0 } + }; + if (!usePbuffer) { eglSwapBuffers(dpy, surface); - } else { - glFinish(); } + glMatrixMode(GL_MODELVIEW); + glScissor(0,dim,dim,h-dim); + glDisable(GL_SCISSOR_TEST); + + for (int y=0 ; y<dim ; y++) { + //glDisable(GL_SCISSOR_TEST); + glClear(GL_COLOR_BUFFER_BIT); + + //glEnable(GL_SCISSOR_TEST); + +#if USE_DRAW_TEXTURE && GL_OES_draw_texture + glDrawTexiOES(0, y, 1, dim, dim); +#else + glLoadIdentity(); + glTranslatef(0, y, 0); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glVertexPointer(2, GL_FLOAT, 0, vertices); + glTexCoordPointer(2, GL_FLOAT, 0, texCoords); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); +#endif + + if (!usePbuffer) { + eglSwapBuffers(dpy, surface); + } else { + glFinish(); + } + } + eglTerminate(dpy); return 0; } diff --git a/opengl/tests/finish/Android.mk b/opengl/tests/finish/Android.mk index 8b46cd7..5620814 100644 --- a/opengl/tests/finish/Android.mk +++ b/opengl/tests/finish/Android.mk @@ -2,7 +2,7 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ - finish.c + finish.cpp LOCAL_SHARED_LIBRARIES := \ libcutils \ @@ -14,4 +14,6 @@ LOCAL_MODULE:= test-opengl-finish LOCAL_MODULE_TAGS := optional +LOCAL_CFLAGS := -DGL_GLEXT_PROTOTYPES + include $(BUILD_EXECUTABLE) diff --git a/opengl/tests/finish/finish.c b/opengl/tests/finish/finish.cpp index 45fc758..91f5c45 100644 --- a/opengl/tests/finish/finish.c +++ b/opengl/tests/finish/finish.cpp @@ -24,39 +24,41 @@ #include <GLES/gl.h> #include <GLES/glext.h> +#include <utils/Timers.h> -long long systemTime() -{ - struct timespec t; - t.tv_sec = t.tv_nsec = 0; - clock_gettime(CLOCK_MONOTONIC, &t); - return (long long)(t.tv_sec)*1000000000LL + t.tv_nsec; -} +#include <ui/FramebufferNativeWindow.h> +#include <ui/EGLUtils.h> + +using namespace android; int main(int argc, char** argv) { - EGLint s_configAttribs[] = { - EGL_RED_SIZE, 5, - EGL_GREEN_SIZE, 6, - EGL_BLUE_SIZE, 5, + EGLint configAttribs[] = { + EGL_DEPTH_SIZE, 0, EGL_NONE }; - EGLint numConfigs = -1; EGLint majorVersion; EGLint minorVersion; - EGLConfig config; EGLContext context; + EGLConfig config; EGLSurface surface; EGLint w, h; - EGLDisplay dpy; + EGLNativeWindowType window = android_createDisplaySurface(); + dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglInitialize(dpy, &majorVersion, &minorVersion); - eglChooseConfig(dpy, s_configAttribs, &config, 1, &numConfigs); - surface = eglCreateWindowSurface(dpy, config, - android_createDisplaySurface(), NULL); + + status_t err = EGLUtils::selectConfigForNativeWindow( + dpy, configAttribs, window, &config); + if (err) { + fprintf(stderr, "couldn't find an EGLConfig matching the screen format\n"); + return 0; + } + + surface = eglCreateWindowSurface(dpy, config, window, NULL); context = eglCreateContext(dpy, config, NULL, NULL); eglMakeCurrent(dpy, surface, surface, context); eglQuerySurface(dpy, surface, EGL_WIDTH, &w); @@ -75,13 +77,13 @@ int main(int argc, char** argv) long long now, t; int i; - char* texels = malloc(512*512*2); + char* texels = (char*)malloc(512*512*2); memset(texels,0xFF,512*512*2); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, texels); - char* dst = malloc(320*480*2); + char* dst = (char*)malloc(320*480*2); memset(dst, 0, 320*480*2); printf("307200 bytes memcpy\n"); for (i=0 ; i<4 ; i++) { diff --git a/opengl/tests/swapinterval/Android.mk b/opengl/tests/swapinterval/Android.mk new file mode 100644 index 0000000..619447c --- /dev/null +++ b/opengl/tests/swapinterval/Android.mk @@ -0,0 +1,17 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= \ + swapinterval.cpp + +LOCAL_SHARED_LIBRARIES := \ + libcutils \ + libEGL \ + libGLESv1_CM \ + libui + +LOCAL_MODULE:= test-opengl-swapinterval + +LOCAL_MODULE_TAGS := optional + +include $(BUILD_EXECUTABLE) diff --git a/opengl/tests/swapinterval/swapinterval.cpp b/opengl/tests/swapinterval/swapinterval.cpp new file mode 100644 index 0000000..df53b62 --- /dev/null +++ b/opengl/tests/swapinterval/swapinterval.cpp @@ -0,0 +1,121 @@ +/* + ** + ** Copyright 2006, The Android Open Source Project + ** + ** Licensed under the Apache License, Version 2.0 (the "License"); + ** you may not use this file except in compliance with the License. + ** You may obtain a copy of the License at + ** + ** http://www.apache.org/licenses/LICENSE-2.0 + ** + ** Unless required by applicable law or agreed to in writing, software + ** distributed under the License is distributed on an "AS IS" BASIS, + ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ** See the License for the specific language governing permissions and + ** limitations under the License. + */ + +#include <stdlib.h> +#include <stdio.h> + +#include <EGL/egl.h> +#include <GLES/gl.h> +#include <GLES/glext.h> + +#include <utils/StopWatch.h> +#include <ui/FramebufferNativeWindow.h> +#include <ui/EGLUtils.h> + +using namespace android; + +int main(int argc, char** argv) +{ + EGLint configAttribs[] = { + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_NONE + }; + + EGLint majorVersion; + EGLint minorVersion; + EGLContext context; + EGLConfig config; + EGLint numConfigs=0; + EGLSurface surface; + EGLint w, h; + EGLDisplay dpy; + + + EGLNativeWindowType window = android_createDisplaySurface(); + + dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); + eglInitialize(dpy, 0 ,0) ;//&majorVersion, &minorVersion); + eglGetConfigs(dpy, NULL, 0, &numConfigs); + printf("# configs = %d\n", numConfigs); + + status_t err = EGLUtils::selectConfigForNativeWindow( + dpy, configAttribs, window, &config); + if (err) { + fprintf(stderr, "couldn't find an EGLConfig matching the screen format\n"); + return 0; + } + + EGLint r,g,b,a; + eglGetConfigAttrib(dpy, config, EGL_RED_SIZE, &r); + eglGetConfigAttrib(dpy, config, EGL_GREEN_SIZE, &g); + eglGetConfigAttrib(dpy, config, EGL_BLUE_SIZE, &b); + eglGetConfigAttrib(dpy, config, EGL_ALPHA_SIZE, &a); + + surface = eglCreateWindowSurface(dpy, config, window, NULL); + if (surface == EGL_NO_SURFACE) { + EGLint err = eglGetError(); + fprintf(stderr, "%s, config=%p, format = %d-%d-%d-%d\n", + EGLUtils::strerror(err), config, r,g,b,a); + return 0; + } else { + printf("config=%p, format = %d-%d-%d-%d\n", config, r,g,b,a); + } + + context = eglCreateContext(dpy, config, NULL, NULL); + eglMakeCurrent(dpy, surface, surface, context); + eglQuerySurface(dpy, surface, EGL_WIDTH, &w); + eglQuerySurface(dpy, surface, EGL_HEIGHT, &h); + + printf("w=%d, h=%d\n", w, h); + + glDisable(GL_DITHER); + glEnable(GL_BLEND); + + glViewport(0, 0, w, h); + glOrthof(0, w, 0, h, 0, 1); + + eglSwapInterval(dpy, 1); + + glClearColor(1,0,0,0); + glClear(GL_COLOR_BUFFER_BIT); + eglSwapBuffers(dpy, surface); + + + int time = 10; + printf("screen should flash red/green quickly for %d s...\n", time); + + int c = 0; + nsecs_t start = systemTime(); + nsecs_t t; + do { + glClearColor(1,0,0,0); + glClear(GL_COLOR_BUFFER_BIT); + eglSwapBuffers(dpy, surface); + glClearColor(0,1,0,0); + glClear(GL_COLOR_BUFFER_BIT); + eglSwapBuffers(dpy, surface); + t = systemTime() - start; + c += 2; + } while (int(ns2s(t))<=time); + + double p = (double(t) / c) / 1000000000.0; + printf("refresh-rate is %f fps (%f ms)\n", 1.0f/p, p*1000.0); + + eglTerminate(dpy); + + return 0; +} diff --git a/opengl/tests/textures/Android.mk b/opengl/tests/textures/Android.mk index 8d5f56d..b2fa185 100644 --- a/opengl/tests/textures/Android.mk +++ b/opengl/tests/textures/Android.mk @@ -2,7 +2,7 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ - textures.c + textures.cpp LOCAL_SHARED_LIBRARIES := \ libcutils \ @@ -14,4 +14,6 @@ LOCAL_MODULE:= test-opengl-textures LOCAL_MODULE_TAGS := optional +LOCAL_CFLAGS := -DGL_GLEXT_PROTOTYPES + include $(BUILD_EXECUTABLE) diff --git a/opengl/tests/textures/textures.c b/opengl/tests/textures/textures.cpp index 214291b..cbe8ffd 100644 --- a/opengl/tests/textures/textures.c +++ b/opengl/tests/textures/textures.cpp @@ -22,30 +22,39 @@ #include <GLES/gl.h> #include <GLES/glext.h> +#include <ui/FramebufferNativeWindow.h> +#include <ui/EGLUtils.h> + +using namespace android; + int main(int argc, char** argv) { - EGLint s_configAttribs[] = { - EGL_RED_SIZE, 5, - EGL_GREEN_SIZE, 6, - EGL_BLUE_SIZE, 5, + EGLint configAttribs[] = { + EGL_DEPTH_SIZE, 0, EGL_NONE }; - EGLint numConfigs = -1; EGLint majorVersion; EGLint minorVersion; - EGLConfig config; EGLContext context; + EGLConfig config; EGLSurface surface; EGLint w, h; - EGLDisplay dpy; + EGLNativeWindowType window = android_createDisplaySurface(); + dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglInitialize(dpy, &majorVersion, &minorVersion); - eglChooseConfig(dpy, s_configAttribs, &config, 1, &numConfigs); - surface = eglCreateWindowSurface(dpy, config, - android_createDisplaySurface(), NULL); + + status_t err = EGLUtils::selectConfigForNativeWindow( + dpy, configAttribs, window, &config); + if (err) { + fprintf(stderr, "couldn't find an EGLConfig matching the screen format\n"); + return 0; + } + + surface = eglCreateWindowSurface(dpy, config, window, NULL); context = eglCreateContext(dpy, config, NULL, NULL); eglMakeCurrent(dpy, surface, surface, context); eglQuerySurface(dpy, surface, EGL_WIDTH, &w); |