OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_GFX_COMPOSITOR_LAYER_H_ | 5 #ifndef UI_GFX_COMPOSITOR_LAYER_H_ |
6 #define UI_GFX_COMPOSITOR_LAYER_H_ | 6 #define UI_GFX_COMPOSITOR_LAYER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 virtual void notifyNeedsComposite(); | 189 virtual void notifyNeedsComposite(); |
190 | 190 |
191 // WebContentLayerClient | 191 // WebContentLayerClient |
192 virtual void paintContents(WebKit::WebCanvas*, const WebKit::WebRect& clip); | 192 virtual void paintContents(WebKit::WebCanvas*, const WebKit::WebRect& clip); |
193 | 193 |
194 #if defined(USE_WEBKIT_COMPOSITOR) | 194 #if defined(USE_WEBKIT_COMPOSITOR) |
195 WebKit::WebLayer web_layer() { return web_layer_; } | 195 WebKit::WebLayer web_layer() { return web_layer_; } |
196 #endif | 196 #endif |
197 | 197 |
198 private: | 198 private: |
| 199 struct LayerProperties { |
| 200 public: |
| 201 ui::Layer* layer; |
| 202 ui::Transform transform_relative_to_root; |
| 203 }; |
| 204 |
199 // TODO(vollick): Eventually, if a non-leaf node has an opacity of less than | 205 // TODO(vollick): Eventually, if a non-leaf node has an opacity of less than |
200 // 1.0, we'll render to a separate texture, and then apply the alpha. | 206 // 1.0, we'll render to a separate texture, and then apply the alpha. |
201 // Currently, we multiply our opacity by all our ancestor's opacities and | 207 // Currently, we multiply our opacity by all our ancestor's opacities and |
202 // use the combined result, but this is only temporary. | 208 // use the combined result, but this is only temporary. |
203 float GetCombinedOpacity() const; | 209 float GetCombinedOpacity() const; |
204 | 210 |
205 // Called during the Draw() pass to freshen the Layer's contents from the | 211 // Called during the Draw() pass to freshen the Layer's contents from the |
206 // delegate. | 212 // delegate. |
207 void UpdateLayerCanvas(); | 213 void UpdateLayerCanvas(); |
208 | 214 |
| 215 // Called to indicate that a layer's properties have changed and that the |
| 216 // holes for the layers must be recomputed. |
| 217 void SetNeedsToRecomputeHole(); |
| 218 |
| 219 // Resets |hole_rect_| to the empty rect for all layers below and |
| 220 // including this one. |
| 221 void ClearHoleRects(); |
| 222 |
| 223 // Does a preorder traversal of layers starting with this layer. Omits layers |
| 224 // which cannot punch a hole in another layer such as non visible layers |
| 225 // and layers which don't fill their bounds opaquely. |
| 226 void GetLayerProperties(const ui::Transform& current_transform, |
| 227 std::vector<LayerProperties>* traverasal); |
| 228 |
209 // A hole in a layer is an area in the layer that does not get drawn | 229 // A hole in a layer is an area in the layer that does not get drawn |
210 // because this area is covered up with another layer which is known to be | 230 // because this area is covered up with another layer which is known to be |
211 // opaque. | 231 // opaque. |
212 // This method computes the dimension of the hole (if there is one) | 232 // This method computes the dimension of the hole (if there is one) |
213 // based on whether one of its child nodes is always opaque. | 233 // based on whether one of its child nodes is always opaque. |
214 // Note: For simplicity's sake, currently a hole is only created if the child | 234 // Note: This method should only be called from the root. |
215 // view has no transform with respect to its parent. | |
216 void RecomputeHole(); | 235 void RecomputeHole(); |
217 | 236 |
218 // Returns true if the layer paints every pixel (fills_bounds_opaquely) | 237 void set_hole_rect(const gfx::Rect& hole_rect) { |
219 // and the alpha of the layer is 1.0f. | 238 hole_rect_ = hole_rect; |
220 bool IsCompletelyOpaque() const; | 239 } |
221 | 240 |
222 // Determines the regions that don't intersect |rect| and places the | 241 // Determines the regions that don't intersect |rect| and places the |
223 // result in |sides|. | 242 // result in |sides|. |
224 // | 243 // |
225 // rect_____________________________ | 244 // rect_____________________________ |
226 // |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx| | 245 // |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx| |
227 // |xxxxxxxxxxxxx top xxxxxxxxxxxxxx| | 246 // |xxxxxxxxxxxxx top xxxxxxxxxxxxxx| |
228 // |________________________________| | 247 // |________________________________| |
229 // |xxxxx| |xxxxx| | 248 // |xxxxx| |xxxxx| |
230 // |xxxxx|region_to_punch_out |xxxxx| | 249 // |xxxxx|region_to_punch_out |xxxxx| |
231 // |left | |right| | 250 // |left | |right| |
232 // |_____|____________________|_____| | 251 // |_____|____________________|_____| |
233 // |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx| | 252 // |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx| |
234 // |xxxxxxxxxx bottom xxxxxxxxxxxxxx| | 253 // |xxxxxxxxxx bottom xxxxxxxxxxxxxx| |
235 // |________________________________| | 254 // |________________________________| |
236 static void PunchHole(const gfx::Rect& rect, | 255 static void PunchHole(const gfx::Rect& rect, |
237 const gfx::Rect& region_to_punch_out, | 256 const gfx::Rect& region_to_punch_out, |
238 std::vector<gfx::Rect>* sides); | 257 std::vector<gfx::Rect>* sides); |
239 | 258 |
| 259 // Drops texture just for this layer. |
| 260 void DropTexture(); |
| 261 |
240 // Drop all textures for layers below and including this one. Called when | 262 // Drop all textures for layers below and including this one. Called when |
241 // the layer is removed from a hierarchy. Textures will be re-generated if | 263 // the layer is removed from a hierarchy. Textures will be re-generated if |
242 // the layer is subsequently re-attached and needs to be drawn. | 264 // the layer is subsequently re-attached and needs to be drawn. |
243 void DropTextures(); | 265 void DropTextures(); |
244 | 266 |
245 bool ConvertPointForAncestor(const Layer* ancestor, gfx::Point* point) const; | 267 bool ConvertPointForAncestor(const Layer* ancestor, gfx::Point* point) const; |
246 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; | 268 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; |
247 | 269 |
248 bool GetTransformRelativeTo(const Layer* ancestor, | 270 bool GetTransformRelativeTo(const Layer* ancestor, |
249 Transform* transform) const; | 271 Transform* transform) const; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 | 310 |
289 gfx::Rect bounds_; | 311 gfx::Rect bounds_; |
290 | 312 |
291 // Visibility of this layer. See SetVisible/IsDrawn for more details. | 313 // Visibility of this layer. See SetVisible/IsDrawn for more details. |
292 bool visible_; | 314 bool visible_; |
293 | 315 |
294 bool fills_bounds_opaquely_; | 316 bool fills_bounds_opaquely_; |
295 | 317 |
296 gfx::Rect hole_rect_; | 318 gfx::Rect hole_rect_; |
297 | 319 |
| 320 bool recompute_hole_; |
| 321 |
298 gfx::Rect invalid_rect_; | 322 gfx::Rect invalid_rect_; |
299 | 323 |
300 // If true the layer is always up to date. | 324 // If true the layer is always up to date. |
301 bool layer_updated_externally_; | 325 bool layer_updated_externally_; |
302 | 326 |
303 float opacity_; | 327 float opacity_; |
304 | 328 |
305 LayerDelegate* delegate_; | 329 LayerDelegate* delegate_; |
306 | 330 |
307 scoped_ptr<LayerAnimator> animator_; | 331 scoped_ptr<LayerAnimator> animator_; |
308 | 332 |
309 #if defined(USE_WEBKIT_COMPOSITOR) | 333 #if defined(USE_WEBKIT_COMPOSITOR) |
310 WebKit::WebLayer web_layer_; | 334 WebKit::WebLayer web_layer_; |
311 bool web_layer_is_accelerated_; | 335 bool web_layer_is_accelerated_; |
312 #endif | 336 #endif |
313 | 337 |
314 DISALLOW_COPY_AND_ASSIGN(Layer); | 338 DISALLOW_COPY_AND_ASSIGN(Layer); |
315 }; | 339 }; |
316 | 340 |
317 } // namespace ui | 341 } // namespace ui |
318 | 342 |
319 #endif // UI_GFX_COMPOSITOR_LAYER_H_ | 343 #endif // UI_GFX_COMPOSITOR_LAYER_H_ |
OLD | NEW |