OLD | NEW |
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_manager.h" | 5 #include "pdf/paint_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 client_->OnPaint(update.paint_rects, &ready, &pending); | 204 client_->OnPaint(update.paint_rects, &ready, &pending); |
205 | 205 |
206 if (ready.empty() && pending.empty()) { | 206 if (ready.empty() && pending.empty()) { |
207 in_paint_ = false; | 207 in_paint_ = false; |
208 return; // Nothing was painted, don't schedule a flush. | 208 return; // Nothing was painted, don't schedule a flush. |
209 } | 209 } |
210 | 210 |
211 std::vector<PaintAggregator::ReadyRect> ready_now; | 211 std::vector<PaintAggregator::ReadyRect> ready_now; |
212 if (pending.empty()) { | 212 if (pending.empty()) { |
213 std::vector<PaintAggregator::ReadyRect> temp_ready; | 213 std::vector<PaintAggregator::ReadyRect> temp_ready; |
214 for (size_t i = 0; i < ready.size(); ++i) | 214 temp_ready.insert(temp_ready.end(), ready.begin(), ready.end()); |
215 temp_ready.push_back(ready[i]); | |
216 aggregator_.SetIntermediateResults(temp_ready, pending); | 215 aggregator_.SetIntermediateResults(temp_ready, pending); |
217 ready_now = aggregator_.GetReadyRects(); | 216 ready_now = aggregator_.GetReadyRects(); |
218 aggregator_.ClearPendingUpdate(); | 217 aggregator_.ClearPendingUpdate(); |
219 | 218 |
220 // Apply any scroll first. | 219 // Apply any scroll first. |
221 if (update.has_scroll) | 220 if (update.has_scroll) |
222 graphics_.Scroll(update.scroll_rect, update.scroll_delta); | 221 graphics_.Scroll(update.scroll_rect, update.scroll_delta); |
223 | 222 |
224 view_size_changed_waiting_for_paint_ = false; | 223 view_size_changed_waiting_for_paint_ = false; |
225 } else { | 224 } else { |
226 std::vector<PaintAggregator::ReadyRect> ready_later; | 225 std::vector<PaintAggregator::ReadyRect> ready_later; |
227 for (size_t i = 0; i < ready.size(); ++i) { | 226 for (const auto& ready_rect : ready) { |
228 // Don't flush any part (i.e. scrollbars) if we're resizing the browser, | 227 // Don't flush any part (i.e. scrollbars) if we're resizing the browser, |
229 // as that'll lead to flashes. Until we flush, the browser will use the | 228 // as that'll lead to flashes. Until we flush, the browser will use the |
230 // previous image, but if we flush, it'll revert to using the blank image. | 229 // previous image, but if we flush, it'll revert to using the blank image. |
231 // We make an exception for the first paint since we want to show the | 230 // We make an exception for the first paint since we want to show the |
232 // default background color instead of the pepper default of black. | 231 // default background color instead of the pepper default of black. |
233 if (ready[i].flush_now && | 232 if (ready_rect.flush_now && |
234 (!view_size_changed_waiting_for_paint_ || first_paint_)) { | 233 (!view_size_changed_waiting_for_paint_ || first_paint_)) { |
235 ready_now.push_back(ready[i]); | 234 ready_now.push_back(ready_rect); |
236 } else { | 235 } else { |
237 ready_later.push_back(ready[i]); | 236 ready_later.push_back(ready_rect); |
238 } | 237 } |
239 } | 238 } |
240 // Take the rectangles, except the ones that need to be flushed right away, | 239 // Take the rectangles, except the ones that need to be flushed right away, |
241 // and save them so that everything is flushed at once. | 240 // and save them so that everything is flushed at once. |
242 aggregator_.SetIntermediateResults(ready_later, pending); | 241 aggregator_.SetIntermediateResults(ready_later, pending); |
243 | 242 |
244 if (ready_now.empty()) { | 243 if (ready_now.empty()) { |
245 in_paint_ = false; | 244 in_paint_ = false; |
246 EnsureCallbackPending(); | 245 EnsureCallbackPending(); |
247 return; | 246 return; |
248 } | 247 } |
249 } | 248 } |
250 | 249 |
251 for (size_t i = 0; i < ready_now.size(); ++i) { | 250 for (const auto& ready_rect : ready_now) { |
252 graphics_.PaintImageData( | 251 graphics_.PaintImageData( |
253 ready_now[i].image_data, ready_now[i].offset, ready_now[i].rect); | 252 ready_rect.image_data, ready_rect.offset, ready_rect.rect); |
254 } | 253 } |
255 | 254 |
256 int32_t result = graphics_.Flush( | 255 int32_t result = graphics_.Flush( |
257 callback_factory_.NewCallback(&PaintManager::OnFlushComplete)); | 256 callback_factory_.NewCallback(&PaintManager::OnFlushComplete)); |
258 | 257 |
259 // If you trigger this assertion, then your plugin has called Flush() | 258 // If you trigger this assertion, then your plugin has called Flush() |
260 // manually. When using the PaintManager, you should not call Flush, it will | 259 // manually. When using the PaintManager, you should not call Flush, it will |
261 // handle that for you because it needs to know when it can do the next paint | 260 // handle that for you because it needs to know when it can do the next paint |
262 // by implementing the flush callback. | 261 // by implementing the flush callback. |
263 // | 262 // |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 DCHECK(manual_callback_pending_); | 295 DCHECK(manual_callback_pending_); |
297 manual_callback_pending_ = false; | 296 manual_callback_pending_ = false; |
298 | 297 |
299 // Just because we have a manual callback doesn't mean there are actually any | 298 // Just because we have a manual callback doesn't mean there are actually any |
300 // invalid regions. Even though we only schedule this callback when something | 299 // invalid regions. Even though we only schedule this callback when something |
301 // is pending, a Flush callback could have come in before this callback was | 300 // is pending, a Flush callback could have come in before this callback was |
302 // executed and that could have cleared the queue. | 301 // executed and that could have cleared the queue. |
303 if (aggregator_.HasPendingUpdate()) | 302 if (aggregator_.HasPendingUpdate()) |
304 DoPaint(); | 303 DoPaint(); |
305 } | 304 } |
OLD | NEW |