blob: eb2c5c3f946876af87d7b8aa4e9c97f9c07f7a31 [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 Mourice0ad962018-10-17 14:33:41 -070027#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 Mouri8147b0e2018-10-09 20:57:19 -070032#include <renderengine/RenderEngine.h>
Alec Mourice0ad962018-10-17 14:33:41 -070033#include <system/window.h>
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -070034#include <ui/GraphicTypes.h>
Peiyong Linfb069302018-04-25 14:34:31 -070035#include <ui/HdrCapabilities.h>
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -070036#include <ui/Region.h>
Peiyong Linefefaac2018-08-17 12:27:51 -070037#include <ui/Transform.h>
Mathias Agopian86303202012-07-24 22:46:10 -070038#include <utils/Mutex.h>
Alec Mouri8147b0e2018-10-09 20:57:19 -070039#include <utils/RefBase.h>
Mathias Agopian4f4f0942013-08-19 17:26:18 -070040#include <utils/String8.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"
chaviwa76b2712017-09-20 12:02:26 -070044#include "RenderArea.h"
Mathias Agopianf4358632012-08-22 17:16:19 -070045
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046namespace android {
47
Jesse Hall99c7dbb2013-03-14 14:29:29 -070048class DisplaySurface;
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;
57struct DisplayInfo;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058
Mathias Agopian028a7572012-08-05 01:23:51 -070059class DisplayDevice : public LightRefBase<DisplayDevice>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060{
61public:
Peiyong Linfb069302018-04-25 14:34:31 -070062 constexpr static float sDefaultMinLumiance = 0.0;
63 constexpr static float sDefaultMaxLumiance = 500.0;
64
Mathias Agopian87baae12012-07-31 12:38:26 -070065 // region in layer-stack space
66 mutable Region dirtyRegion;
67 // region in screen space
Mathias Agopian87baae12012-07-31 12:38:26 -070068 Region undefinedRegion;
Jesse Hallb7a05492014-08-14 15:45:06 -070069 bool lastCompositionHadVisibleLayers;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070070
Mathias Agopian92a979a2012-08-02 18:32:23 -070071 enum {
Jesse Hall01e29052013-02-19 16:13:35 -080072 NO_LAYER_STACK = 0xFFFFFFFF,
73 };
74
Lloyd Pique2eef1d22018-09-18 21:30:04 -070075 explicit DisplayDevice(DisplayDeviceCreationArgs&& args);
Mathias Agopian028a7572012-08-05 01:23:51 -070076 ~DisplayDevice();
Mathias Agopian92a979a2012-08-02 18:32:23 -070077
Dominik Laskowski075d3172018-05-24 15:50:06 -070078 bool isVirtual() const { return mIsVirtual; }
79 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.
83 bool isSecure() const { return mIsSecure; }
84
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080085 // Flip the front and back buffers if the back buffer is "dirty". Might
86 // be instantaneous, might involve copying the frame buffer around.
Chia-I Wub02087d2017-11-09 10:19:54 -080087 void flip() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080088
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080089 int getWidth() const;
90 int getHeight() const;
Chia-I Wua02871c2018-08-27 14:38:23 -070091 int getInstallOrientation() const { return mDisplayInstallOrientation; }
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070092
Mathias Agopian13127d82013-03-05 17:47:11 -080093 void setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers);
94 const Vector< sp<Layer> >& getVisibleLayersSortedByZ() const;
Chia-I Wu83806892017-11-16 10:50:20 -080095 void setLayersNeedingFences(const Vector< sp<Layer> >& layers);
96 const Vector< sp<Layer> >& getLayersNeedingFences() const;
Mathias Agopiancd60f992012-08-16 16:28:27 -070097 Region getDirtyRegion(bool repaintEverything) const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -070098
Mathias Agopian28947d72012-08-08 18:51:15 -070099 void setLayerStack(uint32_t stack);
Michael Lentine47e45402014-07-18 15:34:25 -0700100 void setDisplaySize(const int newWidth, const int newHeight);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700101 void setProjection(int orientation, const Rect& viewport, const Rect& frame);
Mathias Agopian28947d72012-08-08 18:51:15 -0700102
Mathias Agopian1b031492012-06-20 17:51:20 -0700103 int getOrientation() const { return mOrientation; }
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700104 uint32_t getOrientationTransform() const;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700105 static uint32_t getPrimaryDisplayOrientationTransform();
Peiyong Linefefaac2018-08-17 12:27:51 -0700106 const ui::Transform& getTransform() const { return mGlobalTransform; }
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800107 const Rect getViewport() const { return mViewport; }
108 const Rect getFrame() const { return mFrame; }
Mathias Agopian766dc492012-10-30 18:08:06 -0700109 const Rect& getScissor() const { return mScissor; }
Mathias Agopianeba8c682012-09-19 23:14:45 -0700110 bool needsFiltering() const { return mNeedsFiltering; }
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700111
Mathias Agopian87baae12012-07-31 12:38:26 -0700112 uint32_t getLayerStack() const { return mLayerStack; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700113
114 const std::optional<DisplayId>& getId() const { return mId; }
115 const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
Mathias Agopian87baae12012-07-31 12:38:26 -0700116
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700117 int32_t getSupportedPerFrameMetadata() const { return mSupportedPerFrameMetadata; }
118
Dan Stoza71433162014-02-04 16:22:36 -0800119 // We pass in mustRecompose so we can keep VirtualDisplaySurface's state
120 // machine happy without actually queueing a buffer if nothing has changed
121 status_t beginFrame(bool mustRecompose) const;
David Sodmanfb95bcc2017-12-22 15:45:30 -0800122 status_t prepareFrame(HWComposer& hwc, std::vector<CompositionInfo>& compositionInfo);
Chia-I Wube02ec02018-05-18 10:59:36 -0700123
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800124 bool hasWideColorGamut() const { return mHasWideColorGamut; }
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700125 // Whether h/w composer has native support for specific HDR type.
Peiyong Lin62665892018-04-16 11:07:44 -0700126 bool hasHDR10Support() const { return mHasHdr10; }
127 bool hasHLGSupport() const { return mHasHLG; }
128 bool hasDolbyVisionSupport() const { return mHasDolbyVision; }
Chia-I Wube02ec02018-05-18 10:59:36 -0700129
Peiyong Lindfde5112018-06-05 10:58:41 -0700130 // Return true if the HDR dataspace is supported but
131 // there is no corresponding color mode.
132 bool hasLegacyHdrSupport(ui::Dataspace dataspace) const;
Chia-I Wube02ec02018-05-18 10:59:36 -0700133
Peiyong Linfb069302018-04-25 14:34:31 -0700134 // The returned HdrCapabilities is the combination of HDR capabilities from
135 // hardware composer and RenderEngine. When the DisplayDevice supports wide
136 // color gamut, RenderEngine is able to simulate HDR support in Display P3
137 // color space for both PQ and HLG HDR contents. The minimum and maximum
138 // luminance will be set to sDefaultMinLumiance and sDefaultMaxLumiance
139 // respectively if hardware composer doesn't return meaningful values.
140 const HdrCapabilities& getHdrCapabilities() const { return mHdrCapabilities; }
Jesse Hall38efe862013-04-06 23:12:29 -0700141
Chia-I Wube02ec02018-05-18 10:59:36 -0700142 // Return true if intent is supported by the display.
143 bool hasRenderIntent(ui::RenderIntent intent) const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700144
Chia-I Wube02ec02018-05-18 10:59:36 -0700145 void getBestColorMode(ui::Dataspace dataspace, ui::RenderIntent intent,
146 ui::Dataspace* outDataspace, ui::ColorMode* outMode,
147 ui::RenderIntent* outIntent) const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700148
Alec Mouri8147b0e2018-10-09 20:57:19 -0700149 // Queues the drawn buffer for consumption by HWC.
150 void queueBuffer(HWComposer& hwc);
151 // Allocates a buffer as scratch space for GPU composition
152 sp<GraphicBuffer> dequeueBuffer();
Jesse Hall01e29052013-02-19 16:13:35 -0800153
Mathias Agopianda27af92012-09-13 18:17:13 -0700154 // called after h/w composer has completed its set() call
Alec Mouri8147b0e2018-10-09 20:57:19 -0700155 void onPresentDisplayCompleted();
Mathias Agopianda27af92012-09-13 18:17:13 -0700156
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700157 Rect getBounds() const {
Mathias Agopian1b031492012-06-20 17:51:20 -0700158 return Rect(mDisplayWidth, mDisplayHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800159 }
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700160 inline Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800161
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700162 void setDisplayName(const std::string& displayName);
163 const std::string& getDisplayName() const { return mDisplayName; }
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700164
Alec Mouri8147b0e2018-10-09 20:57:19 -0700165 // Acquires a new buffer for GPU composition.
166 void readyNewBuffer();
167 // Marks the current buffer has finished, so that it can be presented and
168 // swapped out.
169 void finishBuffer();
Mathias Agopian875d8e12013-06-07 15:35:48 -0700170 void setViewportAndProjection() const;
Mathias Agopianbae92d02012-09-28 01:00:47 -0700171
Dan Stoza9e56aa02015-11-02 13:00:03 -0800172 const sp<Fence>& getClientTargetAcquireFence() const;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800173
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700174 /* ------------------------------------------------------------------------
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700175 * Display power mode management.
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700176 */
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700177 int getPowerMode() const;
178 void setPowerMode(int mode);
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700179 bool isPoweredOn() const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700180
Peiyong Linfd997e02018-03-28 15:29:00 -0700181 ui::ColorMode getActiveColorMode() const;
182 void setActiveColorMode(ui::ColorMode mode);
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800183 ui::RenderIntent getActiveRenderIntent() const;
184 void setActiveRenderIntent(ui::RenderIntent renderIntent);
Yiwei Zhang7c64f172018-03-07 14:52:28 -0800185 android_color_transform_t getColorTransform() const;
186 void setColorTransform(const mat4& transform);
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700187 void setCompositionDataSpace(ui::Dataspace dataspace);
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800188 ui::Dataspace getCompositionDataSpace() const;
Michael Wright28f24d02016-07-12 13:30:53 -0700189
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700190 /* ------------------------------------------------------------------------
191 * Display active config management.
192 */
193 int getActiveConfig() const;
194 void setActiveConfig(int mode);
195
Jesse Hall02d86562013-03-25 14:43:23 -0700196 // release HWC resources (if any) for removable displays
197 void disconnect(HWComposer& hwc);
198
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700199 /* ------------------------------------------------------------------------
200 * Debugging
201 */
202 uint32_t getPageFlipCount() const;
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700203 std::string getDebugName() const;
Mathias Agopian74d211a2013-04-22 16:55:35 +0200204 void dump(String8& result) const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700205
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800206private:
Dominik Laskowski075d3172018-05-24 15:50:06 -0700207 const sp<SurfaceFlinger> mFlinger;
208 const wp<IBinder> mDisplayToken;
209
210 std::optional<DisplayId> mId;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700211
Mathias Agopiana4912602012-07-12 14:25:33 -0700212 // ANativeWindow this display is rendering into
Mathias Agopiand8552d72012-08-04 21:39:11 -0700213 sp<ANativeWindow> mNativeWindow;
Alec Mouri8147b0e2018-10-09 20:57:19 -0700214 // Current buffer that this display can render to.
215 sp<GraphicBuffer> mGraphicBuffer;
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700216 sp<DisplaySurface> mDisplaySurface;
Alec Mouri8147b0e2018-10-09 20:57:19 -0700217 // File descriptor indicating that mGraphicBuffer is ready for display, i.e.
218 // that drawing to the buffer is now complete.
219 base::unique_fd mBufferReady;
Mathias Agopiana4912602012-07-12 14:25:33 -0700220
Mathias Agopian1b031492012-06-20 17:51:20 -0700221 int mDisplayWidth;
222 int mDisplayHeight;
Chia-I Wua02871c2018-08-27 14:38:23 -0700223 const int mDisplayInstallOrientation;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700224 mutable uint32_t mPageFlipCount;
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700225 std::string mDisplayName;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700226
227 const bool mIsVirtual;
228 const bool mIsSecure;
Mathias Agopian03e40722012-04-26 16:11:59 -0700229
Mathias Agopiana4912602012-07-12 14:25:33 -0700230 /*
231 * Can only accessed from the main thread, these members
232 * don't need synchronization.
233 */
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700234
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700235 // list of visible layers on that display
Mathias Agopian13127d82013-03-05 17:47:11 -0800236 Vector< sp<Layer> > mVisibleLayersSortedByZ;
Chia-I Wu83806892017-11-16 10:50:20 -0800237 // list of layers needing fences
238 Vector< sp<Layer> > mLayersNeedingFences;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700239
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700240 /*
241 * Transaction state
242 */
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700243 static status_t orientationToTransfrom(int orientation,
Peiyong Linefefaac2018-08-17 12:27:51 -0700244 int w, int h, ui::Transform* tr);
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700245
Fabien Sanglardf0c53d62017-03-03 18:58:50 -0800246 // The identifier of the active layer stack for this display. Several displays
247 // can use the same layer stack: A z-ordered group of layers (sometimes called
248 // "surfaces"). Any given layer can only be on a single layer stack.
Mathias Agopian87baae12012-07-31 12:38:26 -0700249 uint32_t mLayerStack;
Fabien Sanglardf0c53d62017-03-03 18:58:50 -0800250
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700251 int mOrientation;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700252 static uint32_t sPrimaryDisplayOrientation;
Mathias Agopian766dc492012-10-30 18:08:06 -0700253 // user-provided visible area of the layer stack
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700254 Rect mViewport;
Mathias Agopian766dc492012-10-30 18:08:06 -0700255 // user-provided rectangle where mViewport gets mapped to
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700256 Rect mFrame;
Mathias Agopian766dc492012-10-30 18:08:06 -0700257 // pre-computed scissor to apply to the display
258 Rect mScissor;
Peiyong Linefefaac2018-08-17 12:27:51 -0700259 ui::Transform mGlobalTransform;
Mathias Agopianeba8c682012-09-19 23:14:45 -0700260 bool mNeedsFiltering;
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700261 // Current power mode
262 int mPowerMode;
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700263 // Current active config
264 int mActiveConfig;
Michael Wright28f24d02016-07-12 13:30:53 -0700265 // current active color mode
Chia-I Wu614e1422018-05-23 02:17:03 -0700266 ui::ColorMode mActiveColorMode = ui::ColorMode::NATIVE;
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800267 // Current active render intent.
Chia-I Wu614e1422018-05-23 02:17:03 -0700268 ui::RenderIntent mActiveRenderIntent = ui::RenderIntent::COLORIMETRIC;
269 ui::Dataspace mCompositionDataSpace = ui::Dataspace::UNKNOWN;
Yiwei Zhang7c64f172018-03-07 14:52:28 -0800270 // Current color transform
271 android_color_transform_t mColorTransform;
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -0600272
273 // Need to know if display is wide-color capable or not.
274 // Initialized by SurfaceFlinger when the DisplayDevice is created.
275 // Fed to RenderEngine during composition.
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800276 bool mHasWideColorGamut;
277 bool mHasHdr10;
Peiyong Lin62665892018-04-16 11:07:44 -0700278 bool mHasHLG;
279 bool mHasDolbyVision;
Peiyong Linfb069302018-04-25 14:34:31 -0700280 HdrCapabilities mHdrCapabilities;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700281 const int32_t mSupportedPerFrameMetadata;
Chia-I Wube02ec02018-05-18 10:59:36 -0700282
283 // Mappings from desired Dataspace/RenderIntent to the supported
284 // Dataspace/ColorMode/RenderIntent.
285 using ColorModeKey = uint64_t;
286 struct ColorModeValue {
287 ui::Dataspace dataspace;
288 ui::ColorMode colorMode;
289 ui::RenderIntent renderIntent;
290 };
291
292 static ColorModeKey getColorModeKey(ui::Dataspace dataspace, ui::RenderIntent intent) {
293 return (static_cast<uint64_t>(dataspace) << 32) | static_cast<uint32_t>(intent);
294 }
295 void populateColorModes(
296 const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>>& hwcColorModes);
297 void addColorMode(
298 const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>>& hwcColorModes,
299 const ui::ColorMode mode, const ui::RenderIntent intent);
300
301 std::unordered_map<ColorModeKey, ColorModeValue> mColorModes;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700302
303 // TODO(b/74619554): Remove special cases for primary display.
304 const bool mIsPrimary;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800305};
306
Irvelffc9efc2016-07-27 15:16:37 -0700307struct DisplayDeviceState {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700308 bool isVirtual() const { return !displayId.has_value(); }
Irvelffc9efc2016-07-27 15:16:37 -0700309
Dominik Laskowski663bd282018-04-19 15:26:54 -0700310 int32_t sequenceId = sNextSequenceId++;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700311 std::optional<DisplayId> displayId;
Irvelffc9efc2016-07-27 15:16:37 -0700312 sp<IGraphicBufferProducer> surface;
313 uint32_t layerStack = DisplayDevice::NO_LAYER_STACK;
314 Rect viewport;
315 Rect frame;
316 uint8_t orientation = 0;
317 uint32_t width = 0;
318 uint32_t height = 0;
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700319 std::string displayName;
Irvelffc9efc2016-07-27 15:16:37 -0700320 bool isSecure = false;
Dominik Laskowski663bd282018-04-19 15:26:54 -0700321
322private:
323 static std::atomic<int32_t> sNextSequenceId;
Irvelffc9efc2016-07-27 15:16:37 -0700324};
325
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700326struct DisplayDeviceCreationArgs {
327 // We use a constructor to ensure some of the values are set, without
328 // assuming a default value.
329 DisplayDeviceCreationArgs(const sp<SurfaceFlinger>& flinger, const wp<IBinder>& displayToken,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700330 const std::optional<DisplayId>& displayId);
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700331
332 const sp<SurfaceFlinger> flinger;
333 const wp<IBinder> displayToken;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700334 const std::optional<DisplayId> displayId;
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700335
Dominik Laskowski075d3172018-05-24 15:50:06 -0700336 bool isVirtual{false};
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700337 bool isSecure{false};
338 sp<ANativeWindow> nativeWindow;
339 sp<DisplaySurface> displaySurface;
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700340 int displayInstallOrientation{DisplayState::eOrientationDefault};
341 bool hasWideColorGamut{false};
342 HdrCapabilities hdrCapabilities;
343 int32_t supportedPerFrameMetadata{0};
344 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> hwcColorModes;
345 int initialPowerMode{HWC_POWER_MODE_NORMAL};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700346 bool isPrimary{false};
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700347};
348
chaviwa76b2712017-09-20 12:02:26 -0700349class DisplayRenderArea : public RenderArea {
350public:
351 DisplayRenderArea(const sp<const DisplayDevice> device,
Chia-I Wuc80dcbb2018-08-24 15:34:02 -0700352 ui::Transform::orientation_flags rotation = ui::Transform::ROT_0)
Chia-I Wu9d1abea2018-08-23 13:44:43 -0700353 : DisplayRenderArea(device, device->getBounds(), device->getWidth(), device->getHeight(),
Peiyong Lin0e003c92018-09-17 11:09:51 -0700354 device->getCompositionDataSpace(), rotation) {}
Chia-I Wu9d1abea2018-08-23 13:44:43 -0700355 DisplayRenderArea(const sp<const DisplayDevice> device, Rect sourceCrop, uint32_t reqWidth,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700356 uint32_t reqHeight, ui::Dataspace reqDataSpace,
357 ui::Transform::orientation_flags rotation)
358 : RenderArea(reqWidth, reqHeight, CaptureFill::OPAQUE, reqDataSpace,
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700359 getDisplayRotation(rotation, device->getInstallOrientation())),
360 mDevice(device),
361 mSourceCrop(sourceCrop) {}
chaviwa76b2712017-09-20 12:02:26 -0700362
Peiyong Linefefaac2018-08-17 12:27:51 -0700363 const ui::Transform& getTransform() const override { return mDevice->getTransform(); }
chaviwa76b2712017-09-20 12:02:26 -0700364 Rect getBounds() const override { return mDevice->getBounds(); }
365 int getHeight() const override { return mDevice->getHeight(); }
366 int getWidth() const override { return mDevice->getWidth(); }
367 bool isSecure() const override { return mDevice->isSecure(); }
Chia-I Wu5f6664c2018-08-28 11:01:44 -0700368
369 bool needsFiltering() const override {
Chia-I Wu8730ba82018-08-29 09:25:59 -0700370 // check if the projection from the logical display to the physical
371 // display needs filtering
Chia-I Wu5f6664c2018-08-28 11:01:44 -0700372 if (mDevice->needsFiltering()) {
373 return true;
374 }
375
Chia-I Wu8730ba82018-08-29 09:25:59 -0700376 // check if the projection from the logical render area (i.e., the
377 // physical display) to the physical render area requires filtering
Chia-I Wu5f6664c2018-08-28 11:01:44 -0700378 const Rect sourceCrop = getSourceCrop();
379 int width = sourceCrop.width();
380 int height = sourceCrop.height();
381 if (getRotationFlags() & ui::Transform::ROT_90) {
382 std::swap(width, height);
383 }
384 return width != getReqWidth() || height != getReqHeight();
385 }
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700386
387 Rect getSourceCrop() const override {
Chia-I Wu8730ba82018-08-29 09:25:59 -0700388 // use the (projected) logical display viewport by default
389 if (mSourceCrop.isEmpty()) {
390 return mDevice->getScissor();
391 }
392
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700393 const int orientation = mDevice->getInstallOrientation();
394 if (orientation == DisplayState::eOrientationDefault) {
395 return mSourceCrop;
396 }
397
Chia-I Wu8730ba82018-08-29 09:25:59 -0700398 // Install orientation is transparent to the callers. Apply it now.
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700399 uint32_t flags = 0x00;
400 switch (orientation) {
401 case DisplayState::eOrientation90:
402 flags = ui::Transform::ROT_90;
403 break;
404 case DisplayState::eOrientation180:
405 flags = ui::Transform::ROT_180;
406 break;
407 case DisplayState::eOrientation270:
408 flags = ui::Transform::ROT_270;
409 break;
410 }
411 ui::Transform tr;
412 tr.set(flags, getWidth(), getHeight());
413 return tr.transform(mSourceCrop);
414 }
chaviwa76b2712017-09-20 12:02:26 -0700415
416private:
Chia-I Wu8730ba82018-08-29 09:25:59 -0700417 // Install orientation is transparent to the callers. We need to cancel
418 // it out by modifying rotation flags.
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700419 static ui::Transform::orientation_flags getDisplayRotation(
420 ui::Transform::orientation_flags rotation, int orientation) {
421 if (orientation == DisplayState::eOrientationDefault) {
422 return rotation;
423 }
424
425 // convert hw orientation into flag presentation
426 // here inverse transform needed
427 uint8_t hw_rot_90 = 0x00;
428 uint8_t hw_flip_hv = 0x00;
429 switch (orientation) {
430 case DisplayState::eOrientation90:
431 hw_rot_90 = ui::Transform::ROT_90;
432 hw_flip_hv = ui::Transform::ROT_180;
433 break;
434 case DisplayState::eOrientation180:
435 hw_flip_hv = ui::Transform::ROT_180;
436 break;
437 case DisplayState::eOrientation270:
438 hw_rot_90 = ui::Transform::ROT_90;
439 break;
440 }
441
442 // transform flags operation
443 // 1) flip H V if both have ROT_90 flag
444 // 2) XOR these flags
445 uint8_t rotation_rot_90 = rotation & ui::Transform::ROT_90;
446 uint8_t rotation_flip_hv = rotation & ui::Transform::ROT_180;
447 if (rotation_rot_90 & hw_rot_90) {
448 rotation_flip_hv = (~rotation_flip_hv) & ui::Transform::ROT_180;
449 }
450
451 return static_cast<ui::Transform::orientation_flags>(
452 (rotation_rot_90 ^ hw_rot_90) | (rotation_flip_hv ^ hw_flip_hv));
453 }
454
chaviwa76b2712017-09-20 12:02:26 -0700455 const sp<const DisplayDevice> mDevice;
456 const Rect mSourceCrop;
457};
458
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800459}; // namespace android
460
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700461#endif // ANDROID_DISPLAY_DEVICE_H