David Sodman | af8bab1 | 2017-12-14 15:30:55 -0800 | [diff] [blame] | 1 | /* |
| 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 Sodman | 8725e81 | 2018-01-06 15:18:35 -0800 | [diff] [blame] | 29 | #include "RenderEngine/Texture.h" |
David Sodman | af8bab1 | 2017-12-14 15:30:55 -0800 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | |
David Sodman | b8af792 | 2017-12-21 15:17:55 -0800 | [diff] [blame] | 33 | class LayerBE; |
| 34 | |
David Sodman | 5d89c1d | 2017-12-14 15:54:51 -0800 | [diff] [blame] | 35 | class LayerContainer |
| 36 | { |
| 37 | public: |
| 38 | LayerContainer(HWComposer* hwc, int32_t hwcId) : mHwc(hwc), mHwcId(hwcId) { |
| 39 | mLayer = hwc->createLayer(hwcId); |
| 40 | } |
| 41 | |
| 42 | ~LayerContainer() { |
| 43 | mHwc->destroyLayer(mHwcId, mLayer); |
| 44 | } |
| 45 | |
| 46 | HWC2::Layer* operator->() { |
| 47 | return mLayer; |
| 48 | } |
| 49 | |
| 50 | operator HWC2::Layer*const () const { |
| 51 | return mLayer; |
| 52 | } |
| 53 | |
| 54 | private: |
| 55 | HWComposer* mHwc; |
| 56 | int32_t mHwcId; |
| 57 | HWC2::Layer* mLayer; |
| 58 | }; |
| 59 | |
David Sodman | af8bab1 | 2017-12-14 15:30:55 -0800 | [diff] [blame] | 60 | struct CompositionInfo { |
David Sodman | b8af792 | 2017-12-21 15:17:55 -0800 | [diff] [blame] | 61 | std::string layerName; |
David Sodman | af8bab1 | 2017-12-14 15:30:55 -0800 | [diff] [blame] | 62 | HWC2::Composition compositionType; |
| 63 | sp<GraphicBuffer> mBuffer = nullptr; |
| 64 | int mBufferSlot = BufferQueue::INVALID_BUFFER_SLOT; |
David Sodman | b8af792 | 2017-12-21 15:17:55 -0800 | [diff] [blame] | 65 | LayerBE* layer = nullptr; |
David Sodman | af8bab1 | 2017-12-14 15:30:55 -0800 | [diff] [blame] | 66 | struct { |
David Sodman | 5d89c1d | 2017-12-14 15:54:51 -0800 | [diff] [blame] | 67 | std::shared_ptr<LayerContainer> hwcLayer; |
David Sodman | af8bab1 | 2017-12-14 15:30:55 -0800 | [diff] [blame] | 68 | int32_t hwid = -1; |
| 69 | sp<Fence> fence; |
| 70 | HWC2::BlendMode blendMode = HWC2::BlendMode::Invalid; |
| 71 | Rect displayFrame; |
| 72 | float alpha; |
| 73 | FloatRect sourceCrop; |
| 74 | HWC2::Transform transform = HWC2::Transform::None; |
| 75 | int z; |
| 76 | int type; |
| 77 | int appId; |
| 78 | Region visibleRegion; |
| 79 | Region surfaceDamage; |
| 80 | sp<NativeHandle> sidebandStream; |
| 81 | android_dataspace dataspace; |
| 82 | hwc_color_t color; |
| 83 | } hwc; |
| 84 | struct { |
| 85 | Mesh* mesh; |
David Sodman | 8725e81 | 2018-01-06 15:18:35 -0800 | [diff] [blame] | 86 | bool blackoutLayer = false; |
| 87 | bool clearArea = false; |
| 88 | bool preMultipliedAlpha = false; |
| 89 | bool opaque = false; |
| 90 | half4 color; |
| 91 | Texture texture; |
| 92 | bool useIdentityTransform = false; |
David Sodman | 839d41b | 2017-12-31 18:44:09 -0800 | [diff] [blame] | 93 | } re; |
David Sodman | b8af792 | 2017-12-21 15:17:55 -0800 | [diff] [blame] | 94 | |
| 95 | void dump(const char* tag) const; |
| 96 | void dumpHwc(const char* tag) const; |
| 97 | void dumpRe(const char* tag) const; |
David Sodman | af8bab1 | 2017-12-14 15:30:55 -0800 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | class LayerBE { |
| 101 | public: |
David Sodman | b8af792 | 2017-12-21 15:17:55 -0800 | [diff] [blame] | 102 | friend class Layer; |
| 103 | friend class BufferLayer; |
| 104 | friend class ColorLayer; |
| 105 | friend class SurfaceFlinger; |
David Sodman | af8bab1 | 2017-12-14 15:30:55 -0800 | [diff] [blame] | 106 | |
David Sodman | 2b727ac | 2017-12-21 14:28:08 -0800 | [diff] [blame^] | 107 | LayerBE(Layer* layer, std::string layerName); |
David Sodman | b8af792 | 2017-12-21 15:17:55 -0800 | [diff] [blame] | 108 | |
| 109 | void onLayerDisplayed(const sp<Fence>& releaseFence); |
| 110 | Mesh& getMesh() { return mMesh; } |
| 111 | |
| 112 | private: |
| 113 | Layer*const mLayer; |
David Sodman | af8bab1 | 2017-12-14 15:30:55 -0800 | [diff] [blame] | 114 | // The mesh used to draw the layer in GLES composition mode |
| 115 | Mesh mMesh; |
| 116 | |
| 117 | // HWC items, accessed from the main thread |
| 118 | struct HWCInfo { |
| 119 | HWCInfo() |
| 120 | : hwc(nullptr), |
| 121 | layer(nullptr), |
| 122 | forceClientComposition(false), |
| 123 | compositionType(HWC2::Composition::Invalid), |
Yiwei Zhang | 7124ad3 | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 124 | clearClientTarget(false), |
| 125 | transform(HWC2::Transform::None) {} |
David Sodman | af8bab1 | 2017-12-14 15:30:55 -0800 | [diff] [blame] | 126 | |
| 127 | HWComposer* hwc; |
David Sodman | 5d89c1d | 2017-12-14 15:54:51 -0800 | [diff] [blame] | 128 | std::shared_ptr<LayerContainer> layer; |
David Sodman | af8bab1 | 2017-12-14 15:30:55 -0800 | [diff] [blame] | 129 | bool forceClientComposition; |
| 130 | HWC2::Composition compositionType; |
| 131 | bool clearClientTarget; |
| 132 | Rect displayFrame; |
| 133 | FloatRect sourceCrop; |
| 134 | HWComposerBufferCache bufferCache; |
Yiwei Zhang | 7124ad3 | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 135 | HWC2::Transform transform; |
David Sodman | af8bab1 | 2017-12-14 15:30:55 -0800 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | |
| 139 | // A layer can be attached to multiple displays when operating in mirror mode |
| 140 | // (a.k.a: when several displays are attached with equal layerStack). In this |
| 141 | // case we need to keep track. In non-mirror mode, a layer will have only one |
| 142 | // HWCInfo. This map key is a display layerStack. |
| 143 | std::unordered_map<int32_t, HWCInfo> mHwcLayers; |
| 144 | |
| 145 | CompositionInfo compositionInfo; |
| 146 | }; |
| 147 | |
| 148 | }; // namespace android |
| 149 | |