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> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "ppapi/c/pp_errors.h" | 13 #include "ppapi/c/pp_errors.h" |
14 #include "ppapi/cpp/instance.h" | 14 #include "ppapi/cpp/instance.h" |
15 #include "ppapi/cpp/module.h" | 15 #include "ppapi/cpp/module.h" |
16 | 16 |
17 PaintManager::PaintManager(pp::Instance* instance, | 17 PaintManager::PaintManager(pp::Instance* instance, |
18 Client* client, | 18 Client* client, |
19 bool is_always_opaque) | 19 bool is_always_opaque) |
20 : instance_(instance), | 20 : instance_(instance), |
21 client_(client), | 21 client_(client), |
22 is_always_opaque_(is_always_opaque), | 22 is_always_opaque_(is_always_opaque), |
23 callback_factory_(NULL), | 23 callback_factory_(NULL), |
24 manual_callback_pending_(false), | 24 manual_callback_pending_(false), |
25 flush_pending_(false), | 25 flush_pending_(false), |
| 26 flush_requested_(false), |
26 has_pending_resize_(false), | 27 has_pending_resize_(false), |
27 graphics_need_to_be_bound_(false), | 28 graphics_need_to_be_bound_(false), |
28 pending_device_scale_(1.0), | 29 pending_device_scale_(1.0), |
29 device_scale_(1.0), | 30 device_scale_(1.0), |
30 in_paint_(false), | 31 in_paint_(false), |
31 first_paint_(true), | 32 first_paint_(true), |
32 view_size_changed_waiting_for_paint_(false) { | 33 view_size_changed_waiting_for_paint_(false) { |
33 // Set the callback object outside of the initializer list to avoid a | 34 // Set the callback object outside of the initializer list to avoid a |
34 // compiler warning about using "this" in an initializer list. | 35 // compiler warning about using "this" in an initializer list. |
35 callback_factory_.Initialize(this); | 36 callback_factory_.Initialize(this); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 DCHECK(!instance_ && !client_); // Can't initialize twice. | 83 DCHECK(!instance_ && !client_); // Can't initialize twice. |
83 instance_ = instance; | 84 instance_ = instance; |
84 client_ = client; | 85 client_ = client; |
85 is_always_opaque_ = is_always_opaque; | 86 is_always_opaque_ = is_always_opaque; |
86 } | 87 } |
87 | 88 |
88 void PaintManager::SetSize(const pp::Size& new_size, float device_scale) { | 89 void PaintManager::SetSize(const pp::Size& new_size, float device_scale) { |
89 if (GetEffectiveSize() == new_size && | 90 if (GetEffectiveSize() == new_size && |
90 GetEffectiveDeviceScale() == device_scale) | 91 GetEffectiveDeviceScale() == device_scale) |
91 return; | 92 return; |
92 | |
93 has_pending_resize_ = true; | 93 has_pending_resize_ = true; |
94 pending_size_ = new_size; | 94 pending_size_ = new_size; |
95 pending_device_scale_ = device_scale; | 95 pending_device_scale_ = device_scale; |
96 | 96 |
97 view_size_changed_waiting_for_paint_ = true; | 97 view_size_changed_waiting_for_paint_ = true; |
| 98 Invalidate(); |
| 99 } |
98 | 100 |
99 Invalidate(); | 101 void PaintManager::SetTransform(float scale, |
| 102 pp::Point origin, |
| 103 pp::Point translate) { |
| 104 if (!flush_pending_) { |
| 105 graphics_.SetLayerTransform(scale, origin, translate); |
| 106 flush_pending_ = true; |
| 107 flush_requested_ = false; |
| 108 graphics_.Flush( |
| 109 callback_factory_.NewCallback(&PaintManager::OnFlushComplete)); |
| 110 scale_ = 1.f; |
| 111 origin_ = pp::Point(); |
| 112 transform_ = pp::Point(); |
| 113 } else { |
| 114 flush_requested_ = true; |
| 115 graphics_.SetLayerTransform(scale, origin, translate); |
| 116 } |
| 117 } |
| 118 |
| 119 void PaintManager::SetTransform(float scale) { |
| 120 graphics_.SetLayerTransform(scale, pp::Point(), pp::Point()); |
| 121 |
| 122 EnsureCallbackPending(); |
100 } | 123 } |
101 | 124 |
102 void PaintManager::Invalidate() { | 125 void PaintManager::Invalidate() { |
103 if (graphics_.is_null() && !has_pending_resize_) | 126 if (graphics_.is_null() && !has_pending_resize_) |
104 return; | 127 return; |
105 | 128 |
106 EnsureCallbackPending(); | 129 EnsureCallbackPending(); |
107 aggregator_.InvalidateRect(pp::Rect(GetEffectiveSize())); | 130 aggregator_.InvalidateRect(pp::Rect(GetEffectiveSize())); |
108 } | 131 } |
109 | 132 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 in_paint_ = false; | 267 in_paint_ = false; |
245 EnsureCallbackPending(); | 268 EnsureCallbackPending(); |
246 return; | 269 return; |
247 } | 270 } |
248 } | 271 } |
249 | 272 |
250 for (const auto& ready_rect : ready_now) { | 273 for (const auto& ready_rect : ready_now) { |
251 graphics_.PaintImageData( | 274 graphics_.PaintImageData( |
252 ready_rect.image_data, ready_rect.offset, ready_rect.rect); | 275 ready_rect.image_data, ready_rect.offset, ready_rect.rect); |
253 } | 276 } |
254 | |
255 int32_t result = graphics_.Flush( | 277 int32_t result = graphics_.Flush( |
256 callback_factory_.NewCallback(&PaintManager::OnFlushComplete)); | 278 callback_factory_.NewCallback(&PaintManager::OnFlushComplete)); |
257 | |
258 // If you trigger this assertion, then your plugin has called Flush() | 279 // If you trigger this assertion, then your plugin has called Flush() |
259 // manually. When using the PaintManager, you should not call Flush, it will | 280 // manually. When using the PaintManager, you should not call Flush, it will |
260 // handle that for you because it needs to know when it can do the next paint | 281 // handle that for you because it needs to know when it can do the next paint |
261 // by implementing the flush callback. | 282 // by implementing the flush callback. |
262 // | 283 // |
263 // Another possible cause of this assertion is re-using devices. If you | 284 // Another possible cause of this assertion is re-using devices. If you |
264 // use one device, swap it with another, then swap it back, we won't know | 285 // use one device, swap it with another, then swap it back, we won't know |
265 // that we've already scheduled a Flush on the first device. It's best to not | 286 // that we've already scheduled a Flush on the first device. It's best to not |
266 // re-use devices in this way. | 287 // re-use devices in this way. |
267 DCHECK(result != PP_ERROR_INPROGRESS); | 288 DCHECK(result != PP_ERROR_INPROGRESS); |
268 | 289 |
269 if (result == PP_OK_COMPLETIONPENDING) { | 290 if (result == PP_OK_COMPLETIONPENDING) { |
270 flush_pending_ = true; | 291 flush_pending_ = true; |
271 } else { | 292 } else { |
272 DCHECK(result == PP_OK); // Catch all other errors in debug mode. | 293 DCHECK(result == PP_OK); // Catch all other errors in debug mode. |
273 } | 294 } |
274 | 295 |
275 in_paint_ = false; | 296 in_paint_ = false; |
276 first_paint_ = false; | 297 first_paint_ = false; |
277 | 298 |
278 if (graphics_need_to_be_bound_) { | 299 if (graphics_need_to_be_bound_) { |
279 instance_->BindGraphics(graphics_); | 300 instance_->BindGraphics(graphics_); |
280 graphics_need_to_be_bound_ = false; | 301 graphics_need_to_be_bound_ = false; |
281 } | 302 } |
282 } | 303 } |
283 | 304 |
284 void PaintManager::OnFlushComplete(int32_t) { | 305 void PaintManager::OnFlushComplete(int32_t) { |
285 DCHECK(flush_pending_); | 306 DCHECK(flush_pending_); |
286 flush_pending_ = false; | 307 flush_pending_ = false; |
287 | 308 // If there was another flush request while flushing we flush again. |
| 309 if (flush_requested_) { |
| 310 flush_requested_ = false; |
| 311 graphics_.Flush( |
| 312 callback_factory_.NewCallback(&PaintManager::OnFlushComplete)); |
| 313 } |
288 // If more paints were enqueued while we were waiting for the flush to | 314 // If more paints were enqueued while we were waiting for the flush to |
289 // complete, execute them now. | 315 // complete, execute them now. |
290 if (aggregator_.HasPendingUpdate()) | 316 if (aggregator_.HasPendingUpdate()) |
291 DoPaint(); | 317 DoPaint(); |
292 } | 318 } |
293 | 319 |
294 void PaintManager::OnManualCallbackComplete(int32_t) { | 320 void PaintManager::OnManualCallbackComplete(int32_t) { |
295 DCHECK(manual_callback_pending_); | 321 DCHECK(manual_callback_pending_); |
296 manual_callback_pending_ = false; | 322 manual_callback_pending_ = false; |
297 | |
298 // Just because we have a manual callback doesn't mean there are actually any | 323 // Just because we have a manual callback doesn't mean there are actually any |
299 // invalid regions. Even though we only schedule this callback when something | 324 // invalid regions. Even though we only schedule this callback when something |
300 // is pending, a Flush callback could have come in before this callback was | 325 // is pending, a Flush callback could have come in before this callback was |
301 // executed and that could have cleared the queue. | 326 // executed and that could have cleared the queue. |
302 if (aggregator_.HasPendingUpdate()) | 327 if (aggregator_.HasPendingUpdate()) |
303 DoPaint(); | 328 DoPaint(); |
304 } | 329 } |
OLD | NEW |