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

Side by Side Diff: pdf/paint_manager.cc

Issue 2400743002: Improved Pinch-Zoom for PDF. (Closed)
Patch Set: Small changes. Created 4 years, 1 month 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 | « pdf/paint_manager.h ('k') | 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_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 14 matching lines...) Expand all
25 25
26 PaintManager::PaintManager(pp::Instance* instance, 26 PaintManager::PaintManager(pp::Instance* instance,
27 Client* client, 27 Client* client,
28 bool is_always_opaque) 28 bool is_always_opaque)
29 : instance_(instance), 29 : instance_(instance),
30 client_(client), 30 client_(client),
31 is_always_opaque_(is_always_opaque), 31 is_always_opaque_(is_always_opaque),
32 callback_factory_(nullptr), 32 callback_factory_(nullptr),
33 manual_callback_pending_(false), 33 manual_callback_pending_(false),
34 flush_pending_(false), 34 flush_pending_(false),
35 flush_requested_(false),
35 has_pending_resize_(false), 36 has_pending_resize_(false),
36 graphics_need_to_be_bound_(false), 37 graphics_need_to_be_bound_(false),
37 pending_device_scale_(1.0), 38 pending_device_scale_(1.0),
38 device_scale_(1.0), 39 device_scale_(1.0),
39 in_paint_(false), 40 in_paint_(false),
40 first_paint_(true), 41 first_paint_(true),
41 view_size_changed_waiting_for_paint_(false) { 42 view_size_changed_waiting_for_paint_(false) {
42 // Set the callback object outside of the initializer list to avoid a 43 // Set the callback object outside of the initializer list to avoid a
43 // compiler warning about using "this" in an initializer list. 44 // compiler warning about using "this" in an initializer list.
44 callback_factory_.Initialize(this); 45 callback_factory_.Initialize(this);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 102
102 has_pending_resize_ = true; 103 has_pending_resize_ = true;
103 pending_size_ = new_size; 104 pending_size_ = new_size;
104 pending_device_scale_ = device_scale; 105 pending_device_scale_ = device_scale;
105 106
106 view_size_changed_waiting_for_paint_ = true; 107 view_size_changed_waiting_for_paint_ = true;
107 108
108 Invalidate(); 109 Invalidate();
109 } 110 }
110 111
112 void PaintManager::SetTransform(float scale,
113 const pp::Point& origin,
114 const pp::Point& translate,
115 bool schedule_flush) {
116 if (graphics_.is_null())
117 return;
118
119 graphics_.SetLayerTransform(scale, origin, translate);
120
121 if (!schedule_flush)
122 return;
123
124 if (flush_pending_) {
125 flush_requested_ = true;
126 return;
127 }
128 Flush();
129 }
130
131 void PaintManager::ClearTransform() {
132 SetTransform(1.f, pp::Point(), pp::Point(), false);
133 }
134
111 void PaintManager::Invalidate() { 135 void PaintManager::Invalidate() {
112 if (graphics_.is_null() && !has_pending_resize_) 136 if (graphics_.is_null() && !has_pending_resize_)
113 return; 137 return;
114 138
115 EnsureCallbackPending(); 139 EnsureCallbackPending();
116 aggregator_.InvalidateRect(pp::Rect(GetEffectiveSize())); 140 aggregator_.InvalidateRect(pp::Rect(GetEffectiveSize()));
117 } 141 }
118 142
119 void PaintManager::InvalidateRect(const pp::Rect& rect) { 143 void PaintManager::InvalidateRect(const pp::Rect& rect) {
120 DCHECK(!in_paint_); 144 DCHECK(!in_paint_);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 EnsureCallbackPending(); 278 EnsureCallbackPending();
255 return; 279 return;
256 } 280 }
257 } 281 }
258 282
259 for (const auto& ready_rect : ready_now) { 283 for (const auto& ready_rect : ready_now) {
260 graphics_.PaintImageData( 284 graphics_.PaintImageData(
261 ready_rect.image_data, ready_rect.offset, ready_rect.rect); 285 ready_rect.image_data, ready_rect.offset, ready_rect.rect);
262 } 286 }
263 287
288 Flush();
289
290 in_paint_ = false;
291 first_paint_ = false;
292
293 if (graphics_need_to_be_bound_) {
294 instance_->BindGraphics(graphics_);
295 graphics_need_to_be_bound_ = false;
296 }
297 }
298
299 void PaintManager::Flush() {
300 flush_requested_ = false;
301
264 int32_t result = graphics_.Flush( 302 int32_t result = graphics_.Flush(
265 callback_factory_.NewCallback(&PaintManager::OnFlushComplete)); 303 callback_factory_.NewCallback(&PaintManager::OnFlushComplete));
266 304
267 // If you trigger this assertion, then your plugin has called Flush() 305 // If you trigger this assertion, then your plugin has called Flush()
268 // manually. When using the PaintManager, you should not call Flush, it will 306 // manually. When using the PaintManager, you should not call Flush, it will
269 // handle that for you because it needs to know when it can do the next paint 307 // handle that for you because it needs to know when it can do the next paint
270 // by implementing the flush callback. 308 // by implementing the flush callback.
271 // 309 //
272 // Another possible cause of this assertion is re-using devices. If you 310 // Another possible cause of this assertion is re-using devices. If you
273 // use one device, swap it with another, then swap it back, we won't know 311 // use one device, swap it with another, then swap it back, we won't know
274 // that we've already scheduled a Flush on the first device. It's best to not 312 // that we've already scheduled a Flush on the first device. It's best to not
275 // re-use devices in this way. 313 // re-use devices in this way.
276 DCHECK(result != PP_ERROR_INPROGRESS); 314 DCHECK(result != PP_ERROR_INPROGRESS);
277 315
278 if (result == PP_OK_COMPLETIONPENDING) { 316 if (result == PP_OK_COMPLETIONPENDING) {
279 flush_pending_ = true; 317 flush_pending_ = true;
280 } else { 318 } else {
281 DCHECK(result == PP_OK); // Catch all other errors in debug mode. 319 DCHECK(result == PP_OK); // Catch all other errors in debug mode.
282 } 320 }
283
284 in_paint_ = false;
285 first_paint_ = false;
286
287 if (graphics_need_to_be_bound_) {
288 instance_->BindGraphics(graphics_);
289 graphics_need_to_be_bound_ = false;
290 }
291 } 321 }
292 322
293 void PaintManager::OnFlushComplete(int32_t) { 323 void PaintManager::OnFlushComplete(int32_t) {
294 DCHECK(flush_pending_); 324 DCHECK(flush_pending_);
295 flush_pending_ = false; 325 flush_pending_ = false;
296 326
297 // If more paints were enqueued while we were waiting for the flush to 327 // If more paints were enqueued while we were waiting for the flush to
298 // complete, execute them now. 328 // complete, execute them now.
299 if (aggregator_.HasPendingUpdate()) 329 if (aggregator_.HasPendingUpdate())
300 DoPaint(); 330 DoPaint();
331
332 // If there was another flush request while flushing we flush again.
333 if (flush_requested_) {
334 Flush();
335 }
301 } 336 }
302 337
303 void PaintManager::OnManualCallbackComplete(int32_t) { 338 void PaintManager::OnManualCallbackComplete(int32_t) {
304 DCHECK(manual_callback_pending_); 339 DCHECK(manual_callback_pending_);
305 manual_callback_pending_ = false; 340 manual_callback_pending_ = false;
306 341
307 // Just because we have a manual callback doesn't mean there are actually any 342 // Just because we have a manual callback doesn't mean there are actually any
308 // invalid regions. Even though we only schedule this callback when something 343 // invalid regions. Even though we only schedule this callback when something
309 // is pending, a Flush callback could have come in before this callback was 344 // is pending, a Flush callback could have come in before this callback was
310 // executed and that could have cleared the queue. 345 // executed and that could have cleared the queue.
311 if (aggregator_.HasPendingUpdate()) 346 if (aggregator_.HasPendingUpdate())
312 DoPaint(); 347 DoPaint();
313 } 348 }
OLDNEW
« no previous file with comments | « pdf/paint_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698