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

Side by Side Diff: third_party/WebKit/Source/core/paint/PaintInvalidationCapableScrollableArea.cpp

Issue 2208463003: First step of PaintInvalidator implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: - Created 4 years, 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "core/paint/PaintInvalidationCapableScrollableArea.h" 5 #include "core/paint/PaintInvalidationCapableScrollableArea.h"
6 6
7 #include "core/frame/Settings.h" 7 #include "core/frame/Settings.h"
8 #include "core/html/HTMLFrameOwnerElement.h" 8 #include "core/html/HTMLFrameOwnerElement.h"
9 #include "core/layout/LayoutBox.h" 9 #include "core/layout/LayoutBox.h"
10 #include "core/layout/LayoutScrollbar.h" 10 #include "core/layout/LayoutScrollbar.h"
11 #include "core/layout/LayoutScrollbarPart.h" 11 #include "core/layout/LayoutScrollbarPart.h"
12 #include "core/layout/PaintInvalidationState.h" 12 #include "core/paint/PaintInvalidator.h"
13 #include "core/paint/PaintLayer.h" 13 #include "core/paint/PaintLayer.h"
14 #include "platform/graphics/GraphicsLayer.h" 14 #include "platform/graphics/GraphicsLayer.h"
15 15
16 namespace blink { 16 namespace blink {
17 17
18 void PaintInvalidationCapableScrollableArea::willRemoveScrollbar(Scrollbar& scro llbar, ScrollbarOrientation orientation) 18 void PaintInvalidationCapableScrollableArea::willRemoveScrollbar(Scrollbar& scro llbar, ScrollbarOrientation orientation)
19 { 19 {
20 if (!scrollbar.isCustomScrollbar() 20 if (!scrollbar.isCustomScrollbar()
21 && !(orientation == HorizontalScrollbar ? layerForHorizontalScrollbar() : layerForVerticalScrollbar())) 21 && !(orientation == HorizontalScrollbar ? layerForHorizontalScrollbar() : layerForVerticalScrollbar()))
22 layoutBox()->slowSetPaintingLayerNeedsRepaintAndInvalidateDisplayItemCli ent(scrollbar, PaintInvalidationScroll); 22 layoutBox()->slowSetPaintingLayerNeedsRepaintAndInvalidateDisplayItemCli ent(scrollbar, PaintInvalidationScroll);
23 23
24 ScrollableArea::willRemoveScrollbar(scrollbar, orientation); 24 ScrollableArea::willRemoveScrollbar(scrollbar, orientation);
25 } 25 }
26 26
27 static LayoutRect scrollControlPaintInvalidationRect(const IntRect& scrollContro lRect, const LayoutBox& box, const PaintInvalidationState& paintInvalidationStat e) 27 static LayoutRect scrollControlPaintInvalidationRect(const IntRect& scrollContro lRect, const LayoutBox& box, const PaintInvalidatorContext& context)
28 { 28 {
29 LayoutRect paintInvalidationRect(scrollControlRect); 29 LayoutRect paintInvalidationRect(scrollControlRect);
30 if (!paintInvalidationRect.isEmpty()) 30 if (!paintInvalidationRect.isEmpty())
31 paintInvalidationState.mapLocalRectToPaintInvalidationBacking(paintInval idationRect); 31 context.mapLocalRectToPaintInvalidationBacking(box, paintInvalidationRec t);
32 return paintInvalidationRect; 32 return paintInvalidationRect;
33 } 33 }
34 34
35 // Returns true if the scroll control is invalidated. 35 // Returns true if the scroll control is invalidated.
36 static bool invalidatePaintOfScrollControlIfNeeded(const LayoutRect& newPaintInv alidationRect, const LayoutRect& previousPaintInvalidationRect, bool needsPaintI nvalidation, LayoutBox& box, const LayoutBoxModelObject& paintInvalidationContai ner) 36 static bool invalidatePaintOfScrollControlIfNeeded(const LayoutRect& newPaintInv alidationRect, const LayoutRect& previousPaintInvalidationRect, bool needsPaintI nvalidation, LayoutBox& box, const LayoutBoxModelObject& paintInvalidationContai ner)
37 { 37 {
38 bool shouldInvalidateNewRect = needsPaintInvalidation; 38 bool shouldInvalidateNewRect = needsPaintInvalidation;
39 if (newPaintInvalidationRect != previousPaintInvalidationRect) { 39 if (newPaintInvalidationRect != previousPaintInvalidationRect) {
40 box.invalidatePaintUsingContainer(paintInvalidationContainer, previousPa intInvalidationRect, PaintInvalidationScroll); 40 box.invalidatePaintUsingContainer(paintInvalidationContainer, previousPa intInvalidationRect, PaintInvalidationScroll);
41 shouldInvalidateNewRect = true; 41 shouldInvalidateNewRect = true;
42 } 42 }
43 if (shouldInvalidateNewRect) { 43 if (shouldInvalidateNewRect) {
44 box.invalidatePaintUsingContainer(paintInvalidationContainer, newPaintIn validationRect, PaintInvalidationScroll); 44 box.invalidatePaintUsingContainer(paintInvalidationContainer, newPaintIn validationRect, PaintInvalidationScroll);
45 return true; 45 return true;
46 } 46 }
47 return false; 47 return false;
48 } 48 }
49 49
50 static void invalidatePaintOfScrollbarIfNeeded(Scrollbar* scrollbar, GraphicsLay er* graphicsLayer, bool& previouslyWasOverlay, LayoutRect& previousPaintInvalida tionRect, bool needsPaintInvalidationArg, LayoutBox& box, const PaintInvalidatio nState& paintInvalidationState) 50 static void invalidatePaintOfScrollbarIfNeeded(Scrollbar* scrollbar, GraphicsLay er* graphicsLayer, bool& previouslyWasOverlay, LayoutRect& previousPaintInvalida tionRect, bool needsPaintInvalidationArg, LayoutBox& box, const PaintInvalidator Context& context)
51 { 51 {
52 bool isOverlay = scrollbar && scrollbar->isOverlayScrollbar(); 52 bool isOverlay = scrollbar && scrollbar->isOverlayScrollbar();
53 53
54 // Calculate paint invalidation rect of the scrollbar, except overlay compos ited scrollbars because we invalidate the graphics layer only. 54 // Calculate paint invalidation rect of the scrollbar, except overlay compos ited scrollbars because we invalidate the graphics layer only.
55 LayoutRect newPaintInvalidationRect; 55 LayoutRect newPaintInvalidationRect;
56 if (scrollbar && !(graphicsLayer && isOverlay)) 56 if (scrollbar && !(graphicsLayer && isOverlay))
57 newPaintInvalidationRect = scrollControlPaintInvalidationRect(scrollbar- >frameRect(), box, paintInvalidationState); 57 newPaintInvalidationRect = scrollControlPaintInvalidationRect(scrollbar- >frameRect(), box, context);
58 58
59 bool needsPaintInvalidation = needsPaintInvalidationArg; 59 bool needsPaintInvalidation = needsPaintInvalidationArg;
60 if (needsPaintInvalidation && graphicsLayer) { 60 if (needsPaintInvalidation && graphicsLayer) {
61 // If the scrollbar needs paint invalidation but didn't change location/ size or the scrollbar is an 61 // If the scrollbar needs paint invalidation but didn't change location/ size or the scrollbar is an
62 // overlay scrollbar (paint invalidation rect is empty), invalidating th e graphics layer is enough 62 // overlay scrollbar (paint invalidation rect is empty), invalidating th e graphics layer is enough
63 // (which has been done in ScrollableArea::setScrollbarNeedsPaintInvalid ation()). 63 // (which has been done in ScrollableArea::setScrollbarNeedsPaintInvalid ation()).
64 // Otherwise invalidatePaintOfScrollControlIfNeeded() below will invalid ate the old and new location 64 // Otherwise invalidatePaintOfScrollControlIfNeeded() below will invalid ate the old and new location
65 // of the scrollbar on the box's paint invalidation container to ensure newly expanded/shrunk areas 65 // of the scrollbar on the box's paint invalidation container to ensure newly expanded/shrunk areas
66 // of the box to be invalidated. 66 // of the box to be invalidated.
67 needsPaintInvalidation = false; 67 needsPaintInvalidation = false;
68 DCHECK(!graphicsLayer->drawsContent() || graphicsLayer->getPaintControll er().cacheIsEmpty()); 68 DCHECK(!graphicsLayer->drawsContent() || graphicsLayer->getPaintControll er().cacheIsEmpty());
69 } 69 }
70 70
71 // Invalidate the box's display item client if the box's padding box size is affected by change of the 71 // Invalidate the box's display item client if the box's padding box size is affected by change of the
72 // non-overlay scrollbar width. We detect change of paint invalidation rect size instead of change of 72 // non-overlay scrollbar width. We detect change of paint invalidation rect size instead of change of
73 // scrollbar width change, which may have some false-positives (e.g. the scr ollbar changed length but 73 // scrollbar width change, which may have some false-positives (e.g. the scr ollbar changed length but
74 // not width) but won't invalidate more than expected because in the false-p ositive case the box must 74 // not width) but won't invalidate more than expected because in the false-p ositive case the box must
75 // have changed size and have been invalidated. 75 // have changed size and have been invalidated.
76 const LayoutBoxModelObject& paintInvalidationContainer = paintInvalidationSt ate.paintInvalidationContainer(); 76 const LayoutBoxModelObject& paintInvalidationContainer = *context.paintInval idationContainer;
77 LayoutSize newScrollbarUsedSpaceInBox; 77 LayoutSize newScrollbarUsedSpaceInBox;
78 if (!isOverlay) 78 if (!isOverlay)
79 newScrollbarUsedSpaceInBox = newPaintInvalidationRect.size(); 79 newScrollbarUsedSpaceInBox = newPaintInvalidationRect.size();
80 LayoutSize previousScrollbarUsedSpaceInBox; 80 LayoutSize previousScrollbarUsedSpaceInBox;
81 if (!previouslyWasOverlay) 81 if (!previouslyWasOverlay)
82 previousScrollbarUsedSpaceInBox= previousPaintInvalidationRect.size(); 82 previousScrollbarUsedSpaceInBox= previousPaintInvalidationRect.size();
83 if (newScrollbarUsedSpaceInBox != previousScrollbarUsedSpaceInBox) 83 if (newScrollbarUsedSpaceInBox != previousScrollbarUsedSpaceInBox) {
84 box.setPaintingLayerNeedsRepaintAndInvalidateDisplayItemClient(paintInva lidationState, box, PaintInvalidationScroll); 84 context.paintingLayer->setNeedsRepaint();
85 box.invalidateDisplayItemClient(box, PaintInvalidationScroll);
86 }
85 87
86 bool invalidated = invalidatePaintOfScrollControlIfNeeded(newPaintInvalidati onRect, previousPaintInvalidationRect, needsPaintInvalidation, box, paintInvalid ationContainer); 88 bool invalidated = invalidatePaintOfScrollControlIfNeeded(newPaintInvalidati onRect, previousPaintInvalidationRect, needsPaintInvalidation, box, paintInvalid ationContainer);
87 89
88 previousPaintInvalidationRect = newPaintInvalidationRect; 90 previousPaintInvalidationRect = newPaintInvalidationRect;
89 previouslyWasOverlay = isOverlay; 91 previouslyWasOverlay = isOverlay;
90 92
91 if (!invalidated || !scrollbar || graphicsLayer) 93 if (!invalidated || !scrollbar || graphicsLayer)
92 return; 94 return;
93 95
94 box.setPaintingLayerNeedsRepaintAndInvalidateDisplayItemClient(paintInvalida tionState, *scrollbar, PaintInvalidationScroll); 96 context.paintingLayer->setNeedsRepaint();
97 box.invalidateDisplayItemClient(*scrollbar, PaintInvalidationScroll);
95 if (scrollbar->isCustomScrollbar()) 98 if (scrollbar->isCustomScrollbar())
96 toLayoutScrollbar(scrollbar)->invalidateDisplayItemClientsOfScrollbarPar ts(); 99 toLayoutScrollbar(scrollbar)->invalidateDisplayItemClientsOfScrollbarPar ts();
97 } 100 }
98 101
99 void PaintInvalidationCapableScrollableArea::invalidatePaintOfScrollControlsIfNe eded(const PaintInvalidationState& paintInvalidationState) 102 void PaintInvalidationCapableScrollableArea::invalidatePaintOfScrollControlsIfNe eded(const PaintInvalidatorContext& context)
100 { 103 {
101 LayoutBox& box = *layoutBox(); 104 LayoutBox& box = *layoutBox();
102 invalidatePaintOfScrollbarIfNeeded(horizontalScrollbar(), layerForHorizontal Scrollbar(), m_horizontalScrollbarPreviouslyWasOverlay, m_horizontalScrollbarPre viousPaintInvalidationRect, horizontalScrollbarNeedsPaintInvalidation(), box, pa intInvalidationState); 105 invalidatePaintOfScrollbarIfNeeded(horizontalScrollbar(), layerForHorizontal Scrollbar(), m_horizontalScrollbarPreviouslyWasOverlay, m_horizontalScrollbarPre viousPaintInvalidationRect, horizontalScrollbarNeedsPaintInvalidation(), box, co ntext);
103 invalidatePaintOfScrollbarIfNeeded(verticalScrollbar(), layerForVerticalScro llbar(), m_verticalScrollbarPreviouslyWasOverlay, m_verticalScrollbarPreviousPai ntInvalidationRect, verticalScrollbarNeedsPaintInvalidation(), box, paintInvalid ationState); 106 invalidatePaintOfScrollbarIfNeeded(verticalScrollbar(), layerForVerticalScro llbar(), m_verticalScrollbarPreviouslyWasOverlay, m_verticalScrollbarPreviousPai ntInvalidationRect, verticalScrollbarNeedsPaintInvalidation(), box, context);
104 107
105 LayoutRect scrollCornerPaintInvalidationRect = scrollControlPaintInvalidatio nRect(scrollCornerAndResizerRect(), box, paintInvalidationState); 108 LayoutRect scrollCornerPaintInvalidationRect = scrollControlPaintInvalidatio nRect(scrollCornerAndResizerRect(), box, context);
106 const LayoutBoxModelObject& paintInvalidationContainer = paintInvalidationSt ate.paintInvalidationContainer(); 109 const LayoutBoxModelObject& paintInvalidationContainer = *context.paintInval idationContainer;
107 if (invalidatePaintOfScrollControlIfNeeded(scrollCornerPaintInvalidationRect , m_scrollCornerAndResizerPreviousPaintInvalidationRect, scrollCornerNeedsPaintI nvalidation(), box, paintInvalidationContainer)) { 110 if (invalidatePaintOfScrollControlIfNeeded(scrollCornerPaintInvalidationRect , m_scrollCornerAndResizerPreviousPaintInvalidationRect, scrollCornerNeedsPaintI nvalidation(), box, paintInvalidationContainer)) {
108 m_scrollCornerAndResizerPreviousPaintInvalidationRect = scrollCornerPain tInvalidationRect; 111 m_scrollCornerAndResizerPreviousPaintInvalidationRect = scrollCornerPain tInvalidationRect;
109 if (LayoutScrollbarPart* scrollCorner = this->scrollCorner()) 112 if (LayoutScrollbarPart* scrollCorner = this->scrollCorner())
110 scrollCorner->invalidateDisplayItemClientsIncludingNonCompositingDes cendants(PaintInvalidationScroll); 113 scrollCorner->invalidateDisplayItemClientsIncludingNonCompositingDes cendants(PaintInvalidationScroll);
111 if (LayoutScrollbarPart* resizer = this->resizer()) 114 if (LayoutScrollbarPart* resizer = this->resizer())
112 resizer->invalidateDisplayItemClientsIncludingNonCompositingDescenda nts(PaintInvalidationScroll); 115 resizer->invalidateDisplayItemClientsIncludingNonCompositingDescenda nts(PaintInvalidationScroll);
113 } 116 }
114 117
115 clearNeedsPaintInvalidationForScrollControls(); 118 clearNeedsPaintInvalidationForScrollControls();
116 } 119 }
117 120
121 void PaintInvalidationCapableScrollableArea::invalidatePaintOfScrollControlsIfNe eded(const PaintInvalidationState& paintInvalidationState)
122 {
123 invalidatePaintOfScrollControlsIfNeeded(PaintInvalidatorContextAdapter(paint InvalidationState));
124 }
125
118 void PaintInvalidationCapableScrollableArea::clearPreviousPaintInvalidationRects () 126 void PaintInvalidationCapableScrollableArea::clearPreviousPaintInvalidationRects ()
119 { 127 {
120 m_horizontalScrollbarPreviousPaintInvalidationRect = LayoutRect(); 128 m_horizontalScrollbarPreviousPaintInvalidationRect = LayoutRect();
121 m_verticalScrollbarPreviousPaintInvalidationRect = LayoutRect(); 129 m_verticalScrollbarPreviousPaintInvalidationRect = LayoutRect();
122 m_scrollCornerAndResizerPreviousPaintInvalidationRect = LayoutRect(); 130 m_scrollCornerAndResizerPreviousPaintInvalidationRect = LayoutRect();
123 } 131 }
124 132
125 LayoutRect PaintInvalidationCapableScrollableArea::visualRectForScrollbarParts() const 133 LayoutRect PaintInvalidationCapableScrollableArea::visualRectForScrollbarParts() const
126 { 134 {
127 LayoutRect fullBounds(m_horizontalScrollbarPreviousPaintInvalidationRect); 135 LayoutRect fullBounds(m_horizontalScrollbarPreviousPaintInvalidationRect);
128 fullBounds.unite(m_verticalScrollbarPreviousPaintInvalidationRect); 136 fullBounds.unite(m_verticalScrollbarPreviousPaintInvalidationRect);
129 fullBounds.unite(m_scrollCornerAndResizerPreviousPaintInvalidationRect); 137 fullBounds.unite(m_scrollCornerAndResizerPreviousPaintInvalidationRect);
130 return fullBounds; 138 return fullBounds;
131 } 139 }
132 140
133 void PaintInvalidationCapableScrollableArea::scrollControlWasSetNeedsPaintInvali dation() 141 void PaintInvalidationCapableScrollableArea::scrollControlWasSetNeedsPaintInvali dation()
134 { 142 {
135 layoutBox()->setMayNeedPaintInvalidation(); 143 layoutBox()->setMayNeedPaintInvalidation();
136 } 144 }
137 145
138 } // namespace blink 146 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698