blob: 14619f6044e6728b2befdd511c5ee2bd87e2149e [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 Sodman5d89c1d2017-12-14 15:54:51 -080033class LayerContainer
34{
35 public:
36 LayerContainer(HWComposer* hwc, int32_t hwcId) : mHwc(hwc), mHwcId(hwcId) {
37 mLayer = hwc->createLayer(hwcId);
38 }
39
40 ~LayerContainer() {
41 mHwc->destroyLayer(mHwcId, mLayer);
42 }
43
44 HWC2::Layer* operator->() {
45 return mLayer;
46 }
47
48 operator HWC2::Layer*const () const {
49 return mLayer;
50 }
51
52 private:
53 HWComposer* mHwc;
54 int32_t mHwcId;
55 HWC2::Layer* mLayer;
56};
57
David Sodmanaf8bab12017-12-14 15:30:55 -080058struct CompositionInfo {
59 HWC2::Composition compositionType;
60 sp<GraphicBuffer> mBuffer = nullptr;
61 int mBufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
62 struct {
David Sodman5d89c1d2017-12-14 15:54:51 -080063 std::shared_ptr<LayerContainer> hwcLayer;
David Sodmanaf8bab12017-12-14 15:30:55 -080064 int32_t hwid = -1;
65 sp<Fence> fence;
66 HWC2::BlendMode blendMode = HWC2::BlendMode::Invalid;
67 Rect displayFrame;
68 float alpha;
69 FloatRect sourceCrop;
70 HWC2::Transform transform = HWC2::Transform::None;
71 int z;
72 int type;
73 int appId;
74 Region visibleRegion;
75 Region surfaceDamage;
76 sp<NativeHandle> sidebandStream;
77 android_dataspace dataspace;
78 hwc_color_t color;
79 } hwc;
80 struct {
81 Mesh* mesh;
David Sodman8725e812018-01-06 15:18:35 -080082 bool blackoutLayer = false;
83 bool clearArea = false;
84 bool preMultipliedAlpha = false;
85 bool opaque = false;
86 half4 color;
87 Texture texture;
88 bool useIdentityTransform = false;
David Sodman839d41b2017-12-31 18:44:09 -080089 } re;
David Sodmanaf8bab12017-12-14 15:30:55 -080090};
91
92class LayerBE {
93public:
94 LayerBE();
95
96 // The mesh used to draw the layer in GLES composition mode
97 Mesh mMesh;
98
99 // HWC items, accessed from the main thread
100 struct HWCInfo {
101 HWCInfo()
102 : hwc(nullptr),
103 layer(nullptr),
104 forceClientComposition(false),
105 compositionType(HWC2::Composition::Invalid),
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800106 clearClientTarget(false),
107 transform(HWC2::Transform::None) {}
David Sodmanaf8bab12017-12-14 15:30:55 -0800108
109 HWComposer* hwc;
David Sodman5d89c1d2017-12-14 15:54:51 -0800110 std::shared_ptr<LayerContainer> layer;
David Sodmanaf8bab12017-12-14 15:30:55 -0800111 bool forceClientComposition;
112 HWC2::Composition compositionType;
113 bool clearClientTarget;
114 Rect displayFrame;
115 FloatRect sourceCrop;
116 HWComposerBufferCache bufferCache;
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800117 HWC2::Transform transform;
David Sodmanaf8bab12017-12-14 15:30:55 -0800118 };
119
120
121 // A layer can be attached to multiple displays when operating in mirror mode
122 // (a.k.a: when several displays are attached with equal layerStack). In this
123 // case we need to keep track. In non-mirror mode, a layer will have only one
124 // HWCInfo. This map key is a display layerStack.
125 std::unordered_map<int32_t, HWCInfo> mHwcLayers;
126
127 CompositionInfo compositionInfo;
128};
129
130}; // namespace android
131