blob: 76b9543c350aa376da465ac98c778202f60ff861 [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 int32_t hwid = -1;
44 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;
56 android_dataspace dataspace;
57 hwc_color_t color;
58 } 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;
65 half4 color;
66 Texture texture;
67 bool useIdentityTransform = false;
David Sodman839d41b2017-12-31 18:44:09 -080068 } re;
David Sodmanb8af7922017-12-21 15:17:55 -080069
70 void dump(const char* tag) const;
71 void dumpHwc(const char* tag) const;
72 void dumpRe(const char* tag) const;
David Sodmanaf8bab12017-12-14 15:30:55 -080073};
74
75class LayerBE {
76public:
David Sodmanb8af7922017-12-21 15:17:55 -080077 friend class Layer;
78 friend class BufferLayer;
79 friend class ColorLayer;
80 friend class SurfaceFlinger;
David Sodmanaf8bab12017-12-14 15:30:55 -080081
David Sodman2b727ac2017-12-21 14:28:08 -080082 LayerBE(Layer* layer, std::string layerName);
David Sodmanb8af7922017-12-21 15:17:55 -080083
84 void onLayerDisplayed(const sp<Fence>& releaseFence);
85 Mesh& getMesh() { return mMesh; }
86
87private:
88 Layer*const mLayer;
David Sodmanaf8bab12017-12-14 15:30:55 -080089 // The mesh used to draw the layer in GLES composition mode
90 Mesh mMesh;
91
92 // HWC items, accessed from the main thread
93 struct HWCInfo {
94 HWCInfo()
95 : hwc(nullptr),
96 layer(nullptr),
97 forceClientComposition(false),
98 compositionType(HWC2::Composition::Invalid),
Yiwei Zhang7124ad32018-02-21 13:02:45 -080099 clearClientTarget(false),
100 transform(HWC2::Transform::None) {}
David Sodmanaf8bab12017-12-14 15:30:55 -0800101
102 HWComposer* hwc;
David Sodmanf6a38932018-05-25 15:27:50 -0700103 HWC2::Layer* layer;
David Sodmanaf8bab12017-12-14 15:30:55 -0800104 bool forceClientComposition;
105 HWC2::Composition compositionType;
106 bool clearClientTarget;
107 Rect displayFrame;
108 FloatRect sourceCrop;
109 HWComposerBufferCache bufferCache;
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800110 HWC2::Transform transform;
David Sodmanaf8bab12017-12-14 15:30:55 -0800111 };
112
113
114 // A layer can be attached to multiple displays when operating in mirror mode
115 // (a.k.a: when several displays are attached with equal layerStack). In this
116 // case we need to keep track. In non-mirror mode, a layer will have only one
117 // HWCInfo. This map key is a display layerStack.
118 std::unordered_map<int32_t, HWCInfo> mHwcLayers;
119
120 CompositionInfo compositionInfo;
121};
122
123}; // namespace android
124