Chromium Code Reviews| Index: views/view.cc |
| diff --git a/views/view.cc b/views/view.cc |
| index db5f589c9c97e3d5e1a75af7d515964ffa71c218..cb0430d8241129d19c882d81aff94a9831ac53d5 100644 |
| --- a/views/view.cc |
| +++ b/views/view.cc |
| @@ -6,6 +6,7 @@ |
| #include <algorithm> |
| +#include "base/debug/trace_event.h" |
| #include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/message_loop.h" |
| @@ -41,11 +42,11 @@ namespace { |
| // Whether to use accelerated compositing when necessary (e.g. when a view has a |
| // transformation). |
| -#if !defined(OS_CHROMEOS) |
| +//#if !defined(OS_CHROMEOS) |
|
Jói
2011/06/30 19:50:50
Should these commented-out lines be removed altoge
|
| bool use_acceleration_when_possible = true; |
| -#else |
| -bool use_acceleration_when_possible = false; |
| -#endif |
| +//#else |
| +//bool use_acceleration_when_possible = false; |
| +//#endif |
| // Saves the drawing state, and restores the state when going out of scope. |
| class ScopedCanvas { |
| @@ -114,6 +115,7 @@ View::View() |
| previous_focusable_view_(NULL), |
| focusable_(false), |
| accessibility_focusable_(false), |
| + painting_enabled_(true), |
| context_menu_controller_(NULL), |
| drag_controller_(NULL) { |
| } |
| @@ -385,18 +387,17 @@ int View::GetHeightForWidth(int w) { |
| void View::SetVisible(bool visible) { |
| if (visible != visible_) { |
| + visible_ = visible; |
| // If the tab is currently visible, schedule paint to refresh parent. |
| if (visible_) |
| SchedulePaint(); |
| else |
| DestroyLayerRecurse(); |
| - visible_ = visible; |
| - |
| - // This notifies all sub-views recursively. |
| - PropagateVisibilityNotifications(this, visible_); |
| + // This notifies all sub-views recursively. |
| + PropagateVisibilityNotifications(this, visible_); |
| - // If we are newly visible, schedule paint. |
| + // If we are newly visible, schedule paint. |
| if (visible_) |
| SchedulePaint(); |
| } |
| @@ -425,6 +426,14 @@ void View::OnEnabledChanged() { |
| SchedulePaint(); |
| } |
| +void View::SetPaintingEnabled(bool enabled) { |
| + painting_enabled_ = enabled; |
| +} |
| + |
| +bool View::IsPaintingEnabled() const { |
| + return painting_enabled_; |
| +} |
| + |
| // Transformations ------------------------------------------------------------- |
| const ui::Transform& View::GetTransform() const { |
| @@ -445,11 +454,6 @@ void View::SetTransform(const ui::Transform& transform) { |
| SchedulePaint(); |
| } else { |
| - // Make sure if the view didn't have its own texture and was painting onto |
| - // something else, that gets refreshed too. |
| - if (!ShouldPaintToLayer()) |
| - MarkLayerDirty(); |
| - |
| if (!layer_helper_.get()) |
| layer_helper_.reset(new internal::LayerHelper()); |
| layer_helper_->SetTransform(transform); |
| @@ -458,15 +462,7 @@ void View::SetTransform(const ui::Transform& transform) { |
| SchedulePaint(); |
| } else { |
| layer_helper_->property_setter()->SetTransform(layer(), transform); |
| - // We have a layer. When the transform changes and the layer is up to |
| - // date we don't want to SchedulePaint as it'll trigger painting to the |
| - // layer. Instead we tell the Widget to paint, which makes the |
| - // compositor draw using the existing layer. |
| - // We schedule paint the complete bounds as compositor generally don't |
| - // support partial painting. |
| - Widget* widget = GetWidget(); |
| - if (widget) |
| - widget->SchedulePaintInRect(widget->GetRootView()->bounds()); |
| + ScheduleComposite(); |
| } |
| } |
| } |
| @@ -532,6 +528,7 @@ int View::GetMirroredXWithWidthInView(int x, int w) const { |
| // Layout ---------------------------------------------------------------------- |
| void View::Layout() { |
| + TRACE_EVENT0("View", "Layout"); |
| needs_layout_ = false; |
| // If we have a layout manager, let it handle the layout for us. |
| @@ -650,6 +647,14 @@ void View::ConvertPointToWidget(const View* src, gfx::Point* p) { |
| } |
| // static |
| +void View::ConvertRectToWidget(const View* src, gfx::Rect* rect) { |
| + DCHECK(src); |
| + DCHECK(rect); |
| + |
| + src->ConvertRectForAncestor(NULL, rect); |
| +} |
| + |
| +// static |
| void View::ConvertPointFromWidget(const View* dest, gfx::Point* p) { |
| DCHECK(dest); |
| DCHECK(p); |
| @@ -693,10 +698,22 @@ void View::SchedulePaintInRect(const gfx::Rect& rect) { |
| SchedulePaintInternal(rect); |
| } |
| -void View::Paint(gfx::Canvas* canvas) { |
| +void View::ScheduleComposite() { |
| + ScheduleCompositeInRect(GetLocalBounds()); |
| +} |
| + |
| +void View::ScheduleCompositeInRect(const gfx::Rect& rect) { |
| if (!IsVisible()) |
| return; |
| + SchedulePaintInternal(rect); |
| +} |
| + |
| +void View::Paint(gfx::Canvas* canvas) { |
| + TRACE_EVENT0("View", "Paint"); |
| + if (!IsVisible() || !IsPaintingEnabled()) |
| + return; |
| + |
| ScopedCanvas scoped_canvas(NULL); |
| scoped_ptr<gfx::Canvas> layer_canvas; |
| gfx::Rect layer_rect; |
| @@ -1169,6 +1186,7 @@ void View::OnPaintFocusBorder(gfx::Canvas* canvas) { |
| // Accelerated Painting -------------------------------------------------------- |
| void View::PaintComposite() { |
| + TRACE_EVENT0("View", "PaintComposite"); |
| if (!IsVisible()) |
| return; |
| @@ -1641,6 +1659,15 @@ bool View::ConvertPointForAncestor(const View* ancestor, |
| return result; |
| } |
| +bool View::ConvertRectForAncestor(const View* ancestor, |
| + gfx::Rect* rect) const { |
| + ui::Transform trans; |
| + // TODO(sad): Have some way of caching the transformation results. |
| + bool result = GetTransformRelativeTo(ancestor, &trans); |
| + trans.TransformRect(rect); |
| + return result; |
| +} |
| + |
| bool View::ConvertPointFromAncestor(const View* ancestor, |
| gfx::Point* point) const { |
| ui::Transform trans; |