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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 DCHECK(!instance_ && !client_); // Can't initialize twice. | 92 DCHECK(!instance_ && !client_); // Can't initialize twice. |
| 92 instance_ = instance; | 93 instance_ = instance; |
| 93 client_ = client; | 94 client_ = client; |
| 94 is_always_opaque_ = is_always_opaque; | 95 is_always_opaque_ = is_always_opaque; |
| 95 } | 96 } |
| 96 | 97 |
| 97 void PaintManager::SetSize(const pp::Size& new_size, float device_scale) { | 98 void PaintManager::SetSize(const pp::Size& new_size, float device_scale) { |
| 98 if (GetEffectiveSize() == new_size && | 99 if (GetEffectiveSize() == new_size && |
| 99 GetEffectiveDeviceScale() == device_scale) | 100 GetEffectiveDeviceScale() == device_scale) |
| 100 return; | 101 return; |
| 101 | |
| 102 has_pending_resize_ = true; | 102 has_pending_resize_ = true; |
|
Kevin McNee - google account
2016/10/06 21:53:18
Unnecessary whitespace change.
Kevin McNee - google account
2016/10/13 18:19:24
Done.
| |
| 103 pending_size_ = new_size; | 103 pending_size_ = new_size; |
| 104 pending_device_scale_ = device_scale; | 104 pending_device_scale_ = device_scale; |
| 105 | 105 |
| 106 view_size_changed_waiting_for_paint_ = true; | 106 view_size_changed_waiting_for_paint_ = true; |
| 107 Invalidate(); | |
|
Kevin McNee - google account
2016/10/06 21:53:18
Unnecessary whitespace change.
Kevin McNee - google account
2016/10/13 18:19:24
Done.
| |
| 108 } | |
| 107 | 109 |
| 108 Invalidate(); | 110 void PaintManager::SetTransform(float scale, |
| 111 pp::Point origin, | |
| 112 pp::Point translate) { | |
| 113 if (!flush_pending_) { | |
| 114 graphics_.SetLayerTransform(scale, origin, translate); | |
| 115 flush_pending_ = true; | |
| 116 flush_requested_ = false; | |
| 117 graphics_.Flush( | |
| 118 callback_factory_.NewCallback(&PaintManager::OnFlushComplete)); | |
| 119 scale_ = 1.f; | |
| 120 origin_ = pp::Point(); | |
| 121 transform_ = pp::Point(); | |
| 122 } else { | |
| 123 flush_requested_ = true; | |
| 124 graphics_.SetLayerTransform(scale, origin, translate); | |
| 125 } | |
| 126 } | |
| 127 | |
| 128 void PaintManager::SetTransform(float scale) { | |
| 129 graphics_.SetLayerTransform(scale, pp::Point(), pp::Point()); | |
| 130 | |
| 131 EnsureCallbackPending(); | |
| 109 } | 132 } |
| 110 | 133 |
| 111 void PaintManager::Invalidate() { | 134 void PaintManager::Invalidate() { |
| 112 if (graphics_.is_null() && !has_pending_resize_) | 135 if (graphics_.is_null() && !has_pending_resize_) |
| 113 return; | 136 return; |
| 114 | 137 |
| 115 EnsureCallbackPending(); | 138 EnsureCallbackPending(); |
| 116 aggregator_.InvalidateRect(pp::Rect(GetEffectiveSize())); | 139 aggregator_.InvalidateRect(pp::Rect(GetEffectiveSize())); |
| 117 } | 140 } |
| 118 | 141 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 if (ready_now.empty()) { | 275 if (ready_now.empty()) { |
| 253 in_paint_ = false; | 276 in_paint_ = false; |
| 254 EnsureCallbackPending(); | 277 EnsureCallbackPending(); |
| 255 return; | 278 return; |
| 256 } | 279 } |
| 257 } | 280 } |
| 258 | 281 |
| 259 for (const auto& ready_rect : ready_now) { | 282 for (const auto& ready_rect : ready_now) { |
| 260 graphics_.PaintImageData( | 283 graphics_.PaintImageData( |
| 261 ready_rect.image_data, ready_rect.offset, ready_rect.rect); | 284 ready_rect.image_data, ready_rect.offset, ready_rect.rect); |
| 262 } | 285 } |
|
Kevin McNee - google account
2016/10/06 21:53:18
Unnecessary whitespace change.
Kevin McNee - google account
2016/10/13 18:19:24
Done.
| |
| 263 | |
| 264 int32_t result = graphics_.Flush( | 286 int32_t result = graphics_.Flush( |
| 265 callback_factory_.NewCallback(&PaintManager::OnFlushComplete)); | 287 callback_factory_.NewCallback(&PaintManager::OnFlushComplete)); |
|
Kevin McNee - google account
2016/10/06 21:53:18
Unnecessary whitespace change.
Kevin McNee - google account
2016/10/13 18:19:24
Done.
| |
| 266 | |
| 267 // If you trigger this assertion, then your plugin has called Flush() | 288 // If you trigger this assertion, then your plugin has called Flush() |
| 268 // manually. When using the PaintManager, you should not call Flush, it will | 289 // 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 | 290 // handle that for you because it needs to know when it can do the next paint |
| 270 // by implementing the flush callback. | 291 // by implementing the flush callback. |
| 271 // | 292 // |
| 272 // Another possible cause of this assertion is re-using devices. If you | 293 // 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 | 294 // 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 | 295 // that we've already scheduled a Flush on the first device. It's best to not |
| 275 // re-use devices in this way. | 296 // re-use devices in this way. |
| 276 DCHECK(result != PP_ERROR_INPROGRESS); | 297 DCHECK(result != PP_ERROR_INPROGRESS); |
| 277 | 298 |
| 278 if (result == PP_OK_COMPLETIONPENDING) { | 299 if (result == PP_OK_COMPLETIONPENDING) { |
| 279 flush_pending_ = true; | 300 flush_pending_ = true; |
| 280 } else { | 301 } else { |
| 281 DCHECK(result == PP_OK); // Catch all other errors in debug mode. | 302 DCHECK(result == PP_OK); // Catch all other errors in debug mode. |
| 282 } | 303 } |
| 283 | 304 |
| 284 in_paint_ = false; | 305 in_paint_ = false; |
| 285 first_paint_ = false; | 306 first_paint_ = false; |
| 286 | 307 |
| 287 if (graphics_need_to_be_bound_) { | 308 if (graphics_need_to_be_bound_) { |
| 288 instance_->BindGraphics(graphics_); | 309 instance_->BindGraphics(graphics_); |
| 289 graphics_need_to_be_bound_ = false; | 310 graphics_need_to_be_bound_ = false; |
| 290 } | 311 } |
| 291 } | 312 } |
| 292 | 313 |
| 293 void PaintManager::OnFlushComplete(int32_t) { | 314 void PaintManager::OnFlushComplete(int32_t) { |
| 294 DCHECK(flush_pending_); | 315 DCHECK(flush_pending_); |
| 295 flush_pending_ = false; | 316 flush_pending_ = false; |
| 296 | 317 // If there was another flush request while flushing we flush again. |
| 318 if (flush_requested_) { | |
| 319 flush_requested_ = false; | |
| 320 graphics_.Flush( | |
| 321 callback_factory_.NewCallback(&PaintManager::OnFlushComplete)); | |
| 322 } | |
| 297 // If more paints were enqueued while we were waiting for the flush to | 323 // If more paints were enqueued while we were waiting for the flush to |
| 298 // complete, execute them now. | 324 // complete, execute them now. |
| 299 if (aggregator_.HasPendingUpdate()) | 325 if (aggregator_.HasPendingUpdate()) |
| 300 DoPaint(); | 326 DoPaint(); |
| 301 } | 327 } |
| 302 | 328 |
| 303 void PaintManager::OnManualCallbackComplete(int32_t) { | 329 void PaintManager::OnManualCallbackComplete(int32_t) { |
| 304 DCHECK(manual_callback_pending_); | 330 DCHECK(manual_callback_pending_); |
| 305 manual_callback_pending_ = false; | 331 manual_callback_pending_ = false; |
|
Kevin McNee - google account
2016/10/06 21:53:18
Unnecessary whitespace change.
Kevin McNee - google account
2016/10/13 18:19:24
Done.
| |
| 306 | |
| 307 // Just because we have a manual callback doesn't mean there are actually any | 332 // 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 | 333 // 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 | 334 // is pending, a Flush callback could have come in before this callback was |
| 310 // executed and that could have cleared the queue. | 335 // executed and that could have cleared the queue. |
| 311 if (aggregator_.HasPendingUpdate()) | 336 if (aggregator_.HasPendingUpdate()) |
| 312 DoPaint(); | 337 DoPaint(); |
| 313 } | 338 } |
| OLD | NEW |