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