blob: b60affabad6e2fa1be76d598223f15204edf8cab [file] [log] [blame]
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001/*
Rheygine Medeled1bc342020-04-22 16:34:51 -04002 * Copyright (c) 2014-2021, The Linux Foundation. All rights reserved.
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05003 * 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 Medeled1bc342020-04-22 16:34:51 -040026#include <QtiGralloc.h>
Gurkaran Singh6f2c67b2021-10-28 16:31:22 -070027#include <QtiGrallocDefs.h>
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050028#include <core/layer_stack.h>
Pullakavi Srinivas2fbff8d2019-04-22 18:32:52 -070029#include <core/layer_buffer.h>
Saurabh Dubey66b807e2018-05-11 10:05:07 +053030#include <utils/utils.h>
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050031#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 Nadaf4b096d02019-10-24 15:39:59 +053036#include <android/hardware/graphics/composer/2.3/IComposerClient.h>
Ramakant Singh907df9e2020-12-16 11:19:18 +053037#include <vendor/qti/hardware/display/composer/3.1/IQtiComposerClient.h>
Naseer Ahmed62ef5282020-02-19 22:23:30 -050038
Naseer Ahmeda6782e42018-06-04 10:56:04 -040039#include <map>
Naseer Ahmed42752212017-01-27 17:32:21 -050040#include <set>
Naseer Ahmed62ef5282020-02-19 22:23:30 -050041
Naseer Ahmed42752212017-01-27 17:32:21 -050042#include "core/buffer_allocator.h"
43#include "hwc_buffer_allocator.h"
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050044
Naseer Ahmeda6782e42018-06-04 10:56:04 -040045using PerFrameMetadataKey =
Gousemoodhin Nadaf4b096d02019-10-24 15:39:59 +053046 android::hardware::graphics::composer::V2_3::IComposerClient::PerFrameMetadataKey;
Ramakant Singh907df9e2020-12-16 11:19:18 +053047using vendor::qti::hardware::display::composer::V3_1::IQtiComposerClient;
Sabarinath M B63bf59f2021-11-12 07:10:07 +053048using android::hardware::graphics::common::V1_2::Dataspace;
Gurkaran Singh6f2c67b2021-10-28 16:31:22 -070049using android::hardware::graphics::common::V1_2::PixelFormat;
Naseer Ahmeda6782e42018-06-04 10:56:04 -040050
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050051namespace sdm {
52
Sushil Chauhan2c9d6a62021-04-15 18:03:18 -070053DisplayError SetCSC(const private_handle_t *pvt_handle, ColorMetaData *color_metadata);
Arun Kumar K.R80e58eb2017-07-13 10:37:00 +053054bool GetColorPrimary(const int32_t &dataspace, ColorPrimaries *color_primary);
55bool GetTransfer(const int32_t &dataspace, GammaTransfer *gamma_transfer);
Arun Kumar K.Rd761c1a2018-04-26 19:47:44 +053056bool GetRange(const int32_t &dataspace, ColorRange *color_range);
Arun Kumar K.R80e58eb2017-07-13 10:37:00 +053057bool GetSDMColorSpace(const int32_t &dataspace, ColorMetaData *color_metadata);
58bool IsBT2020(const ColorPrimaries &color_primary);
Arun Kumar K.R4aa2c4c2018-05-14 11:45:00 +053059int32_t TranslateFromLegacyDataspace(const int32_t &legacy_ds);
Sabarinath M B63bf59f2021-11-12 07:10:07 +053060DisplayError ColorMetadataToDataspace(ColorMetaData color_metadata, Dataspace *dataspace);
Arun Kumar K.R4aa2c4c2018-05-14 11:45:00 +053061
Ray Zhang2ee82472019-09-05 02:53:29 +080062enum LayerTypes {
63 kLayerUnknown = 0,
64 kLayerApp = 1,
65 kLayerGame = 2,
66 kLayerBrowser = 3,
67};
68
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050069class HWCLayer {
70 public:
Naseer Ahmed42752212017-01-27 17:32:21 -050071 explicit HWCLayer(hwc2_display_t display_id, HWCBufferAllocator *buf_allocator);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050072 ~HWCLayer();
73 uint32_t GetZ() const { return z_; }
74 hwc2_layer_t GetId() const { return id_; }
Ray Zhang2ee82472019-09-05 02:53:29 +080075 LayerTypes GetType() const { return type_; }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050076 Layer *GetSDMLayer() { return layer_; }
Prabhanjan Kandula5265b052017-05-30 17:13:40 -070077 void ResetPerFrameData();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050078
79 HWC2::Error SetLayerBlendMode(HWC2::BlendMode mode);
Rajavenu Kyathamdb8788e2019-12-30 19:52:16 +053080 HWC2::Error SetLayerBuffer(buffer_handle_t buffer, shared_ptr<Fence> acquire_fence);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050081 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 Srinivas68a166c2017-05-24 12:17:07 +053085 HWC2::Error SetCursorPosition(int32_t x, int32_t y);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050086 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 Ahmeda6782e42018-06-04 10:56:04 -040091 HWC2::Error SetLayerPerFrameMetadata(uint32_t num_elements, const PerFrameMetadataKey *keys,
92 const float *metadata);
Gousemoodhin Nadaf4b096d02019-10-24 15:39:59 +053093 HWC2::Error SetLayerPerFrameMetadataBlobs(uint32_t num_elements, const PerFrameMetadataKey *keys,
Gurkaran Singh6f2c67b2021-10-28 16:31:22 -070094 const uint32_t *sizes, const uint8_t *metadata);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050095 HWC2::Error SetLayerZOrder(uint32_t z);
Ray Zhang2ee82472019-09-05 02:53:29 +080096 HWC2::Error SetLayerType(IQtiComposerClient::LayerType type);
Pullakavi Srinivasfee9dc62021-01-12 16:16:30 +053097 HWC2::Error SetLayerFlag(IQtiComposerClient::LayerFlag flag);
Tharaga Balachandran209db582019-03-25 18:56:50 -040098 HWC2::Error SetLayerColorTransform(const float *matrix);
Arun Kumar K.R2c0ff8d2016-06-01 16:56:52 -070099 void SetComposition(const LayerComposition &sdm_composition);
100 HWC2::Composition GetClientRequestedCompositionType() { return client_requested_; }
Rheygine Medelf9918e32019-07-16 12:30:44 -0400101 HWC2::Composition GetOrigClientRequestedCompositionType() { return client_requested_orig_; }
Naseer Ahmed63c2b5d2016-08-25 16:54:41 -0400102 void UpdateClientCompositionType(HWC2::Composition type) { client_requested_ = type; }
Arun Kumar K.R2c0ff8d2016-06-01 16:56:52 -0700103 HWC2::Composition GetDeviceSelectedCompositionType() { return device_selected_; }
Naseer Ahmedade4ee62016-10-07 17:07:38 -0400104 int32_t GetLayerDataspace() { return dataspace_; }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500105 uint32_t GetGeometryChanges() { return geometry_changes_; }
Sushil Chauhanc679c612020-12-14 13:01:50 -0800106 void ResetGeometryChanges();
Sushil Chauhand1906042019-04-05 14:03:19 -0700107 void ResetValidation() { layer_->update_mask.reset(); }
108 bool NeedsValidation() { return (geometry_changes_ || layer_->update_mask.any()); }
Ramakant Singhae057092017-08-31 12:34:54 +0530109 bool IsSingleBuffered() { return single_buffer_; }
110 bool IsScalingPresent();
111 bool IsRotationPresent();
Saurabh Dubey66b807e2018-05-11 10:05:07 +0530112 bool IsDataSpaceSupported();
Naseer Ahmed4ecea222019-09-24 15:07:39 -0400113 bool IsProtected() { return secure_; }
Gousemoodhin Nadafa990d722018-04-04 08:33:43 +0530114 static LayerBufferFormat GetSDMFormat(const int32_t &source, const int flags);
Sushil Chauhan9735cf82018-07-10 12:06:01 -0700115 bool IsSurfaceUpdated() { return surface_updated_; }
Pullakavi Srinivase08594d2017-12-28 12:46:02 +0530116 bool IsNonIntegralSourceCrop() { return non_integral_source_crop_; }
Pullakavi Srinivas3dbb0d92018-03-07 15:15:14 +0530117 bool HasMetaDataRefreshRate() { return has_metadata_refresh_rate_; }
Tharaga Balachandran209db582019-03-25 18:56:50 -0400118 bool IsColorTransformSet() { return color_transform_matrix_set_; }
Pullakavi Srinivas2fbff8d2019-04-22 18:32:52 -0700119 void SetLayerAsMask();
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700120 bool BufferLatched() { return buffer_flipped_; }
121 void ResetBufferFlip() { buffer_flipped_ = false; }
Pullakavi Srinivas49032c42021-01-19 18:52:30 +0530122 shared_ptr<Fence> GetReleaseFence();
123 void SetReleaseFence(const shared_ptr<Fence> &release_fence);
Pullakavi Srinivasfee9dc62021-01-12 16:16:30 +0530124 bool IsLayerCompatible() { return compatible_; }
Gurkaran Singh6f2c67b2021-10-28 16:31:22 -0700125 void IgnoreSdrContentMetadata(bool disable) { ignore_sdr_content_md_ = disable; }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500126
127 private:
128 Layer *layer_ = nullptr;
Ray Zhang2ee82472019-09-05 02:53:29 +0800129 LayerTypes type_ = kLayerUnknown;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500130 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 Srinivas49032c42021-01-19 18:52:30 +0530134 shared_ptr<Fence> release_fence_;
Naseer Ahmed42752212017-01-27 17:32:21 -0500135 HWCBufferAllocator *buffer_allocator_ = NULL;
Gurkaran Singh6f2c67b2021-10-28 16:31:22 -0700136 int32_t dataspace_ = HAL_DATASPACE_UNKNOWN;
Prabhanjan Kandula5265b052017-05-30 17:13:40 -0700137 LayerTransform layer_transform_ = {};
138 LayerRect dst_rect_ = {};
Ramakant Singhae057092017-08-31 12:34:54 +0530139 bool single_buffer_ = false;
Ramkumar Radhakrishnan525e6432017-12-15 16:43:07 -0800140 int buffer_fd_ = -1;
Saurabh Dubey66b807e2018-05-11 10:05:07 +0530141 bool dataspace_supported_ = false;
Sushil Chauhan9735cf82018-07-10 12:06:01 -0700142 bool surface_updated_ = true;
Pullakavi Srinivase08594d2017-12-28 12:46:02 +0530143 bool non_integral_source_crop_ = false;
Pullakavi Srinivas3dbb0d92018-03-07 15:15:14 +0530144 bool has_metadata_refresh_rate_ = false;
Tharaga Balachandran209db582019-03-25 18:56:50 -0400145 bool color_transform_matrix_set_ = false;
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700146 bool buffer_flipped_ = false;
Naseer Ahmed4ecea222019-09-24 15:07:39 -0400147 bool secure_ = false;
Pullakavi Srinivasfee9dc62021-01-12 16:16:30 +0530148 bool compatible_ = false;
Christopher Bragaf7a92c12021-09-07 16:56:35 -0400149 bool ignore_sdr_content_md_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500150
Rheygine Medelf9918e32019-07-16 12:30:44 -0400151 // 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.R2c0ff8d2016-06-01 16:56:52 -0700154 HWC2::Composition client_requested_ = HWC2::Composition::Device;
155 // Composition selected by SDM
156 HWC2::Composition device_selected_ = HWC2::Composition::Device;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500157 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 Ramaswamyf081afe2017-07-04 22:08:36 -0700162 void GetUBWCStatsFromMetaData(UBWCStats *cr_stats, UbwcCrStatsVector *cr_vec);
Sushil Chauhan2c9d6a62021-04-15 18:03:18 -0700163 DisplayError SetMetaData(const private_handle_t *pvt_handle, Layer *layer);
Naseer Ahmed89ff4522016-05-17 11:36:27 -0400164 uint32_t RoundToStandardFPS(float fps);
Sushil Chauhan2c9d6a62021-04-15 18:03:18 -0700165 void ValidateAndSetCSC(const private_handle_t *handle);
Sushil Chauhan9735cf82018-07-10 12:06:01 -0700166 void SetDirtyRegions(hwc_region_t surface_damage);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500167};
168
169struct SortLayersByZ {
Naseer Ahmedf81aac32017-06-09 18:33:07 -0400170 bool operator()(const HWCLayer *lhs, const HWCLayer *rhs) const {
Naseer Ahmed72dea242016-05-03 19:13:07 -0400171 return lhs->GetZ() < rhs->GetZ();
172 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500173};
174
175} // namespace sdm
176#endif // __HWC_LAYERS_H__