blob: f610677dc0b9ab192200119e1ddb053eeba6a40d [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 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 Sodmanb8af7922017-12-21 15:17:55 -080040 LayerBE* layer = nullptr;
David Sodmanaf8bab12017-12-14 15:30:55 -080041 struct {
David Sodmanf6a38932018-05-25 15:27:50 -070042 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;
55 android_dataspace dataspace;
56 hwc_color_t color;
57 } hwc;
58 struct {
59 Mesh* mesh;
David Sodman8725e812018-01-06 15:18:35 -080060 bool blackoutLayer = false;
61 bool clearArea = false;
62 bool preMultipliedAlpha = false;
63 bool opaque = false;
64 half4 color;
65 Texture texture;
66 bool useIdentityTransform = false;
David Sodman839d41b2017-12-31 18:44:09 -080067 } re;
David Sodmanb8af7922017-12-21 15:17:55 -080068
69 void dump(const char* tag) const;
70 void dumpHwc(const char* tag) const;
71 void dumpRe(const char* tag) const;
David Sodmanaf8bab12017-12-14 15:30:55 -080072};
73
74class LayerBE {
75public:
David Sodmanb8af7922017-12-21 15:17:55 -080076 friend class Layer;
77 friend class BufferLayer;
78 friend class ColorLayer;
79 friend class SurfaceFlinger;
David Sodmanaf8bab12017-12-14 15:30:55 -080080
David Sodman2b727ac2017-12-21 14:28:08 -080081 LayerBE(Layer* layer, std::string layerName);
David Sodmanb8af7922017-12-21 15:17:55 -080082
83 void onLayerDisplayed(const sp<Fence>& releaseFence);
84 Mesh& getMesh() { return mMesh; }
85
86private:
87 Layer*const mLayer;
David Sodmanaf8bab12017-12-14 15:30:55 -080088 // The mesh used to draw the layer in GLES composition mode
89 Mesh mMesh;
90
91 // HWC items, accessed from the main thread
92 struct HWCInfo {
93 HWCInfo()
94 : hwc(nullptr),
95 layer(nullptr),
96 forceClientComposition(false),
97 compositionType(HWC2::Composition::Invalid),
Yiwei Zhang7124ad32018-02-21 13:02:45 -080098 clearClientTarget(false),
99 transform(HWC2::Transform::None) {}
David Sodmanaf8bab12017-12-14 15:30:55 -0800100
101 HWComposer* hwc;
David Sodmanf6a38932018-05-25 15:27:50 -0700102 HWC2::Layer* layer;
David Sodmanaf8bab12017-12-14 15:30:55 -0800103 bool forceClientComposition;
104 HWC2::Composition compositionType;
105 bool clearClientTarget;
106 Rect displayFrame;
107 FloatRect sourceCrop;
108 HWComposerBufferCache bufferCache;
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800109 HWC2::Transform transform;
David Sodmanaf8bab12017-12-14 15:30:55 -0800110 };
111
112
113 // A layer can be attached to multiple displays when operating in mirror mode
114 // (a.k.a: when several displays are attached with equal layerStack). In this
115 // case we need to keep track. In non-mirror mode, a layer will have only one
116 // HWCInfo. This map key is a display layerStack.
117 std::unordered_map<int32_t, HWCInfo> mHwcLayers;
118
119 CompositionInfo compositionInfo;
120};
121
122}; // namespace android
123