blob: 4d7396ef81debfc1809bfbe8b2ed0b2c4316fe2f [file] [log] [blame]
Marissa Wall61c58622018-07-18 10:12:20 -07001/*
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 "RenderEngine/Image.h"
20#include "RenderEngine/RenderEngine.h"
21
22#include "BufferLayer.h"
23#include "Layer.h"
24
25#include <gui/GLConsumer.h>
26#include <system/window.h>
27#include <utils/String8.h>
28
29namespace android {
30
31class BufferStateLayer : public BufferLayer {
32public:
33 BufferStateLayer(SurfaceFlinger* flinger, const sp<Client>& client, const String8& name,
34 uint32_t w, uint32_t h, uint32_t flags);
35
36 // -----------------------------------------------------------------------
37 // Interface implementation for Layer
38 // -----------------------------------------------------------------------
39 void onLayerDisplayed(const sp<Fence>& releaseFence) override;
40 void setTransformHint(uint32_t orientation) const override;
41 void releasePendingBuffer(nsecs_t dequeueReadyTime) override;
42
43 bool shouldPresentNow(const DispSync& dispSync) const override;
44
45 bool getTransformToDisplayInverse() const override;
46
47 uint32_t doTransactionResize(uint32_t flags, Layer::State* /*stateToCommit*/) override {
48 return flags;
49 }
50 void pushPendingState() override;
51 bool applyPendingStates(Layer::State* stateToCommit) override;
52
53 uint32_t getActiveWidth(const Layer::State& s) const override { return s.active.w; }
54 uint32_t getActiveHeight(const Layer::State& s) const override { return s.active.h; }
55 Transform getActiveTransform(const Layer::State& s) const override {
56 return s.active.transform;
57 }
58 Region getActiveTransparentRegion(const Layer::State& s) const override {
59 return s.transparentRegionHint;
60 }
61 Rect getCrop(const Layer::State& s) const;
62 Rect getFinalCrop(const Layer::State& /*s*/) const { return Rect::EMPTY_RECT; }
63
64 bool setTransform(uint32_t transform) override;
65 bool setTransformToDisplayInverse(bool transformToDisplayInverse) override;
66 bool setCrop(const Rect& crop) override;
67 bool setBuffer(sp<GraphicBuffer> buffer) override;
68 bool setAcquireFence(const sp<Fence>& fence) override;
69 bool setDataspace(ui::Dataspace dataspace) override;
70 bool setHdrMetadata(const HdrMetadata& hdrMetadata) override;
71 bool setSurfaceDamageRegion(const Region& surfaceDamage) override;
72 bool setApi(int32_t api) override;
73 bool setSidebandStream(const sp<NativeHandle>& sidebandStream) override;
74
75 bool setSize(uint32_t w, uint32_t h) override;
76 bool setPosition(float x, float y, bool immediate) override;
77 bool setTransparentRegionHint(const Region& transparent) override;
78 bool setMatrix(const layer_state_t::matrix22_t& matrix,
79 bool allowNonRectPreservingTransforms) override;
80
81 // Override to ignore legacy layer state properties that are not used by BufferStateLayer
82 bool setCrop_legacy(const Rect& /*crop*/, bool /*immediate*/) override { return false; };
83 bool setFinalCrop_legacy(const Rect& /*crop*/, bool /*immediate*/) override { return false; };
84 void deferTransactionUntil_legacy(const sp<IBinder>& /*barrierHandle*/,
85 uint64_t /*frameNumber*/) override {}
86 void deferTransactionUntil_legacy(const sp<Layer>& /*barrierLayer*/,
87 uint64_t /*frameNumber*/) override {}
88 // -----------------------------------------------------------------------
89
90 // -----------------------------------------------------------------------
91 // Interface implementation for BufferLayer
92 // -----------------------------------------------------------------------
93 bool fenceHasSignaled() const override;
94
95private:
96 nsecs_t getDesiredPresentTime() override;
97 std::shared_ptr<FenceTime> getCurrentFenceTime() const override;
98
99 void getDrawingTransformMatrix(float *matrix) override;
100 uint32_t getDrawingTransform() const override;
101 ui::Dataspace getDrawingDataSpace() const override;
102 Rect getDrawingCrop() const override;
103 uint32_t getDrawingScalingMode() const override;
104 Region getDrawingSurfaceDamage() const override;
105 const HdrMetadata& getDrawingHdrMetadata() const override;
106 int getDrawingApi() const override;
107 PixelFormat getPixelFormat() const override;
108
109 uint64_t getFrameNumber() const override;
110
111 bool getAutoRefresh() const override;
112 bool getSidebandStreamChanged() const override;
113
114 std::optional<Region> latchSidebandStream(bool& recomputeVisibleRegions) override;
115
116 bool hasDrawingBuffer() const override;
117
118 void setFilteringEnabled(bool enabled) override;
119
120 status_t bindTextureImage() const override;
121 status_t updateTexImage(bool& recomputeVisibleRegions, nsecs_t latchTime) override;
122
123 status_t updateActiveBuffer() override;
124 status_t updateFrameNumber(nsecs_t latchTime) override;
125
126 void setHwcLayerBuffer(const sp<const DisplayDevice>& display) override;
127 // -----------------------------------------------------------------------
128private:
129 void onFirstRef() override;
130
131 std::unique_ptr<RE::Image> mTextureImage;
132
133 std::array<float, 16> mTransformMatrix;
134
135 std::atomic<bool> mSidebandStreamChanged;
136
137 uint32_t mFrameNumber;
138
139 // TODO(marissaw): support sticky transform for LEGACY camera mode
140};
141
142} // namespace android