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 | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 236 | // initialize the display orientation transform. |
| 237 | // it's a constant that should come from the display driver. |
| 238 | int displayOrientation = ISurfaceComposer::eOrientationDefault; |
| 239 | char property[PROPERTY_VALUE_MAX]; |
| 240 | if (property_get("ro.sf.hwrotation", property, NULL) > 0) { |
| 241 | //displayOrientation |
| 242 | switch (atoi(property)) { |
| 243 | case 90: |
| 244 | displayOrientation = ISurfaceComposer::eOrientation90; |
| 245 | break; |
| 246 | case 270: |
| 247 | displayOrientation = ISurfaceComposer::eOrientation270; |
| 248 | break; |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | w = mDisplayWidth; |
| 253 | h = mDisplayHeight; |
| 254 | DisplayHardware::orientationToTransfrom(displayOrientation, w, h, |
| 255 | &mDisplayTransform); |
| 256 | if (displayOrientation & ISurfaceComposer::eOrientationSwapMask) { |
| 257 | mLogicalDisplayWidth = h; |
| 258 | mLogicalDisplayHeight = w; |
| 259 | } else { |
| 260 | mLogicalDisplayWidth = w; |
| 261 | mLogicalDisplayHeight = h; |
| 262 | } |
| 263 | DisplayHardware::setOrientation(ISurfaceComposer::eOrientationDefault); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 264 | |
| 265 | // initialize the shared control block |
| 266 | surface_flinger_cblk_t* const scblk = mFlinger->getControlBlock(); |
| 267 | scblk->connected |= 1 << mDisplayId; |
| 268 | display_cblk_t* dcblk = &scblk->displays[mDisplayId]; |
| 269 | memset(dcblk, 0, sizeof(display_cblk_t)); |
| 270 | dcblk->w = w; // XXX: plane.getWidth(); |
| 271 | dcblk->h = h; // XXX: plane.getHeight(); |
| 272 | dcblk->format = format; |
| 273 | dcblk->orientation = ISurfaceComposer::eOrientationDefault; |
| 274 | dcblk->xdpi = mDpiX; |
| 275 | dcblk->ydpi = mDpiY; |
| 276 | dcblk->fps = mRefreshRate; |
| 277 | dcblk->density = mDensity; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 280 | void DisplayHardware::setVSyncHandler(const sp<VSyncHandler>& handler) { |
| 281 | Mutex::Autolock _l(mLock); |
| 282 | mVSyncHandler = handler; |
| 283 | } |
| 284 | |
Mathias Agopian | 03e4072 | 2012-04-26 16:11:59 -0700 | [diff] [blame] | 285 | void DisplayHardware::eventControl(int event, int enabled) { |
| 286 | if (event == EVENT_VSYNC) { |
| 287 | mPowerHAL.vsyncHint(enabled); |
| 288 | } |
| 289 | mHwc->eventControl(event, enabled); |
| 290 | } |
| 291 | |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 292 | void DisplayHardware::onVSyncReceived(int dpy, nsecs_t timestamp) { |
| 293 | sp<VSyncHandler> handler; |
| 294 | { // scope for the lock |
| 295 | Mutex::Autolock _l(mLock); |
| 296 | mLastHwVSync = timestamp; |
| 297 | if (mVSyncHandler != NULL) { |
| 298 | handler = mVSyncHandler.promote(); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | if (handler != NULL) { |
| 303 | handler->onVSyncReceived(dpy, timestamp); |
| 304 | } |
| 305 | } |
| 306 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 307 | HWComposer& DisplayHardware::getHwComposer() const { |
| 308 | return *mHwc; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | } |
| 310 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | void DisplayHardware::releaseScreen() const |
| 312 | { |
| 313 | DisplayHardwareBase::releaseScreen(); |
Antti Hatala | f5f2712 | 2010-09-09 02:33:05 -0700 | [diff] [blame] | 314 | if (mHwc->initCheck() == NO_ERROR) { |
| 315 | mHwc->release(); |
| 316 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | void DisplayHardware::acquireScreen() const |
| 320 | { |
Colin Cross | 10fbdb6 | 2012-07-12 17:56:34 -0700 | [diff] [blame] | 321 | if (mHwc->initCheck() == NO_ERROR) { |
| 322 | mHwc->acquire(); |
| 323 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | DisplayHardwareBase::acquireScreen(); |
| 325 | } |
| 326 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | uint32_t DisplayHardware::getPageFlipCount() const { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 328 | return mPageFlipCount; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | } |
| 330 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 331 | nsecs_t DisplayHardware::getRefreshTimestamp() const { |
| 332 | // this returns the last refresh timestamp. |
| 333 | // if the last one is not available, we estimate it based on |
| 334 | // the refresh period and whatever closest timestamp we have. |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 335 | Mutex::Autolock _l(mLock); |
| 336 | nsecs_t now = systemTime(CLOCK_MONOTONIC); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 337 | return now - ((now - mLastHwVSync) % mRefreshPeriod); |
| 338 | } |
| 339 | |
| 340 | nsecs_t DisplayHardware::getRefreshPeriod() const { |
| 341 | return mRefreshPeriod; |
| 342 | } |
| 343 | |
Mathias Agopian | 74faca2 | 2009-09-17 16:18:16 -0700 | [diff] [blame] | 344 | status_t DisplayHardware::compositionComplete() const { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 345 | if (mFramebufferSurface == NULL) { |
| 346 | return NO_ERROR; |
| 347 | } |
| 348 | return mFramebufferSurface->compositionComplete(); |
Mathias Agopian | 74faca2 | 2009-09-17 16:18:16 -0700 | [diff] [blame] | 349 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | |
| 351 | void DisplayHardware::flip(const Region& dirty) const |
| 352 | { |
| 353 | checkGLErrors(); |
| 354 | |
| 355 | EGLDisplay dpy = mDisplay; |
| 356 | EGLSurface surface = mSurface; |
| 357 | |
Mathias Agopian | 5e78e09 | 2009-06-11 17:19:54 -0700 | [diff] [blame] | 358 | #ifdef EGL_ANDROID_swap_rectangle |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 359 | if (mFlags & SWAP_RECTANGLE) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 360 | const Region newDirty(dirty.intersect(bounds())); |
| 361 | const Rect b(newDirty.getBounds()); |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 362 | eglSetSwapRectangleANDROID(dpy, surface, |
| 363 | b.left, b.top, b.width(), b.height()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | } |
Mathias Agopian | 5e78e09 | 2009-06-11 17:19:54 -0700 | [diff] [blame] | 365 | #endif |
| 366 | |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 367 | if (mFlags & PARTIAL_UPDATES) { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 368 | if (mFramebufferSurface != NULL) { |
| 369 | mFramebufferSurface->setUpdateRectangle(dirty.getBounds()); |
| 370 | } |
Mathias Agopian | 1e16b13 | 2009-05-07 17:40:23 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 373 | mPageFlipCount++; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 374 | |
| 375 | if (mHwc->initCheck() == NO_ERROR) { |
| 376 | mHwc->commit(); |
| 377 | } else { |
| 378 | eglSwapBuffers(dpy, surface); |
| 379 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | checkEGLErrors("eglSwapBuffers"); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | uint32_t DisplayHardware::getFlags() const |
| 384 | { |
| 385 | return mFlags; |
| 386 | } |
| 387 | |
Erik Gilling | 1d21a9c | 2010-12-01 16:38:01 -0800 | [diff] [blame] | 388 | void DisplayHardware::dump(String8& res) const |
| 389 | { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 390 | if (mFramebufferSurface != NULL) { |
| 391 | mFramebufferSurface->dump(res); |
| 392 | } |
Erik Gilling | 1d21a9c | 2010-12-01 16:38:01 -0800 | [diff] [blame] | 393 | } |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 394 | |
| 395 | // ---------------------------------------------------------------------------- |
| 396 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 397 | void DisplayHardware::setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers) { |
| 398 | mVisibleLayersSortedByZ = layers; |
| 399 | size_t count = layers.size(); |
| 400 | for (size_t i=0 ; i<count ; i++) { |
| 401 | if (layers[i]->isSecure()) { |
| 402 | mSecureLayerVisible = true; |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | Vector< sp<LayerBase> > DisplayHardware::getVisibleLayersSortedByZ() const { |
| 408 | return mVisibleLayersSortedByZ; |
| 409 | } |
| 410 | |
| 411 | bool DisplayHardware::getSecureLayerVisible() const { |
| 412 | return mSecureLayerVisible; |
| 413 | } |
| 414 | |
| 415 | // ---------------------------------------------------------------------------- |
| 416 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 417 | status_t DisplayHardware::orientationToTransfrom( |
| 418 | int orientation, int w, int h, Transform* tr) |
| 419 | { |
| 420 | uint32_t flags = 0; |
| 421 | switch (orientation) { |
| 422 | case ISurfaceComposer::eOrientationDefault: |
| 423 | flags = Transform::ROT_0; |
| 424 | break; |
| 425 | case ISurfaceComposer::eOrientation90: |
| 426 | flags = Transform::ROT_90; |
| 427 | break; |
| 428 | case ISurfaceComposer::eOrientation180: |
| 429 | flags = Transform::ROT_180; |
| 430 | break; |
| 431 | case ISurfaceComposer::eOrientation270: |
| 432 | flags = Transform::ROT_270; |
| 433 | break; |
| 434 | default: |
| 435 | return BAD_VALUE; |
| 436 | } |
| 437 | tr->set(flags, w, h); |
| 438 | return NO_ERROR; |
| 439 | } |
| 440 | |
| 441 | status_t DisplayHardware::setOrientation(int orientation) |
| 442 | { |
| 443 | // If the rotation can be handled in hardware, this is where |
| 444 | // the magic should happen. |
| 445 | |
| 446 | const int w = mLogicalDisplayWidth; |
| 447 | const int h = mLogicalDisplayHeight; |
| 448 | mUserDisplayWidth = w; |
| 449 | mUserDisplayHeight = h; |
| 450 | |
| 451 | Transform orientationTransform; |
| 452 | DisplayHardware::orientationToTransfrom(orientation, w, h, |
| 453 | &orientationTransform); |
| 454 | if (orientation & ISurfaceComposer::eOrientationSwapMask) { |
| 455 | mUserDisplayWidth = h; |
| 456 | mUserDisplayHeight = w; |
| 457 | } |
| 458 | |
| 459 | mOrientation = orientation; |
| 460 | mGlobalTransform = mDisplayTransform * orientationTransform; |
| 461 | return NO_ERROR; |
| 462 | } |