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

Side by Side Diff: pdf/paint_aggregator.cc

Issue 1160513004: Fix graphics corruption that can occur in the PDF viewer when scrolling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "pdf/paint_aggregator.h" 5 #include "pdf/paint_aggregator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
11 namespace {
12
13 bool IsNegative(int32_t num) {
14 return num < 0;
15 }
16
17 } // namespace
18
11 // ---------------------------------------------------------------------------- 19 // ----------------------------------------------------------------------------
12 // ALGORITHM NOTES 20 // ALGORITHM NOTES
13 // 21 //
14 // We attempt to maintain a scroll rect in the presence of invalidations that 22 // We attempt to maintain a scroll rect in the presence of invalidations that
15 // are contained within the scroll rect. If an invalidation crosses a scroll 23 // are contained within the scroll rect. If an invalidation crosses a scroll
16 // rect, then we just treat the scroll rect as an invalidation rect. 24 // rect, then we just treat the scroll rect as an invalidation rect.
17 // 25 //
18 // For invalidations performed prior to scrolling and contained within the 26 // For invalidations performed prior to scrolling and contained within the
19 // scroll rect, we offset the invalidation rects to account for the fact that 27 // scroll rect, we offset the invalidation rects to account for the fact that
20 // the consumer will perform scrolling before painting. 28 // the consumer will perform scrolling before painting.
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 146 }
139 147
140 // Again, we only support scrolling along one axis at a time. Make sure this 148 // Again, we only support scrolling along one axis at a time. Make sure this
141 // update doesn't scroll on a different axis than any existing one. 149 // update doesn't scroll on a different axis than any existing one.
142 if ((amount.x() && update_.scroll_delta.y()) || 150 if ((amount.x() && update_.scroll_delta.y()) ||
143 (amount.y() && update_.scroll_delta.x())) { 151 (amount.y() && update_.scroll_delta.x())) {
144 InvalidateRect(clip_rect); 152 InvalidateRect(clip_rect);
145 return; 153 return;
146 } 154 }
147 155
156 // If we scroll in a reverse direction to the direction we originally scrolled
157 // and there were invalidations that happened in-between we may end up
158 // incorrectly clipping the invalidated rects (see crbug.com/488390). This bug
159 // doesn't exist in the original implementation
160 // (ppapi/utility/graphics/paint_aggregator.cc) which uses a different method
161 // of handling invalidations that occur after a scroll. The problem is that
162 // when we scroll the invalidated region, we clip it to the scroll rect. This
163 // can cause us to lose information about what the invalidated region was if
164 // it gets scrolled back into view. We either need to not do this clipping or
165 // disallow combining scrolls that occur in different directions with
166 // invalidations that happen in-between. This code really needs some tests...
167 if (!update_.paint_rects.empty()) {
168 if (IsNegative(amount.x()) != IsNegative(update_.scroll_delta.x()) ||
169 IsNegative(amount.y()) != IsNegative(update_.scroll_delta.y())) {
170 InvalidateRect(clip_rect);
171 return;
172 }
173 }
174
148 // The scroll rect is new or isn't changing (though the scroll amount may 175 // The scroll rect is new or isn't changing (though the scroll amount may
149 // be changing). 176 // be changing).
150 update_.scroll_rect = clip_rect; 177 update_.scroll_rect = clip_rect;
151 update_.scroll_delta += amount; 178 update_.scroll_delta += amount;
152 179
153 // We might have just wiped out a pre-existing scroll. 180 // We might have just wiped out a pre-existing scroll.
154 if (update_.scroll_delta == pp::Point()) { 181 if (update_.scroll_delta == pp::Point()) {
155 update_.scroll_rect = pp::Rect(); 182 update_.scroll_rect = pp::Rect();
156 return; 183 return;
157 } 184 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 281 }
255 282
256 // If the new paint overlaps with a scroll, then also invalidate the rect in 283 // If the new paint overlaps with a scroll, then also invalidate the rect in
257 // its new position. 284 // its new position.
258 if (check_scroll && 285 if (check_scroll &&
259 !update_.scroll_rect.IsEmpty() && 286 !update_.scroll_rect.IsEmpty() &&
260 update_.scroll_rect.Intersects(rect)) { 287 update_.scroll_rect.Intersects(rect)) {
261 InvalidateRectInternal(ScrollPaintRect(rect, update_.scroll_delta), false); 288 InvalidateRectInternal(ScrollPaintRect(rect, update_.scroll_delta), false);
262 } 289 }
263 } 290 }
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