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 "views/view.h" | 5 #include "views/view.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" |
| (...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1209 if (!layer_helper_.get()) | 1209 if (!layer_helper_.get()) |
| 1210 layer_helper_.reset(new internal::LayerHelper()); | 1210 layer_helper_.reset(new internal::LayerHelper()); |
| 1211 | 1211 |
| 1212 layer_helper_->set_fills_bounds_opaquely(fills_bounds_opaquely); | 1212 layer_helper_->set_fills_bounds_opaquely(fills_bounds_opaquely); |
| 1213 | 1213 |
| 1214 if (layer()) | 1214 if (layer()) |
| 1215 layer()->SetFillsBoundsOpaquely(fills_bounds_opaquely); | 1215 layer()->SetFillsBoundsOpaquely(fills_bounds_opaquely); |
| 1216 } | 1216 } |
| 1217 | 1217 |
| 1218 bool View::SetExternalTexture(ui::Texture* texture) { | 1218 bool View::SetExternalTexture(ui::Texture* texture) { |
| 1219 // A little heavy-handed -- it should be that each child has it's own layer. | |
| 1220 // The desired use case is where there are no children. | |
| 1221 DCHECK_EQ(child_count(), 0); | |
| 1222 | |
| 1223 if (!texture && !layer_helper_.get()) | 1219 if (!texture && !layer_helper_.get()) |
| 1224 return true; | 1220 return true; |
| 1225 | 1221 |
| 1226 if (!layer_helper_.get()) | 1222 if (!layer_helper_.get()) |
| 1227 layer_helper_.reset(new internal::LayerHelper()); | 1223 layer_helper_.reset(new internal::LayerHelper()); |
| 1228 bool use_external = (texture != NULL); | 1224 bool use_external = (texture != NULL); |
| 1229 if (use_external != layer_helper_->paint_to_layer()) | 1225 if (use_external != layer_helper_->paint_to_layer()) |
| 1230 SetPaintToLayer(use_external); | 1226 SetPaintToLayer(use_external); |
| 1231 else if (use_external && !layer()) | 1227 else if (use_external && !layer()) |
| 1232 CreateLayer(); | 1228 CreateLayer(); |
| 1233 | 1229 |
| 1234 if (use_external && !layer()) | 1230 if (use_external && !layer()) |
| 1235 return false; | 1231 return false; |
| 1236 | 1232 |
| 1233 // Child views must not paint into the external texture. So make sure each | |
| 1234 // child view has its own layer to paint into. | |
| 1235 if (use_external) { | |
| 1236 for (Views::iterator i = children_.begin(); i != children_.end(); ++i) | |
| 1237 (*i)->SetPaintToLayer(true); | |
|
rjkroege
2011/08/10 14:29:53
this is not recursive right? It's only the immedia
sadrul
2011/08/10 14:33:05
Yes, that is correct (i.e. not recursive).
| |
| 1238 } | |
| 1239 | |
| 1237 layer_helper_->set_layer_updated_externally(use_external); | 1240 layer_helper_->set_layer_updated_externally(use_external); |
| 1238 layer_helper_->set_bitmap_needs_updating(!use_external); | 1241 layer_helper_->set_bitmap_needs_updating(!use_external); |
| 1239 if (layer()) | 1242 if (layer()) |
| 1240 layer()->SetTexture(texture); | 1243 layer()->SetTexture(texture); |
| 1241 | 1244 |
| 1242 if (IsVisible()) | 1245 if (IsVisible()) |
| 1243 SchedulePaintInternal(GetLocalBounds()); | 1246 SchedulePaintInternal(GetLocalBounds()); |
| 1244 | 1247 |
| 1245 return true; | 1248 return true; |
| 1246 } | 1249 } |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1713 gfx::Point3f p(*point); | 1716 gfx::Point3f p(*point); |
| 1714 trans.TransformPointReverse(p); | 1717 trans.TransformPointReverse(p); |
| 1715 *point = p.AsPoint(); | 1718 *point = p.AsPoint(); |
| 1716 return result; | 1719 return result; |
| 1717 } | 1720 } |
| 1718 | 1721 |
| 1719 // Accelerated painting -------------------------------------------------------- | 1722 // Accelerated painting -------------------------------------------------------- |
| 1720 | 1723 |
| 1721 bool View::ShouldPaintToLayer() const { | 1724 bool View::ShouldPaintToLayer() const { |
| 1722 return use_acceleration_when_possible && | 1725 return use_acceleration_when_possible && |
| 1723 layer_helper_.get() && layer_helper_->ShouldPaintToLayer(); | 1726 ((layer_helper_.get() && layer_helper_->ShouldPaintToLayer()) || |
| 1727 (parent_ && parent_->layer_helper_.get() && | |
| 1728 parent_->layer_helper_->layer_updated_externally())); | |
| 1724 } | 1729 } |
| 1725 | 1730 |
| 1726 void View::CreateLayer() { | 1731 void View::CreateLayer() { |
| 1727 if (!ShouldPaintToLayer() || layer()) | 1732 if (!ShouldPaintToLayer() || layer()) |
| 1728 return; | 1733 return; |
| 1729 | 1734 |
| 1730 ui::Compositor* compositor = GetCompositor(); | 1735 ui::Compositor* compositor = GetCompositor(); |
| 1731 if (!compositor) | 1736 if (!compositor) |
| 1732 return; | 1737 return; |
| 1733 | 1738 |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2041 result.append(child_at(i)->PrintViewGraph(false)); | 2046 result.append(child_at(i)->PrintViewGraph(false)); |
| 2042 | 2047 |
| 2043 if (first) | 2048 if (first) |
| 2044 result.append("}\n"); | 2049 result.append("}\n"); |
| 2045 | 2050 |
| 2046 return result; | 2051 return result; |
| 2047 } | 2052 } |
| 2048 #endif | 2053 #endif |
| 2049 | 2054 |
| 2050 } // namespace views | 2055 } // namespace views |
| OLD | NEW |