blob: b7584b36b125808e2105eaf7c6fb7f145e0f31be [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 Agopianb5dd9c02012-03-22 12:15:54 -0700165 if (mDpiX == 0 || mDpiY == 0) {
166 ALOGE("invalid screen resolution from fb HAL (xdpi=%f, ydpi=%f), "
167 "defaulting to 160 dpi", mDpiX, mDpiY);
168 mDpiX = mDpiY = 160;
169 }
Mathias Agopian385977f2011-11-04 18:46:11 -0700170
Mathias Agopianb5dd9c02012-03-22 12:15:54 -0700171 class Density {
172 static int getDensityFromProperty(char const* propName) {
173 char property[PROPERTY_VALUE_MAX];
174 int density = 0;
175 if (property_get(propName, property, NULL) > 0) {
176 density = atoi(property);
177 }
178 return density;
179 }
180 public:
181 static int getEmuDensity() {
182 return getDensityFromProperty("qemu.sf.lcd_density"); }
183 static int getBuildDensity() {
184 return getDensityFromProperty("ro.sf.lcd_density"); }
185 };
186
187
188 // The density of the device is provided by a build property
189 mDensity = Density::getBuildDensity() / 160.0f;
190
191 if (mDensity == 0) {
192 // the build doesn't provide a density -- this is wrong!
193 // use xdpi instead
194 ALOGE("ro.sf.lcd_density must be defined as a build property");
195 mDensity = mDpiX / 160.0f;
196 }
197
198 if (Density::getEmuDensity()) {
199 // if "qemu.sf.lcd_density" is specified, it overrides everything
200 mDpiX = mDpiY = mDensity = Density::getEmuDensity();
201 mDensity /= 160.0f;
202 }
203
204
205
206 /* FIXME: this is a temporary HACK until we are able to report the refresh rate
207 * properly from the HAL. The WindowManagerService now relies on this value.
208 */
Mathias Agopian385977f2011-11-04 18:46:11 -0700209#ifndef REFRESH_RATE
210 mRefreshRate = fbDev->fps;
211#else
212 mRefreshRate = REFRESH_RATE;
213#warning "refresh rate set via makefile to REFRESH_RATE"
214#endif
215
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800216 mRefreshPeriod = nsecs_t(1e9 / mRefreshRate);
217
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700218 EGLint w, h, dummy;
219 EGLint numConfigs=0;
220 EGLSurface surface;
221 EGLContext context;
Mathias Agopian61630912011-07-06 16:35:30 -0700222 EGLBoolean result;
223 status_t err;
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700224
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800225 // initialize EGL
Mathias Agopiana5b02e02009-09-04 18:49:03 -0700226 EGLint attribs[] = {
Mathias Agopian61630912011-07-06 16:35:30 -0700227 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
228 EGL_NONE, 0,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800229 EGL_NONE
230 };
Mathias Agopiana5b02e02009-09-04 18:49:03 -0700231
232 // debug: disable h/w rendering
233 char property[PROPERTY_VALUE_MAX];
234 if (property_get("debug.sf.hw", property, NULL) > 0) {
235 if (atoi(property) == 0) {
Steve Block32397c12012-01-05 23:22:43 +0000236 ALOGW("H/W composition disabled");
Mathias Agopiana5b02e02009-09-04 18:49:03 -0700237 attribs[2] = EGL_CONFIG_CAVEAT;
238 attribs[3] = EGL_SLOW_CONFIG;
239 }
240 }
241
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800242 // TODO: all the extensions below should be queried through
243 // eglGetProcAddress().
244
245 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
246 eglInitialize(display, NULL, NULL);
247 eglGetConfigs(display, NULL, 0, &numConfigs);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700248
Mathias Agopian61630912011-07-06 16:35:30 -0700249 EGLConfig config = NULL;
250 err = selectConfigForPixelFormat(display, attribs, format, &config);
Steve Blocke6f43dd2012-01-06 19:20:56 +0000251 ALOGE_IF(err, "couldn't find an EGLConfig matching the screen format");
Mathias Agopian6cf50a72009-08-06 16:05:39 -0700252
Mathias Agopian0928e312009-08-07 16:38:10 -0700253 EGLint r,g,b,a;
254 eglGetConfigAttrib(display, config, EGL_RED_SIZE, &r);
255 eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &g);
256 eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &b);
257 eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &a);
258
Mathias Agopian1e16b132009-05-07 17:40:23 -0700259 if (mNativeWindow->isUpdateOnDemand()) {
Mathias Agopian95a666b2009-09-24 14:57:26 -0700260 mFlags |= PARTIAL_UPDATES;
Mathias Agopian1e16b132009-05-07 17:40:23 -0700261 }
262
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800263 if (eglGetConfigAttrib(display, config, EGL_CONFIG_CAVEAT, &dummy) == EGL_TRUE) {
264 if (dummy == EGL_SLOW_CONFIG)
265 mFlags |= SLOW_CONFIG;
266 }
267
268 /*
269 * Create our main surface
270 */
271
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700272 surface = eglCreateWindowSurface(display, config, mNativeWindow.get(), NULL);
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700273 eglQuerySurface(display, surface, EGL_WIDTH, &mWidth);
274 eglQuerySurface(display, surface, EGL_HEIGHT, &mHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800275
Mathias Agopian95a666b2009-09-24 14:57:26 -0700276 if (mFlags & PARTIAL_UPDATES) {
277 // if we have partial updates, we definitely don't need to
278 // preserve the backbuffer, which may be costly.
Mathias Agopian0928bee2009-09-16 20:15:42 -0700279 eglSurfaceAttrib(display, surface,
280 EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED);
281 }
282
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800283 if (eglQuerySurface(display, surface, EGL_SWAP_BEHAVIOR, &dummy) == EGL_TRUE) {
284 if (dummy == EGL_BUFFER_PRESERVED) {
285 mFlags |= BUFFER_PRESERVED;
286 }
287 }
Dima Zavin6fc0a9b2012-03-21 23:37:46 -0700288
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800289 /*
290 * Create our OpenGL ES context
291 */
292
Mathias Agopian67226812010-10-11 17:54:43 -0700293 EGLint contextAttributes[] = {
294#ifdef EGL_IMG_context_priority
295#ifdef HAS_CONTEXT_PRIORITY
296#warning "using EGL_IMG_context_priority"
297 EGL_CONTEXT_PRIORITY_LEVEL_IMG, EGL_CONTEXT_PRIORITY_HIGH_IMG,
298#endif
299#endif
300 EGL_NONE, EGL_NONE
301 };
302 context = eglCreateContext(display, config, NULL, contextAttributes);
303
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800304 mDisplay = display;
305 mConfig = config;
306 mSurface = surface;
307 mContext = context;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700308 mFormat = fbDev->format;
309 mPageFlipCount = 0;
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700310
311 /*
312 * Gather OpenGL ES extensions
313 */
314
Mathias Agopian61630912011-07-06 16:35:30 -0700315 result = eglMakeCurrent(display, surface, surface, context);
316 if (!result) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000317 ALOGE("Couldn't create a working GLES context. check logs. exiting...");
Mathias Agopian61630912011-07-06 16:35:30 -0700318 exit(0);
319 }
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700320
321 GLExtensions& extensions(GLExtensions::getInstance());
322 extensions.initWithGLStrings(
323 glGetString(GL_VENDOR),
324 glGetString(GL_RENDERER),
325 glGetString(GL_VERSION),
326 glGetString(GL_EXTENSIONS),
327 eglQueryString(display, EGL_VENDOR),
328 eglQueryString(display, EGL_VERSION),
329 eglQueryString(display, EGL_EXTENSIONS));
330
331 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
Mathias Agopian3d64e732011-04-18 15:59:24 -0700332 glGetIntegerv(GL_MAX_VIEWPORT_DIMS, mMaxViewportDims);
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700333
Steve Blocka19954a2012-01-04 20:05:49 +0000334 ALOGI("EGL informations:");
335 ALOGI("# of configs : %d", numConfigs);
336 ALOGI("vendor : %s", extensions.getEglVendor());
337 ALOGI("version : %s", extensions.getEglVersion());
338 ALOGI("extensions: %s", extensions.getEglExtension());
339 ALOGI("Client API: %s", eglQueryString(display, EGL_CLIENT_APIS)?:"Not Supported");
340 ALOGI("EGLSurface: %d-%d-%d-%d, config=%p", r, g, b, a, config);
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700341
Steve Blocka19954a2012-01-04 20:05:49 +0000342 ALOGI("OpenGL informations:");
343 ALOGI("vendor : %s", extensions.getVendor());
344 ALOGI("renderer : %s", extensions.getRenderer());
345 ALOGI("version : %s", extensions.getVersion());
346 ALOGI("extensions: %s", extensions.getExtension());
347 ALOGI("GL_MAX_TEXTURE_SIZE = %d", mMaxTextureSize);
348 ALOGI("GL_MAX_VIEWPORT_DIMS = %d x %d", mMaxViewportDims[0], mMaxViewportDims[1]);
349 ALOGI("flags = %08x", mFlags);
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700350
351 // Unbind the context from this thread
352 eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700353
354
355 // initialize the H/W composer
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700356 mHwc = new HWComposer(mFlinger);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700357 if (mHwc->initCheck() == NO_ERROR) {
358 mHwc->setFrameBuffer(mDisplay, mSurface);
359 }
360}
361
362HWComposer& DisplayHardware::getHwComposer() const {
363 return *mHwc;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800364}
365
366/*
367 * Clean up. Throw out our local state.
368 *
369 * (It's entirely possible we'll never get here, since this is meant
370 * for real hardware, which doesn't restart.)
371 */
372
373void DisplayHardware::fini()
374{
375 eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
376 eglTerminate(mDisplay);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800377}
378
379void DisplayHardware::releaseScreen() const
380{
381 DisplayHardwareBase::releaseScreen();
Antti Hatalaf5f27122010-09-09 02:33:05 -0700382 if (mHwc->initCheck() == NO_ERROR) {
383 mHwc->release();
384 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800385}
386
387void DisplayHardware::acquireScreen() const
388{
389 DisplayHardwareBase::acquireScreen();
390}
391
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800392uint32_t DisplayHardware::getPageFlipCount() const {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700393 return mPageFlipCount;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800394}
395
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800396// this needs to be thread safe
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800397nsecs_t DisplayHardware::waitForRefresh() const {
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800398 nsecs_t timestamp;
399 if (mVSync.wait(&timestamp) < 0) {
400 // vsync not supported!
401 usleep( getDelayToNextVSyncUs(&timestamp) );
402 }
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800403 mLastHwVSync = timestamp; // FIXME: Not thread safe
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800404 return timestamp;
405}
406
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800407nsecs_t DisplayHardware::getRefreshTimestamp() const {
408 // this returns the last refresh timestamp.
409 // if the last one is not available, we estimate it based on
410 // the refresh period and whatever closest timestamp we have.
411 nsecs_t now = systemTime();
412 return now - ((now - mLastHwVSync) % mRefreshPeriod);
413}
414
415nsecs_t DisplayHardware::getRefreshPeriod() const {
416 return mRefreshPeriod;
417}
418
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800419int32_t DisplayHardware::getDelayToNextVSyncUs(nsecs_t* timestamp) const {
420 Mutex::Autolock _l(mFakeVSyncMutex);
421 const nsecs_t period = mRefreshPeriod;
422 const nsecs_t now = systemTime(CLOCK_MONOTONIC);
423 nsecs_t next_vsync = mNextFakeVSync;
424 nsecs_t sleep = next_vsync - now;
425 if (sleep < 0) {
426 // we missed, find where the next vsync should be
427 sleep = (period - ((now - next_vsync) % period));
428 next_vsync = now + sleep;
429 }
430 mNextFakeVSync = next_vsync + period;
431 timestamp[0] = next_vsync;
432
433 // round to next microsecond
434 int32_t sleep_us = (sleep + 999LL) / 1000LL;
435
436 // guaranteed to be > 0
437 return sleep_us;
438}
439
Mathias Agopian74faca22009-09-17 16:18:16 -0700440status_t DisplayHardware::compositionComplete() const {
441 return mNativeWindow->compositionComplete();
442}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800443
444void DisplayHardware::flip(const Region& dirty) const
445{
446 checkGLErrors();
447
448 EGLDisplay dpy = mDisplay;
449 EGLSurface surface = mSurface;
450
Mathias Agopian5e78e092009-06-11 17:19:54 -0700451#ifdef EGL_ANDROID_swap_rectangle
Mathias Agopiandf3ca302009-05-04 19:29:25 -0700452 if (mFlags & SWAP_RECTANGLE) {
Mathias Agopianb8a55602009-06-26 19:06:36 -0700453 const Region newDirty(dirty.intersect(bounds()));
454 const Rect b(newDirty.getBounds());
Mathias Agopiandf3ca302009-05-04 19:29:25 -0700455 eglSetSwapRectangleANDROID(dpy, surface,
456 b.left, b.top, b.width(), b.height());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800457 }
Mathias Agopian5e78e092009-06-11 17:19:54 -0700458#endif
459
Mathias Agopian95a666b2009-09-24 14:57:26 -0700460 if (mFlags & PARTIAL_UPDATES) {
Mathias Agopian29d06ac2009-06-29 18:49:56 -0700461 mNativeWindow->setUpdateRectangle(dirty.getBounds());
Mathias Agopian1e16b132009-05-07 17:40:23 -0700462 }
463
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700464 mPageFlipCount++;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700465
466 if (mHwc->initCheck() == NO_ERROR) {
467 mHwc->commit();
468 } else {
469 eglSwapBuffers(dpy, surface);
470 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800471 checkEGLErrors("eglSwapBuffers");
472
473 // for debugging
474 //glClearColor(1,0,0,0);
475 //glClear(GL_COLOR_BUFFER_BIT);
476}
477
478uint32_t DisplayHardware::getFlags() const
479{
480 return mFlags;
481}
482
483void DisplayHardware::makeCurrent() const
484{
485 eglMakeCurrent(mDisplay, mSurface, mSurface, mContext);
486}
Erik Gilling1d21a9c2010-12-01 16:38:01 -0800487
488void DisplayHardware::dump(String8& res) const
489{
490 mNativeWindow->dump(res);
491}