• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
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 
26 #include <gralloc_priv.h>
27 #include <qdMetaData.h>
28 #include <core/layer_stack.h>
29 #define HWC2_INCLUDE_STRINGIFICATION
30 #define HWC2_USE_CPP11
31 #include <hardware/hwcomposer2.h>
32 #undef HWC2_INCLUDE_STRINGIFICATION
33 #undef HWC2_USE_CPP11
34 #include <android/hardware/graphics/common/1.1/types.h>
35 #include <android/hardware/graphics/composer/2.2/IComposerClient.h>
36 #include <deque>
37 #include <map>
38 #include <set>
39 #include "core/buffer_allocator.h"
40 #include "hwc_buffer_allocator.h"
41 
42 using android::hardware::graphics::common::V1_1::ColorMode;
43 using PerFrameMetadataKey =
44     android::hardware::graphics::composer::V2_2::IComposerClient::PerFrameMetadataKey;
45 
46 namespace sdm {
47 
48 DisplayError SetCSC(const private_handle_t *pvt_handle, ColorMetaData *color_metadata);
49 bool GetColorPrimary(const int32_t &dataspace, ColorPrimaries *color_primary);
50 bool GetTransfer(const int32_t &dataspace, GammaTransfer *gamma_transfer);
51 void GetRange(const int32_t &dataspace, ColorRange *color_range);
52 bool GetSDMColorSpace(const int32_t &dataspace, ColorMetaData *color_metadata);
53 bool IsBT2020(const ColorPrimaries &color_primary);
54 int32_t GetDataspace(ColorMode mode);
55 
56 enum GeometryChanges {
57   kNone         = 0x000,
58   kBlendMode    = 0x001,
59   kDataspace    = 0x002,
60   kDisplayFrame = 0x004,
61   kPlaneAlpha   = 0x008,
62   kSourceCrop   = 0x010,
63   kTransform    = 0x020,
64   kZOrder       = 0x040,
65   kAdded        = 0x080,
66   kRemoved      = 0x100,
67   kBufferGeometry = 0x200,
68 };
69 
70 class HWCLayer {
71  public:
72   explicit HWCLayer(hwc2_display_t display_id, HWCBufferAllocator *buf_allocator);
73   ~HWCLayer();
GetZ()74   uint32_t GetZ() const { return z_; }
GetId()75   hwc2_layer_t GetId() const { return id_; }
GetSDMLayer()76   Layer *GetSDMLayer() { return layer_; }
77   void ResetPerFrameData();
78 
79   HWC2::Error SetLayerBlendMode(HWC2::BlendMode mode);
80   HWC2::Error SetLayerBuffer(buffer_handle_t buffer, int32_t acquire_fence);
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);
85   HWC2::Error SetCursorPosition(int32_t x, int32_t y);
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);
91   HWC2::Error SetLayerPerFrameMetadata(uint32_t num_elements, const PerFrameMetadataKey *keys,
92                                        const float *metadata);
93   HWC2::Error SetLayerZOrder(uint32_t z);
94   void SetComposition(const LayerComposition &sdm_composition);
GetClientRequestedCompositionType()95   HWC2::Composition GetClientRequestedCompositionType() { return client_requested_; }
UpdateClientCompositionType(HWC2::Composition type)96   void UpdateClientCompositionType(HWC2::Composition type) { client_requested_ = type; }
GetDeviceSelectedCompositionType()97   HWC2::Composition GetDeviceSelectedCompositionType() { return device_selected_; }
GetLayerDataspace()98   int32_t GetLayerDataspace() { return dataspace_; }
GetGeometryChanges()99   uint32_t GetGeometryChanges() { return geometry_changes_; }
ResetGeometryChanges()100   void ResetGeometryChanges() { geometry_changes_ = GeometryChanges::kNone; }
101   void PushBackReleaseFence(int32_t fence);
102   int32_t PopBackReleaseFence(void);
103   int32_t PopFrontReleaseFence(void);
104   bool ValidateAndSetCSC();
105   bool SupportLocalConversion(ColorPrimaries working_primaries);
ResetValidation()106   void ResetValidation() { needs_validate_ = false; }
NeedsValidation()107   bool NeedsValidation() { return (needs_validate_ || geometry_changes_); }
IsSingleBuffered()108   bool IsSingleBuffered() { return single_buffer_; }
109   bool IsScalingPresent();
110   bool IsRotationPresent();
IsSurfaceUpdated()111   bool IsSurfaceUpdated() { return surface_updated_; }
IsNonIntegralSourceCrop()112   bool IsNonIntegralSourceCrop() { return non_integral_source_crop_; }
HasMetaDataRefreshRate()113   bool HasMetaDataRefreshRate() { return has_metadata_refresh_rate_; }
SetPartialUpdate(bool enabled)114   void SetPartialUpdate(bool enabled) { partial_update_enabled_ = enabled; }
115 
116  private:
117   Layer *layer_ = nullptr;
118   uint32_t z_ = 0;
119   const hwc2_layer_t id_;
120   const hwc2_display_t display_id_;
121   static std::atomic<hwc2_layer_t> next_id_;
122   std::deque<int32_t> release_fences_;
123   HWCBufferAllocator *buffer_allocator_ = NULL;
124   int32_t dataspace_ =  HAL_DATASPACE_UNKNOWN;
125   LayerTransform layer_transform_ = {};
126   LayerRect dst_rect_ = {};
127   bool needs_validate_ = true;
128   bool single_buffer_ = false;
129   int buffer_fd_ = -1;
130   bool non_integral_source_crop_ = false;
131   bool has_metadata_refresh_rate_ = false;
132   bool partial_update_enabled_ = false;
133   bool surface_updated_ = true;
134 
135   // Composition requested by client(SF)
136   HWC2::Composition client_requested_ = HWC2::Composition::Device;
137   // Composition selected by SDM
138   HWC2::Composition device_selected_ = HWC2::Composition::Device;
139   uint32_t geometry_changes_ = GeometryChanges::kNone;
140 
141   void SetRect(const hwc_rect_t &source, LayerRect *target);
142   void SetRect(const hwc_frect_t &source, LayerRect *target);
143   uint32_t GetUint32Color(const hwc_color_t &source);
144   LayerBufferFormat GetSDMFormat(const int32_t &source, const int flags);
145   LayerBufferS3DFormat GetS3DFormat(uint32_t s3d_format);
146   void GetUBWCStatsFromMetaData(UBWCStats *cr_stats, UbwcCrStatsVector *cr_vec);
147   DisplayError SetMetaData(const private_handle_t *pvt_handle, Layer *layer);
148   DisplayError SetIGC(IGC_t source, LayerIGC *target);
149   uint32_t RoundToStandardFPS(float fps);
150   void SetDirtyRegions(hwc_region_t surface_damage);
151 };
152 
153 struct SortLayersByZ {
operatorSortLayersByZ154   bool operator()(const HWCLayer *lhs, const HWCLayer *rhs) const {
155     return lhs->GetZ() < rhs->GetZ();
156   }
157 };
158 
159 }  // namespace sdm
160 #endif  // __HWC_LAYERS_H__
161