Chromium Code Reviews| 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/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 11 #include "ui/gfx/canvas_skia.h" | 11 #include "ui/gfx/canvas_skia.h" |
| 12 #include "ui/gfx/point3.h" | 12 #include "ui/gfx/point3.h" |
| 13 | 13 |
| 14 namespace ui { | 14 namespace ui { |
| 15 | 15 |
| 16 Layer::Layer(Compositor* compositor) | 16 Layer::Layer(Compositor* compositor) |
| 17 : compositor_(compositor), | 17 : compositor_(compositor), |
| 18 texture_(compositor->CreateTexture()), | 18 texture_(compositor->CreateTexture()), |
| 19 parent_(NULL), | 19 parent_(NULL), |
| 20 fills_bounds_opaquely_(false), | 20 fills_bounds_opaquely_(false), |
| 21 delegate_(NULL) { | 21 delegate_(NULL) { |
|
sky
2011/09/13 17:47:06
visible_(true)
| |
| 22 } | 22 } |
| 23 | 23 |
| 24 Layer::~Layer() { | 24 Layer::~Layer() { |
| 25 if (parent_) | 25 if (parent_) |
| 26 parent_->Remove(this); | 26 parent_->Remove(this); |
| 27 for (size_t i = 0; i < children_.size(); ++i) | 27 for (size_t i = 0; i < children_.size(); ++i) |
| 28 children_[i]->parent_ = NULL; | 28 children_[i]->parent_ = NULL; |
| 29 } | 29 } |
| 30 | 30 |
| 31 void Layer::Add(Layer* child) { | 31 void Layer::Add(Layer* child) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 texture_->SetCanvas(canvas, origin, bounds_.size()); | 111 texture_->SetCanvas(canvas, origin, bounds_.size()); |
| 112 invalid_rect_ = gfx::Rect(); | 112 invalid_rect_ = gfx::Rect(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void Layer::SchedulePaint(const gfx::Rect& invalid_rect) { | 115 void Layer::SchedulePaint(const gfx::Rect& invalid_rect) { |
| 116 invalid_rect_ = invalid_rect_.Union(invalid_rect); | 116 invalid_rect_ = invalid_rect_.Union(invalid_rect); |
| 117 compositor_->SchedulePaint(); | 117 compositor_->SchedulePaint(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void Layer::Draw() { | 120 void Layer::Draw() { |
| 121 if (!visible_) | |
| 122 return; | |
| 123 | |
| 121 UpdateLayerCanvas(); | 124 UpdateLayerCanvas(); |
| 122 | 125 |
| 123 ui::TextureDrawParams texture_draw_params; | 126 ui::TextureDrawParams texture_draw_params; |
| 124 for (Layer* layer = this; layer; layer = layer->parent_) { | 127 for (Layer* layer = this; layer; layer = layer->parent_) { |
| 125 texture_draw_params.transform.ConcatTransform(layer->transform_); | 128 texture_draw_params.transform.ConcatTransform(layer->transform_); |
| 126 texture_draw_params.transform.ConcatTranslate( | 129 texture_draw_params.transform.ConcatTranslate( |
| 127 static_cast<float>(layer->bounds_.x()), | 130 static_cast<float>(layer->bounds_.x()), |
| 128 static_cast<float>(layer->bounds_.y())); | 131 static_cast<float>(layer->bounds_.y())); |
| 129 } | 132 } |
| 130 | 133 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 154 hole_rect_.height())); | 157 hole_rect_.height())); |
| 155 | 158 |
| 156 // bottom | 159 // bottom |
| 157 DrawRegion(texture_draw_params, gfx::Rect( | 160 DrawRegion(texture_draw_params, gfx::Rect( |
| 158 0, | 161 0, |
| 159 hole_rect_.bottom(), | 162 hole_rect_.bottom(), |
| 160 bounds_.width(), | 163 bounds_.width(), |
| 161 bounds_.height() - hole_rect_.bottom())); | 164 bounds_.height() - hole_rect_.bottom())); |
| 162 } | 165 } |
| 163 | 166 |
| 167 void Layer::DrawTree() { | |
| 168 Draw(); | |
| 169 for (size_t i = 0; i < children_.size(); ++i) | |
|
sky
2011/09/13 17:47:06
I don't think you want to paint children if this i
| |
| 170 children_.at(i)->DrawTree(); | |
| 171 } | |
| 172 | |
| 164 void Layer::DrawRegion(const ui::TextureDrawParams& params, | 173 void Layer::DrawRegion(const ui::TextureDrawParams& params, |
| 165 const gfx::Rect& region_to_draw) { | 174 const gfx::Rect& region_to_draw) { |
| 166 if (!region_to_draw.IsEmpty()) | 175 if (!region_to_draw.IsEmpty()) |
| 167 texture_->Draw(params, region_to_draw); | 176 texture_->Draw(params, region_to_draw); |
| 168 } | 177 } |
| 169 | 178 |
| 170 void Layer::UpdateLayerCanvas() { | 179 void Layer::UpdateLayerCanvas() { |
| 171 // If we have no delegate, that means that whoever constructed the Layer is | 180 // If we have no delegate, that means that whoever constructed the Layer is |
| 172 // setting its canvas directly with SetCanvas(). | 181 // setting its canvas directly with SetCanvas(). |
| 173 if (!delegate_) | 182 if (!delegate_) |
| 174 return; | 183 return; |
| 175 gfx::Rect local_bounds = gfx::Rect(gfx::Point(), bounds_.size()); | 184 gfx::Rect local_bounds = gfx::Rect(gfx::Point(), bounds_.size()); |
| 176 gfx::Rect draw_rect = invalid_rect_.Intersect(local_bounds); | 185 gfx::Rect draw_rect = invalid_rect_.Intersect(local_bounds); |
| 177 if (draw_rect.IsEmpty()) { | 186 if (draw_rect.IsEmpty()) { |
| 178 invalid_rect_ = gfx::Rect(); | 187 invalid_rect_ = gfx::Rect(); |
| 179 return; | 188 return; |
| 180 } | 189 } |
| 181 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvas( | 190 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvas( |
| 182 draw_rect.width(), draw_rect.height(), false)); | 191 draw_rect.width(), draw_rect.height(), false)); |
| 183 canvas->TranslateInt(draw_rect.x(), draw_rect.y()); | 192 canvas->TranslateInt(draw_rect.x(), draw_rect.y()); |
| 184 delegate_->OnPaint(canvas.get()); | 193 delegate_->OnPaintLayer(canvas.get()); |
| 185 SetCanvas(*canvas->AsCanvasSkia(), bounds().origin()); | 194 SetCanvas(*canvas->AsCanvasSkia(), bounds().origin()); |
| 186 } | 195 } |
| 187 | 196 |
| 188 void Layer::RecomputeHole() { | 197 void Layer::RecomputeHole() { |
| 189 for (size_t i = 0; i < children_.size(); ++i) { | 198 for (size_t i = 0; i < children_.size(); ++i) { |
| 190 if (children_[i]->fills_bounds_opaquely() && | 199 if (children_[i]->fills_bounds_opaquely() && |
| 191 !children_[i]->transform().HasChange()) { | 200 !children_[i]->transform().HasChange()) { |
| 192 hole_rect_ = children_[i]->bounds(); | 201 hole_rect_ = children_[i]->bounds(); |
| 193 return; | 202 return; |
| 194 } | 203 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 223 for (; p && p != ancestor; p = p->parent()) { | 232 for (; p && p != ancestor; p = p->parent()) { |
| 224 if (p->transform().HasChange()) | 233 if (p->transform().HasChange()) |
| 225 transform->ConcatTransform(p->transform()); | 234 transform->ConcatTransform(p->transform()); |
| 226 transform->ConcatTranslate(static_cast<float>(p->bounds().x()), | 235 transform->ConcatTranslate(static_cast<float>(p->bounds().x()), |
| 227 static_cast<float>(p->bounds().y())); | 236 static_cast<float>(p->bounds().y())); |
| 228 } | 237 } |
| 229 return p == ancestor; | 238 return p == ancestor; |
| 230 } | 239 } |
| 231 | 240 |
| 232 } // namespace ui | 241 } // namespace ui |
| OLD | NEW |