Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1881)

Side by Side Diff: ui/compositor/layer.cc

Issue 12093067: Handle ui::Layer's visibility using cc::Layer's m_isDrawable flag (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix nits Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/compositor/layer.h ('k') | ui/compositor/layer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/compositor/layer.h" 5 #include "ui/compositor/layer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 25 matching lines...) Expand all
36 36
37 } // namespace 37 } // namespace
38 38
39 namespace ui { 39 namespace ui {
40 40
41 Layer::Layer() 41 Layer::Layer()
42 : type_(LAYER_TEXTURED), 42 : type_(LAYER_TEXTURED),
43 compositor_(NULL), 43 compositor_(NULL),
44 parent_(NULL), 44 parent_(NULL),
45 visible_(true), 45 visible_(true),
46 is_drawn_(true),
46 force_render_surface_(false), 47 force_render_surface_(false),
47 fills_bounds_opaquely_(true), 48 fills_bounds_opaquely_(true),
48 layer_updated_externally_(false), 49 layer_updated_externally_(false),
49 opacity_(1.0f), 50 opacity_(1.0f),
50 background_blur_radius_(0), 51 background_blur_radius_(0),
51 layer_saturation_(0.0f), 52 layer_saturation_(0.0f),
52 layer_brightness_(0.0f), 53 layer_brightness_(0.0f),
53 layer_grayscale_(0.0f), 54 layer_grayscale_(0.0f),
54 layer_inverted_(false), 55 layer_inverted_(false),
55 layer_mask_(NULL), 56 layer_mask_(NULL),
56 layer_mask_back_link_(NULL), 57 layer_mask_back_link_(NULL),
57 zoom_x_offset_(0), 58 zoom_x_offset_(0),
58 zoom_y_offset_(0), 59 zoom_y_offset_(0),
59 zoom_(1), 60 zoom_(1),
60 zoom_inset_(0), 61 zoom_inset_(0),
61 delegate_(NULL), 62 delegate_(NULL),
62 cc_layer_(NULL), 63 cc_layer_(NULL),
63 scale_content_(true), 64 scale_content_(true),
64 device_scale_factor_(1.0f) { 65 device_scale_factor_(1.0f) {
65 CreateWebLayer(); 66 CreateWebLayer();
66 } 67 }
67 68
68 Layer::Layer(LayerType type) 69 Layer::Layer(LayerType type)
69 : type_(type), 70 : type_(type),
70 compositor_(NULL), 71 compositor_(NULL),
71 parent_(NULL), 72 parent_(NULL),
72 visible_(true), 73 visible_(true),
74 is_drawn_(true),
73 force_render_surface_(false), 75 force_render_surface_(false),
74 fills_bounds_opaquely_(true), 76 fills_bounds_opaquely_(true),
75 layer_updated_externally_(false), 77 layer_updated_externally_(false),
76 opacity_(1.0f), 78 opacity_(1.0f),
77 background_blur_radius_(0), 79 background_blur_radius_(0),
78 layer_saturation_(0.0f), 80 layer_saturation_(0.0f),
79 layer_brightness_(0.0f), 81 layer_brightness_(0.0f),
80 layer_grayscale_(0.0f), 82 layer_grayscale_(0.0f),
81 layer_inverted_(false), 83 layer_inverted_(false),
82 layer_mask_(NULL), 84 layer_mask_(NULL),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 129 }
128 130
129 void Layer::Add(Layer* child) { 131 void Layer::Add(Layer* child) {
130 DCHECK(!child->compositor_); 132 DCHECK(!child->compositor_);
131 if (child->parent_) 133 if (child->parent_)
132 child->parent_->Remove(child); 134 child->parent_->Remove(child);
133 child->parent_ = this; 135 child->parent_ = this;
134 children_.push_back(child); 136 children_.push_back(child);
135 cc_layer_->addChild(child->cc_layer_); 137 cc_layer_->addChild(child->cc_layer_);
136 child->OnDeviceScaleFactorChanged(device_scale_factor_); 138 child->OnDeviceScaleFactorChanged(device_scale_factor_);
139 child->UpdateIsDrawn();
137 } 140 }
138 141
139 void Layer::Remove(Layer* child) { 142 void Layer::Remove(Layer* child) {
140 std::vector<Layer*>::iterator i = 143 std::vector<Layer*>::iterator i =
141 std::find(children_.begin(), children_.end(), child); 144 std::find(children_.begin(), children_.end(), child);
142 DCHECK(i != children_.end()); 145 DCHECK(i != children_.end());
143 children_.erase(i); 146 children_.erase(i);
144 child->parent_ = NULL; 147 child->parent_ = NULL;
145 child->cc_layer_->removeFromParent(); 148 child->cc_layer_->removeFromParent();
146 } 149 }
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 } 363 }
361 364
362 bool Layer::GetTargetVisibility() const { 365 bool Layer::GetTargetVisibility() const {
363 if (animator_.get() && animator_->IsAnimatingProperty( 366 if (animator_.get() && animator_->IsAnimatingProperty(
364 LayerAnimationElement::VISIBILITY)) 367 LayerAnimationElement::VISIBILITY))
365 return animator_->GetTargetVisibility(); 368 return animator_->GetTargetVisibility();
366 return visible_; 369 return visible_;
367 } 370 }
368 371
369 bool Layer::IsDrawn() const { 372 bool Layer::IsDrawn() const {
370 const Layer* layer = this; 373 return is_drawn_;
371 while (layer && layer->visible_) 374 }
372 layer = layer->parent_; 375
373 return layer == NULL; 376 void Layer::UpdateIsDrawn() {
377 bool updated_is_drawn = visible_ && (!parent_ || parent_->IsDrawn());
378
379 if (updated_is_drawn == is_drawn_)
380 return;
381
382 is_drawn_ = updated_is_drawn;
383 cc_layer_->setIsDrawable(is_drawn_ && type_ != LAYER_NOT_DRAWN);
384
385 for (size_t i = 0; i < children_.size(); ++i) {
386 children_[i]->UpdateIsDrawn();
387 }
374 } 388 }
375 389
376 bool Layer::ShouldDraw() const { 390 bool Layer::ShouldDraw() const {
377 return type_ != LAYER_NOT_DRAWN && GetCombinedOpacity() > 0.0f; 391 return type_ != LAYER_NOT_DRAWN && GetCombinedOpacity() > 0.0f;
378 } 392 }
379 393
380 // static 394 // static
381 void Layer::ConvertPointToLayer(const Layer* source, 395 void Layer::ConvertPointToLayer(const Layer* source,
382 const Layer* target, 396 const Layer* target,
383 gfx::Point* point) { 397 gfx::Point* point) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 parent_->cc_layer_->replaceChild(cc_layer_, new_layer); 445 parent_->cc_layer_->replaceChild(cc_layer_, new_layer);
432 } 446 }
433 cc_layer_= new_layer; 447 cc_layer_= new_layer;
434 cc_layer_is_accelerated_ = layer_updated_externally_; 448 cc_layer_is_accelerated_ = layer_updated_externally_;
435 for (size_t i = 0; i < children_.size(); ++i) { 449 for (size_t i = 0; i < children_.size(); ++i) {
436 DCHECK(children_[i]->cc_layer_); 450 DCHECK(children_[i]->cc_layer_);
437 cc_layer_->addChild(children_[i]->cc_layer_); 451 cc_layer_->addChild(children_[i]->cc_layer_);
438 } 452 }
439 cc_layer_->setAnchorPoint(gfx::PointF()); 453 cc_layer_->setAnchorPoint(gfx::PointF());
440 cc_layer_->setContentsOpaque(fills_bounds_opaquely_); 454 cc_layer_->setContentsOpaque(fills_bounds_opaquely_);
441 cc_layer_->setOpacity(visible_ ? opacity_ : 0.f); 455 cc_layer_->setOpacity(opacity_);
442 cc_layer_->setForceRenderSurface(force_render_surface_); 456 cc_layer_->setForceRenderSurface(force_render_surface_);
443 cc_layer_->setIsDrawable(true); 457 cc_layer_->setIsDrawable(IsDrawn());
444 RecomputeTransform(); 458 RecomputeTransform();
445 } 459 }
446 RecomputeDrawsContentAndUVRect(); 460 RecomputeDrawsContentAndUVRect();
447 } 461 }
448 462
449 void Layer::SetColor(SkColor color) { 463 void Layer::SetColor(SkColor color) {
450 GetAnimator()->SetColor(color); 464 GetAnimator()->SetColor(color);
451 } 465 }
452 466
453 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { 467 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 } 649 }
636 } 650 }
637 651
638 void Layer::SetTransformImmediately(const gfx::Transform& transform) { 652 void Layer::SetTransformImmediately(const gfx::Transform& transform) {
639 transform_ = transform; 653 transform_ = transform;
640 654
641 RecomputeTransform(); 655 RecomputeTransform();
642 } 656 }
643 657
644 void Layer::SetOpacityImmediately(float opacity) { 658 void Layer::SetOpacityImmediately(float opacity) {
645 bool schedule_draw = (opacity != opacity_ && IsDrawn());
646 opacity_ = opacity; 659 opacity_ = opacity;
647 660
648 if (visible_) 661 cc_layer_->setOpacity(opacity);
649 cc_layer_->setOpacity(opacity); 662 ScheduleDraw();
650 if (schedule_draw)
651 ScheduleDraw();
652 } 663 }
653 664
654 void Layer::SetVisibilityImmediately(bool visible) { 665 void Layer::SetVisibilityImmediately(bool visible) {
655 if (visible_ == visible) 666 if (visible_ == visible)
656 return; 667 return;
657 668
658 visible_ = visible; 669 visible_ = visible;
659 // TODO(piman): Expose a visibility flag on WebLayer. 670 UpdateIsDrawn();
660 cc_layer_->setOpacity(visible_ ? opacity_ : 0.f);
661 } 671 }
662 672
663 void Layer::SetBrightnessImmediately(float brightness) { 673 void Layer::SetBrightnessImmediately(float brightness) {
664 layer_brightness_ = brightness; 674 layer_brightness_ = brightness;
665 SetLayerFilters(); 675 SetLayerFilters();
666 } 676 }
667 677
668 void Layer::SetGrayscaleImmediately(float grayscale) { 678 void Layer::SetGrayscaleImmediately(float grayscale) {
669 layer_grayscale_ = grayscale; 679 layer_grayscale_ = grayscale;
670 SetLayerFilters(); 680 SetLayerFilters();
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 gfx::PointF uv_bottom_right( 800 gfx::PointF uv_bottom_right(
791 static_cast<float>(size.width())/texture_size.width(), 801 static_cast<float>(size.width())/texture_size.width(),
792 static_cast<float>(size.height())/texture_size.height()); 802 static_cast<float>(size.height())/texture_size.height());
793 texture_layer_->setUV(uv_top_left, uv_bottom_right); 803 texture_layer_->setUV(uv_top_left, uv_bottom_right);
794 804
795 cc_layer_->setBounds(ConvertSizeToPixel(this, size)); 805 cc_layer_->setBounds(ConvertSizeToPixel(this, size));
796 } 806 }
797 } 807 }
798 808
799 } // namespace ui 809 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/layer.h ('k') | ui/compositor/layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698