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 {
27 Composition_Device = 0,
28 Composition_Client = 1,
29 Composition_SolidColor = 2,
30 } HWCLayerCompositionType;
37 HwcLayer& operator=(const HwcLayer& rhs) = delete;
39 void SetNativeHandle(HWCNativeHandle handle);
41 HWCNativeHandle GetNativeHandle() const {
45 void SetTransform(int32_t sf_transform);
47 uint32_t GetTransform() const {
51 void SetAlpha(uint8_t alpha);
53 uint8_t GetAlpha() const {
57 void SetBlending(HWCBlending blending);
59 HWCBlending GetBlending() const {
63 void SetSourceCrop(const HwcRect<float>& source_crop);
64 const HwcRect<float>& GetSourceCrop() const {
68 void SetDisplayFrame(const HwcRect<int>& display_frame, int translate_x_pos,
71 const HwcRect<int>& GetDisplayFrame() const {
72 return display_frame_;
75 uint32_t GetSourceCropWidth() const {
76 return source_crop_width_;
79 uint32_t GetSourceCropHeight() const {
80 return source_crop_height_;
83 uint32_t GetDisplayFrameWidth() const {
84 return display_frame_width_;
87 uint32_t GetDisplayFrameHeight() const {
88 return display_frame_height_;
92 * API for setting surface damage for this layer.
93 * @param surface_damage should contain exactly 1
94 * rect with all zeros if content of the
95 * layer has not changed from last Present call.
96 * If no of rects is zero than assumption is that
97 * the contents of layer has completely changed
98 * from last Present call.
100 void SetSurfaceDamage(const HwcRegion& surface_damage);
103 * API for getting surface damage of this layer.
105 const HwcRect<int>& GetSurfaceDamage() const {
106 return surface_damage_;
110 * API for querying damage region of this layer
111 * has changed from last Present call to
114 bool HasSurfaceDamageRegionChanged() const {
115 return state_ & kSurfaceDamageChanged;
119 * API for querying if content of layer has changed
120 * for last Present call to NativeDisplay.
122 bool HasLayerContentChanged() const {
123 return state_ & kLayerContentChanged;
127 * API for setting visible region for this layer. The
128 * new visible region will take into effect in next Present
129 * call, by default this would be same as default frame.
130 * @param visible_region should contain regions of
131 * layer which are visible.
133 void SetVisibleRegion(const HwcRegion& visible_region);
136 * API for getting visible rect of this layer.
138 const HwcRect<int>& GetVisibleRect() const {
139 return visible_rect_;
143 * API for querying if visible region has
144 * changed from last Present call to NativeDisplay.
146 bool HasVisibleRegionChanged() const {
147 return state_ & kVisibleRegionChanged;
151 * API for querying if Display FrameRect has
152 * changed from last Present call to NativeDisplay.
154 bool HasDisplayRectChanged() const {
155 return layer_cache_ & kDisplayFrameRectChanged;
159 * API for querying if Layer source rect has
160 * changed from last Present call to NativeDisplay.
162 bool HasSourceRectChanged() const {
163 return layer_cache_ & kSourceRectChanged;
167 * API for querying if layer is visible.
169 bool IsVisible() const {
170 return state_ & kVisible;
174 * API for querying if layer attributes has
175 * changed from last Present call to NativeDisplay.
176 * This takes into consideration any changes to
177 * transform of the layer.
179 bool HasLayerAttributesChanged() const {
180 return layer_cache_ & kLayerAttributesChanged;
184 * API for setting release fence for this layer.
185 * @param fd will be populated with Native Fence object.
186 * When fd is signalled, any previous frame
187 * composition results can be invalidated.
189 void SetReleaseFence(int32_t fd);
192 * API for getting release fence of this layer.
193 * @return "-1" if no valid release fence present
194 * for this layer. Ownership of fd is passed
195 * to caller and caller is responsible for
198 int32_t GetReleaseFence();
201 * API for setting acquire fence for this layer.
202 * @param fd will be populated with Native Fence object.
203 * When fd is signalled, the buffer associated
204 * with the layer is ready to be read from.
206 void SetAcquireFence(int32_t fd);
209 * API for getting acquire fence of this layer.
210 * @return "-1" if no valid acquire fence present
211 * for this layer. Ownership of acquire
212 * fence is passed to caller and caller is
213 * responsible for closing the fd.
215 int32_t GetAcquireFence();
218 * API for querying if this layer has been presented
219 * atleast once during Present call to NativeDisplay.
221 bool IsValidated() const {
222 return state_ & kLayerValidated;
226 * API for setting ZOrder for this layer.
228 void SetLayerZOrder(uint32_t z_order);
231 * API for getting ZOrder for this layer.
233 uint32_t GetZorder() const {
238 * API for setting SolidColor for this layer.
240 void SetSolidColor(uint32_t color);
243 * API for getting SolidColor.
245 uint32_t GetSolidColor() {
249 bool HasZorderChanged() const {
250 return state_ & kZorderChanged;
253 void SetLayerCompositionType(HWCLayerCompositionType type) {
254 composition_type_ = type;
257 HWCLayerCompositionType GetLayerCompositionType() {
258 return composition_type_;
261 void SetLeftConstraint(int32_t left_constraint);
262 int32_t GetLeftConstraint();
264 void SetRightConstraint(int32_t right_constraint);
265 int32_t GetRightConstraint();
267 void SetLeftSourceConstraint(int32_t left_constraint);
268 int32_t GetLeftSourceConstraint();
270 void SetRightSourceConstraint(int32_t right_constraint);
271 int32_t GetRightSourceConstraint();
273 void MarkAsCursorLayer();
274 bool IsCursorLayer() const;
277 * API for getting damage area caused by this layer for current
280 const HwcRect<int>& GetLayerDamage();
284 void UpdateRenderingDamage(const HwcRect<int>& old_rect,
285 const HwcRect<int>& newrect, bool same_rect);
287 Get Rendering Damage from source surface damage
290 void SufaceDamageTransfrom();
292 void SetTotalDisplays(uint32_t total_displays);
293 friend class VirtualDisplay;
294 friend class PhysicalDisplay;
295 friend class MosaicDisplay;
298 kSurfaceDamageChanged = 1 << 0,
299 kLayerContentChanged = 1 << 1,
300 kVisibleRegionChanged = 1 << 2,
302 kLayerValidated = 1 << 4,
303 kVisibleRegionSet = 1 << 5,
304 kZorderChanged = 1 << 6
308 kLayerAttributesChanged = 1 << 0,
309 kDisplayFrameRectChanged = 1 << 1,
310 kSourceRectChanged = 1 << 2,
313 int32_t transform_ = 0;
314 uint32_t source_crop_width_ = 0;
315 uint32_t source_crop_height_ = 0;
316 uint32_t display_frame_width_ = 0;
317 uint32_t display_frame_height_ = 0;
318 uint8_t alpha_ = 0xff;
319 HwcRect<float> source_crop_;
320 HwcRect<int> display_frame_;
321 HwcRect<int> surface_damage_;
322 HwcRect<int> visible_rect_;
323 HwcRect<int> current_rendering_damage_;
324 HWCBlending blending_ = HWCBlending::kBlendingNone;
325 HWCNativeHandle sf_handle_ = 0;
326 int32_t release_fd_ = -1;
327 int32_t acquire_fence_ = -1;
328 std::vector<int32_t> left_constraint_;
329 std::vector<int32_t> right_constraint_;
330 std::vector<int32_t> left_source_constraint_;
331 std::vector<int32_t> right_source_constraint_;
333 uint32_t total_displays_ = 1;
335 kVisible | kSurfaceDamageChanged | kVisibleRegionChanged | kZorderChanged;
336 int layer_cache_ = kLayerAttributesChanged | kDisplayFrameRectChanged;
337 bool is_cursor_layer_ = false;
338 uint32_t solid_color_ = 0;
340 HWCLayerCompositionType composition_type_ = Composition_Device;
343 } // namespace hwcomposer
344 #endif // PUBLIC_HWCLAYER_H_