Source/WebCore/ChangeLog

 12018-01-25 Said Abou-Hallawa <sabouhallawa@apple.com>
 2
 3 REGRESSION(r217236): [iOS] PDFDocumentImage does not update its cached ImageBuffer if it has a sub-rectangle of the image
 4 https://bugs.webkit.org/show_bug.cgi?id=182083
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Revert the change r217236 back and fix the issue of throwing the cached
 9 ImageBuffer of the PDF document because of moving its rectangle.
 10
 11 Test: fast/images/pdf-as-image-dest-rect-change.html
 12
 13 * platform/graphics/cg/PDFDocumentImage.cpp:
 14 (WebCore::PDFDocumentImage::cacheParametersMatch const):
 15 (WebCore::PDFDocumentImage::updateCachedImageIfNeeded):
 16 * platform/graphics/cg/PDFDocumentImage.h:
 17 * testing/Internals.cpp:
 18 (WebCore::pdfDocumentImageFromImageElement):
 19 (WebCore::Internals::pdfDocumentCachingCount):
 20 * testing/Internals.h:
 21 * testing/Internals.idl:
 22
1232018-01-25 Zan Dobersek <zdobersek@igalia.com>
224
325 [Cairo] Use GraphicsContextImplCairo in Nicosia::PaintingContextCairo
227610

Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp

@@bool PDFDocumentImage::cacheParametersMa
113113 if (srcRect != m_cachedSourceRect)
114114 return false;
115115
 116 if (dstRect != m_cachedImageRect && !m_cachedImageRect.contains(context.clipBounds()))
 117 return false;
 118
116119 AffineTransform::DecomposedType decomposedTransform;
117120 context.getCTM(GraphicsContext::DefinitelyIncludeDeviceScale).decompose(decomposedTransform);
118121

@@void PDFDocumentImage::updateCachedImage
201204 bool repaintIfNecessary = interpolationQuality != InterpolationNone && interpolationQuality != InterpolationLow;
202205#endif
203206
 207 // Clipped option is for testing only. Force recaching the PDF with each draw.
 208 if (m_pdfImageCachingPolicy != PDFImageCachingClipBoundsOnly) {
 209 // The whole dstRect is cached so it does not matter where it will be displayed.
 210 if (dstRect.size() == m_cachedImageRect.size())
 211 m_cachedImageRect = dstRect;
 212 if (m_cachedImageBuffer && (!repaintIfNecessary || cacheParametersMatch(context, dstRect, srcRect)))
 213 return;
 214 }
 215
204216 switch (m_pdfImageCachingPolicy) {
205217 case PDFImageCachingDisabled:
206218 return;

@@void PDFDocumentImage::updateCachedImage
217229 break;
218230 }
219231
220  // Clipped option is for testing only. Force recaching the PDF with each draw.
221  if (m_pdfImageCachingPolicy != PDFImageCachingClipBoundsOnly) {
222  if (m_cachedImageBuffer && (!repaintIfNecessary || cacheParametersMatch(context, dstRect, srcRect)))
223  return;
224  }
225 
226232 FloatSize cachedImageSize = FloatRect(enclosingIntRect(m_cachedImageRect)).size();
227233
228234 // Cache the PDF image only if the size of the new image won't exceed the cache threshold.

@@void PDFDocumentImage::updateCachedImage
250256 m_cachedTransform = context.getCTM(GraphicsContext::DefinitelyIncludeDeviceScale);
251257 m_cachedDestinationSize = dstRect.size();
252258 m_cachedSourceRect = srcRect;
 259 ++m_cachingCountForTesting;
253260
254261 IntSize internalSize = m_cachedImageBuffer->internalSize();
255262 decodedSizeChanged(internalSize.unclampedArea() * 4);
227422

Source/WebCore/platform/graphics/cg/PDFDocumentImage.h

@@public:
5959 WEBCORE_EXPORT static RetainPtr<CFMutableDataRef> convertPostScriptDataToPDF(RetainPtr<CFDataRef>&& postScriptData);
6060#endif
6161
 62 unsigned cachingCountForTesting() const { return m_cachingCountForTesting; }
 63
6264private:
6365 PDFDocumentImage(ImageObserver*);
6466 virtual ~PDFDocumentImage();

@@private:
106108 FloatSize m_cachedDestinationSize;
107109 FloatRect m_cachedSourceRect;
108110 size_t m_cachedBytes { 0 };
 111 unsigned m_cachingCountForTesting { 0 };
109112
110113 FloatRect m_cropBox;
111114 int m_rotationDegrees { 0 }; // Can only be 0, 90, 180, or 270 degrees.
227422

Source/WebCore/testing/Internals.cpp

104104#include "MockLibWebRTCPeerConnection.h"
105105#include "MockPageOverlay.h"
106106#include "MockPageOverlayClient.h"
 107#if USE(CG)
 108#include "PDFDocumentImage.h"
 109#endif
107110#include "Page.h"
108111#include "PageCache.h"
109112#include "PageOverlay.h"

@@static BitmapImage* bitmapImageFromImage
773776 return image && is<BitmapImage>(image) ? &downcast<BitmapImage>(*image) : nullptr;
774777}
775778
 779#if USE(CG)
 780static PDFDocumentImage* pdfDocumentImageFromImageElement(HTMLImageElement& element)
 781{
 782 auto* image = imageFromImageElement(element);
 783 return image && is<PDFDocumentImage>(image) ? &downcast<PDFDocumentImage>(*image) : nullptr;
 784}
 785#endif
 786
776787unsigned Internals::imageFrameIndex(HTMLImageElement& element)
777788{
778789 auto* bitmapImage = bitmapImageFromImageElement(element);

@@unsigned Internals::imageDecodeCount(HTM
809820 return bitmapImage ? bitmapImage->decodeCountForTesting() : 0;
810821}
811822
 823unsigned Internals::pdfDocumentCachingCount(HTMLImageElement& element)
 824{
 825#if USE(CG)
 826 auto* pdfDocumentImage = pdfDocumentImageFromImageElement(element);
 827 return pdfDocumentImage ? pdfDocumentImage->cachingCountForTesting() : 0;
 828#else
 829 UNUSED_PARAM(element);
 830 return 0;
 831#endif
 832}
 833
812834void Internals::setLargeImageAsyncDecodingEnabledForTesting(HTMLImageElement& element, bool enabled)
813835{
814836 if (auto* bitmapImage = bitmapImageFromImageElement(element))
227422

Source/WebCore/testing/Internals.h

@@public:
139139 bool isImageAnimating(HTMLImageElement&);
140140 void setClearDecoderAfterAsyncFrameRequestForTesting(HTMLImageElement&, bool enabled);
141141 unsigned imageDecodeCount(HTMLImageElement&);
 142 unsigned pdfDocumentCachingCount(HTMLImageElement&);
142143 void setLargeImageAsyncDecodingEnabledForTesting(HTMLImageElement&, bool enabled);
143144
144145 void setGridMaxTracksLimit(unsigned);
227422

Source/WebCore/testing/Internals.idl

@@enum EventThrottlingBehavior {
262262 boolean isImageAnimating(HTMLImageElement element);
263263 void setClearDecoderAfterAsyncFrameRequestForTesting(HTMLImageElement element, boolean enabled);
264264 unsigned long imageDecodeCount(HTMLImageElement element);
 265 unsigned long pdfDocumentCachingCount(HTMLImageElement element);
265266 void setLargeImageAsyncDecodingEnabledForTesting(HTMLImageElement element, boolean enabled);
266267
267268 void setGridMaxTracksLimit(unsigned long maxTracksLimit);
227422

LayoutTests/ChangeLog

 12018-01-25 Said Abou-Hallawa <sabouhallawa@apple.com>
 2
 3 REGRESSION(r217236): [iOS] PDFDocumentImage does not update its cached ImageBuffer if it has a sub-rectangle of the image
 4 https://bugs.webkit.org/show_bug.cgi?id=182083
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 PDFDocumentImage renders only on CG platforms. Also on Mac, caching the
 9 PDF drawing might be disbaled for low quality image interpolation context.
 10 So enable the new test for iOS only.
 11
 12 * TestExpectations:
 13 * fast/images/pdf-as-image-dest-rect-change-expected.txt: Added.
 14 * fast/images/pdf-as-image-dest-rect-change.html: Added.
 15 * platform/ios/TestExpectations:
 16
1172018-01-23 Andy Estes <aestes@apple.com>
218
319 Follow-up layout test fix after r227260.
227422

LayoutTests/TestExpectations

@@fast/attachment/attachment-borderless.ht
110110editing/selection/character-granularity-selected-range-after-dismissing-selection.html [ Skip ]
111111editing/selection/character-granularity-select-text-with-click-handler.html [ Skip ]
112112editing/selection/caret-after-tap-in-editable-selection.html [ Skip ]
 113fast/images/pdf-as-image-dest-rect-change.html [ Skip ]
113114
114115# Only iOS has selection UI drawn by UIKit
115116editing/selection/character-granularity-rect.html [ Skip ]
227422

LayoutTests/fast/images/pdf-as-image-dest-rect-change-expected.txt

 1Test the cached ImageBuffer of a PDF docoument image won't be thrown away if the image moves.
 2
 3On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 4
 5
 6PASS internals.pdfDocumentCachingCount(window.image) is 1
 7PASS successfullyParsed is true
 8
 9TEST COMPLETE
 10
nonexistent

LayoutTests/fast/images/pdf-as-image-dest-rect-change.html

 1<head>
 2 <style>
 3 img {
 4 width: 100px;
 5 height: 100px;
 6 position: absolute;
 7 top: 200px;
 8 }
 9 </style>
 10 <script src="../../resources/js-test-pre.js"></script>
 11</head>
 12<body>
 13 <img src="resources/annotation.pdf">
 14 <script>
 15 description("Test the cached ImageBuffer of a PDF docoument image won't be thrown away if the image moves.");
 16 jsTestIsAsync = true;
 17
 18 function moveImageLoop(image, stepDistance, stepCount) {
 19 var step = 0;
 20 function loop() {
 21 image.style.left = step * stepDistance + 'px';
 22 if (++step < stepCount) {
 23 requestAnimationFrame(loop);
 24 return;
 25 }
 26
 27 if (window.internals) {
 28 window.image = image;
 29 shouldBe("internals.pdfDocumentCachingCount(window.image)", "1");
 30 }
 31 finishJSTest();
 32 }
 33 loop();
 34 }
 35 moveImageLoop(document.querySelector("img"), 50, 10);
 36 </script>
 37 <script src="../../resources/js-test-post.js"></script>
 38</body>
nonexistent

LayoutTests/platform/ios/TestExpectations

@@media/video-seek-to-current-time.html [
27992799
28002800fast/attachment/attachment-wrapping-action.html [ Pass ]
28012801fast/attachment/attachment-borderless.html [ Pass ]
 2802fast/images/pdf-as-image-dest-rect-change.html [ Pass ]
28022803
28032804fast/events/page-visibility-iframe-move-test.html [ Skip ]
28042805
227422