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 visible_(true), |
20 fills_bounds_opaquely_(false), | 21 fills_bounds_opaquely_(false), |
21 delegate_(NULL) { | 22 delegate_(NULL) { |
22 } | 23 } |
23 | 24 |
24 Layer::~Layer() { | 25 Layer::~Layer() { |
25 if (parent_) | 26 if (parent_) |
26 parent_->Remove(this); | 27 parent_->Remove(this); |
27 for (size_t i = 0; i < children_.size(); ++i) | 28 for (size_t i = 0; i < children_.size(); ++i) |
28 children_[i]->parent_ = NULL; | 29 children_[i]->parent_ = NULL; |
29 } | 30 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 hole_rect_.height())); | 155 hole_rect_.height())); |
155 | 156 |
156 // bottom | 157 // bottom |
157 DrawRegion(texture_draw_params, gfx::Rect( | 158 DrawRegion(texture_draw_params, gfx::Rect( |
158 0, | 159 0, |
159 hole_rect_.bottom(), | 160 hole_rect_.bottom(), |
160 bounds_.width(), | 161 bounds_.width(), |
161 bounds_.height() - hole_rect_.bottom())); | 162 bounds_.height() - hole_rect_.bottom())); |
162 } | 163 } |
163 | 164 |
| 165 void Layer::DrawTree() { |
| 166 if (!visible_) |
| 167 return; |
| 168 |
| 169 Draw(); |
| 170 for (size_t i = 0; i < children_.size(); ++i) |
| 171 children_.at(i)->DrawTree(); |
| 172 } |
| 173 |
164 void Layer::DrawRegion(const ui::TextureDrawParams& params, | 174 void Layer::DrawRegion(const ui::TextureDrawParams& params, |
165 const gfx::Rect& region_to_draw) { | 175 const gfx::Rect& region_to_draw) { |
166 if (!region_to_draw.IsEmpty()) | 176 if (!region_to_draw.IsEmpty()) |
167 texture_->Draw(params, region_to_draw); | 177 texture_->Draw(params, region_to_draw); |
168 } | 178 } |
169 | 179 |
170 void Layer::UpdateLayerCanvas() { | 180 void Layer::UpdateLayerCanvas() { |
171 // If we have no delegate, that means that whoever constructed the Layer is | 181 // If we have no delegate, that means that whoever constructed the Layer is |
172 // setting its canvas directly with SetCanvas(). | 182 // setting its canvas directly with SetCanvas(). |
173 if (!delegate_) | 183 if (!delegate_) |
174 return; | 184 return; |
175 gfx::Rect local_bounds = gfx::Rect(gfx::Point(), bounds_.size()); | 185 gfx::Rect local_bounds = gfx::Rect(gfx::Point(), bounds_.size()); |
176 gfx::Rect draw_rect = invalid_rect_.Intersect(local_bounds); | 186 gfx::Rect draw_rect = invalid_rect_.Intersect(local_bounds); |
177 if (draw_rect.IsEmpty()) { | 187 if (draw_rect.IsEmpty()) { |
178 invalid_rect_ = gfx::Rect(); | 188 invalid_rect_ = gfx::Rect(); |
179 return; | 189 return; |
180 } | 190 } |
181 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvas( | 191 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvas( |
182 draw_rect.width(), draw_rect.height(), false)); | 192 draw_rect.width(), draw_rect.height(), false)); |
183 canvas->TranslateInt(draw_rect.x(), draw_rect.y()); | 193 canvas->TranslateInt(draw_rect.x(), draw_rect.y()); |
184 delegate_->OnPaint(canvas.get()); | 194 delegate_->OnPaintLayer(canvas.get()); |
185 SetCanvas(*canvas->AsCanvasSkia(), bounds().origin()); | 195 SetCanvas(*canvas->AsCanvasSkia(), bounds().origin()); |
186 } | 196 } |
187 | 197 |
188 void Layer::RecomputeHole() { | 198 void Layer::RecomputeHole() { |
189 for (size_t i = 0; i < children_.size(); ++i) { | 199 for (size_t i = 0; i < children_.size(); ++i) { |
190 if (children_[i]->fills_bounds_opaquely() && | 200 if (children_[i]->fills_bounds_opaquely() && |
191 !children_[i]->transform().HasChange()) { | 201 !children_[i]->transform().HasChange()) { |
192 hole_rect_ = children_[i]->bounds(); | 202 hole_rect_ = children_[i]->bounds(); |
193 return; | 203 return; |
194 } | 204 } |
(...skipping 28 matching lines...) Expand all Loading... |
223 for (; p && p != ancestor; p = p->parent()) { | 233 for (; p && p != ancestor; p = p->parent()) { |
224 if (p->transform().HasChange()) | 234 if (p->transform().HasChange()) |
225 transform->ConcatTransform(p->transform()); | 235 transform->ConcatTransform(p->transform()); |
226 transform->ConcatTranslate(static_cast<float>(p->bounds().x()), | 236 transform->ConcatTranslate(static_cast<float>(p->bounds().x()), |
227 static_cast<float>(p->bounds().y())); | 237 static_cast<float>(p->bounds().y())); |
228 } | 238 } |
229 return p == ancestor; | 239 return p == ancestor; |
230 } | 240 } |
231 | 241 |
232 } // namespace ui | 242 } // namespace ui |
OLD | NEW |