0

Fix min threshhold calculation for resizing the PDF graphics context

This fixes the calculation for the threshhold we use to calculate
whether the graphics context needs to be resized. There isn't a
correctness issue here, as the context will always be large enough
but it results in resizing more than necessary.

This example demonstrates the issue:
-If the plugin size was 100 x 100, we would set the context size to
100+kBufferSize x 100+kBufferSize.
-If the plugin was then resized to 90x90 we would check to see if the plugin
size is smaller than (100+kBufferSize)-kBufferSize x (100+kBufferSize)-kBufferSize
which is equal to 100 x 100.
-But we really intend to check whether it is smaller than
100-kBufferSize x 100-kBufferSize

Thus we should check whether the plugin is smaller than the
(current context size) - 2*kBufferSize which is kBufferSize less than
the plugin size when the context size was last computed.

BUG=303491

Review URL: https://codereview.chromium.org/337443002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277387 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
raymes@chromium.org
2014-06-16 08:35:44 +00:00
parent 1a7d89c673
commit cdd5491a7f

@ -41,15 +41,21 @@ PaintManager::~PaintManager() {
// static
pp::Size PaintManager::GetNewContextSize(const pp::Size& current_context_size,
const pp::Size& plugin_size) {
// The number of additional space in pixels to allocate to the right/bottom
// of the context.
const int kBufferSize = 100;
// The amount of additional space in pixels to allocate to the right/bottom of
// the context.
const int kBufferSize = 50;
// Default to returning the same size.
pp::Size result = current_context_size;
pp::Size min_size(std::max(current_context_size.width() - kBufferSize, 0),
std::max(current_context_size.height() - kBufferSize, 0));
// The minimum size of the plugin before resizing the context to ensure we
// aren't wasting too much memory. We deduct twice the kBufferSize from the
// current context size which gives a threshhold that is kBufferSize below
// the plugin size when the context size was last computed.
pp::Size min_size(
std::max(current_context_size.width() - 2 * kBufferSize, 0),
std::max(current_context_size.height() - 2 * kBufferSize, 0));
// If the plugin size is bigger than the current context size, we need to
// resize the context. If the plugin size is smaller than the current
// context size by a given threshhold then resize the context so that we