blob: e5110b7bea4051fc7e3736d791526b5f10fb2be7 [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
Peiyong Lincbc184f2018-08-22 13:24:10 -070022#include <renderengine/Mesh.h>
23#include <renderengine/Texture.h>
David Sodmanaf8bab12017-12-14 15:30:55 -080024#include <ui/Region.h>
25
David Sodmanaf8bab12017-12-14 15:30:55 -080026#include "DisplayHardware/HWComposer.h"
27#include "DisplayHardware/HWComposerBufferCache.h"
Peiyong Lincbc184f2018-08-22 13:24:10 -070028#include "SurfaceFlinger.h"
David Sodmanaf8bab12017-12-14 15:30:55 -080029
30namespace android {
31
David Sodmanb8af7922017-12-21 15:17:55 -080032class LayerBE;
33
David Sodmanaf8bab12017-12-14 15:30:55 -080034struct CompositionInfo {
David Sodmanb8af7922017-12-21 15:17:55 -080035 std::string layerName;
David Sodmanaf8bab12017-12-14 15:30:55 -080036 HWC2::Composition compositionType;
37 sp<GraphicBuffer> mBuffer = nullptr;
38 int mBufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
David Sodman40a3a5a2018-05-16 11:55:52 -070039 std::shared_ptr<LayerBE> layer;
David Sodmanaf8bab12017-12-14 15:30:55 -080040 struct {
David Sodmanb8aaea12017-12-14 15:54:51 -080041 std::shared_ptr<HWC2::Layer> hwcLayer;
David Sodman15fb96e2018-01-07 10:23:24 -080042 int32_t displayId = -1;
David Sodmanaf8bab12017-12-14 15:30:55 -080043 sp<Fence> fence;
44 HWC2::BlendMode blendMode = HWC2::BlendMode::Invalid;
45 Rect displayFrame;
46 float alpha;
47 FloatRect sourceCrop;
48 HWC2::Transform transform = HWC2::Transform::None;
49 int z;
50 int type;
51 int appId;
52 Region visibleRegion;
53 Region surfaceDamage;
54 sp<NativeHandle> sidebandStream;
David Sodmanca10ed22018-04-16 14:10:25 -070055 ui::Dataspace dataspace;
David Sodmanaf8bab12017-12-14 15:30:55 -080056 hwc_color_t color;
David Sodmanef46cce2018-08-05 15:23:10 -070057 bool clearClientTarget = false;
David Sodmanba340492018-08-05 21:51:33 -070058 bool supportedPerFrameMetadata = false;
59 HdrMetadata hdrMetadata;
David Sodmanaf8bab12017-12-14 15:30:55 -080060 } hwc;
61 struct {
62 Mesh* mesh;
David Sodman8725e812018-01-06 15:18:35 -080063 bool blackoutLayer = false;
64 bool clearArea = false;
65 bool preMultipliedAlpha = false;
66 bool opaque = false;
David Sodmanca10ed22018-04-16 14:10:25 -070067 bool disableTexture = false;
David Sodman8725e812018-01-06 15:18:35 -080068 half4 color;
69 Texture texture;
70 bool useIdentityTransform = false;
David Sodmanca10ed22018-04-16 14:10:25 -070071 bool Y410BT2020 = false;
David Sodman839d41b2017-12-31 18:44:09 -080072 } re;
David Sodmanb8af7922017-12-21 15:17:55 -080073
74 void dump(const char* tag) const;
David Sodman7e4ae112018-02-09 15:02:28 -080075 void dump(std::string& result, const char* tag = nullptr) const;
76 void dumpHwc(std::string& result, const char* tag = nullptr) const;
77 void dumpRe(std::string& result, const char* tag = nullptr) const;
David Sodmanaf8bab12017-12-14 15:30:55 -080078};
79
80class LayerBE {
81public:
David Sodmanb8af7922017-12-21 15:17:55 -080082 friend class Layer;
83 friend class BufferLayer;
Marissa Wallfd668622018-05-10 10:21:13 -070084 friend class BufferQueueLayer;
Marissa Wall61c58622018-07-18 10:12:20 -070085 friend class BufferStateLayer;
David Sodmanb8af7922017-12-21 15:17:55 -080086 friend class ColorLayer;
87 friend class SurfaceFlinger;
David Sodmanaf8bab12017-12-14 15:30:55 -080088
David Sodman2b727ac2017-12-21 14:28:08 -080089 LayerBE(Layer* layer, std::string layerName);
David Sodman40a3a5a2018-05-16 11:55:52 -070090 explicit LayerBE(const LayerBE& layer);
David Sodmanb8af7922017-12-21 15:17:55 -080091
92 void onLayerDisplayed(const sp<Fence>& releaseFence);
93 Mesh& getMesh() { return mMesh; }
94
95private:
96 Layer*const mLayer;
David Sodmanaf8bab12017-12-14 15:30:55 -080097 // The mesh used to draw the layer in GLES composition mode
98 Mesh mMesh;
99
100 // HWC items, accessed from the main thread
101 struct HWCInfo {
102 HWCInfo()
103 : hwc(nullptr),
104 layer(nullptr),
105 forceClientComposition(false),
106 compositionType(HWC2::Composition::Invalid),
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800107 clearClientTarget(false),
108 transform(HWC2::Transform::None) {}
David Sodmanaf8bab12017-12-14 15:30:55 -0800109
110 HWComposer* hwc;
David Sodmanb8aaea12017-12-14 15:54:51 -0800111 std::shared_ptr<HWC2::Layer> layer;
David Sodmanaf8bab12017-12-14 15:30:55 -0800112 bool forceClientComposition;
113 HWC2::Composition compositionType;
114 bool clearClientTarget;
115 Rect displayFrame;
116 FloatRect sourceCrop;
117 HWComposerBufferCache bufferCache;
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800118 HWC2::Transform transform;
David Sodmanaf8bab12017-12-14 15:30:55 -0800119 };
120
121
122 // A layer can be attached to multiple displays when operating in mirror mode
123 // (a.k.a: when several displays are attached with equal layerStack). In this
124 // case we need to keep track. In non-mirror mode, a layer will have only one
125 // HWCInfo. This map key is a display layerStack.
126 std::unordered_map<int32_t, HWCInfo> mHwcLayers;
127
128 CompositionInfo compositionInfo;
129};
130
131}; // namespace android
132