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