blob: 3affdb7044b7e8d41d1d16dd946958b31b3b80ca [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"
29
30namespace android {
31
David Sodman5d89c1d2017-12-14 15:54:51 -080032class LayerContainer
33{
34 public:
35 LayerContainer(HWComposer* hwc, int32_t hwcId) : mHwc(hwc), mHwcId(hwcId) {
36 mLayer = hwc->createLayer(hwcId);
37 }
38
39 ~LayerContainer() {
40 mHwc->destroyLayer(mHwcId, mLayer);
41 }
42
43 HWC2::Layer* operator->() {
44 return mLayer;
45 }
46
47 operator HWC2::Layer*const () const {
48 return mLayer;
49 }
50
51 private:
52 HWComposer* mHwc;
53 int32_t mHwcId;
54 HWC2::Layer* mLayer;
55};
56
David Sodmanaf8bab12017-12-14 15:30:55 -080057struct CompositionInfo {
58 HWC2::Composition compositionType;
59 sp<GraphicBuffer> mBuffer = nullptr;
60 int mBufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
61 struct {
David Sodman5d89c1d2017-12-14 15:54:51 -080062 std::shared_ptr<LayerContainer> hwcLayer;
David Sodmanaf8bab12017-12-14 15:30:55 -080063 int32_t hwid = -1;
64 sp<Fence> fence;
65 HWC2::BlendMode blendMode = HWC2::BlendMode::Invalid;
66 Rect displayFrame;
67 float alpha;
68 FloatRect sourceCrop;
69 HWC2::Transform transform = HWC2::Transform::None;
70 int z;
71 int type;
72 int appId;
73 Region visibleRegion;
74 Region surfaceDamage;
75 sp<NativeHandle> sidebandStream;
76 android_dataspace dataspace;
77 hwc_color_t color;
78 } hwc;
79 struct {
80 Mesh* mesh;
David Sodman839d41b2017-12-31 18:44:09 -080081 } re;
David Sodmanaf8bab12017-12-14 15:30:55 -080082};
83
84class LayerBE {
85public:
86 LayerBE();
87
88 // 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 Sodman5d89c1d2017-12-14 15:54:51 -0800102 std::shared_ptr<LayerContainer> 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