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 SetDataSpace(uint32_t dataspace);
47 void SetTransform(int32_t sf_transform);
49 uint32_t GetTransform() const {
53 void SetAlpha(uint8_t alpha);
55 uint8_t GetAlpha() const {
59 void SetBlending(HWCBlending blending);
61 HWCBlending GetBlending() const {
65 void SetSourceCrop(const HwcRect<float>& source_crop);
66 const HwcRect<float>& GetSourceCrop() const {
70 void SetDisplayFrame(const HwcRect<int>& display_frame, int translate_x_pos,
73 uint32_t GetDataSpace() const {
77 const HwcRect<int>& GetDisplayFrame() const {
78 return display_frame_;
81 uint32_t GetSourceCropWidth() const {
82 return source_crop_width_;
85 uint32_t GetSourceCropHeight() const {
86 return source_crop_height_;
89 uint32_t GetDisplayFrameWidth() const {
90 return display_frame_width_;
93 uint32_t GetDisplayFrameHeight() const {
94 return display_frame_height_;
98 * API for setting surface damage for this layer.
99 * @param surface_damage should contain exactly 1
100 * rect with all zeros if content of the
101 * layer has not changed from last Present call.
102 * If no of rects is zero than assumption is that
103 * the contents of layer has completely changed
104 * from last Present call.
106 void SetSurfaceDamage(const HwcRegion& surface_damage);
109 * API for getting surface damage of this layer.
111 const HwcRect<int>& GetSurfaceDamage() const {
112 return surface_damage_;
116 * API for querying damage region of this layer
117 * has changed from last Present call to
120 bool HasSurfaceDamageRegionChanged() const {
121 return state_ & kSurfaceDamageChanged;
125 * API for querying if content of layer has changed
126 * for last Present call to NativeDisplay.
128 bool HasLayerContentChanged() const {
129 return state_ & kLayerContentChanged;
133 * API for setting visible region for this layer. The
134 * new visible region will take into effect in next Present
135 * call, by default this would be same as default frame.
136 * @param visible_region should contain regions of
137 * layer which are visible.
139 void SetVisibleRegion(const HwcRegion& visible_region);
142 * API for getting visible rect of this layer.
144 const HwcRect<int>& GetVisibleRect() const {
145 return visible_rect_;
149 * API for querying if visible region has
150 * changed from last Present call to NativeDisplay.
152 bool HasVisibleRegionChanged() const {
153 return state_ & kVisibleRegionChanged;
157 * API for querying if Display FrameRect has
158 * changed from last Present call to NativeDisplay.
160 bool HasDisplayRectChanged() const {
161 return layer_cache_ & kDisplayFrameRectChanged;
165 * API for querying if Layer source rect has
166 * changed from last Present call to NativeDisplay.
168 bool HasSourceRectChanged() const {
169 return layer_cache_ & kSourceRectChanged;
173 * API for querying if layer is visible.
175 bool IsVisible() const {
176 return state_ & kVisible;
180 * API for querying if layer attributes has
181 * changed from last Present call to NativeDisplay.
182 * This takes into consideration any changes to
183 * transform of the layer.
185 bool HasLayerAttributesChanged() const {
186 return layer_cache_ & kLayerAttributesChanged;
190 * API for setting release fence for this layer.
191 * @param fd will be populated with Native Fence object.
192 * When fd is signalled, any previous frame
193 * composition results can be invalidated.
195 void SetReleaseFence(int32_t fd);
198 * API for getting release fence of this layer.
199 * @return "-1" if no valid release fence present
200 * for this layer. Ownership of fd is passed
201 * to caller and caller is responsible for
204 int32_t GetReleaseFence();
207 * API for setting acquire fence for this layer.
208 * @param fd will be populated with Native Fence object.
209 * When fd is signalled, the buffer associated
210 * with the layer is ready to be read from.
212 void SetAcquireFence(int32_t fd);
215 * API for getting acquire fence of this layer.
216 * @return "-1" if no valid acquire fence present
217 * for this layer. Ownership of acquire
218 * fence is passed to caller and caller is
219 * responsible for closing the fd.
221 int32_t GetAcquireFence();
224 * API for querying if this layer has been presented
225 * atleast once during Present call to NativeDisplay.
227 bool IsValidated() const {
228 return state_ & kLayerValidated;
232 * API for setting ZOrder for this layer.
234 void SetLayerZOrder(uint32_t z_order);
237 * API for getting ZOrder for this layer.
239 uint32_t GetZorder() const {
244 * API for setting SolidColor for this layer.
246 void SetSolidColor(uint32_t color);
249 * API for getting SolidColor.
251 uint32_t GetSolidColor() {
255 bool HasZorderChanged() const {
256 return state_ & kZorderChanged;
259 void SetLayerCompositionType(HWCLayerCompositionType type) {
260 composition_type_ = type;
263 HWCLayerCompositionType GetLayerCompositionType() {
264 return composition_type_;
267 void SetLeftConstraint(int32_t left_constraint);
268 int32_t GetLeftConstraint();
270 void SetRightConstraint(int32_t right_constraint);
271 int32_t GetRightConstraint();
273 void SetLeftSourceConstraint(int32_t left_constraint);
274 int32_t GetLeftSourceConstraint();
276 void SetRightSourceConstraint(int32_t right_constraint);
277 int32_t GetRightSourceConstraint();
279 void MarkAsCursorLayer();
280 bool IsCursorLayer() const;
283 * API for getting damage area caused by this layer for current
286 const HwcRect<int>& GetLayerDamage();
290 void UpdateRenderingDamage(const HwcRect<int>& old_rect,
291 const HwcRect<int>& newrect, bool same_rect);
294 Get Rendering Damage from source surface damage
298 void SufaceDamageTransfrom();
300 void SetTotalDisplays(uint32_t total_displays);
301 friend class VirtualDisplay;
302 friend class PhysicalDisplay;
303 friend class MosaicDisplay;
305 #ifdef ENABLE_PANORAMA
306 friend class VirtualPanoramaDisplay;
310 kSurfaceDamageChanged = 1 << 0,
311 kLayerContentChanged = 1 << 1,
312 kVisibleRegionChanged = 1 << 2,
314 kLayerValidated = 1 << 4,
315 kVisibleRegionSet = 1 << 5,
316 kZorderChanged = 1 << 6
320 kLayerAttributesChanged = 1 << 0,
321 kDisplayFrameRectChanged = 1 << 1,
322 kSourceRectChanged = 1 << 2,
325 int32_t transform_ = 0;
326 uint32_t source_crop_width_ = 0;
327 uint32_t source_crop_height_ = 0;
328 uint32_t display_frame_width_ = 0;
329 uint32_t display_frame_height_ = 0;
330 uint8_t alpha_ = 0xff;
331 uint32_t dataspace_ = 0;
332 HwcRect<float> source_crop_;
333 HwcRect<int> display_frame_;
334 HwcRect<int> surface_damage_;
335 HwcRect<int> visible_rect_;
336 HwcRect<int> current_rendering_damage_;
337 HWCBlending blending_ = HWCBlending::kBlendingNone;
338 HWCNativeHandle sf_handle_ = 0;
339 int32_t release_fd_ = -1;
340 int32_t acquire_fence_ = -1;
341 std::vector<int32_t> left_constraint_;
342 std::vector<int32_t> right_constraint_;
343 std::vector<int32_t> left_source_constraint_;
344 std::vector<int32_t> right_source_constraint_;
346 uint32_t total_displays_ = 1;
348 kVisible | kSurfaceDamageChanged | kVisibleRegionChanged | kZorderChanged;
349 int layer_cache_ = kLayerAttributesChanged | kDisplayFrameRectChanged;
350 bool is_cursor_layer_ = false;
351 uint32_t solid_color_ = 0;
353 HWCLayerCompositionType composition_type_ = Composition_Device;
356 } // namespace hwcomposer
357 #endif // PUBLIC_HWCLAYER_H_