1 /* 2 * Copyright 2022 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 #ifndef ANDROID_HWC_LAYER_H 18 #define ANDROID_HWC_LAYER_H 19 20 #include <optional> 21 #include <vector> 22 23 #include "Common.h" 24 #include "FencedBuffer.h" 25 26 namespace aidl::android::hardware::graphics::composer3::impl { 27 28 class Layer { 29 public: 30 explicit Layer(); 31 32 Layer(const Layer&) = delete; 33 Layer& operator=(const Layer&) = delete; 34 35 Layer(Layer&&) = delete; 36 Layer& operator=(Layer&&) = delete; 37 getId()38 int64_t getId() const { return mId; } 39 40 HWC3::Error setCursorPosition(const common::Point& cursorPosition); 41 common::Point getCursorPosition() const; 42 43 HWC3::Error setBuffer(buffer_handle_t buffer, const ndk::ScopedFileDescriptor& fence); 44 FencedBuffer& getBuffer(); 45 buffer_handle_t waitAndGetBuffer(); 46 47 HWC3::Error setSurfaceDamage(const std::vector<std::optional<common::Rect>>& damage); 48 49 HWC3::Error setBlendMode(common::BlendMode mode); 50 common::BlendMode getBlendMode() const; 51 52 HWC3::Error setColor(Color color); 53 Color getColor() const; 54 55 HWC3::Error setCompositionType(Composition composition); 56 Composition getCompositionType() const; 57 58 HWC3::Error setDataspace(common::Dataspace dataspace); 59 common::Dataspace getDataspace() const; 60 61 HWC3::Error setDisplayFrame(common::Rect frame); 62 common::Rect getDisplayFrame() const; 63 64 HWC3::Error setPlaneAlpha(float alpha); 65 float getPlaneAlpha() const; 66 67 HWC3::Error setSidebandStream(buffer_handle_t stream); 68 69 HWC3::Error setSourceCrop(common::FRect crop); 70 common::FRect getSourceCrop() const; 71 common::Rect getSourceCropInt() const; 72 73 HWC3::Error setTransform(common::Transform transform); 74 common::Transform getTransform() const; 75 76 HWC3::Error setVisibleRegion(const std::vector<std::optional<common::Rect>>& visible); 77 std::size_t getNumVisibleRegions() const; 78 79 HWC3::Error setZOrder(int32_t z); 80 int32_t getZOrder() const; 81 82 HWC3::Error setPerFrameMetadata( 83 const std::vector<std::optional<PerFrameMetadata>>& perFrameMetadata); 84 85 HWC3::Error setColorTransform(const std::vector<float>& colorTransform); 86 const std::optional<std::array<float, 16>>& getColorTransform() const; 87 88 HWC3::Error setBrightness(float brightness); 89 float getBrightness() const; 90 91 HWC3::Error setPerFrameMetadataBlobs( 92 const std::vector<std::optional<PerFrameMetadataBlob>>& perFrameMetadata); 93 94 // For log use only. 95 void logCompositionFallbackIfChanged(Composition to); 96 97 private: 98 const int64_t mId; 99 common::Point mCursorPosition; 100 FencedBuffer mBuffer; 101 common::BlendMode mBlendMode = common::BlendMode::NONE; 102 Color mColor = {0, 0, 0, 0}; 103 Composition mCompositionType = Composition::INVALID; 104 common::Dataspace mDataspace = common::Dataspace::UNKNOWN; 105 struct CompositionTypeFallback { 106 Composition from; 107 Composition to; 108 }; 109 // For log use only. 110 std::optional<CompositionTypeFallback> mLastCompositionFallback = std::nullopt; 111 common::Rect mDisplayFrame = {0, 0, -1, -1}; 112 float mPlaneAlpha = 0.0f; 113 common::FRect mSourceCrop = {0.0f, 0.0f, -1.0f, -1.0f}; 114 common::Transform mTransform = common::Transform{0}; 115 std::vector<common::Rect> mVisibleRegion; 116 int32_t mZOrder = 0; 117 std::optional<std::array<float, 16>> mColorTransform; 118 float mBrightness = 1.0f; 119 }; 120 121 } // namespace aidl::android::hardware::graphics::composer3::impl 122 123 #endif 124