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

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 // We don't use std::sign here to avoid any issues with negative 0.
Sam McNally 2015/06/02 03:29:26 Don't pp:Points contain ints?
14 int32_t sign(int32_t num) {
Sam McNally 2015/06/02 03:29:26 How about bool IsNegative(int32_t num) { return nu
raymes 2015/06/02 06:57:08 Done.
15 return num < 0 ? -1 : 1;
16 }
17
18 } // namespace
19
11 // ---------------------------------------------------------------------------- 20 // ----------------------------------------------------------------------------
12 // ALGORITHM NOTES 21 // ALGORITHM NOTES
13 // 22 //
14 // We attempt to maintain a scroll rect in the presence of invalidations that 23 // 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 24 // 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. 25 // rect, then we just treat the scroll rect as an invalidation rect.
17 // 26 //
18 // For invalidations performed prior to scrolling and contained within the 27 // For invalidations performed prior to scrolling and contained within the
19 // scroll rect, we offset the invalidation rects to account for the fact that 28 // scroll rect, we offset the invalidation rects to account for the fact that
20 // the consumer will perform scrolling before painting. 29 // the consumer will perform scrolling before painting.
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 147 }
139 148
140 // Again, we only support scrolling along one axis at a time. Make sure this 149 // 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. 150 // update doesn't scroll on a different axis than any existing one.
142 if ((amount.x() && update_.scroll_delta.y()) || 151 if ((amount.x() && update_.scroll_delta.y()) ||
143 (amount.y() && update_.scroll_delta.x())) { 152 (amount.y() && update_.scroll_delta.x())) {
144 InvalidateRect(clip_rect); 153 InvalidateRect(clip_rect);
145 return; 154 return;
146 } 155 }
147 156
157 // If we scroll in a reverse direction to the direction we originally scrolled
158 // and there were invalidations that happened in-between we may end up
159 // incorrectly clipping the invalidated rects (see crbug.com/488390). This bug
160 // doesn't exist in the original implementation
161 // (ppapi/utility/graphics/paint_aggregator.cc) which uses a different method
162 // of handling invalidations that occur after a scroll. The problem is that
163 // when we scroll the invalidated region, we clip it to the scroll rect. This
164 // can cause us to lose information about what the invalidated region was if
165 // it gets scrolled back into view. We either need to not do this clipping or
166 // disallow combining scrolls that occur in different directions with
167 // invalidations that happen in-between. This code really needs some tests...
168 if (!update_.paint_rects.empty()) {
169 if (sign(amount.x()) != sign(update_.scroll_delta.x()) ||
170 sign(amount.y()) != sign(update_.scroll_delta.y())) {
171 InvalidateRect(clip_rect);
172 return;
173 }
174 }
175
148 // The scroll rect is new or isn't changing (though the scroll amount may 176 // The scroll rect is new or isn't changing (though the scroll amount may
149 // be changing). 177 // be changing).
150 update_.scroll_rect = clip_rect; 178 update_.scroll_rect = clip_rect;
151 update_.scroll_delta += amount; 179 update_.scroll_delta += amount;
152 180
153 // We might have just wiped out a pre-existing scroll. 181 // We might have just wiped out a pre-existing scroll.
154 if (update_.scroll_delta == pp::Point()) { 182 if (update_.scroll_delta == pp::Point()) {
155 update_.scroll_rect = pp::Rect(); 183 update_.scroll_rect = pp::Rect();
156 return; 184 return;
157 } 185 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 282 }
255 283
256 // If the new paint overlaps with a scroll, then also invalidate the rect in 284 // If the new paint overlaps with a scroll, then also invalidate the rect in
257 // its new position. 285 // its new position.
258 if (check_scroll && 286 if (check_scroll &&
259 !update_.scroll_rect.IsEmpty() && 287 !update_.scroll_rect.IsEmpty() &&
260 update_.scroll_rect.Intersects(rect)) { 288 update_.scroll_rect.Intersects(rect)) {
261 InvalidateRectInternal(ScrollPaintRect(rect, update_.scroll_delta), false); 289 InvalidateRectInternal(ScrollPaintRect(rect, update_.scroll_delta), false);
262 } 290 }
263 } 291 }
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