David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
Chia-I Wu | 0cb75ac | 2017-11-27 15:56:04 -0800 | [diff] [blame] | 19 | #include "BufferLayerConsumer.h" |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 20 | #include "Client.h" |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 21 | #include "Layer.h" |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 22 | #include "DisplayHardware/HWComposer.h" |
| 23 | #include "DisplayHardware/HWComposerBufferCache.h" |
| 24 | #include "FrameTracker.h" |
| 25 | #include "LayerVector.h" |
| 26 | #include "MonitoredProducer.h" |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 27 | #include "SurfaceFlinger.h" |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 28 | |
| 29 | #include <gui/ISurfaceComposerClient.h> |
| 30 | #include <gui/LayerState.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 31 | #include <renderengine/Mesh.h> |
| 32 | #include <renderengine/Texture.h> |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 33 | #include <ui/FrameStats.h> |
| 34 | #include <ui/GraphicBuffer.h> |
| 35 | #include <ui/PixelFormat.h> |
| 36 | #include <ui/Region.h> |
| 37 | |
| 38 | #include <utils/RefBase.h> |
| 39 | #include <utils/String8.h> |
| 40 | #include <utils/Timers.h> |
| 41 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 42 | #include <system/window.h> // For NATIVE_WINDOW_SCALING_MODE_FREEZE |
| 43 | |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 44 | #include <stdint.h> |
| 45 | #include <sys/types.h> |
| 46 | #include <list> |
| 47 | |
| 48 | namespace android { |
| 49 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 50 | class BufferLayer : public Layer { |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 51 | public: |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 52 | explicit BufferLayer(const LayerCreationArgs& args); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 53 | ~BufferLayer() override; |
| 54 | |
| 55 | // ----------------------------------------------------------------------- |
| 56 | // Overriden from Layer |
| 57 | // ----------------------------------------------------------------------- |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 58 | public: |
| 59 | // If we have received a new buffer this frame, we will pass its surface |
| 60 | // damage down to hardware composer. Otherwise, we must send a region with |
| 61 | // one empty rect. |
| 62 | void useSurfaceDamage() override; |
| 63 | void useEmptyDamage() override; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 64 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 65 | // getTypeId - Provide unique string for each class type in the Layer |
| 66 | // hierarchy |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 67 | const char* getTypeId() const override { return "BufferLayer"; } |
| 68 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 69 | bool isOpaque(const Layer::State& s) const override; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 70 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 71 | // isVisible - true if this layer is visible, false otherwise |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 72 | bool isVisible() const override EXCLUDES(mStateMutex); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 73 | |
Peiyong Lin | fb530cf | 2018-12-15 05:07:38 +0000 | [diff] [blame^] | 74 | // isProtected - true if the layer may contain protected content in the |
| 75 | // GRALLOC_USAGE_PROTECTED sense. |
| 76 | bool isProtected() const override; |
| 77 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 78 | // isFixedSize - true if content has a fixed size |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 79 | bool isFixedSize() const override; |
| 80 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 81 | // onDraw - draws the surface. |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 82 | void onDraw(const RenderArea& renderArea, const Region& clip, |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 83 | bool useIdentityTransform) override; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 84 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 85 | bool isHdrY410() const override; |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 86 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 87 | void setPerFrameData(DisplayId displayId, const ui::Transform& transform, const Rect& viewport, |
| 88 | int32_t supportedPerFrameMetadata) override; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 89 | |
| 90 | bool onPreComposition(nsecs_t refreshStartTime) override; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 91 | bool onPostComposition(const std::optional<DisplayId>& displayId, |
| 92 | const std::shared_ptr<FenceTime>& glDoneFence, |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 93 | const std::shared_ptr<FenceTime>& presentFence, |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 94 | const CompositorTiming& compositorTiming) override EXCLUDES(mStateMutex); |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 95 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 96 | // latchBuffer - called each time the screen is redrawn and returns whether |
| 97 | // the visible regions need to be recomputed (this is a fairly heavy |
| 98 | // operation, so this should be set only if needed). Typically this is used |
| 99 | // to figure out if the content or size of a surface has changed. |
Alec Mouri | 86770e5 | 2018-09-24 22:40:58 +0000 | [diff] [blame] | 100 | // If there was a GL composition step rendering the previous frame, then |
| 101 | // releaseFence will be populated with a native fence that fires when |
| 102 | // composition has completed. |
| 103 | Region latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime, |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 104 | const sp<Fence>& releaseFence) override EXCLUDES(mStateMutex); |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 105 | |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 106 | bool isBufferLatched() const override { return mRefreshPending; } |
| 107 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 108 | void notifyAvailableFrames() override; |
Chia-I Wu | 692e083 | 2018-06-05 15:46:58 -0700 | [diff] [blame] | 109 | |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 110 | bool hasReadyFrame() const override EXCLUDES(mStateMutex); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 111 | |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 112 | // Returns the current scaling mode, unless mOverrideScalingMode |
| 113 | // is set, in which case, it returns mOverrideScalingMode |
| 114 | uint32_t getEffectiveScalingMode() const override; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 115 | // ----------------------------------------------------------------------- |
| 116 | |
| 117 | // ----------------------------------------------------------------------- |
| 118 | // Functions that must be implemented by derived classes |
| 119 | // ----------------------------------------------------------------------- |
| 120 | private: |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 121 | virtual bool fenceHasSignaled() const EXCLUDES(mStateMutex) = 0; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 122 | |
| 123 | virtual nsecs_t getDesiredPresentTime() = 0; |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 124 | std::shared_ptr<FenceTime> getCurrentFenceTime() const EXCLUDES(mStateMutex) { |
| 125 | Mutex::Autolock lock(mStateMutex); |
| 126 | return getCurrentFenceTimeLocked(); |
| 127 | } |
| 128 | |
| 129 | virtual std::shared_ptr<FenceTime> getCurrentFenceTimeLocked() const REQUIRES(mStateMutex) = 0; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 130 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 131 | virtual void getDrawingTransformMatrix(float *matrix) = 0; |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 132 | virtual uint32_t getDrawingTransform() const REQUIRES(mStateMutex) = 0; |
| 133 | virtual ui::Dataspace getDrawingDataSpace() const REQUIRES(mStateMutex) = 0; |
| 134 | virtual Rect getDrawingCrop() const REQUIRES(mStateMutex) = 0; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 135 | virtual uint32_t getDrawingScalingMode() const = 0; |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 136 | virtual Region getDrawingSurfaceDamage() const EXCLUDES(mStateMutex) = 0; |
| 137 | virtual const HdrMetadata& getDrawingHdrMetadata() const EXCLUDES(mStateMutex) = 0; |
| 138 | virtual int getDrawingApi() const EXCLUDES(mStateMutex) = 0; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 139 | virtual PixelFormat getPixelFormat() const = 0; |
| 140 | |
| 141 | virtual uint64_t getFrameNumber() const = 0; |
| 142 | |
| 143 | virtual bool getAutoRefresh() const = 0; |
| 144 | virtual bool getSidebandStreamChanged() const = 0; |
| 145 | |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 146 | virtual std::optional<Region> latchSidebandStream(bool& recomputeVisibleRegions) |
| 147 | EXCLUDES(mStateMutex) = 0; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 148 | |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 149 | virtual bool hasFrameUpdateLocked() const REQUIRES(mStateMutex) = 0; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 150 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 151 | virtual void setFilteringEnabled(bool enabled) = 0; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 152 | |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 153 | virtual status_t bindTextureImage() EXCLUDES(mStateMutex) = 0; |
Alec Mouri | 86770e5 | 2018-09-24 22:40:58 +0000 | [diff] [blame] | 154 | virtual status_t updateTexImage(bool& recomputeVisibleRegions, nsecs_t latchTime, |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 155 | const sp<Fence>& flushFence) REQUIRES(mStateMutex) = 0; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 156 | |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 157 | virtual status_t updateActiveBuffer() REQUIRES(mStateMutex) = 0; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 158 | virtual status_t updateFrameNumber(nsecs_t latchTime) = 0; |
| 159 | |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 160 | virtual void setHwcLayerBuffer(DisplayId displayId) EXCLUDES(mStateMutex) = 0; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 161 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 162 | protected: |
| 163 | // Loads the corresponding system property once per process |
| 164 | static bool latchUnsignaledBuffers(); |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 165 | |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 166 | // Check all of the local sync points to ensure that all transactions |
| 167 | // which need to have been applied prior to the frame which is about to |
| 168 | // be latched have signaled |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 169 | bool allTransactionsSignaled() REQUIRES(mStateMutex); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 170 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 171 | static bool getOpacityForFormat(uint32_t format); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 172 | |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 173 | bool hasFrameUpdate() const EXCLUDES(mStateMutex) { |
| 174 | Mutex::Autolock lock(mStateMutex); |
| 175 | return hasFrameUpdateLocked(); |
| 176 | } |
| 177 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 178 | // from GLES |
| 179 | const uint32_t mTextureName; |
| 180 | |
| 181 | private: |
| 182 | // needsLinearFiltering - true if this surface's state requires filtering |
| 183 | bool needsFiltering(const RenderArea& renderArea) const; |
| 184 | |
| 185 | // drawing |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 186 | void drawWithOpenGL(const RenderArea& renderArea, bool useIdentityTransform) const |
| 187 | EXCLUDES(mStateMutex); |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 188 | |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 189 | uint64_t getHeadFrameNumber() const EXCLUDES(mStateMutex); |
| 190 | |
| 191 | uint64_t getHeadFrameNumberLocked() const REQUIRES(mStateMutex); |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 192 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 193 | uint32_t mCurrentScalingMode{NATIVE_WINDOW_SCALING_MODE_FREEZE}; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 194 | |
| 195 | // main thread. |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 196 | bool mBufferLatched{false}; // TODO: Use mActiveBuffer? |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 197 | |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 198 | // The texture used to draw the layer in GLES composition mode |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 199 | mutable renderengine::Texture mTexture; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 200 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 201 | bool mRefreshPending{false}; |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 202 | |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 203 | Rect getBufferSize(const State& s) const override REQUIRES(mStateMutex); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | } // namespace android |