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

Unified 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: Address review comments Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: ui/compositor/layer.cc
diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc
index 119a1cfa868390103209691c432da434f32c665f..c72bf3b65de48604677a4cab87766097de182295 100644
--- a/ui/compositor/layer.cc
+++ b/ui/compositor/layer.cc
@@ -43,6 +43,7 @@ Layer::Layer()
compositor_(NULL),
parent_(NULL),
visible_(true),
+ is_drawn_(true),
force_render_surface_(false),
fills_bounds_opaquely_(true),
layer_updated_externally_(false),
@@ -70,6 +71,7 @@ Layer::Layer(LayerType type)
compositor_(NULL),
parent_(NULL),
visible_(true),
+ is_drawn_(true),
force_render_surface_(false),
fills_bounds_opaquely_(true),
layer_updated_externally_(false),
@@ -134,6 +136,7 @@ void Layer::Add(Layer* child) {
children_.push_back(child);
cc_layer_->addChild(child->cc_layer_);
child->OnDeviceScaleFactorChanged(device_scale_factor_);
+ child->UpdateIsDrawn();
}
void Layer::Remove(Layer* child) {
@@ -367,10 +370,21 @@ bool Layer::GetTargetVisibility() const {
}
bool Layer::IsDrawn() const {
- const Layer* layer = this;
- while (layer && layer->visible_)
- layer = layer->parent_;
- return layer == NULL;
+ return is_drawn_;
+}
+
+void Layer::UpdateIsDrawn() {
+ bool updated_is_drawn = visible_ && (!parent_ || parent_->IsDrawn());
+
+ if (updated_is_drawn == is_drawn_)
+ return;
+
+ is_drawn_ = updated_is_drawn;
+ cc_layer_->setIsDrawable(is_drawn_ && type_ != LAYER_NOT_DRAWN);
+
+ for (size_t i = 0; i < children_.size(); ++i) {
+ children_[i]->UpdateIsDrawn();
+ }
}
bool Layer::ShouldDraw() const {
@@ -438,9 +452,9 @@ void Layer::SetExternalTexture(Texture* texture) {
}
cc_layer_->setAnchorPoint(gfx::PointF());
cc_layer_->setContentsOpaque(fills_bounds_opaquely_);
- cc_layer_->setOpacity(visible_ ? opacity_ : 0.f);
+ cc_layer_->setOpacity(opacity_);
cc_layer_->setForceRenderSurface(force_render_surface_);
- cc_layer_->setIsDrawable(true);
+ cc_layer_->setIsDrawable(IsDrawn());
RecomputeTransform();
}
RecomputeDrawsContentAndUVRect();
@@ -645,8 +659,7 @@ void Layer::SetOpacityImmediately(float opacity) {
bool schedule_draw = (opacity != opacity_ && IsDrawn());
piman 2013/02/01 18:06:55 nit: I'm pretty sure you can remove that logic now
ajuma 2013/02/01 18:40:24 Done.
opacity_ = opacity;
- if (visible_)
- cc_layer_->setOpacity(opacity);
+ cc_layer_->setOpacity(opacity);
if (schedule_draw)
ScheduleDraw();
}
@@ -656,8 +669,7 @@ void Layer::SetVisibilityImmediately(bool visible) {
return;
visible_ = visible;
- // TODO(piman): Expose a visibility flag on WebLayer.
- cc_layer_->setOpacity(visible_ ? opacity_ : 0.f);
+ UpdateIsDrawn();
}
void Layer::SetBrightnessImmediately(float brightness) {

Powered by Google App Engine
This is Rietveld 408576698