blob: 86d4ac48658170088563f98606adc0300dbb4c39 [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
Lloyd Pique074e8122018-07-26 12:57:23 -070024#include "SurfaceFlinger.h"
25
David Sodmanaf8bab12017-12-14 15:30:55 -080026#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 Sodmanaf8bab12017-12-14 15:30:55 -080035struct CompositionInfo {
David Sodmanb8af7922017-12-21 15:17:55 -080036 std::string layerName;
David Sodmanaf8bab12017-12-14 15:30:55 -080037 HWC2::Composition compositionType;
38 sp<GraphicBuffer> mBuffer = nullptr;
39 int mBufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
David Sodman40a3a5a2018-05-16 11:55:52 -070040 std::shared_ptr<LayerBE> layer;
David Sodmanaf8bab12017-12-14 15:30:55 -080041 struct {
David Sodmanb8aaea12017-12-14 15:54:51 -080042 std::shared_ptr<HWC2::Layer> hwcLayer;
David Sodman15fb96e2018-01-07 10:23:24 -080043 int32_t displayId = -1;
David Sodmanaf8bab12017-12-14 15:30:55 -080044 sp<Fence> fence;
45 HWC2::BlendMode blendMode = HWC2::BlendMode::Invalid;
46 Rect displayFrame;
47 float alpha;
48 FloatRect sourceCrop;
49 HWC2::Transform transform = HWC2::Transform::None;
50 int z;
51 int type;
52 int appId;
53 Region visibleRegion;
54 Region surfaceDamage;
55 sp<NativeHandle> sidebandStream;
David Sodmanca10ed22018-04-16 14:10:25 -070056 ui::Dataspace dataspace;
David Sodmanaf8bab12017-12-14 15:30:55 -080057 hwc_color_t color;
David Sodmanef46cce2018-08-05 15:23:10 -070058 bool clearClientTarget = false;
David Sodmanba340492018-08-05 21:51:33 -070059 bool supportedPerFrameMetadata = false;
60 HdrMetadata hdrMetadata;
David Sodmanaf8bab12017-12-14 15:30:55 -080061 } hwc;
62 struct {
63 Mesh* mesh;
David Sodman8725e812018-01-06 15:18:35 -080064 bool blackoutLayer = false;
65 bool clearArea = false;
66 bool preMultipliedAlpha = false;
67 bool opaque = false;
David Sodmanca10ed22018-04-16 14:10:25 -070068 bool disableTexture = false;
David Sodman8725e812018-01-06 15:18:35 -080069 half4 color;
70 Texture texture;
71 bool useIdentityTransform = false;
David Sodmanca10ed22018-04-16 14:10:25 -070072 bool Y410BT2020 = false;
David Sodman839d41b2017-12-31 18:44:09 -080073 } re;
David Sodmanb8af7922017-12-21 15:17:55 -080074
75 void dump(const char* tag) const;
David Sodman7e4ae112018-02-09 15:02:28 -080076 void dump(std::string& result, const char* tag = nullptr) const;
77 void dumpHwc(std::string& result, const char* tag = nullptr) const;
78 void dumpRe(std::string& result, const char* tag = nullptr) const;
David Sodmanaf8bab12017-12-14 15:30:55 -080079};
80
81class LayerBE {
82public:
David Sodmanb8af7922017-12-21 15:17:55 -080083 friend class Layer;
84 friend class BufferLayer;
Marissa Wallfd668622018-05-10 10:21:13 -070085 friend class BufferQueueLayer;
Marissa Wall61c58622018-07-18 10:12:20 -070086 friend class BufferStateLayer;
David Sodmanb8af7922017-12-21 15:17:55 -080087 friend class ColorLayer;
88 friend class SurfaceFlinger;
David Sodmanaf8bab12017-12-14 15:30:55 -080089
David Sodman2b727ac2017-12-21 14:28:08 -080090 LayerBE(Layer* layer, std::string layerName);
David Sodman40a3a5a2018-05-16 11:55:52 -070091 explicit LayerBE(const LayerBE& layer);
David Sodmanb8af7922017-12-21 15:17:55 -080092
93 void onLayerDisplayed(const sp<Fence>& releaseFence);
94 Mesh& getMesh() { return mMesh; }
95
96private:
97 Layer*const mLayer;
David Sodmanaf8bab12017-12-14 15:30:55 -080098 // The mesh used to draw the layer in GLES composition mode
99 Mesh mMesh;
100
101 // HWC items, accessed from the main thread
102 struct HWCInfo {
103 HWCInfo()
104 : hwc(nullptr),
105 layer(nullptr),
106 forceClientComposition(false),
107 compositionType(HWC2::Composition::Invalid),
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800108 clearClientTarget(false),
109 transform(HWC2::Transform::None) {}
David Sodmanaf8bab12017-12-14 15:30:55 -0800110
111 HWComposer* hwc;
David Sodmanb8aaea12017-12-14 15:54:51 -0800112 std::shared_ptr<HWC2::Layer> layer;
David Sodmanaf8bab12017-12-14 15:30:55 -0800113 bool forceClientComposition;
114 HWC2::Composition compositionType;
115 bool clearClientTarget;
116 Rect displayFrame;
117 FloatRect sourceCrop;
118 HWComposerBufferCache bufferCache;
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800119 HWC2::Transform transform;
David Sodmanaf8bab12017-12-14 15:30:55 -0800120 };
121
122
123 // A layer can be attached to multiple displays when operating in mirror mode
124 // (a.k.a: when several displays are attached with equal layerStack). In this
125 // case we need to keep track. In non-mirror mode, a layer will have only one
126 // HWCInfo. This map key is a display layerStack.
127 std::unordered_map<int32_t, HWCInfo> mHwcLayers;
128
129 CompositionInfo compositionInfo;
130};
131
132}; // namespace android
133