blob: 38482c9dd588829abb579dbd35fa20019b533970 [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>
23#include <string>
Peiyong Lin136fbbc2018-04-17 15:09:44 -070024#include <unordered_map>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080025
Dan Stoza9e56aa02015-11-02 13:00:03 -080026#include <binder/IBinder.h>
Chia-I Wuf2aa3112018-08-27 14:54:37 -070027#include <gui/LayerState.h>
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -070028#include <hardware/hwcomposer_defs.h>
Peiyong Linefefaac2018-08-17 12:27:51 -070029#include <math/mat4.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070030#include <renderengine/Surface.h>
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -070031#include <ui/GraphicTypes.h>
Peiyong Linfb069302018-04-25 14:34:31 -070032#include <ui/HdrCapabilities.h>
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -070033#include <ui/Region.h>
Peiyong Linefefaac2018-08-17 12:27:51 -070034#include <ui/Transform.h>
Dan Stoza9e56aa02015-11-02 13:00:03 -080035#include <utils/RefBase.h>
Mathias Agopian86303202012-07-24 22:46:10 -070036#include <utils/Mutex.h>
Mathias Agopian4f4f0942013-08-19 17:26:18 -070037#include <utils/String8.h>
Mathias Agopian86303202012-07-24 22:46:10 -070038#include <utils/Timers.h>
39
chaviwa76b2712017-09-20 12:02:26 -070040#include "RenderArea.h"
Mathias Agopianf4358632012-08-22 17:16:19 -070041
Mathias Agopiand8552d72012-08-04 21:39:11 -070042struct ANativeWindow;
43
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044namespace android {
45
Jesse Hall99c7dbb2013-03-14 14:29:29 -070046class DisplaySurface;
Dan Stoza9e56aa02015-11-02 13:00:03 -080047class Fence;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070048class HWComposer;
Jesse Hall9e663de2013-08-16 14:28:37 -070049class IGraphicBufferProducer;
Mathias Agopian13127d82013-03-05 17:47:11 -080050class Layer;
Mathias Agopian86303202012-07-24 22:46:10 -070051class SurfaceFlinger;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070052
David Sodmanfb95bcc2017-12-22 15:45:30 -080053struct CompositionInfo;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070054struct DisplayDeviceCreationArgs;
55struct DisplayInfo;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056
Mathias Agopian028a7572012-08-05 01:23:51 -070057class DisplayDevice : public LightRefBase<DisplayDevice>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058{
59public:
Peiyong Linfb069302018-04-25 14:34:31 -070060 constexpr static float sDefaultMinLumiance = 0.0;
61 constexpr static float sDefaultMaxLumiance = 500.0;
62
Mathias Agopian87baae12012-07-31 12:38:26 -070063 // region in layer-stack space
64 mutable Region dirtyRegion;
65 // region in screen space
Mathias Agopian87baae12012-07-31 12:38:26 -070066 Region undefinedRegion;
Jesse Hallb7a05492014-08-14 15:45:06 -070067 bool lastCompositionHadVisibleLayers;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070068
Mathias Agopian3ee454a2012-08-27 16:28:24 -070069 enum DisplayType {
70 DISPLAY_ID_INVALID = -1,
71 DISPLAY_PRIMARY = HWC_DISPLAY_PRIMARY,
72 DISPLAY_EXTERNAL = HWC_DISPLAY_EXTERNAL,
Jesse Hall9e663de2013-08-16 14:28:37 -070073 DISPLAY_VIRTUAL = HWC_DISPLAY_VIRTUAL,
74 NUM_BUILTIN_DISPLAY_TYPES = HWC_NUM_PHYSICAL_DISPLAY_TYPES,
Mathias Agopian92a979a2012-08-02 18:32:23 -070075 };
76
77 enum {
Jesse Hall01e29052013-02-19 16:13:35 -080078 NO_LAYER_STACK = 0xFFFFFFFF,
79 };
80
Lloyd Pique2eef1d22018-09-18 21:30:04 -070081 explicit DisplayDevice(DisplayDeviceCreationArgs&& args);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080082
Mathias Agopian028a7572012-08-05 01:23:51 -070083 ~DisplayDevice();
Mathias Agopian92a979a2012-08-02 18:32:23 -070084
85 // whether this is a valid object. An invalid DisplayDevice is returned
86 // when an non existing id is requested
87 bool isValid() const;
88
Jamie Gennisdd3cb842012-10-19 18:19:11 -070089 // isSecure indicates whether this display can be trusted to display
90 // secure surfaces.
91 bool isSecure() const { return mIsSecure; }
92
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080093 // Flip the front and back buffers if the back buffer is "dirty". Might
94 // be instantaneous, might involve copying the frame buffer around.
Chia-I Wub02087d2017-11-09 10:19:54 -080095 void flip() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080096
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080097 int getWidth() const;
98 int getHeight() const;
Chia-I Wua02871c2018-08-27 14:38:23 -070099 int getInstallOrientation() const { return mDisplayInstallOrientation; }
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700100
Mathias Agopian13127d82013-03-05 17:47:11 -0800101 void setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers);
102 const Vector< sp<Layer> >& getVisibleLayersSortedByZ() const;
Chia-I Wu83806892017-11-16 10:50:20 -0800103 void setLayersNeedingFences(const Vector< sp<Layer> >& layers);
104 const Vector< sp<Layer> >& getLayersNeedingFences() const;
Mathias Agopiancd60f992012-08-16 16:28:27 -0700105 Region getDirtyRegion(bool repaintEverything) const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700106
Mathias Agopian28947d72012-08-08 18:51:15 -0700107 void setLayerStack(uint32_t stack);
Michael Lentine47e45402014-07-18 15:34:25 -0700108 void setDisplaySize(const int newWidth, const int newHeight);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700109 void setProjection(int orientation, const Rect& viewport, const Rect& frame);
Mathias Agopian28947d72012-08-08 18:51:15 -0700110
Mathias Agopian1b031492012-06-20 17:51:20 -0700111 int getOrientation() const { return mOrientation; }
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700112 uint32_t getOrientationTransform() const;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700113 static uint32_t getPrimaryDisplayOrientationTransform();
Peiyong Linefefaac2018-08-17 12:27:51 -0700114 const ui::Transform& getTransform() const { return mGlobalTransform; }
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800115 const Rect getViewport() const { return mViewport; }
116 const Rect getFrame() const { return mFrame; }
Mathias Agopian766dc492012-10-30 18:08:06 -0700117 const Rect& getScissor() const { return mScissor; }
Mathias Agopianeba8c682012-09-19 23:14:45 -0700118 bool needsFiltering() const { return mNeedsFiltering; }
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700119
Mathias Agopian87baae12012-07-31 12:38:26 -0700120 uint32_t getLayerStack() const { return mLayerStack; }
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700121 int32_t getDisplayType() const { return mType; }
Chia-I Wuab0c3192017-08-01 11:29:00 -0700122 bool isPrimary() const { return mType == DISPLAY_PRIMARY; }
Dominik Laskowski281644e2018-04-19 15:47:35 -0700123 bool isVirtual() const { return mType == DISPLAY_VIRTUAL; }
Dominik Laskowski7e045462018-05-30 13:02:02 -0700124 int32_t getId() const { return mId; }
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700125 const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
Mathias Agopian87baae12012-07-31 12:38:26 -0700126
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700127 int32_t getSupportedPerFrameMetadata() const { return mSupportedPerFrameMetadata; }
128
Dan Stoza71433162014-02-04 16:22:36 -0800129 // We pass in mustRecompose so we can keep VirtualDisplaySurface's state
130 // machine happy without actually queueing a buffer if nothing has changed
131 status_t beginFrame(bool mustRecompose) const;
David Sodmanfb95bcc2017-12-22 15:45:30 -0800132 status_t prepareFrame(HWComposer& hwc, std::vector<CompositionInfo>& compositionInfo);
Chia-I Wube02ec02018-05-18 10:59:36 -0700133
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800134 bool hasWideColorGamut() const { return mHasWideColorGamut; }
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700135 // Whether h/w composer has native support for specific HDR type.
Peiyong Lin62665892018-04-16 11:07:44 -0700136 bool hasHDR10Support() const { return mHasHdr10; }
137 bool hasHLGSupport() const { return mHasHLG; }
138 bool hasDolbyVisionSupport() const { return mHasDolbyVision; }
Chia-I Wube02ec02018-05-18 10:59:36 -0700139
Peiyong Lindfde5112018-06-05 10:58:41 -0700140 // Return true if the HDR dataspace is supported but
141 // there is no corresponding color mode.
142 bool hasLegacyHdrSupport(ui::Dataspace dataspace) const;
Chia-I Wube02ec02018-05-18 10:59:36 -0700143
Peiyong Linfb069302018-04-25 14:34:31 -0700144 // The returned HdrCapabilities is the combination of HDR capabilities from
145 // hardware composer and RenderEngine. When the DisplayDevice supports wide
146 // color gamut, RenderEngine is able to simulate HDR support in Display P3
147 // color space for both PQ and HLG HDR contents. The minimum and maximum
148 // luminance will be set to sDefaultMinLumiance and sDefaultMaxLumiance
149 // respectively if hardware composer doesn't return meaningful values.
150 const HdrCapabilities& getHdrCapabilities() const { return mHdrCapabilities; }
Jesse Hall38efe862013-04-06 23:12:29 -0700151
Chia-I Wube02ec02018-05-18 10:59:36 -0700152 // Return true if intent is supported by the display.
153 bool hasRenderIntent(ui::RenderIntent intent) const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700154
Chia-I Wube02ec02018-05-18 10:59:36 -0700155 void getBestColorMode(ui::Dataspace dataspace, ui::RenderIntent intent,
156 ui::Dataspace* outDataspace, ui::ColorMode* outMode,
157 ui::RenderIntent* outIntent) const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700158
Mathias Agopianda27af92012-09-13 18:17:13 -0700159 void swapBuffers(HWComposer& hwc) const;
Jesse Hall01e29052013-02-19 16:13:35 -0800160
Mathias Agopianda27af92012-09-13 18:17:13 -0700161 // called after h/w composer has completed its set() call
Dan Stoza9e56aa02015-11-02 13:00:03 -0800162 void onSwapBuffersCompleted() const;
Mathias Agopianda27af92012-09-13 18:17:13 -0700163
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700164 Rect getBounds() const {
Mathias Agopian1b031492012-06-20 17:51:20 -0700165 return Rect(mDisplayWidth, mDisplayHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800166 }
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700167 inline Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800168
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700169 void setDisplayName(const std::string& displayName);
170 const std::string& getDisplayName() const { return mDisplayName; }
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700171
Chia-I Wuf846a352017-11-10 09:22:52 -0800172 bool makeCurrent() const;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700173 void setViewportAndProjection() const;
Mathias Agopianbae92d02012-09-28 01:00:47 -0700174
Dan Stoza9e56aa02015-11-02 13:00:03 -0800175 const sp<Fence>& getClientTargetAcquireFence() const;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800176
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700177 /* ------------------------------------------------------------------------
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700178 * Display power mode management.
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700179 */
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700180 int getPowerMode() const;
181 void setPowerMode(int mode);
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700182 bool isPoweredOn() const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700183
Peiyong Linfd997e02018-03-28 15:29:00 -0700184 ui::ColorMode getActiveColorMode() const;
185 void setActiveColorMode(ui::ColorMode mode);
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800186 ui::RenderIntent getActiveRenderIntent() const;
187 void setActiveRenderIntent(ui::RenderIntent renderIntent);
Yiwei Zhang7c64f172018-03-07 14:52:28 -0800188 android_color_transform_t getColorTransform() const;
189 void setColorTransform(const mat4& transform);
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700190 void setCompositionDataSpace(ui::Dataspace dataspace);
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800191 ui::Dataspace getCompositionDataSpace() const;
Michael Wright28f24d02016-07-12 13:30:53 -0700192
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700193 /* ------------------------------------------------------------------------
194 * Display active config management.
195 */
196 int getActiveConfig() const;
197 void setActiveConfig(int mode);
198
Jesse Hall02d86562013-03-25 14:43:23 -0700199 // release HWC resources (if any) for removable displays
200 void disconnect(HWComposer& hwc);
201
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700202 /* ------------------------------------------------------------------------
203 * Debugging
204 */
205 uint32_t getPageFlipCount() const;
Mathias Agopian74d211a2013-04-22 16:55:35 +0200206 void dump(String8& result) const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700207
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800208private:
Mathias Agopiana4912602012-07-12 14:25:33 -0700209 /*
210 * Constants, set during initialization
211 */
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700212 sp<SurfaceFlinger> mFlinger;
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700213 DisplayType mType;
Dominik Laskowski7e045462018-05-30 13:02:02 -0700214 int32_t mId;
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700215 wp<IBinder> mDisplayToken;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700216
Mathias Agopiana4912602012-07-12 14:25:33 -0700217 // ANativeWindow this display is rendering into
Mathias Agopiand8552d72012-08-04 21:39:11 -0700218 sp<ANativeWindow> mNativeWindow;
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700219 sp<DisplaySurface> mDisplaySurface;
Mathias Agopiana4912602012-07-12 14:25:33 -0700220
Peiyong Lin833074a2018-08-28 11:53:54 -0700221 std::unique_ptr<renderengine::Surface> mSurface;
Mathias Agopian1b031492012-06-20 17:51:20 -0700222 int mDisplayWidth;
223 int mDisplayHeight;
Chia-I Wua02871c2018-08-27 14:38:23 -0700224 const int mDisplayInstallOrientation;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700225 mutable uint32_t mPageFlipCount;
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700226 std::string mDisplayName;
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700227 bool mIsSecure;
Mathias Agopian03e40722012-04-26 16:11:59 -0700228
Mathias Agopiana4912602012-07-12 14:25:33 -0700229 /*
230 * Can only accessed from the main thread, these members
231 * don't need synchronization.
232 */
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700233
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700234 // list of visible layers on that display
Mathias Agopian13127d82013-03-05 17:47:11 -0800235 Vector< sp<Layer> > mVisibleLayersSortedByZ;
Chia-I Wu83806892017-11-16 10:50:20 -0800236 // list of layers needing fences
237 Vector< sp<Layer> > mLayersNeedingFences;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700238
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700239 /*
240 * Transaction state
241 */
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700242 static status_t orientationToTransfrom(int orientation,
Peiyong Linefefaac2018-08-17 12:27:51 -0700243 int w, int h, ui::Transform* tr);
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700244
Fabien Sanglardf0c53d62017-03-03 18:58:50 -0800245 // The identifier of the active layer stack for this display. Several displays
246 // can use the same layer stack: A z-ordered group of layers (sometimes called
247 // "surfaces"). Any given layer can only be on a single layer stack.
Mathias Agopian87baae12012-07-31 12:38:26 -0700248 uint32_t mLayerStack;
Fabien Sanglardf0c53d62017-03-03 18:58:50 -0800249
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700250 int mOrientation;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700251 static uint32_t sPrimaryDisplayOrientation;
Mathias Agopian766dc492012-10-30 18:08:06 -0700252 // user-provided visible area of the layer stack
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700253 Rect mViewport;
Mathias Agopian766dc492012-10-30 18:08:06 -0700254 // user-provided rectangle where mViewport gets mapped to
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700255 Rect mFrame;
Mathias Agopian766dc492012-10-30 18:08:06 -0700256 // pre-computed scissor to apply to the display
257 Rect mScissor;
Peiyong Linefefaac2018-08-17 12:27:51 -0700258 ui::Transform mGlobalTransform;
Mathias Agopianeba8c682012-09-19 23:14:45 -0700259 bool mNeedsFiltering;
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700260 // Current power mode
261 int mPowerMode;
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700262 // Current active config
263 int mActiveConfig;
Michael Wright28f24d02016-07-12 13:30:53 -0700264 // current active color mode
Chia-I Wu614e1422018-05-23 02:17:03 -0700265 ui::ColorMode mActiveColorMode = ui::ColorMode::NATIVE;
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800266 // Current active render intent.
Chia-I Wu614e1422018-05-23 02:17:03 -0700267 ui::RenderIntent mActiveRenderIntent = ui::RenderIntent::COLORIMETRIC;
268 ui::Dataspace mCompositionDataSpace = ui::Dataspace::UNKNOWN;
Yiwei Zhang7c64f172018-03-07 14:52:28 -0800269 // Current color transform
270 android_color_transform_t mColorTransform;
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -0600271
272 // Need to know if display is wide-color capable or not.
273 // Initialized by SurfaceFlinger when the DisplayDevice is created.
274 // Fed to RenderEngine during composition.
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800275 bool mHasWideColorGamut;
276 bool mHasHdr10;
Peiyong Lin62665892018-04-16 11:07:44 -0700277 bool mHasHLG;
278 bool mHasDolbyVision;
Peiyong Linfb069302018-04-25 14:34:31 -0700279 HdrCapabilities mHdrCapabilities;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700280 const int32_t mSupportedPerFrameMetadata;
Chia-I Wube02ec02018-05-18 10:59:36 -0700281
282 // Mappings from desired Dataspace/RenderIntent to the supported
283 // Dataspace/ColorMode/RenderIntent.
284 using ColorModeKey = uint64_t;
285 struct ColorModeValue {
286 ui::Dataspace dataspace;
287 ui::ColorMode colorMode;
288 ui::RenderIntent renderIntent;
289 };
290
291 static ColorModeKey getColorModeKey(ui::Dataspace dataspace, ui::RenderIntent intent) {
292 return (static_cast<uint64_t>(dataspace) << 32) | static_cast<uint32_t>(intent);
293 }
294 void populateColorModes(
295 const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>>& hwcColorModes);
296 void addColorMode(
297 const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>>& hwcColorModes,
298 const ui::ColorMode mode, const ui::RenderIntent intent);
299
300 std::unordered_map<ColorModeKey, ColorModeValue> mColorModes;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800301};
302
Irvelffc9efc2016-07-27 15:16:37 -0700303struct DisplayDeviceState {
Dominik Laskowski663bd282018-04-19 15:26:54 -0700304 bool isVirtual() const { return type >= DisplayDevice::DISPLAY_VIRTUAL; }
Irvelffc9efc2016-07-27 15:16:37 -0700305
Dominik Laskowski663bd282018-04-19 15:26:54 -0700306 int32_t sequenceId = sNextSequenceId++;
Irvelffc9efc2016-07-27 15:16:37 -0700307 DisplayDevice::DisplayType type = DisplayDevice::DISPLAY_ID_INVALID;
308 sp<IGraphicBufferProducer> surface;
309 uint32_t layerStack = DisplayDevice::NO_LAYER_STACK;
310 Rect viewport;
311 Rect frame;
312 uint8_t orientation = 0;
313 uint32_t width = 0;
314 uint32_t height = 0;
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700315 std::string displayName;
Irvelffc9efc2016-07-27 15:16:37 -0700316 bool isSecure = false;
Dominik Laskowski663bd282018-04-19 15:26:54 -0700317
318private:
319 static std::atomic<int32_t> sNextSequenceId;
Irvelffc9efc2016-07-27 15:16:37 -0700320};
321
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700322struct DisplayDeviceCreationArgs {
323 // We use a constructor to ensure some of the values are set, without
324 // assuming a default value.
325 DisplayDeviceCreationArgs(const sp<SurfaceFlinger>& flinger, const wp<IBinder>& displayToken,
326 DisplayDevice::DisplayType type, int32_t id);
327
328 const sp<SurfaceFlinger> flinger;
329 const wp<IBinder> displayToken;
330 const DisplayDevice::DisplayType type;
331 const int32_t id;
332
333 bool isSecure{false};
334 sp<ANativeWindow> nativeWindow;
335 sp<DisplaySurface> displaySurface;
336 std::unique_ptr<renderengine::Surface> renderSurface;
337 int displayWidth{0};
338 int displayHeight{0};
339 int displayInstallOrientation{DisplayState::eOrientationDefault};
340 bool hasWideColorGamut{false};
341 HdrCapabilities hdrCapabilities;
342 int32_t supportedPerFrameMetadata{0};
343 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> hwcColorModes;
344 int initialPowerMode{HWC_POWER_MODE_NORMAL};
345};
346
chaviwa76b2712017-09-20 12:02:26 -0700347class DisplayRenderArea : public RenderArea {
348public:
349 DisplayRenderArea(const sp<const DisplayDevice> device,
Chia-I Wuc80dcbb2018-08-24 15:34:02 -0700350 ui::Transform::orientation_flags rotation = ui::Transform::ROT_0)
Chia-I Wu9d1abea2018-08-23 13:44:43 -0700351 : DisplayRenderArea(device, device->getBounds(), device->getWidth(), device->getHeight(),
chaviwa76b2712017-09-20 12:02:26 -0700352 rotation) {}
Chia-I Wu9d1abea2018-08-23 13:44:43 -0700353 DisplayRenderArea(const sp<const DisplayDevice> device, Rect sourceCrop, uint32_t reqWidth,
Chia-I Wuc80dcbb2018-08-24 15:34:02 -0700354 uint32_t reqHeight, ui::Transform::orientation_flags rotation)
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700355 : RenderArea(reqWidth, reqHeight, CaptureFill::OPAQUE,
356 getDisplayRotation(rotation, device->getInstallOrientation())),
357 mDevice(device),
358 mSourceCrop(sourceCrop) {}
chaviwa76b2712017-09-20 12:02:26 -0700359
Peiyong Linefefaac2018-08-17 12:27:51 -0700360 const ui::Transform& getTransform() const override { return mDevice->getTransform(); }
chaviwa76b2712017-09-20 12:02:26 -0700361 Rect getBounds() const override { return mDevice->getBounds(); }
362 int getHeight() const override { return mDevice->getHeight(); }
363 int getWidth() const override { return mDevice->getWidth(); }
364 bool isSecure() const override { return mDevice->isSecure(); }
Chia-I Wu5f6664c2018-08-28 11:01:44 -0700365
366 bool needsFiltering() const override {
Chia-I Wu8730ba82018-08-29 09:25:59 -0700367 // check if the projection from the logical display to the physical
368 // display needs filtering
Chia-I Wu5f6664c2018-08-28 11:01:44 -0700369 if (mDevice->needsFiltering()) {
370 return true;
371 }
372
Chia-I Wu8730ba82018-08-29 09:25:59 -0700373 // check if the projection from the logical render area (i.e., the
374 // physical display) to the physical render area requires filtering
Chia-I Wu5f6664c2018-08-28 11:01:44 -0700375 const Rect sourceCrop = getSourceCrop();
376 int width = sourceCrop.width();
377 int height = sourceCrop.height();
378 if (getRotationFlags() & ui::Transform::ROT_90) {
379 std::swap(width, height);
380 }
381 return width != getReqWidth() || height != getReqHeight();
382 }
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700383
384 Rect getSourceCrop() const override {
Chia-I Wu8730ba82018-08-29 09:25:59 -0700385 // use the (projected) logical display viewport by default
386 if (mSourceCrop.isEmpty()) {
387 return mDevice->getScissor();
388 }
389
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700390 const int orientation = mDevice->getInstallOrientation();
391 if (orientation == DisplayState::eOrientationDefault) {
392 return mSourceCrop;
393 }
394
Chia-I Wu8730ba82018-08-29 09:25:59 -0700395 // Install orientation is transparent to the callers. Apply it now.
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700396 uint32_t flags = 0x00;
397 switch (orientation) {
398 case DisplayState::eOrientation90:
399 flags = ui::Transform::ROT_90;
400 break;
401 case DisplayState::eOrientation180:
402 flags = ui::Transform::ROT_180;
403 break;
404 case DisplayState::eOrientation270:
405 flags = ui::Transform::ROT_270;
406 break;
407 }
408 ui::Transform tr;
409 tr.set(flags, getWidth(), getHeight());
410 return tr.transform(mSourceCrop);
411 }
chaviwa76b2712017-09-20 12:02:26 -0700412
413private:
Chia-I Wu8730ba82018-08-29 09:25:59 -0700414 // Install orientation is transparent to the callers. We need to cancel
415 // it out by modifying rotation flags.
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700416 static ui::Transform::orientation_flags getDisplayRotation(
417 ui::Transform::orientation_flags rotation, int orientation) {
418 if (orientation == DisplayState::eOrientationDefault) {
419 return rotation;
420 }
421
422 // convert hw orientation into flag presentation
423 // here inverse transform needed
424 uint8_t hw_rot_90 = 0x00;
425 uint8_t hw_flip_hv = 0x00;
426 switch (orientation) {
427 case DisplayState::eOrientation90:
428 hw_rot_90 = ui::Transform::ROT_90;
429 hw_flip_hv = ui::Transform::ROT_180;
430 break;
431 case DisplayState::eOrientation180:
432 hw_flip_hv = ui::Transform::ROT_180;
433 break;
434 case DisplayState::eOrientation270:
435 hw_rot_90 = ui::Transform::ROT_90;
436 break;
437 }
438
439 // transform flags operation
440 // 1) flip H V if both have ROT_90 flag
441 // 2) XOR these flags
442 uint8_t rotation_rot_90 = rotation & ui::Transform::ROT_90;
443 uint8_t rotation_flip_hv = rotation & ui::Transform::ROT_180;
444 if (rotation_rot_90 & hw_rot_90) {
445 rotation_flip_hv = (~rotation_flip_hv) & ui::Transform::ROT_180;
446 }
447
448 return static_cast<ui::Transform::orientation_flags>(
449 (rotation_rot_90 ^ hw_rot_90) | (rotation_flip_hv ^ hw_flip_hv));
450 }
451
chaviwa76b2712017-09-20 12:02:26 -0700452 const sp<const DisplayDevice> mDevice;
453 const Rect mSourceCrop;
454};
455
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800456}; // namespace android
457
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700458#endif // ANDROID_DISPLAY_DEVICE_H