blob: cea17f878b8ac754e5161b01567b0d2880533ab8 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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 Projectedbf3b62009-03-03 19:31:44 -080017#include <stdlib.h>
18#include <stdio.h>
19#include <string.h>
20#include <math.h>
21
22#include <cutils/properties.h>
23
Mathias Agopian076b1cc2009-04-10 14:24:30 -070024#include <utils/RefBase.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080025#include <utils/Log.h>
26
Mathias Agopian076b1cc2009-04-10 14:24:30 -070027#include <ui/PixelFormat.h>
Mathias Agopian0926f502009-05-04 14:17:04 -070028#include <ui/FramebufferNativeWindow.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080029
30#include <GLES/gl.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070031#include <EGL/egl.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032#include <EGL/eglext.h>
33
Mathias Agopian076b1cc2009-04-10 14:24:30 -070034#include <pixelflinger/pixelflinger.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035
36#include "DisplayHardware/DisplayHardware.h"
37
Mathias Agopian076b1cc2009-04-10 14:24:30 -070038#include <hardware/gralloc.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080039
Mathias Agopian1f7bec62010-06-25 18:02:21 -070040#include "GLExtensions.h"
Mathias Agopiana350ff92010-08-10 17:14:02 -070041#include "HWComposer.h"
Mathias Agopianc7d14e22011-08-01 16:32:21 -070042#include "SurfaceFlinger.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070043
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044using namespace android;
45
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046
47static __attribute__((noinline))
48void checkGLErrors()
49{
Mathias Agopiancbb288b2009-09-07 16:32:45 -070050 do {
51 // there could be more than one error flag
52 GLenum error = glGetError();
53 if (error == GL_NO_ERROR)
54 break;
Steve Blocke6f43dd2012-01-06 19:20:56 +000055 ALOGE("GL error 0x%04x", int(error));
Mathias Agopiancbb288b2009-09-07 16:32:45 -070056 } while(true);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057}
58
59static __attribute__((noinline))
60void checkEGLErrors(const char* token)
61{
Mathias Agopian870b8aa2012-02-24 16:42:46 -080062 struct EGLUtils {
63 static const char *strerror(EGLint err) {
64 switch (err){
65 case EGL_SUCCESS: return "EGL_SUCCESS";
66 case EGL_NOT_INITIALIZED: return "EGL_NOT_INITIALIZED";
67 case EGL_BAD_ACCESS: return "EGL_BAD_ACCESS";
68 case EGL_BAD_ALLOC: return "EGL_BAD_ALLOC";
69 case EGL_BAD_ATTRIBUTE: return "EGL_BAD_ATTRIBUTE";
70 case EGL_BAD_CONFIG: return "EGL_BAD_CONFIG";
71 case EGL_BAD_CONTEXT: return "EGL_BAD_CONTEXT";
72 case EGL_BAD_CURRENT_SURFACE: return "EGL_BAD_CURRENT_SURFACE";
73 case EGL_BAD_DISPLAY: return "EGL_BAD_DISPLAY";
74 case EGL_BAD_MATCH: return "EGL_BAD_MATCH";
75 case EGL_BAD_NATIVE_PIXMAP: return "EGL_BAD_NATIVE_PIXMAP";
76 case EGL_BAD_NATIVE_WINDOW: return "EGL_BAD_NATIVE_WINDOW";
77 case EGL_BAD_PARAMETER: return "EGL_BAD_PARAMETER";
78 case EGL_BAD_SURFACE: return "EGL_BAD_SURFACE";
79 case EGL_CONTEXT_LOST: return "EGL_CONTEXT_LOST";
80 default: return "UNKNOWN";
81 }
82 }
83 };
84
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080085 EGLint error = eglGetError();
Mathias Agopiancbb288b2009-09-07 16:32:45 -070086 if (error && error != EGL_SUCCESS) {
Steve Blocke6f43dd2012-01-06 19:20:56 +000087 ALOGE("%s: EGL error 0x%04x (%s)",
Mathias Agopian0928e312009-08-07 16:38:10 -070088 token, int(error), EGLUtils::strerror(error));
Mathias Agopiancbb288b2009-09-07 16:32:45 -070089 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080090}
91
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080092/*
93 * Initialize the display to the specified values.
94 *
95 */
96
97DisplayHardware::DisplayHardware(
98 const sp<SurfaceFlinger>& flinger,
99 uint32_t dpy)
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700100 : DisplayHardwareBase(flinger, dpy),
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700101 mFlinger(flinger), mFlags(0), mHwc(0)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102{
103 init(dpy);
104}
105
106DisplayHardware::~DisplayHardware()
107{
108 fini();
109}
110
111float DisplayHardware::getDpiX() const { return mDpiX; }
112float DisplayHardware::getDpiY() const { return mDpiY; }
113float DisplayHardware::getDensity() const { return mDensity; }
114float DisplayHardware::getRefreshRate() const { return mRefreshRate; }
115int DisplayHardware::getWidth() const { return mWidth; }
116int DisplayHardware::getHeight() const { return mHeight; }
117PixelFormat DisplayHardware::getFormat() const { return mFormat; }
Mathias Agopianca99fb82010-04-14 16:43:44 -0700118uint32_t DisplayHardware::getMaxTextureSize() const { return mMaxTextureSize; }
Mathias Agopian3d64e732011-04-18 15:59:24 -0700119
120uint32_t DisplayHardware::getMaxViewportDims() const {
121 return mMaxViewportDims[0] < mMaxViewportDims[1] ?
122 mMaxViewportDims[0] : mMaxViewportDims[1];
123}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800124
Mathias Agopian61630912011-07-06 16:35:30 -0700125static status_t selectConfigForPixelFormat(
126 EGLDisplay dpy,
127 EGLint const* attrs,
128 PixelFormat format,
129 EGLConfig* outConfig)
130{
131 EGLConfig config = NULL;
132 EGLint numConfigs = -1, n=0;
133 eglGetConfigs(dpy, NULL, 0, &numConfigs);
134 EGLConfig* const configs = new EGLConfig[numConfigs];
135 eglChooseConfig(dpy, attrs, configs, numConfigs, &n);
136 for (int i=0 ; i<n ; i++) {
137 EGLint nativeVisualId = 0;
138 eglGetConfigAttrib(dpy, configs[i], EGL_NATIVE_VISUAL_ID, &nativeVisualId);
139 if (nativeVisualId>0 && format == nativeVisualId) {
140 *outConfig = configs[i];
141 delete [] configs;
142 return NO_ERROR;
143 }
144 }
145 delete [] configs;
146 return NAME_NOT_FOUND;
147}
148
149
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800150void DisplayHardware::init(uint32_t dpy)
151{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700152 mNativeWindow = new FramebufferNativeWindow();
Mathias Agopian0928e312009-08-07 16:38:10 -0700153 framebuffer_device_t const * fbDev = mNativeWindow->getDevice();
Mathias Agopian1f339ff2011-07-01 17:08:43 -0700154 if (!fbDev) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000155 ALOGE("Display subsystem failed to initialize. check logs. exiting...");
Mathias Agopian1f339ff2011-07-01 17:08:43 -0700156 exit(0);
157 }
158
Mathias Agopian61630912011-07-06 16:35:30 -0700159 int format;
160 ANativeWindow const * const window = mNativeWindow.get();
161 window->query(window, NATIVE_WINDOW_FORMAT, &format);
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700162 mDpiX = mNativeWindow->xdpi;
163 mDpiY = mNativeWindow->ydpi;
164 mRefreshRate = fbDev->fps;
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800165 mNextFakeVSync = 0;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700166
Mathias Agopian385977f2011-11-04 18:46:11 -0700167
168/* FIXME: this is a temporary HACK until we are able to report the refresh rate
169 * properly from the HAL. The WindowManagerService now relies on this value.
170 */
171#ifndef REFRESH_RATE
172 mRefreshRate = fbDev->fps;
173#else
174 mRefreshRate = REFRESH_RATE;
175#warning "refresh rate set via makefile to REFRESH_RATE"
176#endif
177
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800178 mRefreshPeriod = nsecs_t(1e9 / mRefreshRate);
179
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700180 EGLint w, h, dummy;
181 EGLint numConfigs=0;
182 EGLSurface surface;
183 EGLContext context;
Mathias Agopian61630912011-07-06 16:35:30 -0700184 EGLBoolean result;
185 status_t err;
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700186
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800187 // initialize EGL
Mathias Agopiana5b02e02009-09-04 18:49:03 -0700188 EGLint attribs[] = {
Mathias Agopian61630912011-07-06 16:35:30 -0700189 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
190 EGL_NONE, 0,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800191 EGL_NONE
192 };
Mathias Agopiana5b02e02009-09-04 18:49:03 -0700193
194 // debug: disable h/w rendering
195 char property[PROPERTY_VALUE_MAX];
196 if (property_get("debug.sf.hw", property, NULL) > 0) {
197 if (atoi(property) == 0) {
Steve Block32397c12012-01-05 23:22:43 +0000198 ALOGW("H/W composition disabled");
Mathias Agopiana5b02e02009-09-04 18:49:03 -0700199 attribs[2] = EGL_CONFIG_CAVEAT;
200 attribs[3] = EGL_SLOW_CONFIG;
201 }
202 }
203
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800204 // TODO: all the extensions below should be queried through
205 // eglGetProcAddress().
206
207 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
208 eglInitialize(display, NULL, NULL);
209 eglGetConfigs(display, NULL, 0, &numConfigs);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700210
Mathias Agopian61630912011-07-06 16:35:30 -0700211 EGLConfig config = NULL;
212 err = selectConfigForPixelFormat(display, attribs, format, &config);
Steve Blocke6f43dd2012-01-06 19:20:56 +0000213 ALOGE_IF(err, "couldn't find an EGLConfig matching the screen format");
Mathias Agopian6cf50a72009-08-06 16:05:39 -0700214
Mathias Agopian0928e312009-08-07 16:38:10 -0700215 EGLint r,g,b,a;
216 eglGetConfigAttrib(display, config, EGL_RED_SIZE, &r);
217 eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &g);
218 eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &b);
219 eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &a);
220
Mathias Agopian1e16b132009-05-07 17:40:23 -0700221 if (mNativeWindow->isUpdateOnDemand()) {
Mathias Agopian95a666b2009-09-24 14:57:26 -0700222 mFlags |= PARTIAL_UPDATES;
Mathias Agopian1e16b132009-05-07 17:40:23 -0700223 }
224
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800225 if (eglGetConfigAttrib(display, config, EGL_CONFIG_CAVEAT, &dummy) == EGL_TRUE) {
226 if (dummy == EGL_SLOW_CONFIG)
227 mFlags |= SLOW_CONFIG;
228 }
229
230 /*
231 * Create our main surface
232 */
233
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700234 surface = eglCreateWindowSurface(display, config, mNativeWindow.get(), NULL);
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700235 eglQuerySurface(display, surface, EGL_WIDTH, &mWidth);
236 eglQuerySurface(display, surface, EGL_HEIGHT, &mHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800237
Mathias Agopian95a666b2009-09-24 14:57:26 -0700238 if (mFlags & PARTIAL_UPDATES) {
239 // if we have partial updates, we definitely don't need to
240 // preserve the backbuffer, which may be costly.
Mathias Agopian0928bee2009-09-16 20:15:42 -0700241 eglSurfaceAttrib(display, surface,
242 EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED);
243 }
244
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800245 if (eglQuerySurface(display, surface, EGL_SWAP_BEHAVIOR, &dummy) == EGL_TRUE) {
246 if (dummy == EGL_BUFFER_PRESERVED) {
247 mFlags |= BUFFER_PRESERVED;
248 }
249 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800250
David 'Digit' Turnerae71acc2009-06-19 04:41:12 +0200251 /* Read density from build-specific ro.sf.lcd_density property
Mathias Agopian24e5f522009-08-12 21:18:15 -0700252 * except if it is overridden by qemu.sf.lcd_density.
David 'Digit' Turnerae71acc2009-06-19 04:41:12 +0200253 */
254 if (property_get("qemu.sf.lcd_density", property, NULL) <= 0) {
255 if (property_get("ro.sf.lcd_density", property, NULL) <= 0) {
Steve Block32397c12012-01-05 23:22:43 +0000256 ALOGW("ro.sf.lcd_density not defined, using 160 dpi by default.");
David 'Digit' Turnerae71acc2009-06-19 04:41:12 +0200257 strcpy(property, "160");
David 'Digit' Turner694e10b2009-06-18 04:30:32 +0200258 }
David 'Digit' Turner31469e12009-07-29 00:38:58 +0200259 } else {
260 /* for the emulator case, reset the dpi values too */
261 mDpiX = mDpiY = atoi(property);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800262 }
263 mDensity = atoi(property) * (1.0f/160.0f);
264
265
266 /*
267 * Create our OpenGL ES context
268 */
269
Mathias Agopian67226812010-10-11 17:54:43 -0700270
271 EGLint contextAttributes[] = {
272#ifdef EGL_IMG_context_priority
273#ifdef HAS_CONTEXT_PRIORITY
274#warning "using EGL_IMG_context_priority"
275 EGL_CONTEXT_PRIORITY_LEVEL_IMG, EGL_CONTEXT_PRIORITY_HIGH_IMG,
276#endif
277#endif
278 EGL_NONE, EGL_NONE
279 };
280 context = eglCreateContext(display, config, NULL, contextAttributes);
281
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800282 mDisplay = display;
283 mConfig = config;
284 mSurface = surface;
285 mContext = context;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700286 mFormat = fbDev->format;
287 mPageFlipCount = 0;
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700288
289 /*
290 * Gather OpenGL ES extensions
291 */
292
Mathias Agopian61630912011-07-06 16:35:30 -0700293 result = eglMakeCurrent(display, surface, surface, context);
294 if (!result) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000295 ALOGE("Couldn't create a working GLES context. check logs. exiting...");
Mathias Agopian61630912011-07-06 16:35:30 -0700296 exit(0);
297 }
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700298
299 GLExtensions& extensions(GLExtensions::getInstance());
300 extensions.initWithGLStrings(
301 glGetString(GL_VENDOR),
302 glGetString(GL_RENDERER),
303 glGetString(GL_VERSION),
304 glGetString(GL_EXTENSIONS),
305 eglQueryString(display, EGL_VENDOR),
306 eglQueryString(display, EGL_VERSION),
307 eglQueryString(display, EGL_EXTENSIONS));
308
309 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
Mathias Agopian3d64e732011-04-18 15:59:24 -0700310 glGetIntegerv(GL_MAX_VIEWPORT_DIMS, mMaxViewportDims);
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700311
Steve Blocka19954a2012-01-04 20:05:49 +0000312 ALOGI("EGL informations:");
313 ALOGI("# of configs : %d", numConfigs);
314 ALOGI("vendor : %s", extensions.getEglVendor());
315 ALOGI("version : %s", extensions.getEglVersion());
316 ALOGI("extensions: %s", extensions.getEglExtension());
317 ALOGI("Client API: %s", eglQueryString(display, EGL_CLIENT_APIS)?:"Not Supported");
318 ALOGI("EGLSurface: %d-%d-%d-%d, config=%p", r, g, b, a, config);
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700319
Steve Blocka19954a2012-01-04 20:05:49 +0000320 ALOGI("OpenGL informations:");
321 ALOGI("vendor : %s", extensions.getVendor());
322 ALOGI("renderer : %s", extensions.getRenderer());
323 ALOGI("version : %s", extensions.getVersion());
324 ALOGI("extensions: %s", extensions.getExtension());
325 ALOGI("GL_MAX_TEXTURE_SIZE = %d", mMaxTextureSize);
326 ALOGI("GL_MAX_VIEWPORT_DIMS = %d x %d", mMaxViewportDims[0], mMaxViewportDims[1]);
327 ALOGI("flags = %08x", mFlags);
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700328
329 // Unbind the context from this thread
330 eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700331
332
333 // initialize the H/W composer
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700334 mHwc = new HWComposer(mFlinger);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700335 if (mHwc->initCheck() == NO_ERROR) {
336 mHwc->setFrameBuffer(mDisplay, mSurface);
337 }
338}
339
340HWComposer& DisplayHardware::getHwComposer() const {
341 return *mHwc;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800342}
343
344/*
345 * Clean up. Throw out our local state.
346 *
347 * (It's entirely possible we'll never get here, since this is meant
348 * for real hardware, which doesn't restart.)
349 */
350
351void DisplayHardware::fini()
352{
353 eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
354 eglTerminate(mDisplay);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800355}
356
357void DisplayHardware::releaseScreen() const
358{
359 DisplayHardwareBase::releaseScreen();
Antti Hatalaf5f27122010-09-09 02:33:05 -0700360 if (mHwc->initCheck() == NO_ERROR) {
361 mHwc->release();
362 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800363}
364
365void DisplayHardware::acquireScreen() const
366{
367 DisplayHardwareBase::acquireScreen();
368}
369
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800370uint32_t DisplayHardware::getPageFlipCount() const {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700371 return mPageFlipCount;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800372}
373
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800374// this needs to be thread safe
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800375nsecs_t DisplayHardware::waitForRefresh() const {
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800376 nsecs_t timestamp;
377 if (mVSync.wait(&timestamp) < 0) {
378 // vsync not supported!
379 usleep( getDelayToNextVSyncUs(&timestamp) );
380 }
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800381 mLastHwVSync = timestamp; // FIXME: Not thread safe
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800382 return timestamp;
383}
384
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800385nsecs_t DisplayHardware::getRefreshTimestamp() const {
386 // this returns the last refresh timestamp.
387 // if the last one is not available, we estimate it based on
388 // the refresh period and whatever closest timestamp we have.
389 nsecs_t now = systemTime();
390 return now - ((now - mLastHwVSync) % mRefreshPeriod);
391}
392
393nsecs_t DisplayHardware::getRefreshPeriod() const {
394 return mRefreshPeriod;
395}
396
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800397int32_t DisplayHardware::getDelayToNextVSyncUs(nsecs_t* timestamp) const {
398 Mutex::Autolock _l(mFakeVSyncMutex);
399 const nsecs_t period = mRefreshPeriod;
400 const nsecs_t now = systemTime(CLOCK_MONOTONIC);
401 nsecs_t next_vsync = mNextFakeVSync;
402 nsecs_t sleep = next_vsync - now;
403 if (sleep < 0) {
404 // we missed, find where the next vsync should be
405 sleep = (period - ((now - next_vsync) % period));
406 next_vsync = now + sleep;
407 }
408 mNextFakeVSync = next_vsync + period;
409 timestamp[0] = next_vsync;
410
411 // round to next microsecond
412 int32_t sleep_us = (sleep + 999LL) / 1000LL;
413
414 // guaranteed to be > 0
415 return sleep_us;
416}
417
Mathias Agopian74faca22009-09-17 16:18:16 -0700418status_t DisplayHardware::compositionComplete() const {
419 return mNativeWindow->compositionComplete();
420}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800421
422void DisplayHardware::flip(const Region& dirty) const
423{
424 checkGLErrors();
425
426 EGLDisplay dpy = mDisplay;
427 EGLSurface surface = mSurface;
428
Mathias Agopian5e78e092009-06-11 17:19:54 -0700429#ifdef EGL_ANDROID_swap_rectangle
Mathias Agopiandf3ca302009-05-04 19:29:25 -0700430 if (mFlags & SWAP_RECTANGLE) {
Mathias Agopianb8a55602009-06-26 19:06:36 -0700431 const Region newDirty(dirty.intersect(bounds()));
432 const Rect b(newDirty.getBounds());
Mathias Agopiandf3ca302009-05-04 19:29:25 -0700433 eglSetSwapRectangleANDROID(dpy, surface,
434 b.left, b.top, b.width(), b.height());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800435 }
Mathias Agopian5e78e092009-06-11 17:19:54 -0700436#endif
437
Mathias Agopian95a666b2009-09-24 14:57:26 -0700438 if (mFlags & PARTIAL_UPDATES) {
Mathias Agopian29d06ac2009-06-29 18:49:56 -0700439 mNativeWindow->setUpdateRectangle(dirty.getBounds());
Mathias Agopian1e16b132009-05-07 17:40:23 -0700440 }
441
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700442 mPageFlipCount++;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700443
444 if (mHwc->initCheck() == NO_ERROR) {
445 mHwc->commit();
446 } else {
447 eglSwapBuffers(dpy, surface);
448 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800449 checkEGLErrors("eglSwapBuffers");
450
451 // for debugging
452 //glClearColor(1,0,0,0);
453 //glClear(GL_COLOR_BUFFER_BIT);
454}
455
456uint32_t DisplayHardware::getFlags() const
457{
458 return mFlags;
459}
460
461void DisplayHardware::makeCurrent() const
462{
463 eglMakeCurrent(mDisplay, mSurface, mSurface, mContext);
464}
Erik Gilling1d21a9c2010-12-01 16:38:01 -0800465
466void DisplayHardware::dump(String8& res) const
467{
468 mNativeWindow->dump(res);
469}