blob: f7ffffdcec68d5013d49b5c1bed3b4e62082e5da [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 Hall646f5412014-08-07 22:19:07 -070046struct DisplayInfo;
Jesse Hall99c7dbb2013-03-14 14:29:29 -070047class DisplaySurface;
Dan Stoza9e56aa02015-11-02 13:00:03 -080048class Fence;
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;
Mathias Agopianda27af92012-09-13 18:17:13 -070052class HWComposer;
David Sodmanfb95bcc2017-12-22 15:45:30 -080053struct CompositionInfo;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054
Mathias Agopian028a7572012-08-05 01:23:51 -070055class DisplayDevice : public LightRefBase<DisplayDevice>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056{
57public:
Peiyong Linfb069302018-04-25 14:34:31 -070058 constexpr static float sDefaultMinLumiance = 0.0;
59 constexpr static float sDefaultMaxLumiance = 500.0;
60
Mathias Agopian87baae12012-07-31 12:38:26 -070061 // region in layer-stack space
62 mutable Region dirtyRegion;
63 // region in screen space
Mathias Agopian87baae12012-07-31 12:38:26 -070064 Region undefinedRegion;
Jesse Hallb7a05492014-08-14 15:45:06 -070065 bool lastCompositionHadVisibleLayers;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070066
Mathias Agopian3ee454a2012-08-27 16:28:24 -070067 enum DisplayType {
68 DISPLAY_ID_INVALID = -1,
69 DISPLAY_PRIMARY = HWC_DISPLAY_PRIMARY,
70 DISPLAY_EXTERNAL = HWC_DISPLAY_EXTERNAL,
Jesse Hall9e663de2013-08-16 14:28:37 -070071 DISPLAY_VIRTUAL = HWC_DISPLAY_VIRTUAL,
72 NUM_BUILTIN_DISPLAY_TYPES = HWC_NUM_PHYSICAL_DISPLAY_TYPES,
Mathias Agopian92a979a2012-08-02 18:32:23 -070073 };
74
75 enum {
Jesse Hall01e29052013-02-19 16:13:35 -080076 NO_LAYER_STACK = 0xFFFFFFFF,
77 };
78
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -060079 // clang-format off
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070080 DisplayDevice(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080081 const sp<SurfaceFlinger>& flinger,
Jamie Gennisdd3cb842012-10-19 18:19:11 -070082 DisplayType type,
Dominik Laskowski7e045462018-05-30 13:02:02 -070083 int32_t id,
Jamie Gennisdd3cb842012-10-19 18:19:11 -070084 bool isSecure,
85 const wp<IBinder>& displayToken,
Lloyd Pique09594832018-01-22 17:48:03 -080086 const sp<ANativeWindow>& nativeWindow,
Jesse Hall99c7dbb2013-03-14 14:29:29 -070087 const sp<DisplaySurface>& displaySurface,
Lloyd Pique09594832018-01-22 17:48:03 -080088 std::unique_ptr<RE::Surface> renderSurface,
89 int displayWidth,
90 int displayHeight,
Chia-I Wua02871c2018-08-27 14:38:23 -070091 int displayInstallOrientation,
Peiyong Lindd9b2ae2018-03-01 16:22:45 -080092 bool hasWideColorGamut,
Peiyong Lin62665892018-04-16 11:07:44 -070093 const HdrCapabilities& hdrCapabilities,
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -070094 const int32_t supportedPerFrameMetadata,
Chia-I Wube02ec02018-05-18 10:59:36 -070095 const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>>& hwcColorModes,
Lloyd Pique09594832018-01-22 17:48:03 -080096 int initialPowerMode);
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -060097 // clang-format on
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080098
Mathias Agopian028a7572012-08-05 01:23:51 -070099 ~DisplayDevice();
Mathias Agopian92a979a2012-08-02 18:32:23 -0700100
101 // whether this is a valid object. An invalid DisplayDevice is returned
102 // when an non existing id is requested
103 bool isValid() const;
104
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700105 // isSecure indicates whether this display can be trusted to display
106 // secure surfaces.
107 bool isSecure() const { return mIsSecure; }
108
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800109 // Flip the front and back buffers if the back buffer is "dirty". Might
110 // be instantaneous, might involve copying the frame buffer around.
Chia-I Wub02087d2017-11-09 10:19:54 -0800111 void flip() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800112
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800113 int getWidth() const;
114 int getHeight() const;
Chia-I Wua02871c2018-08-27 14:38:23 -0700115 int getInstallOrientation() const { return mDisplayInstallOrientation; }
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700116
Mathias Agopian13127d82013-03-05 17:47:11 -0800117 void setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers);
118 const Vector< sp<Layer> >& getVisibleLayersSortedByZ() const;
Chia-I Wu83806892017-11-16 10:50:20 -0800119 void setLayersNeedingFences(const Vector< sp<Layer> >& layers);
120 const Vector< sp<Layer> >& getLayersNeedingFences() const;
Mathias Agopiancd60f992012-08-16 16:28:27 -0700121 Region getDirtyRegion(bool repaintEverything) const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700122
Mathias Agopian28947d72012-08-08 18:51:15 -0700123 void setLayerStack(uint32_t stack);
Michael Lentine47e45402014-07-18 15:34:25 -0700124 void setDisplaySize(const int newWidth, const int newHeight);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700125 void setProjection(int orientation, const Rect& viewport, const Rect& frame);
Mathias Agopian28947d72012-08-08 18:51:15 -0700126
Mathias Agopian1b031492012-06-20 17:51:20 -0700127 int getOrientation() const { return mOrientation; }
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700128 uint32_t getOrientationTransform() const;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700129 static uint32_t getPrimaryDisplayOrientationTransform();
Peiyong Linefefaac2018-08-17 12:27:51 -0700130 const ui::Transform& getTransform() const { return mGlobalTransform; }
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800131 const Rect getViewport() const { return mViewport; }
132 const Rect getFrame() const { return mFrame; }
Mathias Agopian766dc492012-10-30 18:08:06 -0700133 const Rect& getScissor() const { return mScissor; }
Mathias Agopianeba8c682012-09-19 23:14:45 -0700134 bool needsFiltering() const { return mNeedsFiltering; }
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700135
Mathias Agopian87baae12012-07-31 12:38:26 -0700136 uint32_t getLayerStack() const { return mLayerStack; }
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700137 int32_t getDisplayType() const { return mType; }
Chia-I Wuab0c3192017-08-01 11:29:00 -0700138 bool isPrimary() const { return mType == DISPLAY_PRIMARY; }
Dominik Laskowski281644e2018-04-19 15:47:35 -0700139 bool isVirtual() const { return mType == DISPLAY_VIRTUAL; }
Dominik Laskowski7e045462018-05-30 13:02:02 -0700140 int32_t getId() const { return mId; }
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700141 const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
Mathias Agopian87baae12012-07-31 12:38:26 -0700142
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700143 int32_t getSupportedPerFrameMetadata() const { return mSupportedPerFrameMetadata; }
144
Dan Stoza71433162014-02-04 16:22:36 -0800145 // We pass in mustRecompose so we can keep VirtualDisplaySurface's state
146 // machine happy without actually queueing a buffer if nothing has changed
147 status_t beginFrame(bool mustRecompose) const;
David Sodmanfb95bcc2017-12-22 15:45:30 -0800148 status_t prepareFrame(HWComposer& hwc, std::vector<CompositionInfo>& compositionInfo);
Chia-I Wube02ec02018-05-18 10:59:36 -0700149
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800150 bool hasWideColorGamut() const { return mHasWideColorGamut; }
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700151 // Whether h/w composer has native support for specific HDR type.
Peiyong Lin62665892018-04-16 11:07:44 -0700152 bool hasHDR10Support() const { return mHasHdr10; }
153 bool hasHLGSupport() const { return mHasHLG; }
154 bool hasDolbyVisionSupport() const { return mHasDolbyVision; }
Chia-I Wube02ec02018-05-18 10:59:36 -0700155
Peiyong Lindfde5112018-06-05 10:58:41 -0700156 // Return true if the HDR dataspace is supported but
157 // there is no corresponding color mode.
158 bool hasLegacyHdrSupport(ui::Dataspace dataspace) const;
Chia-I Wube02ec02018-05-18 10:59:36 -0700159
Peiyong Linfb069302018-04-25 14:34:31 -0700160 // The returned HdrCapabilities is the combination of HDR capabilities from
161 // hardware composer and RenderEngine. When the DisplayDevice supports wide
162 // color gamut, RenderEngine is able to simulate HDR support in Display P3
163 // color space for both PQ and HLG HDR contents. The minimum and maximum
164 // luminance will be set to sDefaultMinLumiance and sDefaultMaxLumiance
165 // respectively if hardware composer doesn't return meaningful values.
166 const HdrCapabilities& getHdrCapabilities() const { return mHdrCapabilities; }
Jesse Hall38efe862013-04-06 23:12:29 -0700167
Chia-I Wube02ec02018-05-18 10:59:36 -0700168 // Return true if intent is supported by the display.
169 bool hasRenderIntent(ui::RenderIntent intent) const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700170
Chia-I Wube02ec02018-05-18 10:59:36 -0700171 void getBestColorMode(ui::Dataspace dataspace, ui::RenderIntent intent,
172 ui::Dataspace* outDataspace, ui::ColorMode* outMode,
173 ui::RenderIntent* outIntent) const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700174
Mathias Agopianda27af92012-09-13 18:17:13 -0700175 void swapBuffers(HWComposer& hwc) const;
Jesse Hall01e29052013-02-19 16:13:35 -0800176
Mathias Agopianda27af92012-09-13 18:17:13 -0700177 // called after h/w composer has completed its set() call
Dan Stoza9e56aa02015-11-02 13:00:03 -0800178 void onSwapBuffersCompleted() const;
Mathias Agopianda27af92012-09-13 18:17:13 -0700179
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700180 Rect getBounds() const {
Mathias Agopian1b031492012-06-20 17:51:20 -0700181 return Rect(mDisplayWidth, mDisplayHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800182 }
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700183 inline Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800184
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700185 void setDisplayName(const std::string& displayName);
186 const std::string& getDisplayName() const { return mDisplayName; }
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700187
Chia-I Wuf846a352017-11-10 09:22:52 -0800188 bool makeCurrent() const;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700189 void setViewportAndProjection() const;
Mathias Agopianbae92d02012-09-28 01:00:47 -0700190
Dan Stoza9e56aa02015-11-02 13:00:03 -0800191 const sp<Fence>& getClientTargetAcquireFence() const;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800192
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700193 /* ------------------------------------------------------------------------
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700194 * Display power mode management.
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700195 */
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700196 int getPowerMode() const;
197 void setPowerMode(int mode);
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700198 bool isPoweredOn() const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700199
Peiyong Linfd997e02018-03-28 15:29:00 -0700200 ui::ColorMode getActiveColorMode() const;
201 void setActiveColorMode(ui::ColorMode mode);
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800202 ui::RenderIntent getActiveRenderIntent() const;
203 void setActiveRenderIntent(ui::RenderIntent renderIntent);
Yiwei Zhang7c64f172018-03-07 14:52:28 -0800204 android_color_transform_t getColorTransform() const;
205 void setColorTransform(const mat4& transform);
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700206 void setCompositionDataSpace(ui::Dataspace dataspace);
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800207 ui::Dataspace getCompositionDataSpace() const;
Michael Wright28f24d02016-07-12 13:30:53 -0700208
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700209 /* ------------------------------------------------------------------------
210 * Display active config management.
211 */
212 int getActiveConfig() const;
213 void setActiveConfig(int mode);
214
Jesse Hall02d86562013-03-25 14:43:23 -0700215 // release HWC resources (if any) for removable displays
216 void disconnect(HWComposer& hwc);
217
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700218 /* ------------------------------------------------------------------------
219 * Debugging
220 */
221 uint32_t getPageFlipCount() const;
Mathias Agopian74d211a2013-04-22 16:55:35 +0200222 void dump(String8& result) const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700223
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800224private:
Mathias Agopiana4912602012-07-12 14:25:33 -0700225 /*
226 * Constants, set during initialization
227 */
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700228 sp<SurfaceFlinger> mFlinger;
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700229 DisplayType mType;
Dominik Laskowski7e045462018-05-30 13:02:02 -0700230 int32_t mId;
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700231 wp<IBinder> mDisplayToken;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700232
Mathias Agopiana4912602012-07-12 14:25:33 -0700233 // ANativeWindow this display is rendering into
Mathias Agopiand8552d72012-08-04 21:39:11 -0700234 sp<ANativeWindow> mNativeWindow;
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700235 sp<DisplaySurface> mDisplaySurface;
Mathias Agopiana4912602012-07-12 14:25:33 -0700236
Lloyd Pique144e1162017-12-20 16:44:52 -0800237 std::unique_ptr<RE::Surface> mSurface;
Mathias Agopian1b031492012-06-20 17:51:20 -0700238 int mDisplayWidth;
239 int mDisplayHeight;
Chia-I Wua02871c2018-08-27 14:38:23 -0700240 const int mDisplayInstallOrientation;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700241 mutable uint32_t mPageFlipCount;
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700242 std::string mDisplayName;
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700243 bool mIsSecure;
Mathias Agopian03e40722012-04-26 16:11:59 -0700244
Mathias Agopiana4912602012-07-12 14:25:33 -0700245 /*
246 * Can only accessed from the main thread, these members
247 * don't need synchronization.
248 */
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700249
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700250 // list of visible layers on that display
Mathias Agopian13127d82013-03-05 17:47:11 -0800251 Vector< sp<Layer> > mVisibleLayersSortedByZ;
Chia-I Wu83806892017-11-16 10:50:20 -0800252 // list of layers needing fences
253 Vector< sp<Layer> > mLayersNeedingFences;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700254
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700255 /*
256 * Transaction state
257 */
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700258 static status_t orientationToTransfrom(int orientation,
Peiyong Linefefaac2018-08-17 12:27:51 -0700259 int w, int h, ui::Transform* tr);
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700260
Fabien Sanglardf0c53d62017-03-03 18:58:50 -0800261 // The identifier of the active layer stack for this display. Several displays
262 // can use the same layer stack: A z-ordered group of layers (sometimes called
263 // "surfaces"). Any given layer can only be on a single layer stack.
Mathias Agopian87baae12012-07-31 12:38:26 -0700264 uint32_t mLayerStack;
Fabien Sanglardf0c53d62017-03-03 18:58:50 -0800265
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700266 int mOrientation;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700267 static uint32_t sPrimaryDisplayOrientation;
Mathias Agopian766dc492012-10-30 18:08:06 -0700268 // user-provided visible area of the layer stack
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700269 Rect mViewport;
Mathias Agopian766dc492012-10-30 18:08:06 -0700270 // user-provided rectangle where mViewport gets mapped to
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700271 Rect mFrame;
Mathias Agopian766dc492012-10-30 18:08:06 -0700272 // pre-computed scissor to apply to the display
273 Rect mScissor;
Peiyong Linefefaac2018-08-17 12:27:51 -0700274 ui::Transform mGlobalTransform;
Mathias Agopianeba8c682012-09-19 23:14:45 -0700275 bool mNeedsFiltering;
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700276 // Current power mode
277 int mPowerMode;
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700278 // Current active config
279 int mActiveConfig;
Michael Wright28f24d02016-07-12 13:30:53 -0700280 // current active color mode
Chia-I Wu614e1422018-05-23 02:17:03 -0700281 ui::ColorMode mActiveColorMode = ui::ColorMode::NATIVE;
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800282 // Current active render intent.
Chia-I Wu614e1422018-05-23 02:17:03 -0700283 ui::RenderIntent mActiveRenderIntent = ui::RenderIntent::COLORIMETRIC;
284 ui::Dataspace mCompositionDataSpace = ui::Dataspace::UNKNOWN;
Yiwei Zhang7c64f172018-03-07 14:52:28 -0800285 // Current color transform
286 android_color_transform_t mColorTransform;
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -0600287
288 // Need to know if display is wide-color capable or not.
289 // Initialized by SurfaceFlinger when the DisplayDevice is created.
290 // Fed to RenderEngine during composition.
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800291 bool mHasWideColorGamut;
292 bool mHasHdr10;
Peiyong Lin62665892018-04-16 11:07:44 -0700293 bool mHasHLG;
294 bool mHasDolbyVision;
Peiyong Linfb069302018-04-25 14:34:31 -0700295 HdrCapabilities mHdrCapabilities;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700296 const int32_t mSupportedPerFrameMetadata;
Chia-I Wube02ec02018-05-18 10:59:36 -0700297
298 // Mappings from desired Dataspace/RenderIntent to the supported
299 // Dataspace/ColorMode/RenderIntent.
300 using ColorModeKey = uint64_t;
301 struct ColorModeValue {
302 ui::Dataspace dataspace;
303 ui::ColorMode colorMode;
304 ui::RenderIntent renderIntent;
305 };
306
307 static ColorModeKey getColorModeKey(ui::Dataspace dataspace, ui::RenderIntent intent) {
308 return (static_cast<uint64_t>(dataspace) << 32) | static_cast<uint32_t>(intent);
309 }
310 void populateColorModes(
311 const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>>& hwcColorModes);
312 void addColorMode(
313 const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>>& hwcColorModes,
314 const ui::ColorMode mode, const ui::RenderIntent intent);
315
316 std::unordered_map<ColorModeKey, ColorModeValue> mColorModes;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800317};
318
Irvelffc9efc2016-07-27 15:16:37 -0700319struct DisplayDeviceState {
Dominik Laskowski663bd282018-04-19 15:26:54 -0700320 bool isVirtual() const { return type >= DisplayDevice::DISPLAY_VIRTUAL; }
Irvelffc9efc2016-07-27 15:16:37 -0700321
Dominik Laskowski663bd282018-04-19 15:26:54 -0700322 int32_t sequenceId = sNextSequenceId++;
Irvelffc9efc2016-07-27 15:16:37 -0700323 DisplayDevice::DisplayType type = DisplayDevice::DISPLAY_ID_INVALID;
324 sp<IGraphicBufferProducer> surface;
325 uint32_t layerStack = DisplayDevice::NO_LAYER_STACK;
326 Rect viewport;
327 Rect frame;
328 uint8_t orientation = 0;
329 uint32_t width = 0;
330 uint32_t height = 0;
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700331 std::string displayName;
Irvelffc9efc2016-07-27 15:16:37 -0700332 bool isSecure = false;
Dominik Laskowski663bd282018-04-19 15:26:54 -0700333
334private:
335 static std::atomic<int32_t> sNextSequenceId;
Irvelffc9efc2016-07-27 15:16:37 -0700336};
337
chaviwa76b2712017-09-20 12:02:26 -0700338class DisplayRenderArea : public RenderArea {
339public:
340 DisplayRenderArea(const sp<const DisplayDevice> device,
Chia-I Wuc80dcbb2018-08-24 15:34:02 -0700341 ui::Transform::orientation_flags rotation = ui::Transform::ROT_0)
Chia-I Wu9d1abea2018-08-23 13:44:43 -0700342 : DisplayRenderArea(device, device->getBounds(), device->getWidth(), device->getHeight(),
chaviwa76b2712017-09-20 12:02:26 -0700343 rotation) {}
Chia-I Wu9d1abea2018-08-23 13:44:43 -0700344 DisplayRenderArea(const sp<const DisplayDevice> device, Rect sourceCrop, uint32_t reqWidth,
Chia-I Wuc80dcbb2018-08-24 15:34:02 -0700345 uint32_t reqHeight, ui::Transform::orientation_flags rotation)
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700346 : RenderArea(reqWidth, reqHeight, CaptureFill::OPAQUE,
347 getDisplayRotation(rotation, device->getInstallOrientation())),
348 mDevice(device),
349 mSourceCrop(sourceCrop) {}
chaviwa76b2712017-09-20 12:02:26 -0700350
Peiyong Linefefaac2018-08-17 12:27:51 -0700351 const ui::Transform& getTransform() const override { return mDevice->getTransform(); }
chaviwa76b2712017-09-20 12:02:26 -0700352 Rect getBounds() const override { return mDevice->getBounds(); }
353 int getHeight() const override { return mDevice->getHeight(); }
354 int getWidth() const override { return mDevice->getWidth(); }
355 bool isSecure() const override { return mDevice->isSecure(); }
Chia-I Wu5f6664c2018-08-28 11:01:44 -0700356
357 bool needsFiltering() const override {
358 if (mDevice->needsFiltering()) {
359 return true;
360 }
361
362 const Rect sourceCrop = getSourceCrop();
363 int width = sourceCrop.width();
364 int height = sourceCrop.height();
365 if (getRotationFlags() & ui::Transform::ROT_90) {
366 std::swap(width, height);
367 }
368 return width != getReqWidth() || height != getReqHeight();
369 }
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700370
371 Rect getSourceCrop() const override {
372 const int orientation = mDevice->getInstallOrientation();
373 if (orientation == DisplayState::eOrientationDefault) {
374 return mSourceCrop;
375 }
376
377 uint32_t flags = 0x00;
378 switch (orientation) {
379 case DisplayState::eOrientation90:
380 flags = ui::Transform::ROT_90;
381 break;
382 case DisplayState::eOrientation180:
383 flags = ui::Transform::ROT_180;
384 break;
385 case DisplayState::eOrientation270:
386 flags = ui::Transform::ROT_270;
387 break;
388 }
389 ui::Transform tr;
390 tr.set(flags, getWidth(), getHeight());
391 return tr.transform(mSourceCrop);
392 }
chaviwa76b2712017-09-20 12:02:26 -0700393
394private:
Chia-I Wuf2aa3112018-08-27 14:54:37 -0700395 static ui::Transform::orientation_flags getDisplayRotation(
396 ui::Transform::orientation_flags rotation, int orientation) {
397 if (orientation == DisplayState::eOrientationDefault) {
398 return rotation;
399 }
400
401 // convert hw orientation into flag presentation
402 // here inverse transform needed
403 uint8_t hw_rot_90 = 0x00;
404 uint8_t hw_flip_hv = 0x00;
405 switch (orientation) {
406 case DisplayState::eOrientation90:
407 hw_rot_90 = ui::Transform::ROT_90;
408 hw_flip_hv = ui::Transform::ROT_180;
409 break;
410 case DisplayState::eOrientation180:
411 hw_flip_hv = ui::Transform::ROT_180;
412 break;
413 case DisplayState::eOrientation270:
414 hw_rot_90 = ui::Transform::ROT_90;
415 break;
416 }
417
418 // transform flags operation
419 // 1) flip H V if both have ROT_90 flag
420 // 2) XOR these flags
421 uint8_t rotation_rot_90 = rotation & ui::Transform::ROT_90;
422 uint8_t rotation_flip_hv = rotation & ui::Transform::ROT_180;
423 if (rotation_rot_90 & hw_rot_90) {
424 rotation_flip_hv = (~rotation_flip_hv) & ui::Transform::ROT_180;
425 }
426
427 return static_cast<ui::Transform::orientation_flags>(
428 (rotation_rot_90 ^ hw_rot_90) | (rotation_flip_hv ^ hw_flip_hv));
429 }
430
chaviwa76b2712017-09-20 12:02:26 -0700431 const sp<const DisplayDevice> mDevice;
432 const Rect mSourceCrop;
433};
434
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800435}; // namespace android
436
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700437#endif // ANDROID_DISPLAY_DEVICE_H