2 // Copyright (c) 2016 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef PUBLIC_HWCLAYER_H_
18 #define PUBLIC_HWCLAYER_H_
22 #include <platformdefines.h>
24 namespace hwcomposer {
31 HwcLayer& operator=(const HwcLayer& rhs) = delete;
33 void SetNativeHandle(HWCNativeHandle handle);
35 HWCNativeHandle GetNativeHandle() const {
39 void SetTransform(int32_t sf_transform);
41 uint32_t GetTransform() const {
45 void SetAlpha(uint8_t alpha);
47 uint8_t GetAlpha() const {
51 void SetBlending(HWCBlending blending);
53 HWCBlending GetBlending() const {
57 void SetSourceCrop(const HwcRect<float>& source_crop);
58 const HwcRect<float>& GetSourceCrop() const {
62 void SetDisplayFrame(const HwcRect<int>& display_frame,
63 uint32_t translate_x_pos);
64 const HwcRect<int>& GetDisplayFrame() const {
65 return display_frame_;
68 uint32_t GetSourceCropWidth() const {
69 return source_crop_width_;
72 uint32_t GetSourceCropHeight() const {
73 return source_crop_height_;
76 uint32_t GetDisplayFrameWidth() const {
77 return display_frame_width_;
80 uint32_t GetDisplayFrameHeight() const {
81 return display_frame_height_;
85 * API for setting surface damage for this layer.
86 * @param surface_damage should contain exactly 1
87 * rect with all zeros if content of the
88 * layer has not changed from last Present call.
89 * If no of rects is zero than assumption is that
90 * the contents of layer has completely changed
91 * from last Present call.
93 void SetSurfaceDamage(const HwcRegion& surface_damage);
96 * API for getting surface damage of this layer.
98 const HwcRect<int>& GetSurfaceDamage() const {
99 return surface_damage_;
103 * API for querying damage region of this layer
104 * has changed from last Present call to
107 bool HasSurfaceDamageRegionChanged() const {
108 return state_ & kSurfaceDamageChanged;
112 * API for querying if content of layer has changed
113 * for last Present call to NativeDisplay.
115 bool HasLayerContentChanged() const {
116 return state_ & kLayerContentChanged;
120 * API for setting visible region for this layer. The
121 * new visible region will take into effect in next Present
122 * call, by default this would be same as default frame.
123 * @param visible_region should contain regions of
124 * layer which are visible.
126 void SetVisibleRegion(const HwcRegion& visible_region);
129 * API for getting visible rect of this layer.
131 const HwcRect<int>& GetVisibleRect() const {
132 return visible_rect_;
136 * API for querying if visible region has
137 * changed from last Present call to NativeDisplay.
139 bool HasVisibleRegionChanged() const {
140 return state_ & kVisibleRegionChanged;
144 * API for querying if Display FrameRect has
145 * changed from last Present call to NativeDisplay.
147 bool HasDisplayRectChanged() const {
148 return layer_cache_ & kDisplayFrameRectChanged;
152 * API for querying if Layer source rect has
153 * changed from last Present call to NativeDisplay.
155 bool HasSourceRectChanged() const {
156 return layer_cache_ & kSourceRectChanged;
160 * API for querying if layer is visible.
162 bool IsVisible() const {
163 return state_ & kVisible;
167 * API for querying if layer attributes has
168 * changed from last Present call to NativeDisplay.
169 * This takes into consideration any changes to
170 * transform of the layer.
172 bool HasLayerAttributesChanged() const {
173 return layer_cache_ & kLayerAttributesChanged;
177 * API for setting release fence for this layer.
178 * @param fd will be populated with Native Fence object.
179 * When fd is signalled, any previous frame
180 * composition results can be invalidated.
182 void SetReleaseFence(int32_t fd);
185 * API for getting release fence of this layer.
186 * @return "-1" if no valid release fence present
187 * for this layer. Ownership of fd is passed
188 * to caller and caller is responsible for
191 int32_t GetReleaseFence();
194 * API for setting acquire fence for this layer.
195 * @param fd will be populated with Native Fence object.
196 * When fd is signalled, the buffer associated
197 * with the layer is ready to be read from.
199 void SetAcquireFence(int32_t fd);
202 * API for getting acquire fence of this layer.
203 * @return "-1" if no valid acquire fence present
204 * for this layer. Ownership of acquire
205 * fence is passed to caller and caller is
206 * responsible for closing the fd.
208 int32_t GetAcquireFence();
211 * API for querying if this layer has been presented
212 * atleast once during Present call to NativeDisplay.
214 bool IsValidated() const {
215 return state_ & kLayerValidated;
219 * API for setting ZOrder for this layer.
221 void SetLayerZOrder(uint32_t z_order);
224 * API for getting ZOrder for this layer.
226 uint32_t GetZorder() const {
230 void SetLeftConstraint(int32_t left_constraint);
231 int32_t GetLeftConstraint();
233 void SetRightConstraint(int32_t right_constraint);
234 int32_t GetRightConstraint();
236 void SetLeftSourceConstraint(int32_t left_constraint);
237 int32_t GetLeftSourceConstraint();
239 void SetRightSourceConstraint(int32_t right_constraint);
240 int32_t GetRightSourceConstraint();
242 void MarkAsCursorLayer();
243 bool IsCursorLayer() const;
246 * API for getting damage area caused by this layer for current
249 const HwcRect<int>& GetLayerDamage();
253 void UpdateRenderingDamage(const HwcRect<int>& old_rect,
254 const HwcRect<int>& newrect, bool same_rect);
256 void SetTotalDisplays(uint32_t total_displays);
257 friend class VirtualDisplay;
258 friend class PhysicalDisplay;
259 friend class MosaicDisplay;
262 kSurfaceDamageChanged = 1 << 0,
263 kLayerContentChanged = 1 << 1,
264 kVisibleRegionChanged = 1 << 2,
266 kLayerValidated = 1 << 4,
267 kVisibleRegionSet = 1 << 5
271 kLayerAttributesChanged = 1 << 0,
272 kDisplayFrameRectChanged = 1 << 1,
273 kSourceRectChanged = 1 << 2
276 int32_t transform_ = 0;
277 uint32_t source_crop_width_ = 0;
278 uint32_t source_crop_height_ = 0;
279 uint32_t display_frame_width_ = 0;
280 uint32_t display_frame_height_ = 0;
281 uint8_t alpha_ = 0xff;
282 HwcRect<float> source_crop_;
283 HwcRect<int> display_frame_;
284 HwcRect<int> surface_damage_;
285 HwcRect<int> visible_rect_;
286 HwcRect<int> current_rendering_damage_;
287 HWCBlending blending_ = HWCBlending::kBlendingNone;
288 HWCNativeHandle sf_handle_ = 0;
289 int32_t release_fd_ = -1;
290 int32_t acquire_fence_ = -1;
291 std::vector<int32_t> left_constraint_;
292 std::vector<int32_t> right_constraint_;
293 std::vector<int32_t> left_source_constraint_;
294 std::vector<int32_t> right_source_constraint_;
295 uint32_t z_order_ = 0;
296 uint32_t total_displays_ = 1;
297 int state_ = kVisible | kSurfaceDamageChanged | kVisibleRegionChanged;
298 int layer_cache_ = kLayerAttributesChanged | kDisplayFrameRectChanged;
299 bool is_cursor_layer_ = false;
302 } // namespace hwcomposer
303 #endif // PUBLIC_HWCLAYER_H_