blob: d63d16f59e947935a3716b1db028248d8c38dd04 [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>
David Sodmanfb95bcc2017-12-22 15:45:30 -080023#include <renderengine/RenderEngine.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070024#include <renderengine/Texture.h>
David Sodmanaf8bab12017-12-14 15:30:55 -080025#include <ui/Region.h>
26
David Sodmanaf8bab12017-12-14 15:30:55 -080027#include "DisplayHardware/HWComposer.h"
28#include "DisplayHardware/HWComposerBufferCache.h"
Peiyong Lincbc184f2018-08-22 13:24:10 -070029#include "SurfaceFlinger.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 Sodman10a41ff2018-08-05 12:14:17 -070037 HWC2::Composition compositionType = HWC2::Composition::Invalid;
David Sodmanfb95bcc2017-12-22 15:45:30 -080038 bool firstClear = false;
David Sodmanaf8bab12017-12-14 15:30:55 -080039 sp<GraphicBuffer> mBuffer = nullptr;
40 int mBufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
David Sodman40a3a5a2018-05-16 11:55:52 -070041 std::shared_ptr<LayerBE> layer;
David Sodmanaf8bab12017-12-14 15:30:55 -080042 struct {
David Sodmanb8aaea12017-12-14 15:54:51 -080043 std::shared_ptr<HWC2::Layer> hwcLayer;
David Sodman10a41ff2018-08-05 12:14:17 -070044 bool skipGeometry = true;
David Sodman15fb96e2018-01-07 10:23:24 -080045 int32_t displayId = -1;
David Sodmanaf8bab12017-12-14 15:30:55 -080046 sp<Fence> fence;
47 HWC2::BlendMode blendMode = HWC2::BlendMode::Invalid;
48 Rect displayFrame;
49 float alpha;
50 FloatRect sourceCrop;
51 HWC2::Transform transform = HWC2::Transform::None;
52 int z;
53 int type;
54 int appId;
55 Region visibleRegion;
56 Region surfaceDamage;
57 sp<NativeHandle> sidebandStream;
David Sodmanca10ed22018-04-16 14:10:25 -070058 ui::Dataspace dataspace;
David Sodmanaf8bab12017-12-14 15:30:55 -080059 hwc_color_t color;
David Sodmanef46cce2018-08-05 15:23:10 -070060 bool clearClientTarget = false;
David Sodmanba340492018-08-05 21:51:33 -070061 bool supportedPerFrameMetadata = false;
62 HdrMetadata hdrMetadata;
Peiyong Lind3788632018-09-18 16:01:31 -070063 mat4 colorTransform;
David Sodmanaf8bab12017-12-14 15:30:55 -080064 } hwc;
65 struct {
David Sodman8725e812018-01-06 15:18:35 -080066 bool blackoutLayer = false;
67 bool clearArea = false;
68 bool preMultipliedAlpha = false;
69 bool opaque = false;
David Sodmanca10ed22018-04-16 14:10:25 -070070 bool disableTexture = false;
David Sodman8725e812018-01-06 15:18:35 -080071 half4 color;
David Sodman8725e812018-01-06 15:18:35 -080072 bool useIdentityTransform = false;
David Sodmanca10ed22018-04-16 14:10:25 -070073 bool Y410BT2020 = false;
David Sodman839d41b2017-12-31 18:44:09 -080074 } re;
David Sodmanb8af7922017-12-21 15:17:55 -080075
76 void dump(const char* tag) const;
David Sodman7e4ae112018-02-09 15:02:28 -080077 void dump(std::string& result, const char* tag = nullptr) const;
78 void dumpHwc(std::string& result, const char* tag = nullptr) const;
79 void dumpRe(std::string& result, const char* tag = nullptr) const;
David Sodmanaf8bab12017-12-14 15:30:55 -080080};
81
82class LayerBE {
83public:
David Sodmanb8af7922017-12-21 15:17:55 -080084 friend class Layer;
85 friend class BufferLayer;
Marissa Wallfd668622018-05-10 10:21:13 -070086 friend class BufferQueueLayer;
Marissa Wall61c58622018-07-18 10:12:20 -070087 friend class BufferStateLayer;
David Sodmanb8af7922017-12-21 15:17:55 -080088 friend class ColorLayer;
89 friend class SurfaceFlinger;
David Sodmanaf8bab12017-12-14 15:30:55 -080090
Lloyd Piqued6b579f2018-04-06 15:29:10 -070091 // For unit tests
92 friend class TestableSurfaceFlinger;
93
David Sodman2b727ac2017-12-21 14:28:08 -080094 LayerBE(Layer* layer, std::string layerName);
David Sodman40a3a5a2018-05-16 11:55:52 -070095 explicit LayerBE(const LayerBE& layer);
David Sodmanb8af7922017-12-21 15:17:55 -080096
97 void onLayerDisplayed(const sp<Fence>& releaseFence);
Peiyong Lin833074a2018-08-28 11:53:54 -070098 void clear(renderengine::RenderEngine& renderEngine);
99 renderengine::Mesh& getMesh() { return mMesh; }
David Sodmanb8af7922017-12-21 15:17:55 -0800100
David Sodman10a41ff2018-08-05 12:14:17 -0700101 Layer*const mLayer;
David Sodmanc1498e62018-09-12 14:36:26 -0700102private:
David Sodmanaf8bab12017-12-14 15:30:55 -0800103 // The mesh used to draw the layer in GLES composition mode
Peiyong Lin833074a2018-08-28 11:53:54 -0700104 renderengine::Mesh mMesh;
David Sodmanaf8bab12017-12-14 15:30:55 -0800105
106 // HWC items, accessed from the main thread
107 struct HWCInfo {
108 HWCInfo()
109 : hwc(nullptr),
110 layer(nullptr),
111 forceClientComposition(false),
112 compositionType(HWC2::Composition::Invalid),
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800113 clearClientTarget(false),
114 transform(HWC2::Transform::None) {}
David Sodmanaf8bab12017-12-14 15:30:55 -0800115
116 HWComposer* hwc;
David Sodmanb8aaea12017-12-14 15:54:51 -0800117 std::shared_ptr<HWC2::Layer> layer;
David Sodmanaf8bab12017-12-14 15:30:55 -0800118 bool forceClientComposition;
119 HWC2::Composition compositionType;
120 bool clearClientTarget;
121 Rect displayFrame;
122 FloatRect sourceCrop;
123 HWComposerBufferCache bufferCache;
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800124 HWC2::Transform transform;
David Sodmanaf8bab12017-12-14 15:30:55 -0800125 };
126
127
128 // A layer can be attached to multiple displays when operating in mirror mode
129 // (a.k.a: when several displays are attached with equal layerStack). In this
130 // case we need to keep track. In non-mirror mode, a layer will have only one
131 // HWCInfo. This map key is a display layerStack.
132 std::unordered_map<int32_t, HWCInfo> mHwcLayers;
133
134 CompositionInfo compositionInfo;
135};
136
137}; // namespace android
138