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 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 17 | // #define LOG_NDEBUG 0 |
| 18 | #undef LOG_TAG |
| 19 | #define LOG_TAG "DisplayDevice" |
| 20 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include <stdlib.h> |
| 22 | #include <stdio.h> |
| 23 | #include <string.h> |
| 24 | #include <math.h> |
| 25 | |
| 26 | #include <cutils/properties.h> |
| 27 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 28 | #include <utils/RefBase.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | #include <utils/Log.h> |
| 30 | |
Courtney Goeltzenleuchter | 152279d | 2017-08-14 18:18:30 -0600 | [diff] [blame] | 31 | #include <ui/DebugUtils.h> |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 32 | #include <ui/DisplayInfo.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 33 | #include <ui/PixelFormat.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 35 | #include <gui/Surface.h> |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 36 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 37 | #include <hardware/gralloc.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 39 | #include "DisplayHardware/DisplaySurface.h" |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 40 | #include "DisplayHardware/HWComposer.h" |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 41 | #ifdef USE_HWC2 |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 42 | #include "DisplayHardware/HWC2.h" |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 43 | #endif |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 44 | #include "RenderEngine/RenderEngine.h" |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 45 | |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 46 | #include "clz.h" |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 47 | #include "DisplayDevice.h" |
Mathias Agopian | c7d14e2 | 2011-08-01 16:32:21 -0700 | [diff] [blame] | 48 | #include "SurfaceFlinger.h" |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 49 | #include "Layer.h" |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 50 | |
Jaesoo Lee | 720a724 | 2017-01-31 15:26:18 +0900 | [diff] [blame] | 51 | #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> |
| 52 | #include <configstore/Utils.h> |
| 53 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 54 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | using namespace android; |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 56 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | |
Andreas Gampe | 89fd4f7 | 2014-11-13 14:18:56 -0800 | [diff] [blame] | 58 | #ifdef EGL_ANDROID_swap_rectangle |
| 59 | static constexpr bool kEGLAndroidSwapRectangle = true; |
| 60 | #else |
| 61 | static constexpr bool kEGLAndroidSwapRectangle = false; |
| 62 | #endif |
| 63 | |
Jaesoo Lee | 720a724 | 2017-01-31 15:26:18 +0900 | [diff] [blame] | 64 | // retrieve triple buffer setting from configstore |
| 65 | using namespace android::hardware::configstore; |
| 66 | using namespace android::hardware::configstore::V1_0; |
| 67 | |
Fabien Sanglard | 1971b63 | 2017-03-10 14:50:03 -0800 | [diff] [blame] | 68 | static bool useTripleFramebuffer = getInt64< ISurfaceFlingerConfigs, |
Fabien Sanglard | 48eb565 | 2017-07-26 14:55:11 -0700 | [diff] [blame] | 69 | &ISurfaceFlingerConfigs::maxFrameBufferAcquiredBuffers>(2) >= 3; |
Jaesoo Lee | 720a724 | 2017-01-31 15:26:18 +0900 | [diff] [blame] | 70 | |
Andreas Gampe | 89fd4f7 | 2014-11-13 14:18:56 -0800 | [diff] [blame] | 71 | #if !defined(EGL_EGLEXT_PROTOTYPES) || !defined(EGL_ANDROID_swap_rectangle) |
| 72 | // Dummy implementation in case it is missing. |
| 73 | inline void eglSetSwapRectangleANDROID (EGLDisplay, EGLSurface, EGLint, EGLint, EGLint, EGLint) { |
| 74 | } |
| 75 | #endif |
| 76 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | /* |
| 78 | * Initialize the display to the specified values. |
| 79 | * |
| 80 | */ |
| 81 | |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 82 | uint32_t DisplayDevice::sPrimaryDisplayOrientation = 0; |
| 83 | |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 84 | // clang-format off |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 85 | DisplayDevice::DisplayDevice( |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | const sp<SurfaceFlinger>& flinger, |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 87 | DisplayType type, |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 88 | int32_t hwcId, |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 89 | #ifndef USE_HWC2 |
| 90 | int format, |
| 91 | #endif |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 92 | bool isSecure, |
| 93 | const wp<IBinder>& displayToken, |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 94 | const sp<DisplaySurface>& displaySurface, |
Mathias Agopian | db89edc | 2013-08-02 01:40:18 -0700 | [diff] [blame] | 95 | const sp<IGraphicBufferProducer>& producer, |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 96 | EGLConfig config, |
| 97 | bool supportWideColor) |
Jesse Hall | b7a0549 | 2014-08-14 15:45:06 -0700 | [diff] [blame] | 98 | : lastCompositionHadVisibleLayers(false), |
| 99 | mFlinger(flinger), |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 100 | mType(type), |
| 101 | mHwcDisplayId(hwcId), |
Chih-Wei Huang | 27e2562 | 2013-01-07 17:33:56 +0800 | [diff] [blame] | 102 | mDisplayToken(displayToken), |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 103 | mDisplaySurface(displaySurface), |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 104 | mDisplay(EGL_NO_DISPLAY), |
| 105 | mSurface(EGL_NO_SURFACE), |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 106 | mDisplayWidth(), |
| 107 | mDisplayHeight(), |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 108 | #ifndef USE_HWC2 |
| 109 | mFormat(), |
| 110 | #endif |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 111 | mFlags(), |
| 112 | mPageFlipCount(), |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 113 | mIsSecure(isSecure), |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 114 | mLayerStack(NO_LAYER_STACK), |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 115 | mOrientation(), |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 116 | mPowerMode(HWC_POWER_MODE_OFF), |
Courtney Goeltzenleuchter | 4f20f9c | 2017-04-06 08:18:34 -0600 | [diff] [blame] | 117 | mActiveConfig(0) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | { |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 119 | // clang-format on |
james.zhang | 5e8eb5e | 2015-12-01 17:55:11 +0800 | [diff] [blame] | 120 | Surface* surface; |
| 121 | mNativeWindow = surface = new Surface(producer, false); |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 122 | ANativeWindow* const window = mNativeWindow.get(); |
| 123 | |
Courtney Goeltzenleuchter | 62caf7c | 2017-03-14 14:18:28 -0600 | [diff] [blame] | 124 | #ifdef USE_HWC2 |
Naseer Ahmed | 901a86e | 2017-05-11 11:15:21 -0400 | [diff] [blame] | 125 | mActiveColorMode = HAL_COLOR_MODE_NATIVE; |
Courtney Goeltzenleuchter | 4f20f9c | 2017-04-06 08:18:34 -0600 | [diff] [blame] | 126 | mDisplayHasWideColor = supportWideColor; |
| 127 | #else |
| 128 | (void) supportWideColor; |
Courtney Goeltzenleuchter | 62caf7c | 2017-03-14 14:18:28 -0600 | [diff] [blame] | 129 | #endif |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 130 | /* |
| 131 | * Create our display's surface |
| 132 | */ |
| 133 | |
james.zhang | 5e8eb5e | 2015-12-01 17:55:11 +0800 | [diff] [blame] | 134 | EGLSurface eglSurface; |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 135 | EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
Jesse Hall | 19e8729 | 2013-12-23 21:02:15 -0800 | [diff] [blame] | 136 | if (config == EGL_NO_CONFIG) { |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 137 | #ifdef USE_HWC2 |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 138 | config = RenderEngine::chooseEglConfig(display, PIXEL_FORMAT_RGBA_8888, |
| 139 | /*logConfig*/ false); |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 140 | #else |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 141 | config = RenderEngine::chooseEglConfig(display, format, |
| 142 | /*logConfig*/ false); |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 143 | #endif |
Jesse Hall | 19e8729 | 2013-12-23 21:02:15 -0800 | [diff] [blame] | 144 | } |
james.zhang | 5e8eb5e | 2015-12-01 17:55:11 +0800 | [diff] [blame] | 145 | eglSurface = eglCreateWindowSurface(display, config, window, NULL); |
| 146 | eglQuerySurface(display, eglSurface, EGL_WIDTH, &mDisplayWidth); |
| 147 | eglQuerySurface(display, eglSurface, EGL_HEIGHT, &mDisplayHeight); |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 148 | |
John Dong | 4ee5696 | 2014-02-21 12:37:59 -0800 | [diff] [blame] | 149 | // Make sure that composition can never be stalled by a virtual display |
| 150 | // consumer that isn't processing buffers fast enough. We have to do this |
| 151 | // in two places: |
| 152 | // * Here, in case the display is composed entirely by HWC. |
| 153 | // * In makeCurrent(), using eglSwapInterval. Some EGL drivers set the |
| 154 | // window's swap interval in eglMakeCurrent, so they'll override the |
| 155 | // interval we set here. |
| 156 | if (mType >= DisplayDevice::DISPLAY_VIRTUAL) |
| 157 | window->setSwapInterval(window, 0); |
| 158 | |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 159 | mConfig = config; |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 160 | mDisplay = display; |
james.zhang | 5e8eb5e | 2015-12-01 17:55:11 +0800 | [diff] [blame] | 161 | mSurface = eglSurface; |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 162 | #ifndef USE_HWC2 |
| 163 | mFormat = format; |
| 164 | #endif |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 165 | mPageFlipCount = 0; |
| 166 | mViewport.makeInvalid(); |
| 167 | mFrame.makeInvalid(); |
| 168 | |
| 169 | // virtual displays are always considered enabled |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 170 | mPowerMode = (mType >= DisplayDevice::DISPLAY_VIRTUAL) ? |
| 171 | HWC_POWER_MODE_NORMAL : HWC_POWER_MODE_OFF; |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 172 | |
| 173 | // Name the display. The name will be replaced shortly if the display |
| 174 | // was created with createDisplay(). |
| 175 | switch (mType) { |
| 176 | case DISPLAY_PRIMARY: |
| 177 | mDisplayName = "Built-in Screen"; |
| 178 | break; |
| 179 | case DISPLAY_EXTERNAL: |
| 180 | mDisplayName = "HDMI Screen"; |
| 181 | break; |
| 182 | default: |
| 183 | mDisplayName = "Virtual Screen"; // e.g. Overlay #n |
| 184 | break; |
| 185 | } |
| 186 | |
| 187 | // initialize the display orientation transform. |
| 188 | setProjection(DisplayState::eOrientationDefault, mViewport, mFrame); |
james.zhang | 5e8eb5e | 2015-12-01 17:55:11 +0800 | [diff] [blame] | 189 | |
Jaesoo Lee | 720a724 | 2017-01-31 15:26:18 +0900 | [diff] [blame] | 190 | if (useTripleFramebuffer) { |
| 191 | surface->allocateBuffers(); |
| 192 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | } |
| 194 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 195 | DisplayDevice::~DisplayDevice() { |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 196 | if (mSurface != EGL_NO_SURFACE) { |
| 197 | eglDestroySurface(mDisplay, mSurface); |
| 198 | mSurface = EGL_NO_SURFACE; |
| 199 | } |
| 200 | } |
| 201 | |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 202 | void DisplayDevice::disconnect(HWComposer& hwc) { |
| 203 | if (mHwcDisplayId >= 0) { |
| 204 | hwc.disconnectDisplay(mHwcDisplayId); |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 205 | #ifndef USE_HWC2 |
| 206 | if (mHwcDisplayId >= DISPLAY_VIRTUAL) |
| 207 | hwc.freeDisplayId(mHwcDisplayId); |
| 208 | #endif |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 209 | mHwcDisplayId = -1; |
| 210 | } |
| 211 | } |
| 212 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 213 | bool DisplayDevice::isValid() const { |
| 214 | return mFlinger != NULL; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | } |
| 216 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 217 | int DisplayDevice::getWidth() const { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 218 | return mDisplayWidth; |
| 219 | } |
| 220 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 221 | int DisplayDevice::getHeight() const { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 222 | return mDisplayHeight; |
| 223 | } |
| 224 | |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 225 | #ifndef USE_HWC2 |
| 226 | PixelFormat DisplayDevice::getFormat() const { |
| 227 | return mFormat; |
| 228 | } |
| 229 | #endif |
| 230 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 231 | EGLSurface DisplayDevice::getEGLSurface() const { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 232 | return mSurface; |
| 233 | } |
| 234 | |
Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 235 | void DisplayDevice::setDisplayName(const String8& displayName) { |
| 236 | if (!displayName.isEmpty()) { |
| 237 | // never override the name with an empty name |
| 238 | mDisplayName = displayName; |
| 239 | } |
| 240 | } |
| 241 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 242 | uint32_t DisplayDevice::getPageFlipCount() const { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 243 | return mPageFlipCount; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 246 | #ifndef USE_HWC2 |
| 247 | status_t DisplayDevice::compositionComplete() const { |
| 248 | return mDisplaySurface->compositionComplete(); |
| 249 | } |
| 250 | #endif |
| 251 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 252 | void DisplayDevice::flip(const Region& dirty) const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | { |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 254 | mFlinger->getRenderEngine().checkErrors(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | |
Andreas Gampe | 89fd4f7 | 2014-11-13 14:18:56 -0800 | [diff] [blame] | 256 | if (kEGLAndroidSwapRectangle) { |
| 257 | if (mFlags & SWAP_RECTANGLE) { |
| 258 | const Region newDirty(dirty.intersect(bounds())); |
| 259 | const Rect b(newDirty.getBounds()); |
| 260 | eglSetSwapRectangleANDROID(mDisplay, mSurface, |
| 261 | b.left, b.top, b.width(), b.height()); |
| 262 | } |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 263 | } |
Mathias Agopian | d870703 | 2012-09-18 01:21:55 -0700 | [diff] [blame] | 264 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 265 | mPageFlipCount++; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 266 | } |
| 267 | |
Dan Stoza | 7143316 | 2014-02-04 16:22:36 -0800 | [diff] [blame] | 268 | status_t DisplayDevice::beginFrame(bool mustRecompose) const { |
| 269 | return mDisplaySurface->beginFrame(mustRecompose); |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 272 | #ifdef USE_HWC2 |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 273 | status_t DisplayDevice::prepareFrame(HWComposer& hwc) { |
| 274 | status_t error = hwc.prepare(*this); |
| 275 | if (error != NO_ERROR) { |
| 276 | return error; |
| 277 | } |
| 278 | |
| 279 | DisplaySurface::CompositionType compositionType; |
| 280 | bool hasClient = hwc.hasClientComposition(mHwcDisplayId); |
| 281 | bool hasDevice = hwc.hasDeviceComposition(mHwcDisplayId); |
| 282 | if (hasClient && hasDevice) { |
| 283 | compositionType = DisplaySurface::COMPOSITION_MIXED; |
| 284 | } else if (hasClient) { |
| 285 | compositionType = DisplaySurface::COMPOSITION_GLES; |
| 286 | } else if (hasDevice) { |
| 287 | compositionType = DisplaySurface::COMPOSITION_HWC; |
| 288 | } else { |
| 289 | // Nothing to do -- when turning the screen off we get a frame like |
| 290 | // this. Call it a HWC frame since we won't be doing any GLES work but |
| 291 | // will do a prepare/set cycle. |
| 292 | compositionType = DisplaySurface::COMPOSITION_HWC; |
| 293 | } |
| 294 | return mDisplaySurface->prepareFrame(compositionType); |
| 295 | } |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 296 | #else |
| 297 | status_t DisplayDevice::prepareFrame(const HWComposer& hwc) const { |
| 298 | DisplaySurface::CompositionType compositionType; |
| 299 | bool haveGles = hwc.hasGlesComposition(mHwcDisplayId); |
| 300 | bool haveHwc = hwc.hasHwcComposition(mHwcDisplayId); |
| 301 | if (haveGles && haveHwc) { |
| 302 | compositionType = DisplaySurface::COMPOSITION_MIXED; |
| 303 | } else if (haveGles) { |
| 304 | compositionType = DisplaySurface::COMPOSITION_GLES; |
| 305 | } else if (haveHwc) { |
| 306 | compositionType = DisplaySurface::COMPOSITION_HWC; |
| 307 | } else { |
| 308 | // Nothing to do -- when turning the screen off we get a frame like |
| 309 | // this. Call it a HWC frame since we won't be doing any GLES work but |
| 310 | // will do a prepare/set cycle. |
| 311 | compositionType = DisplaySurface::COMPOSITION_HWC; |
| 312 | } |
| 313 | return mDisplaySurface->prepareFrame(compositionType); |
| 314 | } |
| 315 | #endif |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 316 | |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 317 | void DisplayDevice::swapBuffers(HWComposer& hwc) const { |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 318 | #ifdef USE_HWC2 |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 319 | if (hwc.hasClientComposition(mHwcDisplayId)) { |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 320 | #else |
| 321 | // We need to call eglSwapBuffers() if: |
| 322 | // (1) we don't have a hardware composer, or |
| 323 | // (2) we did GLES composition this frame, and either |
| 324 | // (a) we have framebuffer target support (not present on legacy |
| 325 | // devices, where HWComposer::commit() handles things); or |
| 326 | // (b) this is a virtual display |
| 327 | if (hwc.initCheck() != NO_ERROR || |
| 328 | (hwc.hasGlesComposition(mHwcDisplayId) && |
| 329 | (hwc.supportsFramebufferTarget() || mType >= DISPLAY_VIRTUAL))) { |
| 330 | #endif |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 331 | EGLBoolean success = eglSwapBuffers(mDisplay, mSurface); |
| 332 | if (!success) { |
| 333 | EGLint error = eglGetError(); |
| 334 | if (error == EGL_CONTEXT_LOST || |
| 335 | mType == DisplayDevice::DISPLAY_PRIMARY) { |
| 336 | LOG_ALWAYS_FATAL("eglSwapBuffers(%p, %p) failed with 0x%08x", |
| 337 | mDisplay, mSurface, error); |
| 338 | } else { |
| 339 | ALOGE("eglSwapBuffers(%p, %p) failed with 0x%08x", |
| 340 | mDisplay, mSurface, error); |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | } |
Mathias Agopian | 52e2148 | 2012-09-24 18:07:21 -0700 | [diff] [blame] | 344 | |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 345 | status_t result = mDisplaySurface->advanceFrame(); |
| 346 | if (result != NO_ERROR) { |
| 347 | ALOGE("[%s] failed pushing new frame to HWC: %d", |
| 348 | mDisplayName.string(), result); |
Mathias Agopian | 3234138 | 2012-09-25 19:16:28 -0700 | [diff] [blame] | 349 | } |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 352 | #ifdef USE_HWC2 |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 353 | void DisplayDevice::onSwapBuffersCompleted() const { |
| 354 | mDisplaySurface->onFrameCommitted(); |
| 355 | } |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 356 | #else |
| 357 | void DisplayDevice::onSwapBuffersCompleted(HWComposer& hwc) const { |
| 358 | if (hwc.initCheck() == NO_ERROR) { |
| 359 | mDisplaySurface->onFrameCommitted(); |
| 360 | } |
| 361 | } |
| 362 | #endif |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 363 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 364 | uint32_t DisplayDevice::getFlags() const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | { |
| 366 | return mFlags; |
| 367 | } |
| 368 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 369 | EGLBoolean DisplayDevice::makeCurrent(EGLDisplay dpy, EGLContext ctx) const { |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 370 | EGLBoolean result = EGL_TRUE; |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 371 | EGLSurface sur = eglGetCurrentSurface(EGL_DRAW); |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 372 | if (sur != mSurface) { |
| 373 | result = eglMakeCurrent(dpy, mSurface, mSurface, ctx); |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 374 | if (result == EGL_TRUE) { |
Jesse Hall | f460f55 | 2013-08-06 17:08:53 -0700 | [diff] [blame] | 375 | if (mType >= DisplayDevice::DISPLAY_VIRTUAL) |
| 376 | eglSwapInterval(dpy, 0); |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 377 | } |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 378 | } |
Mathias Agopian | 931bda1 | 2013-08-28 18:11:46 -0700 | [diff] [blame] | 379 | setViewportAndProjection(); |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 380 | return result; |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 383 | void DisplayDevice::setViewportAndProjection() const { |
| 384 | size_t w = mDisplayWidth; |
| 385 | size_t h = mDisplayHeight; |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 386 | Rect sourceCrop(0, 0, w, h); |
Riley Andrews | c3ebe66 | 2014-09-04 16:20:31 -0700 | [diff] [blame] | 387 | mFlinger->getRenderEngine().setViewportAndProjection(w, h, sourceCrop, h, |
| 388 | false, Transform::ROT_0); |
Mathias Agopian | bae92d0 | 2012-09-28 01:00:47 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 391 | const sp<Fence>& DisplayDevice::getClientTargetAcquireFence() const { |
| 392 | return mDisplaySurface->getClientTargetAcquireFence(); |
| 393 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 394 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 395 | // ---------------------------------------------------------------------------- |
| 396 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 397 | void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers) { |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 398 | mVisibleLayersSortedByZ = layers; |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 401 | const Vector< sp<Layer> >& DisplayDevice::getVisibleLayersSortedByZ() const { |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 402 | return mVisibleLayersSortedByZ; |
| 403 | } |
| 404 | |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 405 | Region DisplayDevice::getDirtyRegion(bool repaintEverything) const { |
| 406 | Region dirty; |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 407 | if (repaintEverything) { |
| 408 | dirty.set(getBounds()); |
| 409 | } else { |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 410 | const Transform& planeTransform(mGlobalTransform); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 411 | dirty = planeTransform.transform(this->dirtyRegion); |
| 412 | dirty.andSelf(getBounds()); |
| 413 | } |
| 414 | return dirty; |
| 415 | } |
| 416 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 417 | // ---------------------------------------------------------------------------- |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 418 | void DisplayDevice::setPowerMode(int mode) { |
| 419 | mPowerMode = mode; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 422 | int DisplayDevice::getPowerMode() const { |
| 423 | return mPowerMode; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 426 | bool DisplayDevice::isDisplayOn() const { |
| 427 | return (mPowerMode != HWC_POWER_MODE_OFF); |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | // ---------------------------------------------------------------------------- |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 431 | void DisplayDevice::setActiveConfig(int mode) { |
| 432 | mActiveConfig = mode; |
| 433 | } |
| 434 | |
| 435 | int DisplayDevice::getActiveConfig() const { |
| 436 | return mActiveConfig; |
| 437 | } |
| 438 | |
| 439 | // ---------------------------------------------------------------------------- |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 440 | #ifdef USE_HWC2 |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 441 | void DisplayDevice::setActiveColorMode(android_color_mode_t mode) { |
| 442 | mActiveColorMode = mode; |
| 443 | } |
| 444 | |
| 445 | android_color_mode_t DisplayDevice::getActiveColorMode() const { |
| 446 | return mActiveColorMode; |
| 447 | } |
Courtney Goeltzenleuchter | 79d2724 | 2017-07-13 17:54:01 -0600 | [diff] [blame] | 448 | |
| 449 | void DisplayDevice::setCompositionDataSpace(android_dataspace dataspace) { |
| 450 | ANativeWindow* const window = mNativeWindow.get(); |
| 451 | native_window_set_buffers_data_space(window, dataspace); |
| 452 | } |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 453 | #endif |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 454 | |
| 455 | // ---------------------------------------------------------------------------- |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 456 | |
Mathias Agopian | 28947d7 | 2012-08-08 18:51:15 -0700 | [diff] [blame] | 457 | void DisplayDevice::setLayerStack(uint32_t stack) { |
| 458 | mLayerStack = stack; |
| 459 | dirtyRegion.set(bounds()); |
| 460 | } |
| 461 | |
| 462 | // ---------------------------------------------------------------------------- |
| 463 | |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 464 | uint32_t DisplayDevice::getOrientationTransform() const { |
| 465 | uint32_t transform = 0; |
| 466 | switch (mOrientation) { |
| 467 | case DisplayState::eOrientationDefault: |
| 468 | transform = Transform::ROT_0; |
| 469 | break; |
| 470 | case DisplayState::eOrientation90: |
| 471 | transform = Transform::ROT_90; |
| 472 | break; |
| 473 | case DisplayState::eOrientation180: |
| 474 | transform = Transform::ROT_180; |
| 475 | break; |
| 476 | case DisplayState::eOrientation270: |
| 477 | transform = Transform::ROT_270; |
| 478 | break; |
| 479 | } |
| 480 | return transform; |
| 481 | } |
| 482 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 483 | status_t DisplayDevice::orientationToTransfrom( |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 484 | int orientation, int w, int h, Transform* tr) |
| 485 | { |
| 486 | uint32_t flags = 0; |
| 487 | switch (orientation) { |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 488 | case DisplayState::eOrientationDefault: |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 489 | flags = Transform::ROT_0; |
| 490 | break; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 491 | case DisplayState::eOrientation90: |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 492 | flags = Transform::ROT_90; |
| 493 | break; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 494 | case DisplayState::eOrientation180: |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 495 | flags = Transform::ROT_180; |
| 496 | break; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 497 | case DisplayState::eOrientation270: |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 498 | flags = Transform::ROT_270; |
| 499 | break; |
| 500 | default: |
| 501 | return BAD_VALUE; |
| 502 | } |
| 503 | tr->set(flags, w, h); |
| 504 | return NO_ERROR; |
| 505 | } |
| 506 | |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 507 | void DisplayDevice::setDisplaySize(const int newWidth, const int newHeight) { |
| 508 | dirtyRegion.set(getBounds()); |
| 509 | |
Michael Lentine | f2568de | 2014-08-20 10:51:23 -0700 | [diff] [blame] | 510 | if (mSurface != EGL_NO_SURFACE) { |
| 511 | eglDestroySurface(mDisplay, mSurface); |
| 512 | mSurface = EGL_NO_SURFACE; |
| 513 | } |
| 514 | |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 515 | mDisplaySurface->resizeBuffers(newWidth, newHeight); |
| 516 | |
| 517 | ANativeWindow* const window = mNativeWindow.get(); |
| 518 | mSurface = eglCreateWindowSurface(mDisplay, mConfig, window, NULL); |
| 519 | eglQuerySurface(mDisplay, mSurface, EGL_WIDTH, &mDisplayWidth); |
| 520 | eglQuerySurface(mDisplay, mSurface, EGL_HEIGHT, &mDisplayHeight); |
| 521 | |
| 522 | LOG_FATAL_IF(mDisplayWidth != newWidth, |
| 523 | "Unable to set new width to %d", newWidth); |
| 524 | LOG_FATAL_IF(mDisplayHeight != newHeight, |
| 525 | "Unable to set new height to %d", newHeight); |
| 526 | } |
| 527 | |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 528 | void DisplayDevice::setProjection(int orientation, |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 529 | const Rect& newViewport, const Rect& newFrame) { |
| 530 | Rect viewport(newViewport); |
| 531 | Rect frame(newFrame); |
| 532 | |
| 533 | const int w = mDisplayWidth; |
| 534 | const int h = mDisplayHeight; |
| 535 | |
| 536 | Transform R; |
| 537 | DisplayDevice::orientationToTransfrom(orientation, w, h, &R); |
| 538 | |
| 539 | if (!frame.isValid()) { |
| 540 | // the destination frame can be invalid if it has never been set, |
| 541 | // in that case we assume the whole display frame. |
| 542 | frame = Rect(w, h); |
| 543 | } |
| 544 | |
| 545 | if (viewport.isEmpty()) { |
| 546 | // viewport can be invalid if it has never been set, in that case |
| 547 | // we assume the whole display size. |
| 548 | // it's also invalid to have an empty viewport, so we handle that |
| 549 | // case in the same way. |
| 550 | viewport = Rect(w, h); |
| 551 | if (R.getOrientation() & Transform::ROT_90) { |
| 552 | // viewport is always specified in the logical orientation |
| 553 | // of the display (ie: post-rotation). |
| 554 | swap(viewport.right, viewport.bottom); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | dirtyRegion.set(getBounds()); |
| 559 | |
| 560 | Transform TL, TP, S; |
| 561 | float src_width = viewport.width(); |
| 562 | float src_height = viewport.height(); |
| 563 | float dst_width = frame.width(); |
| 564 | float dst_height = frame.height(); |
| 565 | if (src_width != dst_width || src_height != dst_height) { |
| 566 | float sx = dst_width / src_width; |
| 567 | float sy = dst_height / src_height; |
| 568 | S.set(sx, 0, 0, sy); |
| 569 | } |
| 570 | |
| 571 | float src_x = viewport.left; |
| 572 | float src_y = viewport.top; |
| 573 | float dst_x = frame.left; |
| 574 | float dst_y = frame.top; |
| 575 | TL.set(-src_x, -src_y); |
| 576 | TP.set(dst_x, dst_y); |
| 577 | |
| 578 | // The viewport and frame are both in the logical orientation. |
| 579 | // Apply the logical translation, scale to physical size, apply the |
| 580 | // physical translation and finally rotate to the physical orientation. |
| 581 | mGlobalTransform = R * TP * S * TL; |
| 582 | |
| 583 | const uint8_t type = mGlobalTransform.getType(); |
| 584 | mNeedsFiltering = (!mGlobalTransform.preserveRects() || |
| 585 | (type >= Transform::SCALE)); |
| 586 | |
| 587 | mScissor = mGlobalTransform.transform(viewport); |
| 588 | if (mScissor.isEmpty()) { |
Mathias Agopian | 6c7f25a | 2013-05-09 20:37:10 -0700 | [diff] [blame] | 589 | mScissor = getBounds(); |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 590 | } |
| 591 | |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 592 | mOrientation = orientation; |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 593 | if (mType == DisplayType::DISPLAY_PRIMARY) { |
| 594 | uint32_t transform = 0; |
| 595 | switch (mOrientation) { |
| 596 | case DisplayState::eOrientationDefault: |
| 597 | transform = Transform::ROT_0; |
| 598 | break; |
| 599 | case DisplayState::eOrientation90: |
| 600 | transform = Transform::ROT_90; |
| 601 | break; |
| 602 | case DisplayState::eOrientation180: |
| 603 | transform = Transform::ROT_180; |
| 604 | break; |
| 605 | case DisplayState::eOrientation270: |
| 606 | transform = Transform::ROT_270; |
| 607 | break; |
| 608 | } |
| 609 | sPrimaryDisplayOrientation = transform; |
| 610 | } |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 611 | mViewport = viewport; |
| 612 | mFrame = frame; |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 613 | } |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 614 | |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 615 | uint32_t DisplayDevice::getPrimaryDisplayOrientationTransform() { |
| 616 | return sPrimaryDisplayOrientation; |
| 617 | } |
| 618 | |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 619 | void DisplayDevice::dump(String8& result) const { |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 620 | const Transform& tr(mGlobalTransform); |
Courtney Goeltzenleuchter | 152279d | 2017-08-14 18:18:30 -0600 | [diff] [blame] | 621 | ANativeWindow* const window = mNativeWindow.get(); |
Courtney Goeltzenleuchter | 0ebaac3 | 2017-04-13 12:17:03 -0600 | [diff] [blame] | 622 | EGLint redSize, greenSize, blueSize, alphaSize; |
| 623 | eglGetConfigAttrib(mDisplay, mConfig, EGL_RED_SIZE, &redSize); |
| 624 | eglGetConfigAttrib(mDisplay, mConfig, EGL_GREEN_SIZE, &greenSize); |
| 625 | eglGetConfigAttrib(mDisplay, mConfig, EGL_BLUE_SIZE, &blueSize); |
| 626 | eglGetConfigAttrib(mDisplay, mConfig, EGL_ALPHA_SIZE, &alphaSize); |
| 627 | result.appendFormat("+ DisplayDevice: %s\n", mDisplayName.string()); |
| 628 | result.appendFormat(" type=%x, hwcId=%d, layerStack=%u, (%4dx%4d), ANativeWindow=%p " |
| 629 | "(%d:%d:%d:%d), orient=%2d (type=%08x), " |
| 630 | "flips=%u, isSecure=%d, powerMode=%d, activeConfig=%d, numLayers=%zu\n", |
Courtney Goeltzenleuchter | 152279d | 2017-08-14 18:18:30 -0600 | [diff] [blame] | 631 | mType, mHwcDisplayId, mLayerStack, mDisplayWidth, mDisplayHeight, window, |
| 632 | redSize, greenSize, blueSize, alphaSize, mOrientation, tr.getType(), |
| 633 | getPageFlipCount(), mIsSecure, mPowerMode, mActiveConfig, |
Courtney Goeltzenleuchter | 0ebaac3 | 2017-04-13 12:17:03 -0600 | [diff] [blame] | 634 | mVisibleLayersSortedByZ.size()); |
| 635 | result.appendFormat(" v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d]," |
| 636 | "transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n", |
| 637 | mViewport.left, mViewport.top, mViewport.right, mViewport.bottom, |
| 638 | mFrame.left, mFrame.top, mFrame.right, mFrame.bottom, mScissor.left, |
| 639 | mScissor.top, mScissor.right, mScissor.bottom, tr[0][0], tr[1][0], tr[2][0], |
| 640 | tr[0][1], tr[1][1], tr[2][1], tr[0][2], tr[1][2], tr[2][2]); |
Courtney Goeltzenleuchter | 152279d | 2017-08-14 18:18:30 -0600 | [diff] [blame] | 641 | auto const surface = static_cast<Surface*>(window); |
| 642 | android_dataspace dataspace = surface->getBuffersDataSpace(); |
| 643 | result.appendFormat(" dataspace: %s (%d)\n", dataspaceDetails(dataspace).c_str(), dataspace); |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 644 | |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 645 | String8 surfaceDump; |
Dan Stoza | f10c46e | 2014-11-11 10:32:31 -0800 | [diff] [blame] | 646 | mDisplaySurface->dumpAsString(surfaceDump); |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 647 | result.append(surfaceDump); |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 648 | } |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 649 | |
| 650 | std::atomic<int32_t> DisplayDeviceState::nextDisplayId(1); |
| 651 | |
| 652 | DisplayDeviceState::DisplayDeviceState(DisplayDevice::DisplayType type, bool isSecure) |
| 653 | : type(type), |
| 654 | layerStack(DisplayDevice::NO_LAYER_STACK), |
| 655 | orientation(0), |
| 656 | width(0), |
| 657 | height(0), |
| 658 | isSecure(isSecure) |
| 659 | { |
| 660 | viewport.makeInvalid(); |
| 661 | frame.makeInvalid(); |
| 662 | } |