OSDN Git Service

Dont reset Damage more than we should do.
[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 struct HwcLayer {
27   ~HwcLayer();
28
29   HwcLayer() = default;
30
31   HwcLayer& operator=(const HwcLayer& rhs) = delete;
32
33   void SetNativeHandle(HWCNativeHandle handle);
34
35   HWCNativeHandle GetNativeHandle() const {
36     return sf_handle_;
37   }
38
39   void SetTransform(int32_t sf_transform);
40
41   uint32_t GetTransform() const {
42     return transform_;
43   }
44
45   void SetAlpha(uint8_t alpha);
46
47   uint8_t GetAlpha() const {
48     return alpha_;
49   }
50
51   void SetBlending(HWCBlending blending);
52
53   HWCBlending GetBlending() const {
54     return blending_;
55   }
56
57   void SetSourceCrop(const HwcRect<float>& source_crop);
58   const HwcRect<float>& GetSourceCrop() const {
59     return source_crop_;
60   }
61
62   void SetDisplayFrame(const HwcRect<int>& display_frame,
63                        uint32_t translate_x_pos);
64   const HwcRect<int>& GetDisplayFrame() const {
65     return display_frame_;
66   }
67
68   uint32_t GetSourceCropWidth() const {
69     return source_crop_width_;
70   }
71
72   uint32_t GetSourceCropHeight() const {
73     return source_crop_height_;
74   }
75
76   uint32_t GetDisplayFrameWidth() const {
77     return display_frame_width_;
78   }
79
80   uint32_t GetDisplayFrameHeight() const {
81     return display_frame_height_;
82   }
83
84   /**
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.
92    */
93   void SetSurfaceDamage(const HwcRegion& surface_damage);
94
95   /**
96    * API for getting surface damage of this layer.
97    */
98   const HwcRect<int>& GetSurfaceDamage() const {
99     return surface_damage_;
100   }
101
102   /**
103    * API for querying damage region of this layer
104    * has changed from last Present call to
105    * NativeDisplay.
106    */
107   bool HasSurfaceDamageRegionChanged() const {
108     return state_ & kSurfaceDamageChanged;
109   }
110
111   /**
112    * API for querying if content of layer has changed
113    * for last Present call to NativeDisplay.
114    */
115   bool HasLayerContentChanged() const {
116     return state_ & kLayerContentChanged;
117   }
118
119   /**
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.
125    */
126   void SetVisibleRegion(const HwcRegion& visible_region);
127
128   /**
129    * API for getting visible rect of this layer.
130    */
131   const HwcRect<int>& GetVisibleRect() const {
132     return visible_rect_;
133   }
134
135   /**
136    * API for querying if visible region has
137    * changed from last Present call to NativeDisplay.
138    */
139   bool HasVisibleRegionChanged() const {
140     return state_ & kVisibleRegionChanged;
141   }
142
143   /**
144    * API for querying if Display FrameRect has
145    * changed from last Present call to NativeDisplay.
146    */
147   bool HasDisplayRectChanged() const {
148     return layer_cache_ & kDisplayFrameRectChanged;
149   }
150
151   /**
152    * API for querying if Layer source rect has
153    * changed from last Present call to NativeDisplay.
154    */
155   bool HasSourceRectChanged() const {
156     return layer_cache_ & kSourceRectChanged;
157   }
158
159   /**
160    * API for querying if layer is visible.
161    */
162   bool IsVisible() const {
163     return state_ & kVisible;
164   }
165
166   /**
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.
171    */
172   bool HasLayerAttributesChanged() const {
173     return layer_cache_ & kLayerAttributesChanged;
174   }
175
176   /**
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.
181    */
182   void SetReleaseFence(int32_t fd);
183
184   /**
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
189    *         closing the fd.
190    */
191   int32_t GetReleaseFence();
192
193   /**
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.
198    */
199   void SetAcquireFence(int32_t fd);
200
201   /**
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.
207    */
208   int32_t GetAcquireFence();
209
210   /**
211    * API for querying if this layer has been presented
212    * atleast once during Present call to NativeDisplay.
213    */
214   bool IsValidated() const {
215     return state_ & kLayerValidated;
216   }
217
218   /**
219    * API for setting ZOrder for this layer.
220    */
221   void SetLayerZOrder(uint32_t z_order);
222
223   /**
224    * API for getting ZOrder for this layer.
225    */
226   uint32_t GetZorder() const {
227     return z_order_;
228   }
229
230   void SetLeftConstraint(int32_t left_constraint);
231   int32_t GetLeftConstraint();
232
233   void SetRightConstraint(int32_t right_constraint);
234   int32_t GetRightConstraint();
235
236   void SetLeftSourceConstraint(int32_t left_constraint);
237   int32_t GetLeftSourceConstraint();
238
239   void SetRightSourceConstraint(int32_t right_constraint);
240   int32_t GetRightSourceConstraint();
241
242   void MarkAsCursorLayer();
243   bool IsCursorLayer() const;
244
245   /**
246    * API for getting damage area caused by this layer for current
247    * frame update.
248    */
249   const HwcRect<int>& GetLayerDamage();
250
251  private:
252   void Validate();
253   void UpdateRenderingDamage(const HwcRect<int>& old_rect,
254                              const HwcRect<int>& newrect, bool same_rect);
255
256   void SetTotalDisplays(uint32_t total_displays);
257   friend class VirtualDisplay;
258   friend class PhysicalDisplay;
259   friend class MosaicDisplay;
260
261   enum LayerState {
262     kSurfaceDamageChanged = 1 << 0,
263     kLayerContentChanged = 1 << 1,
264     kVisibleRegionChanged = 1 << 2,
265     kVisible = 1 << 3,
266     kLayerValidated = 1 << 4,
267     kVisibleRegionSet = 1 << 5
268   };
269
270   enum LayerCache {
271     kLayerAttributesChanged = 1 << 0,
272     kDisplayFrameRectChanged = 1 << 1,
273     kSourceRectChanged = 1 << 2
274   };
275
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;
300 };
301
302 }  // namespace hwcomposer
303 #endif  // PUBLIC_HWCLAYER_H_