blob: 3055621edc8e3b093ca2f4bcb51e256a3c8b4b23 [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 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 Sodmanaf8bab12017-12-14 15:30:55 -080058 } hwc;
59 struct {
60 Mesh* mesh;
David Sodman8725e812018-01-06 15:18:35 -080061 bool blackoutLayer = false;
62 bool clearArea = false;
63 bool preMultipliedAlpha = false;
64 bool opaque = false;
David Sodmanca10ed22018-04-16 14:10:25 -070065 bool disableTexture = false;
David Sodman8725e812018-01-06 15:18:35 -080066 half4 color;
67 Texture texture;
68 bool useIdentityTransform = false;
David Sodmanca10ed22018-04-16 14:10:25 -070069 bool Y410BT2020 = false;
David Sodman839d41b2017-12-31 18:44:09 -080070 } re;
David Sodmanb8af7922017-12-21 15:17:55 -080071
72 void dump(const char* tag) const;
73 void dumpHwc(const char* tag) const;
74 void dumpRe(const char* tag) const;
David Sodmanaf8bab12017-12-14 15:30:55 -080075};
76
77class LayerBE {
78public:
David Sodmanb8af7922017-12-21 15:17:55 -080079 friend class Layer;
80 friend class BufferLayer;
Marissa Wallfd668622018-05-10 10:21:13 -070081 friend class BufferQueueLayer;
Marissa Wall61c58622018-07-18 10:12:20 -070082 friend class BufferStateLayer;
David Sodmanb8af7922017-12-21 15:17:55 -080083 friend class ColorLayer;
84 friend class SurfaceFlinger;
David Sodmanaf8bab12017-12-14 15:30:55 -080085
David Sodman2b727ac2017-12-21 14:28:08 -080086 LayerBE(Layer* layer, std::string layerName);
David Sodman40a3a5a2018-05-16 11:55:52 -070087 explicit LayerBE(const LayerBE& layer);
David Sodmanb8af7922017-12-21 15:17:55 -080088
89 void onLayerDisplayed(const sp<Fence>& releaseFence);
90 Mesh& getMesh() { return mMesh; }
91
92private:
93 Layer*const mLayer;
David Sodmanaf8bab12017-12-14 15:30:55 -080094 // The mesh used to draw the layer in GLES composition mode
95 Mesh mMesh;
96
97 // HWC items, accessed from the main thread
98 struct HWCInfo {
99 HWCInfo()
100 : hwc(nullptr),
101 layer(nullptr),
102 forceClientComposition(false),
103 compositionType(HWC2::Composition::Invalid),
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800104 clearClientTarget(false),
105 transform(HWC2::Transform::None) {}
David Sodmanaf8bab12017-12-14 15:30:55 -0800106
107 HWComposer* hwc;
David Sodmanb8aaea12017-12-14 15:54:51 -0800108 std::shared_ptr<HWC2::Layer> layer;
David Sodmanaf8bab12017-12-14 15:30:55 -0800109 bool forceClientComposition;
110 HWC2::Composition compositionType;
111 bool clearClientTarget;
112 Rect displayFrame;
113 FloatRect sourceCrop;
114 HWComposerBufferCache bufferCache;
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800115 HWC2::Transform transform;
David Sodmanaf8bab12017-12-14 15:30:55 -0800116 };
117
118
119 // A layer can be attached to multiple displays when operating in mirror mode
120 // (a.k.a: when several displays are attached with equal layerStack). In this
121 // case we need to keep track. In non-mirror mode, a layer will have only one
122 // HWCInfo. This map key is a display layerStack.
123 std::unordered_map<int32_t, HWCInfo> mHwcLayers;
124
125 CompositionInfo compositionInfo;
126};
127
128}; // namespace android
129