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> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
| 29 | #include <GLES/gl.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 30 | #include <EGL/egl.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | #include <EGL/eglext.h> |
| 32 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 33 | #include <hardware/gralloc.h> |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 34 | #include <private/gui/SharedBufferStack.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 36 | #include "DisplayHardware/FramebufferSurface.h" |
| 37 | #include "DisplayHardware/DisplayHardwareBase.h" |
| 38 | #include "DisplayHardware/HWComposer.h" |
| 39 | |
| 40 | #include "DisplayHardware.h" |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 41 | #include "GLExtensions.h" |
Mathias Agopian | c7d14e2 | 2011-08-01 16:32:21 -0700 | [diff] [blame] | 42 | #include "SurfaceFlinger.h" |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 43 | #include "LayerBase.h" |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 44 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 45 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | using namespace android; |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 47 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | |
| 49 | static __attribute__((noinline)) |
| 50 | void checkGLErrors() |
| 51 | { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 52 | do { |
| 53 | // there could be more than one error flag |
| 54 | GLenum error = glGetError(); |
| 55 | if (error == GL_NO_ERROR) |
| 56 | break; |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 57 | ALOGE("GL error 0x%04x", int(error)); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 58 | } while(true); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static __attribute__((noinline)) |
| 62 | void checkEGLErrors(const char* token) |
| 63 | { |
Mathias Agopian | 870b8aa | 2012-02-24 16:42:46 -0800 | [diff] [blame] | 64 | struct EGLUtils { |
| 65 | static const char *strerror(EGLint err) { |
| 66 | switch (err){ |
| 67 | case EGL_SUCCESS: return "EGL_SUCCESS"; |
| 68 | case EGL_NOT_INITIALIZED: return "EGL_NOT_INITIALIZED"; |
| 69 | case EGL_BAD_ACCESS: return "EGL_BAD_ACCESS"; |
| 70 | case EGL_BAD_ALLOC: return "EGL_BAD_ALLOC"; |
| 71 | case EGL_BAD_ATTRIBUTE: return "EGL_BAD_ATTRIBUTE"; |
| 72 | case EGL_BAD_CONFIG: return "EGL_BAD_CONFIG"; |
| 73 | case EGL_BAD_CONTEXT: return "EGL_BAD_CONTEXT"; |
| 74 | case EGL_BAD_CURRENT_SURFACE: return "EGL_BAD_CURRENT_SURFACE"; |
| 75 | case EGL_BAD_DISPLAY: return "EGL_BAD_DISPLAY"; |
| 76 | case EGL_BAD_MATCH: return "EGL_BAD_MATCH"; |
| 77 | case EGL_BAD_NATIVE_PIXMAP: return "EGL_BAD_NATIVE_PIXMAP"; |
| 78 | case EGL_BAD_NATIVE_WINDOW: return "EGL_BAD_NATIVE_WINDOW"; |
| 79 | case EGL_BAD_PARAMETER: return "EGL_BAD_PARAMETER"; |
| 80 | case EGL_BAD_SURFACE: return "EGL_BAD_SURFACE"; |
| 81 | case EGL_CONTEXT_LOST: return "EGL_CONTEXT_LOST"; |
| 82 | default: return "UNKNOWN"; |
| 83 | } |
| 84 | } |
| 85 | }; |
| 86 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | EGLint error = eglGetError(); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 88 | if (error && error != EGL_SUCCESS) { |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 89 | ALOGE("%s: EGL error 0x%04x (%s)", |
Mathias Agopian | 0928e31 | 2009-08-07 16:38:10 -0700 | [diff] [blame] | 90 | token, int(error), EGLUtils::strerror(error)); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 91 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 94 | // ---------------------------------------------------------------------------- |
| 95 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | /* |
| 97 | * Initialize the display to the specified values. |
| 98 | * |
| 99 | */ |
| 100 | |
| 101 | DisplayHardware::DisplayHardware( |
| 102 | const sp<SurfaceFlinger>& flinger, |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 103 | int display, |
| 104 | const sp<SurfaceTextureClient>& surface, |
| 105 | EGLConfig config) |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 106 | : DisplayHardwareBase(display), |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 107 | mFlinger(flinger), |
| 108 | mDisplayId(display), |
| 109 | mHwc(0), |
| 110 | mNativeWindow(surface), |
| 111 | mFlags(0), |
| 112 | mSecureLayerVisible(false) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 114 | init(config); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 117 | DisplayHardware::~DisplayHardware() { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | } |
| 119 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 120 | float DisplayHardware::getDpiX() const { |
| 121 | return mDpiX; |
Mathias Agopian | 3d64e73 | 2011-04-18 15:59:24 -0700 | [diff] [blame] | 122 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 124 | float DisplayHardware::getDpiY() const { |
| 125 | return mDpiY; |
Mathias Agopian | 6163091 | 2011-07-06 16:35:30 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 128 | float DisplayHardware::getDensity() const { |
| 129 | return mDensity; |
| 130 | } |
Mathias Agopian | 6163091 | 2011-07-06 16:35:30 -0700 | [diff] [blame] | 131 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 132 | float DisplayHardware::getRefreshRate() const { |
| 133 | return mRefreshRate; |
| 134 | } |
| 135 | |
| 136 | int DisplayHardware::getWidth() const { |
| 137 | return mDisplayWidth; |
| 138 | } |
| 139 | |
| 140 | int DisplayHardware::getHeight() const { |
| 141 | return mDisplayHeight; |
| 142 | } |
| 143 | |
| 144 | PixelFormat DisplayHardware::getFormat() const { |
| 145 | return mFormat; |
| 146 | } |
| 147 | |
| 148 | EGLSurface DisplayHardware::getEGLSurface() const { |
| 149 | return mSurface; |
| 150 | } |
| 151 | |
| 152 | void DisplayHardware::init(EGLConfig config) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 154 | ANativeWindow* const window = mNativeWindow.get(); |
| 155 | |
| 156 | int concreteType; |
| 157 | window->query(window, NATIVE_WINDOW_CONCRETE_TYPE, &concreteType); |
| 158 | if (concreteType == NATIVE_WINDOW_FRAMEBUFFER) { |
| 159 | mFramebufferSurface = static_cast<FramebufferSurface *>(mNativeWindow.get()); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Mathias Agopian | 6163091 | 2011-07-06 16:35:30 -0700 | [diff] [blame] | 162 | int format; |
Mathias Agopian | 6163091 | 2011-07-06 16:35:30 -0700 | [diff] [blame] | 163 | window->query(window, NATIVE_WINDOW_FORMAT, &format); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 164 | mDpiX = window->xdpi; |
| 165 | mDpiY = window->ydpi; |
| 166 | if (mFramebufferSurface != NULL) { |
| 167 | mRefreshRate = mFramebufferSurface->getRefreshRate(); |
| 168 | } else { |
| 169 | mRefreshRate = 60; |
Mathias Agopian | b5dd9c0 | 2012-03-22 12:15:54 -0700 | [diff] [blame] | 170 | } |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 171 | mRefreshPeriod = nsecs_t(1e9 / mRefreshRate); |
Mathias Agopian | 385977f | 2011-11-04 18:46:11 -0700 | [diff] [blame] | 172 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 173 | |
| 174 | // TODO: Not sure if display density should handled by SF any longer |
Mathias Agopian | b5dd9c0 | 2012-03-22 12:15:54 -0700 | [diff] [blame] | 175 | class Density { |
| 176 | static int getDensityFromProperty(char const* propName) { |
| 177 | char property[PROPERTY_VALUE_MAX]; |
| 178 | int density = 0; |
| 179 | if (property_get(propName, property, NULL) > 0) { |
| 180 | density = atoi(property); |
| 181 | } |
| 182 | return density; |
| 183 | } |
| 184 | public: |
| 185 | static int getEmuDensity() { |
| 186 | return getDensityFromProperty("qemu.sf.lcd_density"); } |
| 187 | static int getBuildDensity() { |
| 188 | return getDensityFromProperty("ro.sf.lcd_density"); } |
| 189 | }; |
Mathias Agopian | b5dd9c0 | 2012-03-22 12:15:54 -0700 | [diff] [blame] | 190 | // The density of the device is provided by a build property |
| 191 | mDensity = Density::getBuildDensity() / 160.0f; |
Mathias Agopian | b5dd9c0 | 2012-03-22 12:15:54 -0700 | [diff] [blame] | 192 | if (mDensity == 0) { |
| 193 | // the build doesn't provide a density -- this is wrong! |
| 194 | // use xdpi instead |
| 195 | ALOGE("ro.sf.lcd_density must be defined as a build property"); |
| 196 | mDensity = mDpiX / 160.0f; |
| 197 | } |
Mathias Agopian | b5dd9c0 | 2012-03-22 12:15:54 -0700 | [diff] [blame] | 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 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | /* |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 205 | * Create our display's surface |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | */ |
| 207 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 208 | EGLSurface surface; |
| 209 | EGLint w, h; |
| 210 | EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 211 | surface = eglCreateWindowSurface(display, config, window, NULL); |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 212 | eglQuerySurface(display, surface, EGL_WIDTH, &mDisplayWidth); |
| 213 | eglQuerySurface(display, surface, EGL_HEIGHT, &mDisplayHeight); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 215 | if (mFramebufferSurface != NULL) { |
| 216 | if (mFramebufferSurface->isUpdateOnDemand()) { |
| 217 | mFlags |= PARTIAL_UPDATES; |
| 218 | // if we have partial updates, we definitely don't need to |
| 219 | // preserve the backbuffer, which may be costly. |
| 220 | eglSurfaceAttrib(display, surface, |
| 221 | EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED); |
| 222 | } |
Mathias Agopian | 0928bee | 2009-09-16 20:15:42 -0700 | [diff] [blame] | 223 | } |
| 224 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | mDisplay = display; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | mSurface = surface; |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 227 | mFormat = format; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 228 | mPageFlipCount = 0; |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 229 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 230 | // initialize the H/W composer |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 231 | mHwc = new HWComposer(mFlinger, *this, mRefreshPeriod); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 232 | if (mHwc->initCheck() == NO_ERROR) { |
| 233 | mHwc->setFrameBuffer(mDisplay, mSurface); |
| 234 | } |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 235 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 236 | // initialize the shared control block |
| 237 | surface_flinger_cblk_t* const scblk = mFlinger->getControlBlock(); |
| 238 | scblk->connected |= 1 << mDisplayId; |
| 239 | display_cblk_t* dcblk = &scblk->displays[mDisplayId]; |
| 240 | memset(dcblk, 0, sizeof(display_cblk_t)); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 241 | dcblk->format = format; |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 242 | dcblk->xdpi = mDpiX; |
| 243 | dcblk->ydpi = mDpiY; |
| 244 | dcblk->fps = mRefreshRate; |
| 245 | dcblk->density = mDensity; |
Mathias Agopian | 98a121a | 2012-07-24 21:08:59 -0700 | [diff] [blame^] | 246 | |
| 247 | // initialize the display orientation transform. |
| 248 | DisplayHardware::setOrientation(ISurfaceComposer::eOrientationDefault); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 251 | void DisplayHardware::setVSyncHandler(const sp<VSyncHandler>& handler) { |
| 252 | Mutex::Autolock _l(mLock); |
| 253 | mVSyncHandler = handler; |
| 254 | } |
| 255 | |
Mathias Agopian | 03e4072 | 2012-04-26 16:11:59 -0700 | [diff] [blame] | 256 | void DisplayHardware::eventControl(int event, int enabled) { |
| 257 | if (event == EVENT_VSYNC) { |
| 258 | mPowerHAL.vsyncHint(enabled); |
| 259 | } |
| 260 | mHwc->eventControl(event, enabled); |
| 261 | } |
| 262 | |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 263 | void DisplayHardware::onVSyncReceived(int dpy, nsecs_t timestamp) { |
| 264 | sp<VSyncHandler> handler; |
| 265 | { // scope for the lock |
| 266 | Mutex::Autolock _l(mLock); |
| 267 | mLastHwVSync = timestamp; |
| 268 | if (mVSyncHandler != NULL) { |
| 269 | handler = mVSyncHandler.promote(); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | if (handler != NULL) { |
| 274 | handler->onVSyncReceived(dpy, timestamp); |
| 275 | } |
| 276 | } |
| 277 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 278 | HWComposer& DisplayHardware::getHwComposer() const { |
| 279 | return *mHwc; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | } |
| 281 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | void DisplayHardware::releaseScreen() const |
| 283 | { |
| 284 | DisplayHardwareBase::releaseScreen(); |
Antti Hatala | f5f2712 | 2010-09-09 02:33:05 -0700 | [diff] [blame] | 285 | if (mHwc->initCheck() == NO_ERROR) { |
| 286 | mHwc->release(); |
| 287 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | void DisplayHardware::acquireScreen() const |
| 291 | { |
Colin Cross | 10fbdb6 | 2012-07-12 17:56:34 -0700 | [diff] [blame] | 292 | if (mHwc->initCheck() == NO_ERROR) { |
| 293 | mHwc->acquire(); |
| 294 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | DisplayHardwareBase::acquireScreen(); |
| 296 | } |
| 297 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 298 | uint32_t DisplayHardware::getPageFlipCount() const { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 299 | return mPageFlipCount; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 300 | } |
| 301 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 302 | nsecs_t DisplayHardware::getRefreshTimestamp() const { |
| 303 | // this returns the last refresh timestamp. |
| 304 | // if the last one is not available, we estimate it based on |
| 305 | // the refresh period and whatever closest timestamp we have. |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 306 | Mutex::Autolock _l(mLock); |
| 307 | nsecs_t now = systemTime(CLOCK_MONOTONIC); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 308 | return now - ((now - mLastHwVSync) % mRefreshPeriod); |
| 309 | } |
| 310 | |
| 311 | nsecs_t DisplayHardware::getRefreshPeriod() const { |
| 312 | return mRefreshPeriod; |
| 313 | } |
| 314 | |
Mathias Agopian | 74faca2 | 2009-09-17 16:18:16 -0700 | [diff] [blame] | 315 | status_t DisplayHardware::compositionComplete() const { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 316 | if (mFramebufferSurface == NULL) { |
| 317 | return NO_ERROR; |
| 318 | } |
| 319 | return mFramebufferSurface->compositionComplete(); |
Mathias Agopian | 74faca2 | 2009-09-17 16:18:16 -0700 | [diff] [blame] | 320 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | |
| 322 | void DisplayHardware::flip(const Region& dirty) const |
| 323 | { |
| 324 | checkGLErrors(); |
| 325 | |
| 326 | EGLDisplay dpy = mDisplay; |
| 327 | EGLSurface surface = mSurface; |
| 328 | |
Mathias Agopian | 5e78e09 | 2009-06-11 17:19:54 -0700 | [diff] [blame] | 329 | #ifdef EGL_ANDROID_swap_rectangle |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 330 | if (mFlags & SWAP_RECTANGLE) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 331 | const Region newDirty(dirty.intersect(bounds())); |
| 332 | const Rect b(newDirty.getBounds()); |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 333 | eglSetSwapRectangleANDROID(dpy, surface, |
| 334 | b.left, b.top, b.width(), b.height()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | } |
Mathias Agopian | 5e78e09 | 2009-06-11 17:19:54 -0700 | [diff] [blame] | 336 | #endif |
| 337 | |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 338 | if (mFlags & PARTIAL_UPDATES) { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 339 | if (mFramebufferSurface != NULL) { |
| 340 | mFramebufferSurface->setUpdateRectangle(dirty.getBounds()); |
| 341 | } |
Mathias Agopian | 1e16b13 | 2009-05-07 17:40:23 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 344 | mPageFlipCount++; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 345 | |
| 346 | if (mHwc->initCheck() == NO_ERROR) { |
| 347 | mHwc->commit(); |
| 348 | } else { |
| 349 | eglSwapBuffers(dpy, surface); |
| 350 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | checkEGLErrors("eglSwapBuffers"); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | uint32_t DisplayHardware::getFlags() const |
| 355 | { |
| 356 | return mFlags; |
| 357 | } |
| 358 | |
Erik Gilling | 1d21a9c | 2010-12-01 16:38:01 -0800 | [diff] [blame] | 359 | void DisplayHardware::dump(String8& res) const |
| 360 | { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 361 | if (mFramebufferSurface != NULL) { |
| 362 | mFramebufferSurface->dump(res); |
| 363 | } |
Erik Gilling | 1d21a9c | 2010-12-01 16:38:01 -0800 | [diff] [blame] | 364 | } |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 365 | |
| 366 | // ---------------------------------------------------------------------------- |
| 367 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 368 | void DisplayHardware::setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers) { |
| 369 | mVisibleLayersSortedByZ = layers; |
| 370 | size_t count = layers.size(); |
| 371 | for (size_t i=0 ; i<count ; i++) { |
| 372 | if (layers[i]->isSecure()) { |
| 373 | mSecureLayerVisible = true; |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | Vector< sp<LayerBase> > DisplayHardware::getVisibleLayersSortedByZ() const { |
| 379 | return mVisibleLayersSortedByZ; |
| 380 | } |
| 381 | |
| 382 | bool DisplayHardware::getSecureLayerVisible() const { |
| 383 | return mSecureLayerVisible; |
| 384 | } |
| 385 | |
| 386 | // ---------------------------------------------------------------------------- |
| 387 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 388 | status_t DisplayHardware::orientationToTransfrom( |
| 389 | int orientation, int w, int h, Transform* tr) |
| 390 | { |
| 391 | uint32_t flags = 0; |
| 392 | switch (orientation) { |
| 393 | case ISurfaceComposer::eOrientationDefault: |
| 394 | flags = Transform::ROT_0; |
| 395 | break; |
| 396 | case ISurfaceComposer::eOrientation90: |
| 397 | flags = Transform::ROT_90; |
| 398 | break; |
| 399 | case ISurfaceComposer::eOrientation180: |
| 400 | flags = Transform::ROT_180; |
| 401 | break; |
| 402 | case ISurfaceComposer::eOrientation270: |
| 403 | flags = Transform::ROT_270; |
| 404 | break; |
| 405 | default: |
| 406 | return BAD_VALUE; |
| 407 | } |
| 408 | tr->set(flags, w, h); |
| 409 | return NO_ERROR; |
| 410 | } |
| 411 | |
Mathias Agopian | 98a121a | 2012-07-24 21:08:59 -0700 | [diff] [blame^] | 412 | status_t DisplayHardware::setOrientation(int orientation) { |
| 413 | int w = mDisplayWidth; |
| 414 | int h = mDisplayHeight; |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 415 | |
Mathias Agopian | 98a121a | 2012-07-24 21:08:59 -0700 | [diff] [blame^] | 416 | DisplayHardware::orientationToTransfrom( |
| 417 | orientation, w, h, &mGlobalTransform); |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 418 | if (orientation & ISurfaceComposer::eOrientationSwapMask) { |
Mathias Agopian | 98a121a | 2012-07-24 21:08:59 -0700 | [diff] [blame^] | 419 | int tmp = w; |
| 420 | w = h; |
| 421 | h = tmp; |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 422 | } |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 423 | mOrientation = orientation; |
Mathias Agopian | 98a121a | 2012-07-24 21:08:59 -0700 | [diff] [blame^] | 424 | |
| 425 | // update the shared control block |
| 426 | surface_flinger_cblk_t* const scblk = mFlinger->getControlBlock(); |
| 427 | volatile display_cblk_t* dcblk = &scblk->displays[mDisplayId]; |
| 428 | dcblk->orientation = orientation; |
| 429 | dcblk->w = w; |
| 430 | dcblk->h = h; |
| 431 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 432 | return NO_ERROR; |
| 433 | } |