Move ImageBuffer:clip() into GraphicsContextCG
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Oct 2015 17:20:10 +0000 (17:20 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Oct 2015 17:20:10 +0000 (17:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150140

Reviewed by Zalan Bujtas.

Move the guts of CG's ImageBuffer:clip() into GraphicsContextCG.

* platform/graphics/GraphicsContext.h:
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::clipToNativeImage):
* platform/graphics/cg/ImageBufferCG.cpp:
(WebCore::ImageBuffer::clip):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/GraphicsContext.h
Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp

index 225dfb1..5eeeac3 100644 (file)
@@ -1,3 +1,18 @@
+2015-10-14  Simon Fraser  <simon.fraser@apple.com>
+
+        Move ImageBuffer:clip() into GraphicsContextCG
+        https://bugs.webkit.org/show_bug.cgi?id=150140
+
+        Reviewed by Zalan Bujtas.
+
+        Move the guts of CG's ImageBuffer:clip() into GraphicsContextCG.
+
+        * platform/graphics/GraphicsContext.h:
+        * platform/graphics/cg/GraphicsContextCG.cpp:
+        (WebCore::GraphicsContext::clipToNativeImage):
+        * platform/graphics/cg/ImageBufferCG.cpp:
+        (WebCore::ImageBuffer::clip):
+
 2015-10-14  Brady Eidson  <beidson@apple.com>
 
         Modern IDB: Add basic transaction committing.
index ca9fab5..c83f408 100644 (file)
@@ -262,6 +262,8 @@ namespace WebCore {
 
         WEBCORE_EXPORT void drawNativeImage(PassNativeImagePtr, const FloatSize& selfSize, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator = CompositeSourceOver, BlendMode = BlendModeNormal, ImageOrientation = DefaultImageOrientation);
 
+        void clipToNativeImage(PassNativeImagePtr, const FloatRect& destRect, const FloatSize& bufferSize);
+
         // Allow font smoothing (LCD antialiasing). Not part of the graphics state.
         void setAllowsFontSmoothing(bool);
         
index 03ad31c..45e464f 100644 (file)
@@ -345,6 +345,18 @@ void GraphicsContext::drawPattern(Image& image, const FloatRect& tileRect, const
     }
 }
 
+void GraphicsContext::clipToNativeImage(PassNativeImagePtr image, const FloatRect& destRect, const FloatSize& bufferSize)
+{
+    CGContextRef context = platformContext();
+    // FIXME: This image needs to be grayscale to be used as an alpha mask here.
+    CGContextTranslateCTM(context, destRect.x(), destRect.y() + bufferSize.height());
+    CGContextScaleCTM(context, 1, -1);
+    CGContextClipToRect(context, FloatRect(FloatPoint(0, bufferSize.height() - destRect.height()), destRect.size()));
+    CGContextClipToMask(context, FloatRect(FloatPoint(), bufferSize), image);
+    CGContextScaleCTM(context, 1, -1);
+    CGContextTranslateCTM(context, -destRect.x(), -destRect.y() - destRect.height());
+}
+
 // Draws a filled rectangle with a stroked border.
 void GraphicsContext::drawRect(const FloatRect& rect, float borderThickness)
 {
index a6e4a4f..7bd7f52 100644 (file)
@@ -266,16 +266,8 @@ void ImageBuffer::drawPattern(GraphicsContext& destContext, const FloatRect& src
 void ImageBuffer::clip(GraphicsContext& contextToClip, const FloatRect& rect) const
 {
     FloatSize backingStoreSizeInUserSpace = scaleSizeToUserSpace(rect.size(), m_data.backingStoreSize, internalSize());
-
-    CGContextRef platformContextToClip = contextToClip.platformContext();
-    // FIXME: This image needs to be grayscale to be used as an alpha mask here.
     RetainPtr<CGImageRef> image = copyNativeImage(DontCopyBackingStore);
-    CGContextTranslateCTM(platformContextToClip, rect.x(), rect.y() + backingStoreSizeInUserSpace.height());
-    CGContextScaleCTM(platformContextToClip, 1, -1);
-    CGContextClipToRect(platformContextToClip, FloatRect(FloatPoint(0, backingStoreSizeInUserSpace.height() - rect.height()), rect.size()));
-    CGContextClipToMask(platformContextToClip, FloatRect(FloatPoint(), backingStoreSizeInUserSpace), image.get());
-    CGContextScaleCTM(platformContextToClip, 1, -1);
-    CGContextTranslateCTM(platformContextToClip, -rect.x(), -rect.y() - rect.height());
+    contextToClip.clipToNativeImage(image.get(), rect, backingStoreSizeInUserSpace);
 }
 
 PassRefPtr<Uint8ClampedArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect, CoordinateSystem coordinateSystem) const