blob: 3a0ff7156f09b88a366add7578305dcecc45052d [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
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080034#include "DisplayHardware/DisplayHardware.h"
35
Mathias Agopian076b1cc2009-04-10 14:24:30 -070036#include <hardware/gralloc.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037
Mathias Agopian1f7bec62010-06-25 18:02:21 -070038#include "GLExtensions.h"
Mathias Agopiana350ff92010-08-10 17:14:02 -070039#include "HWComposer.h"
Mathias Agopianc7d14e22011-08-01 16:32:21 -070040#include "SurfaceFlinger.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070041
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042using namespace android;
43
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044
45static __attribute__((noinline))
46void checkGLErrors()
47{
Mathias Agopiancbb288b2009-09-07 16:32:45 -070048 do {
49 // there could be more than one error flag
50 GLenum error = glGetError();
51 if (error == GL_NO_ERROR)
52 break;
Steve Blocke6f43dd2012-01-06 19:20:56 +000053 ALOGE("GL error 0x%04x", int(error));
Mathias Agopiancbb288b2009-09-07 16:32:45 -070054 } while(true);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055}
56
57static __attribute__((noinline))
58void checkEGLErrors(const char* token)
59{
Mathias Agopian870b8aa2012-02-24 16:42:46 -080060 struct EGLUtils {
61 static const char *strerror(EGLint err) {
62 switch (err){
63 case EGL_SUCCESS: return "EGL_SUCCESS";
64 case EGL_NOT_INITIALIZED: return "EGL_NOT_INITIALIZED";
65 case EGL_BAD_ACCESS: return "EGL_BAD_ACCESS";
66 case EGL_BAD_ALLOC: return "EGL_BAD_ALLOC";
67 case EGL_BAD_ATTRIBUTE: return "EGL_BAD_ATTRIBUTE";
68 case EGL_BAD_CONFIG: return "EGL_BAD_CONFIG";
69 case EGL_BAD_CONTEXT: return "EGL_BAD_CONTEXT";
70 case EGL_BAD_CURRENT_SURFACE: return "EGL_BAD_CURRENT_SURFACE";
71 case EGL_BAD_DISPLAY: return "EGL_BAD_DISPLAY";
72 case EGL_BAD_MATCH: return "EGL_BAD_MATCH";
73 case EGL_BAD_NATIVE_PIXMAP: return "EGL_BAD_NATIVE_PIXMAP";
74 case EGL_BAD_NATIVE_WINDOW: return "EGL_BAD_NATIVE_WINDOW";
75 case EGL_BAD_PARAMETER: return "EGL_BAD_PARAMETER";
76 case EGL_BAD_SURFACE: return "EGL_BAD_SURFACE";
77 case EGL_CONTEXT_LOST: return "EGL_CONTEXT_LOST";
78 default: return "UNKNOWN";
79 }
80 }
81 };
82
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080083 EGLint error = eglGetError();
Mathias Agopiancbb288b2009-09-07 16:32:45 -070084 if (error && error != EGL_SUCCESS) {
Steve Blocke6f43dd2012-01-06 19:20:56 +000085 ALOGE("%s: EGL error 0x%04x (%s)",
Mathias Agopian0928e312009-08-07 16:38:10 -070086 token, int(error), EGLUtils::strerror(error));
Mathias Agopiancbb288b2009-09-07 16:32:45 -070087 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080088}
89
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080090/*
91 * Initialize the display to the specified values.
92 *
93 */
94
95DisplayHardware::DisplayHardware(
96 const sp<SurfaceFlinger>& flinger,
97 uint32_t dpy)
Mathias Agopian1f7bec62010-06-25 18:02:21 -070098 : DisplayHardwareBase(flinger, dpy),
Mathias Agopianc7d14e22011-08-01 16:32:21 -070099 mFlinger(flinger), mFlags(0), mHwc(0)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800100{
101 init(dpy);
102}
103
104DisplayHardware::~DisplayHardware()
105{
106 fini();
107}
108
109float DisplayHardware::getDpiX() const { return mDpiX; }
110float DisplayHardware::getDpiY() const { return mDpiY; }
111float DisplayHardware::getDensity() const { return mDensity; }
112float DisplayHardware::getRefreshRate() const { return mRefreshRate; }
113int DisplayHardware::getWidth() const { return mWidth; }
114int DisplayHardware::getHeight() const { return mHeight; }
115PixelFormat DisplayHardware::getFormat() const { return mFormat; }
Mathias Agopianca99fb82010-04-14 16:43:44 -0700116uint32_t DisplayHardware::getMaxTextureSize() const { return mMaxTextureSize; }
Mathias Agopian3d64e732011-04-18 15:59:24 -0700117
118uint32_t DisplayHardware::getMaxViewportDims() const {
119 return mMaxViewportDims[0] < mMaxViewportDims[1] ?
120 mMaxViewportDims[0] : mMaxViewportDims[1];
121}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800122
Mathias Agopian61630912011-07-06 16:35:30 -0700123static status_t selectConfigForPixelFormat(
124 EGLDisplay dpy,
125 EGLint const* attrs,
126 PixelFormat format,
127 EGLConfig* outConfig)
128{
129 EGLConfig config = NULL;
130 EGLint numConfigs = -1, n=0;
131 eglGetConfigs(dpy, NULL, 0, &numConfigs);
132 EGLConfig* const configs = new EGLConfig[numConfigs];
133 eglChooseConfig(dpy, attrs, configs, numConfigs, &n);
134 for (int i=0 ; i<n ; i++) {
135 EGLint nativeVisualId = 0;
136 eglGetConfigAttrib(dpy, configs[i], EGL_NATIVE_VISUAL_ID, &nativeVisualId);
137 if (nativeVisualId>0 && format == nativeVisualId) {
138 *outConfig = configs[i];
139 delete [] configs;
140 return NO_ERROR;
141 }
142 }
143 delete [] configs;
144 return NAME_NOT_FOUND;
145}
146
147
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800148void DisplayHardware::init(uint32_t dpy)
149{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700150 mNativeWindow = new FramebufferNativeWindow();
Mathias Agopian0928e312009-08-07 16:38:10 -0700151 framebuffer_device_t const * fbDev = mNativeWindow->getDevice();
Mathias Agopian1f339ff2011-07-01 17:08:43 -0700152 if (!fbDev) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000153 ALOGE("Display subsystem failed to initialize. check logs. exiting...");
Mathias Agopian1f339ff2011-07-01 17:08:43 -0700154 exit(0);
155 }
156
Mathias Agopian61630912011-07-06 16:35:30 -0700157 int format;
158 ANativeWindow const * const window = mNativeWindow.get();
159 window->query(window, NATIVE_WINDOW_FORMAT, &format);
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700160 mDpiX = mNativeWindow->xdpi;
161 mDpiY = mNativeWindow->ydpi;
162 mRefreshRate = fbDev->fps;
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800163 mNextFakeVSync = 0;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700164
Mathias Agopian385977f2011-11-04 18:46:11 -0700165
166/* FIXME: this is a temporary HACK until we are able to report the refresh rate
167 * properly from the HAL. The WindowManagerService now relies on this value.
168 */
169#ifndef REFRESH_RATE
170 mRefreshRate = fbDev->fps;
171#else
172 mRefreshRate = REFRESH_RATE;
173#warning "refresh rate set via makefile to REFRESH_RATE"
174#endif
175
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800176 mRefreshPeriod = nsecs_t(1e9 / mRefreshRate);
177
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700178 EGLint w, h, dummy;
179 EGLint numConfigs=0;
180 EGLSurface surface;
181 EGLContext context;
Mathias Agopian61630912011-07-06 16:35:30 -0700182 EGLBoolean result;
183 status_t err;
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700184
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800185 // initialize EGL
Mathias Agopiana5b02e02009-09-04 18:49:03 -0700186 EGLint attribs[] = {
Mathias Agopian61630912011-07-06 16:35:30 -0700187 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
188 EGL_NONE, 0,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800189 EGL_NONE
190 };
Mathias Agopiana5b02e02009-09-04 18:49:03 -0700191
192 // debug: disable h/w rendering
193 char property[PROPERTY_VALUE_MAX];
194 if (property_get("debug.sf.hw", property, NULL) > 0) {
195 if (atoi(property) == 0) {
Steve Block32397c12012-01-05 23:22:43 +0000196 ALOGW("H/W composition disabled");
Mathias Agopiana5b02e02009-09-04 18:49:03 -0700197 attribs[2] = EGL_CONFIG_CAVEAT;
198 attribs[3] = EGL_SLOW_CONFIG;
199 }
200 }
201
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800202 // TODO: all the extensions below should be queried through
203 // eglGetProcAddress().
204
205 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
206 eglInitialize(display, NULL, NULL);
207 eglGetConfigs(display, NULL, 0, &numConfigs);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700208
Mathias Agopian61630912011-07-06 16:35:30 -0700209 EGLConfig config = NULL;
210 err = selectConfigForPixelFormat(display, attribs, format, &config);
Steve Blocke6f43dd2012-01-06 19:20:56 +0000211 ALOGE_IF(err, "couldn't find an EGLConfig matching the screen format");
Mathias Agopian6cf50a72009-08-06 16:05:39 -0700212
Mathias Agopian0928e312009-08-07 16:38:10 -0700213 EGLint r,g,b,a;
214 eglGetConfigAttrib(display, config, EGL_RED_SIZE, &r);
215 eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &g);
216 eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &b);
217 eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &a);
218
Mathias Agopian1e16b132009-05-07 17:40:23 -0700219 if (mNativeWindow->isUpdateOnDemand()) {
Mathias Agopian95a666b2009-09-24 14:57:26 -0700220 mFlags |= PARTIAL_UPDATES;
Mathias Agopian1e16b132009-05-07 17:40:23 -0700221 }
222
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800223 if (eglGetConfigAttrib(display, config, EGL_CONFIG_CAVEAT, &dummy) == EGL_TRUE) {
224 if (dummy == EGL_SLOW_CONFIG)
225 mFlags |= SLOW_CONFIG;
226 }
227
228 /*
229 * Create our main surface
230 */
231
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700232 surface = eglCreateWindowSurface(display, config, mNativeWindow.get(), NULL);
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700233 eglQuerySurface(display, surface, EGL_WIDTH, &mWidth);
234 eglQuerySurface(display, surface, EGL_HEIGHT, &mHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800235
Mathias Agopian95a666b2009-09-24 14:57:26 -0700236 if (mFlags & PARTIAL_UPDATES) {
237 // if we have partial updates, we definitely don't need to
238 // preserve the backbuffer, which may be costly.
Mathias Agopian0928bee2009-09-16 20:15:42 -0700239 eglSurfaceAttrib(display, surface,
240 EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED);
241 }
242
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800243 if (eglQuerySurface(display, surface, EGL_SWAP_BEHAVIOR, &dummy) == EGL_TRUE) {
244 if (dummy == EGL_BUFFER_PRESERVED) {
245 mFlags |= BUFFER_PRESERVED;
246 }
247 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800248
David 'Digit' Turnerae71acc2009-06-19 04:41:12 +0200249 /* Read density from build-specific ro.sf.lcd_density property
Mathias Agopian24e5f522009-08-12 21:18:15 -0700250 * except if it is overridden by qemu.sf.lcd_density.
David 'Digit' Turnerae71acc2009-06-19 04:41:12 +0200251 */
252 if (property_get("qemu.sf.lcd_density", property, NULL) <= 0) {
253 if (property_get("ro.sf.lcd_density", property, NULL) <= 0) {
Dima Zavin1b15e1e2012-03-14 17:15:10 -0700254 if (mDpiX && mDpiY) {
255 ALOGI("Using density info from display: xdpi=%d ydpi=%d\n",
256 mDpiX, mDpiY);
257 } else {
258 ALOGW("No display dpi and ro.sf.lcd_density not defined, using 160 dpi by default.");
259 mDpiX = mDpiY = 160;
260 }
David 'Digit' Turner694e10b2009-06-18 04:30:32 +0200261 }
David 'Digit' Turner31469e12009-07-29 00:38:58 +0200262 } else {
263 /* for the emulator case, reset the dpi values too */
264 mDpiX = mDpiY = atoi(property);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800265 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800266
Dima Zavin1b15e1e2012-03-14 17:15:10 -0700267 /* use the xdpi as our density baseline */
268 mDensity = mDpiX * (1.0f / 160.0f);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800269
270 /*
271 * Create our OpenGL ES context
272 */
273
Mathias Agopian67226812010-10-11 17:54:43 -0700274
275 EGLint contextAttributes[] = {
276#ifdef EGL_IMG_context_priority
277#ifdef HAS_CONTEXT_PRIORITY
278#warning "using EGL_IMG_context_priority"
279 EGL_CONTEXT_PRIORITY_LEVEL_IMG, EGL_CONTEXT_PRIORITY_HIGH_IMG,
280#endif
281#endif
282 EGL_NONE, EGL_NONE
283 };
284 context = eglCreateContext(display, config, NULL, contextAttributes);
285
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800286 mDisplay = display;
287 mConfig = config;
288 mSurface = surface;
289 mContext = context;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700290 mFormat = fbDev->format;
291 mPageFlipCount = 0;
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700292
293 /*
294 * Gather OpenGL ES extensions
295 */
296
Mathias Agopian61630912011-07-06 16:35:30 -0700297 result = eglMakeCurrent(display, surface, surface, context);
298 if (!result) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000299 ALOGE("Couldn't create a working GLES context. check logs. exiting...");
Mathias Agopian61630912011-07-06 16:35:30 -0700300 exit(0);
301 }
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700302
303 GLExtensions& extensions(GLExtensions::getInstance());
304 extensions.initWithGLStrings(
305 glGetString(GL_VENDOR),
306 glGetString(GL_RENDERER),
307 glGetString(GL_VERSION),
308 glGetString(GL_EXTENSIONS),
309 eglQueryString(display, EGL_VENDOR),
310 eglQueryString(display, EGL_VERSION),
311 eglQueryString(display, EGL_EXTENSIONS));
312
313 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
Mathias Agopian3d64e732011-04-18 15:59:24 -0700314 glGetIntegerv(GL_MAX_VIEWPORT_DIMS, mMaxViewportDims);
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700315
Steve Blocka19954a2012-01-04 20:05:49 +0000316 ALOGI("EGL informations:");
317 ALOGI("# of configs : %d", numConfigs);
318 ALOGI("vendor : %s", extensions.getEglVendor());
319 ALOGI("version : %s", extensions.getEglVersion());
320 ALOGI("extensions: %s", extensions.getEglExtension());
321 ALOGI("Client API: %s", eglQueryString(display, EGL_CLIENT_APIS)?:"Not Supported");
322 ALOGI("EGLSurface: %d-%d-%d-%d, config=%p", r, g, b, a, config);
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700323
Steve Blocka19954a2012-01-04 20:05:49 +0000324 ALOGI("OpenGL informations:");
325 ALOGI("vendor : %s", extensions.getVendor());
326 ALOGI("renderer : %s", extensions.getRenderer());
327 ALOGI("version : %s", extensions.getVersion());
328 ALOGI("extensions: %s", extensions.getExtension());
329 ALOGI("GL_MAX_TEXTURE_SIZE = %d", mMaxTextureSize);
330 ALOGI("GL_MAX_VIEWPORT_DIMS = %d x %d", mMaxViewportDims[0], mMaxViewportDims[1]);
331 ALOGI("flags = %08x", mFlags);
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700332
333 // Unbind the context from this thread
334 eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700335
336
337 // initialize the H/W composer
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700338 mHwc = new HWComposer(mFlinger);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700339 if (mHwc->initCheck() == NO_ERROR) {
340 mHwc->setFrameBuffer(mDisplay, mSurface);
341 }
342}
343
344HWComposer& DisplayHardware::getHwComposer() const {
345 return *mHwc;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800346}
347
348/*
349 * Clean up. Throw out our local state.
350 *
351 * (It's entirely possible we'll never get here, since this is meant
352 * for real hardware, which doesn't restart.)
353 */
354
355void DisplayHardware::fini()
356{
357 eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
358 eglTerminate(mDisplay);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800359}
360
361void DisplayHardware::releaseScreen() const
362{
363 DisplayHardwareBase::releaseScreen();
Antti Hatalaf5f27122010-09-09 02:33:05 -0700364 if (mHwc->initCheck() == NO_ERROR) {
365 mHwc->release();
366 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800367}
368
369void DisplayHardware::acquireScreen() const
370{
371 DisplayHardwareBase::acquireScreen();
372}
373
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800374uint32_t DisplayHardware::getPageFlipCount() const {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700375 return mPageFlipCount;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800376}
377
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800378// this needs to be thread safe
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800379nsecs_t DisplayHardware::waitForRefresh() const {
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800380 nsecs_t timestamp;
381 if (mVSync.wait(&timestamp) < 0) {
382 // vsync not supported!
383 usleep( getDelayToNextVSyncUs(&timestamp) );
384 }
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800385 mLastHwVSync = timestamp; // FIXME: Not thread safe
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800386 return timestamp;
387}
388
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800389nsecs_t DisplayHardware::getRefreshTimestamp() const {
390 // this returns the last refresh timestamp.
391 // if the last one is not available, we estimate it based on
392 // the refresh period and whatever closest timestamp we have.
393 nsecs_t now = systemTime();
394 return now - ((now - mLastHwVSync) % mRefreshPeriod);
395}
396
397nsecs_t DisplayHardware::getRefreshPeriod() const {
398 return mRefreshPeriod;
399}
400
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800401int32_t DisplayHardware::getDelayToNextVSyncUs(nsecs_t* timestamp) const {
402 Mutex::Autolock _l(mFakeVSyncMutex);
403 const nsecs_t period = mRefreshPeriod;
404 const nsecs_t now = systemTime(CLOCK_MONOTONIC);
405 nsecs_t next_vsync = mNextFakeVSync;
406 nsecs_t sleep = next_vsync - now;
407 if (sleep < 0) {
408 // we missed, find where the next vsync should be
409 sleep = (period - ((now - next_vsync) % period));
410 next_vsync = now + sleep;
411 }
412 mNextFakeVSync = next_vsync + period;
413 timestamp[0] = next_vsync;
414
415 // round to next microsecond
416 int32_t sleep_us = (sleep + 999LL) / 1000LL;
417
418 // guaranteed to be > 0
419 return sleep_us;
420}
421
Mathias Agopian74faca22009-09-17 16:18:16 -0700422status_t DisplayHardware::compositionComplete() const {
423 return mNativeWindow->compositionComplete();
424}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800425
426void DisplayHardware::flip(const Region& dirty) const
427{
428 checkGLErrors();
429
430 EGLDisplay dpy = mDisplay;
431 EGLSurface surface = mSurface;
432
Mathias Agopian5e78e092009-06-11 17:19:54 -0700433#ifdef EGL_ANDROID_swap_rectangle
Mathias Agopiandf3ca302009-05-04 19:29:25 -0700434 if (mFlags & SWAP_RECTANGLE) {
Mathias Agopianb8a55602009-06-26 19:06:36 -0700435 const Region newDirty(dirty.intersect(bounds()));
436 const Rect b(newDirty.getBounds());
Mathias Agopiandf3ca302009-05-04 19:29:25 -0700437 eglSetSwapRectangleANDROID(dpy, surface,
438 b.left, b.top, b.width(), b.height());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800439 }
Mathias Agopian5e78e092009-06-11 17:19:54 -0700440#endif
441
Mathias Agopian95a666b2009-09-24 14:57:26 -0700442 if (mFlags & PARTIAL_UPDATES) {
Mathias Agopian29d06ac2009-06-29 18:49:56 -0700443 mNativeWindow->setUpdateRectangle(dirty.getBounds());
Mathias Agopian1e16b132009-05-07 17:40:23 -0700444 }
445
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700446 mPageFlipCount++;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700447
448 if (mHwc->initCheck() == NO_ERROR) {
449 mHwc->commit();
450 } else {
451 eglSwapBuffers(dpy, surface);
452 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800453 checkEGLErrors("eglSwapBuffers");
454
455 // for debugging
456 //glClearColor(1,0,0,0);
457 //glClear(GL_COLOR_BUFFER_BIT);
458}
459
460uint32_t DisplayHardware::getFlags() const
461{
462 return mFlags;
463}
464
465void DisplayHardware::makeCurrent() const
466{
467 eglMakeCurrent(mDisplay, mSurface, mSurface, mContext);
468}
Erik Gilling1d21a9c2010-12-01 16:38:01 -0800469
470void DisplayHardware::dump(String8& res) const
471{
472 mNativeWindow->dump(res);
473}