Remove ImageBuffer::sizeForDestinationSize()
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Jan 2020 21:32:11 +0000 (21:32 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Jan 2020 21:32:11 +0000 (21:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=206541

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2020-01-22
Reviewed by Tim Horton.

-- Remove ImageBuffer::sizeForDestinationSize() since it is currently
   doing nothing. For CG and D2D ports, it scales a rect by the ratio
   backingStoreSize / internalSize which is always 1. The constructor
   ImageBuffer::ImageBuffer() sets m_size and m_data.backingStoreSize
   to the same value always.

-- Remove ImageBuffer::isCompatibleWithContext() since it is not used.

-- Remove ImageBuffer::fastCopyImageMode() since it returns
   DontCopyBackingStore on all ports.

* html/CustomPaintCanvas.cpp:
(WebCore::CustomPaintCanvas::copiedImage const):
* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::texSubImage2D):
(WebCore::WebGLRenderingContextBase::texImage2D):
(WebCore::WebGLRenderingContextBase::drawImageIntoBuffer):
* platform/graphics/ImageBuffer.cpp:
(WebCore::ImageBuffer::sizeForDestinationSize const): Deleted.
(WebCore::ImageBuffer::isCompatibleWithContext const): Deleted.
* platform/graphics/ImageBuffer.h:
(WebCore::ImageBuffer::logicalSize const):
* platform/graphics/cairo/ImageBufferCairo.cpp:
(WebCore::ImageBuffer::fastCopyImageMode): Deleted.
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::clipToImageBuffer):
* platform/graphics/cg/ImageBufferCG.cpp:
(WebCore::ImageBuffer::ImageBuffer):
(WebCore::createBitmapImageAfterScalingIfNeeded):
(WebCore::ImageBuffer::copyImage const):
(WebCore::ImageBuffer::sinkIntoImage):
(WebCore::ImageBuffer::toCFData const):
(WebCore::scaleSizeToUserSpace): Deleted.
(WebCore::ImageBuffer::sizeForDestinationSize const): Deleted.
(WebCore::ImageBuffer::fastCopyImageMode): Deleted.
* platform/graphics/win/ImageBufferDirect2D.cpp:
(WebCore::scaleSizeToUserSpace): Deleted.
(WebCore::ImageBuffer::sizeForDestinationSize const): Deleted.
(WebCore::ImageBuffer::fastCopyImageMode): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254941 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/html/CustomPaintCanvas.cpp
Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
Source/WebCore/platform/graphics/ImageBuffer.cpp
Source/WebCore/platform/graphics/ImageBuffer.h
Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp
Source/WebCore/platform/graphics/win/ImageBufferDirect2D.cpp

index f1168e5..c1e7ce6 100644 (file)
@@ -1,3 +1,50 @@
+2020-01-22  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        Remove ImageBuffer::sizeForDestinationSize()
+        https://bugs.webkit.org/show_bug.cgi?id=206541
+
+        Reviewed by Tim Horton.
+
+        -- Remove ImageBuffer::sizeForDestinationSize() since it is currently
+           doing nothing. For CG and D2D ports, it scales a rect by the ratio
+           backingStoreSize / internalSize which is always 1. The constructor
+           ImageBuffer::ImageBuffer() sets m_size and m_data.backingStoreSize
+           to the same value always.
+
+        -- Remove ImageBuffer::isCompatibleWithContext() since it is not used.
+
+        -- Remove ImageBuffer::fastCopyImageMode() since it returns 
+           DontCopyBackingStore on all ports.
+
+        * html/CustomPaintCanvas.cpp:
+        (WebCore::CustomPaintCanvas::copiedImage const):
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::texSubImage2D):
+        (WebCore::WebGLRenderingContextBase::texImage2D):
+        (WebCore::WebGLRenderingContextBase::drawImageIntoBuffer):
+        * platform/graphics/ImageBuffer.cpp:
+        (WebCore::ImageBuffer::sizeForDestinationSize const): Deleted.
+        (WebCore::ImageBuffer::isCompatibleWithContext const): Deleted.
+        * platform/graphics/ImageBuffer.h:
+        (WebCore::ImageBuffer::logicalSize const):
+        * platform/graphics/cairo/ImageBufferCairo.cpp:
+        (WebCore::ImageBuffer::fastCopyImageMode): Deleted.
+        * platform/graphics/cg/GraphicsContextCG.cpp:
+        (WebCore::GraphicsContext::clipToImageBuffer):
+        * platform/graphics/cg/ImageBufferCG.cpp:
+        (WebCore::ImageBuffer::ImageBuffer):
+        (WebCore::createBitmapImageAfterScalingIfNeeded):
+        (WebCore::ImageBuffer::copyImage const):
+        (WebCore::ImageBuffer::sinkIntoImage):
+        (WebCore::ImageBuffer::toCFData const):
+        (WebCore::scaleSizeToUserSpace): Deleted.
+        (WebCore::ImageBuffer::sizeForDestinationSize const): Deleted.
+        (WebCore::ImageBuffer::fastCopyImageMode): Deleted.
+        * platform/graphics/win/ImageBufferDirect2D.cpp:
+        (WebCore::scaleSizeToUserSpace): Deleted.
+        (WebCore::ImageBuffer::sizeForDestinationSize const): Deleted.
+        (WebCore::ImageBuffer::fastCopyImageMode): Deleted.
+
 2020-01-22  Zalan Bujtas  <zalan@apple.com>
 
         [LFC] Do not create a FormattingContext to compute intrinsic width unless there's some content.
index 147762f..9205a98 100644 (file)
@@ -102,7 +102,7 @@ Image* CustomPaintCanvas::copiedImage() const
         m_context->paintRenderingResultsToCanvas();
     m_destinationGraphicsContext = nullptr;
 
-    m_copiedImage = m_copiedBuffer->copyImage(m_copiedBuffer->fastCopyImageMode(), PreserveResolution::Yes);
+    m_copiedImage = m_copiedBuffer->copyImage(DontCopyBackingStore, PreserveResolution::Yes);
     return m_copiedImage.get();
 }
 
index 4288216..0efa4b4 100644 (file)
@@ -3982,7 +3982,7 @@ ExceptionOr<void> WebGLRenderingContextBase::texSubImage2D(GCGLenum target, GCGL
         if (!buffer)
             return { };
 
-        RefPtr<Image> image = buffer->copyImage(ImageBuffer::fastCopyImageMode());
+        RefPtr<Image> image = buffer->copyImage(DontCopyBackingStore);
         if (image)
             texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get(), GraphicsContextGL::DOMSource::Image, m_unpackFlipY, m_unpackPremultiplyAlpha);
         return { };
@@ -4104,7 +4104,7 @@ ExceptionOr<void> WebGLRenderingContextBase::texSubImage2D(GCGLenum target, GCGL
         if (!validateTexFunc("texSubImage2D", TexSubImage, SourceHTMLVideoElement, target, level, internalFormat, video->videoWidth(), video->videoHeight(), 0, format, type, xoffset, yoffset))
             return { };
 
-        RefPtr<Image> image = videoFrameToImage(video.get(), ImageBuffer::fastCopyImageMode());
+        RefPtr<Image> image = videoFrameToImage(video.get(), DontCopyBackingStore);
         if (!image)
             return { };
         texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get(), GraphicsContextGL::DOMSource::Video, m_unpackFlipY, m_unpackPremultiplyAlpha);
@@ -4551,7 +4551,7 @@ ExceptionOr<void> WebGLRenderingContextBase::texImage2D(GCGLenum target, GCGLint
         }
 
         // Normal pure SW path.
-        RefPtr<Image> image = buffer->copyImage(ImageBuffer::fastCopyImageMode());
+        RefPtr<Image> image = buffer->copyImage(DontCopyBackingStore);
         if (image)
             texImage2DImpl(target, level, internalformat, format, type, image.get(), GraphicsContextGL::DOMSource::Image, m_unpackFlipY, m_unpackPremultiplyAlpha);
         return { };
@@ -4665,7 +4665,7 @@ ExceptionOr<void> WebGLRenderingContextBase::texImage2D(GCGLenum target, GCGLint
         }
 
         // Normal pure SW path.
-        RefPtr<Image> image = videoFrameToImage(video.get(), ImageBuffer::fastCopyImageMode());
+        RefPtr<Image> image = videoFrameToImage(video.get(), DontCopyBackingStore);
         if (!image)
             return { };
         texImage2DImpl(target, level, internalformat, format, type, image.get(), GraphicsContextGL::DOMSource::Video, m_unpackFlipY, m_unpackPremultiplyAlpha);
@@ -4690,7 +4690,7 @@ RefPtr<Image> WebGLRenderingContextBase::drawImageIntoBuffer(Image& image, int w
     FloatRect srcRect(FloatPoint(), image.size());
     FloatRect destRect(FloatPoint(), size);
     buf->context().drawImage(image, destRect, srcRect);
-    return buf->copyImage(ImageBuffer::fastCopyImageMode());
+    return buf->copyImage(DontCopyBackingStore);
 }
 
 #if ENABLE(VIDEO)
index c012637..20b9810 100644 (file)
@@ -114,12 +114,6 @@ Vector<uint8_t> ImageBuffer::toBGRAData() const
 #endif
 
 #if !(USE(CG) || USE(DIRECT2D))
-
-FloatSize ImageBuffer::sizeForDestinationSize(FloatSize size) const
-{
-    return size;
-}
-
 void ImageBuffer::transformColorSpace(ColorSpace srcColorSpace, ColorSpace dstColorSpace)
 {
     if (srcColorSpace == dstColorSpace)
@@ -244,11 +238,6 @@ IntSize ImageBuffer::compatibleBufferSize(const FloatSize& size, const GraphicsC
     return expandedIntSize(size * context.scaleFactor());
 }
 
-bool ImageBuffer::isCompatibleWithContext(const GraphicsContext& context) const
-{
-    return areEssentiallyEqual(context.scaleFactor(), this->context().scaleFactor());
-}
-
 #if !USE(IOSURFACE_CANVAS_BACKING_STORE)
 size_t ImageBuffer::memoryCost() const
 {
index 26df7cd..7b772a2 100644 (file)
@@ -85,25 +85,18 @@ public:
     static std::unique_ptr<ImageBuffer> createCompatibleBuffer(const FloatSize&, float resolutionScale, ColorSpace, const GraphicsContext&);
 
     static IntSize compatibleBufferSize(const FloatSize&, const GraphicsContext&);
-    bool isCompatibleWithContext(const GraphicsContext&) const;
 
     WEBCORE_EXPORT ~ImageBuffer();
 
     // The actual resolution of the backing store
     const IntSize& internalSize() const { return m_size; }
     const IntSize& logicalSize() const { return m_logicalSize; }
-
-    FloatSize sizeForDestinationSize(FloatSize) const;
-
     float resolutionScale() const { return m_resolutionScale; }
 
     WEBCORE_EXPORT GraphicsContext& context() const;
 
     WEBCORE_EXPORT RefPtr<Image> copyImage(BackingStoreCopy = CopyBackingStore, PreserveResolution = PreserveResolution::No) const;
     WEBCORE_EXPORT static RefPtr<Image> sinkIntoImage(std::unique_ptr<ImageBuffer>, PreserveResolution = PreserveResolution::No);
-    // Give hints on the faster copyImage Mode, return DontCopyBackingStore if it supports the DontCopyBackingStore behavior
-    // or return CopyBackingStore if it doesn't.  
-    static BackingStoreCopy fastCopyImageMode();
 
     enum CoordinateSystem { LogicalCoordinateSystem, BackingStoreCoordinateSystem };
 
index 91c0a1a..bbb5c64 100644 (file)
@@ -351,11 +351,6 @@ RefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyBehavior, PreserveReso
     return BitmapImage::create(RefPtr<cairo_surface_t>(m_data.m_surface));
 }
 
-BackingStoreCopy ImageBuffer::fastCopyImageMode()
-{
-    return DontCopyBackingStore;
-}
-
 void ImageBuffer::drawConsuming(std::unique_ptr<ImageBuffer> imageBuffer, GraphicsContext& destContext, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options)
 {
     imageBuffer->draw(destContext, destRect, srcRect, options);
index fa991ad..c54b0b9 100644 (file)
@@ -512,7 +512,7 @@ void GraphicsContext::clipToImageBuffer(ImageBuffer& buffer, const FloatRect& de
     if (paintingDisabled())
         return;
 
-    FloatSize bufferDestinationSize = buffer.sizeForDestinationSize(destRect.size());
+    FloatSize bufferDestinationSize = destRect.size();
     RetainPtr<CGImageRef> image = buffer.copyNativeImage(DontCopyBackingStore);
 
     CGContextRef context = platformContext();
index 068b725..afd5e4e 100644 (file)
@@ -66,13 +66,6 @@ namespace WebCore {
 DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(ImageBuffer);
 DEFINE_ALLOCATOR_WITH_HEAP_IDENTIFIER(ImageBuffer);
 
-static FloatSize scaleSizeToUserSpace(const FloatSize& logicalSize, const IntSize& backingStoreSize, const IntSize& internalSize)
-{
-    float xMagnification = static_cast<float>(backingStoreSize.width()) / internalSize.width();
-    float yMagnification = static_cast<float>(backingStoreSize.height()) / internalSize.height();
-    return FloatSize(logicalSize.width() * xMagnification, logicalSize.height() * yMagnification);
-}
-
 std::unique_ptr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const FloatSize& size, const GraphicsContext& context)
 {
     if (size.isEmpty())
@@ -155,7 +148,7 @@ ImageBuffer::ImageBuffer(const FloatSize& size, float resolutionScale, CGColorSp
     RetainPtr<CGContextRef> cgContext;
     if (accelerateRendering) {
 #if USE(IOSURFACE_CANVAS_BACKING_STORE)
-        FloatSize userBounds = sizeForDestinationSize(FloatSize(width.unsafeGet(), height.unsafeGet()));
+        FloatSize userBounds = FloatSize(width.unsafeGet(), height.unsafeGet());
         m_data.surface = IOSurface::create(m_data.backingStoreSize, IntSize(userBounds), colorSpace);
         if (m_data.surface) {
             cgContext = m_data.surface->ensurePlatformContext(hostWindow);
@@ -210,11 +203,6 @@ ImageBuffer::ImageBuffer(const FloatSize& size, float resolutionScale, ColorSpac
 
 ImageBuffer::~ImageBuffer() = default;
 
-FloatSize ImageBuffer::sizeForDestinationSize(FloatSize destinationSize) const
-{
-    return scaleSizeToUserSpace(destinationSize, m_data.backingStoreSize, internalSize());
-}
-
 #if USE(IOSURFACE_CANVAS_BACKING_STORE)
 size_t ImageBuffer::memoryCost() const
 {
@@ -259,7 +247,7 @@ static RetainPtr<CGImageRef> createCroppedImageIfNecessary(CGImageRef image, con
     return image;
 }
 
-static RefPtr<Image> createBitmapImageAfterScalingIfNeeded(RetainPtr<CGImageRef>&& image, IntSize internalSize, IntSize logicalSize, IntSize backingStoreSize, float resolutionScale, PreserveResolution preserveResolution)
+static RefPtr<Image> createBitmapImageAfterScalingIfNeeded(RetainPtr<CGImageRef>&& image, IntSize logicalSize, IntSize internalSize, float resolutionScale, PreserveResolution preserveResolution)
 {
     if (resolutionScale == 1 || preserveResolution == PreserveResolution::Yes)
         image = createCroppedImageIfNecessary(image.get(), internalSize);
@@ -267,7 +255,7 @@ static RefPtr<Image> createBitmapImageAfterScalingIfNeeded(RetainPtr<CGImageRef>
         auto context = adoptCF(CGBitmapContextCreate(0, logicalSize.width(), logicalSize.height(), 8, 4 * logicalSize.width(), sRGBColorSpaceRef(), kCGImageAlphaPremultipliedLast));
         CGContextSetBlendMode(context.get(), kCGBlendModeCopy);
         CGContextClipToRect(context.get(), FloatRect(FloatPoint::zero(), logicalSize));
-        FloatSize imageSizeInUserSpace = scaleSizeToUserSpace(logicalSize, backingStoreSize, internalSize);
+        FloatSize imageSizeInUserSpace = logicalSize;
         CGContextDrawImage(context.get(), FloatRect(FloatPoint::zero(), imageSizeInUserSpace), image.get());
         image = adoptCF(CGBitmapContextCreateImage(context.get()));
     }
@@ -286,22 +274,16 @@ RefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyBehavior, PreserveReso
     else
         image = copyNativeImage(DontCopyBackingStore);
 
-    return createBitmapImageAfterScalingIfNeeded(WTFMove(image), internalSize(), logicalSize(), m_data.backingStoreSize, m_resolutionScale, preserveResolution);
+    return createBitmapImageAfterScalingIfNeeded(WTFMove(image), logicalSize(), internalSize(), m_resolutionScale, preserveResolution);
 }
 
 RefPtr<Image> ImageBuffer::sinkIntoImage(std::unique_ptr<ImageBuffer> imageBuffer, PreserveResolution preserveResolution)
 {
     IntSize internalSize = imageBuffer->internalSize();
     IntSize logicalSize = imageBuffer->logicalSize();
-    IntSize backingStoreSize = imageBuffer->m_data.backingStoreSize;
     float resolutionScale = imageBuffer->m_resolutionScale;
 
-    return createBitmapImageAfterScalingIfNeeded(sinkIntoNativeImage(WTFMove(imageBuffer)), internalSize, logicalSize, backingStoreSize, resolutionScale, preserveResolution);
-}
-
-BackingStoreCopy ImageBuffer::fastCopyImageMode()
-{
-    return DontCopyBackingStore;
+    return createBitmapImageAfterScalingIfNeeded(sinkIntoNativeImage(WTFMove(imageBuffer)), logicalSize, internalSize, resolutionScale, preserveResolution);
 }
 
 RetainPtr<CGImageRef> ImageBuffer::sinkIntoNativeImage(std::unique_ptr<ImageBuffer> imageBuffer)
@@ -493,7 +475,7 @@ RetainPtr<CFDataRef> ImageBuffer::toCFData(const String& mimeType, Optional<doub
         auto context = adoptCF(CGBitmapContextCreate(0, logicalSize().width(), logicalSize().height(), 8, 4 * logicalSize().width(), sRGBColorSpaceRef(), kCGImageAlphaPremultipliedLast));
         CGContextSetBlendMode(context.get(), kCGBlendModeCopy);
         CGContextClipToRect(context.get(), CGRectMake(0, 0, logicalSize().width(), logicalSize().height()));
-        FloatSize imageSizeInUserSpace = sizeForDestinationSize(logicalSize());
+        FloatSize imageSizeInUserSpace = logicalSize();
         CGContextDrawImage(context.get(), CGRectMake(0, 0, imageSizeInUserSpace.width(), imageSizeInUserSpace.height()), image.get());
         image = adoptCF(CGBitmapContextCreateImage(context.get()));
     }
index b8e3b0b..e04218f 100644 (file)
 
 namespace WebCore {
 
-static FloatSize scaleSizeToUserSpace(const FloatSize& logicalSize, const IntSize& backingStoreSize, const IntSize& internalSize)
-{
-    float xMagnification = static_cast<float>(backingStoreSize.width()) / internalSize.width();
-    float yMagnification = static_cast<float>(backingStoreSize.height()) / internalSize.height();
-    return FloatSize(logicalSize.width() * xMagnification, logicalSize.height() * yMagnification);
-}
-
 std::unique_ptr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const FloatSize& size, const GraphicsContext& context)
 {
     if (size.isEmpty())
@@ -132,11 +125,6 @@ ImageBuffer::ImageBuffer(const FloatSize& size, float resolutionScale, ColorSpac
 
 ImageBuffer::~ImageBuffer() = default;
 
-FloatSize ImageBuffer::sizeForDestinationSize(FloatSize destinationSize) const
-{
-    return scaleSizeToUserSpace(destinationSize, m_data.backingStoreSize, internalSize());
-}
-
 GraphicsContext& ImageBuffer::context() const
 {
     return *m_data.context;
@@ -206,11 +194,6 @@ RefPtr<Image> ImageBuffer::sinkIntoImage(std::unique_ptr<ImageBuffer> imageBuffe
     return createBitmapImageAfterScalingIfNeeded(bitmapTarget.get(), sinkIntoNativeImage(WTFMove(imageBuffer)), internalSize, logicalSize, backingStoreSize, resolutionScale, preserveResolution);
 }
 
-BackingStoreCopy ImageBuffer::fastCopyImageMode()
-{
-    return DontCopyBackingStore;
-}
-
 COMPtr<ID2D1Bitmap> ImageBuffer::sinkIntoNativeImage(std::unique_ptr<ImageBuffer> imageBuffer)
 {
     // FIXME: See if we can reuse the on-hardware image.