blob: 64d6a858b735154619adc816e81c943ef5904845 [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
Lloyd Pique0449b0f2018-12-20 16:23:45 -080044 bool getTransformToDisplayInverse() const override;
Marissa Wall61c58622018-07-18 10:12:20 -070045
46 uint32_t doTransactionResize(uint32_t flags, Layer::State* /*stateToCommit*/) override {
47 return flags;
48 }
Lloyd Pique0449b0f2018-12-20 16:23:45 -080049 void pushPendingState() override;
50 bool applyPendingStates(Layer::State* stateToCommit) override;
Marissa Wall61c58622018-07-18 10:12:20 -070051
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
Lloyd Pique0449b0f2018-12-20 16:23:45 -080062 bool setTransform(uint32_t transform) override;
63 bool setTransformToDisplayInverse(bool transformToDisplayInverse) override;
64 bool setCrop(const Rect& crop) override;
65 bool setFrame(const Rect& frame) override;
66 bool setBuffer(const sp<GraphicBuffer>& buffer) override;
67 bool setAcquireFence(const sp<Fence>& fence) override;
68 bool setDataspace(ui::Dataspace dataspace) override;
69 bool setHdrMetadata(const HdrMetadata& hdrMetadata) override;
70 bool setSurfaceDamageRegion(const Region& surfaceDamage) override;
71 bool setApi(int32_t api) override;
72 bool setSidebandStream(const sp<NativeHandle>& sidebandStream) override;
73 bool setTransactionCompletedListeners(const std::vector<sp<CallbackHandle>>& handles) override;
Marissa Wall61c58622018-07-18 10:12:20 -070074
Marissa Wall61c58622018-07-18 10:12:20 -070075 // Override to ignore legacy layer state properties that are not used by BufferStateLayer
Marissa Wall861616d2018-10-22 12:52:23 -070076 bool setSize(uint32_t /*w*/, uint32_t /*h*/) override { return false; }
77 bool setPosition(float /*x*/, float /*y*/, bool /*immediate*/) override { return false; }
78 bool setTransparentRegionHint(const Region& transparent) override;
79 bool setMatrix(const layer_state_t::matrix22_t& /*matrix*/,
80 bool /*allowNonRectPreservingTransforms*/) override {
81 return false;
82 }
83 bool setCrop_legacy(const Rect& /*crop*/, bool /*immediate*/) override { return false; }
84 bool setOverrideScalingMode(int32_t /*overrideScalingMode*/) override { return false; }
Valerie Haua72e2812019-01-23 13:40:39 -080085 bool setColor(const half3& color) override;
86 bool setColorAlpha(float alpha) override;
87 bool setColorDataspace(ui::Dataspace dataspace) override;
Marissa Wall61c58622018-07-18 10:12:20 -070088 void deferTransactionUntil_legacy(const sp<IBinder>& /*barrierHandle*/,
89 uint64_t /*frameNumber*/) override {}
90 void deferTransactionUntil_legacy(const sp<Layer>& /*barrierLayer*/,
91 uint64_t /*frameNumber*/) override {}
Marissa Wall861616d2018-10-22 12:52:23 -070092
Lloyd Pique0449b0f2018-12-20 16:23:45 -080093 Rect getBufferSize(const State& s) const override;
Marissa Wall61c58622018-07-18 10:12:20 -070094 // -----------------------------------------------------------------------
95
96 // -----------------------------------------------------------------------
97 // Interface implementation for BufferLayer
98 // -----------------------------------------------------------------------
Lloyd Pique0449b0f2018-12-20 16:23:45 -080099 bool fenceHasSignaled() const override;
Marissa Wall61c58622018-07-18 10:12:20 -0700100
101private:
102 nsecs_t getDesiredPresentTime() override;
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800103 std::shared_ptr<FenceTime> getCurrentFenceTime() const override;
Marissa Wall61c58622018-07-18 10:12:20 -0700104
105 void getDrawingTransformMatrix(float *matrix) override;
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800106 uint32_t getDrawingTransform() const override;
107 ui::Dataspace getDrawingDataSpace() const override;
108 Rect getDrawingCrop() const override;
Marissa Wall61c58622018-07-18 10:12:20 -0700109 uint32_t getDrawingScalingMode() const override;
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800110 Region getDrawingSurfaceDamage() const override;
111 const HdrMetadata& getDrawingHdrMetadata() const override;
112 int getDrawingApi() const override;
Marissa Wall61c58622018-07-18 10:12:20 -0700113 PixelFormat getPixelFormat() const override;
114
115 uint64_t getFrameNumber() const override;
116
117 bool getAutoRefresh() const override;
118 bool getSidebandStreamChanged() const override;
119
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800120 std::optional<Region> latchSidebandStream(bool& recomputeVisibleRegions) override;
Marissa Wall61c58622018-07-18 10:12:20 -0700121
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800122 bool hasFrameUpdate() const override;
Marissa Wall61c58622018-07-18 10:12:20 -0700123
124 void setFilteringEnabled(bool enabled) override;
125
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800126 status_t bindTextureImage() override;
Alec Mouri86770e52018-09-24 22:40:58 +0000127 status_t updateTexImage(bool& recomputeVisibleRegions, nsecs_t latchTime,
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800128 const sp<Fence>& releaseFence) override;
Marissa Wall61c58622018-07-18 10:12:20 -0700129
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800130 status_t updateActiveBuffer() override;
Marissa Wall61c58622018-07-18 10:12:20 -0700131 status_t updateFrameNumber(nsecs_t latchTime) override;
132
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800133 void setHwcLayerBuffer(DisplayId displayId) override;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700134
Marissa Wall61c58622018-07-18 10:12:20 -0700135private:
136 void onFirstRef() override;
Marissa Walle2ffb422018-10-12 11:33:52 -0700137 bool willPresentCurrentTransaction() const;
Marissa Wall61c58622018-07-18 10:12:20 -0700138
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700139 static const std::array<float, 16> IDENTITY_MATRIX;
140
Peiyong Lin833074a2018-08-28 11:53:54 -0700141 std::unique_ptr<renderengine::Image> mTextureImage;
Marissa Wall61c58622018-07-18 10:12:20 -0700142
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700143 std::array<float, 16> mTransformMatrix{IDENTITY_MATRIX};
Marissa Wall61c58622018-07-18 10:12:20 -0700144
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700145 std::atomic<bool> mSidebandStreamChanged{false};
Marissa Wall61c58622018-07-18 10:12:20 -0700146
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700147 uint32_t mFrameNumber{0};
Marissa Wall61c58622018-07-18 10:12:20 -0700148
Marissa Wallfda30bb2018-10-12 11:34:28 -0700149 sp<Fence> mPreviousReleaseFence;
150
Marissa Wall024a1912018-08-13 13:55:35 -0700151 bool mCurrentStateModified = false;
Marissa Wallfda30bb2018-10-12 11:34:28 -0700152 bool mReleasePreviousBuffer = false;
153 nsecs_t mCallbackHandleAcquireTime = -1;
Marissa Wall024a1912018-08-13 13:55:35 -0700154
Marissa Wall61c58622018-07-18 10:12:20 -0700155 // TODO(marissaw): support sticky transform for LEGACY camera mode
156};
157
158} // namespace android