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 | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 27 | #include <ui/DisplayInfo.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 28 | #include <ui/PixelFormat.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | |
| 30 | #include <GLES/gl.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 31 | #include <EGL/egl.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | #include <EGL/eglext.h> |
| 33 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 34 | #include <hardware/gralloc.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), |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 109 | mNativeWindow(surface), |
| 110 | mFlags(0), |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 111 | mSecureLayerVisible(false), |
| 112 | mLayerStack(0) |
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 | |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 152 | status_t DisplayHardware::getInfo(DisplayInfo* info) const { |
| 153 | info->w = getWidth(); |
| 154 | info->h = getHeight(); |
| 155 | info->xdpi = getDpiX(); |
| 156 | info->ydpi = getDpiY(); |
| 157 | info->fps = getRefreshRate(); |
| 158 | info->density = getDensity(); |
| 159 | info->orientation = getOrientation(); |
| 160 | // TODO: this needs to go away (currently needed only by webkit) |
| 161 | getPixelFormatInfo(getFormat(), &info->pixelFormatInfo); |
| 162 | return NO_ERROR; |
| 163 | } |
| 164 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 165 | void DisplayHardware::init(EGLConfig config) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 167 | ANativeWindow* const window = mNativeWindow.get(); |
| 168 | |
| 169 | int concreteType; |
| 170 | window->query(window, NATIVE_WINDOW_CONCRETE_TYPE, &concreteType); |
| 171 | if (concreteType == NATIVE_WINDOW_FRAMEBUFFER) { |
| 172 | mFramebufferSurface = static_cast<FramebufferSurface *>(mNativeWindow.get()); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Mathias Agopian | 6163091 | 2011-07-06 16:35:30 -0700 | [diff] [blame] | 175 | int format; |
Mathias Agopian | 6163091 | 2011-07-06 16:35:30 -0700 | [diff] [blame] | 176 | window->query(window, NATIVE_WINDOW_FORMAT, &format); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 177 | mDpiX = window->xdpi; |
| 178 | mDpiY = window->ydpi; |
| 179 | if (mFramebufferSurface != NULL) { |
| 180 | mRefreshRate = mFramebufferSurface->getRefreshRate(); |
| 181 | } else { |
| 182 | mRefreshRate = 60; |
Mathias Agopian | b5dd9c0 | 2012-03-22 12:15:54 -0700 | [diff] [blame] | 183 | } |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 184 | mRefreshPeriod = nsecs_t(1e9 / mRefreshRate); |
Mathias Agopian | 385977f | 2011-11-04 18:46:11 -0700 | [diff] [blame] | 185 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 186 | |
| 187 | // TODO: Not sure if display density should handled by SF any longer |
Mathias Agopian | b5dd9c0 | 2012-03-22 12:15:54 -0700 | [diff] [blame] | 188 | class Density { |
| 189 | static int getDensityFromProperty(char const* propName) { |
| 190 | char property[PROPERTY_VALUE_MAX]; |
| 191 | int density = 0; |
| 192 | if (property_get(propName, property, NULL) > 0) { |
| 193 | density = atoi(property); |
| 194 | } |
| 195 | return density; |
| 196 | } |
| 197 | public: |
| 198 | static int getEmuDensity() { |
| 199 | return getDensityFromProperty("qemu.sf.lcd_density"); } |
| 200 | static int getBuildDensity() { |
| 201 | return getDensityFromProperty("ro.sf.lcd_density"); } |
| 202 | }; |
Mathias Agopian | b5dd9c0 | 2012-03-22 12:15:54 -0700 | [diff] [blame] | 203 | // The density of the device is provided by a build property |
| 204 | mDensity = Density::getBuildDensity() / 160.0f; |
Mathias Agopian | b5dd9c0 | 2012-03-22 12:15:54 -0700 | [diff] [blame] | 205 | if (mDensity == 0) { |
| 206 | // the build doesn't provide a density -- this is wrong! |
| 207 | // use xdpi instead |
| 208 | ALOGE("ro.sf.lcd_density must be defined as a build property"); |
| 209 | mDensity = mDpiX / 160.0f; |
| 210 | } |
Mathias Agopian | b5dd9c0 | 2012-03-22 12:15:54 -0700 | [diff] [blame] | 211 | if (Density::getEmuDensity()) { |
| 212 | // if "qemu.sf.lcd_density" is specified, it overrides everything |
| 213 | mDpiX = mDpiY = mDensity = Density::getEmuDensity(); |
| 214 | mDensity /= 160.0f; |
| 215 | } |
| 216 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | /* |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 218 | * Create our display's surface |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | */ |
| 220 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 221 | EGLSurface surface; |
| 222 | EGLint w, h; |
| 223 | EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 224 | surface = eglCreateWindowSurface(display, config, window, NULL); |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 225 | eglQuerySurface(display, surface, EGL_WIDTH, &mDisplayWidth); |
| 226 | eglQuerySurface(display, surface, EGL_HEIGHT, &mDisplayHeight); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 228 | if (mFramebufferSurface != NULL) { |
| 229 | if (mFramebufferSurface->isUpdateOnDemand()) { |
| 230 | mFlags |= PARTIAL_UPDATES; |
| 231 | // if we have partial updates, we definitely don't need to |
| 232 | // preserve the backbuffer, which may be costly. |
| 233 | eglSurfaceAttrib(display, surface, |
| 234 | EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED); |
| 235 | } |
Mathias Agopian | 0928bee | 2009-09-16 20:15:42 -0700 | [diff] [blame] | 236 | } |
| 237 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | mDisplay = display; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | mSurface = surface; |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 240 | mFormat = format; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 241 | mPageFlipCount = 0; |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 242 | |
Mathias Agopian | 98a121a | 2012-07-24 21:08:59 -0700 | [diff] [blame] | 243 | // initialize the display orientation transform. |
| 244 | DisplayHardware::setOrientation(ISurfaceComposer::eOrientationDefault); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 245 | } |
| 246 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | uint32_t DisplayHardware::getPageFlipCount() const { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 248 | return mPageFlipCount; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | } |
| 250 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 251 | nsecs_t DisplayHardware::getRefreshTimestamp() const { |
| 252 | // this returns the last refresh timestamp. |
| 253 | // if the last one is not available, we estimate it based on |
| 254 | // the refresh period and whatever closest timestamp we have. |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 255 | Mutex::Autolock _l(mLock); |
| 256 | nsecs_t now = systemTime(CLOCK_MONOTONIC); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 257 | return now - ((now - mLastHwVSync) % mRefreshPeriod); |
| 258 | } |
| 259 | |
| 260 | nsecs_t DisplayHardware::getRefreshPeriod() const { |
| 261 | return mRefreshPeriod; |
| 262 | } |
| 263 | |
Mathias Agopian | 74faca2 | 2009-09-17 16:18:16 -0700 | [diff] [blame] | 264 | status_t DisplayHardware::compositionComplete() const { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 265 | if (mFramebufferSurface == NULL) { |
| 266 | return NO_ERROR; |
| 267 | } |
| 268 | return mFramebufferSurface->compositionComplete(); |
Mathias Agopian | 74faca2 | 2009-09-17 16:18:16 -0700 | [diff] [blame] | 269 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 271 | void DisplayHardware::onVSyncReceived(nsecs_t timestamp) { |
| 272 | Mutex::Autolock _l(mLock); |
| 273 | mLastHwVSync = timestamp; |
| 274 | } |
| 275 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | void DisplayHardware::flip(const Region& dirty) const |
| 277 | { |
| 278 | checkGLErrors(); |
| 279 | |
| 280 | EGLDisplay dpy = mDisplay; |
| 281 | EGLSurface surface = mSurface; |
| 282 | |
Mathias Agopian | 5e78e09 | 2009-06-11 17:19:54 -0700 | [diff] [blame] | 283 | #ifdef EGL_ANDROID_swap_rectangle |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 284 | if (mFlags & SWAP_RECTANGLE) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 285 | const Region newDirty(dirty.intersect(bounds())); |
| 286 | const Rect b(newDirty.getBounds()); |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 287 | eglSetSwapRectangleANDROID(dpy, surface, |
| 288 | b.left, b.top, b.width(), b.height()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | } |
Mathias Agopian | 5e78e09 | 2009-06-11 17:19:54 -0700 | [diff] [blame] | 290 | #endif |
| 291 | |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 292 | if (mFlags & PARTIAL_UPDATES) { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 293 | if (mFramebufferSurface != NULL) { |
| 294 | mFramebufferSurface->setUpdateRectangle(dirty.getBounds()); |
| 295 | } |
Mathias Agopian | 1e16b13 | 2009-05-07 17:40:23 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 298 | mPageFlipCount++; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | uint32_t DisplayHardware::getFlags() const |
| 302 | { |
| 303 | return mFlags; |
| 304 | } |
| 305 | |
Erik Gilling | 1d21a9c | 2010-12-01 16:38:01 -0800 | [diff] [blame] | 306 | void DisplayHardware::dump(String8& res) const |
| 307 | { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 308 | if (mFramebufferSurface != NULL) { |
| 309 | mFramebufferSurface->dump(res); |
| 310 | } |
Erik Gilling | 1d21a9c | 2010-12-01 16:38:01 -0800 | [diff] [blame] | 311 | } |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 312 | |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame^] | 313 | void DisplayHardware::makeCurrent(const DisplayHardware& hw, EGLContext ctx) { |
| 314 | EGLSurface sur = eglGetCurrentSurface(EGL_DRAW); |
| 315 | if (sur != hw.mSurface) { |
| 316 | EGLDisplay dpy = eglGetCurrentDisplay(); |
| 317 | eglMakeCurrent(dpy, hw.mSurface, hw.mSurface, ctx); |
| 318 | } |
| 319 | } |
| 320 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 321 | // ---------------------------------------------------------------------------- |
| 322 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 323 | void DisplayHardware::setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers) { |
| 324 | mVisibleLayersSortedByZ = layers; |
| 325 | size_t count = layers.size(); |
| 326 | for (size_t i=0 ; i<count ; i++) { |
| 327 | if (layers[i]->isSecure()) { |
| 328 | mSecureLayerVisible = true; |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | Vector< sp<LayerBase> > DisplayHardware::getVisibleLayersSortedByZ() const { |
| 334 | return mVisibleLayersSortedByZ; |
| 335 | } |
| 336 | |
| 337 | bool DisplayHardware::getSecureLayerVisible() const { |
| 338 | return mSecureLayerVisible; |
| 339 | } |
| 340 | |
| 341 | // ---------------------------------------------------------------------------- |
| 342 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 343 | status_t DisplayHardware::orientationToTransfrom( |
| 344 | int orientation, int w, int h, Transform* tr) |
| 345 | { |
| 346 | uint32_t flags = 0; |
| 347 | switch (orientation) { |
| 348 | case ISurfaceComposer::eOrientationDefault: |
| 349 | flags = Transform::ROT_0; |
| 350 | break; |
| 351 | case ISurfaceComposer::eOrientation90: |
| 352 | flags = Transform::ROT_90; |
| 353 | break; |
| 354 | case ISurfaceComposer::eOrientation180: |
| 355 | flags = Transform::ROT_180; |
| 356 | break; |
| 357 | case ISurfaceComposer::eOrientation270: |
| 358 | flags = Transform::ROT_270; |
| 359 | break; |
| 360 | default: |
| 361 | return BAD_VALUE; |
| 362 | } |
| 363 | tr->set(flags, w, h); |
| 364 | return NO_ERROR; |
| 365 | } |
| 366 | |
Mathias Agopian | 98a121a | 2012-07-24 21:08:59 -0700 | [diff] [blame] | 367 | status_t DisplayHardware::setOrientation(int orientation) { |
| 368 | int w = mDisplayWidth; |
| 369 | int h = mDisplayHeight; |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 370 | |
Mathias Agopian | 98a121a | 2012-07-24 21:08:59 -0700 | [diff] [blame] | 371 | DisplayHardware::orientationToTransfrom( |
| 372 | orientation, w, h, &mGlobalTransform); |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 373 | if (orientation & ISurfaceComposer::eOrientationSwapMask) { |
Mathias Agopian | 98a121a | 2012-07-24 21:08:59 -0700 | [diff] [blame] | 374 | int tmp = w; |
| 375 | w = h; |
| 376 | h = tmp; |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 377 | } |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 378 | mOrientation = orientation; |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 379 | return NO_ERROR; |
| 380 | } |