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 | |
| 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 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 | |
| 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 Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 81 | 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 | |
| 92 | private: |
| 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 Mouri | 86770e5 | 2018-09-24 22:40:58 +0000 | [diff] [blame] | 118 | status_t updateTexImage(bool& recomputeVisibleRegions, nsecs_t latchTime, |
| 119 | const sp<Fence>& releaseFence) override; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 120 | |
| 121 | status_t updateActiveBuffer() override; |
| 122 | status_t updateFrameNumber(nsecs_t latchTime) override; |
| 123 | |
| 124 | void setHwcLayerBuffer(const sp<const DisplayDevice>& display) override; |
| 125 | // ----------------------------------------------------------------------- |
| 126 | private: |
| 127 | void onFirstRef() override; |
| 128 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 129 | static const std::array<float, 16> IDENTITY_MATRIX; |
| 130 | |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 131 | std::unique_ptr<renderengine::Image> mTextureImage; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 132 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 133 | std::array<float, 16> mTransformMatrix{IDENTITY_MATRIX}; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 134 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 135 | std::atomic<bool> mSidebandStreamChanged{false}; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 136 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 137 | uint32_t mFrameNumber{0}; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 138 | |
| 139 | // TODO(marissaw): support sticky transform for LEGACY camera mode |
| 140 | }; |
| 141 | |
| 142 | } // namespace android |