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 14 matching lines...) Expand all Loading... | |
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 Loading... | |
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 if (graphics_.is_null()) | |
116 return; | |
117 | |
118 graphics_.SetLayerTransform(scale, origin, translate); | |
119 | |
120 if (flush_pending_) { | |
Lei Zhang
2016/10/27 23:04:33
Given the differences in behavior, maybe this meth
Kevin McNee - google account
2016/10/28 19:19:38
I've made the behaviour w.r.t. flushing more expli
| |
121 flush_requested_ = true; | |
122 return; | |
123 } | |
124 Flush(); | |
125 } | |
126 | |
127 void PaintManager::SetTransform(float scale) { | |
128 if (graphics_.is_null()) | |
129 return; | |
130 | |
131 graphics_.SetLayerTransform(scale, pp::Point(), pp::Point()); | |
132 | |
133 EnsureCallbackPending(); | |
134 } | |
135 | |
111 void PaintManager::Invalidate() { | 136 void PaintManager::Invalidate() { |
112 if (graphics_.is_null() && !has_pending_resize_) | 137 if (graphics_.is_null() && !has_pending_resize_) |
113 return; | 138 return; |
114 | 139 |
115 EnsureCallbackPending(); | 140 EnsureCallbackPending(); |
116 aggregator_.InvalidateRect(pp::Rect(GetEffectiveSize())); | 141 aggregator_.InvalidateRect(pp::Rect(GetEffectiveSize())); |
117 } | 142 } |
118 | 143 |
119 void PaintManager::InvalidateRect(const pp::Rect& rect) { | 144 void PaintManager::InvalidateRect(const pp::Rect& rect) { |
120 DCHECK(!in_paint_); | 145 DCHECK(!in_paint_); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 EnsureCallbackPending(); | 279 EnsureCallbackPending(); |
255 return; | 280 return; |
256 } | 281 } |
257 } | 282 } |
258 | 283 |
259 for (const auto& ready_rect : ready_now) { | 284 for (const auto& ready_rect : ready_now) { |
260 graphics_.PaintImageData( | 285 graphics_.PaintImageData( |
261 ready_rect.image_data, ready_rect.offset, ready_rect.rect); | 286 ready_rect.image_data, ready_rect.offset, ready_rect.rect); |
262 } | 287 } |
263 | 288 |
289 Flush(); | |
290 | |
291 in_paint_ = false; | |
292 first_paint_ = false; | |
293 | |
294 if (graphics_need_to_be_bound_) { | |
295 instance_->BindGraphics(graphics_); | |
296 graphics_need_to_be_bound_ = false; | |
297 } | |
298 } | |
299 | |
300 void PaintManager::Flush() { | |
301 flush_requested_ = false; | |
302 | |
264 int32_t result = graphics_.Flush( | 303 int32_t result = graphics_.Flush( |
265 callback_factory_.NewCallback(&PaintManager::OnFlushComplete)); | 304 callback_factory_.NewCallback(&PaintManager::OnFlushComplete)); |
266 | 305 |
267 // If you trigger this assertion, then your plugin has called Flush() | 306 // If you trigger this assertion, then your plugin has called Flush() |
268 // manually. When using the PaintManager, you should not call Flush, it will | 307 // 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 | 308 // handle that for you because it needs to know when it can do the next paint |
270 // by implementing the flush callback. | 309 // by implementing the flush callback. |
271 // | 310 // |
272 // Another possible cause of this assertion is re-using devices. If you | 311 // 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 | 312 // 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 | 313 // that we've already scheduled a Flush on the first device. It's best to not |
275 // re-use devices in this way. | 314 // re-use devices in this way. |
276 DCHECK(result != PP_ERROR_INPROGRESS); | 315 DCHECK(result != PP_ERROR_INPROGRESS); |
277 | 316 |
278 if (result == PP_OK_COMPLETIONPENDING) { | 317 if (result == PP_OK_COMPLETIONPENDING) { |
279 flush_pending_ = true; | 318 flush_pending_ = true; |
280 } else { | 319 } else { |
281 DCHECK(result == PP_OK); // Catch all other errors in debug mode. | 320 DCHECK(result == PP_OK); // Catch all other errors in debug mode. |
282 } | 321 } |
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 } | 322 } |
292 | 323 |
293 void PaintManager::OnFlushComplete(int32_t) { | 324 void PaintManager::OnFlushComplete(int32_t) { |
294 DCHECK(flush_pending_); | 325 DCHECK(flush_pending_); |
295 flush_pending_ = false; | 326 flush_pending_ = false; |
296 | 327 |
297 // If more paints were enqueued while we were waiting for the flush to | 328 // If more paints were enqueued while we were waiting for the flush to |
298 // complete, execute them now. | 329 // complete, execute them now. |
299 if (aggregator_.HasPendingUpdate()) | 330 if (aggregator_.HasPendingUpdate()) |
300 DoPaint(); | 331 DoPaint(); |
332 | |
333 // If there was another flush request while flushing we flush again. | |
334 if (flush_requested_) { | |
335 Flush(); | |
336 } | |
301 } | 337 } |
302 | 338 |
303 void PaintManager::OnManualCallbackComplete(int32_t) { | 339 void PaintManager::OnManualCallbackComplete(int32_t) { |
304 DCHECK(manual_callback_pending_); | 340 DCHECK(manual_callback_pending_); |
305 manual_callback_pending_ = false; | 341 manual_callback_pending_ = false; |
306 | 342 |
307 // Just because we have a manual callback doesn't mean there are actually any | 343 // 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 | 344 // 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 | 345 // is pending, a Flush callback could have come in before this callback was |
310 // executed and that could have cleared the queue. | 346 // executed and that could have cleared the queue. |
311 if (aggregator_.HasPendingUpdate()) | 347 if (aggregator_.HasPendingUpdate()) |
312 DoPaint(); | 348 DoPaint(); |
313 } | 349 } |
OLD | NEW |