blob: b134fc57c6b487a54a6cfb4720c59d6976029e2f [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
Marissa Wall61c58622018-07-18 10:12:20 -070019#include "BufferLayer.h"
20#include "Layer.h"
21
22#include <gui/GLConsumer.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070023#include <renderengine/Image.h>
24#include <renderengine/RenderEngine.h>
Marissa Wall61c58622018-07-18 10:12:20 -070025#include <system/window.h>
26#include <utils/String8.h>
27
28namespace android {
29
30class BufferStateLayer : public BufferLayer {
31public:
Lloyd Pique42ab75e2018-09-12 20:46:03 -070032 explicit BufferStateLayer(const LayerCreationArgs&);
33 ~BufferStateLayer() override;
Marissa Wall61c58622018-07-18 10:12:20 -070034
35 // -----------------------------------------------------------------------
36 // Interface implementation for Layer
37 // -----------------------------------------------------------------------
38 void onLayerDisplayed(const sp<Fence>& releaseFence) override;
39 void setTransformHint(uint32_t orientation) const override;
40 void releasePendingBuffer(nsecs_t dequeueReadyTime) override;
41
Ana Krulec010d2192018-10-08 06:29:54 -070042 bool shouldPresentNow(nsecs_t expectedPresentTime) const override;
Marissa Wall61c58622018-07-18 10:12:20 -070043
44 bool getTransformToDisplayInverse() const override;
45
46 uint32_t doTransactionResize(uint32_t flags, Layer::State* /*stateToCommit*/) override {
47 return flags;
48 }
49 void pushPendingState() override;
50 bool applyPendingStates(Layer::State* stateToCommit) override;
51
52 uint32_t getActiveWidth(const Layer::State& s) const override { return s.active.w; }
53 uint32_t getActiveHeight(const Layer::State& s) const override { return s.active.h; }
Peiyong Linefefaac2018-08-17 12:27:51 -070054 ui::Transform getActiveTransform(const Layer::State& s) const override {
Marissa Wall61c58622018-07-18 10:12:20 -070055 return s.active.transform;
56 }
57 Region getActiveTransparentRegion(const Layer::State& s) const override {
58 return s.transparentRegionHint;
59 }
60 Rect getCrop(const Layer::State& s) const;
Marissa Wall61c58622018-07-18 10:12:20 -070061
62 bool setTransform(uint32_t transform) override;
63 bool setTransformToDisplayInverse(bool transformToDisplayInverse) override;
64 bool setCrop(const Rect& crop) override;
65 bool setBuffer(sp<GraphicBuffer> buffer) override;
66 bool setAcquireFence(const sp<Fence>& fence) override;
67 bool setDataspace(ui::Dataspace dataspace) override;
68 bool setHdrMetadata(const HdrMetadata& hdrMetadata) override;
69 bool setSurfaceDamageRegion(const Region& surfaceDamage) override;
70 bool setApi(int32_t api) override;
71 bool setSidebandStream(const sp<NativeHandle>& sidebandStream) override;
72
73 bool setSize(uint32_t w, uint32_t h) override;
74 bool setPosition(float x, float y, bool immediate) override;
75 bool setTransparentRegionHint(const Region& transparent) override;
76 bool setMatrix(const layer_state_t::matrix22_t& matrix,
77 bool allowNonRectPreservingTransforms) override;
78
79 // Override to ignore legacy layer state properties that are not used by BufferStateLayer
80 bool setCrop_legacy(const Rect& /*crop*/, bool /*immediate*/) override { return false; };
Marissa Wall61c58622018-07-18 10:12:20 -070081 void deferTransactionUntil_legacy(const sp<IBinder>& /*barrierHandle*/,
82 uint64_t /*frameNumber*/) override {}
83 void deferTransactionUntil_legacy(const sp<Layer>& /*barrierLayer*/,
84 uint64_t /*frameNumber*/) override {}
85 // -----------------------------------------------------------------------
86
87 // -----------------------------------------------------------------------
88 // Interface implementation for BufferLayer
89 // -----------------------------------------------------------------------
90 bool fenceHasSignaled() const override;
91
92private:
93 nsecs_t getDesiredPresentTime() override;
94 std::shared_ptr<FenceTime> getCurrentFenceTime() const override;
95
96 void getDrawingTransformMatrix(float *matrix) override;
97 uint32_t getDrawingTransform() const override;
98 ui::Dataspace getDrawingDataSpace() const override;
99 Rect getDrawingCrop() const override;
100 uint32_t getDrawingScalingMode() const override;
101 Region getDrawingSurfaceDamage() const override;
102 const HdrMetadata& getDrawingHdrMetadata() const override;
103 int getDrawingApi() const override;
104 PixelFormat getPixelFormat() const override;
105
106 uint64_t getFrameNumber() const override;
107
108 bool getAutoRefresh() const override;
109 bool getSidebandStreamChanged() const override;
110
111 std::optional<Region> latchSidebandStream(bool& recomputeVisibleRegions) override;
112
113 bool hasDrawingBuffer() const override;
114
115 void setFilteringEnabled(bool enabled) override;
116
117 status_t bindTextureImage() const override;
Alec Mouri86770e52018-09-24 22:40:58 +0000118 status_t updateTexImage(bool& recomputeVisibleRegions, nsecs_t latchTime,
119 const sp<Fence>& releaseFence) override;
Marissa Wall61c58622018-07-18 10:12:20 -0700120
121 status_t updateActiveBuffer() override;
122 status_t updateFrameNumber(nsecs_t latchTime) override;
123
124 void setHwcLayerBuffer(const sp<const DisplayDevice>& display) override;
125 // -----------------------------------------------------------------------
126private:
127 void onFirstRef() override;
128
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700129 static const std::array<float, 16> IDENTITY_MATRIX;
130
Peiyong Lin833074a2018-08-28 11:53:54 -0700131 std::unique_ptr<renderengine::Image> mTextureImage;
Marissa Wall61c58622018-07-18 10:12:20 -0700132
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700133 std::array<float, 16> mTransformMatrix{IDENTITY_MATRIX};
Marissa Wall61c58622018-07-18 10:12:20 -0700134
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700135 std::atomic<bool> mSidebandStreamChanged{false};
Marissa Wall61c58622018-07-18 10:12:20 -0700136
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700137 uint32_t mFrameNumber{0};
Marissa Wall61c58622018-07-18 10:12:20 -0700138
139 // TODO(marissaw): support sticky transform for LEGACY camera mode
140};
141
142} // namespace android