• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2014-2017, 2019, 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 <map>
35 #include <queue>
36 #include <set>
37 #include "core/buffer_allocator.h"
38 #include "hwc_buffer_allocator.h"
39 
40 namespace sdm {
41 
42 DisplayError SetCSC(const private_handle_t *pvt_handle, ColorMetaData *color_metadata);
43 bool GetColorPrimary(const int32_t &dataspace, ColorPrimaries *color_primary);
44 bool GetTransfer(const int32_t &dataspace, GammaTransfer *gamma_transfer);
45 void GetRange(const int32_t &dataspace, ColorRange *color_range);
46 bool GetSDMColorSpace(const int32_t &dataspace, ColorMetaData *color_metadata);
47 bool IsBT2020(const ColorPrimaries &color_primary);
48 enum GeometryChanges {
49   kNone         = 0x000,
50   kBlendMode    = 0x001,
51   kDataspace    = 0x002,
52   kDisplayFrame = 0x004,
53   kPlaneAlpha   = 0x008,
54   kSourceCrop   = 0x010,
55   kTransform    = 0x020,
56   kZOrder       = 0x040,
57   kAdded        = 0x080,
58   kRemoved      = 0x100,
59   kBufferGeometry = 0x200,
60 };
61 
62 class HWCLayer {
63  public:
64   explicit HWCLayer(hwc2_display_t display_id, HWCBufferAllocator *buf_allocator);
65   ~HWCLayer();
GetZ()66   uint32_t GetZ() const { return z_; }
GetId()67   hwc2_layer_t GetId() const { return id_; }
GetSDMLayer()68   Layer *GetSDMLayer() { return layer_; }
69 
70   HWC2::Error SetLayerBlendMode(HWC2::BlendMode mode);
71   HWC2::Error SetLayerBuffer(buffer_handle_t buffer, int32_t acquire_fence);
72   HWC2::Error SetLayerColor(hwc_color_t color);
73   HWC2::Error SetLayerCompositionType(HWC2::Composition type);
74   HWC2::Error SetLayerDataspace(int32_t dataspace);
75   HWC2::Error SetLayerDisplayFrame(hwc_rect_t frame);
76   HWC2::Error SetLayerPlaneAlpha(float alpha);
77   HWC2::Error SetLayerSourceCrop(hwc_frect_t crop);
78   HWC2::Error SetLayerSurfaceDamage(hwc_region_t damage);
79   HWC2::Error SetLayerTransform(HWC2::Transform transform);
80   HWC2::Error SetLayerVisibleRegion(hwc_region_t visible);
81   HWC2::Error SetLayerZOrder(uint32_t z);
82   void SetComposition(const LayerComposition &sdm_composition);
GetClientRequestedCompositionType()83   HWC2::Composition GetClientRequestedCompositionType() { return client_requested_; }
UpdateClientCompositionType(HWC2::Composition type)84   void UpdateClientCompositionType(HWC2::Composition type) { client_requested_ = type; }
GetDeviceSelectedCompositionType()85   HWC2::Composition GetDeviceSelectedCompositionType() { return device_selected_; }
GetLayerDataspace()86   int32_t GetLayerDataspace() { return dataspace_; }
GetGeometryChanges()87   uint32_t GetGeometryChanges() { return geometry_changes_; }
ResetGeometryChanges()88   void ResetGeometryChanges() { geometry_changes_ = GeometryChanges::kNone; }
89   void PushReleaseFence(int32_t fence);
90   int32_t PopReleaseFence(void);
91   bool ValidateAndSetCSC();
92   bool SupportLocalConversion(ColorPrimaries working_primaries);
ResetValidation()93   void ResetValidation() { needs_validate_ = false; }
NeedsValidation()94   bool NeedsValidation() { return (needs_validate_ || geometry_changes_); }
IsSurfaceUpdated()95   bool IsSurfaceUpdated() { return surface_updated_; }
SetPartialUpdate(bool enabled)96   void SetPartialUpdate(bool enabled) { partial_update_enabled_ = enabled; }
97 
98  private:
99   Layer *layer_ = nullptr;
100   uint32_t z_ = 0;
101   const hwc2_layer_t id_;
102   const hwc2_display_t display_id_;
103   static std::atomic<hwc2_layer_t> next_id_;
104   std::queue<int32_t> release_fences_;
105   int ion_fd_ = -1;
106   HWCBufferAllocator *buffer_allocator_ = NULL;
107   int32_t dataspace_ =  HAL_DATASPACE_UNKNOWN;
108   bool needs_validate_ = true;
109   bool partial_update_enabled_ = false;
110   bool surface_updated_ = true;
111 
112   // Composition requested by client(SF)
113   HWC2::Composition client_requested_ = HWC2::Composition::Device;
114   // Composition selected by SDM
115   HWC2::Composition device_selected_ = HWC2::Composition::Device;
116   uint32_t geometry_changes_ = GeometryChanges::kNone;
117 
118   void SetRect(const hwc_rect_t &source, LayerRect *target);
119   void SetRect(const hwc_frect_t &source, LayerRect *target);
120   uint32_t GetUint32Color(const hwc_color_t &source);
121   LayerBufferFormat GetSDMFormat(const int32_t &source, const int flags);
122   LayerBufferS3DFormat GetS3DFormat(uint32_t s3d_format);
123   DisplayError SetMetaData(const private_handle_t *pvt_handle, Layer *layer);
124   DisplayError SetIGC(IGC_t source, LayerIGC *target);
125   uint32_t RoundToStandardFPS(float fps);
126   void SetDirtyRegions(hwc_region_t surface_damage);
127 };
128 
129 struct SortLayersByZ {
operatorSortLayersByZ130   bool operator()(const HWCLayer *lhs, const HWCLayer *rhs) const {
131     return lhs->GetZ() < rhs->GetZ();
132   }
133 };
134 
135 }  // namespace sdm
136 #endif  // __HWC_LAYERS_H__
137