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