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