OSDN Git Service

Added the support of panorama view mode in AaaG HWC.
[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 SetDataSpace(uint32_t dataspace);
46
47   void SetTransform(int32_t sf_transform);
48
49   uint32_t GetTransform() const {
50     return transform_;
51   }
52
53   void SetAlpha(uint8_t alpha);
54
55   uint8_t GetAlpha() const {
56     return alpha_;
57   }
58
59   void SetBlending(HWCBlending blending);
60
61   HWCBlending GetBlending() const {
62     return blending_;
63   }
64
65   void SetSourceCrop(const HwcRect<float>& source_crop);
66   const HwcRect<float>& GetSourceCrop() const {
67     return source_crop_;
68   }
69
70   void SetDisplayFrame(const HwcRect<int>& display_frame, int translate_x_pos,
71                        int translate_y_pos);
72
73   uint32_t GetDataSpace() const {
74     return dataspace_;
75   }
76
77   const HwcRect<int>& GetDisplayFrame() const {
78     return display_frame_;
79   }
80
81   uint32_t GetSourceCropWidth() const {
82     return source_crop_width_;
83   }
84
85   uint32_t GetSourceCropHeight() const {
86     return source_crop_height_;
87   }
88
89   uint32_t GetDisplayFrameWidth() const {
90     return display_frame_width_;
91   }
92
93   uint32_t GetDisplayFrameHeight() const {
94     return display_frame_height_;
95   }
96
97   /**
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.
105    */
106   void SetSurfaceDamage(const HwcRegion& surface_damage);
107
108   /**
109    * API for getting surface damage of this layer.
110    */
111   const HwcRect<int>& GetSurfaceDamage() const {
112     return surface_damage_;
113   }
114
115   /**
116    * API for querying damage region of this layer
117    * has changed from last Present call to
118    * NativeDisplay.
119    */
120   bool HasSurfaceDamageRegionChanged() const {
121     return state_ & kSurfaceDamageChanged;
122   }
123
124   /**
125    * API for querying if content of layer has changed
126    * for last Present call to NativeDisplay.
127    */
128   bool HasLayerContentChanged() const {
129     return state_ & kLayerContentChanged;
130   }
131
132   /**
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.
138    */
139   void SetVisibleRegion(const HwcRegion& visible_region);
140
141   /**
142    * API for getting visible rect of this layer.
143    */
144   const HwcRect<int>& GetVisibleRect() const {
145     return visible_rect_;
146   }
147
148   /**
149    * API for querying if visible region has
150    * changed from last Present call to NativeDisplay.
151    */
152   bool HasVisibleRegionChanged() const {
153     return state_ & kVisibleRegionChanged;
154   }
155
156   /**
157    * API for querying if Display FrameRect has
158    * changed from last Present call to NativeDisplay.
159    */
160   bool HasDisplayRectChanged() const {
161     return layer_cache_ & kDisplayFrameRectChanged;
162   }
163
164   /**
165    * API for querying if Layer source rect has
166    * changed from last Present call to NativeDisplay.
167    */
168   bool HasSourceRectChanged() const {
169     return layer_cache_ & kSourceRectChanged;
170   }
171
172   /**
173    * API for querying if layer is visible.
174    */
175   bool IsVisible() const {
176     return state_ & kVisible;
177   }
178
179   /**
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.
184    */
185   bool HasLayerAttributesChanged() const {
186     return layer_cache_ & kLayerAttributesChanged;
187   }
188
189   /**
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.
194    */
195   void SetReleaseFence(int32_t fd);
196
197   /**
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
202    *         closing the fd.
203    */
204   int32_t GetReleaseFence();
205
206   /**
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.
211    */
212   void SetAcquireFence(int32_t fd);
213
214   /**
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.
220    */
221   int32_t GetAcquireFence();
222
223   /**
224    * API for querying if this layer has been presented
225    * atleast once during Present call to NativeDisplay.
226    */
227   bool IsValidated() const {
228     return state_ & kLayerValidated;
229   }
230
231   /**
232    * API for setting ZOrder for this layer.
233    */
234   void SetLayerZOrder(uint32_t z_order);
235
236   /**
237    * API for getting ZOrder for this layer.
238    */
239   uint32_t GetZorder() const {
240     return z_order_;
241   }
242
243   /**
244    * API for setting SolidColor for this layer.
245    */
246   void SetSolidColor(uint32_t color);
247
248   /**
249    * API for getting SolidColor.
250    */
251   uint32_t GetSolidColor() {
252     return solid_color_;
253   }
254
255   bool HasZorderChanged() const {
256     return state_ & kZorderChanged;
257   }
258
259   void SetLayerCompositionType(HWCLayerCompositionType type) {
260     composition_type_ = type;
261   }
262
263   HWCLayerCompositionType GetLayerCompositionType() {
264     return composition_type_;
265   }
266
267   void SetLeftConstraint(int32_t left_constraint);
268   int32_t GetLeftConstraint();
269
270   void SetRightConstraint(int32_t right_constraint);
271   int32_t GetRightConstraint();
272
273   void SetLeftSourceConstraint(int32_t left_constraint);
274   int32_t GetLeftSourceConstraint();
275
276   void SetRightSourceConstraint(int32_t right_constraint);
277   int32_t GetRightSourceConstraint();
278
279   void MarkAsCursorLayer();
280   bool IsCursorLayer() const;
281
282   /**
283    * API for getting damage area caused by this layer for current
284    * frame update.
285    */
286   const HwcRect<int>& GetLayerDamage();
287
288  private:
289   void Validate();
290   void UpdateRenderingDamage(const HwcRect<int>& old_rect,
291                              const HwcRect<int>& newrect, bool same_rect);
292
293   /*
294    Get Rendering Damage from source surface damage
295    Apply transform here
296   */
297
298   void SufaceDamageTransfrom();
299
300   void SetTotalDisplays(uint32_t total_displays);
301   friend class VirtualDisplay;
302   friend class PhysicalDisplay;
303   friend class MosaicDisplay;
304
305 #ifdef ENABLE_PANORAMA
306   friend class VirtualPanoramaDisplay;
307 #endif
308
309   enum LayerState {
310     kSurfaceDamageChanged = 1 << 0,
311     kLayerContentChanged = 1 << 1,
312     kVisibleRegionChanged = 1 << 2,
313     kVisible = 1 << 3,
314     kLayerValidated = 1 << 4,
315     kVisibleRegionSet = 1 << 5,
316     kZorderChanged = 1 << 6
317   };
318
319   enum LayerCache {
320     kLayerAttributesChanged = 1 << 0,
321     kDisplayFrameRectChanged = 1 << 1,
322     kSourceRectChanged = 1 << 2,
323   };
324
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_;
345   int z_order_ = -1;
346   uint32_t total_displays_ = 1;
347   int state_ =
348       kVisible | kSurfaceDamageChanged | kVisibleRegionChanged | kZorderChanged;
349   int layer_cache_ = kLayerAttributesChanged | kDisplayFrameRectChanged;
350   bool is_cursor_layer_ = false;
351   uint32_t solid_color_ = 0;
352
353   HWCLayerCompositionType composition_type_ = Composition_Device;
354 };
355
356 }  // namespace hwcomposer
357 #endif  // PUBLIC_HWCLAYER_H_