OSDN Git Service

cefb9cf3fbb1c1eae5898541912684bb69e3dc37
[android-x86/external-IA-Hardware-Composer.git] / public / hwclayer.h
1 /*
2 // Copyright (c) 2016 Intel Corporation
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 PUBLIC_HWCLAYER_H_
18 #define PUBLIC_HWCLAYER_H_
19
20 #include <hwcdefs.h>
21
22 #include <platformdefines.h>
23
24 namespace hwcomposer {
25
26 typedef enum {
27   Composition_Device = 0,
28   Composition_Client = 1,
29   Composition_SolidColor = 2,
30 } HWCLayerCompositionType;
31
32 struct HwcLayer {
33   ~HwcLayer();
34
35   HwcLayer() = default;
36
37   HwcLayer& operator=(const HwcLayer& rhs) = delete;
38
39   void SetNativeHandle(HWCNativeHandle handle);
40
41   HWCNativeHandle GetNativeHandle() const {
42     return sf_handle_;
43   }
44
45   void SetTransform(int32_t sf_transform);
46
47   uint32_t GetTransform() const {
48     return transform_;
49   }
50
51   void SetAlpha(uint8_t alpha);
52
53   uint8_t GetAlpha() const {
54     return alpha_;
55   }
56
57   void SetBlending(HWCBlending blending);
58
59   HWCBlending GetBlending() const {
60     return blending_;
61   }
62
63   void SetSourceCrop(const HwcRect<float>& source_crop);
64   const HwcRect<float>& GetSourceCrop() const {
65     return source_crop_;
66   }
67
68   void SetDisplayFrame(const HwcRect<int>& display_frame, int translate_x_pos,
69                        int translate_y_pos);
70
71   const HwcRect<int>& GetDisplayFrame() const {
72     return display_frame_;
73   }
74
75   uint32_t GetSourceCropWidth() const {
76     return source_crop_width_;
77   }
78
79   uint32_t GetSourceCropHeight() const {
80     return source_crop_height_;
81   }
82
83   uint32_t GetDisplayFrameWidth() const {
84     return display_frame_width_;
85   }
86
87   uint32_t GetDisplayFrameHeight() const {
88     return display_frame_height_;
89   }
90
91   /**
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.
99    */
100   void SetSurfaceDamage(const HwcRegion& surface_damage);
101
102   /**
103    * API for getting surface damage of this layer.
104    */
105   const HwcRect<int>& GetSurfaceDamage() const {
106     return surface_damage_;
107   }
108
109   /**
110    * API for querying damage region of this layer
111    * has changed from last Present call to
112    * NativeDisplay.
113    */
114   bool HasSurfaceDamageRegionChanged() const {
115     return state_ & kSurfaceDamageChanged;
116   }
117
118   /**
119    * API for querying if content of layer has changed
120    * for last Present call to NativeDisplay.
121    */
122   bool HasLayerContentChanged() const {
123     return state_ & kLayerContentChanged;
124   }
125
126   /**
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.
132    */
133   void SetVisibleRegion(const HwcRegion& visible_region);
134
135   /**
136    * API for getting visible rect of this layer.
137    */
138   const HwcRect<int>& GetVisibleRect() const {
139     return visible_rect_;
140   }
141
142   /**
143    * API for querying if visible region has
144    * changed from last Present call to NativeDisplay.
145    */
146   bool HasVisibleRegionChanged() const {
147     return state_ & kVisibleRegionChanged;
148   }
149
150   /**
151    * API for querying if Display FrameRect has
152    * changed from last Present call to NativeDisplay.
153    */
154   bool HasDisplayRectChanged() const {
155     return layer_cache_ & kDisplayFrameRectChanged;
156   }
157
158   /**
159    * API for querying if Layer source rect has
160    * changed from last Present call to NativeDisplay.
161    */
162   bool HasSourceRectChanged() const {
163     return layer_cache_ & kSourceRectChanged;
164   }
165
166   /**
167    * API for querying if layer is visible.
168    */
169   bool IsVisible() const {
170     return state_ & kVisible;
171   }
172
173   /**
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.
178    */
179   bool HasLayerAttributesChanged() const {
180     return layer_cache_ & kLayerAttributesChanged;
181   }
182
183   /**
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.
188    */
189   void SetReleaseFence(int32_t fd);
190
191   /**
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
196    *         closing the fd.
197    */
198   int32_t GetReleaseFence();
199
200   /**
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.
205    */
206   void SetAcquireFence(int32_t fd);
207
208   /**
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.
214    */
215   int32_t GetAcquireFence();
216
217   /**
218    * API for querying if this layer has been presented
219    * atleast once during Present call to NativeDisplay.
220    */
221   bool IsValidated() const {
222     return state_ & kLayerValidated;
223   }
224
225   /**
226    * API for setting ZOrder for this layer.
227    */
228   void SetLayerZOrder(uint32_t z_order);
229
230   /**
231    * API for getting ZOrder for this layer.
232    */
233   uint32_t GetZorder() const {
234     return z_order_;
235   }
236
237   /**
238    * API for setting SolidColor for this layer.
239    */
240   void SetSolidColor(uint32_t color);
241
242   /**
243    * API for getting SolidColor.
244    */
245   uint32_t GetSolidColor() {
246     return solid_color_;
247   }
248
249   bool HasZorderChanged() const {
250     return state_ & kZorderChanged;
251   }
252
253   void SetLayerCompositionType(HWCLayerCompositionType type) {
254     composition_type_ = type;
255   }
256
257   HWCLayerCompositionType GetLayerCompositionType() {
258     return composition_type_;
259   }
260
261   void SetLeftConstraint(int32_t left_constraint);
262   int32_t GetLeftConstraint();
263
264   void SetRightConstraint(int32_t right_constraint);
265   int32_t GetRightConstraint();
266
267   void SetLeftSourceConstraint(int32_t left_constraint);
268   int32_t GetLeftSourceConstraint();
269
270   void SetRightSourceConstraint(int32_t right_constraint);
271   int32_t GetRightSourceConstraint();
272
273   void MarkAsCursorLayer();
274   bool IsCursorLayer() const;
275
276   /**
277    * API for getting damage area caused by this layer for current
278    * frame update.
279    */
280   const HwcRect<int>& GetLayerDamage();
281
282  private:
283   void Validate();
284   void UpdateRenderingDamage(const HwcRect<int>& old_rect,
285                              const HwcRect<int>& newrect, bool same_rect);
286   /*
287    Get Rendering Damage from source surface damage
288    Apply transform here
289   */
290   void SufaceDamageTransfrom();
291
292   void SetTotalDisplays(uint32_t total_displays);
293   friend class VirtualDisplay;
294   friend class PhysicalDisplay;
295   friend class MosaicDisplay;
296
297   enum LayerState {
298     kSurfaceDamageChanged = 1 << 0,
299     kLayerContentChanged = 1 << 1,
300     kVisibleRegionChanged = 1 << 2,
301     kVisible = 1 << 3,
302     kLayerValidated = 1 << 4,
303     kVisibleRegionSet = 1 << 5,
304     kZorderChanged = 1 << 6
305   };
306
307   enum LayerCache {
308     kLayerAttributesChanged = 1 << 0,
309     kDisplayFrameRectChanged = 1 << 1,
310     kSourceRectChanged = 1 << 2,
311   };
312
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_;
332   int z_order_ = -1;
333   uint32_t total_displays_ = 1;
334   int state_ =
335       kVisible | kSurfaceDamageChanged | kVisibleRegionChanged | kZorderChanged;
336   int layer_cache_ = kLayerAttributesChanged | kDisplayFrameRectChanged;
337   bool is_cursor_layer_ = false;
338   uint32_t solid_color_ = 0;
339
340   HWCLayerCompositionType composition_type_ = Composition_Device;
341 };
342
343 }  // namespace hwcomposer
344 #endif  // PUBLIC_HWCLAYER_H_