Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1 | /* |
Rheygine Medel | ed1bc34 | 2020-04-22 16:34:51 -0400 | [diff] [blame] | 2 | * Copyright (c) 2014-2021, The Linux Foundation. All rights reserved. |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 3 | * Not a Contribution. |
| 4 | * |
| 5 | * Copyright 2015 The Android Open Source Project |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
| 19 | |
| 20 | #ifndef __HWC_LAYERS_H__ |
| 21 | #define __HWC_LAYERS_H__ |
| 22 | |
| 23 | /* This class translates HWC2 Layer functions to the SDM LayerStack |
| 24 | */ |
| 25 | |
Rheygine Medel | ed1bc34 | 2020-04-22 16:34:51 -0400 | [diff] [blame] | 26 | #include <QtiGralloc.h> |
Gurkaran Singh | 6f2c67b | 2021-10-28 16:31:22 -0700 | [diff] [blame^] | 27 | #include <QtiGrallocDefs.h> |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 28 | #include <core/layer_stack.h> |
Pullakavi Srinivas | 2fbff8d | 2019-04-22 18:32:52 -0700 | [diff] [blame] | 29 | #include <core/layer_buffer.h> |
Saurabh Dubey | 66b807e | 2018-05-11 10:05:07 +0530 | [diff] [blame] | 30 | #include <utils/utils.h> |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 31 | #define HWC2_INCLUDE_STRINGIFICATION |
| 32 | #define HWC2_USE_CPP11 |
| 33 | #include <hardware/hwcomposer2.h> |
| 34 | #undef HWC2_INCLUDE_STRINGIFICATION |
| 35 | #undef HWC2_USE_CPP11 |
Gousemoodhin Nadaf | 4b096d0 | 2019-10-24 15:39:59 +0530 | [diff] [blame] | 36 | #include <android/hardware/graphics/composer/2.3/IComposerClient.h> |
Ramakant Singh | 907df9e | 2020-12-16 11:19:18 +0530 | [diff] [blame] | 37 | #include <vendor/qti/hardware/display/composer/3.1/IQtiComposerClient.h> |
Naseer Ahmed | 62ef528 | 2020-02-19 22:23:30 -0500 | [diff] [blame] | 38 | |
Naseer Ahmed | a6782e4 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 39 | #include <map> |
Naseer Ahmed | 4275221 | 2017-01-27 17:32:21 -0500 | [diff] [blame] | 40 | #include <set> |
Naseer Ahmed | 62ef528 | 2020-02-19 22:23:30 -0500 | [diff] [blame] | 41 | |
Naseer Ahmed | 4275221 | 2017-01-27 17:32:21 -0500 | [diff] [blame] | 42 | #include "core/buffer_allocator.h" |
| 43 | #include "hwc_buffer_allocator.h" |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 44 | |
Naseer Ahmed | a6782e4 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 45 | using PerFrameMetadataKey = |
Gousemoodhin Nadaf | 4b096d0 | 2019-10-24 15:39:59 +0530 | [diff] [blame] | 46 | android::hardware::graphics::composer::V2_3::IComposerClient::PerFrameMetadataKey; |
Ramakant Singh | 907df9e | 2020-12-16 11:19:18 +0530 | [diff] [blame] | 47 | using vendor::qti::hardware::display::composer::V3_1::IQtiComposerClient; |
Sabarinath M B | 63bf59f | 2021-11-12 07:10:07 +0530 | [diff] [blame] | 48 | using android::hardware::graphics::common::V1_2::Dataspace; |
Gurkaran Singh | 6f2c67b | 2021-10-28 16:31:22 -0700 | [diff] [blame^] | 49 | using android::hardware::graphics::common::V1_2::PixelFormat; |
Naseer Ahmed | a6782e4 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 50 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 51 | namespace sdm { |
| 52 | |
Sushil Chauhan | 2c9d6a6 | 2021-04-15 18:03:18 -0700 | [diff] [blame] | 53 | DisplayError SetCSC(const private_handle_t *pvt_handle, ColorMetaData *color_metadata); |
Arun Kumar K.R | 80e58eb | 2017-07-13 10:37:00 +0530 | [diff] [blame] | 54 | bool GetColorPrimary(const int32_t &dataspace, ColorPrimaries *color_primary); |
| 55 | bool GetTransfer(const int32_t &dataspace, GammaTransfer *gamma_transfer); |
Arun Kumar K.R | d761c1a | 2018-04-26 19:47:44 +0530 | [diff] [blame] | 56 | bool GetRange(const int32_t &dataspace, ColorRange *color_range); |
Arun Kumar K.R | 80e58eb | 2017-07-13 10:37:00 +0530 | [diff] [blame] | 57 | bool GetSDMColorSpace(const int32_t &dataspace, ColorMetaData *color_metadata); |
| 58 | bool IsBT2020(const ColorPrimaries &color_primary); |
Arun Kumar K.R | 4aa2c4c | 2018-05-14 11:45:00 +0530 | [diff] [blame] | 59 | int32_t TranslateFromLegacyDataspace(const int32_t &legacy_ds); |
Sabarinath M B | 63bf59f | 2021-11-12 07:10:07 +0530 | [diff] [blame] | 60 | DisplayError ColorMetadataToDataspace(ColorMetaData color_metadata, Dataspace *dataspace); |
Arun Kumar K.R | 4aa2c4c | 2018-05-14 11:45:00 +0530 | [diff] [blame] | 61 | |
Ray Zhang | 2ee8247 | 2019-09-05 02:53:29 +0800 | [diff] [blame] | 62 | enum LayerTypes { |
| 63 | kLayerUnknown = 0, |
| 64 | kLayerApp = 1, |
| 65 | kLayerGame = 2, |
| 66 | kLayerBrowser = 3, |
| 67 | }; |
| 68 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 69 | class HWCLayer { |
| 70 | public: |
Naseer Ahmed | 4275221 | 2017-01-27 17:32:21 -0500 | [diff] [blame] | 71 | explicit HWCLayer(hwc2_display_t display_id, HWCBufferAllocator *buf_allocator); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 72 | ~HWCLayer(); |
| 73 | uint32_t GetZ() const { return z_; } |
| 74 | hwc2_layer_t GetId() const { return id_; } |
Ray Zhang | 2ee8247 | 2019-09-05 02:53:29 +0800 | [diff] [blame] | 75 | LayerTypes GetType() const { return type_; } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 76 | Layer *GetSDMLayer() { return layer_; } |
Prabhanjan Kandula | 5265b05 | 2017-05-30 17:13:40 -0700 | [diff] [blame] | 77 | void ResetPerFrameData(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 78 | |
| 79 | HWC2::Error SetLayerBlendMode(HWC2::BlendMode mode); |
Rajavenu Kyatham | db8788e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 80 | HWC2::Error SetLayerBuffer(buffer_handle_t buffer, shared_ptr<Fence> acquire_fence); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 81 | HWC2::Error SetLayerColor(hwc_color_t color); |
| 82 | HWC2::Error SetLayerCompositionType(HWC2::Composition type); |
| 83 | HWC2::Error SetLayerDataspace(int32_t dataspace); |
| 84 | HWC2::Error SetLayerDisplayFrame(hwc_rect_t frame); |
Pullakavi Srinivas | 68a166c | 2017-05-24 12:17:07 +0530 | [diff] [blame] | 85 | HWC2::Error SetCursorPosition(int32_t x, int32_t y); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 86 | HWC2::Error SetLayerPlaneAlpha(float alpha); |
| 87 | HWC2::Error SetLayerSourceCrop(hwc_frect_t crop); |
| 88 | HWC2::Error SetLayerSurfaceDamage(hwc_region_t damage); |
| 89 | HWC2::Error SetLayerTransform(HWC2::Transform transform); |
| 90 | HWC2::Error SetLayerVisibleRegion(hwc_region_t visible); |
Naseer Ahmed | a6782e4 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 91 | HWC2::Error SetLayerPerFrameMetadata(uint32_t num_elements, const PerFrameMetadataKey *keys, |
| 92 | const float *metadata); |
Gousemoodhin Nadaf | 4b096d0 | 2019-10-24 15:39:59 +0530 | [diff] [blame] | 93 | HWC2::Error SetLayerPerFrameMetadataBlobs(uint32_t num_elements, const PerFrameMetadataKey *keys, |
Gurkaran Singh | 6f2c67b | 2021-10-28 16:31:22 -0700 | [diff] [blame^] | 94 | const uint32_t *sizes, const uint8_t *metadata); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 95 | HWC2::Error SetLayerZOrder(uint32_t z); |
Ray Zhang | 2ee8247 | 2019-09-05 02:53:29 +0800 | [diff] [blame] | 96 | HWC2::Error SetLayerType(IQtiComposerClient::LayerType type); |
Pullakavi Srinivas | fee9dc6 | 2021-01-12 16:16:30 +0530 | [diff] [blame] | 97 | HWC2::Error SetLayerFlag(IQtiComposerClient::LayerFlag flag); |
Tharaga Balachandran | 209db58 | 2019-03-25 18:56:50 -0400 | [diff] [blame] | 98 | HWC2::Error SetLayerColorTransform(const float *matrix); |
Arun Kumar K.R | 2c0ff8d | 2016-06-01 16:56:52 -0700 | [diff] [blame] | 99 | void SetComposition(const LayerComposition &sdm_composition); |
| 100 | HWC2::Composition GetClientRequestedCompositionType() { return client_requested_; } |
Rheygine Medel | f9918e3 | 2019-07-16 12:30:44 -0400 | [diff] [blame] | 101 | HWC2::Composition GetOrigClientRequestedCompositionType() { return client_requested_orig_; } |
Naseer Ahmed | 63c2b5d | 2016-08-25 16:54:41 -0400 | [diff] [blame] | 102 | void UpdateClientCompositionType(HWC2::Composition type) { client_requested_ = type; } |
Arun Kumar K.R | 2c0ff8d | 2016-06-01 16:56:52 -0700 | [diff] [blame] | 103 | HWC2::Composition GetDeviceSelectedCompositionType() { return device_selected_; } |
Naseer Ahmed | ade4ee6 | 2016-10-07 17:07:38 -0400 | [diff] [blame] | 104 | int32_t GetLayerDataspace() { return dataspace_; } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 105 | uint32_t GetGeometryChanges() { return geometry_changes_; } |
Sushil Chauhan | c679c61 | 2020-12-14 13:01:50 -0800 | [diff] [blame] | 106 | void ResetGeometryChanges(); |
Sushil Chauhan | d190604 | 2019-04-05 14:03:19 -0700 | [diff] [blame] | 107 | void ResetValidation() { layer_->update_mask.reset(); } |
| 108 | bool NeedsValidation() { return (geometry_changes_ || layer_->update_mask.any()); } |
Ramakant Singh | ae05709 | 2017-08-31 12:34:54 +0530 | [diff] [blame] | 109 | bool IsSingleBuffered() { return single_buffer_; } |
| 110 | bool IsScalingPresent(); |
| 111 | bool IsRotationPresent(); |
Saurabh Dubey | 66b807e | 2018-05-11 10:05:07 +0530 | [diff] [blame] | 112 | bool IsDataSpaceSupported(); |
Naseer Ahmed | 4ecea22 | 2019-09-24 15:07:39 -0400 | [diff] [blame] | 113 | bool IsProtected() { return secure_; } |
Gousemoodhin Nadaf | a990d72 | 2018-04-04 08:33:43 +0530 | [diff] [blame] | 114 | static LayerBufferFormat GetSDMFormat(const int32_t &source, const int flags); |
Sushil Chauhan | 9735cf8 | 2018-07-10 12:06:01 -0700 | [diff] [blame] | 115 | bool IsSurfaceUpdated() { return surface_updated_; } |
Pullakavi Srinivas | e08594d | 2017-12-28 12:46:02 +0530 | [diff] [blame] | 116 | bool IsNonIntegralSourceCrop() { return non_integral_source_crop_; } |
Pullakavi Srinivas | 3dbb0d9 | 2018-03-07 15:15:14 +0530 | [diff] [blame] | 117 | bool HasMetaDataRefreshRate() { return has_metadata_refresh_rate_; } |
Tharaga Balachandran | 209db58 | 2019-03-25 18:56:50 -0400 | [diff] [blame] | 118 | bool IsColorTransformSet() { return color_transform_matrix_set_; } |
Pullakavi Srinivas | 2fbff8d | 2019-04-22 18:32:52 -0700 | [diff] [blame] | 119 | void SetLayerAsMask(); |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 120 | bool BufferLatched() { return buffer_flipped_; } |
| 121 | void ResetBufferFlip() { buffer_flipped_ = false; } |
Pullakavi Srinivas | 49032c4 | 2021-01-19 18:52:30 +0530 | [diff] [blame] | 122 | shared_ptr<Fence> GetReleaseFence(); |
| 123 | void SetReleaseFence(const shared_ptr<Fence> &release_fence); |
Pullakavi Srinivas | fee9dc6 | 2021-01-12 16:16:30 +0530 | [diff] [blame] | 124 | bool IsLayerCompatible() { return compatible_; } |
Gurkaran Singh | 6f2c67b | 2021-10-28 16:31:22 -0700 | [diff] [blame^] | 125 | void IgnoreSdrContentMetadata(bool disable) { ignore_sdr_content_md_ = disable; } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 126 | |
| 127 | private: |
| 128 | Layer *layer_ = nullptr; |
Ray Zhang | 2ee8247 | 2019-09-05 02:53:29 +0800 | [diff] [blame] | 129 | LayerTypes type_ = kLayerUnknown; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 130 | uint32_t z_ = 0; |
| 131 | const hwc2_layer_t id_; |
| 132 | const hwc2_display_t display_id_; |
| 133 | static std::atomic<hwc2_layer_t> next_id_; |
Pullakavi Srinivas | 49032c4 | 2021-01-19 18:52:30 +0530 | [diff] [blame] | 134 | shared_ptr<Fence> release_fence_; |
Naseer Ahmed | 4275221 | 2017-01-27 17:32:21 -0500 | [diff] [blame] | 135 | HWCBufferAllocator *buffer_allocator_ = NULL; |
Gurkaran Singh | 6f2c67b | 2021-10-28 16:31:22 -0700 | [diff] [blame^] | 136 | int32_t dataspace_ = HAL_DATASPACE_UNKNOWN; |
Prabhanjan Kandula | 5265b05 | 2017-05-30 17:13:40 -0700 | [diff] [blame] | 137 | LayerTransform layer_transform_ = {}; |
| 138 | LayerRect dst_rect_ = {}; |
Ramakant Singh | ae05709 | 2017-08-31 12:34:54 +0530 | [diff] [blame] | 139 | bool single_buffer_ = false; |
Ramkumar Radhakrishnan | 525e643 | 2017-12-15 16:43:07 -0800 | [diff] [blame] | 140 | int buffer_fd_ = -1; |
Saurabh Dubey | 66b807e | 2018-05-11 10:05:07 +0530 | [diff] [blame] | 141 | bool dataspace_supported_ = false; |
Sushil Chauhan | 9735cf8 | 2018-07-10 12:06:01 -0700 | [diff] [blame] | 142 | bool surface_updated_ = true; |
Pullakavi Srinivas | e08594d | 2017-12-28 12:46:02 +0530 | [diff] [blame] | 143 | bool non_integral_source_crop_ = false; |
Pullakavi Srinivas | 3dbb0d9 | 2018-03-07 15:15:14 +0530 | [diff] [blame] | 144 | bool has_metadata_refresh_rate_ = false; |
Tharaga Balachandran | 209db58 | 2019-03-25 18:56:50 -0400 | [diff] [blame] | 145 | bool color_transform_matrix_set_ = false; |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 146 | bool buffer_flipped_ = false; |
Naseer Ahmed | 4ecea22 | 2019-09-24 15:07:39 -0400 | [diff] [blame] | 147 | bool secure_ = false; |
Pullakavi Srinivas | fee9dc6 | 2021-01-12 16:16:30 +0530 | [diff] [blame] | 148 | bool compatible_ = false; |
Christopher Braga | f7a92c1 | 2021-09-07 16:56:35 -0400 | [diff] [blame] | 149 | bool ignore_sdr_content_md_ = false; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 150 | |
Rheygine Medel | f9918e3 | 2019-07-16 12:30:44 -0400 | [diff] [blame] | 151 | // Composition requested by client(SF) Original |
| 152 | HWC2::Composition client_requested_orig_ = HWC2::Composition::Device; |
| 153 | // Composition requested by client(SF) Modified for internel use |
Arun Kumar K.R | 2c0ff8d | 2016-06-01 16:56:52 -0700 | [diff] [blame] | 154 | HWC2::Composition client_requested_ = HWC2::Composition::Device; |
| 155 | // Composition selected by SDM |
| 156 | HWC2::Composition device_selected_ = HWC2::Composition::Device; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 157 | uint32_t geometry_changes_ = GeometryChanges::kNone; |
| 158 | |
| 159 | void SetRect(const hwc_rect_t &source, LayerRect *target); |
| 160 | void SetRect(const hwc_frect_t &source, LayerRect *target); |
| 161 | uint32_t GetUint32Color(const hwc_color_t &source); |
Gurunath Ramaswamy | f081afe | 2017-07-04 22:08:36 -0700 | [diff] [blame] | 162 | void GetUBWCStatsFromMetaData(UBWCStats *cr_stats, UbwcCrStatsVector *cr_vec); |
Sushil Chauhan | 2c9d6a6 | 2021-04-15 18:03:18 -0700 | [diff] [blame] | 163 | DisplayError SetMetaData(const private_handle_t *pvt_handle, Layer *layer); |
Naseer Ahmed | 89ff452 | 2016-05-17 11:36:27 -0400 | [diff] [blame] | 164 | uint32_t RoundToStandardFPS(float fps); |
Sushil Chauhan | 2c9d6a6 | 2021-04-15 18:03:18 -0700 | [diff] [blame] | 165 | void ValidateAndSetCSC(const private_handle_t *handle); |
Sushil Chauhan | 9735cf8 | 2018-07-10 12:06:01 -0700 | [diff] [blame] | 166 | void SetDirtyRegions(hwc_region_t surface_damage); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | struct SortLayersByZ { |
Naseer Ahmed | f81aac3 | 2017-06-09 18:33:07 -0400 | [diff] [blame] | 170 | bool operator()(const HWCLayer *lhs, const HWCLayer *rhs) const { |
Naseer Ahmed | 72dea24 | 2016-05-03 19:13:07 -0400 | [diff] [blame] | 171 | return lhs->GetZ() < rhs->GetZ(); |
| 172 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | } // namespace sdm |
| 176 | #endif // __HWC_LAYERS_H__ |