• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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_HWC2_DEVICE_HWC_LAYER_H
18 #define ANDROID_HWC2_DEVICE_HWC_LAYER_H
19 
20 #include <hardware/hwcomposer2.h>
21 
22 #include <cmath>
23 
24 #include "drmhwcomposer.h"
25 
26 namespace android {
27 
28 class HwcLayer {
29  public:
GetSfType()30   HWC2::Composition GetSfType() const {
31     return sf_type_;
32   }
GetValidatedType()33   HWC2::Composition GetValidatedType() const {
34     return validated_type_;
35   }
AcceptTypeChange()36   void AcceptTypeChange() {
37     sf_type_ = validated_type_;
38   }
SetValidatedType(HWC2::Composition type)39   void SetValidatedType(HWC2::Composition type) {
40     validated_type_ = type;
41   }
IsTypeChanged()42   bool IsTypeChanged() const {
43     return sf_type_ != validated_type_;
44   }
45 
GetZOrder()46   uint32_t GetZOrder() const {
47     return z_order_;
48   }
49 
GetBuffer()50   buffer_handle_t GetBuffer() {
51     return buffer_;
52   }
53 
GetDisplayFrame()54   hwc_rect_t GetDisplayFrame() {
55     return display_frame_;
56   }
57 
GetReleaseFence()58   UniqueFd GetReleaseFence() {
59     return std::move(release_fence_);
60   }
61 
62   void PopulateDrmLayer(DrmHwcLayer *layer);
63 
RequireScalingOrPhasing()64   bool RequireScalingOrPhasing() const {
65     float src_width = source_crop_.right - source_crop_.left;
66     float src_height = source_crop_.bottom - source_crop_.top;
67 
68     auto dest_width = float(display_frame_.right - display_frame_.left);
69     auto dest_height = float(display_frame_.bottom - display_frame_.top);
70 
71     bool scaling = src_width != dest_width || src_height != dest_height;
72     bool phasing = (source_crop_.left - std::floor(source_crop_.left) != 0) ||
73                    (source_crop_.top - std::floor(source_crop_.top) != 0);
74     return scaling || phasing;
75   }
76 
77   // Layer hooks
78   HWC2::Error SetCursorPosition(int32_t /*x*/, int32_t /*y*/);
79   HWC2::Error SetLayerBlendMode(int32_t 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(int32_t type);
83   HWC2::Error SetLayerDataspace(int32_t dataspace);
84   HWC2::Error SetLayerDisplayFrame(hwc_rect_t frame);
85   HWC2::Error SetLayerPlaneAlpha(float alpha);
86   HWC2::Error SetLayerSidebandStream(const native_handle_t *stream);
87   HWC2::Error SetLayerSourceCrop(hwc_frect_t crop);
88   HWC2::Error SetLayerSurfaceDamage(hwc_region_t damage);
89   HWC2::Error SetLayerTransform(int32_t transform);
90   HWC2::Error SetLayerVisibleRegion(hwc_region_t visible);
91   HWC2::Error SetLayerZOrder(uint32_t order);
92 
93  private:
94   // sf_type_ stores the initial type given to us by surfaceflinger,
95   // validated_type_ stores the type after running ValidateDisplay
96   HWC2::Composition sf_type_ = HWC2::Composition::Invalid;
97   HWC2::Composition validated_type_ = HWC2::Composition::Invalid;
98 
99   buffer_handle_t buffer_ = nullptr;
100   hwc_rect_t display_frame_;
101   static constexpr float kOpaqueFloat = 1.0F;
102   float alpha_ = kOpaqueFloat;
103   hwc_frect_t source_crop_;
104   DrmHwcTransform transform_ = DrmHwcTransform::kIdentity;
105   uint32_t z_order_ = 0;
106   DrmHwcBlending blending_ = DrmHwcBlending::kNone;
107   DrmHwcColorSpace color_space_ = DrmHwcColorSpace::kUndefined;
108   DrmHwcSampleRange sample_range_ = DrmHwcSampleRange::kUndefined;
109 
110   UniqueFd acquire_fence_;
111 
112   /*
113    * Release fence is not used.
114    * There is no release fence support available in the DRM/KMS. In case no
115    * release fence provided application will use this buffer for writing when
116    * the next frame present fence is signaled.
117    */
118   UniqueFd release_fence_;
119 };
120 
121 }  // namespace android
122 
123 #endif
124