Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1 | /* |
| 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 Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 19 | #include "BufferLayer.h" |
| 20 | #include "Layer.h" |
| 21 | |
| 22 | #include <gui/GLConsumer.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 23 | #include <renderengine/Image.h> |
| 24 | #include <renderengine/RenderEngine.h> |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 25 | #include <system/window.h> |
| 26 | #include <utils/String8.h> |
| 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | class BufferStateLayer : public BufferLayer { |
| 31 | public: |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 32 | explicit BufferStateLayer(const LayerCreationArgs&); |
| 33 | ~BufferStateLayer() override; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 34 | |
| 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 Krulec | 010d219 | 2018-10-08 06:29:54 -0700 | [diff] [blame] | 42 | bool shouldPresentNow(nsecs_t expectedPresentTime) const override; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 43 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 44 | bool getTransformToDisplayInverse() const override; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 45 | |
| 46 | uint32_t doTransactionResize(uint32_t flags, Layer::State* /*stateToCommit*/) override { |
| 47 | return flags; |
| 48 | } |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 49 | void pushPendingState() override; |
| 50 | bool applyPendingStates(Layer::State* stateToCommit) override; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 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 Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 54 | ui::Transform getActiveTransform(const Layer::State& s) const override { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 55 | 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 Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 61 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 62 | 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 Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 74 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 75 | // Override to ignore legacy layer state properties that are not used by BufferStateLayer |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 76 | 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; } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 85 | void deferTransactionUntil_legacy(const sp<IBinder>& /*barrierHandle*/, |
| 86 | uint64_t /*frameNumber*/) override {} |
| 87 | void deferTransactionUntil_legacy(const sp<Layer>& /*barrierLayer*/, |
| 88 | uint64_t /*frameNumber*/) override {} |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 89 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 90 | Rect getBufferSize(const State& s) const override; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame^] | 91 | FloatRect computeSourceBounds(const FloatRect& parentBounds) const override; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 92 | // ----------------------------------------------------------------------- |
| 93 | |
| 94 | // ----------------------------------------------------------------------- |
| 95 | // Interface implementation for BufferLayer |
| 96 | // ----------------------------------------------------------------------- |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 97 | bool fenceHasSignaled() const override; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 98 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 99 | protected: |
| 100 | bool useCachedBufferForClientComposition() const override; |
| 101 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 102 | private: |
| 103 | nsecs_t getDesiredPresentTime() override; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 104 | std::shared_ptr<FenceTime> getCurrentFenceTime() const override; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 105 | |
| 106 | void getDrawingTransformMatrix(float *matrix) override; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 107 | uint32_t getDrawingTransform() const override; |
| 108 | ui::Dataspace getDrawingDataSpace() const override; |
| 109 | Rect getDrawingCrop() const override; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 110 | uint32_t getDrawingScalingMode() const override; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 111 | Region getDrawingSurfaceDamage() const override; |
| 112 | const HdrMetadata& getDrawingHdrMetadata() const override; |
| 113 | int getDrawingApi() const override; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 114 | PixelFormat getPixelFormat() const override; |
| 115 | |
| 116 | uint64_t getFrameNumber() const override; |
| 117 | |
| 118 | bool getAutoRefresh() const override; |
| 119 | bool getSidebandStreamChanged() const override; |
| 120 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 121 | bool latchSidebandStream(bool& recomputeVisibleRegions) override; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 122 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 123 | bool hasFrameUpdate() const override; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 124 | |
| 125 | void setFilteringEnabled(bool enabled) override; |
| 126 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 127 | status_t bindTextureImage() override; |
Alec Mouri | 86770e5 | 2018-09-24 22:40:58 +0000 | [diff] [blame] | 128 | status_t updateTexImage(bool& recomputeVisibleRegions, nsecs_t latchTime, |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 129 | const sp<Fence>& releaseFence) override; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 130 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 131 | status_t updateActiveBuffer() override; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 132 | status_t updateFrameNumber(nsecs_t latchTime) override; |
| 133 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 134 | void setHwcLayerBuffer(DisplayId displayId) override; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 135 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 136 | private: |
| 137 | void onFirstRef() override; |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 138 | bool willPresentCurrentTransaction() const; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 139 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 140 | static const std::array<float, 16> IDENTITY_MATRIX; |
| 141 | |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 142 | std::unique_ptr<renderengine::Image> mTextureImage; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 143 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 144 | std::array<float, 16> mTransformMatrix{IDENTITY_MATRIX}; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 145 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 146 | std::atomic<bool> mSidebandStreamChanged{false}; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 147 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 148 | uint32_t mFrameNumber{0}; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 149 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 150 | sp<Fence> mPreviousReleaseFence; |
| 151 | |
Marissa Wall | 024a191 | 2018-08-13 13:55:35 -0700 | [diff] [blame] | 152 | bool mCurrentStateModified = false; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 153 | bool mReleasePreviousBuffer = false; |
| 154 | nsecs_t mCallbackHandleAcquireTime = -1; |
Marissa Wall | 024a191 | 2018-08-13 13:55:35 -0700 | [diff] [blame] | 155 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 156 | // TODO(marissaw): support sticky transform for LEGACY camera mode |
| 157 | }; |
| 158 | |
| 159 | } // namespace android |