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" |
| 27 | #include "RenderEngine/Mesh.h" |
| 28 | #include "RenderEngine/Texture.h" |
| 29 | #include "SurfaceFlinger.h" |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 30 | #include "Transform.h" |
| 31 | |
| 32 | #include <gui/ISurfaceComposerClient.h> |
| 33 | #include <gui/LayerState.h> |
| 34 | |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 35 | #include <ui/FrameStats.h> |
| 36 | #include <ui/GraphicBuffer.h> |
| 37 | #include <ui/PixelFormat.h> |
| 38 | #include <ui/Region.h> |
| 39 | |
| 40 | #include <utils/RefBase.h> |
| 41 | #include <utils/String8.h> |
| 42 | #include <utils/Timers.h> |
| 43 | |
| 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: |
| 52 | BufferLayer(SurfaceFlinger* flinger, const sp<Client>& client, const String8& name, uint32_t w, |
| 53 | uint32_t h, uint32_t flags); |
| 54 | |
| 55 | ~BufferLayer() override; |
| 56 | |
| 57 | // ----------------------------------------------------------------------- |
| 58 | // Overriden from Layer |
| 59 | // ----------------------------------------------------------------------- |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame^] | 60 | public: |
| 61 | // If we have received a new buffer this frame, we will pass its surface |
| 62 | // damage down to hardware composer. Otherwise, we must send a region with |
| 63 | // one empty rect. |
| 64 | void useSurfaceDamage() override; |
| 65 | void useEmptyDamage() override; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 66 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame^] | 67 | // getTypeId - Provide unique string for each class type in the Layer |
| 68 | // hierarchy |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 69 | const char* getTypeId() const override { return "BufferLayer"; } |
| 70 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame^] | 71 | bool isOpaque(const Layer::State& s) const override; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 72 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame^] | 73 | // isVisible - true if this layer is visible, false otherwise |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 74 | bool isVisible() const override; |
| 75 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame^] | 76 | // isFixedSize - true if content has a fixed size |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 77 | bool isFixedSize() const override; |
| 78 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame^] | 79 | // onDraw - draws the surface. |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 80 | void onDraw(const RenderArea& renderArea, const Region& clip, |
| 81 | bool useIdentityTransform) const override; |
David Sodman | ca10ed2 | 2018-04-16 14:10:25 -0700 | [diff] [blame] | 82 | void drawNow(const RenderArea& renderArea, bool useIdentityTransform) const; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 83 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame^] | 84 | bool isHdrY410() const override; |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 85 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame^] | 86 | void setPerFrameData(const sp<const DisplayDevice>& displayDevice) override; |
| 87 | |
| 88 | bool onPreComposition(nsecs_t refreshStartTime) override; |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 89 | bool onPostComposition(const std::shared_ptr<FenceTime>& glDoneFence, |
| 90 | const std::shared_ptr<FenceTime>& presentFence, |
| 91 | const CompositorTiming& compositorTiming) override; |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 92 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame^] | 93 | // latchBuffer - called each time the screen is redrawn and returns whether |
| 94 | // the visible regions need to be recomputed (this is a fairly heavy |
| 95 | // operation, so this should be set only if needed). Typically this is used |
| 96 | // to figure out if the content or size of a surface has changed. |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 97 | Region latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime) override; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame^] | 98 | |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 99 | bool isBufferLatched() const override { return mRefreshPending; } |
| 100 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame^] | 101 | void notifyAvailableFrames() override; |
Chia-I Wu | 692e083 | 2018-06-05 15:46:58 -0700 | [diff] [blame] | 102 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame^] | 103 | bool hasReadyFrame() const override; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 104 | |
| 105 | private: |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 106 | // Returns the current scaling mode, unless mOverrideScalingMode |
| 107 | // is set, in which case, it returns mOverrideScalingMode |
| 108 | uint32_t getEffectiveScalingMode() const override; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame^] | 109 | // ----------------------------------------------------------------------- |
| 110 | |
| 111 | // ----------------------------------------------------------------------- |
| 112 | // Functions that must be implemented by derived classes |
| 113 | // ----------------------------------------------------------------------- |
| 114 | private: |
| 115 | virtual bool fenceHasSignaled() const = 0; |
| 116 | |
| 117 | virtual nsecs_t getDesiredPresentTime() = 0; |
| 118 | virtual std::shared_ptr<FenceTime> getCurrentFenceTime() const = 0; |
| 119 | |
| 120 | virtual void getDrawingTransformMatrix(float matrix[16]) const = 0; |
| 121 | virtual uint32_t getDrawingTransform() const = 0; |
| 122 | virtual ui::Dataspace getDrawingDataSpace() const = 0; |
| 123 | virtual Rect getDrawingCrop() const = 0; |
| 124 | virtual uint32_t getDrawingScalingMode() const = 0; |
| 125 | virtual Region getDrawingSurfaceDamage() const = 0; |
| 126 | virtual const HdrMetadata& getDrawingHdrMetadata() const = 0; |
| 127 | virtual int getDrawingApi() const = 0; |
| 128 | virtual PixelFormat getPixelFormat() const = 0; |
| 129 | |
| 130 | virtual uint64_t getFrameNumber() const = 0; |
| 131 | |
| 132 | virtual bool getAutoRefresh() const = 0; |
| 133 | virtual bool getSidebandStreamChanged() const = 0; |
| 134 | |
| 135 | virtual std::optional<Region> latchSidebandStream(bool& recomputeVisibleRegions) = 0; |
| 136 | |
| 137 | virtual bool hasDrawingBuffer() const = 0; |
| 138 | |
| 139 | virtual void setFilteringEnabled(bool enabled) const = 0; |
| 140 | |
| 141 | virtual status_t bindTextureImage() const = 0; |
| 142 | virtual status_t updateTexImage(bool& recomputeVisibleRegions, nsecs_t latchTime) = 0; |
| 143 | |
| 144 | virtual status_t updateActiveBuffer() = 0; |
| 145 | virtual status_t updateFrameNumber(nsecs_t latchTime) = 0; |
| 146 | |
| 147 | virtual void setHwcLayerBuffer(const sp<const DisplayDevice>& display) = 0; |
| 148 | |
| 149 | // ----------------------------------------------------------------------- |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 150 | |
| 151 | public: |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame^] | 152 | // isProtected - true if the layer may contain protected content in the |
| 153 | // GRALLOC_USAGE_PROTECTED sense. |
| 154 | bool isProtected() const; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 155 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame^] | 156 | protected: |
| 157 | // Loads the corresponding system property once per process |
| 158 | static bool latchUnsignaledBuffers(); |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 159 | |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 160 | // Check all of the local sync points to ensure that all transactions |
| 161 | // which need to have been applied prior to the frame which is about to |
| 162 | // be latched have signaled |
| 163 | bool allTransactionsSignaled(); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 164 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame^] | 165 | static bool getOpacityForFormat(uint32_t format); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 166 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame^] | 167 | // from GLES |
| 168 | const uint32_t mTextureName; |
| 169 | |
| 170 | private: |
| 171 | // needsLinearFiltering - true if this surface's state requires filtering |
| 172 | bool needsFiltering(const RenderArea& renderArea) const; |
| 173 | |
| 174 | // drawing |
| 175 | void drawWithOpenGL(const RenderArea& renderArea, bool useIdentityTransform) const; |
| 176 | |
| 177 | uint64_t getHeadFrameNumber() const; |
| 178 | |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 179 | uint32_t mCurrentScalingMode; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame^] | 180 | |
| 181 | // main thread. |
| 182 | bool mBufferLatched; // TODO: Use mActiveBuffer? |
| 183 | |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 184 | // The texture used to draw the layer in GLES composition mode |
| 185 | mutable Texture mTexture; |
| 186 | |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 187 | bool mRefreshPending; |
| 188 | }; |
| 189 | |
| 190 | } // namespace android |