[iOS] PDFDocumentImage should not create a cached image larger than 4M pixels
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Jun 2016 00:39:58 +0000 (00:39 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Jun 2016 00:39:58 +0000 (00:39 +0000)
commit922a25d5557b828d0b336e3ed72676a59f2645cd
tree04829dd9ca7870ff807b74212fd6daee4ae76800
parentd6c54e7335284024175a129e1865e52a41ce58ae
[iOS] PDFDocumentImage should not create a cached image larger than 4M pixels
https://bugs.webkit.org/show_bug.cgi?id=157857

Patch by Said Abou-Hallawa <sabouhallawa@apple,com> on 2016-06-02
Reviewed by Darin Adler.

Source/WebCore:

On iOS, if the scaled size of the PDFDocumentImage cached image will exceed
the 4M pixels limit and the system physical memory is 1GB or less, do not
create it. PDFDocumentImage::draw() falls back peacefully if the cached image
couldn't be created for any reason. The PDF will be drawn directly to the
GraphicsContext without having to go through the cached image. This means
the whole PDF will be drawn multiple times; one time for each tile. I think
this is okay for zooming a large PDFDocumentImage on a low end device.

* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::drawTextInternal): Call the static function
ImageBuffer::createCompatibleBuffer() without having to go through the GraphicsContext.

* platform/graphics/BitmapImage.cpp:
(WebCore::BitmapImage::drawPattern): Ditto.

* platform/graphics/FloatSize.h:
(WebCore::FloatSize::area): A helper function similar to IntSize::area().
(WebCore::operator*): Scale a FloatSize by another FloatSize and return the result.

* platform/graphics/GradientImage.cpp:
(WebCore::GradientImage::drawPattern): Call ImageBuffer::createCompatibleBuffer().

* platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::scaleFactor):: Return the scaling part of the current CTM.
(WebCore::scalesMatch): Deleted.
(WebCore::GraphicsContext::createCompatibleBuffer): Deleted.
(WebCore::GraphicsContext::isCompatibleWithBuffer): Deleted.
* platform/graphics/GraphicsContext.h:
Move these image buffer functions to ImageBuffer.

* platform/graphics/ImageBuffer.cpp:
(WebCore::ImageBuffer::createCompatibleBuffer): Make createCompatibleBuffer
a static function of the ImageBuffer. There is no need to go through the
GraphicsContext just to get the GraphicsContext scaleFactor.

(WebCore::ImageBuffer::compatibleBufferSize):  Scale the size of the cachedImage
by the scaleFactor of the context.

(WebCore::ImageBuffer::isCompatibleWithContext): Returns true if the drawing
context and the ImageBuffer context have the same scaleFactor.

* platform/graphics/ImageBuffer.h:

* platform/graphics/NamedImageGeneratedImage.cpp:
(WebCore::NamedImageGeneratedImage::drawPattern): Call ImageBuffer::createCompatibleBuffer().

* platform/graphics/cg/PDFDocumentImage.cpp:
(WebCore::PDFDocumentImage::updateCachedImageIfNeeded): On iOS, if the
physical memory is less than 1GB, do not allocate more than 16MB for the
PDF cachedImage.

* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::paintFillLayerExtended): Call ImageBuffer::createCompatibleBuffer().
* rendering/svg/SVGRenderingContext.cpp:
(WebCore::SVGRenderingContext::bufferForeground): Ditto.

Source/WTF:

* wtf/StdLibExtras.h: Add a constant value for GB (2^30).

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@201629 268f45cc-cd09-0410-ab3c-d52691b4dbfc
15 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/StdLibExtras.h
Source/WebCore/ChangeLog
Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
Source/WebCore/platform/graphics/BitmapImage.cpp
Source/WebCore/platform/graphics/FloatSize.h
Source/WebCore/platform/graphics/GradientImage.cpp
Source/WebCore/platform/graphics/GraphicsContext.cpp
Source/WebCore/platform/graphics/GraphicsContext.h
Source/WebCore/platform/graphics/ImageBuffer.cpp
Source/WebCore/platform/graphics/ImageBuffer.h
Source/WebCore/platform/graphics/NamedImageGeneratedImage.cpp
Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp
Source/WebCore/rendering/RenderBoxModelObject.cpp
Source/WebCore/rendering/svg/SVGRenderingContext.cpp