blob: 0b92e53f7802e6095f8c1acd2ed9157ac312ac4e [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>
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>
Alec Mouri8d4f90a2018-11-14 22:33:24 +000038#include <utils/Mutex.h>
Alec Mouri0a9c7b82018-11-16 13:05:25 -080039#include <utils/RefBase.h>
Mathias Agopian86303202012-07-24 22:46:10 -070040#include <utils/Timers.h>
41
Dominik Laskowski075d3172018-05-24 15:50:06 -070042#include "DisplayHardware/DisplayIdentification.h"
chaviwa76b2712017-09-20 12:02:26 -070043#include "RenderArea.h"
Mathias Agopianf4358632012-08-22 17:16:19 -070044
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045namespace android {
46
Jesse Hall99c7dbb2013-03-14 14:29:29 -070047class DisplaySurface;
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;
56struct DisplayInfo;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057
Lloyd Pique45a165a2018-10-19 11:54:47 -070058namespace compositionengine {
59class Display;
60} // namespace compositionengine
61
62class DisplayDevice : public LightRefBase<DisplayDevice> {
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
Mathias Agopian87baae12012-07-31 12:38:26 -070067 // region in layer-stack space
68 mutable Region dirtyRegion;
69 // region in screen space
Mathias Agopian87baae12012-07-31 12:38:26 -070070 Region undefinedRegion;
Jesse Hallb7a05492014-08-14 15:45:06 -070071 bool lastCompositionHadVisibleLayers;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070072
Mathias Agopian92a979a2012-08-02 18:32:23 -070073 enum {
Jesse Hall01e29052013-02-19 16:13:35 -080074 NO_LAYER_STACK = 0xFFFFFFFF,
75 };
76
Lloyd Pique2eef1d22018-09-18 21:30:04 -070077 explicit DisplayDevice(DisplayDeviceCreationArgs&& args);
Lloyd Pique45a165a2018-10-19 11:54:47 -070078 virtual ~DisplayDevice();
79
80 std::shared_ptr<compositionengine::Display> getCompositionDisplay() const {
81 return mCompositionDisplay;
82 }
Mathias Agopian92a979a2012-08-02 18:32:23 -070083
Dominik Laskowski075d3172018-05-24 15:50:06 -070084 bool isVirtual() const { return mIsVirtual; }
85 bool isPrimary() const { return mIsPrimary; }
Mathias Agopian92a979a2012-08-02 18:32:23 -070086
Jamie Gennisdd3cb842012-10-19 18:19:11 -070087 // isSecure indicates whether this display can be trusted to display
88 // secure surfaces.
Lloyd Pique45a165a2018-10-19 11:54:47 -070089 bool isSecure() const;
Jamie Gennisdd3cb842012-10-19 18:19:11 -070090
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080091 // Flip the front and back buffers if the back buffer is "dirty". Might
92 // be instantaneous, might involve copying the frame buffer around.
Chia-I Wub02087d2017-11-09 10:19:54 -080093 void flip() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080094
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080095 int getWidth() const;
96 int getHeight() const;
Chia-I Wua02871c2018-08-27 14:38:23 -070097 int getInstallOrientation() const { return mDisplayInstallOrientation; }
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070098
Mathias Agopian13127d82013-03-05 17:47:11 -080099 void setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers);
100 const Vector< sp<Layer> >& getVisibleLayersSortedByZ() const;
Chia-I Wu83806892017-11-16 10:50:20 -0800101 void setLayersNeedingFences(const Vector< sp<Layer> >& layers);
102 const Vector< sp<Layer> >& getLayersNeedingFences() const;
Mathias Agopiancd60f992012-08-16 16:28:27 -0700103 Region getDirtyRegion(bool repaintEverything) const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700104
Mathias Agopian28947d72012-08-08 18:51:15 -0700105 void setLayerStack(uint32_t stack);
Michael Lentine47e45402014-07-18 15:34:25 -0700106 void setDisplaySize(const int newWidth, const int newHeight);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700107 void setProjection(int orientation, const Rect& viewport, const Rect& frame);
Mathias Agopian28947d72012-08-08 18:51:15 -0700108
Mathias Agopian1b031492012-06-20 17:51:20 -0700109 int getOrientation() const { return mOrientation; }
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700110 uint32_t getOrientationTransform() const;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700111 static uint32_t getPrimaryDisplayOrientationTransform();
Peiyong Linefefaac2018-08-17 12:27:51 -0700112 const ui::Transform& getTransform() const { return mGlobalTransform; }
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800113 const Rect getViewport() const { return mViewport; }
114 const Rect getFrame() const { return mFrame; }
Mathias Agopian766dc492012-10-30 18:08:06 -0700115 const Rect& getScissor() const { return mScissor; }
Mathias Agopianeba8c682012-09-19 23:14:45 -0700116 bool needsFiltering() const { return mNeedsFiltering; }
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700117
Mathias Agopian87baae12012-07-31 12:38:26 -0700118 uint32_t getLayerStack() const { return mLayerStack; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700119
Lloyd Pique45a165a2018-10-19 11:54:47 -0700120 const std::optional<DisplayId>& getId() const;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700121 const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
Dominik Laskowskie9774092018-12-11 10:04:24 -0800122 int32_t getSequenceId() const { return mSequenceId; }
Mathias Agopian87baae12012-07-31 12:38:26 -0700123
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700124 int32_t getSupportedPerFrameMetadata() const { return mSupportedPerFrameMetadata; }
125
Dan Stoza71433162014-02-04 16:22:36 -0800126 // We pass in mustRecompose so we can keep VirtualDisplaySurface's state
127 // machine happy without actually queueing a buffer if nothing has changed
128 status_t beginFrame(bool mustRecompose) const;
David Sodmanfb95bcc2017-12-22 15:45:30 -0800129 status_t prepareFrame(HWComposer& hwc, std::vector<CompositionInfo>& compositionInfo);
Chia-I Wube02ec02018-05-18 10:59:36 -0700130
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800131 bool hasWideColorGamut() const { return mHasWideColorGamut; }
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700132 // Whether h/w composer has native support for specific HDR type.
Valerie Haue9e843a2018-12-18 13:39:23 -0800133 bool hasHDR10PlusSupport() const { return mHasHdr10Plus; }
Peiyong Lin62665892018-04-16 11:07:44 -0700134 bool hasHDR10Support() const { return mHasHdr10; }
135 bool hasHLGSupport() const { return mHasHLG; }
136 bool hasDolbyVisionSupport() const { return mHasDolbyVision; }
Chia-I Wube02ec02018-05-18 10:59:36 -0700137
Peiyong Lindfde5112018-06-05 10:58:41 -0700138 // Return true if the HDR dataspace is supported but
139 // there is no corresponding color mode.
140 bool hasLegacyHdrSupport(ui::Dataspace dataspace) const;
Chia-I Wube02ec02018-05-18 10:59:36 -0700141
Peiyong Linfb069302018-04-25 14:34:31 -0700142 // The returned HdrCapabilities is the combination of HDR capabilities from
143 // hardware composer and RenderEngine. When the DisplayDevice supports wide
144 // color gamut, RenderEngine is able to simulate HDR support in Display P3
145 // color space for both PQ and HLG HDR contents. The minimum and maximum
146 // luminance will be set to sDefaultMinLumiance and sDefaultMaxLumiance
147 // respectively if hardware composer doesn't return meaningful values.
148 const HdrCapabilities& getHdrCapabilities() const { return mHdrCapabilities; }
Jesse Hall38efe862013-04-06 23:12:29 -0700149
Chia-I Wube02ec02018-05-18 10:59:36 -0700150 // Return true if intent is supported by the display.
151 bool hasRenderIntent(ui::RenderIntent intent) const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700152
Chia-I Wube02ec02018-05-18 10:59:36 -0700153 void getBestColorMode(ui::Dataspace dataspace, ui::RenderIntent intent,
154 ui::Dataspace* outDataspace, ui::ColorMode* outMode,
155 ui::RenderIntent* outIntent) const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700156
Peiyong Linfb530cf2018-12-15 05:07:38 +0000157 void setProtected(bool useProtected);
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800158 // Queues the drawn buffer for consumption by HWC.
159 void queueBuffer(HWComposer& hwc);
160 // Allocates a buffer as scratch space for GPU composition
161 sp<GraphicBuffer> dequeueBuffer();
Jesse Hall01e29052013-02-19 16:13:35 -0800162
Mathias Agopianda27af92012-09-13 18:17:13 -0700163 // called after h/w composer has completed its set() call
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800164 void onPresentDisplayCompleted();
Mathias Agopianda27af92012-09-13 18:17:13 -0700165
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700166 Rect getBounds() const {
Mathias Agopian1b031492012-06-20 17:51:20 -0700167 return Rect(mDisplayWidth, mDisplayHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800168 }
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700169 inline Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800170
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700171 void setDisplayName(const std::string& displayName);
172 const std::string& getDisplayName() const { return mDisplayName; }
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700173
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800174 // Acquires a new buffer for GPU composition.
175 void readyNewBuffer();
176 // Marks the current buffer has finished, so that it can be presented and
177 // swapped out.
178 void finishBuffer();
Mathias Agopian875d8e12013-06-07 15:35:48 -0700179 void setViewportAndProjection() const;
Mathias Agopianbae92d02012-09-28 01:00:47 -0700180
Dan Stoza9e56aa02015-11-02 13:00:03 -0800181 const sp<Fence>& getClientTargetAcquireFence() const;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800182
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700183 /* ------------------------------------------------------------------------
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700184 * Display power mode management.
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700185 */
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700186 int getPowerMode() const;
187 void setPowerMode(int mode);
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700188 bool isPoweredOn() const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700189
Peiyong Linfd997e02018-03-28 15:29:00 -0700190 ui::ColorMode getActiveColorMode() const;
191 void setActiveColorMode(ui::ColorMode mode);
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800192 ui::RenderIntent getActiveRenderIntent() const;
193 void setActiveRenderIntent(ui::RenderIntent renderIntent);
Yiwei Zhang7c64f172018-03-07 14:52:28 -0800194 android_color_transform_t getColorTransform() const;
195 void setColorTransform(const mat4& transform);
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700196 void setCompositionDataSpace(ui::Dataspace dataspace);
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800197 ui::Dataspace getCompositionDataSpace() const;
Michael Wright28f24d02016-07-12 13:30:53 -0700198
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700199 /* ------------------------------------------------------------------------
200 * Display active config management.
201 */
202 int getActiveConfig() const;
203 void setActiveConfig(int mode);
204
Jesse Hall02d86562013-03-25 14:43:23 -0700205 // release HWC resources (if any) for removable displays
Lloyd Pique45a165a2018-10-19 11:54:47 -0700206 void disconnect();
Jesse Hall02d86562013-03-25 14:43:23 -0700207
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700208 /* ------------------------------------------------------------------------
209 * Debugging
210 */
211 uint32_t getPageFlipCount() const;
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700212 std::string getDebugName() const;
Yiwei Zhang5434a782018-12-05 18:06:32 -0800213 void dump(std::string& result) const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700214
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800215private:
Lloyd Pique45a165a2018-10-19 11:54:47 -0700216 /*
217 * Constants, set during initialization
218 */
Dominik Laskowski075d3172018-05-24 15:50:06 -0700219 const sp<SurfaceFlinger> mFlinger;
220 const wp<IBinder> mDisplayToken;
Dominik Laskowskie9774092018-12-11 10:04:24 -0800221 const int32_t mSequenceId;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700222
Lloyd Pique45a165a2018-10-19 11:54:47 -0700223 const int mDisplayInstallOrientation;
224 const std::shared_ptr<compositionengine::Display> mCompositionDisplay;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700225
Mathias Agopiana4912602012-07-12 14:25:33 -0700226 // ANativeWindow this display is rendering into
Mathias Agopiand8552d72012-08-04 21:39:11 -0700227 sp<ANativeWindow> mNativeWindow;
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800228 // Current buffer that this display can render to.
229 sp<GraphicBuffer> mGraphicBuffer;
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700230 sp<DisplaySurface> mDisplaySurface;
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800231 // File descriptor indicating that mGraphicBuffer is ready for display, i.e.
232 // that drawing to the buffer is now complete.
233 base::unique_fd mBufferReady;
Mathias Agopiana4912602012-07-12 14:25:33 -0700234
Mathias Agopian1b031492012-06-20 17:51:20 -0700235 int mDisplayWidth;
236 int mDisplayHeight;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700237 mutable uint32_t mPageFlipCount;
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700238 std::string mDisplayName;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700239
240 const bool mIsVirtual;
Mathias Agopian03e40722012-04-26 16:11:59 -0700241
Mathias Agopiana4912602012-07-12 14:25:33 -0700242 /*
243 * Can only accessed from the main thread, these members
244 * don't need synchronization.
245 */
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700246
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700247 // list of visible layers on that display
Mathias Agopian13127d82013-03-05 17:47:11 -0800248 Vector< sp<Layer> > mVisibleLayersSortedByZ;
Chia-I Wu83806892017-11-16 10:50:20 -0800249 // list of layers needing fences
250 Vector< sp<Layer> > mLayersNeedingFences;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700251
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700252 /*
253 * Transaction state
254 */
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700255 static status_t orientationToTransfrom(int orientation,
Peiyong Linefefaac2018-08-17 12:27:51 -0700256 int w, int h, ui::Transform* tr);
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700257
Fabien Sanglardf0c53d62017-03-03 18:58:50 -0800258 // The identifier of the active layer stack for this display. Several displays
259 // can use the same layer stack: A z-ordered group of layers (sometimes called
260 // "surfaces"). Any given layer can only be on a single layer stack.
Mathias Agopian87baae12012-07-31 12:38:26 -0700261 uint32_t mLayerStack;
Fabien Sanglardf0c53d62017-03-03 18:58:50 -0800262
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700263 int mOrientation;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700264 static uint32_t sPrimaryDisplayOrientation;
Mathias Agopian766dc492012-10-30 18:08:06 -0700265 // user-provided visible area of the layer stack
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700266 Rect mViewport;
Mathias Agopian766dc492012-10-30 18:08:06 -0700267 // user-provided rectangle where mViewport gets mapped to
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700268 Rect mFrame;
Mathias Agopian766dc492012-10-30 18:08:06 -0700269 // pre-computed scissor to apply to the display
270 Rect mScissor;
Peiyong Linefefaac2018-08-17 12:27:51 -0700271 ui::Transform mGlobalTransform;
Mathias Agopianeba8c682012-09-19 23:14:45 -0700272 bool mNeedsFiltering;
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700273 // Current power mode
274 int mPowerMode;
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700275 // Current active config
276 int mActiveConfig;
Michael Wright28f24d02016-07-12 13:30:53 -0700277 // current active color mode
Chia-I Wu614e1422018-05-23 02:17:03 -0700278 ui::ColorMode mActiveColorMode = ui::ColorMode::NATIVE;
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800279 // Current active render intent.
Chia-I Wu614e1422018-05-23 02:17:03 -0700280 ui::RenderIntent mActiveRenderIntent = ui::RenderIntent::COLORIMETRIC;
281 ui::Dataspace mCompositionDataSpace = ui::Dataspace::UNKNOWN;
Yiwei Zhang7c64f172018-03-07 14:52:28 -0800282 // Current color transform
283 android_color_transform_t mColorTransform;
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -0600284
285 // Need to know if display is wide-color capable or not.
286 // Initialized by SurfaceFlinger when the DisplayDevice is created.
287 // Fed to RenderEngine during composition.
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800288 bool mHasWideColorGamut;
Valerie Haue9e843a2018-12-18 13:39:23 -0800289 bool mHasHdr10Plus;
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800290 bool mHasHdr10;
Peiyong Lin62665892018-04-16 11:07:44 -0700291 bool mHasHLG;
292 bool mHasDolbyVision;
Peiyong Linfb069302018-04-25 14:34:31 -0700293 HdrCapabilities mHdrCapabilities;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700294 const int32_t mSupportedPerFrameMetadata;
Chia-I Wube02ec02018-05-18 10:59:36 -0700295
296 // Mappings from desired Dataspace/RenderIntent to the supported
297 // Dataspace/ColorMode/RenderIntent.
298 using ColorModeKey = uint64_t;
299 struct ColorModeValue {
300 ui::Dataspace dataspace;
301 ui::ColorMode colorMode;
302 ui::RenderIntent renderIntent;
303 };
304
305 static ColorModeKey getColorModeKey(ui::Dataspace dataspace, ui::RenderIntent intent) {
306 return (static_cast<uint64_t>(dataspace) << 32) | static_cast<uint32_t>(intent);
307 }
308 void populateColorModes(
309 const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>>& hwcColorModes);
310 void addColorMode(
311 const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>>& hwcColorModes,
312 const ui::ColorMode mode, const ui::RenderIntent intent);
313
314 std::unordered_map<ColorModeKey, ColorModeValue> mColorModes;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700315
316 // TODO(b/74619554): Remove special cases for primary display.
317 const bool mIsPrimary;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800318};
319
Irvelffc9efc2016-07-27 15:16:37 -0700320struct DisplayDeviceState {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700321 bool isVirtual() const { return !displayId.has_value(); }
Irvelffc9efc2016-07-27 15:16:37 -0700322
Dominik Laskowski663bd282018-04-19 15:26:54 -0700323 int32_t sequenceId = sNextSequenceId++;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700324 std::optional<DisplayId> displayId;
Irvelffc9efc2016-07-27 15:16:37 -0700325 sp<IGraphicBufferProducer> surface;
326 uint32_t layerStack = DisplayDevice::NO_LAYER_STACK;
327 Rect viewport;
328 Rect frame;
329 uint8_t orientation = 0;
330 uint32_t width = 0;
331 uint32_t height = 0;
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700332 std::string displayName;
Irvelffc9efc2016-07-27 15:16:37 -0700333 bool isSecure = false;
Dominik Laskowski663bd282018-04-19 15:26:54 -0700334
335private:
336 static std::atomic<int32_t> sNextSequenceId;
Irvelffc9efc2016-07-27 15:16:37 -0700337};
338
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700339struct DisplayDeviceCreationArgs {
340 // We use a constructor to ensure some of the values are set, without
341 // assuming a default value.
342 DisplayDeviceCreationArgs(const sp<SurfaceFlinger>& flinger, const wp<IBinder>& displayToken,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700343 const std::optional<DisplayId>& displayId);
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700344
345 const sp<SurfaceFlinger> flinger;
346 const wp<IBinder> displayToken;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700347 const std::optional<DisplayId> displayId;
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700348
Dominik Laskowskie9774092018-12-11 10:04:24 -0800349 int32_t sequenceId{0};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700350 bool isVirtual{false};
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700351 bool isSecure{false};
352 sp<ANativeWindow> nativeWindow;
353 sp<DisplaySurface> displaySurface;
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700354 int displayInstallOrientation{DisplayState::eOrientationDefault};
355 bool hasWideColorGamut{false};
356 HdrCapabilities hdrCapabilities;
357 int32_t supportedPerFrameMetadata{0};
358 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> hwcColorModes;
359 int initialPowerMode{HWC_POWER_MODE_NORMAL};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700360 bool isPrimary{false};
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700361};
362
chaviwa76b2712017-09-20 12:02:26 -0700363class DisplayRenderArea : public RenderArea {
364public:
365 DisplayRenderArea(const sp<const DisplayDevice> device,
Chia-I Wuc80dcbb2018-08-24 15:34:02 -0700366 ui::Transform::orientation_flags rotation = ui::Transform::ROT_0)
Chia-I Wu9d1abea2018-08-23 13:44:43 -0700367 : DisplayRenderArea(device, device->getBounds(), device->getWidth(), device->getHeight(),
Peiyong Lin0e003c92018-09-17 11:09:51 -0700368 device->getCompositionDataSpace(), rotation) {}
Chia-I Wu9d1abea2018-08-23 13:44:43 -0700369 DisplayRenderArea(const sp<const DisplayDevice> device, Rect sourceCrop, uint32_t reqWidth,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700370 uint32_t reqHeight, ui::Dataspace reqDataSpace,
371 ui::Transform::orientation_flags rotation)
372 : RenderArea(reqWidth, reqHeight, CaptureFill::OPAQUE, reqDataSpace,
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700373 getDisplayRotation(rotation, device->getInstallOrientation())),
374 mDevice(device),
375 mSourceCrop(sourceCrop) {}
chaviwa76b2712017-09-20 12:02:26 -0700376
Peiyong Linefefaac2018-08-17 12:27:51 -0700377 const ui::Transform& getTransform() const override { return mDevice->getTransform(); }
chaviwa76b2712017-09-20 12:02:26 -0700378 Rect getBounds() const override { return mDevice->getBounds(); }
379 int getHeight() const override { return mDevice->getHeight(); }
380 int getWidth() const override { return mDevice->getWidth(); }
381 bool isSecure() const override { return mDevice->isSecure(); }
Chia-I Wu5f6664c2018-08-28 11:01:44 -0700382
383 bool needsFiltering() const override {
Chia-I Wu8730ba82018-08-29 09:25:59 -0700384 // check if the projection from the logical display to the physical
385 // display needs filtering
Chia-I Wu5f6664c2018-08-28 11:01:44 -0700386 if (mDevice->needsFiltering()) {
387 return true;
388 }
389
Chia-I Wu8730ba82018-08-29 09:25:59 -0700390 // check if the projection from the logical render area (i.e., the
391 // physical display) to the physical render area requires filtering
Chia-I Wu5f6664c2018-08-28 11:01:44 -0700392 const Rect sourceCrop = getSourceCrop();
393 int width = sourceCrop.width();
394 int height = sourceCrop.height();
395 if (getRotationFlags() & ui::Transform::ROT_90) {
396 std::swap(width, height);
397 }
398 return width != getReqWidth() || height != getReqHeight();
399 }
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700400
401 Rect getSourceCrop() const override {
Chia-I Wu8730ba82018-08-29 09:25:59 -0700402 // use the (projected) logical display viewport by default
403 if (mSourceCrop.isEmpty()) {
404 return mDevice->getScissor();
405 }
406
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700407 const int orientation = mDevice->getInstallOrientation();
408 if (orientation == DisplayState::eOrientationDefault) {
409 return mSourceCrop;
410 }
411
Chia-I Wu8730ba82018-08-29 09:25:59 -0700412 // Install orientation is transparent to the callers. Apply it now.
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700413 uint32_t flags = 0x00;
414 switch (orientation) {
415 case DisplayState::eOrientation90:
416 flags = ui::Transform::ROT_90;
417 break;
418 case DisplayState::eOrientation180:
419 flags = ui::Transform::ROT_180;
420 break;
421 case DisplayState::eOrientation270:
422 flags = ui::Transform::ROT_270;
423 break;
424 }
425 ui::Transform tr;
426 tr.set(flags, getWidth(), getHeight());
427 return tr.transform(mSourceCrop);
428 }
chaviwa76b2712017-09-20 12:02:26 -0700429
430private:
Chia-I Wu8730ba82018-08-29 09:25:59 -0700431 // Install orientation is transparent to the callers. We need to cancel
432 // it out by modifying rotation flags.
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700433 static ui::Transform::orientation_flags getDisplayRotation(
434 ui::Transform::orientation_flags rotation, int orientation) {
435 if (orientation == DisplayState::eOrientationDefault) {
436 return rotation;
437 }
438
439 // convert hw orientation into flag presentation
440 // here inverse transform needed
441 uint8_t hw_rot_90 = 0x00;
442 uint8_t hw_flip_hv = 0x00;
443 switch (orientation) {
444 case DisplayState::eOrientation90:
445 hw_rot_90 = ui::Transform::ROT_90;
446 hw_flip_hv = ui::Transform::ROT_180;
447 break;
448 case DisplayState::eOrientation180:
449 hw_flip_hv = ui::Transform::ROT_180;
450 break;
451 case DisplayState::eOrientation270:
452 hw_rot_90 = ui::Transform::ROT_90;
453 break;
454 }
455
456 // transform flags operation
457 // 1) flip H V if both have ROT_90 flag
458 // 2) XOR these flags
459 uint8_t rotation_rot_90 = rotation & ui::Transform::ROT_90;
460 uint8_t rotation_flip_hv = rotation & ui::Transform::ROT_180;
461 if (rotation_rot_90 & hw_rot_90) {
462 rotation_flip_hv = (~rotation_flip_hv) & ui::Transform::ROT_180;
463 }
464
465 return static_cast<ui::Transform::orientation_flags>(
466 (rotation_rot_90 ^ hw_rot_90) | (rotation_flip_hv ^ hw_flip_hv));
467 }
468
chaviwa76b2712017-09-20 12:02:26 -0700469 const sp<const DisplayDevice> mDevice;
470 const Rect mSourceCrop;
471};
472
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800473}; // namespace android
474
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700475#endif // ANDROID_DISPLAY_DEVICE_H