1076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/*
2edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project**
3edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project** Copyright 2007 The Android Open Source Project
4edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project**
5076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian** Licensed under the Apache License Version 2.0(the "License");
6076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian** you may not use this file except in compliance with the License.
7076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian** You may obtain a copy of the License at
8edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project**
9076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian**     http://www.apache.org/licenses/LICENSE-2.0
10edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project**
11076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian** Unless required by applicable law or agreed to in writing software
12076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian** distributed under the License is distributed on an "AS IS" BASIS
13076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
14076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian** See the License for the specific language governing permissions and
15edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project** limitations under the License.
16edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project*/
17edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
18edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <assert.h>
19edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <errno.h>
20edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <stdlib.h>
21edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <stdio.h>
22edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <string.h>
23edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <unistd.h>
24edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <fcntl.h>
25edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <sys/ioctl.h>
26edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <sys/types.h>
27edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <sys/mman.h>
28edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
29edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <cutils/log.h>
30edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <cutils/atomic.h>
31edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
32edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <utils/threads.h>
335f2165f9455d4893b581b73a67c5431f4344b47eMathias Agopian#include <ui/ANativeObjectBase.h>
34d8e812ce6fe9ae0388e98b08456e1d18b9498239Jamie Gennis#include <ui/Fence.h>
35edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
36edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <EGL/egl.h>
37edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <EGL/eglext.h>
38edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <GLES/gl.h>
39edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <GLES/glext.h>
40edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
41edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <pixelflinger/format.h>
42edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <pixelflinger/pixelflinger.h>
43edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
44edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include "context.h"
45edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include "state.h"
46edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include "texture.h"
47edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include "matrix.h"
48edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
49edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#undef NELEM
50edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#define NELEM(x) (sizeof(x)/sizeof(*(x)))
51edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
525f2165f9455d4893b581b73a67c5431f4344b47eMathias Agopian// ----------------------------------------------------------------------------
534b9511c16195a646242eff833b0af212933b6ecaMathias Agopian
544b9511c16195a646242eff833b0af212933b6ecaMathias AgopianEGLBoolean EGLAPI eglSetSwapRectangleANDROID(EGLDisplay dpy, EGLSurface draw,
554b9511c16195a646242eff833b0af212933b6ecaMathias Agopian        EGLint left, EGLint top, EGLint width, EGLint height);
564b9511c16195a646242eff833b0af212933b6ecaMathias Agopian
57edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
58edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectnamespace android {
595f2165f9455d4893b581b73a67c5431f4344b47eMathias Agopian
60edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
61edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
62edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectconst unsigned int NUM_DISPLAYS = 1;
63edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
64edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic pthread_mutex_t gInitMutex = PTHREAD_MUTEX_INITIALIZER;
65edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic pthread_mutex_t gErrorKeyMutex = PTHREAD_MUTEX_INITIALIZER;
66edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic pthread_key_t gEGLErrorKey = -1;
67edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#ifndef HAVE_ANDROID_OS
68edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectnamespace gl {
69edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectpthread_key_t gGLKey = -1;
70edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}; // namespace gl
71edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#endif
72edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
73edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projecttemplate<typename T>
74edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic T setError(GLint error, T returnValue) {
75edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_unlikely(gEGLErrorKey == -1)) {
76edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        pthread_mutex_lock(&gErrorKeyMutex);
77edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (gEGLErrorKey == -1)
78edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            pthread_key_create(&gEGLErrorKey, NULL);
79edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        pthread_mutex_unlock(&gErrorKeyMutex);
80edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
81444839b842798497cfa326204285a4f2ca2362afColin Cross    pthread_setspecific(gEGLErrorKey, (void*)(uintptr_t)error);
82edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return returnValue;
83edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
84edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
85edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic GLint getError() {
86edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_unlikely(gEGLErrorKey == -1))
87edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return EGL_SUCCESS;
88444839b842798497cfa326204285a4f2ca2362afColin Cross    GLint error = (GLint)(uintptr_t)pthread_getspecific(gEGLErrorKey);
892076f35549c7c04035b9f626d9209e049b6c91f8Jamie Gennis    if (error == 0) {
902076f35549c7c04035b9f626d9209e049b6c91f8Jamie Gennis        // The TLS key has been created by another thread, but the value for
912076f35549c7c04035b9f626d9209e049b6c91f8Jamie Gennis        // this thread has not been initialized.
922076f35549c7c04035b9f626d9209e049b6c91f8Jamie Gennis        return EGL_SUCCESS;
932076f35549c7c04035b9f626d9209e049b6c91f8Jamie Gennis    }
94444839b842798497cfa326204285a4f2ca2362afColin Cross    pthread_setspecific(gEGLErrorKey, (void*)(uintptr_t)EGL_SUCCESS);
95edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return error;
96edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
97edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
98edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
99edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
100edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstruct egl_display_t
101edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
102edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    egl_display_t() : type(0), initialized(0) { }
103076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
104edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    static egl_display_t& get_display(EGLDisplay dpy);
105076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
106edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    static EGLBoolean is_valid(EGLDisplay dpy) {
107edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return ((uintptr_t(dpy)-1U) >= NUM_DISPLAYS) ? EGL_FALSE : EGL_TRUE;
108edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
109edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
110edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    NativeDisplayType   type;
111edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    volatile int32_t    initialized;
112edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
113edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
114edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic egl_display_t gDisplays[NUM_DISPLAYS];
115edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
116edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectegl_display_t& egl_display_t::get_display(EGLDisplay dpy) {
117edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return gDisplays[uintptr_t(dpy)-1U];
118edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
119edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
120edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstruct egl_context_t {
121edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    enum {
122edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        IS_CURRENT      =   0x00010000,
123edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        NEVER_CURRENT   =   0x00020000
124edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    };
125edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    uint32_t            flags;
126edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    EGLDisplay          dpy;
127edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    EGLConfig           config;
128edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    EGLSurface          read;
129edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    EGLSurface          draw;
130edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
131edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    static inline egl_context_t* context(EGLContext ctx) {
132edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        ogles_context_t* const gl = static_cast<ogles_context_t*>(ctx);
133edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return static_cast<egl_context_t*>(gl->rasterizer.base);
134edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
135edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
136edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
137edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
138edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
139edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstruct egl_surface_t
140edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
141edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    enum {
142edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        PAGE_FLIP = 0x00000001,
143edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        MAGIC     = 0x31415265
144edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    };
145edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
146edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    uint32_t            magic;
147edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    EGLDisplay          dpy;
148edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    EGLConfig           config;
149edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    EGLContext          ctx;
15078141e3acc9913153883fa337a0f3a5eff7acc64Jesse Hall    bool                zombie;
151edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
152edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                egl_surface_t(EGLDisplay dpy, EGLConfig config, int32_t depthFormat);
153edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     ~egl_surface_t();
1540696a572294bbaa977245afb630065de3278473bMathias Agopian                bool    isValid() const;
1550696a572294bbaa977245afb630065de3278473bMathias Agopian    virtual     bool    initCheck() const = 0;
156076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
157edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLBoolean  bindDrawSurface(ogles_context_t* gl) = 0;
158edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLBoolean  bindReadSurface(ogles_context_t* gl) = 0;
159cf81c84e43eb33931b950fa2c9b4c6f51afe7197Mathias Agopian    virtual     EGLBoolean  connect() { return EGL_TRUE; }
160e71212ba5397387100a578d23b15862518a7a859Mathias Agopian    virtual     void        disconnect() {}
161edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLint      getWidth() const = 0;
162edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLint      getHeight() const = 0;
163edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
164edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLint      getHorizontalResolution() const;
165edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLint      getVerticalResolution() const;
166edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLint      getRefreshRate() const;
167edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLint      getSwapBehavior() const;
168edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLBoolean  swapBuffers();
169df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    virtual     EGLBoolean  setSwapRectangle(EGLint l, EGLint t, EGLint w, EGLint h);
170edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectprotected:
171edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    GGLSurface              depth;
172edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
173edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
174edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectegl_surface_t::egl_surface_t(EGLDisplay dpy,
175edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        EGLConfig config,
176edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        int32_t depthFormat)
17778141e3acc9913153883fa337a0f3a5eff7acc64Jesse Hall    : magic(MAGIC), dpy(dpy), config(config), ctx(0), zombie(false)
178edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
179edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    depth.version = sizeof(GGLSurface);
180edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    depth.data = 0;
181edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    depth.format = depthFormat;
182edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
183edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectegl_surface_t::~egl_surface_t()
184edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
185edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    magic = 0;
186edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    free(depth.data);
187edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
1880696a572294bbaa977245afb630065de3278473bMathias Agopianbool egl_surface_t::isValid() const {
189e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block    ALOGE_IF(magic != MAGIC, "invalid EGLSurface (%p)", this);
1900696a572294bbaa977245afb630065de3278473bMathias Agopian    return magic == MAGIC;
1910696a572294bbaa977245afb630065de3278473bMathias Agopian}
1920696a572294bbaa977245afb630065de3278473bMathias Agopian
193edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source ProjectEGLBoolean egl_surface_t::swapBuffers() {
194edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return EGL_FALSE;
195edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
196edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source ProjectEGLint egl_surface_t::getHorizontalResolution() const {
197edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return (0 * EGL_DISPLAY_SCALING) * (1.0f / 25.4f);
198edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
199edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source ProjectEGLint egl_surface_t::getVerticalResolution() const {
200edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return (0 * EGL_DISPLAY_SCALING) * (1.0f / 25.4f);
201edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
202edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source ProjectEGLint egl_surface_t::getRefreshRate() const {
203edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return (60 * EGL_DISPLAY_SCALING);
204edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
205edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source ProjectEGLint egl_surface_t::getSwapBehavior() const {
206edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return EGL_BUFFER_PRESERVED;
207edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
208df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias AgopianEGLBoolean egl_surface_t::setSwapRectangle(
20992dc3fc52cf097bd105460cf377779bdcf146d62Mark Salyzyn        EGLint /*l*/, EGLint /*t*/, EGLint /*w*/, EGLint /*h*/)
210df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian{
211df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    return EGL_FALSE;
212df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian}
213edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
214edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
215edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
216076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopianstruct egl_window_surface_v2_t : public egl_surface_t
217edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
218076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    egl_window_surface_v2_t(
219edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            EGLDisplay dpy, EGLConfig config,
220edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            int32_t depthFormat,
2214b5e91e4820f03dba7dcc36e4b148331bc964b4bDianne Hackborn            ANativeWindow* window);
222edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
2230696a572294bbaa977245afb630065de3278473bMathias Agopian    ~egl_window_surface_v2_t();
224edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
2250696a572294bbaa977245afb630065de3278473bMathias Agopian    virtual     bool        initCheck() const { return true; } // TODO: report failure if ctor fails
226edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLBoolean  swapBuffers();
227edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLBoolean  bindDrawSurface(ogles_context_t* gl);
228edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLBoolean  bindReadSurface(ogles_context_t* gl);
229cf81c84e43eb33931b950fa2c9b4c6f51afe7197Mathias Agopian    virtual     EGLBoolean  connect();
230e71212ba5397387100a578d23b15862518a7a859Mathias Agopian    virtual     void        disconnect();
231cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian    virtual     EGLint      getWidth() const    { return width;  }
232cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian    virtual     EGLint      getHeight() const   { return height; }
233edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLint      getHorizontalResolution() const;
234edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLint      getVerticalResolution() const;
235edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLint      getRefreshRate() const;
236edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLint      getSwapBehavior() const;
237df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    virtual     EGLBoolean  setSwapRectangle(EGLint l, EGLint t, EGLint w, EGLint h);
2388d2e83b9f44c7f2207a312fcfda8eb3a4c26745fMathias Agopian
239edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectprivate:
240697526bc9e44ce61c88614f98387ae8bbf0a187eIliyan Malchev    status_t lock(ANativeWindowBuffer* buf, int usage, void** vaddr);
241697526bc9e44ce61c88614f98387ae8bbf0a187eIliyan Malchev    status_t unlock(ANativeWindowBuffer* buf);
2424b5e91e4820f03dba7dcc36e4b148331bc964b4bDianne Hackborn    ANativeWindow*   nativeWindow;
243697526bc9e44ce61c88614f98387ae8bbf0a187eIliyan Malchev    ANativeWindowBuffer*   buffer;
244697526bc9e44ce61c88614f98387ae8bbf0a187eIliyan Malchev    ANativeWindowBuffer*   previousBuffer;
2450926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian    gralloc_module_t const*    module;
246076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    int width;
247076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    int height;
248e71212ba5397387100a578d23b15862518a7a859Mathias Agopian    void* bits;
249df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    GGLFormat const* pixelFormatTable;
250df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian
251df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    struct Rect {
252df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        inline Rect() { };
253df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        inline Rect(int32_t w, int32_t h)
254df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian            : left(0), top(0), right(w), bottom(h) { }
255df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        inline Rect(int32_t l, int32_t t, int32_t r, int32_t b)
256df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian            : left(l), top(t), right(r), bottom(b) { }
257df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        Rect& andSelf(const Rect& r) {
258df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian            left   = max(left, r.left);
259df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian            top    = max(top, r.top);
260df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian            right  = min(right, r.right);
261df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian            bottom = min(bottom, r.bottom);
262df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian            return *this;
263df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        }
264df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        bool isEmpty() const {
265df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian            return (left>=right || top>=bottom);
266df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        }
267df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        void dump(char const* what) {
2689d4536835248525f32f1504a3d28d5bbfa0a2910Steve Block            ALOGD("%s { %5d, %5d, w=%5d, h=%5d }",
269df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                    what, left, top, right-left, bottom-top);
270df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        }
271df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian
272df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        int32_t left;
273df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        int32_t top;
274df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        int32_t right;
275df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        int32_t bottom;
276df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    };
277df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian
278df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    struct Region {
279df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        inline Region() : count(0) { }
280240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian        typedef Rect const* const_iterator;
281240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian        const_iterator begin() const { return storage; }
282240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian        const_iterator end() const { return storage+count; }
283df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        static Region subtract(const Rect& lhs, const Rect& rhs) {
284df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian            Region reg;
285df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian            Rect* storage = reg.storage;
286df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian            if (!lhs.isEmpty()) {
287df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                if (lhs.top < rhs.top) { // top rect
288df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                    storage->left   = lhs.left;
289df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                    storage->top    = lhs.top;
290df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                    storage->right  = lhs.right;
291240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                    storage->bottom = rhs.top;
292df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                    storage++;
293df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                }
294240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                const int32_t top = max(lhs.top, rhs.top);
295240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                const int32_t bot = min(lhs.bottom, rhs.bottom);
296240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                if (top < bot) {
297240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                    if (lhs.left < rhs.left) { // left-side rect
298240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                        storage->left   = lhs.left;
299240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                        storage->top    = top;
300240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                        storage->right  = rhs.left;
301240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                        storage->bottom = bot;
302240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                        storage++;
303240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                    }
304240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                    if (lhs.right > rhs.right) { // right-side rect
305240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                        storage->left   = rhs.right;
306240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                        storage->top    = top;
307240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                        storage->right  = lhs.right;
308240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                        storage->bottom = bot;
309240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                        storage++;
310240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                    }
311df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                }
312df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                if (lhs.bottom > rhs.bottom) { // bottom rect
313df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                    storage->left   = lhs.left;
314240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                    storage->top    = rhs.bottom;
315df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                    storage->right  = lhs.right;
316df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                    storage->bottom = lhs.bottom;
317df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                    storage++;
318df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                }
319df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                reg.count = storage - reg.storage;
320df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian            }
321df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian            return reg;
322df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        }
323df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        bool isEmpty() const {
324df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian            return count<=0;
325df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        }
326df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    private:
327df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        Rect storage[4];
328df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        ssize_t count;
329df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    };
330df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian
331df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    void copyBlt(
332697526bc9e44ce61c88614f98387ae8bbf0a187eIliyan Malchev            ANativeWindowBuffer* dst, void* dst_vaddr,
333697526bc9e44ce61c88614f98387ae8bbf0a187eIliyan Malchev            ANativeWindowBuffer* src, void const* src_vaddr,
334240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian            const Region& clip);
335df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian
336df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    Rect dirtyRegion;
337df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    Rect oldDirtyRegion;
338edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
339edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
340076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopianegl_window_surface_v2_t::egl_window_surface_v2_t(EGLDisplay dpy,
341edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        EGLConfig config,
342edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        int32_t depthFormat,
3434b5e91e4820f03dba7dcc36e4b148331bc964b4bDianne Hackborn        ANativeWindow* window)
3440926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian    : egl_surface_t(dpy, config, depthFormat),
345df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    nativeWindow(window), buffer(0), previousBuffer(0), module(0),
3469cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian    bits(NULL)
347edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
34869e43b71afb2af729657f6d26ffef142fedbafabMathias Agopian    hw_module_t const* pModule;
34969e43b71afb2af729657f6d26ffef142fedbafabMathias Agopian    hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &pModule);
35069e43b71afb2af729657f6d26ffef142fedbafabMathias Agopian    module = reinterpret_cast<gralloc_module_t const*>(pModule);
35169e43b71afb2af729657f6d26ffef142fedbafabMathias Agopian
352df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    pixelFormatTable = gglGetPixelFormatTable();
353df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian
354df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    // keep a reference on the window
355076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    nativeWindow->common.incRef(&nativeWindow->common);
356cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian    nativeWindow->query(nativeWindow, NATIVE_WINDOW_WIDTH, &width);
357cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian    nativeWindow->query(nativeWindow, NATIVE_WINDOW_HEIGHT, &height);
358cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian}
359076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
360cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopianegl_window_surface_v2_t::~egl_window_surface_v2_t() {
361cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian    if (buffer) {
362cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian        buffer->common.decRef(&buffer->common);
363cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian    }
364cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian    if (previousBuffer) {
365cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian        previousBuffer->common.decRef(&previousBuffer->common);
366cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian    }
367cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian    nativeWindow->common.decRef(&nativeWindow->common);
368cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian}
369cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian
370cf81c84e43eb33931b950fa2c9b4c6f51afe7197Mathias AgopianEGLBoolean egl_window_surface_v2_t::connect()
371cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian{
3725221271375f361b84a6eeec3d7086f223997fbb3Mathias Agopian    // we're intending to do software rendering
3735221271375f361b84a6eeec3d7086f223997fbb3Mathias Agopian    native_window_set_usage(nativeWindow,
3745221271375f361b84a6eeec3d7086f223997fbb3Mathias Agopian            GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
3755221271375f361b84a6eeec3d7086f223997fbb3Mathias Agopian
376df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    // dequeue a buffer
377d8e812ce6fe9ae0388e98b08456e1d18b9498239Jamie Gennis    int fenceFd = -1;
378d8e812ce6fe9ae0388e98b08456e1d18b9498239Jamie Gennis    if (nativeWindow->dequeueBuffer(nativeWindow, &buffer,
379d8e812ce6fe9ae0388e98b08456e1d18b9498239Jamie Gennis            &fenceFd) != NO_ERROR) {
380d8e812ce6fe9ae0388e98b08456e1d18b9498239Jamie Gennis        return setError(EGL_BAD_ALLOC, EGL_FALSE);
381d8e812ce6fe9ae0388e98b08456e1d18b9498239Jamie Gennis    }
382d8e812ce6fe9ae0388e98b08456e1d18b9498239Jamie Gennis
383d8e812ce6fe9ae0388e98b08456e1d18b9498239Jamie Gennis    // wait for the buffer
384d8e812ce6fe9ae0388e98b08456e1d18b9498239Jamie Gennis    sp<Fence> fence(new Fence(fenceFd));
385d8e812ce6fe9ae0388e98b08456e1d18b9498239Jamie Gennis    if (fence->wait(Fence::TIMEOUT_NEVER) != NO_ERROR) {
386d8e812ce6fe9ae0388e98b08456e1d18b9498239Jamie Gennis        nativeWindow->cancelBuffer(nativeWindow, buffer, fenceFd);
387cf81c84e43eb33931b950fa2c9b4c6f51afe7197Mathias Agopian        return setError(EGL_BAD_ALLOC, EGL_FALSE);
388cf81c84e43eb33931b950fa2c9b4c6f51afe7197Mathias Agopian    }
389df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian
390df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    // allocate a corresponding depth-buffer
391076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    width = buffer->width;
392076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    height = buffer->height;
393cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian    if (depth.format) {
394076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian        depth.width   = width;
395076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian        depth.height  = height;
396edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        depth.stride  = depth.width; // use the width here
397edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        depth.data    = (GGLubyte*)malloc(depth.stride*depth.height*2);
398edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (depth.data == 0) {
399cf81c84e43eb33931b950fa2c9b4c6f51afe7197Mathias Agopian            return setError(EGL_BAD_ALLOC, EGL_FALSE);
400edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        }
401edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
402076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
403df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    // keep a reference on the buffer
404076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    buffer->common.incRef(&buffer->common);
405df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian
406df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    // pin the buffer down
407df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    if (lock(buffer, GRALLOC_USAGE_SW_READ_OFTEN |
408df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian            GRALLOC_USAGE_SW_WRITE_OFTEN, &bits) != NO_ERROR) {
409e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block        ALOGE("connect() failed to lock buffer %p (%ux%u)",
410df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                buffer, buffer->width, buffer->height);
411cf81c84e43eb33931b950fa2c9b4c6f51afe7197Mathias Agopian        return setError(EGL_BAD_ACCESS, EGL_FALSE);
412df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        // FIXME: we should make sure we're not accessing the buffer anymore
413df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    }
414cf81c84e43eb33931b950fa2c9b4c6f51afe7197Mathias Agopian    return EGL_TRUE;
415e71212ba5397387100a578d23b15862518a7a859Mathias Agopian}
416e71212ba5397387100a578d23b15862518a7a859Mathias Agopian
417e71212ba5397387100a578d23b15862518a7a859Mathias Agopianvoid egl_window_surface_v2_t::disconnect()
418e71212ba5397387100a578d23b15862518a7a859Mathias Agopian{
4199648c1a2b9b527bcef64bb9d96e8385a14949840Mathias Agopian    if (buffer && bits) {
420e71212ba5397387100a578d23b15862518a7a859Mathias Agopian        bits = NULL;
421e71212ba5397387100a578d23b15862518a7a859Mathias Agopian        unlock(buffer);
422e71212ba5397387100a578d23b15862518a7a859Mathias Agopian    }
423cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian    if (buffer) {
4245f555569e757d280f707e2587b3d154c9d8c872fJesse Hall        nativeWindow->cancelBuffer(nativeWindow, buffer, -1);
425cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian        buffer->common.decRef(&buffer->common);
426cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian        buffer = 0;
427cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian    }
428cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian    if (previousBuffer) {
429cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian        previousBuffer->common.decRef(&previousBuffer->common);
430cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian        previousBuffer = 0;
431cb6b9041647b4f080324742eee5ce709960ff610Mathias Agopian    }
432edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
433076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
4340926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopianstatus_t egl_window_surface_v2_t::lock(
435697526bc9e44ce61c88614f98387ae8bbf0a187eIliyan Malchev        ANativeWindowBuffer* buf, int usage, void** vaddr)
4360926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian{
437bc4929117d0b07fec2f0986f38641eecc9f20d55Mathias Agopian    int err;
438695b66f082033d618ce19ee289d858130bd5420bMathias Agopian
439695b66f082033d618ce19ee289d858130bd5420bMathias Agopian    err = module->lock(module, buf->handle,
440695b66f082033d618ce19ee289d858130bd5420bMathias Agopian            usage, 0, 0, buf->width, buf->height, vaddr);
441695b66f082033d618ce19ee289d858130bd5420bMathias Agopian
4420926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian    return err;
4430926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian}
4440926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian
445697526bc9e44ce61c88614f98387ae8bbf0a187eIliyan Malchevstatus_t egl_window_surface_v2_t::unlock(ANativeWindowBuffer* buf)
4460926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian{
447cf81c84e43eb33931b950fa2c9b4c6f51afe7197Mathias Agopian    if (!buf) return BAD_VALUE;
448bc4929117d0b07fec2f0986f38641eecc9f20d55Mathias Agopian    int err = NO_ERROR;
449695b66f082033d618ce19ee289d858130bd5420bMathias Agopian
450695b66f082033d618ce19ee289d858130bd5420bMathias Agopian    err = module->unlock(module, buf->handle);
451695b66f082033d618ce19ee289d858130bd5420bMathias Agopian
4520926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian    return err;
4530926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian}
4540926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian
455df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopianvoid egl_window_surface_v2_t::copyBlt(
456697526bc9e44ce61c88614f98387ae8bbf0a187eIliyan Malchev        ANativeWindowBuffer* dst, void* dst_vaddr,
457697526bc9e44ce61c88614f98387ae8bbf0a187eIliyan Malchev        ANativeWindowBuffer* src, void const* src_vaddr,
458240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian        const Region& clip)
459df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian{
460df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    // NOTE: dst and src must be the same format
461df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian
4629cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian    Region::const_iterator cur = clip.begin();
4639cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian    Region::const_iterator end = clip.end();
4649cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian
4659cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian    const size_t bpp = pixelFormatTable[src->format].size;
4669cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian    const size_t dbpr = dst->stride * bpp;
4679cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian    const size_t sbpr = src->stride * bpp;
4689cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian
4699cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian    uint8_t const * const src_bits = (uint8_t const *)src_vaddr;
4709cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian    uint8_t       * const dst_bits = (uint8_t       *)dst_vaddr;
4719cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian
4729cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian    while (cur != end) {
4739cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian        const Rect& r(*cur++);
4749cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian        ssize_t w = r.right - r.left;
4759cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian        ssize_t h = r.bottom - r.top;
4769cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian        if (w <= 0 || h<=0) continue;
4779cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian        size_t size = w * bpp;
4789cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian        uint8_t const * s = src_bits + (r.left + src->stride * r.top) * bpp;
4799cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian        uint8_t       * d = dst_bits + (r.left + dst->stride * r.top) * bpp;
4809cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian        if (dbpr==sbpr && size==sbpr) {
4819cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian            size *= h;
4829cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian            h = 1;
483df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        }
4849cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian        do {
4859cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian            memcpy(d, s, size);
4869cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian            d += dbpr;
4879cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian            s += sbpr;
4889cdb01da71934e98b6732db0f5758ea4edd5d5c7Mathias Agopian        } while (--h > 0);
489076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    }
490edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
491edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
492076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias AgopianEGLBoolean egl_window_surface_v2_t::swapBuffers()
493edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
494cf81c84e43eb33931b950fa2c9b4c6f51afe7197Mathias Agopian    if (!buffer) {
495cf81c84e43eb33931b950fa2c9b4c6f51afe7197Mathias Agopian        return setError(EGL_BAD_ACCESS, EGL_FALSE);
496cf81c84e43eb33931b950fa2c9b4c6f51afe7197Mathias Agopian    }
497cf81c84e43eb33931b950fa2c9b4c6f51afe7197Mathias Agopian
498df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    /*
499df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian     * Handle eglSetSwapRectangleANDROID()
500df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian     * We copyback from the front buffer
501df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian     */
502df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    if (!dirtyRegion.isEmpty()) {
503df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        dirtyRegion.andSelf(Rect(buffer->width, buffer->height));
504df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        if (previousBuffer) {
50572c384e0a16504638927fea2da36a4731953c8dfKristian Monsen            // This was const Region copyBack, but that causes an
50672c384e0a16504638927fea2da36a4731953c8dfKristian Monsen            // internal compile error on simulator builds
50772c384e0a16504638927fea2da36a4731953c8dfKristian Monsen            /*const*/ Region copyBack(Region::subtract(oldDirtyRegion, dirtyRegion));
508df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian            if (!copyBack.isEmpty()) {
509df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                void* prevBits;
510df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                if (lock(previousBuffer,
511240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                        GRALLOC_USAGE_SW_READ_OFTEN, &prevBits) == NO_ERROR) {
512240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                    // copy from previousBuffer to buffer
513240c9fe59e9db5807c88796f60889acc44ba845cMathias Agopian                    copyBlt(buffer, bits, previousBuffer, prevBits, copyBack);
514df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                    unlock(previousBuffer);
515df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian                }
516df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian            }
517df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        }
518df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        oldDirtyRegion = dirtyRegion;
519df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    }
520076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
521df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    if (previousBuffer) {
522df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        previousBuffer->common.decRef(&previousBuffer->common);
523df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        previousBuffer = 0;
524df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    }
525076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
5260926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian    unlock(buffer);
527df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    previousBuffer = buffer;
528d8e812ce6fe9ae0388e98b08456e1d18b9498239Jamie Gennis    nativeWindow->queueBuffer(nativeWindow, buffer, -1);
529df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    buffer = 0;
530076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
531df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    // dequeue a new buffer
532d8e812ce6fe9ae0388e98b08456e1d18b9498239Jamie Gennis    int fenceFd = -1;
533d8e812ce6fe9ae0388e98b08456e1d18b9498239Jamie Gennis    if (nativeWindow->dequeueBuffer(nativeWindow, &buffer, &fenceFd) == NO_ERROR) {
534d8e812ce6fe9ae0388e98b08456e1d18b9498239Jamie Gennis        sp<Fence> fence(new Fence(fenceFd));
535d8e812ce6fe9ae0388e98b08456e1d18b9498239Jamie Gennis        if (fence->wait(Fence::TIMEOUT_NEVER)) {
536d8e812ce6fe9ae0388e98b08456e1d18b9498239Jamie Gennis            nativeWindow->cancelBuffer(nativeWindow, buffer, fenceFd);
537d8e812ce6fe9ae0388e98b08456e1d18b9498239Jamie Gennis            return setError(EGL_BAD_ALLOC, EGL_FALSE);
538d8e812ce6fe9ae0388e98b08456e1d18b9498239Jamie Gennis        }
539031213e5b31c317135f603271333949dda89e01eMathias Agopian
540031213e5b31c317135f603271333949dda89e01eMathias Agopian        // reallocate the depth-buffer if needed
541031213e5b31c317135f603271333949dda89e01eMathias Agopian        if ((width != buffer->width) || (height != buffer->height)) {
542031213e5b31c317135f603271333949dda89e01eMathias Agopian            // TODO: we probably should reset the swap rect here
543031213e5b31c317135f603271333949dda89e01eMathias Agopian            // if the window size has changed
544031213e5b31c317135f603271333949dda89e01eMathias Agopian            width = buffer->width;
545031213e5b31c317135f603271333949dda89e01eMathias Agopian            height = buffer->height;
546031213e5b31c317135f603271333949dda89e01eMathias Agopian            if (depth.data) {
547031213e5b31c317135f603271333949dda89e01eMathias Agopian                free(depth.data);
548031213e5b31c317135f603271333949dda89e01eMathias Agopian                depth.width   = width;
549031213e5b31c317135f603271333949dda89e01eMathias Agopian                depth.height  = height;
550031213e5b31c317135f603271333949dda89e01eMathias Agopian                depth.stride  = buffer->stride;
551031213e5b31c317135f603271333949dda89e01eMathias Agopian                depth.data    = (GGLubyte*)malloc(depth.stride*depth.height*2);
552031213e5b31c317135f603271333949dda89e01eMathias Agopian                if (depth.data == 0) {
553031213e5b31c317135f603271333949dda89e01eMathias Agopian                    setError(EGL_BAD_ALLOC, EGL_FALSE);
554031213e5b31c317135f603271333949dda89e01eMathias Agopian                    return EGL_FALSE;
555031213e5b31c317135f603271333949dda89e01eMathias Agopian                }
556edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            }
557edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        }
558df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian
559031213e5b31c317135f603271333949dda89e01eMathias Agopian        // keep a reference on the buffer
560031213e5b31c317135f603271333949dda89e01eMathias Agopian        buffer->common.incRef(&buffer->common);
561031213e5b31c317135f603271333949dda89e01eMathias Agopian
562031213e5b31c317135f603271333949dda89e01eMathias Agopian        // finally pin the buffer down
563031213e5b31c317135f603271333949dda89e01eMathias Agopian        if (lock(buffer, GRALLOC_USAGE_SW_READ_OFTEN |
564031213e5b31c317135f603271333949dda89e01eMathias Agopian                GRALLOC_USAGE_SW_WRITE_OFTEN, &bits) != NO_ERROR) {
565e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block            ALOGE("eglSwapBuffers() failed to lock buffer %p (%ux%u)",
566031213e5b31c317135f603271333949dda89e01eMathias Agopian                    buffer, buffer->width, buffer->height);
567031213e5b31c317135f603271333949dda89e01eMathias Agopian            return setError(EGL_BAD_ACCESS, EGL_FALSE);
568031213e5b31c317135f603271333949dda89e01eMathias Agopian            // FIXME: we should make sure we're not accessing the buffer anymore
569031213e5b31c317135f603271333949dda89e01eMathias Agopian        }
570031213e5b31c317135f603271333949dda89e01eMathias Agopian    } else {
571031213e5b31c317135f603271333949dda89e01eMathias Agopian        return setError(EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
572df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    }
573df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian
574df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    return EGL_TRUE;
575df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian}
576df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian
577df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias AgopianEGLBoolean egl_window_surface_v2_t::setSwapRectangle(
578df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        EGLint l, EGLint t, EGLint w, EGLint h)
579df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian{
580df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    dirtyRegion = Rect(l, t, l+w, t+h);
581edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return EGL_TRUE;
582edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
583edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
584076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias AgopianEGLBoolean egl_window_surface_v2_t::bindDrawSurface(ogles_context_t* gl)
585edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
586edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    GGLSurface buffer;
587edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    buffer.version = sizeof(GGLSurface);
588076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    buffer.width   = this->buffer->width;
589076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    buffer.height  = this->buffer->height;
590076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    buffer.stride  = this->buffer->stride;
591e71212ba5397387100a578d23b15862518a7a859Mathias Agopian    buffer.data    = (GGLubyte*)bits;
592076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    buffer.format  = this->buffer->format;
593edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    gl->rasterizer.procs.colorBuffer(gl, &buffer);
594edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (depth.data != gl->rasterizer.state.buffers.depth.data)
595edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        gl->rasterizer.procs.depthBuffer(gl, &depth);
5960a3139a21e628093893bba8ca0bb0b4742e0522cMathias Agopian
597edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return EGL_TRUE;
598edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
599076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias AgopianEGLBoolean egl_window_surface_v2_t::bindReadSurface(ogles_context_t* gl)
600edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
601edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    GGLSurface buffer;
602edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    buffer.version = sizeof(GGLSurface);
603076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    buffer.width   = this->buffer->width;
604076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    buffer.height  = this->buffer->height;
605076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    buffer.stride  = this->buffer->stride;
606e71212ba5397387100a578d23b15862518a7a859Mathias Agopian    buffer.data    = (GGLubyte*)bits; // FIXME: hopefully is is LOCKED!!!
607076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    buffer.format  = this->buffer->format;
608edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    gl->rasterizer.procs.readBuffer(gl, &buffer);
609edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return EGL_TRUE;
610edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
611076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias AgopianEGLint egl_window_surface_v2_t::getHorizontalResolution() const {
612edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return (nativeWindow->xdpi * EGL_DISPLAY_SCALING) * (1.0f / 25.4f);
613edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
614076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias AgopianEGLint egl_window_surface_v2_t::getVerticalResolution() const {
615edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return (nativeWindow->ydpi * EGL_DISPLAY_SCALING) * (1.0f / 25.4f);
616edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
617076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias AgopianEGLint egl_window_surface_v2_t::getRefreshRate() const {
618076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    return (60 * EGL_DISPLAY_SCALING); // FIXME
619edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
620df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias AgopianEGLint egl_window_surface_v2_t::getSwapBehavior() const
621df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian{
622df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian    /*
623df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian     * EGL_BUFFER_PRESERVED means that eglSwapBuffers() completely preserves
624df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian     * the content of the swapped buffer.
625df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian     *
626df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian     * EGL_BUFFER_DESTROYED means that the content of the buffer is lost.
627df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian     *
628df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian     * However when ANDROID_swap_retcangle is supported, EGL_BUFFER_DESTROYED
629df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian     * only applies to the area specified by eglSetSwapRectangleANDROID(), that
630df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian     * is, everything outside of this area is preserved.
631df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian     *
632df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian     * This implementation of EGL assumes the later case.
633df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian     *
634df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian     */
635df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian
636076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    return EGL_BUFFER_DESTROYED;
637edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
638edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
639edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
640edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
641edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstruct egl_pixmap_surface_t : public egl_surface_t
642edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
643edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    egl_pixmap_surface_t(
644edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            EGLDisplay dpy, EGLConfig config,
645edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            int32_t depthFormat,
646edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            egl_native_pixmap_t const * pixmap);
647edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
648edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual ~egl_pixmap_surface_t() { }
649edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
6500696a572294bbaa977245afb630065de3278473bMathias Agopian    virtual     bool        initCheck() const { return !depth.format || depth.data!=0; }
651edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLBoolean  bindDrawSurface(ogles_context_t* gl);
652edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLBoolean  bindReadSurface(ogles_context_t* gl);
653edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLint      getWidth() const    { return nativePixmap.width;  }
654edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLint      getHeight() const   { return nativePixmap.height; }
655edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectprivate:
656edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    egl_native_pixmap_t     nativePixmap;
657edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
658edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
659edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectegl_pixmap_surface_t::egl_pixmap_surface_t(EGLDisplay dpy,
660edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        EGLConfig config,
661edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        int32_t depthFormat,
662edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        egl_native_pixmap_t const * pixmap)
663edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    : egl_surface_t(dpy, config, depthFormat), nativePixmap(*pixmap)
664edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
665edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (depthFormat) {
666edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        depth.width   = pixmap->width;
667edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        depth.height  = pixmap->height;
668edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        depth.stride  = depth.width; // use the width here
669edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        depth.data    = (GGLubyte*)malloc(depth.stride*depth.height*2);
670edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (depth.data == 0) {
671edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            setError(EGL_BAD_ALLOC, EGL_NO_SURFACE);
672edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        }
673edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
674edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
675edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source ProjectEGLBoolean egl_pixmap_surface_t::bindDrawSurface(ogles_context_t* gl)
676edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
677edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    GGLSurface buffer;
678edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    buffer.version = sizeof(GGLSurface);
679edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    buffer.width   = nativePixmap.width;
680edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    buffer.height  = nativePixmap.height;
681edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    buffer.stride  = nativePixmap.stride;
682edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    buffer.data    = nativePixmap.data;
683edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    buffer.format  = nativePixmap.format;
684076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
685edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    gl->rasterizer.procs.colorBuffer(gl, &buffer);
686edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (depth.data != gl->rasterizer.state.buffers.depth.data)
687edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        gl->rasterizer.procs.depthBuffer(gl, &depth);
688edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return EGL_TRUE;
689edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
690edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source ProjectEGLBoolean egl_pixmap_surface_t::bindReadSurface(ogles_context_t* gl)
691edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
692edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    GGLSurface buffer;
693edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    buffer.version = sizeof(GGLSurface);
694edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    buffer.width   = nativePixmap.width;
695edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    buffer.height  = nativePixmap.height;
696edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    buffer.stride  = nativePixmap.stride;
697edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    buffer.data    = nativePixmap.data;
698edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    buffer.format  = nativePixmap.format;
699edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    gl->rasterizer.procs.readBuffer(gl, &buffer);
700edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return EGL_TRUE;
701edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
702edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
703edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
704edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
705edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstruct egl_pbuffer_surface_t : public egl_surface_t
706edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
707edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    egl_pbuffer_surface_t(
708edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            EGLDisplay dpy, EGLConfig config, int32_t depthFormat,
709edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            int32_t w, int32_t h, int32_t f);
710edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
711edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual ~egl_pbuffer_surface_t();
712edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
7130696a572294bbaa977245afb630065de3278473bMathias Agopian    virtual     bool        initCheck() const   { return pbuffer.data != 0; }
714edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLBoolean  bindDrawSurface(ogles_context_t* gl);
715edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLBoolean  bindReadSurface(ogles_context_t* gl);
716edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLint      getWidth() const    { return pbuffer.width;  }
717edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     EGLint      getHeight() const   { return pbuffer.height; }
718edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectprivate:
719edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    GGLSurface  pbuffer;
720edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
721edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
722edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectegl_pbuffer_surface_t::egl_pbuffer_surface_t(EGLDisplay dpy,
723edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        EGLConfig config, int32_t depthFormat,
724edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        int32_t w, int32_t h, int32_t f)
725edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    : egl_surface_t(dpy, config, depthFormat)
726edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
727edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    size_t size = w*h;
728edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    switch (f) {
729edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        case GGL_PIXEL_FORMAT_A_8:          size *= 1; break;
730edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        case GGL_PIXEL_FORMAT_RGB_565:      size *= 2; break;
731edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        case GGL_PIXEL_FORMAT_RGBA_8888:    size *= 4; break;
7328b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian        case GGL_PIXEL_FORMAT_RGBX_8888:    size *= 4; break;
733edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        default:
734e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block            ALOGE("incompatible pixel format for pbuffer (format=%d)", f);
735edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            pbuffer.data = 0;
736edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            break;
737edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
738edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    pbuffer.version = sizeof(GGLSurface);
739edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    pbuffer.width   = w;
740edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    pbuffer.height  = h;
741edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    pbuffer.stride  = w;
742edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    pbuffer.data    = (GGLubyte*)malloc(size);
743edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    pbuffer.format  = f;
744076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
745edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (depthFormat) {
746edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        depth.width   = pbuffer.width;
747edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        depth.height  = pbuffer.height;
748edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        depth.stride  = depth.width; // use the width here
749edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        depth.data    = (GGLubyte*)malloc(depth.stride*depth.height*2);
750edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (depth.data == 0) {
751edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            setError(EGL_BAD_ALLOC, EGL_NO_SURFACE);
752edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            return;
753edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        }
754edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
755edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
756edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectegl_pbuffer_surface_t::~egl_pbuffer_surface_t() {
757edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    free(pbuffer.data);
758edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
759edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source ProjectEGLBoolean egl_pbuffer_surface_t::bindDrawSurface(ogles_context_t* gl)
760edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
761edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    gl->rasterizer.procs.colorBuffer(gl, &pbuffer);
762edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (depth.data != gl->rasterizer.state.buffers.depth.data)
763edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        gl->rasterizer.procs.depthBuffer(gl, &depth);
764edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return EGL_TRUE;
765edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
766edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source ProjectEGLBoolean egl_pbuffer_surface_t::bindReadSurface(ogles_context_t* gl)
767edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
768edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    gl->rasterizer.procs.readBuffer(gl, &pbuffer);
769edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return EGL_TRUE;
770edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
771edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
772edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
773edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
774edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstruct config_pair_t {
775edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    GLint key;
776edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    GLint value;
777edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
778edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
779edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstruct configs_t {
780edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const config_pair_t* array;
781edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    int                  size;
782edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
783edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
784edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstruct config_management_t {
785edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    GLint key;
786edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    bool (*match)(GLint reqValue, GLint confValue);
787edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    static bool atLeast(GLint reqValue, GLint confValue) {
788edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return (reqValue == EGL_DONT_CARE) || (confValue >= reqValue);
789edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
790edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    static bool exact(GLint reqValue, GLint confValue) {
791edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return (reqValue == EGL_DONT_CARE) || (confValue == reqValue);
792edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
793edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    static bool mask(GLint reqValue, GLint confValue) {
794edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return (confValue & reqValue) == reqValue;
795edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
79692dc3fc52cf097bd105460cf377779bdcf146d62Mark Salyzyn    static bool ignore(GLint /*reqValue*/, GLint /*confValue*/) {
797639716736f5d87b64a43a20f39f37dee6bd98806Mathias Agopian        return true;
798639716736f5d87b64a43a20f39f37dee6bd98806Mathias Agopian    }
799edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
800edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
801edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
802edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
803edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#define VERSION_MAJOR 1
804edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#define VERSION_MINOR 2
805edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic char const * const gVendorString     = "Google Inc.";
806141550bc18f670f7e7ec65fc25363da3dd35d52eMathias Agopianstatic char const * const gVersionString    = "1.2 Android Driver 1.2.0";
807cc2b1560e87369676a2d13f17bd1ff4021a91819Mathias Agopianstatic char const * const gClientApiString  = "OpenGL_ES";
808076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopianstatic char const * const gExtensionsString =
80983e7c8c431ec8b578b6f778811837632e3798768Jesse Hall        "EGL_KHR_fence_sync "
810e6bf8b32b616450f80b64d226ea673f4a2e0bf8dMathias Agopian        "EGL_KHR_image_base "
811076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian        // "KHR_image_pixmap "
812076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian        "EGL_ANDROID_image_native_buffer "
813df3ca30bf663cb8eed88ee3f16fb5e9a65dc00fcMathias Agopian        "EGL_ANDROID_swap_rectangle "
814076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian        ;
815edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
816edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
817edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
818edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstruct extention_map_t {
819edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const char * const name;
820edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    __eglMustCastToProperFunctionPointerType address;
821edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
822edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
823edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic const extention_map_t gExtentionMap[] = {
824076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    { "glDrawTexsOES",
825076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian            (__eglMustCastToProperFunctionPointerType)&glDrawTexsOES },
826076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    { "glDrawTexiOES",
827076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian            (__eglMustCastToProperFunctionPointerType)&glDrawTexiOES },
828076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    { "glDrawTexfOES",
829076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian            (__eglMustCastToProperFunctionPointerType)&glDrawTexfOES },
830076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    { "glDrawTexxOES",
831076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian            (__eglMustCastToProperFunctionPointerType)&glDrawTexxOES },
832076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    { "glDrawTexsvOES",
833076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian            (__eglMustCastToProperFunctionPointerType)&glDrawTexsvOES },
834076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    { "glDrawTexivOES",
835076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian            (__eglMustCastToProperFunctionPointerType)&glDrawTexivOES },
836076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    { "glDrawTexfvOES",
837076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian            (__eglMustCastToProperFunctionPointerType)&glDrawTexfvOES },
838076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    { "glDrawTexxvOES",
839076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian            (__eglMustCastToProperFunctionPointerType)&glDrawTexxvOES },
840076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    { "glQueryMatrixxOES",
841076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian            (__eglMustCastToProperFunctionPointerType)&glQueryMatrixxOES },
842076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    { "glEGLImageTargetTexture2DOES",
843076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian            (__eglMustCastToProperFunctionPointerType)&glEGLImageTargetTexture2DOES },
844076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    { "glEGLImageTargetRenderbufferStorageOES",
845076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian            (__eglMustCastToProperFunctionPointerType)&glEGLImageTargetRenderbufferStorageOES },
846076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    { "glClipPlanef",
847076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian            (__eglMustCastToProperFunctionPointerType)&glClipPlanef },
848076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    { "glClipPlanex",
849076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian            (__eglMustCastToProperFunctionPointerType)&glClipPlanex },
850076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    { "glBindBuffer",
851076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian            (__eglMustCastToProperFunctionPointerType)&glBindBuffer },
852076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    { "glBufferData",
853076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian            (__eglMustCastToProperFunctionPointerType)&glBufferData },
854076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    { "glBufferSubData",
855076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian            (__eglMustCastToProperFunctionPointerType)&glBufferSubData },
856076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    { "glDeleteBuffers",
857076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian            (__eglMustCastToProperFunctionPointerType)&glDeleteBuffers },
858076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    { "glGenBuffers",
859076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian            (__eglMustCastToProperFunctionPointerType)&glGenBuffers },
8608d2e83b9f44c7f2207a312fcfda8eb3a4c26745fMathias Agopian    { "eglCreateImageKHR",
8618d2e83b9f44c7f2207a312fcfda8eb3a4c26745fMathias Agopian            (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR },
8628d2e83b9f44c7f2207a312fcfda8eb3a4c26745fMathias Agopian    { "eglDestroyImageKHR",
8638d2e83b9f44c7f2207a312fcfda8eb3a4c26745fMathias Agopian            (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR },
86483e7c8c431ec8b578b6f778811837632e3798768Jesse Hall    { "eglCreateSyncKHR",
86583e7c8c431ec8b578b6f778811837632e3798768Jesse Hall            (__eglMustCastToProperFunctionPointerType)&eglCreateSyncKHR },
86683e7c8c431ec8b578b6f778811837632e3798768Jesse Hall    { "eglDestroySyncKHR",
86783e7c8c431ec8b578b6f778811837632e3798768Jesse Hall            (__eglMustCastToProperFunctionPointerType)&eglDestroySyncKHR },
86883e7c8c431ec8b578b6f778811837632e3798768Jesse Hall    { "eglClientWaitSyncKHR",
86983e7c8c431ec8b578b6f778811837632e3798768Jesse Hall            (__eglMustCastToProperFunctionPointerType)&eglClientWaitSyncKHR },
87083e7c8c431ec8b578b6f778811837632e3798768Jesse Hall    { "eglGetSyncAttribKHR",
87183e7c8c431ec8b578b6f778811837632e3798768Jesse Hall            (__eglMustCastToProperFunctionPointerType)&eglGetSyncAttribKHR },
8728d2e83b9f44c7f2207a312fcfda8eb3a4c26745fMathias Agopian    { "eglSetSwapRectangleANDROID",
8738d2e83b9f44c7f2207a312fcfda8eb3a4c26745fMathias Agopian            (__eglMustCastToProperFunctionPointerType)&eglSetSwapRectangleANDROID },
874edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
875edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
876076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/*
877edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * In the lists below, attributes names MUST be sorted.
878edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * Additionally, all configs must be sorted according to
879edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * the EGL specification.
880edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project */
881edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
882edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic config_pair_t const config_base_attribute_list[] = {
883edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_STENCIL_SIZE,               0                                 },
884edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_CONFIG_CAVEAT,              EGL_SLOW_CONFIG                   },
885edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_LEVEL,                      0                                 },
886edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_MAX_PBUFFER_HEIGHT,         GGL_MAX_VIEWPORT_DIMS             },
887076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian        { EGL_MAX_PBUFFER_PIXELS,
888edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                GGL_MAX_VIEWPORT_DIMS*GGL_MAX_VIEWPORT_DIMS                 },
889edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_MAX_PBUFFER_WIDTH,          GGL_MAX_VIEWPORT_DIMS             },
890edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_NATIVE_RENDERABLE,          EGL_TRUE                          },
891edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_NATIVE_VISUAL_ID,           0                                 },
892edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_NATIVE_VISUAL_TYPE,         GGL_PIXEL_FORMAT_RGB_565          },
893edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_SAMPLES,                    0                                 },
894edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_SAMPLE_BUFFERS,             0                                 },
895edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_TRANSPARENT_TYPE,           EGL_NONE                          },
896edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_TRANSPARENT_BLUE_VALUE,     0                                 },
897edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_TRANSPARENT_GREEN_VALUE,    0                                 },
898edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_TRANSPARENT_RED_VALUE,      0                                 },
899edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_BIND_TO_TEXTURE_RGBA,       EGL_FALSE                         },
900edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_BIND_TO_TEXTURE_RGB,        EGL_FALSE                         },
901edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_MIN_SWAP_INTERVAL,          1                                 },
90256fa27572a2bbdd84a4762968327dba670fedae0Mathias Agopian        { EGL_MAX_SWAP_INTERVAL,          1                                 },
9030985f6a4ea1c457d98b0169ba9caa6b3713b1c7eMathias Agopian        { EGL_LUMINANCE_SIZE,             0                                 },
9040985f6a4ea1c457d98b0169ba9caa6b3713b1c7eMathias Agopian        { EGL_ALPHA_MASK_SIZE,            0                                 },
9050985f6a4ea1c457d98b0169ba9caa6b3713b1c7eMathias Agopian        { EGL_COLOR_BUFFER_TYPE,          EGL_RGB_BUFFER                    },
90656fa27572a2bbdd84a4762968327dba670fedae0Mathias Agopian        { EGL_RENDERABLE_TYPE,            EGL_OPENGL_ES_BIT                 },
9070985f6a4ea1c457d98b0169ba9caa6b3713b1c7eMathias Agopian        { EGL_CONFORMANT,                 0                                 }
908edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
909edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
910edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// These configs can override the base attribute list
911edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// NOTE: when adding a config here, don't forget to update eglCreate*Surface()
912edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
9138b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian// 565 configs
914edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic config_pair_t const config_0_attribute_list[] = {
915edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_BUFFER_SIZE,     16 },
916edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_ALPHA_SIZE,       0 },
917edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_BLUE_SIZE,        5 },
918edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_GREEN_SIZE,       6 },
919edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_RED_SIZE,         5 },
920edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_DEPTH_SIZE,       0 },
921edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_CONFIG_ID,        0 },
922d8e5ceb963c9bd3cba5c307aef481ded7859ef79Mathias Agopian        { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_RGB_565 },
923edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_SURFACE_TYPE,     EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT },
924edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
925edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
926edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic config_pair_t const config_1_attribute_list[] = {
927edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_BUFFER_SIZE,     16 },
928edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_ALPHA_SIZE,       0 },
929edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_BLUE_SIZE,        5 },
930edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_GREEN_SIZE,       6 },
931edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_RED_SIZE,         5 },
932edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_DEPTH_SIZE,      16 },
933edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_CONFIG_ID,        1 },
934d8e5ceb963c9bd3cba5c307aef481ded7859ef79Mathias Agopian        { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_RGB_565 },
935edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_SURFACE_TYPE,     EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT },
936edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
937edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
9388b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian// RGB 888 configs
939edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic config_pair_t const config_2_attribute_list[] = {
940edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_BUFFER_SIZE,     32 },
9418b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian        { EGL_ALPHA_SIZE,       0 },
9428b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian        { EGL_BLUE_SIZE,        8 },
9438b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian        { EGL_GREEN_SIZE,       8 },
9448b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian        { EGL_RED_SIZE,         8 },
9458b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian        { EGL_DEPTH_SIZE,       0 },
9468b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian        { EGL_CONFIG_ID,        6 },
947d8e5ceb963c9bd3cba5c307aef481ded7859ef79Mathias Agopian        { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_RGBX_8888 },
9488b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian        { EGL_SURFACE_TYPE,     EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT },
9498b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian};
9508b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian
9518b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopianstatic config_pair_t const config_3_attribute_list[] = {
9528b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian        { EGL_BUFFER_SIZE,     32 },
9538b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian        { EGL_ALPHA_SIZE,       0 },
9548b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian        { EGL_BLUE_SIZE,        8 },
9558b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian        { EGL_GREEN_SIZE,       8 },
9568b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian        { EGL_RED_SIZE,         8 },
9578b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian        { EGL_DEPTH_SIZE,      16 },
9588b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian        { EGL_CONFIG_ID,        7 },
959d8e5ceb963c9bd3cba5c307aef481ded7859ef79Mathias Agopian        { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_RGBX_8888 },
9608b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian        { EGL_SURFACE_TYPE,     EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT },
9618b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian};
9628b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian
9638b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian// 8888 configs
9648b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopianstatic config_pair_t const config_4_attribute_list[] = {
9658b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopian        { EGL_BUFFER_SIZE,     32 },
966edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_ALPHA_SIZE,       8 },
967edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_BLUE_SIZE,        8 },
968edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_GREEN_SIZE,       8 },
969edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_RED_SIZE,         8 },
970edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_DEPTH_SIZE,       0 },
971edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_CONFIG_ID,        2 },
9726af358e0a752b179671a9f9ea01757ade3b123cfMathias Agopian        { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_RGBA_8888 },
973edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_SURFACE_TYPE,     EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT },
974edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
975edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
9768b6b95abaec4a7e3df80a648bed75aa5aa74e8feMathias Agopianstatic config_pair_t const config_5_attribute_list[] = {
977edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_BUFFER_SIZE,     32 },
978edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_ALPHA_SIZE,       8 },
979edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_BLUE_SIZE,        8 },
980edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_GREEN_SIZE,       8 },
981edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_RED_SIZE,         8 },
982edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        { EGL_DEPTH_SIZE,      16 },
983