| 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 30 matching lines...) Expand all Loading... |
| 41 first_paint_(true), | 41 first_paint_(true), |
| 42 view_size_changed_waiting_for_paint_(false) { | 42 view_size_changed_waiting_for_paint_(false) { |
| 43 // 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 |
| 44 // compiler warning about using "this" in an initializer list. | 44 // compiler warning about using "this" in an initializer list. |
| 45 callback_factory_.Initialize(this); | 45 callback_factory_.Initialize(this); |
| 46 | 46 |
| 47 // You can not use a NULL client pointer. | 47 // You can not use a NULL client pointer. |
| 48 DCHECK(client); | 48 DCHECK(client); |
| 49 } | 49 } |
| 50 | 50 |
| 51 PaintManager::~PaintManager() { | 51 PaintManager::~PaintManager() {} |
| 52 } | |
| 53 | 52 |
| 54 // static | 53 // static |
| 55 pp::Size PaintManager::GetNewContextSize(const pp::Size& current_context_size, | 54 pp::Size PaintManager::GetNewContextSize(const pp::Size& current_context_size, |
| 56 const pp::Size& plugin_size) { | 55 const pp::Size& plugin_size) { |
| 57 // The amount of additional space in pixels to allocate to the right/bottom of | 56 // The amount of additional space in pixels to allocate to the right/bottom of |
| 58 // the context. | 57 // the context. |
| 59 const int kBufferSize = 50; | 58 const int kBufferSize = 50; |
| 60 | 59 |
| 61 // Default to returning the same size. | 60 // Default to returning the same size. |
| 62 pp::Size result = current_context_size; | 61 pp::Size result = current_context_size; |
| 63 | 62 |
| 64 // The minimum size of the plugin before resizing the context to ensure we | 63 // The minimum size of the plugin before resizing the context to ensure we |
| 65 // aren't wasting too much memory. We deduct twice the kBufferSize from the | 64 // aren't wasting too much memory. We deduct twice the kBufferSize from the |
| 66 // current context size which gives a threshhold that is kBufferSize below | 65 // current context size which gives a threshhold that is kBufferSize below |
| 67 // the plugin size when the context size was last computed. | 66 // the plugin size when the context size was last computed. |
| 68 pp::Size min_size( | 67 pp::Size min_size( |
| 69 std::max(current_context_size.width() - 2 * kBufferSize, 0), | 68 std::max(current_context_size.width() - 2 * kBufferSize, 0), |
| 70 std::max(current_context_size.height() - 2 * kBufferSize, 0)); | 69 std::max(current_context_size.height() - 2 * kBufferSize, 0)); |
| 71 | 70 |
| 72 // If the plugin size is bigger than the current context size, we need to | 71 // If the plugin size is bigger than the current context size, we need to |
| 73 // resize the context. If the plugin size is smaller than the current | 72 // resize the context. If the plugin size is smaller than the current |
| 74 // context size by a given threshhold then resize the context so that we | 73 // context size by a given threshhold then resize the context so that we |
| 75 // aren't wasting too much memory. | 74 // aren't wasting too much memory. |
| 76 if (plugin_size.width() > current_context_size.width() || | 75 if (plugin_size.width() > current_context_size.width() || |
| 77 plugin_size.height() > current_context_size.height() || | 76 plugin_size.height() > current_context_size.height() || |
| 78 plugin_size.width() < min_size.width() || | 77 plugin_size.width() < min_size.width() || |
| 79 plugin_size.height() < min_size.height()) { | 78 plugin_size.height() < min_size.height()) { |
| 80 // Create a larger context than needed so that if we only resize by a | 79 // Create a larger context than needed so that if we only resize by a |
| 81 // small margin, we don't need a new context. | 80 // small margin, we don't need a new context. |
| 82 result = pp::Size(plugin_size.width() + kBufferSize, | 81 result = pp::Size(plugin_size.width() + kBufferSize, |
| 83 plugin_size.height() + kBufferSize); | 82 plugin_size.height() + kBufferSize); |
| 84 } | 83 } |
| 85 | 84 |
| 86 return result; | 85 return result; |
| 87 } | 86 } |
| 88 | 87 |
| 89 void PaintManager::Initialize(pp::Instance* instance, | 88 void PaintManager::Initialize(pp::Instance* instance, |
| 90 Client* client, | 89 Client* client, |
| 91 bool is_always_opaque) { | 90 bool is_always_opaque) { |
| 92 DCHECK(!instance_ && !client_); // Can't initialize twice. | 91 DCHECK(!instance_ && !client_); // Can't initialize twice. |
| 93 instance_ = instance; | 92 instance_ = instance; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 // don't have to do anything differently now. | 180 // don't have to do anything differently now. |
| 182 if (flush_pending_) | 181 if (flush_pending_) |
| 183 return; | 182 return; |
| 184 | 183 |
| 185 // If no flush is pending, we need to do a manual call to get back to the | 184 // If no flush is pending, we need to do a manual call to get back to the |
| 186 // main thread. We may have one already pending, or we may need to schedule. | 185 // main thread. We may have one already pending, or we may need to schedule. |
| 187 if (manual_callback_pending_) | 186 if (manual_callback_pending_) |
| 188 return; | 187 return; |
| 189 | 188 |
| 190 pp::Module::Get()->core()->CallOnMainThread( | 189 pp::Module::Get()->core()->CallOnMainThread( |
| 191 0, | 190 0, callback_factory_.NewCallback(&PaintManager::OnManualCallbackComplete), |
| 192 callback_factory_.NewCallback(&PaintManager::OnManualCallbackComplete), | |
| 193 0); | 191 0); |
| 194 manual_callback_pending_ = true; | 192 manual_callback_pending_ = true; |
| 195 } | 193 } |
| 196 | 194 |
| 197 void PaintManager::DoPaint() { | 195 void PaintManager::DoPaint() { |
| 198 in_paint_ = true; | 196 in_paint_ = true; |
| 199 | 197 |
| 200 std::vector<ReadyRect> ready_rects; | 198 std::vector<ReadyRect> ready_rects; |
| 201 std::vector<pp::Rect> pending_rects; | 199 std::vector<pp::Rect> pending_rects; |
| 202 | 200 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 aggregator_.SetIntermediateResults(ready_later, pending_rects); | 272 aggregator_.SetIntermediateResults(ready_later, pending_rects); |
| 275 | 273 |
| 276 if (ready_now.empty()) { | 274 if (ready_now.empty()) { |
| 277 in_paint_ = false; | 275 in_paint_ = false; |
| 278 EnsureCallbackPending(); | 276 EnsureCallbackPending(); |
| 279 return; | 277 return; |
| 280 } | 278 } |
| 281 } | 279 } |
| 282 | 280 |
| 283 for (const auto& ready_rect : ready_now) { | 281 for (const auto& ready_rect : ready_now) { |
| 284 graphics_.PaintImageData( | 282 graphics_.PaintImageData(ready_rect.image_data, ready_rect.offset, |
| 285 ready_rect.image_data, ready_rect.offset, ready_rect.rect); | 283 ready_rect.rect); |
| 286 } | 284 } |
| 287 | 285 |
| 288 Flush(); | 286 Flush(); |
| 289 | 287 |
| 290 in_paint_ = false; | 288 in_paint_ = false; |
| 291 first_paint_ = false; | 289 first_paint_ = false; |
| 292 | 290 |
| 293 if (graphics_need_to_be_bound_) { | 291 if (graphics_need_to_be_bound_) { |
| 294 instance_->BindGraphics(graphics_); | 292 instance_->BindGraphics(graphics_); |
| 295 graphics_need_to_be_bound_ = false; | 293 graphics_need_to_be_bound_ = false; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 DCHECK(manual_callback_pending_); | 337 DCHECK(manual_callback_pending_); |
| 340 manual_callback_pending_ = false; | 338 manual_callback_pending_ = false; |
| 341 | 339 |
| 342 // Just because we have a manual callback doesn't mean there are actually any | 340 // Just because we have a manual callback doesn't mean there are actually any |
| 343 // invalid regions. Even though we only schedule this callback when something | 341 // invalid regions. Even though we only schedule this callback when something |
| 344 // is pending, a Flush callback could have come in before this callback was | 342 // is pending, a Flush callback could have come in before this callback was |
| 345 // executed and that could have cleared the queue. | 343 // executed and that could have cleared the queue. |
| 346 if (aggregator_.HasPendingUpdate()) | 344 if (aggregator_.HasPendingUpdate()) |
| 347 DoPaint(); | 345 DoPaint(); |
| 348 } | 346 } |
| OLD | NEW |