Chromium Code Reviews| 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 pp::Point origin, | |
| 114 pp::Point translate) { | |
| 115 graphics_.SetLayerTransform(scale, origin, translate); | |
|
Lei Zhang
2016/10/27 16:56:36
A few methods check for the following. Should this
Kevin McNee - google account
2016/10/27 21:40:30
Yeah, checking graphics_.is_null() is a good idea,
| |
| 116 if (!flush_pending_) { | |
|
Lei Zhang
2016/10/27 16:56:36
Does this read better?
if (flush_pending_) {
fl
Kevin McNee - google account
2016/10/27 21:40:30
Done.
| |
| 117 Flush(); | |
| 118 } else { | |
| 119 flush_requested_ = true; | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 void PaintManager::SetTransform(float scale) { | |
| 124 graphics_.SetLayerTransform(scale, pp::Point(), pp::Point()); | |
| 125 | |
| 126 EnsureCallbackPending(); | |
| 127 } | |
| 128 | |
| 111 void PaintManager::Invalidate() { | 129 void PaintManager::Invalidate() { |
| 112 if (graphics_.is_null() && !has_pending_resize_) | 130 if (graphics_.is_null() && !has_pending_resize_) |
| 113 return; | 131 return; |
| 114 | 132 |
| 115 EnsureCallbackPending(); | 133 EnsureCallbackPending(); |
| 116 aggregator_.InvalidateRect(pp::Rect(GetEffectiveSize())); | 134 aggregator_.InvalidateRect(pp::Rect(GetEffectiveSize())); |
| 117 } | 135 } |
| 118 | 136 |
| 119 void PaintManager::InvalidateRect(const pp::Rect& rect) { | 137 void PaintManager::InvalidateRect(const pp::Rect& rect) { |
| 120 DCHECK(!in_paint_); | 138 DCHECK(!in_paint_); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 EnsureCallbackPending(); | 272 EnsureCallbackPending(); |
| 255 return; | 273 return; |
| 256 } | 274 } |
| 257 } | 275 } |
| 258 | 276 |
| 259 for (const auto& ready_rect : ready_now) { | 277 for (const auto& ready_rect : ready_now) { |
| 260 graphics_.PaintImageData( | 278 graphics_.PaintImageData( |
| 261 ready_rect.image_data, ready_rect.offset, ready_rect.rect); | 279 ready_rect.image_data, ready_rect.offset, ready_rect.rect); |
| 262 } | 280 } |
| 263 | 281 |
| 282 Flush(); | |
| 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 } | |
| 292 | |
| 293 void PaintManager::Flush() { | |
| 294 flush_requested_ = false; | |
| 295 | |
| 264 int32_t result = graphics_.Flush( | 296 int32_t result = graphics_.Flush( |
| 265 callback_factory_.NewCallback(&PaintManager::OnFlushComplete)); | 297 callback_factory_.NewCallback(&PaintManager::OnFlushComplete)); |
| 266 | 298 |
| 267 // If you trigger this assertion, then your plugin has called Flush() | 299 // If you trigger this assertion, then your plugin has called Flush() |
| 268 // manually. When using the PaintManager, you should not call Flush, it will | 300 // 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 | 301 // handle that for you because it needs to know when it can do the next paint |
| 270 // by implementing the flush callback. | 302 // by implementing the flush callback. |
| 271 // | 303 // |
| 272 // Another possible cause of this assertion is re-using devices. If you | 304 // 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 | 305 // 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 | 306 // that we've already scheduled a Flush on the first device. It's best to not |
| 275 // re-use devices in this way. | 307 // re-use devices in this way. |
| 276 DCHECK(result != PP_ERROR_INPROGRESS); | 308 DCHECK(result != PP_ERROR_INPROGRESS); |
| 277 | 309 |
| 278 if (result == PP_OK_COMPLETIONPENDING) { | 310 if (result == PP_OK_COMPLETIONPENDING) { |
| 279 flush_pending_ = true; | 311 flush_pending_ = true; |
| 280 } else { | 312 } else { |
| 281 DCHECK(result == PP_OK); // Catch all other errors in debug mode. | 313 DCHECK(result == PP_OK); // Catch all other errors in debug mode. |
| 282 } | 314 } |
| 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 } | 315 } |
| 292 | 316 |
| 293 void PaintManager::OnFlushComplete(int32_t) { | 317 void PaintManager::OnFlushComplete(int32_t) { |
| 294 DCHECK(flush_pending_); | 318 DCHECK(flush_pending_); |
| 295 flush_pending_ = false; | 319 flush_pending_ = false; |
| 296 | 320 |
| 297 // If more paints were enqueued while we were waiting for the flush to | 321 // If more paints were enqueued while we were waiting for the flush to |
| 298 // complete, execute them now. | 322 // complete, execute them now. |
| 299 if (aggregator_.HasPendingUpdate()) | 323 if (aggregator_.HasPendingUpdate()) |
| 300 DoPaint(); | 324 DoPaint(); |
| 325 | |
| 326 // If there was another flush request while flushing we flush again. | |
| 327 if (flush_requested_) { | |
| 328 Flush(); | |
| 329 } | |
| 301 } | 330 } |
| 302 | 331 |
| 303 void PaintManager::OnManualCallbackComplete(int32_t) { | 332 void PaintManager::OnManualCallbackComplete(int32_t) { |
| 304 DCHECK(manual_callback_pending_); | 333 DCHECK(manual_callback_pending_); |
| 305 manual_callback_pending_ = false; | 334 manual_callback_pending_ = false; |
| 306 | 335 |
| 307 // Just because we have a manual callback doesn't mean there are actually any | 336 // 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 | 337 // 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 | 338 // is pending, a Flush callback could have come in before this callback was |
| 310 // executed and that could have cleared the queue. | 339 // executed and that could have cleared the queue. |
| 311 if (aggregator_.HasPendingUpdate()) | 340 if (aggregator_.HasPendingUpdate()) |
| 312 DoPaint(); | 341 DoPaint(); |
| 313 } | 342 } |
| OLD | NEW |