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

Side by Side Diff: ui/views/view.cc

Issue 1101783002: ui: Cache the output of View::OnPaint when the View isn't invalid. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cache: . Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « ui/views/view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first.
6 6
7 #include "ui/views/view.h" 7 #include "ui/views/view.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 gfx::Vector2d offset_to_parent; 741 gfx::Vector2d offset_to_parent;
742 if (!layer()) { 742 if (!layer()) {
743 // If the View has a layer() then it is a paint root. Otherwise, we need to 743 // If the View has a layer() then it is a paint root. Otherwise, we need to
744 // add the offset from the parent into the total offset from the paint root. 744 // add the offset from the parent into the total offset from the paint root.
745 DCHECK_IMPLIES(!parent(), bounds().origin() == gfx::Point()); 745 DCHECK_IMPLIES(!parent(), bounds().origin() == gfx::Point());
746 offset_to_parent = GetMirroredPosition().OffsetFromOrigin(); 746 offset_to_parent = GetMirroredPosition().OffsetFromOrigin();
747 } 747 }
748 ui::PaintContext context = 748 ui::PaintContext context =
749 parent_context.CloneWithPaintOffset(offset_to_parent); 749 parent_context.CloneWithPaintOffset(offset_to_parent);
750 750
751 if (context.CanCheckInvalidated()) { 751 bool is_invalidated = true;
752 if (context.CanCheckInvalid()) {
752 #if DCHECK_IS_ON() 753 #if DCHECK_IS_ON()
753 gfx::Vector2d offset; 754 gfx::Vector2d offset;
754 context.Visited(this); 755 context.Visited(this);
755 View* view = this; 756 View* view = this;
756 while (view->parent() && !view->layer()) { 757 while (view->parent() && !view->layer()) {
757 DCHECK(view->GetTransform().IsIdentity()); 758 DCHECK(view->GetTransform().IsIdentity());
758 offset += view->GetMirroredPosition().OffsetFromOrigin(); 759 offset += view->GetMirroredPosition().OffsetFromOrigin();
759 view = view->parent(); 760 view = view->parent();
760 } 761 }
761 // The offset in the PaintContext should be the offset up to the paint root, 762 // The offset in the PaintContext should be the offset up to the paint root,
762 // which we compute and verify here. 763 // which we compute and verify here.
763 DCHECK_EQ(context.PaintOffset().x(), offset.x()); 764 DCHECK_EQ(context.PaintOffset().x(), offset.x());
764 DCHECK_EQ(context.PaintOffset().y(), offset.y()); 765 DCHECK_EQ(context.PaintOffset().y(), offset.y());
765 // The above loop will stop when |view| is the paint root, which should be 766 // The above loop will stop when |view| is the paint root, which should be
766 // the root of the current paint walk, as verified by storing the root in 767 // the root of the current paint walk, as verified by storing the root in
767 // the PaintContext. 768 // the PaintContext.
768 DCHECK_EQ(context.RootVisited(), view); 769 DCHECK_EQ(context.RootVisited(), view);
769 #endif 770 #endif
770 771
771 // If the View wasn't invalidated, don't waste time painting it, the output 772 // If the View wasn't invalidated, don't waste time painting it, the output
772 // would be culled. 773 // would be culled.
773 if (!context.IsRectInvalidated(GetLocalBounds())) 774 is_invalidated = context.IsRectInvalid(GetLocalBounds());
774 return;
775 } 775 }
776 776
777 if (!is_invalidated && context.ShouldEarlyOutOfPaintingWhenValid())
778 return;
779
777 TRACE_EVENT1("views", "View::Paint", "class", GetClassName()); 780 TRACE_EVENT1("views", "View::Paint", "class", GetClassName());
778 781
779 // If the view is backed by a layer, it should paint with itself as the origin 782 // If the view is backed by a layer, it should paint with itself as the origin
780 // rather than relative to its parent. 783 // rather than relative to its parent.
781 scoped_ptr<ui::ClipTransformRecorder> clip_transform_recorder; 784 scoped_ptr<ui::ClipTransformRecorder> clip_transform_recorder;
782 if (!layer()) { 785 if (!layer()) {
783 clip_transform_recorder.reset(new ui::ClipTransformRecorder(context)); 786 clip_transform_recorder.reset(new ui::ClipTransformRecorder(context));
784 787
785 // Set the clip rect to the bounds of this View. Note that the X (or left) 788 // Set the clip rect to the bounds of this View. Note that the X (or left)
786 // position we pass to ClipRect takes into consideration whether or not the 789 // position we pass to ClipRect takes into consideration whether or not the
787 // View uses a right-to-left layout so that we paint the View in its 790 // View uses a right-to-left layout so that we paint the View in its
788 // mirrored position if need be. 791 // mirrored position if need be.
789 gfx::Rect clip_rect_in_parent = bounds(); 792 gfx::Rect clip_rect_in_parent = bounds();
790 clip_rect_in_parent.Inset(clip_insets_); 793 clip_rect_in_parent.Inset(clip_insets_);
791 if (parent_) 794 if (parent_)
792 clip_rect_in_parent.set_x( 795 clip_rect_in_parent.set_x(
793 parent_->GetMirroredXForRect(clip_rect_in_parent)); 796 parent_->GetMirroredXForRect(clip_rect_in_parent));
794 clip_transform_recorder->ClipRect(clip_rect_in_parent); 797 clip_transform_recorder->ClipRect(clip_rect_in_parent);
795 798
796 // Translate the graphics such that 0,0 corresponds to where 799 // Translate the graphics such that 0,0 corresponds to where
797 // this View is located relative to its parent. 800 // this View is located relative to its parent.
798 gfx::Transform transform_from_parent; 801 gfx::Transform transform_from_parent;
799 gfx::Vector2d offset_from_parent = GetMirroredPosition().OffsetFromOrigin(); 802 gfx::Vector2d offset_from_parent = GetMirroredPosition().OffsetFromOrigin();
800 transform_from_parent.Translate(offset_from_parent.x(), 803 transform_from_parent.Translate(offset_from_parent.x(),
801 offset_from_parent.y()); 804 offset_from_parent.y());
802 transform_from_parent.PreconcatTransform(GetTransform()); 805 transform_from_parent.PreconcatTransform(GetTransform());
803 clip_transform_recorder->Transform(transform_from_parent); 806 clip_transform_recorder->Transform(transform_from_parent);
804 } 807 }
805 808
806 { 809 if (is_invalidated || !paint_cache_.UseCache(context)) {
807 ui::PaintRecorder recorder(context); 810 ui::PaintRecorder recorder(context, &paint_cache_);
808 gfx::Canvas* canvas = recorder.canvas(); 811 gfx::Canvas* canvas = recorder.canvas();
809 gfx::ScopedCanvas scoped_canvas(canvas); 812 gfx::ScopedCanvas scoped_canvas(canvas);
810 813
811 // If the View we are about to paint requested the canvas to be flipped, we 814 // If the View we are about to paint requested the canvas to be flipped, we
812 // should change the transform appropriately. 815 // should change the transform appropriately.
813 // The canvas mirroring is undone once the View is done painting so that we 816 // The canvas mirroring is undone once the View is done painting so that we
814 // don't pass the canvas with the mirrored transform to Views that didn't 817 // don't pass the canvas with the mirrored transform to Views that didn't
815 // request the canvas to be flipped. 818 // request the canvas to be flipped.
816 if (FlipCanvasOnPaintForRTLUI()) { 819 if (FlipCanvasOnPaintForRTLUI()) {
817 canvas->Translate(gfx::Vector2d(width(), 0)); 820 canvas->Translate(gfx::Vector2d(width(), 0));
(...skipping 1551 matching lines...) Expand 10 before | Expand all | Expand 10 after
2369 // Message the RootView to do the drag and drop. That way if we're removed 2372 // Message the RootView to do the drag and drop. That way if we're removed
2370 // the RootView can detect it and avoid calling us back. 2373 // the RootView can detect it and avoid calling us back.
2371 gfx::Point widget_location(event.location()); 2374 gfx::Point widget_location(event.location());
2372 ConvertPointToWidget(this, &widget_location); 2375 ConvertPointToWidget(this, &widget_location);
2373 widget->RunShellDrag(this, data, widget_location, drag_operations, source); 2376 widget->RunShellDrag(this, data, widget_location, drag_operations, source);
2374 // WARNING: we may have been deleted. 2377 // WARNING: we may have been deleted.
2375 return true; 2378 return true;
2376 } 2379 }
2377 2380
2378 } // namespace views 2381 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698