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

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

Issue 1037513002: Move early outs to the top of View::Paint and OnPaintLayer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: paint-visible-earlyouts: . Created 5 years, 9 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 | « no previous file | 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 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 if (layer()) { 757 if (layer()) {
758 layer()->SchedulePaint(rect); 758 layer()->SchedulePaint(rect);
759 } else if (parent_) { 759 } else if (parent_) {
760 // Translate the requested paint rect to the parent's coordinate system 760 // Translate the requested paint rect to the parent's coordinate system
761 // then pass this notification up to the parent. 761 // then pass this notification up to the parent.
762 parent_->SchedulePaintInRect(ConvertRectToParent(rect)); 762 parent_->SchedulePaintInRect(ConvertRectToParent(rect));
763 } 763 }
764 } 764 }
765 765
766 void View::Paint(gfx::Canvas* canvas, const CullSet& cull_set) { 766 void View::Paint(gfx::Canvas* canvas, const CullSet& cull_set) {
767 if (!visible_)
768 return;
767 // The cull_set may allow us to skip painting without canvas construction or 769 // The cull_set may allow us to skip painting without canvas construction or
768 // even canvas rect intersection. 770 // even canvas rect intersection.
769 if (cull_set.ShouldPaint(this)) { 771 if (!cull_set.ShouldPaint(this))
770 TRACE_EVENT1("views", "View::Paint", "class", GetClassName()); 772 return;
771 773
772 gfx::ScopedCanvas scoped_canvas(canvas); 774 TRACE_EVENT1("views", "View::Paint", "class", GetClassName());
773 775
774 // Paint this View and its children, setting the clip rect to the bounds 776 gfx::ScopedCanvas scoped_canvas(canvas);
775 // of this View and translating the origin to the local bounds' top left 777
776 // point. 778 // Paint this View and its children, setting the clip rect to the bounds
777 // 779 // of this View and translating the origin to the local bounds' top left
778 // Note that the X (or left) position we pass to ClipRectInt takes into 780 // point.
779 // consideration whether or not the view uses a right-to-left layout so that 781 //
780 // we paint our view in its mirrored position if need be. 782 // Note that the X (or left) position we pass to ClipRectInt takes into
781 gfx::Rect clip_rect = bounds(); 783 // consideration whether or not the view uses a right-to-left layout so that
782 clip_rect.Inset(clip_insets_); 784 // we paint our view in its mirrored position if need be.
783 if (parent_) 785 gfx::Rect clip_rect = bounds();
784 clip_rect.set_x(parent_->GetMirroredXForRect(clip_rect)); 786 clip_rect.Inset(clip_insets_);
785 canvas->ClipRect(clip_rect); 787 if (parent_)
786 if (canvas->IsClipEmpty()) 788 clip_rect.set_x(parent_->GetMirroredXForRect(clip_rect));
789 canvas->ClipRect(clip_rect);
790 if (canvas->IsClipEmpty())
791 return;
792
793 // Non-empty clip, translate the graphics such that 0,0 corresponds to where
794 // this view is located (related to its parent).
795 canvas->Translate(GetMirroredPosition().OffsetFromOrigin());
796 canvas->Transform(GetTransform());
797
798 // If we are a paint root, we need to construct our own CullSet object for
799 // propagation to our children.
800 if (IsPaintRoot()) {
801 if (!bounds_tree_)
802 bounds_tree_.reset(new BoundsTree(2, 5));
803
804 // Recompute our bounds tree as needed.
805 UpdateRootBounds(bounds_tree_.get(), gfx::Vector2d());
806
807 // Grab the clip rect from the supplied canvas to use as the query rect.
808 gfx::Rect canvas_bounds;
809 if (!canvas->GetClipBounds(&canvas_bounds)) {
810 NOTREACHED() << "Failed to get clip bounds from the canvas!";
787 return; 811 return;
812 }
788 813
789 // Non-empty clip, translate the graphics such that 0,0 corresponds to where 814 // Now query our bounds_tree_ for a set of damaged views that intersect
790 // this view is located (related to its parent). 815 // our canvas bounds.
791 canvas->Translate(GetMirroredPosition().OffsetFromOrigin()); 816 scoped_ptr<base::hash_set<intptr_t>> damaged_views(
792 canvas->Transform(GetTransform()); 817 new base::hash_set<intptr_t>());
793 818 bounds_tree_->AppendIntersectingRecords(canvas_bounds, damaged_views.get());
794 // If we are a paint root, we need to construct our own CullSet object for 819 // Construct a CullSet to wrap the damaged views set, it will delete it
795 // propagation to our children. 820 // for us on scope exit.
796 if (IsPaintRoot()) { 821 CullSet paint_root_cull_set(damaged_views.Pass());
797 if (!bounds_tree_) 822 // Paint all descendents using our new cull set.
798 bounds_tree_.reset(new BoundsTree(2, 5)); 823 PaintCommon(canvas, paint_root_cull_set);
799 824 } else {
800 // Recompute our bounds tree as needed. 825 // Not a paint root, so we can proceed as normal.
801 UpdateRootBounds(bounds_tree_.get(), gfx::Vector2d()); 826 PaintCommon(canvas, cull_set);
802
803 // Grab the clip rect from the supplied canvas to use as the query rect.
804 gfx::Rect canvas_bounds;
805 if (!canvas->GetClipBounds(&canvas_bounds)) {
806 NOTREACHED() << "Failed to get clip bounds from the canvas!";
807 return;
808 }
809
810 // Now query our bounds_tree_ for a set of damaged views that intersect
811 // our canvas bounds.
812 scoped_ptr<base::hash_set<intptr_t> > damaged_views(
813 new base::hash_set<intptr_t>());
814 bounds_tree_->AppendIntersectingRecords(
815 canvas_bounds, damaged_views.get());
816 // Construct a CullSet to wrap the damaged views set, it will delete it
817 // for us on scope exit.
818 CullSet paint_root_cull_set(damaged_views.Pass());
819 // Paint all descendents using our new cull set.
820 PaintCommon(canvas, paint_root_cull_set);
821 } else {
822 // Not a paint root, so we can proceed as normal.
823 PaintCommon(canvas, cull_set);
824 }
825 } 827 }
826 } 828 }
827 829
828 void View::set_background(Background* b) { 830 void View::set_background(Background* b) {
829 background_.reset(b); 831 background_.reset(b);
830 } 832 }
831 833
832 void View::SetBorder(scoped_ptr<Border> b) { border_ = b.Pass(); } 834 void View::SetBorder(scoped_ptr<Border> b) { border_ = b.Pass(); }
833 835
834 ui::ThemeProvider* View::GetThemeProvider() const { 836 ui::ThemeProvider* View::GetThemeProvider() const {
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 } else { 1457 } else {
1456 for (int i = 0, count = child_count(); i < count; ++i) { 1458 for (int i = 0, count = child_count(); i < count; ++i) {
1457 View* child = child_at(i); 1459 View* child = child_at(i);
1458 child->UpdateChildLayerBounds( 1460 child->UpdateChildLayerBounds(
1459 offset + gfx::Vector2d(child->GetMirroredX(), child->y())); 1461 offset + gfx::Vector2d(child->GetMirroredX(), child->y()));
1460 } 1462 }
1461 } 1463 }
1462 } 1464 }
1463 1465
1464 void View::OnPaintLayer(gfx::Canvas* canvas) { 1466 void View::OnPaintLayer(gfx::Canvas* canvas) {
1467 if (!visible_)
sky 2015/03/24 22:11:21 I'm tempted to say this should be a DCHECK, but it
danakj 2015/03/24 22:15:20 It would get garbage if it claimed to be opaque "s
1468 return;
1465 if (!layer() || !layer()->fills_bounds_opaquely()) 1469 if (!layer() || !layer()->fills_bounds_opaquely())
1466 canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); 1470 canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
1467 PaintCommon(canvas, CullSet()); 1471 PaintCommon(canvas, CullSet());
1468 } 1472 }
1469 1473
1470 void View::OnDelegatedFrameDamage( 1474 void View::OnDelegatedFrameDamage(
1471 const gfx::Rect& damage_rect_in_dip) { 1475 const gfx::Rect& damage_rect_in_dip) {
1472 } 1476 }
1473 1477
1474 void View::OnDeviceScaleFactorChanged(float device_scale_factor) { 1478 void View::OnDeviceScaleFactorChanged(float device_scale_factor) {
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1741 } else if (parent_ && type == SCHEDULE_PAINT_SIZE_SAME) { 1745 } else if (parent_ && type == SCHEDULE_PAINT_SIZE_SAME) {
1742 // The compositor doesn't Draw() until something on screen changes, so 1746 // The compositor doesn't Draw() until something on screen changes, so
1743 // if our position changes but nothing is being animated on screen, then 1747 // if our position changes but nothing is being animated on screen, then
1744 // tell the compositor to redraw the scene. We know layer() exists due to 1748 // tell the compositor to redraw the scene. We know layer() exists due to
1745 // the above if clause. 1749 // the above if clause.
1746 layer()->ScheduleDraw(); 1750 layer()->ScheduleDraw();
1747 } 1751 }
1748 } 1752 }
1749 1753
1750 void View::PaintCommon(gfx::Canvas* canvas, const CullSet& cull_set) { 1754 void View::PaintCommon(gfx::Canvas* canvas, const CullSet& cull_set) {
1751 if (!visible_)
1752 return;
1753
1754 { 1755 {
1755 // If the View we are about to paint requested the canvas to be flipped, we 1756 // If the View we are about to paint requested the canvas to be flipped, we
1756 // should change the transform appropriately. 1757 // should change the transform appropriately.
1757 // The canvas mirroring is undone once the View is done painting so that we 1758 // The canvas mirroring is undone once the View is done painting so that we
1758 // don't pass the canvas with the mirrored transform to Views that didn't 1759 // don't pass the canvas with the mirrored transform to Views that didn't
1759 // request the canvas to be flipped. 1760 // request the canvas to be flipped.
1760 gfx::ScopedCanvas scoped(canvas); 1761 gfx::ScopedCanvas scoped(canvas);
1761 if (FlipCanvasOnPaintForRTLUI()) { 1762 if (FlipCanvasOnPaintForRTLUI()) {
1762 canvas->Translate(gfx::Vector2d(width(), 0)); 1763 canvas->Translate(gfx::Vector2d(width(), 0));
1763 canvas->Scale(-1, 1); 1764 canvas->Scale(-1, 1);
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
2473 // Message the RootView to do the drag and drop. That way if we're removed 2474 // Message the RootView to do the drag and drop. That way if we're removed
2474 // the RootView can detect it and avoid calling us back. 2475 // the RootView can detect it and avoid calling us back.
2475 gfx::Point widget_location(event.location()); 2476 gfx::Point widget_location(event.location());
2476 ConvertPointToWidget(this, &widget_location); 2477 ConvertPointToWidget(this, &widget_location);
2477 widget->RunShellDrag(this, data, widget_location, drag_operations, source); 2478 widget->RunShellDrag(this, data, widget_location, drag_operations, source);
2478 // WARNING: we may have been deleted. 2479 // WARNING: we may have been deleted.
2479 return true; 2480 return true;
2480 } 2481 }
2481 2482
2482 } // namespace views 2483 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698