blob: 13f4e83b44174b1fb9163c82872a57ef1c580f8a [file] [log] [blame]
David Sodman0c69cad2017-08-21 12:12:51 -07001/*
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 Wu0cb75ac2017-11-27 15:56:04 -080019#include "BufferLayerConsumer.h"
David Sodman0c69cad2017-08-21 12:12:51 -070020#include "Client.h"
David Sodman41fdfc92017-11-06 16:09:56 -080021#include "Layer.h"
David Sodman0c69cad2017-08-21 12:12:51 -070022#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 Sodman0c69cad2017-08-21 12:12:51 -070030#include "Transform.h"
31
32#include <gui/ISurfaceComposerClient.h>
33#include <gui/LayerState.h>
34
David Sodman0c69cad2017-08-21 12:12:51 -070035#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
48namespace android {
49
Marissa Wallfd668622018-05-10 10:21:13 -070050class BufferLayer : public Layer {
David Sodman0c69cad2017-08-21 12:12:51 -070051public:
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 Wallfd668622018-05-10 10:21:13 -070060public:
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 Sodman0c69cad2017-08-21 12:12:51 -070066
Marissa Wallfd668622018-05-10 10:21:13 -070067 // getTypeId - Provide unique string for each class type in the Layer
68 // hierarchy
David Sodman0c69cad2017-08-21 12:12:51 -070069 const char* getTypeId() const override { return "BufferLayer"; }
70
Marissa Wallfd668622018-05-10 10:21:13 -070071 bool isOpaque(const Layer::State& s) const override;
David Sodman0c69cad2017-08-21 12:12:51 -070072
Marissa Wallfd668622018-05-10 10:21:13 -070073 // isVisible - true if this layer is visible, false otherwise
David Sodman0c69cad2017-08-21 12:12:51 -070074 bool isVisible() const override;
75
Marissa Wallfd668622018-05-10 10:21:13 -070076 // isFixedSize - true if content has a fixed size
David Sodman0c69cad2017-08-21 12:12:51 -070077 bool isFixedSize() const override;
78
Marissa Wallfd668622018-05-10 10:21:13 -070079 // onDraw - draws the surface.
David Sodman0c69cad2017-08-21 12:12:51 -070080 void onDraw(const RenderArea& renderArea, const Region& clip,
Marissa Wall61c58622018-07-18 10:12:20 -070081 bool useIdentityTransform) override;
82 void drawNow(const RenderArea& renderArea, bool useIdentityTransform);
David Sodman0c69cad2017-08-21 12:12:51 -070083
Marissa Wallfd668622018-05-10 10:21:13 -070084 bool isHdrY410() const override;
David Sodmaneb085e02017-10-05 18:49:04 -070085
Marissa Wallfd668622018-05-10 10:21:13 -070086 void setPerFrameData(const sp<const DisplayDevice>& displayDevice) override;
87
88 bool onPreComposition(nsecs_t refreshStartTime) override;
David Sodmaneb085e02017-10-05 18:49:04 -070089 bool onPostComposition(const std::shared_ptr<FenceTime>& glDoneFence,
90 const std::shared_ptr<FenceTime>& presentFence,
91 const CompositorTiming& compositorTiming) override;
David Sodmaneb085e02017-10-05 18:49:04 -070092
Marissa Wallfd668622018-05-10 10:21:13 -070093 // 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 Sodman0c69cad2017-08-21 12:12:51 -070097 Region latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime) override;
Marissa Wallfd668622018-05-10 10:21:13 -070098
David Sodman0c69cad2017-08-21 12:12:51 -070099 bool isBufferLatched() const override { return mRefreshPending; }
100
Marissa Wallfd668622018-05-10 10:21:13 -0700101 void notifyAvailableFrames() override;
Chia-I Wu692e0832018-06-05 15:46:58 -0700102
Marissa Wallfd668622018-05-10 10:21:13 -0700103 bool hasReadyFrame() const override;
David Sodman0c69cad2017-08-21 12:12:51 -0700104
David Sodman0c69cad2017-08-21 12:12:51 -0700105 // Returns the current scaling mode, unless mOverrideScalingMode
106 // is set, in which case, it returns mOverrideScalingMode
107 uint32_t getEffectiveScalingMode() const override;
Marissa Wallfd668622018-05-10 10:21:13 -0700108 // -----------------------------------------------------------------------
109
110 // -----------------------------------------------------------------------
111 // Functions that must be implemented by derived classes
112 // -----------------------------------------------------------------------
113private:
114 virtual bool fenceHasSignaled() const = 0;
115
116 virtual nsecs_t getDesiredPresentTime() = 0;
117 virtual std::shared_ptr<FenceTime> getCurrentFenceTime() const = 0;
118
Marissa Wall61c58622018-07-18 10:12:20 -0700119 virtual void getDrawingTransformMatrix(float *matrix) = 0;
Marissa Wallfd668622018-05-10 10:21:13 -0700120 virtual uint32_t getDrawingTransform() const = 0;
121 virtual ui::Dataspace getDrawingDataSpace() const = 0;
122 virtual Rect getDrawingCrop() const = 0;
123 virtual uint32_t getDrawingScalingMode() const = 0;
124 virtual Region getDrawingSurfaceDamage() const = 0;
125 virtual const HdrMetadata& getDrawingHdrMetadata() const = 0;
126 virtual int getDrawingApi() const = 0;
127 virtual PixelFormat getPixelFormat() const = 0;
128
129 virtual uint64_t getFrameNumber() const = 0;
130
131 virtual bool getAutoRefresh() const = 0;
132 virtual bool getSidebandStreamChanged() const = 0;
133
134 virtual std::optional<Region> latchSidebandStream(bool& recomputeVisibleRegions) = 0;
135
136 virtual bool hasDrawingBuffer() const = 0;
137
Marissa Wall61c58622018-07-18 10:12:20 -0700138 virtual void setFilteringEnabled(bool enabled) = 0;
Marissa Wallfd668622018-05-10 10:21:13 -0700139
140 virtual status_t bindTextureImage() const = 0;
141 virtual status_t updateTexImage(bool& recomputeVisibleRegions, nsecs_t latchTime) = 0;
142
143 virtual status_t updateActiveBuffer() = 0;
144 virtual status_t updateFrameNumber(nsecs_t latchTime) = 0;
145
146 virtual void setHwcLayerBuffer(const sp<const DisplayDevice>& display) = 0;
147
148 // -----------------------------------------------------------------------
David Sodman0c69cad2017-08-21 12:12:51 -0700149
150public:
Marissa Wallfd668622018-05-10 10:21:13 -0700151 // isProtected - true if the layer may contain protected content in the
152 // GRALLOC_USAGE_PROTECTED sense.
153 bool isProtected() const;
David Sodman0c69cad2017-08-21 12:12:51 -0700154
Marissa Wallfd668622018-05-10 10:21:13 -0700155protected:
156 // Loads the corresponding system property once per process
157 static bool latchUnsignaledBuffers();
David Sodmaneb085e02017-10-05 18:49:04 -0700158
David Sodman0c69cad2017-08-21 12:12:51 -0700159 // Check all of the local sync points to ensure that all transactions
160 // which need to have been applied prior to the frame which is about to
161 // be latched have signaled
162 bool allTransactionsSignaled();
David Sodman0c69cad2017-08-21 12:12:51 -0700163
Marissa Wallfd668622018-05-10 10:21:13 -0700164 static bool getOpacityForFormat(uint32_t format);
David Sodman0c69cad2017-08-21 12:12:51 -0700165
Marissa Wallfd668622018-05-10 10:21:13 -0700166 // from GLES
167 const uint32_t mTextureName;
168
169private:
170 // needsLinearFiltering - true if this surface's state requires filtering
171 bool needsFiltering(const RenderArea& renderArea) const;
172
173 // drawing
174 void drawWithOpenGL(const RenderArea& renderArea, bool useIdentityTransform) const;
175
176 uint64_t getHeadFrameNumber() const;
177
David Sodman0c69cad2017-08-21 12:12:51 -0700178 uint32_t mCurrentScalingMode;
Marissa Wallfd668622018-05-10 10:21:13 -0700179
180 // main thread.
181 bool mBufferLatched; // TODO: Use mActiveBuffer?
182
David Sodman0c69cad2017-08-21 12:12:51 -0700183 // The texture used to draw the layer in GLES composition mode
184 mutable Texture mTexture;
185
David Sodman0c69cad2017-08-21 12:12:51 -0700186 bool mRefreshPending;
187};
188
189} // namespace android