The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | #include <stdlib.h> |
| 18 | #include <stdio.h> |
| 19 | #include <string.h> |
| 20 | #include <math.h> |
| 21 | |
| 22 | #include <cutils/properties.h> |
| 23 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 24 | #include <utils/RefBase.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <utils/Log.h> |
| 26 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 27 | #include <ui/PixelFormat.h> |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 28 | #include <ui/FramebufferNativeWindow.h> |
Mathias Agopian | 6cf50a7 | 2009-08-06 16:05:39 -0700 | [diff] [blame] | 29 | #include <ui/EGLUtils.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | |
| 31 | #include <GLES/gl.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 32 | #include <EGL/egl.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | #include <EGL/eglext.h> |
| 34 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 35 | #include <pixelflinger/pixelflinger.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
| 37 | #include "DisplayHardware/DisplayHardware.h" |
| 38 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 39 | #include <hardware/gralloc.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 41 | #include "GLExtensions.h" |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 42 | #include "HWComposer.h" |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 43 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | using namespace android; |
| 45 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | |
| 47 | static __attribute__((noinline)) |
| 48 | void checkGLErrors() |
| 49 | { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 50 | do { |
| 51 | // there could be more than one error flag |
| 52 | GLenum error = glGetError(); |
| 53 | if (error == GL_NO_ERROR) |
| 54 | break; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | LOGE("GL error 0x%04x", int(error)); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 56 | } while(true); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | static __attribute__((noinline)) |
| 60 | void checkEGLErrors(const char* token) |
| 61 | { |
| 62 | EGLint error = eglGetError(); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 63 | if (error && error != EGL_SUCCESS) { |
| 64 | LOGE("%s: EGL error 0x%04x (%s)", |
Mathias Agopian | 0928e31 | 2009-08-07 16:38:10 -0700 | [diff] [blame] | 65 | token, int(error), EGLUtils::strerror(error)); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 66 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | } |
| 68 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | /* |
| 70 | * Initialize the display to the specified values. |
| 71 | * |
| 72 | */ |
| 73 | |
| 74 | DisplayHardware::DisplayHardware( |
| 75 | const sp<SurfaceFlinger>& flinger, |
| 76 | uint32_t dpy) |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 77 | : DisplayHardwareBase(flinger, dpy), |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 78 | mFlags(0), mHwc(0) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | { |
| 80 | init(dpy); |
| 81 | } |
| 82 | |
| 83 | DisplayHardware::~DisplayHardware() |
| 84 | { |
| 85 | fini(); |
| 86 | } |
| 87 | |
| 88 | float DisplayHardware::getDpiX() const { return mDpiX; } |
| 89 | float DisplayHardware::getDpiY() const { return mDpiY; } |
| 90 | float DisplayHardware::getDensity() const { return mDensity; } |
| 91 | float DisplayHardware::getRefreshRate() const { return mRefreshRate; } |
| 92 | int DisplayHardware::getWidth() const { return mWidth; } |
| 93 | int DisplayHardware::getHeight() const { return mHeight; } |
| 94 | PixelFormat DisplayHardware::getFormat() const { return mFormat; } |
Mathias Agopian | ca99fb8 | 2010-04-14 16:43:44 -0700 | [diff] [blame] | 95 | uint32_t DisplayHardware::getMaxTextureSize() const { return mMaxTextureSize; } |
Mathias Agopian | 3d64e73 | 2011-04-18 15:59:24 -0700 | [diff] [blame] | 96 | |
| 97 | uint32_t DisplayHardware::getMaxViewportDims() const { |
| 98 | return mMaxViewportDims[0] < mMaxViewportDims[1] ? |
| 99 | mMaxViewportDims[0] : mMaxViewportDims[1]; |
| 100 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | |
| 102 | void DisplayHardware::init(uint32_t dpy) |
| 103 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 104 | mNativeWindow = new FramebufferNativeWindow(); |
Mathias Agopian | 0928e31 | 2009-08-07 16:38:10 -0700 | [diff] [blame] | 105 | framebuffer_device_t const * fbDev = mNativeWindow->getDevice(); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 106 | if (!fbDev) { |
| 107 | LOGE("Display subsystem failed to initialize. check logs. exiting..."); |
| 108 | exit(0); |
| 109 | } |
| 110 | |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 111 | mDpiX = mNativeWindow->xdpi; |
| 112 | mDpiY = mNativeWindow->ydpi; |
| 113 | mRefreshRate = fbDev->fps; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 114 | |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 115 | EGLint w, h, dummy; |
| 116 | EGLint numConfigs=0; |
| 117 | EGLSurface surface; |
| 118 | EGLContext context; |
| 119 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | // initialize EGL |
Mathias Agopian | a5b02e0 | 2009-09-04 18:49:03 -0700 | [diff] [blame] | 121 | EGLint attribs[] = { |
Mathias Agopian | 0928e31 | 2009-08-07 16:38:10 -0700 | [diff] [blame] | 122 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
Mathias Agopian | a5b02e0 | 2009-09-04 18:49:03 -0700 | [diff] [blame] | 123 | EGL_NONE, 0, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | EGL_NONE |
| 125 | }; |
Mathias Agopian | a5b02e0 | 2009-09-04 18:49:03 -0700 | [diff] [blame] | 126 | |
| 127 | // debug: disable h/w rendering |
| 128 | char property[PROPERTY_VALUE_MAX]; |
| 129 | if (property_get("debug.sf.hw", property, NULL) > 0) { |
| 130 | if (atoi(property) == 0) { |
| 131 | LOGW("H/W composition disabled"); |
| 132 | attribs[2] = EGL_CONFIG_CAVEAT; |
| 133 | attribs[3] = EGL_SLOW_CONFIG; |
| 134 | } |
| 135 | } |
| 136 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | // TODO: all the extensions below should be queried through |
| 138 | // eglGetProcAddress(). |
| 139 | |
| 140 | EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 141 | eglInitialize(display, NULL, NULL); |
| 142 | eglGetConfigs(display, NULL, 0, &numConfigs); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 143 | |
Mathias Agopian | 6cf50a7 | 2009-08-06 16:05:39 -0700 | [diff] [blame] | 144 | EGLConfig config; |
Mathias Agopian | 0928e31 | 2009-08-07 16:38:10 -0700 | [diff] [blame] | 145 | status_t err = EGLUtils::selectConfigForNativeWindow( |
| 146 | display, attribs, mNativeWindow.get(), &config); |
Mathias Agopian | 6cf50a7 | 2009-08-06 16:05:39 -0700 | [diff] [blame] | 147 | LOGE_IF(err, "couldn't find an EGLConfig matching the screen format"); |
| 148 | |
Mathias Agopian | 0928e31 | 2009-08-07 16:38:10 -0700 | [diff] [blame] | 149 | EGLint r,g,b,a; |
| 150 | eglGetConfigAttrib(display, config, EGL_RED_SIZE, &r); |
| 151 | eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &g); |
| 152 | eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &b); |
| 153 | eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &a); |
| 154 | |
Mathias Agopian | 1e16b13 | 2009-05-07 17:40:23 -0700 | [diff] [blame] | 155 | if (mNativeWindow->isUpdateOnDemand()) { |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 156 | mFlags |= PARTIAL_UPDATES; |
Mathias Agopian | 1e16b13 | 2009-05-07 17:40:23 -0700 | [diff] [blame] | 157 | } |
| 158 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | if (eglGetConfigAttrib(display, config, EGL_CONFIG_CAVEAT, &dummy) == EGL_TRUE) { |
| 160 | if (dummy == EGL_SLOW_CONFIG) |
| 161 | mFlags |= SLOW_CONFIG; |
| 162 | } |
| 163 | |
| 164 | /* |
| 165 | * Create our main surface |
| 166 | */ |
| 167 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 168 | surface = eglCreateWindowSurface(display, config, mNativeWindow.get(), NULL); |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 169 | eglQuerySurface(display, surface, EGL_WIDTH, &mWidth); |
| 170 | eglQuerySurface(display, surface, EGL_HEIGHT, &mHeight); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 172 | if (mFlags & PARTIAL_UPDATES) { |
| 173 | // if we have partial updates, we definitely don't need to |
| 174 | // preserve the backbuffer, which may be costly. |
Mathias Agopian | 0928bee | 2009-09-16 20:15:42 -0700 | [diff] [blame] | 175 | eglSurfaceAttrib(display, surface, |
| 176 | EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED); |
| 177 | } |
| 178 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | if (eglQuerySurface(display, surface, EGL_SWAP_BEHAVIOR, &dummy) == EGL_TRUE) { |
| 180 | if (dummy == EGL_BUFFER_PRESERVED) { |
| 181 | mFlags |= BUFFER_PRESERVED; |
| 182 | } |
| 183 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | |
David 'Digit' Turner | ae71acc | 2009-06-19 04:41:12 +0200 | [diff] [blame] | 185 | /* Read density from build-specific ro.sf.lcd_density property |
Mathias Agopian | 24e5f52 | 2009-08-12 21:18:15 -0700 | [diff] [blame] | 186 | * except if it is overridden by qemu.sf.lcd_density. |
David 'Digit' Turner | ae71acc | 2009-06-19 04:41:12 +0200 | [diff] [blame] | 187 | */ |
| 188 | if (property_get("qemu.sf.lcd_density", property, NULL) <= 0) { |
| 189 | if (property_get("ro.sf.lcd_density", property, NULL) <= 0) { |
| 190 | LOGW("ro.sf.lcd_density not defined, using 160 dpi by default."); |
| 191 | strcpy(property, "160"); |
David 'Digit' Turner | 694e10b | 2009-06-18 04:30:32 +0200 | [diff] [blame] | 192 | } |
David 'Digit' Turner | 31469e1 | 2009-07-29 00:38:58 +0200 | [diff] [blame] | 193 | } else { |
| 194 | /* for the emulator case, reset the dpi values too */ |
| 195 | mDpiX = mDpiY = atoi(property); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | } |
| 197 | mDensity = atoi(property) * (1.0f/160.0f); |
| 198 | |
| 199 | |
| 200 | /* |
| 201 | * Create our OpenGL ES context |
| 202 | */ |
| 203 | |
Mathias Agopian | 6722681 | 2010-10-11 17:54:43 -0700 | [diff] [blame] | 204 | |
| 205 | EGLint contextAttributes[] = { |
| 206 | #ifdef EGL_IMG_context_priority |
| 207 | #ifdef HAS_CONTEXT_PRIORITY |
| 208 | #warning "using EGL_IMG_context_priority" |
| 209 | EGL_CONTEXT_PRIORITY_LEVEL_IMG, EGL_CONTEXT_PRIORITY_HIGH_IMG, |
| 210 | #endif |
| 211 | #endif |
| 212 | EGL_NONE, EGL_NONE |
| 213 | }; |
| 214 | context = eglCreateContext(display, config, NULL, contextAttributes); |
| 215 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | mDisplay = display; |
| 217 | mConfig = config; |
| 218 | mSurface = surface; |
| 219 | mContext = context; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 220 | mFormat = fbDev->format; |
| 221 | mPageFlipCount = 0; |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 222 | |
| 223 | /* |
| 224 | * Gather OpenGL ES extensions |
| 225 | */ |
| 226 | |
| 227 | eglMakeCurrent(display, surface, surface, context); |
| 228 | |
| 229 | GLExtensions& extensions(GLExtensions::getInstance()); |
| 230 | extensions.initWithGLStrings( |
| 231 | glGetString(GL_VENDOR), |
| 232 | glGetString(GL_RENDERER), |
| 233 | glGetString(GL_VERSION), |
| 234 | glGetString(GL_EXTENSIONS), |
| 235 | eglQueryString(display, EGL_VENDOR), |
| 236 | eglQueryString(display, EGL_VERSION), |
| 237 | eglQueryString(display, EGL_EXTENSIONS)); |
| 238 | |
| 239 | glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize); |
Mathias Agopian | 3d64e73 | 2011-04-18 15:59:24 -0700 | [diff] [blame] | 240 | glGetIntegerv(GL_MAX_VIEWPORT_DIMS, mMaxViewportDims); |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 241 | |
| 242 | |
| 243 | #ifdef EGL_ANDROID_swap_rectangle |
| 244 | if (extensions.hasExtension("EGL_ANDROID_swap_rectangle")) { |
| 245 | if (eglSetSwapRectangleANDROID(display, surface, |
| 246 | 0, 0, mWidth, mHeight) == EGL_TRUE) { |
| 247 | // This could fail if this extension is not supported by this |
| 248 | // specific surface (of config) |
| 249 | mFlags |= SWAP_RECTANGLE; |
| 250 | } |
| 251 | } |
| 252 | // when we have the choice between PARTIAL_UPDATES and SWAP_RECTANGLE |
| 253 | // choose PARTIAL_UPDATES, which should be more efficient |
| 254 | if (mFlags & PARTIAL_UPDATES) |
| 255 | mFlags &= ~SWAP_RECTANGLE; |
| 256 | #endif |
| 257 | |
| 258 | LOGI("EGL informations:"); |
| 259 | LOGI("# of configs : %d", numConfigs); |
| 260 | LOGI("vendor : %s", extensions.getEglVendor()); |
| 261 | LOGI("version : %s", extensions.getEglVersion()); |
| 262 | LOGI("extensions: %s", extensions.getEglExtension()); |
| 263 | LOGI("Client API: %s", eglQueryString(display, EGL_CLIENT_APIS)?:"Not Supported"); |
| 264 | LOGI("EGLSurface: %d-%d-%d-%d, config=%p", r, g, b, a, config); |
| 265 | |
| 266 | LOGI("OpenGL informations:"); |
| 267 | LOGI("vendor : %s", extensions.getVendor()); |
| 268 | LOGI("renderer : %s", extensions.getRenderer()); |
| 269 | LOGI("version : %s", extensions.getVersion()); |
| 270 | LOGI("extensions: %s", extensions.getExtension()); |
| 271 | LOGI("GL_MAX_TEXTURE_SIZE = %d", mMaxTextureSize); |
Mathias Agopian | 3d64e73 | 2011-04-18 15:59:24 -0700 | [diff] [blame] | 272 | LOGI("GL_MAX_VIEWPORT_DIMS = %d x %d", mMaxViewportDims[0], mMaxViewportDims[1]); |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 273 | LOGI("flags = %08x", mFlags); |
| 274 | |
| 275 | // Unbind the context from this thread |
| 276 | eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 277 | |
| 278 | |
| 279 | // initialize the H/W composer |
| 280 | mHwc = new HWComposer(); |
| 281 | if (mHwc->initCheck() == NO_ERROR) { |
| 282 | mHwc->setFrameBuffer(mDisplay, mSurface); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | HWComposer& DisplayHardware::getHwComposer() const { |
| 287 | return *mHwc; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | /* |
| 291 | * Clean up. Throw out our local state. |
| 292 | * |
| 293 | * (It's entirely possible we'll never get here, since this is meant |
| 294 | * for real hardware, which doesn't restart.) |
| 295 | */ |
| 296 | |
| 297 | void DisplayHardware::fini() |
| 298 | { |
| 299 | eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
| 300 | eglTerminate(mDisplay); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | void DisplayHardware::releaseScreen() const |
| 304 | { |
| 305 | DisplayHardwareBase::releaseScreen(); |
Antti Hatala | f5f2712 | 2010-09-09 02:33:05 -0700 | [diff] [blame] | 306 | if (mHwc->initCheck() == NO_ERROR) { |
| 307 | mHwc->release(); |
| 308 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | void DisplayHardware::acquireScreen() const |
| 312 | { |
| 313 | DisplayHardwareBase::acquireScreen(); |
| 314 | } |
| 315 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | uint32_t DisplayHardware::getPageFlipCount() const { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 317 | return mPageFlipCount; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Mathias Agopian | 74faca2 | 2009-09-17 16:18:16 -0700 | [diff] [blame] | 320 | status_t DisplayHardware::compositionComplete() const { |
| 321 | return mNativeWindow->compositionComplete(); |
| 322 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | |
Mathias Agopian | 35b48d1 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 324 | int DisplayHardware::getCurrentBufferIndex() const { |
| 325 | return mNativeWindow->getCurrentBufferIndex(); |
| 326 | } |
| 327 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 328 | void DisplayHardware::flip(const Region& dirty) const |
| 329 | { |
| 330 | checkGLErrors(); |
| 331 | |
| 332 | EGLDisplay dpy = mDisplay; |
| 333 | EGLSurface surface = mSurface; |
| 334 | |
Mathias Agopian | 5e78e09 | 2009-06-11 17:19:54 -0700 | [diff] [blame] | 335 | #ifdef EGL_ANDROID_swap_rectangle |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 336 | if (mFlags & SWAP_RECTANGLE) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 337 | const Region newDirty(dirty.intersect(bounds())); |
| 338 | const Rect b(newDirty.getBounds()); |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 339 | eglSetSwapRectangleANDROID(dpy, surface, |
| 340 | b.left, b.top, b.width(), b.height()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | } |
Mathias Agopian | 5e78e09 | 2009-06-11 17:19:54 -0700 | [diff] [blame] | 342 | #endif |
| 343 | |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 344 | if (mFlags & PARTIAL_UPDATES) { |
Mathias Agopian | 29d06ac | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 345 | mNativeWindow->setUpdateRectangle(dirty.getBounds()); |
Mathias Agopian | 1e16b13 | 2009-05-07 17:40:23 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 348 | mPageFlipCount++; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 349 | |
| 350 | if (mHwc->initCheck() == NO_ERROR) { |
| 351 | mHwc->commit(); |
| 352 | } else { |
| 353 | eglSwapBuffers(dpy, surface); |
| 354 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | checkEGLErrors("eglSwapBuffers"); |
| 356 | |
| 357 | // for debugging |
| 358 | //glClearColor(1,0,0,0); |
| 359 | //glClear(GL_COLOR_BUFFER_BIT); |
| 360 | } |
| 361 | |
| 362 | uint32_t DisplayHardware::getFlags() const |
| 363 | { |
| 364 | return mFlags; |
| 365 | } |
| 366 | |
| 367 | void DisplayHardware::makeCurrent() const |
| 368 | { |
| 369 | eglMakeCurrent(mDisplay, mSurface, mSurface, mContext); |
| 370 | } |
Erik Gilling | 1d21a9c | 2010-12-01 16:38:01 -0800 | [diff] [blame] | 371 | |
| 372 | void DisplayHardware::dump(String8& res) const |
| 373 | { |
| 374 | mNativeWindow->dump(res); |
| 375 | } |