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 #include "ui/gfx/compositor/layer.h" | 5 #include "ui/gfx/compositor/layer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatPoint.h" | |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatRect.h" | |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" | |
14 #include "ui/base/animation/animation.h" | 11 #include "ui/base/animation/animation.h" |
15 #include "ui/gfx/compositor/layer_animator.h" | 12 #include "ui/gfx/compositor/layer_animator.h" |
16 #include "ui/gfx/canvas_skia.h" | 13 #include "ui/gfx/canvas_skia.h" |
17 #include "ui/gfx/interpolated_transform.h" | 14 #include "ui/gfx/interpolated_transform.h" |
18 #include "ui/gfx/point3.h" | 15 #include "ui/gfx/point3.h" |
19 | 16 |
20 namespace { | 17 namespace { |
21 | 18 |
22 const float EPSILON = 1e-3f; | 19 const float EPSILON = 1e-3f; |
23 | 20 |
24 bool IsApproximateMultilpleOf(float value, float base) { | 21 bool IsApproximateMultilpleOf(float value, float base) { |
25 float remainder = fmod(fabs(value), base); | 22 float remainder = fmod(fabs(value), base); |
26 return remainder < EPSILON || base - remainder < EPSILON; | 23 return remainder < EPSILON || base - remainder < EPSILON; |
27 } | 24 } |
28 | 25 |
29 } // namespace | 26 } // namespace |
30 | 27 |
31 namespace ui { | 28 namespace ui { |
32 | 29 |
33 Layer::Layer(Compositor* compositor) | 30 Layer::Layer(Compositor* compositor) |
34 : type_(LAYER_HAS_TEXTURE), | 31 : type_(LAYER_HAS_TEXTURE), |
35 compositor_(compositor), | 32 compositor_(compositor), |
36 parent_(NULL), | 33 parent_(NULL), |
37 visible_(true), | 34 visible_(true), |
38 fills_bounds_opaquely_(true), | 35 fills_bounds_opaquely_(true), |
39 layer_updated_externally_(false), | 36 layer_updated_externally_(false), |
40 opacity_(1.0f), | 37 opacity_(1.0f), |
41 delegate_(NULL) { | 38 delegate_(NULL) { |
42 #if defined(USE_WEBKIT_COMPOSITOR) | |
43 CreateWebLayer(); | |
44 #endif | |
45 } | 39 } |
46 | 40 |
47 Layer::Layer(Compositor* compositor, LayerType type) | 41 Layer::Layer(Compositor* compositor, LayerType type) |
48 : type_(type), | 42 : type_(type), |
49 compositor_(compositor), | 43 compositor_(compositor), |
50 parent_(NULL), | 44 parent_(NULL), |
51 visible_(true), | 45 visible_(true), |
52 fills_bounds_opaquely_(true), | 46 fills_bounds_opaquely_(true), |
53 layer_updated_externally_(false), | 47 layer_updated_externally_(false), |
54 opacity_(1.0f), | 48 opacity_(1.0f), |
55 delegate_(NULL) { | 49 delegate_(NULL) { |
56 #if defined(USE_WEBKIT_COMPOSITOR) | |
57 CreateWebLayer(); | |
58 #endif | |
59 } | 50 } |
60 | 51 |
61 Layer::~Layer() { | 52 Layer::~Layer() { |
62 if (parent_) | 53 if (parent_) |
63 parent_->Remove(this); | 54 parent_->Remove(this); |
64 for (size_t i = 0; i < children_.size(); ++i) | 55 for (size_t i = 0; i < children_.size(); ++i) |
65 children_[i]->parent_ = NULL; | 56 children_[i]->parent_ = NULL; |
66 #if defined(USE_WEBKIT_COMPOSITOR) | |
67 web_layer_.removeFromParent(); | |
68 #endif | |
69 } | 57 } |
70 | 58 |
71 Compositor* Layer::GetCompositor() { | 59 Compositor* Layer::GetCompositor() { |
72 return compositor_ ? compositor_ : parent_ ? parent_->GetCompositor() : NULL; | 60 return compositor_ ? compositor_ : parent_ ? parent_->GetCompositor() : NULL; |
73 } | 61 } |
74 | 62 |
75 void Layer::SetCompositor(Compositor* compositor) { | 63 void Layer::SetCompositor(Compositor* compositor) { |
76 // This function must only be called once, with a valid compositor, and only | 64 // This function must only be called once, with a valid compositor, and only |
77 // for the compositor's root layer. | 65 // for the compositor's root layer. |
78 DCHECK(!compositor_); | 66 DCHECK(!compositor_); |
79 DCHECK(compositor); | 67 DCHECK(compositor); |
80 DCHECK_EQ(compositor->root_layer(), this); | 68 DCHECK_EQ(compositor->root_layer(), this); |
81 compositor_ = compositor; | 69 compositor_ = compositor; |
82 } | 70 } |
83 | 71 |
84 void Layer::Add(Layer* child) { | 72 void Layer::Add(Layer* child) { |
85 if (child->parent_) | 73 if (child->parent_) |
86 child->parent_->Remove(child); | 74 child->parent_->Remove(child); |
87 child->parent_ = this; | 75 child->parent_ = this; |
88 children_.push_back(child); | 76 children_.push_back(child); |
89 #if defined(USE_WEBKIT_COMPOSITOR) | |
90 web_layer_.addChild(child->web_layer_); | |
91 #endif | |
92 | 77 |
93 RecomputeHole(); | 78 RecomputeHole(); |
94 } | 79 } |
95 | 80 |
96 void Layer::Remove(Layer* child) { | 81 void Layer::Remove(Layer* child) { |
97 std::vector<Layer*>::iterator i = | 82 std::vector<Layer*>::iterator i = |
98 std::find(children_.begin(), children_.end(), child); | 83 std::find(children_.begin(), children_.end(), child); |
99 DCHECK(i != children_.end()); | 84 DCHECK(i != children_.end()); |
100 children_.erase(i); | 85 children_.erase(i); |
101 child->parent_ = NULL; | 86 child->parent_ = NULL; |
102 #if defined(USE_WEBKIT_COMPOSITOR) | |
103 child->web_layer_.removeFromParent(); | |
104 #endif | |
105 | 87 |
106 RecomputeHole(); | 88 RecomputeHole(); |
107 | 89 |
108 child->DropTextures(); | 90 child->DropTextures(); |
109 } | 91 } |
110 | 92 |
111 void Layer::MoveToFront(Layer* child) { | 93 void Layer::MoveToFront(Layer* child) { |
112 std::vector<Layer*>::iterator i = | 94 std::vector<Layer*>::iterator i = |
113 std::find(children_.begin(), children_.end(), child); | 95 std::find(children_.begin(), children_.end(), child); |
114 DCHECK(i != children_.end()); | 96 DCHECK(i != children_.end()); |
115 children_.erase(i); | 97 children_.erase(i); |
116 children_.push_back(child); | 98 children_.push_back(child); |
117 #if defined(USE_WEBKIT_COMPOSITOR) | |
118 child->web_layer_.removeFromParent(); | |
119 web_layer_.addChild(child->web_layer_); | |
120 #endif | |
121 } | 99 } |
122 | 100 |
123 bool Layer::Contains(const Layer* other) const { | 101 bool Layer::Contains(const Layer* other) const { |
124 for (const Layer* parent = other; parent; parent = parent->parent()) { | 102 for (const Layer* parent = other; parent; parent = parent->parent()) { |
125 if (parent == this) | 103 if (parent == this) |
126 return true; | 104 return true; |
127 } | 105 } |
128 return false; | 106 return false; |
129 } | 107 } |
130 | 108 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 bool was_drawn = IsDrawn(); | 158 bool was_drawn = IsDrawn(); |
181 visible_ = visible; | 159 visible_ = visible; |
182 bool is_drawn = IsDrawn(); | 160 bool is_drawn = IsDrawn(); |
183 if (was_drawn == is_drawn) | 161 if (was_drawn == is_drawn) |
184 return; | 162 return; |
185 | 163 |
186 if (!is_drawn) | 164 if (!is_drawn) |
187 DropTextures(); | 165 DropTextures(); |
188 if (parent_) | 166 if (parent_) |
189 parent_->RecomputeHole(); | 167 parent_->RecomputeHole(); |
190 #if defined(USE_WEBKIT_COMPOSITOR) | |
191 // TODO(piman): Expose a visibility flag on WebLayer. | |
192 web_layer_.setOpacity(visible_ ? opacity_ : 0.f); | |
193 #endif | |
194 } | 168 } |
195 | 169 |
196 bool Layer::IsDrawn() const { | 170 bool Layer::IsDrawn() const { |
197 const Layer* layer = this; | 171 const Layer* layer = this; |
198 while (layer && layer->visible_) | 172 while (layer && layer->visible_) |
199 layer = layer->parent_; | 173 layer = layer->parent_; |
200 return layer == NULL; | 174 return layer == NULL; |
201 } | 175 } |
202 | 176 |
203 bool Layer::ShouldDraw() const { | 177 bool Layer::ShouldDraw() { |
204 return type_ == LAYER_HAS_TEXTURE && GetCombinedOpacity() > 0.0f && | 178 return type_ == LAYER_HAS_TEXTURE && GetCombinedOpacity() > 0.0f && |
205 !hole_rect_.Contains(gfx::Rect(gfx::Point(0, 0), bounds_.size())); | 179 !hole_rect_.Contains(gfx::Rect(gfx::Point(0, 0), bounds_.size())); |
206 } | 180 } |
207 | 181 |
208 // static | 182 // static |
209 void Layer::ConvertPointToLayer(const Layer* source, | 183 void Layer::ConvertPointToLayer(const Layer* source, |
210 const Layer* target, | 184 const Layer* target, |
211 gfx::Point* point) { | 185 gfx::Point* point) { |
212 const Layer* inner = NULL; | 186 const Layer* inner = NULL; |
213 const Layer* outer = NULL; | 187 const Layer* outer = NULL; |
(...skipping 11 matching lines...) Expand all Loading... |
225 } | 199 } |
226 | 200 |
227 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { | 201 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { |
228 if (fills_bounds_opaquely_ == fills_bounds_opaquely) | 202 if (fills_bounds_opaquely_ == fills_bounds_opaquely) |
229 return; | 203 return; |
230 | 204 |
231 fills_bounds_opaquely_ = fills_bounds_opaquely; | 205 fills_bounds_opaquely_ = fills_bounds_opaquely; |
232 | 206 |
233 if (parent()) | 207 if (parent()) |
234 parent()->RecomputeHole(); | 208 parent()->RecomputeHole(); |
235 #if defined(USE_WEBKIT_COMPOSITOR) | |
236 web_layer_.setOpaque(fills_bounds_opaquely); | |
237 #endif | |
238 } | 209 } |
239 | 210 |
240 void Layer::SetExternalTexture(ui::Texture* texture) { | 211 void Layer::SetExternalTexture(ui::Texture* texture) { |
241 DCHECK(texture); | 212 DCHECK(texture); |
242 layer_updated_externally_ = true; | 213 layer_updated_externally_ = true; |
243 texture_ = texture; | 214 texture_ = texture; |
244 } | 215 } |
245 | 216 |
246 void Layer::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) { | 217 void Layer::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) { |
247 #if defined(USE_WEBKIT_COMPOSITOR) | |
248 NOTREACHED(); | |
249 #else | |
250 DCHECK_EQ(type_, LAYER_HAS_TEXTURE); | 218 DCHECK_EQ(type_, LAYER_HAS_TEXTURE); |
251 | 219 |
252 if (!texture_.get()) | 220 if (!texture_.get()) |
253 texture_ = GetCompositor()->CreateTexture(); | 221 texture_ = GetCompositor()->CreateTexture(); |
254 | 222 |
255 texture_->SetCanvas(canvas, origin, bounds_.size()); | 223 texture_->SetCanvas(canvas, origin, bounds_.size()); |
256 invalid_rect_ = gfx::Rect(); | 224 invalid_rect_ = gfx::Rect(); |
257 #endif | |
258 } | 225 } |
259 | 226 |
260 void Layer::SchedulePaint(const gfx::Rect& invalid_rect) { | 227 void Layer::SchedulePaint(const gfx::Rect& invalid_rect) { |
261 #if defined(USE_WEBKIT_COMPOSITOR) | |
262 WebKit::WebFloatRect web_rect(invalid_rect.x(), | |
263 invalid_rect.y(), | |
264 invalid_rect.width(), | |
265 invalid_rect.height()); | |
266 web_layer_.invalidateRect(web_rect); | |
267 #else | |
268 invalid_rect_ = invalid_rect_.Union(invalid_rect); | 228 invalid_rect_ = invalid_rect_.Union(invalid_rect); |
269 ScheduleDraw(); | 229 ScheduleDraw(); |
270 #endif | |
271 } | 230 } |
272 | 231 |
273 void Layer::ScheduleDraw() { | 232 void Layer::ScheduleDraw() { |
274 Compositor* compositor = GetCompositor(); | 233 if (GetCompositor()) |
275 if (compositor) | 234 GetCompositor()->ScheduleDraw(); |
276 compositor->ScheduleDraw(); | |
277 } | 235 } |
278 | 236 |
279 void Layer::Draw() { | 237 void Layer::Draw() { |
280 #if defined(USE_WEBKIT_COMPOSITOR) | |
281 NOTREACHED(); | |
282 #else | |
283 DCHECK(GetCompositor()); | 238 DCHECK(GetCompositor()); |
284 if (!ShouldDraw()) | 239 if (!ShouldDraw()) |
285 return; | 240 return; |
286 | 241 |
287 UpdateLayerCanvas(); | 242 UpdateLayerCanvas(); |
288 | 243 |
289 // Layer drew nothing, no texture was created. | 244 // Layer drew nothing, no texture was created. |
290 if (!texture_.get()) | 245 if (!texture_.get()) |
291 return; | 246 return; |
292 | 247 |
(...skipping 19 matching lines...) Expand all Loading... |
312 texture_draw_params.has_valid_alpha_channel = has_valid_alpha_channel(); | 267 texture_draw_params.has_valid_alpha_channel = has_valid_alpha_channel(); |
313 | 268 |
314 std::vector<gfx::Rect> regions_to_draw; | 269 std::vector<gfx::Rect> regions_to_draw; |
315 PunchHole(gfx::Rect(gfx::Point(), bounds().size()), hole_rect_, | 270 PunchHole(gfx::Rect(gfx::Point(), bounds().size()), hole_rect_, |
316 ®ions_to_draw); | 271 ®ions_to_draw); |
317 | 272 |
318 for (size_t i = 0; i < regions_to_draw.size(); ++i) { | 273 for (size_t i = 0; i < regions_to_draw.size(); ++i) { |
319 if (!regions_to_draw[i].IsEmpty()) | 274 if (!regions_to_draw[i].IsEmpty()) |
320 texture_->Draw(texture_draw_params, regions_to_draw[i]); | 275 texture_->Draw(texture_draw_params, regions_to_draw[i]); |
321 } | 276 } |
322 #endif | |
323 } | 277 } |
324 | 278 |
325 void Layer::DrawTree() { | 279 void Layer::DrawTree() { |
326 #if defined(USE_WEBKIT_COMPOSITOR) | |
327 NOTREACHED(); | |
328 #else | |
329 if (!visible_) | 280 if (!visible_) |
330 return; | 281 return; |
331 | 282 |
332 Draw(); | 283 Draw(); |
333 for (size_t i = 0; i < children_.size(); ++i) | 284 for (size_t i = 0; i < children_.size(); ++i) |
334 children_.at(i)->DrawTree(); | 285 children_.at(i)->DrawTree(); |
335 #endif | |
336 } | |
337 | |
338 void Layer::notifyNeedsComposite() { | |
339 #if defined(USE_WEBKIT_COMPOSITOR) | |
340 ScheduleDraw(); | |
341 #else | |
342 NOTREACHED(); | |
343 #endif | |
344 } | |
345 | |
346 void Layer::paintContents(WebKit::WebCanvas* web_canvas, | |
347 const WebKit::WebRect& clip) { | |
348 #if defined(USE_WEBKIT_COMPOSITOR) | |
349 gfx::CanvasSkia canvas(web_canvas); | |
350 delegate_->OnPaintLayer(&canvas); | |
351 #else | |
352 NOTREACHED(); | |
353 #endif | |
354 } | 286 } |
355 | 287 |
356 float Layer::GetCombinedOpacity() const { | 288 float Layer::GetCombinedOpacity() const { |
357 float opacity = opacity_; | 289 float opacity = opacity_; |
358 Layer* current = this->parent_; | 290 Layer* current = this->parent_; |
359 while (current) { | 291 while (current) { |
360 opacity *= current->opacity_; | 292 opacity *= current->opacity_; |
361 current = current->parent_; | 293 current = current->parent_; |
362 } | 294 } |
363 return opacity; | 295 return opacity; |
364 } | 296 } |
365 | 297 |
366 void Layer::UpdateLayerCanvas() { | 298 void Layer::UpdateLayerCanvas() { |
367 #if defined(USE_WEBKIT_COMPOSITOR) | |
368 NOTREACHED(); | |
369 #else | |
370 // If we have no delegate, that means that whoever constructed the Layer is | 299 // If we have no delegate, that means that whoever constructed the Layer is |
371 // setting its canvas directly with SetCanvas(). | 300 // setting its canvas directly with SetCanvas(). |
372 if (!delegate_ || layer_updated_externally_) | 301 if (!delegate_ || layer_updated_externally_) |
373 return; | 302 return; |
374 gfx::Rect local_bounds = gfx::Rect(gfx::Point(), bounds_.size()); | 303 gfx::Rect local_bounds = gfx::Rect(gfx::Point(), bounds_.size()); |
375 gfx::Rect draw_rect = texture_.get() ? invalid_rect_.Intersect(local_bounds) : | 304 gfx::Rect draw_rect = texture_.get() ? invalid_rect_.Intersect(local_bounds) : |
376 local_bounds; | 305 local_bounds; |
377 if (draw_rect.IsEmpty()) { | 306 if (draw_rect.IsEmpty()) { |
378 invalid_rect_ = gfx::Rect(); | 307 invalid_rect_ = gfx::Rect(); |
379 return; | 308 return; |
380 } | 309 } |
381 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvas( | 310 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvas( |
382 draw_rect.width(), draw_rect.height(), false)); | 311 draw_rect.width(), draw_rect.height(), false)); |
383 canvas->TranslateInt(-draw_rect.x(), -draw_rect.y()); | 312 canvas->TranslateInt(-draw_rect.x(), -draw_rect.y()); |
384 delegate_->OnPaintLayer(canvas.get()); | 313 delegate_->OnPaintLayer(canvas.get()); |
385 SetCanvas(*canvas->GetSkCanvas(), draw_rect.origin()); | 314 SetCanvas(*canvas->GetSkCanvas(), draw_rect.origin()); |
386 #endif | |
387 } | 315 } |
388 | 316 |
389 void Layer::RecomputeHole() { | 317 void Layer::RecomputeHole() { |
390 if (type_ == LAYER_HAS_NO_TEXTURE) | 318 if (type_ == LAYER_HAS_NO_TEXTURE) |
391 return; | 319 return; |
392 | 320 |
393 // Reset to default. | 321 // Reset to default. |
394 hole_rect_ = gfx::Rect(); | 322 hole_rect_ = gfx::Rect(); |
395 | 323 |
396 // Find the largest hole | 324 // Find the largest hole |
(...skipping 25 matching lines...) Expand all Loading... |
422 candidate_hole = gfx::Rect(bounds().size()).Intersect(candidate_hole); | 350 candidate_hole = gfx::Rect(bounds().size()).Intersect(candidate_hole); |
423 | 351 |
424 // Ensure we have the largest hole. | 352 // Ensure we have the largest hole. |
425 if (candidate_hole.size().GetArea() > hole_rect_.size().GetArea()) | 353 if (candidate_hole.size().GetArea() > hole_rect_.size().GetArea()) |
426 hole_rect_ = candidate_hole; | 354 hole_rect_ = candidate_hole; |
427 } | 355 } |
428 | 356 |
429 // Free up texture memory if the hole fills bounds of layer. | 357 // Free up texture memory if the hole fills bounds of layer. |
430 if (!ShouldDraw() && !layer_updated_externally_) | 358 if (!ShouldDraw() && !layer_updated_externally_) |
431 texture_ = NULL; | 359 texture_ = NULL; |
432 | |
433 #if defined(USE_WEBKIT_COMPOSITOR) | |
434 RecomputeDrawsContent(); | |
435 #endif | |
436 } | 360 } |
437 | 361 |
438 bool Layer::IsCompletelyOpaque() const { | 362 bool Layer::IsCompletelyOpaque() const { |
439 return fills_bounds_opaquely() && GetCombinedOpacity() == 1.0f; | 363 return fills_bounds_opaquely() && GetCombinedOpacity() == 1.0f; |
440 } | 364 } |
441 | 365 |
442 // static | 366 // static |
443 void Layer::PunchHole(const gfx::Rect& rect, | 367 void Layer::PunchHole(const gfx::Rect& rect, |
444 const gfx::Rect& region_to_punch_out, | 368 const gfx::Rect& region_to_punch_out, |
445 std::vector<gfx::Rect>* sides) { | 369 std::vector<gfx::Rect>* sides) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 SetTransformImmediately(animator_->GetTargetTransform()); | 459 SetTransformImmediately(animator_->GetTargetTransform()); |
536 } | 460 } |
537 animator_.reset(); | 461 animator_.reset(); |
538 } | 462 } |
539 | 463 |
540 void Layer::SetBoundsImmediately(const gfx::Rect& bounds) { | 464 void Layer::SetBoundsImmediately(const gfx::Rect& bounds) { |
541 bounds_ = bounds; | 465 bounds_ = bounds; |
542 | 466 |
543 if (parent()) | 467 if (parent()) |
544 parent()->RecomputeHole(); | 468 parent()->RecomputeHole(); |
545 #if defined(USE_WEBKIT_COMPOSITOR) | |
546 web_layer_.setBounds(bounds.size()); | |
547 RecomputeTransform(); | |
548 RecomputeDrawsContent(); | |
549 #endif | |
550 } | 469 } |
551 | 470 |
552 void Layer::SetTransformImmediately(const ui::Transform& transform) { | 471 void Layer::SetTransformImmediately(const ui::Transform& transform) { |
553 transform_ = transform; | 472 transform_ = transform; |
554 | 473 |
555 if (parent()) | 474 if (parent()) |
556 parent()->RecomputeHole(); | 475 parent()->RecomputeHole(); |
557 #if defined(USE_WEBKIT_COMPOSITOR) | |
558 RecomputeTransform(); | |
559 #endif | |
560 } | 476 } |
561 | 477 |
562 void Layer::SetOpacityImmediately(float opacity) { | 478 void Layer::SetOpacityImmediately(float opacity) { |
563 bool was_opaque = GetCombinedOpacity() == 1.0f; | 479 bool was_opaque = GetCombinedOpacity() == 1.0f; |
564 opacity_ = opacity; | 480 opacity_ = opacity; |
565 bool is_opaque = GetCombinedOpacity() == 1.0f; | 481 bool is_opaque = GetCombinedOpacity() == 1.0f; |
566 | 482 |
567 // If our opacity has changed we need to recompute our hole, our parent's hole | 483 // If our opacity has changed we need to recompute our hole, our parent's hole |
568 // and the holes of all our descendants. | 484 // and the holes of all our descendants. |
569 if (was_opaque != is_opaque) { | 485 if (was_opaque != is_opaque) { |
570 if (parent_) | 486 if (parent_) |
571 parent_->RecomputeHole(); | 487 parent_->RecomputeHole(); |
572 std::queue<Layer*> to_process; | 488 std::queue<Layer*> to_process; |
573 to_process.push(this); | 489 to_process.push(this); |
574 while (!to_process.empty()) { | 490 while (!to_process.empty()) { |
575 Layer* current = to_process.front(); | 491 Layer* current = to_process.front(); |
576 to_process.pop(); | 492 to_process.pop(); |
577 current->RecomputeHole(); | 493 current->RecomputeHole(); |
578 for (size_t i = 0; i < current->children_.size(); ++i) | 494 for (size_t i = 0; i < current->children_.size(); ++i) |
579 to_process.push(current->children_.at(i)); | 495 to_process.push(current->children_.at(i)); |
580 } | 496 } |
581 } | 497 } |
582 #if defined(USE_WEBKIT_COMPOSITOR) | |
583 if (visible_) | |
584 web_layer_.setOpacity(opacity); | |
585 RecomputeDrawsContent(); | |
586 #endif | |
587 } | 498 } |
588 | 499 |
589 void Layer::SetBoundsFromAnimator(const gfx::Rect& bounds) { | 500 void Layer::SetBoundsFromAnimator(const gfx::Rect& bounds) { |
590 SetBoundsImmediately(bounds); | 501 SetBoundsImmediately(bounds); |
591 } | 502 } |
592 | 503 |
593 void Layer::SetTransformFromAnimator(const Transform& transform) { | 504 void Layer::SetTransformFromAnimator(const Transform& transform) { |
594 SetTransformImmediately(transform); | 505 SetTransformImmediately(transform); |
595 } | 506 } |
596 | 507 |
597 void Layer::SetOpacityFromAnimator(float opacity) { | 508 void Layer::SetOpacityFromAnimator(float opacity) { |
598 SetOpacityImmediately(opacity); | 509 SetOpacityImmediately(opacity); |
599 } | 510 } |
600 | 511 |
601 #if defined(USE_WEBKIT_COMPOSITOR) | |
602 void Layer::CreateWebLayer() { | |
603 web_layer_ = WebKit::WebContentLayer::create(this, this); | |
604 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | |
605 web_layer_.setOpaque(true); | |
606 RecomputeDrawsContent(); | |
607 } | |
608 | |
609 void Layer::RecomputeTransform() { | |
610 ui::Transform transform = transform_; | |
611 transform.ConcatTranslate(bounds_.x(), bounds_.y()); | |
612 web_layer_.setTransform(transform.matrix()); | |
613 } | |
614 | |
615 void Layer::RecomputeDrawsContent() { | |
616 web_layer_.setDrawsContent(ShouldDraw()); | |
617 } | |
618 #endif | |
619 | |
620 } // namespace ui | 512 } // namespace ui |
OLD | NEW |