blob: 2b19cc5872ae1a24d549da589a1ef4be8a73a2b3 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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
Dominik Laskowski718f9602019-11-09 20:01:35 -080017#pragma once
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080018
Peiyong Linefefaac2018-08-17 12:27:51 -070019#include <memory>
Dominik Laskowski075d3172018-05-24 15:50:06 -070020#include <optional>
Peiyong Linefefaac2018-08-17 12:27:51 -070021#include <string>
Peiyong Lin136fbbc2018-04-17 15:09:44 -070022#include <unordered_map>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080023
Alec Mourif6fd29e2018-11-17 04:56:41 +000024#include <android/native_window.h>
Dan Stoza9e56aa02015-11-02 13:00:03 -080025#include <binder/IBinder.h>
Chia-I Wuf2aa3112018-08-27 14:54:37 -070026#include <gui/LayerState.h>
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -070027#include <hardware/hwcomposer_defs.h>
Peiyong Linefefaac2018-08-17 12:27:51 -070028#include <math/mat4.h>
Alec Mouri0a9c7b82018-11-16 13:05:25 -080029#include <renderengine/RenderEngine.h>
Alec Mourif6fd29e2018-11-17 04:56:41 +000030#include <system/window.h>
Dominik Laskowski55c85402020-01-21 16:25:47 -080031#include <ui/DisplayInfo.h>
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080032#include <ui/DisplayState.h>
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -070033#include <ui/GraphicTypes.h>
Peiyong Linfb069302018-04-25 14:34:31 -070034#include <ui/HdrCapabilities.h>
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -070035#include <ui/Region.h>
Peiyong Linefefaac2018-08-17 12:27:51 -070036#include <ui/Transform.h>
Alec Mouri8d4f90a2018-11-14 22:33:24 +000037#include <utils/Mutex.h>
Alec Mouri0a9c7b82018-11-16 13:05:25 -080038#include <utils/RefBase.h>
Mathias Agopian86303202012-07-24 22:46:10 -070039#include <utils/Timers.h>
40
Dominik Laskowski075d3172018-05-24 15:50:06 -070041#include "DisplayHardware/DisplayIdentification.h"
Peiyong Line9d809e2020-04-14 13:10:48 -070042#include "DisplayHardware/Hal.h"
Lloyd Pique688abd42019-02-15 15:42:24 -080043#include "DisplayHardware/PowerAdvisor.h"
chaviwa76b2712017-09-20 12:02:26 -070044#include "RenderArea.h"
Ady Abraham2139f732019-11-13 18:56:40 -080045#include "Scheduler/HwcStrongTypes.h"
Mathias Agopianf4358632012-08-22 17:16:19 -070046
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047namespace android {
48
Dan Stoza9e56aa02015-11-02 13:00:03 -080049class Fence;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070050class HWComposer;
Jesse Hall9e663de2013-08-16 14:28:37 -070051class IGraphicBufferProducer;
Mathias Agopian13127d82013-03-05 17:47:11 -080052class Layer;
Mathias Agopian86303202012-07-24 22:46:10 -070053class SurfaceFlinger;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070054
David Sodmanfb95bcc2017-12-22 15:45:30 -080055struct CompositionInfo;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070056struct DisplayDeviceCreationArgs;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057
Lloyd Pique45a165a2018-10-19 11:54:47 -070058namespace compositionengine {
59class Display;
Lloyd Pique542307f2018-10-19 13:24:08 -070060class DisplaySurface;
Lloyd Pique45a165a2018-10-19 11:54:47 -070061} // namespace compositionengine
62
63class DisplayDevice : public LightRefBase<DisplayDevice> {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064public:
Peiyong Linfb069302018-04-25 14:34:31 -070065 constexpr static float sDefaultMinLumiance = 0.0;
66 constexpr static float sDefaultMaxLumiance = 500.0;
67
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070068 explicit DisplayDevice(DisplayDeviceCreationArgs& args);
Lloyd Pique45a165a2018-10-19 11:54:47 -070069 virtual ~DisplayDevice();
70
71 std::shared_ptr<compositionengine::Display> getCompositionDisplay() const {
72 return mCompositionDisplay;
73 }
Mathias Agopian92a979a2012-08-02 18:32:23 -070074
Dominik Laskowski55c85402020-01-21 16:25:47 -080075 std::optional<DisplayConnectionType> getConnectionType() const { return mConnectionType; }
76
77 bool isVirtual() const { return !mConnectionType; }
Dominik Laskowski075d3172018-05-24 15:50:06 -070078 bool isPrimary() const { return mIsPrimary; }
Mathias Agopian92a979a2012-08-02 18:32:23 -070079
Jamie Gennisdd3cb842012-10-19 18:19:11 -070080 // isSecure indicates whether this display can be trusted to display
81 // secure surfaces.
Lloyd Pique45a165a2018-10-19 11:54:47 -070082 bool isSecure() const;
Jamie Gennisdd3cb842012-10-19 18:19:11 -070083
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080084 int getWidth() const;
85 int getHeight() const;
86 ui::Size getSize() const { return {getWidth(), getHeight()}; }
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070087
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080088 void setLayerStack(ui::LayerStack);
89 void setDisplaySize(int width, int height);
Dominik Laskowski718f9602019-11-09 20:01:35 -080090 void setProjection(ui::Rotation orientation, Rect viewport, Rect frame);
91
92 ui::Rotation getPhysicalOrientation() const { return mPhysicalOrientation; }
93 ui::Rotation getOrientation() const { return mOrientation; }
94
95 static ui::Transform::RotationFlags getPrimaryDisplayRotationFlags();
96
Lloyd Pique32cbe282018-10-19 13:09:22 -070097 const ui::Transform& getTransform() const;
98 const Rect& getViewport() const;
99 const Rect& getFrame() const;
Lloyd Piquee8fe4742020-01-21 15:26:18 -0800100 const Rect& getSourceClip() const;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700101 bool needsFiltering() const;
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800102 ui::LayerStack getLayerStack() const;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700103
Lloyd Pique45a165a2018-10-19 11:54:47 -0700104 const std::optional<DisplayId>& getId() const;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700105 const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
Dominik Laskowskie9774092018-12-11 10:04:24 -0800106 int32_t getSequenceId() const { return mSequenceId; }
Mathias Agopian87baae12012-07-31 12:38:26 -0700107
Lloyd Pique32cbe282018-10-19 13:09:22 -0700108 const Region& getUndefinedRegion() const;
109
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700110 int32_t getSupportedPerFrameMetadata() const;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700111
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700112 bool hasWideColorGamut() const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700113 // Whether h/w composer has native support for specific HDR type.
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700114 bool hasHDR10PlusSupport() const;
115 bool hasHDR10Support() const;
116 bool hasHLGSupport() const;
117 bool hasDolbyVisionSupport() const;
Chia-I Wube02ec02018-05-18 10:59:36 -0700118
Peiyong Linfb069302018-04-25 14:34:31 -0700119 // The returned HdrCapabilities is the combination of HDR capabilities from
120 // hardware composer and RenderEngine. When the DisplayDevice supports wide
121 // color gamut, RenderEngine is able to simulate HDR support in Display P3
122 // color space for both PQ and HLG HDR contents. The minimum and maximum
123 // luminance will be set to sDefaultMinLumiance and sDefaultMaxLumiance
124 // respectively if hardware composer doesn't return meaningful values.
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700125 const HdrCapabilities& getHdrCapabilities() const;
Jesse Hall38efe862013-04-06 23:12:29 -0700126
Chia-I Wube02ec02018-05-18 10:59:36 -0700127 // Return true if intent is supported by the display.
128 bool hasRenderIntent(ui::RenderIntent intent) const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700129
Lloyd Pique32cbe282018-10-19 13:09:22 -0700130 const Rect& getBounds() const;
131 const Rect& bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800132
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700133 void setDisplayName(const std::string& displayName);
134 const std::string& getDisplayName() const { return mDisplayName; }
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700135
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700136 /* ------------------------------------------------------------------------
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700137 * Display power mode management.
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700138 */
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700139 int getPowerMode() const;
140 void setPowerMode(int mode);
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700141 bool isPoweredOn() const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700142
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800143 ui::Dataspace getCompositionDataSpace() const;
Michael Wright28f24d02016-07-12 13:30:53 -0700144
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700145 /* ------------------------------------------------------------------------
146 * Display active config management.
147 */
Ady Abraham2139f732019-11-13 18:56:40 -0800148 HwcConfigIndexType getActiveConfig() const;
149 void setActiveConfig(HwcConfigIndexType mode);
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700150
Jesse Hall02d86562013-03-25 14:43:23 -0700151 // release HWC resources (if any) for removable displays
Lloyd Pique45a165a2018-10-19 11:54:47 -0700152 void disconnect();
Jesse Hall02d86562013-03-25 14:43:23 -0700153
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700154 /* ------------------------------------------------------------------------
155 * Debugging
156 */
157 uint32_t getPageFlipCount() const;
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700158 std::string getDebugName() const;
Yiwei Zhang5434a782018-12-05 18:06:32 -0800159 void dump(std::string& result) const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700160
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800161private:
Dominik Laskowski075d3172018-05-24 15:50:06 -0700162 const sp<SurfaceFlinger> mFlinger;
163 const wp<IBinder> mDisplayToken;
Dominik Laskowskie9774092018-12-11 10:04:24 -0800164 const int32_t mSequenceId;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800165 const std::optional<DisplayConnectionType> mConnectionType;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700166
Lloyd Pique45a165a2018-10-19 11:54:47 -0700167 const std::shared_ptr<compositionengine::Display> mCompositionDisplay;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700168
Lloyd Pique31cb2942018-10-19 17:23:03 -0700169 std::string mDisplayName;
Mathias Agopian03e40722012-04-26 16:11:59 -0700170
Dominik Laskowski718f9602019-11-09 20:01:35 -0800171 const ui::Rotation mPhysicalOrientation;
172 ui::Rotation mOrientation = ui::ROTATION_0;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700173
Dominik Laskowski718f9602019-11-09 20:01:35 -0800174 static ui::Transform::RotationFlags sPrimaryDisplayRotationFlags;
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700175
Dominik Laskowski718f9602019-11-09 20:01:35 -0800176 int mPowerMode = HWC_POWER_MODE_OFF;
Ady Abraham2139f732019-11-13 18:56:40 -0800177 HwcConfigIndexType mActiveConfig;
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -0600178
Dominik Laskowski075d3172018-05-24 15:50:06 -0700179 // TODO(b/74619554): Remove special cases for primary display.
180 const bool mIsPrimary;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800181};
182
Irvelffc9efc2016-07-27 15:16:37 -0700183struct DisplayDeviceState {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800184 struct Physical {
185 DisplayId id;
186 DisplayConnectionType type;
Peiyong Line9d809e2020-04-14 13:10:48 -0700187 android::hardware::graphics::composer::hal::HWDisplayId hwcDisplayId;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800188
189 bool operator==(const Physical& other) const {
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100190 return id == other.id && type == other.type && hwcDisplayId == other.hwcDisplayId;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800191 }
192 };
193
194 bool isVirtual() const { return !physical; }
Irvelffc9efc2016-07-27 15:16:37 -0700195
Dominik Laskowski663bd282018-04-19 15:26:54 -0700196 int32_t sequenceId = sNextSequenceId++;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800197 std::optional<Physical> physical;
Irvelffc9efc2016-07-27 15:16:37 -0700198 sp<IGraphicBufferProducer> surface;
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800199 ui::LayerStack layerStack = ui::NO_LAYER_STACK;
Irvelffc9efc2016-07-27 15:16:37 -0700200 Rect viewport;
201 Rect frame;
Dominik Laskowski718f9602019-11-09 20:01:35 -0800202 ui::Rotation orientation = ui::ROTATION_0;
Irvelffc9efc2016-07-27 15:16:37 -0700203 uint32_t width = 0;
204 uint32_t height = 0;
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700205 std::string displayName;
Irvelffc9efc2016-07-27 15:16:37 -0700206 bool isSecure = false;
Dominik Laskowski663bd282018-04-19 15:26:54 -0700207
208private:
209 static std::atomic<int32_t> sNextSequenceId;
Irvelffc9efc2016-07-27 15:16:37 -0700210};
211
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700212struct DisplayDeviceCreationArgs {
213 // We use a constructor to ensure some of the values are set, without
214 // assuming a default value.
Dominik Laskowski55c85402020-01-21 16:25:47 -0800215 DisplayDeviceCreationArgs(const sp<SurfaceFlinger>&, const wp<IBinder>& displayToken,
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700216 std::shared_ptr<compositionengine::Display>);
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700217 const sp<SurfaceFlinger> flinger;
218 const wp<IBinder> displayToken;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700219 const std::shared_ptr<compositionengine::Display> compositionDisplay;
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700220
Dominik Laskowskie9774092018-12-11 10:04:24 -0800221 int32_t sequenceId{0};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800222 std::optional<DisplayConnectionType> connectionType;
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700223 bool isSecure{false};
224 sp<ANativeWindow> nativeWindow;
Lloyd Pique542307f2018-10-19 13:24:08 -0700225 sp<compositionengine::DisplaySurface> displaySurface;
Dominik Laskowski718f9602019-11-09 20:01:35 -0800226 ui::Rotation physicalOrientation{ui::ROTATION_0};
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700227 bool hasWideColorGamut{false};
228 HdrCapabilities hdrCapabilities;
229 int32_t supportedPerFrameMetadata{0};
230 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> hwcColorModes;
231 int initialPowerMode{HWC_POWER_MODE_NORMAL};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700232 bool isPrimary{false};
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700233};
234
chaviwa76b2712017-09-20 12:02:26 -0700235class DisplayRenderArea : public RenderArea {
236public:
Dominik Laskowski718f9602019-11-09 20:01:35 -0800237 DisplayRenderArea(const sp<const DisplayDevice>& display,
238 RotationFlags rotation = ui::Transform::ROT_0)
Ady Abraham8a82ba62020-01-17 12:43:17 -0800239 : DisplayRenderArea(display, display->getBounds(),
240 static_cast<uint32_t>(display->getWidth()),
241 static_cast<uint32_t>(display->getHeight()),
242 display->getCompositionDataSpace(), rotation) {}
Dominik Laskowski718f9602019-11-09 20:01:35 -0800243
244 DisplayRenderArea(sp<const DisplayDevice> display, const Rect& sourceCrop, uint32_t reqWidth,
245 uint32_t reqHeight, ui::Dataspace reqDataSpace, RotationFlags rotation,
246 bool allowSecureLayers = true)
Peiyong Lin0e003c92018-09-17 11:09:51 -0700247 : RenderArea(reqWidth, reqHeight, CaptureFill::OPAQUE, reqDataSpace,
Alec Mouri5a6d8572020-03-23 23:56:15 -0700248 display->getViewport(), applyDeviceOrientation(rotation, display)),
Dominik Laskowski718f9602019-11-09 20:01:35 -0800249 mDisplay(std::move(display)),
Robert Carrfa8855f2019-02-19 10:05:00 -0800250 mSourceCrop(sourceCrop),
251 mAllowSecureLayers(allowSecureLayers) {}
chaviwa76b2712017-09-20 12:02:26 -0700252
Alec Mouri5a6d8572020-03-23 23:56:15 -0700253 const ui::Transform& getTransform() const override { return mTransform; }
Dominik Laskowski718f9602019-11-09 20:01:35 -0800254 Rect getBounds() const override { return mDisplay->getBounds(); }
255 int getHeight() const override { return mDisplay->getHeight(); }
256 int getWidth() const override { return mDisplay->getWidth(); }
257 bool isSecure() const override { return mAllowSecureLayers && mDisplay->isSecure(); }
258 sp<const DisplayDevice> getDisplayDevice() const override { return mDisplay; }
Chia-I Wu5f6664c2018-08-28 11:01:44 -0700259
260 bool needsFiltering() const override {
Alec Mouri5a6d8572020-03-23 23:56:15 -0700261 // check if the projection from the logical render area
262 // to the physical render area requires filtering
263 const Rect& sourceCrop = getSourceCrop();
Chia-I Wu5f6664c2018-08-28 11:01:44 -0700264 int width = sourceCrop.width();
265 int height = sourceCrop.height();
266 if (getRotationFlags() & ui::Transform::ROT_90) {
267 std::swap(width, height);
268 }
269 return width != getReqWidth() || height != getReqHeight();
270 }
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700271
272 Rect getSourceCrop() const override {
Alec Mouriadb75f42019-03-28 21:42:24 -0700273 // use the projected display viewport by default.
Chia-I Wu8730ba82018-08-29 09:25:59 -0700274 if (mSourceCrop.isEmpty()) {
Lloyd Piquee8fe4742020-01-21 15:26:18 -0800275 return mDisplay->getSourceClip();
Chia-I Wu8730ba82018-08-29 09:25:59 -0700276 }
277
Alec Mouri5a6d8572020-03-23 23:56:15 -0700278 // If there is a source crop provided then it is assumed that the device
279 // was in portrait orientation. This may not logically be true, so
280 // correct for the orientation error by undoing the rotation
281
282 ui::Rotation logicalOrientation = mDisplay->getOrientation();
283 if (logicalOrientation == ui::Rotation::Rotation90) {
284 logicalOrientation = ui::Rotation::Rotation270;
285 } else if (logicalOrientation == ui::Rotation::Rotation270) {
286 logicalOrientation = ui::Rotation::Rotation90;
287 }
288
289 const auto flags = ui::Transform::toRotationFlags(logicalOrientation);
290 int width = mDisplay->getSourceClip().getWidth();
291 int height = mDisplay->getSourceClip().getHeight();
Alec Mouriadb75f42019-03-28 21:42:24 -0700292 ui::Transform rotation;
Alec Mouri5a6d8572020-03-23 23:56:15 -0700293 rotation.set(flags, width, height);
294 return rotation.transform(mSourceCrop);
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700295 }
chaviwa76b2712017-09-20 12:02:26 -0700296
297private:
Alec Mouri5a6d8572020-03-23 23:56:15 -0700298 static RotationFlags applyDeviceOrientation(RotationFlags orientationFlag,
299 const sp<const DisplayDevice>& device) {
Dominik Laskowski718f9602019-11-09 20:01:35 -0800300 uint32_t inverseRotate90 = 0;
301 uint32_t inverseReflect = 0;
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700302
Alec Mouri5a6d8572020-03-23 23:56:15 -0700303 // Reverse the logical orientation.
304 ui::Rotation logicalOrientation = device->getOrientation();
305 if (logicalOrientation == ui::Rotation::Rotation90) {
306 logicalOrientation = ui::Rotation::Rotation270;
307 } else if (logicalOrientation == ui::Rotation::Rotation270) {
308 logicalOrientation = ui::Rotation::Rotation90;
309 }
310
311 const ui::Rotation orientation = device->getPhysicalOrientation() + logicalOrientation;
312
313 switch (orientation) {
Dominik Laskowski718f9602019-11-09 20:01:35 -0800314 case ui::ROTATION_0:
Alec Mouri5a6d8572020-03-23 23:56:15 -0700315 return orientationFlag;
Dominik Laskowski718f9602019-11-09 20:01:35 -0800316
317 case ui::ROTATION_90:
318 inverseRotate90 = ui::Transform::ROT_90;
319 inverseReflect = ui::Transform::ROT_180;
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700320 break;
Dominik Laskowski718f9602019-11-09 20:01:35 -0800321
322 case ui::ROTATION_180:
323 inverseReflect = ui::Transform::ROT_180;
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700324 break;
Dominik Laskowski718f9602019-11-09 20:01:35 -0800325
326 case ui::ROTATION_270:
327 inverseRotate90 = ui::Transform::ROT_90;
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700328 break;
329 }
330
Alec Mouri5a6d8572020-03-23 23:56:15 -0700331 const uint32_t rotate90 = orientationFlag & ui::Transform::ROT_90;
332 uint32_t reflect = orientationFlag & ui::Transform::ROT_180;
Dominik Laskowski718f9602019-11-09 20:01:35 -0800333
334 // Apply reflection for double rotation.
335 if (rotate90 & inverseRotate90) {
336 reflect = ~reflect & ui::Transform::ROT_180;
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700337 }
338
Dominik Laskowski718f9602019-11-09 20:01:35 -0800339 return static_cast<RotationFlags>((rotate90 ^ inverseRotate90) |
340 (reflect ^ inverseReflect));
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700341 }
342
Dominik Laskowski718f9602019-11-09 20:01:35 -0800343 const sp<const DisplayDevice> mDisplay;
chaviwa76b2712017-09-20 12:02:26 -0700344 const Rect mSourceCrop;
Robert Carrfa8855f2019-02-19 10:05:00 -0800345 const bool mAllowSecureLayers;
Alec Mouri5a6d8572020-03-23 23:56:15 -0700346 const ui::Transform mTransform = ui::Transform();
chaviwa76b2712017-09-20 12:02:26 -0700347};
348
Dominik Laskowski718f9602019-11-09 20:01:35 -0800349} // namespace android