blob: 79a118571e83d20911bf805df8a096f5f70ba967 [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
Mathias Agopiand3ee2312012-08-02 14:01:42 -070017#ifndef ANDROID_DISPLAY_DEVICE_H
18#define ANDROID_DISPLAY_DEVICE_H
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080019
20#include <stdlib.h>
Peiyong Linefefaac2018-08-17 12:27:51 -070021
22#include <memory>
Dominik Laskowski075d3172018-05-24 15:50:06 -070023#include <optional>
Peiyong Linefefaac2018-08-17 12:27:51 -070024#include <string>
Peiyong Lin136fbbc2018-04-17 15:09:44 -070025#include <unordered_map>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026
Alec Mourif6fd29e2018-11-17 04:56:41 +000027#include <android/native_window.h>
Dan Stoza9e56aa02015-11-02 13:00:03 -080028#include <binder/IBinder.h>
Chia-I Wuf2aa3112018-08-27 14:54:37 -070029#include <gui/LayerState.h>
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -070030#include <hardware/hwcomposer_defs.h>
Peiyong Linefefaac2018-08-17 12:27:51 -070031#include <math/mat4.h>
Alec Mouri0a9c7b82018-11-16 13:05:25 -080032#include <renderengine/RenderEngine.h>
Alec Mourif6fd29e2018-11-17 04:56:41 +000033#include <system/window.h>
Huihong Luod6f1fc22019-09-10 14:29:20 -070034#include <ui/DisplayInfo.h>
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -070035#include <ui/GraphicTypes.h>
Peiyong Linfb069302018-04-25 14:34:31 -070036#include <ui/HdrCapabilities.h>
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -070037#include <ui/Region.h>
Peiyong Linefefaac2018-08-17 12:27:51 -070038#include <ui/Transform.h>
Alec Mouri8d4f90a2018-11-14 22:33:24 +000039#include <utils/Mutex.h>
Alec Mouri0a9c7b82018-11-16 13:05:25 -080040#include <utils/RefBase.h>
Mathias Agopian86303202012-07-24 22:46:10 -070041#include <utils/Timers.h>
42
Dominik Laskowski075d3172018-05-24 15:50:06 -070043#include "DisplayHardware/DisplayIdentification.h"
Lloyd Pique688abd42019-02-15 15:42:24 -080044#include "DisplayHardware/PowerAdvisor.h"
chaviwa76b2712017-09-20 12:02:26 -070045#include "RenderArea.h"
Ady Abraham2139f732019-11-13 18:56:40 -080046#include "Scheduler/HwcStrongTypes.h"
Mathias Agopianf4358632012-08-22 17:16:19 -070047
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048namespace android {
49
Dan Stoza9e56aa02015-11-02 13:00:03 -080050class Fence;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070051class HWComposer;
Jesse Hall9e663de2013-08-16 14:28:37 -070052class IGraphicBufferProducer;
Mathias Agopian13127d82013-03-05 17:47:11 -080053class Layer;
Mathias Agopian86303202012-07-24 22:46:10 -070054class SurfaceFlinger;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070055
David Sodmanfb95bcc2017-12-22 15:45:30 -080056struct CompositionInfo;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070057struct DisplayDeviceCreationArgs;
58struct DisplayInfo;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080059
Lloyd Pique45a165a2018-10-19 11:54:47 -070060namespace compositionengine {
61class Display;
Lloyd Pique542307f2018-10-19 13:24:08 -070062class DisplaySurface;
Lloyd Pique45a165a2018-10-19 11:54:47 -070063} // namespace compositionengine
64
65class DisplayDevice : public LightRefBase<DisplayDevice> {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066public:
Peiyong Linfb069302018-04-25 14:34:31 -070067 constexpr static float sDefaultMinLumiance = 0.0;
68 constexpr static float sDefaultMaxLumiance = 500.0;
69
Lloyd Pique2eef1d22018-09-18 21:30:04 -070070 explicit DisplayDevice(DisplayDeviceCreationArgs&& args);
Lloyd Pique45a165a2018-10-19 11:54:47 -070071 virtual ~DisplayDevice();
72
73 std::shared_ptr<compositionengine::Display> getCompositionDisplay() const {
74 return mCompositionDisplay;
75 }
Mathias Agopian92a979a2012-08-02 18:32:23 -070076
Dominik Laskowski075d3172018-05-24 15:50:06 -070077 bool isVirtual() const { return mIsVirtual; }
78 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
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080084 int getWidth() const;
85 int getHeight() const;
Chia-I Wua02871c2018-08-27 14:38:23 -070086 int getInstallOrientation() const { return mDisplayInstallOrientation; }
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070087
Mathias Agopian28947d72012-08-08 18:51:15 -070088 void setLayerStack(uint32_t stack);
Michael Lentine47e45402014-07-18 15:34:25 -070089 void setDisplaySize(const int newWidth, const int newHeight);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -070090 void setProjection(int orientation, const Rect& viewport, const Rect& frame);
Mathias Agopian28947d72012-08-08 18:51:15 -070091
Mathias Agopian1b031492012-06-20 17:51:20 -070092 int getOrientation() const { return mOrientation; }
Pablo Ceballos021623b2016-04-15 17:31:51 -070093 static uint32_t getPrimaryDisplayOrientationTransform();
Lloyd Pique32cbe282018-10-19 13:09:22 -070094 const ui::Transform& getTransform() const;
95 const Rect& getViewport() const;
96 const Rect& getFrame() const;
97 const Rect& getScissor() const;
98 bool needsFiltering() const;
99 uint32_t getLayerStack() const;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700100
Lloyd Pique45a165a2018-10-19 11:54:47 -0700101 const std::optional<DisplayId>& getId() const;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700102 const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
Dominik Laskowskie9774092018-12-11 10:04:24 -0800103 int32_t getSequenceId() const { return mSequenceId; }
Mathias Agopian87baae12012-07-31 12:38:26 -0700104
Lloyd Pique32cbe282018-10-19 13:09:22 -0700105 const Region& getUndefinedRegion() const;
106
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700107 int32_t getSupportedPerFrameMetadata() const;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700108
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700109 bool hasWideColorGamut() const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700110 // Whether h/w composer has native support for specific HDR type.
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700111 bool hasHDR10PlusSupport() const;
112 bool hasHDR10Support() const;
113 bool hasHLGSupport() const;
114 bool hasDolbyVisionSupport() const;
Chia-I Wube02ec02018-05-18 10:59:36 -0700115
Peiyong Linfb069302018-04-25 14:34:31 -0700116 // The returned HdrCapabilities is the combination of HDR capabilities from
117 // hardware composer and RenderEngine. When the DisplayDevice supports wide
118 // color gamut, RenderEngine is able to simulate HDR support in Display P3
119 // color space for both PQ and HLG HDR contents. The minimum and maximum
120 // luminance will be set to sDefaultMinLumiance and sDefaultMaxLumiance
121 // respectively if hardware composer doesn't return meaningful values.
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700122 const HdrCapabilities& getHdrCapabilities() const;
Jesse Hall38efe862013-04-06 23:12:29 -0700123
Chia-I Wube02ec02018-05-18 10:59:36 -0700124 // Return true if intent is supported by the display.
125 bool hasRenderIntent(ui::RenderIntent intent) const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700126
Lloyd Pique32cbe282018-10-19 13:09:22 -0700127 const Rect& getBounds() const;
128 const Rect& bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800129
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700130 void setDisplayName(const std::string& displayName);
131 const std::string& getDisplayName() const { return mDisplayName; }
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700132
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700133 /* ------------------------------------------------------------------------
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700134 * Display power mode management.
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700135 */
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700136 int getPowerMode() const;
137 void setPowerMode(int mode);
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700138 bool isPoweredOn() const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700139
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800140 ui::Dataspace getCompositionDataSpace() const;
Michael Wright28f24d02016-07-12 13:30:53 -0700141
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700142 /* ------------------------------------------------------------------------
143 * Display active config management.
144 */
Ady Abraham2139f732019-11-13 18:56:40 -0800145 HwcConfigIndexType getActiveConfig() const;
146 void setActiveConfig(HwcConfigIndexType mode);
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700147
Jesse Hall02d86562013-03-25 14:43:23 -0700148 // release HWC resources (if any) for removable displays
Lloyd Pique45a165a2018-10-19 11:54:47 -0700149 void disconnect();
Jesse Hall02d86562013-03-25 14:43:23 -0700150
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700151 /* ------------------------------------------------------------------------
152 * Debugging
153 */
154 uint32_t getPageFlipCount() const;
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700155 std::string getDebugName() const;
Yiwei Zhang5434a782018-12-05 18:06:32 -0800156 void dump(std::string& result) const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700157
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800158private:
Lloyd Pique45a165a2018-10-19 11:54:47 -0700159 /*
160 * Constants, set during initialization
161 */
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 Laskowski075d3172018-05-24 15:50:06 -0700165
Lloyd Pique45a165a2018-10-19 11:54:47 -0700166 const int mDisplayInstallOrientation;
167 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;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700170 const bool mIsVirtual;
Mathias Agopian03e40722012-04-26 16:11:59 -0700171
Mathias Agopiana4912602012-07-12 14:25:33 -0700172 /*
173 * Can only accessed from the main thread, these members
174 * don't need synchronization.
175 */
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700176
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700177 /*
178 * Transaction state
179 */
Lloyd Pique32cbe282018-10-19 13:09:22 -0700180 static uint32_t displayStateOrientationToTransformOrientation(int orientation);
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700181 static status_t orientationToTransfrom(int orientation,
Peiyong Linefefaac2018-08-17 12:27:51 -0700182 int w, int h, ui::Transform* tr);
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700183
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700184 int mOrientation;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700185 static uint32_t sPrimaryDisplayOrientation;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700186
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700187 // Current power mode
188 int mPowerMode;
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700189 // Current active config
Ady Abraham2139f732019-11-13 18:56:40 -0800190 HwcConfigIndexType mActiveConfig;
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -0600191
Dominik Laskowski075d3172018-05-24 15:50:06 -0700192 // TODO(b/74619554): Remove special cases for primary display.
193 const bool mIsPrimary;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800194};
195
Irvelffc9efc2016-07-27 15:16:37 -0700196struct DisplayDeviceState {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700197 bool isVirtual() const { return !displayId.has_value(); }
Irvelffc9efc2016-07-27 15:16:37 -0700198
Dominik Laskowski663bd282018-04-19 15:26:54 -0700199 int32_t sequenceId = sNextSequenceId++;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700200 std::optional<DisplayId> displayId;
Irvelffc9efc2016-07-27 15:16:37 -0700201 sp<IGraphicBufferProducer> surface;
Huihong Luod6f1fc22019-09-10 14:29:20 -0700202 uint32_t layerStack = NO_LAYER_STACK;
Irvelffc9efc2016-07-27 15:16:37 -0700203 Rect viewport;
204 Rect frame;
205 uint8_t orientation = 0;
206 uint32_t width = 0;
207 uint32_t height = 0;
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700208 std::string displayName;
Irvelffc9efc2016-07-27 15:16:37 -0700209 bool isSecure = false;
Dominik Laskowski663bd282018-04-19 15:26:54 -0700210
211private:
212 static std::atomic<int32_t> sNextSequenceId;
Irvelffc9efc2016-07-27 15:16:37 -0700213};
214
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700215struct DisplayDeviceCreationArgs {
216 // We use a constructor to ensure some of the values are set, without
217 // assuming a default value.
218 DisplayDeviceCreationArgs(const sp<SurfaceFlinger>& flinger, const wp<IBinder>& displayToken,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700219 const std::optional<DisplayId>& displayId);
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700220
221 const sp<SurfaceFlinger> flinger;
222 const wp<IBinder> displayToken;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700223 const std::optional<DisplayId> displayId;
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700224
Dominik Laskowskie9774092018-12-11 10:04:24 -0800225 int32_t sequenceId{0};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700226 bool isVirtual{false};
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700227 bool isSecure{false};
228 sp<ANativeWindow> nativeWindow;
Lloyd Pique542307f2018-10-19 13:24:08 -0700229 sp<compositionengine::DisplaySurface> displaySurface;
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700230 int displayInstallOrientation{DisplayState::eOrientationDefault};
231 bool hasWideColorGamut{false};
232 HdrCapabilities hdrCapabilities;
233 int32_t supportedPerFrameMetadata{0};
234 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> hwcColorModes;
235 int initialPowerMode{HWC_POWER_MODE_NORMAL};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700236 bool isPrimary{false};
Lloyd Pique688abd42019-02-15 15:42:24 -0800237 Hwc2::PowerAdvisor* powerAdvisor{nullptr};
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700238};
239
chaviwa76b2712017-09-20 12:02:26 -0700240class DisplayRenderArea : public RenderArea {
241public:
242 DisplayRenderArea(const sp<const DisplayDevice> device,
Chia-I Wuc80dcbb2018-08-24 15:34:02 -0700243 ui::Transform::orientation_flags rotation = ui::Transform::ROT_0)
Chia-I Wu9d1abea2018-08-23 13:44:43 -0700244 : DisplayRenderArea(device, device->getBounds(), device->getWidth(), device->getHeight(),
Peiyong Lin0e003c92018-09-17 11:09:51 -0700245 device->getCompositionDataSpace(), rotation) {}
Chia-I Wu9d1abea2018-08-23 13:44:43 -0700246 DisplayRenderArea(const sp<const DisplayDevice> device, Rect sourceCrop, uint32_t reqWidth,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700247 uint32_t reqHeight, ui::Dataspace reqDataSpace,
Robert Carrfa8855f2019-02-19 10:05:00 -0800248 ui::Transform::orientation_flags rotation, bool allowSecureLayers = true)
Peiyong Lin0e003c92018-09-17 11:09:51 -0700249 : RenderArea(reqWidth, reqHeight, CaptureFill::OPAQUE, reqDataSpace,
Vishnu Nair3a7346c2019-12-04 08:09:09 -0800250 device->getViewport(),
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700251 getDisplayRotation(rotation, device->getInstallOrientation())),
252 mDevice(device),
Robert Carrfa8855f2019-02-19 10:05:00 -0800253 mSourceCrop(sourceCrop),
254 mAllowSecureLayers(allowSecureLayers) {}
chaviwa76b2712017-09-20 12:02:26 -0700255
Peiyong Linefefaac2018-08-17 12:27:51 -0700256 const ui::Transform& getTransform() const override { return mDevice->getTransform(); }
chaviwa76b2712017-09-20 12:02:26 -0700257 Rect getBounds() const override { return mDevice->getBounds(); }
258 int getHeight() const override { return mDevice->getHeight(); }
259 int getWidth() const override { return mDevice->getWidth(); }
Robert Carrfa8855f2019-02-19 10:05:00 -0800260 bool isSecure() const override { return mAllowSecureLayers && mDevice->isSecure(); }
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800261 const sp<const DisplayDevice> getDisplayDevice() const override { return mDevice; }
Chia-I Wu5f6664c2018-08-28 11:01:44 -0700262
263 bool needsFiltering() const override {
Chia-I Wu8730ba82018-08-29 09:25:59 -0700264 // check if the projection from the logical display to the physical
265 // display needs filtering
Chia-I Wu5f6664c2018-08-28 11:01:44 -0700266 if (mDevice->needsFiltering()) {
267 return true;
268 }
269
Chia-I Wu8730ba82018-08-29 09:25:59 -0700270 // check if the projection from the logical render area (i.e., the
271 // physical display) to the physical render area requires filtering
Chia-I Wu5f6664c2018-08-28 11:01:44 -0700272 const Rect sourceCrop = getSourceCrop();
273 int width = sourceCrop.width();
274 int height = sourceCrop.height();
275 if (getRotationFlags() & ui::Transform::ROT_90) {
276 std::swap(width, height);
277 }
278 return width != getReqWidth() || height != getReqHeight();
279 }
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700280
281 Rect getSourceCrop() const override {
Alec Mouriadb75f42019-03-28 21:42:24 -0700282 // use the projected display viewport by default.
Chia-I Wu8730ba82018-08-29 09:25:59 -0700283 if (mSourceCrop.isEmpty()) {
284 return mDevice->getScissor();
285 }
286
Alec Mouriadb75f42019-03-28 21:42:24 -0700287 // Recompute the device transformation for the source crop.
288 ui::Transform rotation;
289 ui::Transform translatePhysical;
290 ui::Transform translateLogical;
291 ui::Transform scale;
292 const Rect& viewport = mDevice->getViewport();
293 const Rect& scissor = mDevice->getScissor();
294 const Rect& frame = mDevice->getFrame();
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700295
Alec Mouriadb75f42019-03-28 21:42:24 -0700296 const int orientation = mDevice->getInstallOrientation();
Chia-I Wu8730ba82018-08-29 09:25:59 -0700297 // Install orientation is transparent to the callers. Apply it now.
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700298 uint32_t flags = 0x00;
299 switch (orientation) {
300 case DisplayState::eOrientation90:
301 flags = ui::Transform::ROT_90;
302 break;
303 case DisplayState::eOrientation180:
304 flags = ui::Transform::ROT_180;
305 break;
306 case DisplayState::eOrientation270:
307 flags = ui::Transform::ROT_270;
308 break;
Alec Mouriadb75f42019-03-28 21:42:24 -0700309 default:
310 break;
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700311 }
Alec Mouriadb75f42019-03-28 21:42:24 -0700312 rotation.set(flags, getWidth(), getHeight());
313 translateLogical.set(-viewport.left, -viewport.top);
314 translatePhysical.set(scissor.left, scissor.top);
315 scale.set(frame.getWidth() / float(viewport.getWidth()), 0, 0,
316 frame.getHeight() / float(viewport.getHeight()));
317 const ui::Transform finalTransform =
318 rotation * translatePhysical * scale * translateLogical;
319 return finalTransform.transform(mSourceCrop);
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700320 }
chaviwa76b2712017-09-20 12:02:26 -0700321
322private:
Chia-I Wu8730ba82018-08-29 09:25:59 -0700323 // Install orientation is transparent to the callers. We need to cancel
324 // it out by modifying rotation flags.
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700325 static ui::Transform::orientation_flags getDisplayRotation(
326 ui::Transform::orientation_flags rotation, int orientation) {
327 if (orientation == DisplayState::eOrientationDefault) {
328 return rotation;
329 }
330
331 // convert hw orientation into flag presentation
332 // here inverse transform needed
333 uint8_t hw_rot_90 = 0x00;
334 uint8_t hw_flip_hv = 0x00;
335 switch (orientation) {
336 case DisplayState::eOrientation90:
337 hw_rot_90 = ui::Transform::ROT_90;
338 hw_flip_hv = ui::Transform::ROT_180;
339 break;
340 case DisplayState::eOrientation180:
341 hw_flip_hv = ui::Transform::ROT_180;
342 break;
343 case DisplayState::eOrientation270:
344 hw_rot_90 = ui::Transform::ROT_90;
345 break;
346 }
347
348 // transform flags operation
349 // 1) flip H V if both have ROT_90 flag
350 // 2) XOR these flags
351 uint8_t rotation_rot_90 = rotation & ui::Transform::ROT_90;
352 uint8_t rotation_flip_hv = rotation & ui::Transform::ROT_180;
353 if (rotation_rot_90 & hw_rot_90) {
354 rotation_flip_hv = (~rotation_flip_hv) & ui::Transform::ROT_180;
355 }
356
357 return static_cast<ui::Transform::orientation_flags>(
358 (rotation_rot_90 ^ hw_rot_90) | (rotation_flip_hv ^ hw_flip_hv));
359 }
360
chaviwa76b2712017-09-20 12:02:26 -0700361 const sp<const DisplayDevice> mDevice;
362 const Rect mSourceCrop;
Robert Carrfa8855f2019-02-19 10:05:00 -0800363 const bool mAllowSecureLayers;
chaviwa76b2712017-09-20 12:02:26 -0700364};
365
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800366}; // namespace android
367
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700368#endif // ANDROID_DISPLAY_DEVICE_H