| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 // You can not use a NULL client pointer. | 34 // You can not use a NULL client pointer. |
| 35 DCHECK(client); | 35 DCHECK(client); |
| 36 } | 36 } |
| 37 | 37 |
| 38 PaintManager::~PaintManager() { | 38 PaintManager::~PaintManager() { |
| 39 } | 39 } |
| 40 | 40 |
| 41 // static | 41 // static |
| 42 pp::Size PaintManager::GetNewContextSize(const pp::Size& current_context_size, | 42 pp::Size PaintManager::GetNewContextSize(const pp::Size& current_context_size, |
| 43 const pp::Size& plugin_size) { | 43 const pp::Size& plugin_size) { |
| 44 // The number of additional space in pixels to allocate to the right/bottom | 44 // The amount of additional space in pixels to allocate to the right/bottom of |
| 45 // of the context. | 45 // the context. |
| 46 const int kBufferSize = 100; | 46 const int kBufferSize = 50; |
| 47 | 47 |
| 48 // Default to returning the same size. | 48 // Default to returning the same size. |
| 49 pp::Size result = current_context_size; | 49 pp::Size result = current_context_size; |
| 50 | 50 |
| 51 pp::Size min_size(std::max(current_context_size.width() - kBufferSize, 0), | 51 // The minimum size of the plugin before resizing the context to ensure we |
| 52 std::max(current_context_size.height() - kBufferSize, 0)); | 52 // aren't wasting too much memory. We deduct twice the kBufferSize from the |
| 53 // current context size which gives a threshhold that is kBufferSize below |
| 54 // the plugin size when the context size was last computed. |
| 55 pp::Size min_size( |
| 56 std::max(current_context_size.width() - 2 * kBufferSize, 0), |
| 57 std::max(current_context_size.height() - 2 * kBufferSize, 0)); |
| 58 |
| 53 // If the plugin size is bigger than the current context size, we need to | 59 // If the plugin size is bigger than the current context size, we need to |
| 54 // resize the context. If the plugin size is smaller than the current | 60 // resize the context. If the plugin size is smaller than the current |
| 55 // context size by a given threshhold then resize the context so that we | 61 // context size by a given threshhold then resize the context so that we |
| 56 // aren't wasting too much memory. | 62 // aren't wasting too much memory. |
| 57 if (plugin_size.width() > current_context_size.width() || | 63 if (plugin_size.width() > current_context_size.width() || |
| 58 plugin_size.height() > current_context_size.height() || | 64 plugin_size.height() > current_context_size.height() || |
| 59 plugin_size.width() < min_size.width() || | 65 plugin_size.width() < min_size.width() || |
| 60 plugin_size.height() < min_size.height()) { | 66 plugin_size.height() < min_size.height()) { |
| 61 // Create a larger context than needed so that if we only resize by a | 67 // Create a larger context than needed so that if we only resize by a |
| 62 // small margin, we don't need a new context. | 68 // small margin, we don't need a new context. |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 DCHECK(manual_callback_pending_); | 293 DCHECK(manual_callback_pending_); |
| 288 manual_callback_pending_ = false; | 294 manual_callback_pending_ = false; |
| 289 | 295 |
| 290 // Just because we have a manual callback doesn't mean there are actually any | 296 // Just because we have a manual callback doesn't mean there are actually any |
| 291 // invalid regions. Even though we only schedule this callback when something | 297 // invalid regions. Even though we only schedule this callback when something |
| 292 // is pending, a Flush callback could have come in before this callback was | 298 // is pending, a Flush callback could have come in before this callback was |
| 293 // executed and that could have cleared the queue. | 299 // executed and that could have cleared the queue. |
| 294 if (aggregator_.HasPendingUpdate()) | 300 if (aggregator_.HasPendingUpdate()) |
| 295 DoPaint(); | 301 DoPaint(); |
| 296 } | 302 } |
| OLD | NEW |