blob: 81b3ccf70ce68150453a2ac535ab284a6705df8f [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 Linefefaac2018-08-17 12:27:51 -070027#include <math/mat4.h>
Alec Mouri0a9c7b82018-11-16 13:05:25 -080028#include <renderengine/RenderEngine.h>
Alec Mourif6fd29e2018-11-17 04:56:41 +000029#include <system/window.h>
Dominik Laskowski55c85402020-01-21 16:25:47 -080030#include <ui/DisplayInfo.h>
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080031#include <ui/DisplayState.h>
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -070032#include <ui/GraphicTypes.h>
Peiyong Linfb069302018-04-25 14:34:31 -070033#include <ui/HdrCapabilities.h>
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -070034#include <ui/Region.h>
Peiyong Linefefaac2018-08-17 12:27:51 -070035#include <ui/Transform.h>
Alec Mouri8d4f90a2018-11-14 22:33:24 +000036#include <utils/Mutex.h>
Alec Mouri0a9c7b82018-11-16 13:05:25 -080037#include <utils/RefBase.h>
Mathias Agopian86303202012-07-24 22:46:10 -070038#include <utils/Timers.h>
39
Dominik Laskowski075d3172018-05-24 15:50:06 -070040#include "DisplayHardware/DisplayIdentification.h"
Peiyong Line9d809e2020-04-14 13:10:48 -070041#include "DisplayHardware/Hal.h"
Lloyd Pique688abd42019-02-15 15:42:24 -080042#include "DisplayHardware/PowerAdvisor.h"
chaviwa76b2712017-09-20 12:02:26 -070043#include "RenderArea.h"
Ady Abraham2139f732019-11-13 18:56:40 -080044#include "Scheduler/HwcStrongTypes.h"
Mathias Agopianf4358632012-08-22 17:16:19 -070045
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046namespace android {
47
Dan Stoza9e56aa02015-11-02 13:00:03 -080048class Fence;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070049class HWComposer;
Jesse Hall9e663de2013-08-16 14:28:37 -070050class IGraphicBufferProducer;
Mathias Agopian13127d82013-03-05 17:47:11 -080051class Layer;
Mathias Agopian86303202012-07-24 22:46:10 -070052class SurfaceFlinger;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070053
David Sodmanfb95bcc2017-12-22 15:45:30 -080054struct CompositionInfo;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070055struct DisplayDeviceCreationArgs;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056
Lloyd Pique45a165a2018-10-19 11:54:47 -070057namespace compositionengine {
58class Display;
Lloyd Pique542307f2018-10-19 13:24:08 -070059class DisplaySurface;
Lloyd Pique45a165a2018-10-19 11:54:47 -070060} // namespace compositionengine
61
Marin Shalamanov1c434292020-06-12 01:47:29 +020062class DisplayDevice : public RefBase {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080063public:
Peiyong Linfb069302018-04-25 14:34:31 -070064 constexpr static float sDefaultMinLumiance = 0.0;
65 constexpr static float sDefaultMaxLumiance = 500.0;
66
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070067 explicit DisplayDevice(DisplayDeviceCreationArgs& args);
Marin Shalamanov1c434292020-06-12 01:47:29 +020068
69 // Must be destroyed on the main thread because it may call into HWComposer.
Lloyd Pique45a165a2018-10-19 11:54:47 -070070 virtual ~DisplayDevice();
71
72 std::shared_ptr<compositionengine::Display> getCompositionDisplay() const {
73 return mCompositionDisplay;
74 }
Mathias Agopian92a979a2012-08-02 18:32:23 -070075
Dominik Laskowski55c85402020-01-21 16:25:47 -080076 std::optional<DisplayConnectionType> getConnectionType() const { return mConnectionType; }
77
78 bool isVirtual() const { return !mConnectionType; }
Dominik Laskowski075d3172018-05-24 15:50:06 -070079 bool isPrimary() const { return mIsPrimary; }
Mathias Agopian92a979a2012-08-02 18:32:23 -070080
Jamie Gennisdd3cb842012-10-19 18:19:11 -070081 // isSecure indicates whether this display can be trusted to display
82 // secure surfaces.
Lloyd Pique45a165a2018-10-19 11:54:47 -070083 bool isSecure() const;
Jamie Gennisdd3cb842012-10-19 18:19:11 -070084
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080085 int getWidth() const;
86 int getHeight() const;
87 ui::Size getSize() const { return {getWidth(), getHeight()}; }
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070088
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080089 void setLayerStack(ui::LayerStack);
90 void setDisplaySize(int width, int height);
Dominik Laskowski718f9602019-11-09 20:01:35 -080091 void setProjection(ui::Rotation orientation, Rect viewport, Rect frame);
92
93 ui::Rotation getPhysicalOrientation() const { return mPhysicalOrientation; }
94 ui::Rotation getOrientation() const { return mOrientation; }
95
96 static ui::Transform::RotationFlags getPrimaryDisplayRotationFlags();
97
Dominik Laskowskib7251f42020-04-20 17:42:59 -070098 ui::Transform::RotationFlags getTransformHint() const {
99 return static_cast<ui::Transform::RotationFlags>(getTransform().getOrientation());
100 }
101
Lloyd Pique32cbe282018-10-19 13:09:22 -0700102 const ui::Transform& getTransform() const;
103 const Rect& getViewport() const;
104 const Rect& getFrame() const;
Lloyd Piquee8fe4742020-01-21 15:26:18 -0800105 const Rect& getSourceClip() const;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700106 bool needsFiltering() const;
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800107 ui::LayerStack getLayerStack() const;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700108
Lloyd Pique45a165a2018-10-19 11:54:47 -0700109 const std::optional<DisplayId>& getId() const;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700110 const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
Dominik Laskowskie9774092018-12-11 10:04:24 -0800111 int32_t getSequenceId() const { return mSequenceId; }
Mathias Agopian87baae12012-07-31 12:38:26 -0700112
Lloyd Pique32cbe282018-10-19 13:09:22 -0700113 const Region& getUndefinedRegion() const;
114
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700115 int32_t getSupportedPerFrameMetadata() const;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700116
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700117 bool hasWideColorGamut() const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700118 // Whether h/w composer has native support for specific HDR type.
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700119 bool hasHDR10PlusSupport() const;
120 bool hasHDR10Support() const;
121 bool hasHLGSupport() const;
122 bool hasDolbyVisionSupport() const;
Chia-I Wube02ec02018-05-18 10:59:36 -0700123
Peiyong Linfb069302018-04-25 14:34:31 -0700124 // The returned HdrCapabilities is the combination of HDR capabilities from
125 // hardware composer and RenderEngine. When the DisplayDevice supports wide
126 // color gamut, RenderEngine is able to simulate HDR support in Display P3
127 // color space for both PQ and HLG HDR contents. The minimum and maximum
128 // luminance will be set to sDefaultMinLumiance and sDefaultMaxLumiance
129 // respectively if hardware composer doesn't return meaningful values.
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700130 const HdrCapabilities& getHdrCapabilities() const;
Jesse Hall38efe862013-04-06 23:12:29 -0700131
Chia-I Wube02ec02018-05-18 10:59:36 -0700132 // Return true if intent is supported by the display.
133 bool hasRenderIntent(ui::RenderIntent intent) const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700134
Lloyd Pique32cbe282018-10-19 13:09:22 -0700135 const Rect& getBounds() const;
136 const Rect& bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800137
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700138 void setDisplayName(const std::string& displayName);
139 const std::string& getDisplayName() const { return mDisplayName; }
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700140
Marin Shalamanove5cceea2020-04-30 18:13:10 +0200141 void setDeviceProductInfo(std::optional<DeviceProductInfo> info);
142 const std::optional<DeviceProductInfo>& getDeviceProductInfo() const {
143 return mDeviceProductInfo;
144 }
145
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700146 /* ------------------------------------------------------------------------
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700147 * Display power mode management.
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700148 */
Peiyong Lin65248e02020-04-18 21:15:07 -0700149 hardware::graphics::composer::hal::PowerMode getPowerMode() const;
150 void setPowerMode(hardware::graphics::composer::hal::PowerMode mode);
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700151 bool isPoweredOn() const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700152
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800153 ui::Dataspace getCompositionDataSpace() const;
Michael Wright28f24d02016-07-12 13:30:53 -0700154
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700155 /* ------------------------------------------------------------------------
156 * Display active config management.
157 */
Ady Abraham2139f732019-11-13 18:56:40 -0800158 HwcConfigIndexType getActiveConfig() const;
159 void setActiveConfig(HwcConfigIndexType mode);
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700160
Jesse Hall02d86562013-03-25 14:43:23 -0700161 // release HWC resources (if any) for removable displays
Lloyd Pique45a165a2018-10-19 11:54:47 -0700162 void disconnect();
Jesse Hall02d86562013-03-25 14:43:23 -0700163
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700164 /* ------------------------------------------------------------------------
165 * Debugging
166 */
167 uint32_t getPageFlipCount() const;
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700168 std::string getDebugName() const;
Yiwei Zhang5434a782018-12-05 18:06:32 -0800169 void dump(std::string& result) const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700170
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800171private:
Dominik Laskowski075d3172018-05-24 15:50:06 -0700172 const sp<SurfaceFlinger> mFlinger;
173 const wp<IBinder> mDisplayToken;
Dominik Laskowskie9774092018-12-11 10:04:24 -0800174 const int32_t mSequenceId;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800175 const std::optional<DisplayConnectionType> mConnectionType;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700176
Lloyd Pique45a165a2018-10-19 11:54:47 -0700177 const std::shared_ptr<compositionengine::Display> mCompositionDisplay;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700178
Lloyd Pique31cb2942018-10-19 17:23:03 -0700179 std::string mDisplayName;
Mathias Agopian03e40722012-04-26 16:11:59 -0700180
Dominik Laskowski718f9602019-11-09 20:01:35 -0800181 const ui::Rotation mPhysicalOrientation;
182 ui::Rotation mOrientation = ui::ROTATION_0;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700183
Dominik Laskowski718f9602019-11-09 20:01:35 -0800184 static ui::Transform::RotationFlags sPrimaryDisplayRotationFlags;
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700185
Peiyong Lin65248e02020-04-18 21:15:07 -0700186 hardware::graphics::composer::hal::PowerMode mPowerMode =
187 hardware::graphics::composer::hal::PowerMode::OFF;
Ady Abraham2139f732019-11-13 18:56:40 -0800188 HwcConfigIndexType mActiveConfig;
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -0600189
Dominik Laskowski075d3172018-05-24 15:50:06 -0700190 // TODO(b/74619554): Remove special cases for primary display.
191 const bool mIsPrimary;
Marin Shalamanove5cceea2020-04-30 18:13:10 +0200192
193 std::optional<DeviceProductInfo> mDeviceProductInfo;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800194};
195
Irvelffc9efc2016-07-27 15:16:37 -0700196struct DisplayDeviceState {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800197 struct Physical {
198 DisplayId id;
199 DisplayConnectionType type;
Peiyong Lin65248e02020-04-18 21:15:07 -0700200 hardware::graphics::composer::hal::HWDisplayId hwcDisplayId;
Marin Shalamanov7ce87642020-05-06 13:45:58 +0200201 std::optional<DeviceProductInfo> deviceProductInfo;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800202 bool operator==(const Physical& other) const {
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100203 return id == other.id && type == other.type && hwcDisplayId == other.hwcDisplayId;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800204 }
205 };
206
207 bool isVirtual() const { return !physical; }
Irvelffc9efc2016-07-27 15:16:37 -0700208
Dominik Laskowski663bd282018-04-19 15:26:54 -0700209 int32_t sequenceId = sNextSequenceId++;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800210 std::optional<Physical> physical;
Irvelffc9efc2016-07-27 15:16:37 -0700211 sp<IGraphicBufferProducer> surface;
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800212 ui::LayerStack layerStack = ui::NO_LAYER_STACK;
Irvelffc9efc2016-07-27 15:16:37 -0700213 Rect viewport;
214 Rect frame;
Dominik Laskowski718f9602019-11-09 20:01:35 -0800215 ui::Rotation orientation = ui::ROTATION_0;
Irvelffc9efc2016-07-27 15:16:37 -0700216 uint32_t width = 0;
217 uint32_t height = 0;
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700218 std::string displayName;
Irvelffc9efc2016-07-27 15:16:37 -0700219 bool isSecure = false;
Dominik Laskowski663bd282018-04-19 15:26:54 -0700220
221private:
222 static std::atomic<int32_t> sNextSequenceId;
Irvelffc9efc2016-07-27 15:16:37 -0700223};
224
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700225struct DisplayDeviceCreationArgs {
226 // We use a constructor to ensure some of the values are set, without
227 // assuming a default value.
Dominik Laskowski55c85402020-01-21 16:25:47 -0800228 DisplayDeviceCreationArgs(const sp<SurfaceFlinger>&, const wp<IBinder>& displayToken,
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700229 std::shared_ptr<compositionengine::Display>);
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700230 const sp<SurfaceFlinger> flinger;
231 const wp<IBinder> displayToken;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700232 const std::shared_ptr<compositionengine::Display> compositionDisplay;
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700233
Dominik Laskowskie9774092018-12-11 10:04:24 -0800234 int32_t sequenceId{0};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800235 std::optional<DisplayConnectionType> connectionType;
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700236 bool isSecure{false};
237 sp<ANativeWindow> nativeWindow;
Lloyd Pique542307f2018-10-19 13:24:08 -0700238 sp<compositionengine::DisplaySurface> displaySurface;
Dominik Laskowski718f9602019-11-09 20:01:35 -0800239 ui::Rotation physicalOrientation{ui::ROTATION_0};
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700240 bool hasWideColorGamut{false};
241 HdrCapabilities hdrCapabilities;
242 int32_t supportedPerFrameMetadata{0};
243 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> hwcColorModes;
Peiyong Lin65248e02020-04-18 21:15:07 -0700244 hardware::graphics::composer::hal::PowerMode initialPowerMode{
245 hardware::graphics::composer::hal::PowerMode::ON};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700246 bool isPrimary{false};
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700247};
248
chaviwa76b2712017-09-20 12:02:26 -0700249class DisplayRenderArea : public RenderArea {
250public:
Marin Shalamanov1c434292020-06-12 01:47:29 +0200251 static std::unique_ptr<RenderArea> create(wp<const DisplayDevice> displayWeak,
252 const Rect& sourceCrop, ui::Size reqSize,
253 ui::Dataspace reqDataSpace, RotationFlags rotation,
254 bool allowSecureLayers = true) {
255 if (auto display = displayWeak.promote()) {
256 // Using new to access a private constructor.
257 return std::unique_ptr<DisplayRenderArea>(
258 new DisplayRenderArea(std::move(display), sourceCrop, reqSize, reqDataSpace,
259 rotation, allowSecureLayers));
260 }
261 return nullptr;
262 }
chaviwa76b2712017-09-20 12:02:26 -0700263
Alec Mouri5a6d8572020-03-23 23:56:15 -0700264 const ui::Transform& getTransform() const override { return mTransform; }
Dominik Laskowski718f9602019-11-09 20:01:35 -0800265 Rect getBounds() const override { return mDisplay->getBounds(); }
266 int getHeight() const override { return mDisplay->getHeight(); }
267 int getWidth() const override { return mDisplay->getWidth(); }
268 bool isSecure() const override { return mAllowSecureLayers && mDisplay->isSecure(); }
269 sp<const DisplayDevice> getDisplayDevice() const override { return mDisplay; }
Chia-I Wu5f6664c2018-08-28 11:01:44 -0700270
271 bool needsFiltering() const override {
Alec Mouri5a6d8572020-03-23 23:56:15 -0700272 // check if the projection from the logical render area
273 // to the physical render area requires filtering
274 const Rect& sourceCrop = getSourceCrop();
Chia-I Wu5f6664c2018-08-28 11:01:44 -0700275 int width = sourceCrop.width();
276 int height = sourceCrop.height();
277 if (getRotationFlags() & ui::Transform::ROT_90) {
278 std::swap(width, height);
279 }
280 return width != getReqWidth() || height != getReqHeight();
281 }
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700282
283 Rect getSourceCrop() const override {
Alec Mouriadb75f42019-03-28 21:42:24 -0700284 // use the projected display viewport by default.
Chia-I Wu8730ba82018-08-29 09:25:59 -0700285 if (mSourceCrop.isEmpty()) {
Lloyd Piquee8fe4742020-01-21 15:26:18 -0800286 return mDisplay->getSourceClip();
Chia-I Wu8730ba82018-08-29 09:25:59 -0700287 }
288
Alec Mouri5a6d8572020-03-23 23:56:15 -0700289 // If there is a source crop provided then it is assumed that the device
290 // was in portrait orientation. This may not logically be true, so
291 // correct for the orientation error by undoing the rotation
292
293 ui::Rotation logicalOrientation = mDisplay->getOrientation();
294 if (logicalOrientation == ui::Rotation::Rotation90) {
295 logicalOrientation = ui::Rotation::Rotation270;
296 } else if (logicalOrientation == ui::Rotation::Rotation270) {
297 logicalOrientation = ui::Rotation::Rotation90;
298 }
299
300 const auto flags = ui::Transform::toRotationFlags(logicalOrientation);
301 int width = mDisplay->getSourceClip().getWidth();
302 int height = mDisplay->getSourceClip().getHeight();
Alec Mouriadb75f42019-03-28 21:42:24 -0700303 ui::Transform rotation;
Alec Mouri5a6d8572020-03-23 23:56:15 -0700304 rotation.set(flags, width, height);
305 return rotation.transform(mSourceCrop);
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700306 }
chaviwa76b2712017-09-20 12:02:26 -0700307
308private:
Marin Shalamanov1c434292020-06-12 01:47:29 +0200309 DisplayRenderArea(sp<const DisplayDevice> display, const Rect& sourceCrop, ui::Size reqSize,
310 ui::Dataspace reqDataSpace, RotationFlags rotation, bool allowSecureLayers)
311 : RenderArea(reqSize, CaptureFill::OPAQUE, reqDataSpace, display->getViewport(),
312 applyDeviceOrientation(rotation, display)),
313 mDisplay(std::move(display)),
314 mSourceCrop(sourceCrop),
315 mAllowSecureLayers(allowSecureLayers) {}
316
Alec Mouri5a6d8572020-03-23 23:56:15 -0700317 static RotationFlags applyDeviceOrientation(RotationFlags orientationFlag,
318 const sp<const DisplayDevice>& device) {
Dominik Laskowski718f9602019-11-09 20:01:35 -0800319 uint32_t inverseRotate90 = 0;
320 uint32_t inverseReflect = 0;
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700321
Alec Mouri5a6d8572020-03-23 23:56:15 -0700322 // Reverse the logical orientation.
323 ui::Rotation logicalOrientation = device->getOrientation();
324 if (logicalOrientation == ui::Rotation::Rotation90) {
325 logicalOrientation = ui::Rotation::Rotation270;
326 } else if (logicalOrientation == ui::Rotation::Rotation270) {
327 logicalOrientation = ui::Rotation::Rotation90;
328 }
329
330 const ui::Rotation orientation = device->getPhysicalOrientation() + logicalOrientation;
331
332 switch (orientation) {
Dominik Laskowski718f9602019-11-09 20:01:35 -0800333 case ui::ROTATION_0:
Alec Mouri5a6d8572020-03-23 23:56:15 -0700334 return orientationFlag;
Dominik Laskowski718f9602019-11-09 20:01:35 -0800335
336 case ui::ROTATION_90:
337 inverseRotate90 = ui::Transform::ROT_90;
338 inverseReflect = ui::Transform::ROT_180;
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700339 break;
Dominik Laskowski718f9602019-11-09 20:01:35 -0800340
341 case ui::ROTATION_180:
342 inverseReflect = ui::Transform::ROT_180;
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700343 break;
Dominik Laskowski718f9602019-11-09 20:01:35 -0800344
345 case ui::ROTATION_270:
346 inverseRotate90 = ui::Transform::ROT_90;
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700347 break;
348 }
349
Alec Mouri5a6d8572020-03-23 23:56:15 -0700350 const uint32_t rotate90 = orientationFlag & ui::Transform::ROT_90;
351 uint32_t reflect = orientationFlag & ui::Transform::ROT_180;
Dominik Laskowski718f9602019-11-09 20:01:35 -0800352
353 // Apply reflection for double rotation.
354 if (rotate90 & inverseRotate90) {
355 reflect = ~reflect & ui::Transform::ROT_180;
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700356 }
357
Dominik Laskowski718f9602019-11-09 20:01:35 -0800358 return static_cast<RotationFlags>((rotate90 ^ inverseRotate90) |
359 (reflect ^ inverseReflect));
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700360 }
361
Dominik Laskowski718f9602019-11-09 20:01:35 -0800362 const sp<const DisplayDevice> mDisplay;
chaviwa76b2712017-09-20 12:02:26 -0700363 const Rect mSourceCrop;
Robert Carrfa8855f2019-02-19 10:05:00 -0800364 const bool mAllowSecureLayers;
Alec Mouri5a6d8572020-03-23 23:56:15 -0700365 const ui::Transform mTransform = ui::Transform();
chaviwa76b2712017-09-20 12:02:26 -0700366};
367
Dominik Laskowski718f9602019-11-09 20:01:35 -0800368} // namespace android