blob: 767a3b3850350328d453ad06b7ca5cd8368f9f12 [file] [log] [blame]
David Sodmanaf8bab12017-12-14 15:30:55 -08001/*
2 * Copyright (C) 2018 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
17#pragma once
18
19#include <stdint.h>
20#include <sys/types.h>
21
David Sodman4b7c4bc2017-11-17 12:13:59 -080022#include <gui/HdrMetadata.h>
David Sodmanaf8bab12017-12-14 15:30:55 -080023#include <ui/Region.h>
24
25#include "SurfaceFlinger.h"
26
27#include "DisplayHardware/HWComposer.h"
28#include "DisplayHardware/HWComposerBufferCache.h"
29#include "RenderEngine/Mesh.h"
David Sodman8725e812018-01-06 15:18:35 -080030#include "RenderEngine/Texture.h"
David Sodmanaf8bab12017-12-14 15:30:55 -080031
32namespace android {
33
David Sodmanb8af7922017-12-21 15:17:55 -080034class LayerBE;
35
David Sodman5d89c1d2017-12-14 15:54:51 -080036class LayerContainer
37{
38 public:
39 LayerContainer(HWComposer* hwc, int32_t hwcId) : mHwc(hwc), mHwcId(hwcId) {
40 mLayer = hwc->createLayer(hwcId);
41 }
42
43 ~LayerContainer() {
44 mHwc->destroyLayer(mHwcId, mLayer);
45 }
46
47 HWC2::Layer* operator->() {
48 return mLayer;
49 }
50
51 operator HWC2::Layer*const () const {
52 return mLayer;
53 }
54
55 private:
56 HWComposer* mHwc;
57 int32_t mHwcId;
58 HWC2::Layer* mLayer;
59};
60
David Sodmanaf8bab12017-12-14 15:30:55 -080061struct CompositionInfo {
David Sodmanb8af7922017-12-21 15:17:55 -080062 std::string layerName;
David Sodmanaf8bab12017-12-14 15:30:55 -080063 HWC2::Composition compositionType;
64 sp<GraphicBuffer> mBuffer = nullptr;
65 int mBufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
David Sodmanb8af7922017-12-21 15:17:55 -080066 LayerBE* layer = nullptr;
David Sodman56912832017-11-28 10:27:38 -080067 bool updateBuffer = false;
David Sodmanaf8bab12017-12-14 15:30:55 -080068 struct {
David Sodman5d89c1d2017-12-14 15:54:51 -080069 std::shared_ptr<LayerContainer> hwcLayer;
David Sodman56912832017-11-28 10:27:38 -080070 bool skipGeometry = true;
David Sodmanaf8bab12017-12-14 15:30:55 -080071 int32_t hwid = -1;
72 sp<Fence> fence;
73 HWC2::BlendMode blendMode = HWC2::BlendMode::Invalid;
74 Rect displayFrame;
75 float alpha;
76 FloatRect sourceCrop;
77 HWC2::Transform transform = HWC2::Transform::None;
78 int z;
79 int type;
80 int appId;
81 Region visibleRegion;
82 Region surfaceDamage;
83 sp<NativeHandle> sidebandStream;
84 android_dataspace dataspace;
85 hwc_color_t color;
David Sodman4b7c4bc2017-11-17 12:13:59 -080086 HdrMetadata hdrMetadata;
David Sodmanaf8bab12017-12-14 15:30:55 -080087 } hwc;
88 struct {
89 Mesh* mesh;
David Sodman8725e812018-01-06 15:18:35 -080090 bool blackoutLayer = false;
91 bool clearArea = false;
92 bool preMultipliedAlpha = false;
93 bool opaque = false;
David Sodmandc5e0622018-01-05 23:10:57 -080094 bool disableTexture = false;
David Sodman8725e812018-01-06 15:18:35 -080095 half4 color;
96 Texture texture;
97 bool useIdentityTransform = false;
David Sodmandc5e0622018-01-05 23:10:57 -080098 bool Y410BT2020 = false;
David Sodman839d41b2017-12-31 18:44:09 -080099 } re;
David Sodmanb8af7922017-12-21 15:17:55 -0800100
101 void dump(const char* tag) const;
102 void dumpHwc(const char* tag) const;
103 void dumpRe(const char* tag) const;
David Sodmanaf8bab12017-12-14 15:30:55 -0800104};
105
106class LayerBE {
107public:
David Sodmanb8af7922017-12-21 15:17:55 -0800108 friend class Layer;
109 friend class BufferLayer;
110 friend class ColorLayer;
111 friend class SurfaceFlinger;
David Sodmanaf8bab12017-12-14 15:30:55 -0800112
David Sodman2b727ac2017-12-21 14:28:08 -0800113 LayerBE(Layer* layer, std::string layerName);
David Sodmanb8af7922017-12-21 15:17:55 -0800114
115 void onLayerDisplayed(const sp<Fence>& releaseFence);
116 Mesh& getMesh() { return mMesh; }
117
118private:
119 Layer*const mLayer;
David Sodmanaf8bab12017-12-14 15:30:55 -0800120 // The mesh used to draw the layer in GLES composition mode
121 Mesh mMesh;
122
123 // HWC items, accessed from the main thread
124 struct HWCInfo {
125 HWCInfo()
126 : hwc(nullptr),
127 layer(nullptr),
128 forceClientComposition(false),
129 compositionType(HWC2::Composition::Invalid),
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800130 clearClientTarget(false),
131 transform(HWC2::Transform::None) {}
David Sodmanaf8bab12017-12-14 15:30:55 -0800132
133 HWComposer* hwc;
David Sodman5d89c1d2017-12-14 15:54:51 -0800134 std::shared_ptr<LayerContainer> layer;
David Sodmanaf8bab12017-12-14 15:30:55 -0800135 bool forceClientComposition;
136 HWC2::Composition compositionType;
137 bool clearClientTarget;
138 Rect displayFrame;
139 FloatRect sourceCrop;
140 HWComposerBufferCache bufferCache;
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800141 HWC2::Transform transform;
David Sodmanaf8bab12017-12-14 15:30:55 -0800142 };
143
144
145 // A layer can be attached to multiple displays when operating in mirror mode
146 // (a.k.a: when several displays are attached with equal layerStack). In this
147 // case we need to keep track. In non-mirror mode, a layer will have only one
148 // HWCInfo. This map key is a display layerStack.
149 std::unordered_map<int32_t, HWCInfo> mHwcLayers;
150
151 CompositionInfo compositionInfo;
152};
153
154}; // namespace android
155