| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
| 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 WebGLRenderingContext* ctx = static_cast<WebGLRenderingContext*>(m_context.g
et()); | 364 WebGLRenderingContext* ctx = static_cast<WebGLRenderingContext*>(m_context.g
et()); |
| 365 | 365 |
| 366 return ctx->paintRenderingResultsToImageData(); | 366 return ctx->paintRenderingResultsToImageData(); |
| 367 #else | 367 #else |
| 368 return 0; | 368 return 0; |
| 369 #endif | 369 #endif |
| 370 } | 370 } |
| 371 | 371 |
| 372 IntRect HTMLCanvasElement::convertLogicalToDevice(const FloatRect& logicalRect)
const | 372 IntRect HTMLCanvasElement::convertLogicalToDevice(const FloatRect& logicalRect)
const |
| 373 { | 373 { |
| 374 float left = floorf(logicalRect.x() * m_pageScaleFactor); | 374 // Prevent under/overflow by ensuring the rect's bounds stay within integer-
expressible range |
| 375 float top = floorf(logicalRect.y() * m_pageScaleFactor); | 375 int left = clampToInteger(floorf(logicalRect.x() * m_pageScaleFactor)); |
| 376 float right = ceilf(logicalRect.maxX() * m_pageScaleFactor); | 376 int top = clampToInteger(floorf(logicalRect.y() * m_pageScaleFactor)); |
| 377 float bottom = ceilf(logicalRect.maxY() * m_pageScaleFactor); | 377 int right = clampToInteger(ceilf(logicalRect.maxX() * m_pageScaleFactor)); |
| 378 | 378 int bottom = clampToInteger(ceilf(logicalRect.maxY() * m_pageScaleFactor)); |
| 379 |
| 379 return IntRect(IntPoint(left, top), convertToValidDeviceSize(right - left, b
ottom - top)); | 380 return IntRect(IntPoint(left, top), convertToValidDeviceSize(right - left, b
ottom - top)); |
| 380 } | 381 } |
| 381 | 382 |
| 382 IntSize HTMLCanvasElement::convertLogicalToDevice(const FloatSize& logicalSize)
const | 383 IntSize HTMLCanvasElement::convertLogicalToDevice(const FloatSize& logicalSize)
const |
| 383 { | 384 { |
| 384 return convertToValidDeviceSize(logicalSize.width() * m_pageScaleFactor, log
icalSize.height() * m_pageScaleFactor); | 385 // Prevent overflow by ensuring the rect's bounds stay within integer-expres
sible range |
| 386 float width = clampToInteger(ceilf(logicalSize.width() * m_pageScaleFactor))
; |
| 387 float height = clampToInteger(ceilf(logicalSize.height() * m_pageScaleFactor
)); |
| 388 return convertToValidDeviceSize(width, height); |
| 385 } | 389 } |
| 386 | 390 |
| 387 IntSize HTMLCanvasElement::convertToValidDeviceSize(float width, float height) c
onst | 391 IntSize HTMLCanvasElement::convertToValidDeviceSize(float width, float height) c
onst |
| 388 { | 392 { |
| 389 width = ceilf(width); | 393 width = ceilf(width); |
| 390 height = ceilf(height); | 394 height = ceilf(height); |
| 391 | 395 |
| 392 if (width < 1 || height < 1 || width * height > MaxCanvasArea) | 396 if (width < 1 || height < 1 || width * height > MaxCanvasArea) |
| 393 return IntSize(); | 397 return IntSize(); |
| 394 | 398 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 ASSERT(m_hasCreatedImageBuffer); | 479 ASSERT(m_hasCreatedImageBuffer); |
| 476 FloatSize unscaledSize(width(), height()); | 480 FloatSize unscaledSize(width(), height()); |
| 477 IntSize size = convertLogicalToDevice(unscaledSize); | 481 IntSize size = convertLogicalToDevice(unscaledSize); |
| 478 AffineTransform transform; | 482 AffineTransform transform; |
| 479 if (size.width() && size.height()) | 483 if (size.width() && size.height()) |
| 480 transform.scaleNonUniform(size.width() / unscaledSize.width(), size.heig
ht() / unscaledSize.height()); | 484 transform.scaleNonUniform(size.width() / unscaledSize.width(), size.heig
ht() / unscaledSize.height()); |
| 481 return m_imageBuffer->baseTransform() * transform; | 485 return m_imageBuffer->baseTransform() * transform; |
| 482 } | 486 } |
| 483 | 487 |
| 484 } | 488 } |
| OLD | NEW |