blob: 854cdd692b6d06bb8d534716b9b57c6b3bfe3cd0 [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
22#include <ui/Region.h>
23
24#include "SurfaceFlinger.h"
25
26#include "DisplayHardware/HWComposer.h"
27#include "DisplayHardware/HWComposerBufferCache.h"
28#include "RenderEngine/Mesh.h"
David Sodman8725e812018-01-06 15:18:35 -080029#include "RenderEngine/Texture.h"
David Sodmanaf8bab12017-12-14 15:30:55 -080030
31namespace android {
32
David Sodmanb8af7922017-12-21 15:17:55 -080033class LayerBE;
34
David Sodman5d89c1d2017-12-14 15:54:51 -080035class LayerContainer
36{
37 public:
38 LayerContainer(HWComposer* hwc, int32_t hwcId) : mHwc(hwc), mHwcId(hwcId) {
39 mLayer = hwc->createLayer(hwcId);
40 }
41
42 ~LayerContainer() {
43 mHwc->destroyLayer(mHwcId, mLayer);
44 }
45
46 HWC2::Layer* operator->() {
47 return mLayer;
48 }
49
50 operator HWC2::Layer*const () const {
51 return mLayer;
52 }
53
54 private:
55 HWComposer* mHwc;
56 int32_t mHwcId;
57 HWC2::Layer* mLayer;
58};
59
David Sodmanaf8bab12017-12-14 15:30:55 -080060struct CompositionInfo {
David Sodmanb8af7922017-12-21 15:17:55 -080061 std::string layerName;
David Sodmanaf8bab12017-12-14 15:30:55 -080062 HWC2::Composition compositionType;
63 sp<GraphicBuffer> mBuffer = nullptr;
64 int mBufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
David Sodmanb8af7922017-12-21 15:17:55 -080065 LayerBE* layer = nullptr;
David Sodmanaf8bab12017-12-14 15:30:55 -080066 struct {
David Sodman5d89c1d2017-12-14 15:54:51 -080067 std::shared_ptr<LayerContainer> hwcLayer;
David Sodmanaf8bab12017-12-14 15:30:55 -080068 int32_t hwid = -1;
69 sp<Fence> fence;
70 HWC2::BlendMode blendMode = HWC2::BlendMode::Invalid;
71 Rect displayFrame;
72 float alpha;
73 FloatRect sourceCrop;
74 HWC2::Transform transform = HWC2::Transform::None;
75 int z;
76 int type;
77 int appId;
78 Region visibleRegion;
79 Region surfaceDamage;
80 sp<NativeHandle> sidebandStream;
81 android_dataspace dataspace;
82 hwc_color_t color;
83 } hwc;
84 struct {
85 Mesh* mesh;
David Sodman8725e812018-01-06 15:18:35 -080086 bool blackoutLayer = false;
87 bool clearArea = false;
88 bool preMultipliedAlpha = false;
89 bool opaque = false;
David Sodmandc5e0622018-01-05 23:10:57 -080090 bool disableTexture = false;
David Sodman8725e812018-01-06 15:18:35 -080091 half4 color;
92 Texture texture;
93 bool useIdentityTransform = false;
David Sodmandc5e0622018-01-05 23:10:57 -080094 bool Y410BT2020 = false;
David Sodman839d41b2017-12-31 18:44:09 -080095 } re;
David Sodmanb8af7922017-12-21 15:17:55 -080096
97 void dump(const char* tag) const;
98 void dumpHwc(const char* tag) const;
99 void dumpRe(const char* tag) const;
David Sodmanaf8bab12017-12-14 15:30:55 -0800100};
101
102class LayerBE {
103public:
David Sodmanb8af7922017-12-21 15:17:55 -0800104 friend class Layer;
105 friend class BufferLayer;
106 friend class ColorLayer;
107 friend class SurfaceFlinger;
David Sodmanaf8bab12017-12-14 15:30:55 -0800108
David Sodman2b727ac2017-12-21 14:28:08 -0800109 LayerBE(Layer* layer, std::string layerName);
David Sodmanb8af7922017-12-21 15:17:55 -0800110
111 void onLayerDisplayed(const sp<Fence>& releaseFence);
112 Mesh& getMesh() { return mMesh; }
113
114private:
115 Layer*const mLayer;
David Sodmanaf8bab12017-12-14 15:30:55 -0800116 // The mesh used to draw the layer in GLES composition mode
117 Mesh mMesh;
118
119 // HWC items, accessed from the main thread
120 struct HWCInfo {
121 HWCInfo()
122 : hwc(nullptr),
123 layer(nullptr),
124 forceClientComposition(false),
125 compositionType(HWC2::Composition::Invalid),
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800126 clearClientTarget(false),
127 transform(HWC2::Transform::None) {}
David Sodmanaf8bab12017-12-14 15:30:55 -0800128
129 HWComposer* hwc;
David Sodman5d89c1d2017-12-14 15:54:51 -0800130 std::shared_ptr<LayerContainer> layer;
David Sodmanaf8bab12017-12-14 15:30:55 -0800131 bool forceClientComposition;
132 HWC2::Composition compositionType;
133 bool clearClientTarget;
134 Rect displayFrame;
135 FloatRect sourceCrop;
136 HWComposerBufferCache bufferCache;
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800137 HWC2::Transform transform;
David Sodmanaf8bab12017-12-14 15:30:55 -0800138 };
139
140
141 // A layer can be attached to multiple displays when operating in mirror mode
142 // (a.k.a: when several displays are attached with equal layerStack). In this
143 // case we need to keep track. In non-mirror mode, a layer will have only one
144 // HWCInfo. This map key is a display layerStack.
145 std::unordered_map<int32_t, HWCInfo> mHwcLayers;
146
147 CompositionInfo compositionInfo;
148};
149
150}; // namespace android
151