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 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 30 | #include <gui/Surface.h> |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 31 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 32 | #include <hardware/gralloc.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 34 | #include "DisplayHardware/DisplaySurface.h" |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 35 | #include "DisplayHardware/HWComposer.h" |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 36 | #include "RenderEngine/RenderEngine.h" |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 37 | |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 38 | #include "clz.h" |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 39 | #include "DisplayDevice.h" |
Mathias Agopian | c7d14e2 | 2011-08-01 16:32:21 -0700 | [diff] [blame] | 40 | #include "SurfaceFlinger.h" |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 41 | #include "Layer.h" |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 42 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 43 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | using namespace android; |
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 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | /* |
| 48 | * Initialize the display to the specified values. |
| 49 | * |
| 50 | */ |
| 51 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 52 | DisplayDevice::DisplayDevice( |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | const sp<SurfaceFlinger>& flinger, |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 54 | DisplayType type, |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 55 | int32_t hwcId, |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 56 | bool isSecure, |
| 57 | const wp<IBinder>& displayToken, |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 58 | const sp<DisplaySurface>& displaySurface, |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 59 | EGLConfig config) |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 60 | : mFlinger(flinger), |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 61 | mType(type), mHwcDisplayId(hwcId), |
Chih-Wei Huang | 27e2562 | 2013-01-07 17:33:56 +0800 | [diff] [blame] | 62 | mDisplayToken(displayToken), |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 63 | mDisplaySurface(displaySurface), |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 64 | mDisplay(EGL_NO_DISPLAY), |
| 65 | mSurface(EGL_NO_SURFACE), |
| 66 | mContext(EGL_NO_CONTEXT), |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 67 | mDisplayWidth(), mDisplayHeight(), mFormat(), |
| 68 | mFlags(), |
| 69 | mPageFlipCount(), |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 70 | mIsSecure(isSecure), |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 71 | mSecureLayerVisible(false), |
| 72 | mScreenAcquired(false), |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 73 | mLayerStack(NO_LAYER_STACK), |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 74 | mOrientation() |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | { |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 76 | mNativeWindow = new Surface(mDisplaySurface->getIGraphicBufferProducer()); |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 77 | ANativeWindow* const window = mNativeWindow.get(); |
| 78 | |
| 79 | int format; |
| 80 | window->query(window, NATIVE_WINDOW_FORMAT, &format); |
| 81 | |
| 82 | /* |
| 83 | * Create our display's surface |
| 84 | */ |
| 85 | |
| 86 | EGLSurface surface; |
| 87 | EGLint w, h; |
| 88 | EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 89 | surface = eglCreateWindowSurface(display, config, window, NULL); |
| 90 | eglQuerySurface(display, surface, EGL_WIDTH, &mDisplayWidth); |
| 91 | eglQuerySurface(display, surface, EGL_HEIGHT, &mDisplayHeight); |
| 92 | |
| 93 | mDisplay = display; |
| 94 | mSurface = surface; |
| 95 | mFormat = format; |
| 96 | mPageFlipCount = 0; |
| 97 | mViewport.makeInvalid(); |
| 98 | mFrame.makeInvalid(); |
| 99 | |
| 100 | // virtual displays are always considered enabled |
| 101 | mScreenAcquired = (mType >= DisplayDevice::DISPLAY_VIRTUAL); |
| 102 | |
| 103 | // Name the display. The name will be replaced shortly if the display |
| 104 | // was created with createDisplay(). |
| 105 | switch (mType) { |
| 106 | case DISPLAY_PRIMARY: |
| 107 | mDisplayName = "Built-in Screen"; |
| 108 | break; |
| 109 | case DISPLAY_EXTERNAL: |
| 110 | mDisplayName = "HDMI Screen"; |
| 111 | break; |
| 112 | default: |
| 113 | mDisplayName = "Virtual Screen"; // e.g. Overlay #n |
| 114 | break; |
| 115 | } |
| 116 | |
| 117 | // initialize the display orientation transform. |
| 118 | setProjection(DisplayState::eOrientationDefault, mViewport, mFrame); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | } |
| 120 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 121 | DisplayDevice::~DisplayDevice() { |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 122 | if (mSurface != EGL_NO_SURFACE) { |
| 123 | eglDestroySurface(mDisplay, mSurface); |
| 124 | mSurface = EGL_NO_SURFACE; |
| 125 | } |
| 126 | } |
| 127 | |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 128 | void DisplayDevice::disconnect(HWComposer& hwc) { |
| 129 | if (mHwcDisplayId >= 0) { |
| 130 | hwc.disconnectDisplay(mHwcDisplayId); |
| 131 | if (mHwcDisplayId >= DISPLAY_VIRTUAL) |
| 132 | hwc.freeDisplayId(mHwcDisplayId); |
| 133 | mHwcDisplayId = -1; |
| 134 | } |
| 135 | } |
| 136 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 137 | bool DisplayDevice::isValid() const { |
| 138 | return mFlinger != NULL; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 141 | int DisplayDevice::getWidth() const { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 142 | return mDisplayWidth; |
| 143 | } |
| 144 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 145 | int DisplayDevice::getHeight() const { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 146 | return mDisplayHeight; |
| 147 | } |
| 148 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 149 | PixelFormat DisplayDevice::getFormat() const { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 150 | return mFormat; |
| 151 | } |
| 152 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 153 | EGLSurface DisplayDevice::getEGLSurface() const { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 154 | return mSurface; |
| 155 | } |
| 156 | |
Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 157 | void DisplayDevice::setDisplayName(const String8& displayName) { |
| 158 | if (!displayName.isEmpty()) { |
| 159 | // never override the name with an empty name |
| 160 | mDisplayName = displayName; |
| 161 | } |
| 162 | } |
| 163 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 164 | uint32_t DisplayDevice::getPageFlipCount() const { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 165 | return mPageFlipCount; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 168 | status_t DisplayDevice::compositionComplete() const { |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 169 | return mDisplaySurface->compositionComplete(); |
Mathias Agopian | 74faca2 | 2009-09-17 16:18:16 -0700 | [diff] [blame] | 170 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 172 | void DisplayDevice::flip(const Region& dirty) const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | { |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 174 | mFlinger->getRenderEngine().checkErrors(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | |
| 176 | EGLDisplay dpy = mDisplay; |
| 177 | EGLSurface surface = mSurface; |
| 178 | |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 179 | #ifdef EGL_ANDROID_swap_rectangle |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 180 | if (mFlags & SWAP_RECTANGLE) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 181 | const Region newDirty(dirty.intersect(bounds())); |
| 182 | const Rect b(newDirty.getBounds()); |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 183 | eglSetSwapRectangleANDROID(dpy, surface, |
| 184 | b.left, b.top, b.width(), b.height()); |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 185 | } |
Mathias Agopian | 5e78e09 | 2009-06-11 17:19:54 -0700 | [diff] [blame] | 186 | #endif |
Mathias Agopian | d870703 | 2012-09-18 01:21:55 -0700 | [diff] [blame] | 187 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 188 | mPageFlipCount++; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 191 | void DisplayDevice::swapBuffers(HWComposer& hwc) const { |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 192 | // We need to call eglSwapBuffers() unless: |
| 193 | // (a) there was no GLES composition this frame, or |
| 194 | // (b) we're using a legacy HWC with no framebuffer target support (in |
| 195 | // which case HWComposer::commit() handles things). |
| 196 | if (hwc.initCheck() != NO_ERROR || |
| 197 | (hwc.hasGlesComposition(mHwcDisplayId) && |
| 198 | hwc.supportsFramebufferTarget())) { |
| 199 | EGLBoolean success = eglSwapBuffers(mDisplay, mSurface); |
| 200 | if (!success) { |
| 201 | EGLint error = eglGetError(); |
| 202 | if (error == EGL_CONTEXT_LOST || |
| 203 | mType == DisplayDevice::DISPLAY_PRIMARY) { |
| 204 | LOG_ALWAYS_FATAL("eglSwapBuffers(%p, %p) failed with 0x%08x", |
| 205 | mDisplay, mSurface, error); |
| 206 | } else { |
| 207 | ALOGE("eglSwapBuffers(%p, %p) failed with 0x%08x", |
| 208 | mDisplay, mSurface, error); |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | } |
Mathias Agopian | 52e2148 | 2012-09-24 18:07:21 -0700 | [diff] [blame] | 212 | |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 213 | status_t result = mDisplaySurface->advanceFrame(); |
| 214 | if (result != NO_ERROR) { |
| 215 | ALOGE("[%s] failed pushing new frame to HWC: %d", |
| 216 | mDisplayName.string(), result); |
Mathias Agopian | 3234138 | 2012-09-25 19:16:28 -0700 | [diff] [blame] | 217 | } |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | void DisplayDevice::onSwapBuffersCompleted(HWComposer& hwc) const { |
| 221 | if (hwc.initCheck() == NO_ERROR) { |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 222 | mDisplaySurface->onFrameCommitted(); |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 226 | uint32_t DisplayDevice::getFlags() const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | { |
| 228 | return mFlags; |
| 229 | } |
| 230 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 231 | EGLBoolean DisplayDevice::makeCurrent(EGLDisplay dpy, EGLContext ctx) const { |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 232 | EGLBoolean result = EGL_TRUE; |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 233 | EGLSurface sur = eglGetCurrentSurface(EGL_DRAW); |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 234 | if (sur != mSurface) { |
| 235 | result = eglMakeCurrent(dpy, mSurface, mSurface, ctx); |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 236 | if (result == EGL_TRUE) { |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 237 | setViewportAndProjection(); |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 238 | } |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 239 | } |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 240 | return result; |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 243 | void DisplayDevice::setViewportAndProjection() const { |
| 244 | size_t w = mDisplayWidth; |
| 245 | size_t h = mDisplayHeight; |
| 246 | mFlinger->getRenderEngine().setViewportAndProjection(w, h); |
Mathias Agopian | bae92d0 | 2012-09-28 01:00:47 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 249 | // ---------------------------------------------------------------------------- |
| 250 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 251 | void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers) { |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 252 | mVisibleLayersSortedByZ = layers; |
Mathias Agopian | ef7b9c7 | 2012-08-10 15:22:19 -0700 | [diff] [blame] | 253 | mSecureLayerVisible = false; |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 254 | size_t count = layers.size(); |
| 255 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 256 | const sp<Layer>& layer(layers[i]); |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 257 | if (layer->isSecure()) { |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 258 | mSecureLayerVisible = true; |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 263 | const Vector< sp<Layer> >& DisplayDevice::getVisibleLayersSortedByZ() const { |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 264 | return mVisibleLayersSortedByZ; |
| 265 | } |
| 266 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 267 | bool DisplayDevice::getSecureLayerVisible() const { |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 268 | return mSecureLayerVisible; |
| 269 | } |
| 270 | |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 271 | Region DisplayDevice::getDirtyRegion(bool repaintEverything) const { |
| 272 | Region dirty; |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 273 | if (repaintEverything) { |
| 274 | dirty.set(getBounds()); |
| 275 | } else { |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 276 | const Transform& planeTransform(mGlobalTransform); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 277 | dirty = planeTransform.transform(this->dirtyRegion); |
| 278 | dirty.andSelf(getBounds()); |
| 279 | } |
| 280 | return dirty; |
| 281 | } |
| 282 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 283 | // ---------------------------------------------------------------------------- |
| 284 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 285 | bool DisplayDevice::canDraw() const { |
| 286 | return mScreenAcquired; |
| 287 | } |
| 288 | |
| 289 | void DisplayDevice::releaseScreen() const { |
| 290 | mScreenAcquired = false; |
| 291 | } |
| 292 | |
| 293 | void DisplayDevice::acquireScreen() const { |
| 294 | mScreenAcquired = true; |
| 295 | } |
| 296 | |
| 297 | bool DisplayDevice::isScreenAcquired() const { |
| 298 | return mScreenAcquired; |
| 299 | } |
| 300 | |
| 301 | // ---------------------------------------------------------------------------- |
| 302 | |
Mathias Agopian | 28947d7 | 2012-08-08 18:51:15 -0700 | [diff] [blame] | 303 | void DisplayDevice::setLayerStack(uint32_t stack) { |
| 304 | mLayerStack = stack; |
| 305 | dirtyRegion.set(bounds()); |
| 306 | } |
| 307 | |
| 308 | // ---------------------------------------------------------------------------- |
| 309 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 310 | status_t DisplayDevice::orientationToTransfrom( |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 311 | int orientation, int w, int h, Transform* tr) |
| 312 | { |
| 313 | uint32_t flags = 0; |
| 314 | switch (orientation) { |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 315 | case DisplayState::eOrientationDefault: |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 316 | flags = Transform::ROT_0; |
| 317 | break; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 318 | case DisplayState::eOrientation90: |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 319 | flags = Transform::ROT_90; |
| 320 | break; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 321 | case DisplayState::eOrientation180: |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 322 | flags = Transform::ROT_180; |
| 323 | break; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 324 | case DisplayState::eOrientation270: |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 325 | flags = Transform::ROT_270; |
| 326 | break; |
| 327 | default: |
| 328 | return BAD_VALUE; |
| 329 | } |
| 330 | tr->set(flags, w, h); |
| 331 | return NO_ERROR; |
| 332 | } |
| 333 | |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 334 | void DisplayDevice::setProjection(int orientation, |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 335 | const Rect& newViewport, const Rect& newFrame) { |
| 336 | Rect viewport(newViewport); |
| 337 | Rect frame(newFrame); |
| 338 | |
| 339 | const int w = mDisplayWidth; |
| 340 | const int h = mDisplayHeight; |
| 341 | |
| 342 | Transform R; |
| 343 | DisplayDevice::orientationToTransfrom(orientation, w, h, &R); |
| 344 | |
| 345 | if (!frame.isValid()) { |
| 346 | // the destination frame can be invalid if it has never been set, |
| 347 | // in that case we assume the whole display frame. |
| 348 | frame = Rect(w, h); |
| 349 | } |
| 350 | |
| 351 | if (viewport.isEmpty()) { |
| 352 | // viewport can be invalid if it has never been set, in that case |
| 353 | // we assume the whole display size. |
| 354 | // it's also invalid to have an empty viewport, so we handle that |
| 355 | // case in the same way. |
| 356 | viewport = Rect(w, h); |
| 357 | if (R.getOrientation() & Transform::ROT_90) { |
| 358 | // viewport is always specified in the logical orientation |
| 359 | // of the display (ie: post-rotation). |
| 360 | swap(viewport.right, viewport.bottom); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | dirtyRegion.set(getBounds()); |
| 365 | |
| 366 | Transform TL, TP, S; |
| 367 | float src_width = viewport.width(); |
| 368 | float src_height = viewport.height(); |
| 369 | float dst_width = frame.width(); |
| 370 | float dst_height = frame.height(); |
| 371 | if (src_width != dst_width || src_height != dst_height) { |
| 372 | float sx = dst_width / src_width; |
| 373 | float sy = dst_height / src_height; |
| 374 | S.set(sx, 0, 0, sy); |
| 375 | } |
| 376 | |
| 377 | float src_x = viewport.left; |
| 378 | float src_y = viewport.top; |
| 379 | float dst_x = frame.left; |
| 380 | float dst_y = frame.top; |
| 381 | TL.set(-src_x, -src_y); |
| 382 | TP.set(dst_x, dst_y); |
| 383 | |
| 384 | // The viewport and frame are both in the logical orientation. |
| 385 | // Apply the logical translation, scale to physical size, apply the |
| 386 | // physical translation and finally rotate to the physical orientation. |
| 387 | mGlobalTransform = R * TP * S * TL; |
| 388 | |
| 389 | const uint8_t type = mGlobalTransform.getType(); |
| 390 | mNeedsFiltering = (!mGlobalTransform.preserveRects() || |
| 391 | (type >= Transform::SCALE)); |
| 392 | |
| 393 | mScissor = mGlobalTransform.transform(viewport); |
| 394 | if (mScissor.isEmpty()) { |
Mathias Agopian | 6c7f25a | 2013-05-09 20:37:10 -0700 | [diff] [blame] | 395 | mScissor = getBounds(); |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 396 | } |
| 397 | |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 398 | mOrientation = orientation; |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 399 | mViewport = viewport; |
| 400 | mFrame = frame; |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 401 | } |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 402 | |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 403 | void DisplayDevice::dump(String8& result) const { |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 404 | const Transform& tr(mGlobalTransform); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 405 | result.appendFormat( |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 406 | "+ DisplayDevice: %s\n" |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 407 | " type=%x, hwcId=%d, layerStack=%u, (%4dx%4d), ANativeWindow=%p, orient=%2d (type=%08x), " |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 408 | "flips=%u, isSecure=%d, secureVis=%d, acquired=%d, numLayers=%u\n" |
Mathias Agopian | 766dc49 | 2012-10-30 18:08:06 -0700 | [diff] [blame] | 409 | " v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d]," |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 410 | "transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n", |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 411 | mDisplayName.string(), mType, mHwcDisplayId, |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 412 | mLayerStack, mDisplayWidth, mDisplayHeight, mNativeWindow.get(), |
| 413 | mOrientation, tr.getType(), getPageFlipCount(), |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 414 | mIsSecure, mSecureLayerVisible, mScreenAcquired, mVisibleLayersSortedByZ.size(), |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 415 | mViewport.left, mViewport.top, mViewport.right, mViewport.bottom, |
| 416 | mFrame.left, mFrame.top, mFrame.right, mFrame.bottom, |
Mathias Agopian | 766dc49 | 2012-10-30 18:08:06 -0700 | [diff] [blame] | 417 | mScissor.left, mScissor.top, mScissor.right, mScissor.bottom, |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 418 | tr[0][0], tr[1][0], tr[2][0], |
| 419 | tr[0][1], tr[1][1], tr[2][1], |
| 420 | tr[0][2], tr[1][2], tr[2][2]); |
| 421 | |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 422 | String8 surfaceDump; |
| 423 | mDisplaySurface->dump(surfaceDump); |
| 424 | result.append(surfaceDump); |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 425 | } |