Diff
Modified: trunk/Source/WebCore/ChangeLog (190999 => 191000)
--- trunk/Source/WebCore/ChangeLog 2015-10-13 18:49:58 UTC (rev 190999)
+++ trunk/Source/WebCore/ChangeLog 2015-10-13 19:03:37 UTC (rev 191000)
@@ -1,3 +1,28 @@
+2015-10-13 Simon Fraser <[email protected]>
+
+ Move Image::drawPattern for CG into GraphicsContext
+ https://bugs.webkit.org/show_bug.cgi?id=150077
+
+ Reviewed by Myles C. Maxfield.
+
+ In order to consolidate code that calls into Core Graphics inside
+ GraphicsContext, move the body of Image::drawPattern() into
+ GraphicsContextCG.cpp, and do the same for Cairo.
+
+ * platform/graphics/GraphicsContext.h:
+ * platform/graphics/cairo/GraphicsContextCairo.cpp:
+ (WebCore::GraphicsContext::drawPattern):
+ * platform/graphics/cairo/ImageCairo.cpp:
+ (WebCore::Image::drawPattern):
+ * platform/graphics/cg/GraphicsContextCG.cpp:
+ (WebCore::drawPatternCallback):
+ (WebCore::patternReleaseCallback):
+ (WebCore::GraphicsContext::drawPattern):
+ * platform/graphics/cg/ImageCG.cpp:
+ (WebCore::Image::drawPattern):
+ (WebCore::drawPatternCallback): Deleted.
+ (WebCore::patternReleaseCallback): Deleted.
+
2015-10-13 Myles C. Maxfield <[email protected]>
Unprefix font-kerning
Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.h (190999 => 191000)
--- trunk/Source/WebCore/platform/graphics/GraphicsContext.h 2015-10-13 18:49:58 UTC (rev 190999)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.h 2015-10-13 19:03:37 UTC (rev 191000)
@@ -320,6 +320,8 @@
void drawImageBuffer(ImageBuffer*, ColorSpace, const FloatRect& destination, const ImagePaintingOptions& = ImagePaintingOptions());
void drawImageBuffer(ImageBuffer*, ColorSpace, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions& = ImagePaintingOptions());
+ void drawPattern(Image&, const FloatRect& srcRect, const AffineTransform&, const FloatPoint& phase, const FloatSize& spacing, ColorSpace, CompositeOperator, const FloatRect& destRect, BlendMode = BlendModeNormal);
+
WEBCORE_EXPORT void setImageInterpolationQuality(InterpolationQuality);
InterpolationQuality imageInterpolationQuality() const;
Modified: trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp (190999 => 191000)
--- trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp 2015-10-13 18:49:58 UTC (rev 190999)
+++ trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp 2015-10-13 19:03:37 UTC (rev 191000)
@@ -1077,6 +1077,16 @@
cairo_restore(cr);
}
+void GraphicsContext::drawPattern(Image& image, const FloatRect& tileRect, const AffineTransform& patternTransform, const FloatPoint& phase, const FloatSize&, ColorSpace, CompositeOperator op, const FloatRect& destRect, BlendMode)
+{
+ RefPtr<cairo_surface_t> surface = image.nativeImageForCurrentFrame();
+ if (!surface) // If it's too early we won't have an image yet.
+ return;
+
+ cairo_t* cr = platformContext()->cr();
+ drawPatternToCairoContext(cr, surface.get(), IntSize(image.size()), tileRect, patternTransform, phase, toCairoOperator(op), destRect);
+}
+
void GraphicsContext::setPlatformShouldAntialias(bool enable)
{
if (paintingDisabled())
Modified: trunk/Source/WebCore/platform/graphics/cairo/ImageCairo.cpp (190999 => 191000)
--- trunk/Source/WebCore/platform/graphics/cairo/ImageCairo.cpp 2015-10-13 18:49:58 UTC (rev 190999)
+++ trunk/Source/WebCore/platform/graphics/cairo/ImageCairo.cpp 2015-10-13 19:03:37 UTC (rev 191000)
@@ -42,15 +42,10 @@
namespace WebCore {
void Image::drawPattern(GraphicsContext& context, const FloatRect& tileRect, const AffineTransform& patternTransform,
- const FloatPoint& phase, const FloatSize&, ColorSpace, CompositeOperator op, const FloatRect& destRect, BlendMode)
+ const FloatPoint& phase, const FloatSize& spacing, ColorSpace colorSpace, CompositeOperator op, const FloatRect& destRect, BlendMode blendMode)
{
- RefPtr<cairo_surface_t> surface = nativeImageForCurrentFrame();
- if (!surface) // If it's too early we won't have an image yet.
- return;
+ context.drawPattern(*this, tileRect, patternTransform, phase, spacing, colorSpace, op, destRect, blendMode);
- cairo_t* cr = context.platformContext()->cr();
- drawPatternToCairoContext(cr, surface.get(), IntSize(size()), tileRect, patternTransform, phase, toCairoOperator(op), destRect);
-
if (imageObserver())
imageObserver()->didDraw(this);
}
Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp (190999 => 191000)
--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp 2015-10-13 18:49:58 UTC (rev 190999)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp 2015-10-13 19:03:37 UTC (rev 191000)
@@ -243,6 +243,108 @@
CGContextDrawImage(context, adjustedDestRect, image.get());
}
+static void drawPatternCallback(void* info, CGContextRef context)
+{
+ CGImageRef image = (CGImageRef)info;
+ CGFloat height = CGImageGetHeight(image);
+#if PLATFORM(IOS)
+ CGContextScaleCTM(context, 1, -1);
+ CGContextTranslateCTM(context, 0, -height);
+#endif
+ CGContextDrawImage(context, GraphicsContext(context).roundToDevicePixels(FloatRect(0, 0, CGImageGetWidth(image), height)), image);
+}
+
+static void patternReleaseCallback(void* info)
+{
+ auto image = static_cast<CGImageRef>(info);
+ callOnMainThread([image] {
+ CGImageRelease(image);
+ });
+}
+
+void GraphicsContext::drawPattern(Image& image, const FloatRect& tileRect, const AffineTransform& patternTransform, const FloatPoint& phase, const FloatSize& spacing, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect, BlendMode blendMode)
+{
+ if (!patternTransform.isInvertible())
+ return;
+
+ CGContextRef context = platformContext();
+ CGContextStateSaver stateSaver(context);
+ CGContextClipToRect(context, destRect);
+
+ setPlatformCompositeOperation(op, blendMode);
+
+ CGContextTranslateCTM(context, destRect.x(), destRect.y() + destRect.height());
+ CGContextScaleCTM(context, 1, -1);
+
+ // Compute the scaled tile size.
+ float scaledTileHeight = tileRect.height() * narrowPrecisionToFloat(patternTransform.d());
+
+ // We have to adjust the phase to deal with the fact we're in Cartesian space now (with the bottom left corner of destRect being
+ // the origin).
+ float adjustedX = phase.x() - destRect.x() + tileRect.x() * narrowPrecisionToFloat(patternTransform.a()); // We translated the context so that destRect.x() is the origin, so subtract it out.
+ float adjustedY = destRect.height() - (phase.y() - destRect.y() + tileRect.y() * narrowPrecisionToFloat(patternTransform.d()) + scaledTileHeight);
+
+ CGImageRef tileImage = image.nativeImageForCurrentFrame();
+ float h = CGImageGetHeight(tileImage);
+
+ RetainPtr<CGImageRef> subImage;
+#if PLATFORM(IOS)
+ FloatSize imageSize = image.originalSize();
+#else
+ FloatSize imageSize = image.size();
+#endif
+ if (tileRect.size() == imageSize)
+ subImage = tileImage;
+ else {
+ // Copying a sub-image out of a partially-decoded image stops the decoding of the original image. It should never happen
+ // because sub-images are only used for border-image, which only renders when the image is fully decoded.
+ ASSERT(h == image.height());
+ subImage = adoptCF(CGImageCreateWithImageInRect(tileImage, tileRect));
+ }
+
+ // Adjust the color space.
+ subImage = Image::imageWithColorSpace(subImage.get(), styleColorSpace);
+
+ // If we need to paint gaps between tiles because we have a partially loaded image or non-zero spacing,
+ // fall back to the less efficient CGPattern-based mechanism.
+ float scaledTileWidth = tileRect.width() * narrowPrecisionToFloat(patternTransform.a());
+ float w = CGImageGetWidth(tileImage);
+ if (w == image.size().width() && h == image.size().height() && !spacing.width() && !spacing.height())
+ CGContextDrawTiledImage(context, FloatRect(adjustedX, adjustedY, scaledTileWidth, scaledTileHeight), subImage.get());
+ else {
+ static const CGPatternCallbacks patternCallbacks = { 0, drawPatternCallback, patternReleaseCallback };
+ CGAffineTransform matrix = CGAffineTransformMake(narrowPrecisionToCGFloat(patternTransform.a()), 0, 0, narrowPrecisionToCGFloat(patternTransform.d()), adjustedX, adjustedY);
+ matrix = CGAffineTransformConcat(matrix, CGContextGetCTM(context));
+ // The top of a partially-decoded image is drawn at the bottom of the tile. Map it to the top.
+ matrix = CGAffineTransformTranslate(matrix, 0, image.size().height() - h);
+#if PLATFORM(IOS)
+ matrix = CGAffineTransformScale(matrix, 1, -1);
+ matrix = CGAffineTransformTranslate(matrix, 0, -h);
+#endif
+ CGImageRef platformImage = CGImageRetain(subImage.get());
+ RetainPtr<CGPatternRef> pattern = adoptCF(CGPatternCreate(platformImage, CGRectMake(0, 0, tileRect.width(), tileRect.height()), matrix,
+ tileRect.width() + spacing.width() * (1 / narrowPrecisionToFloat(patternTransform.a())),
+ tileRect.height() + spacing.height() * (1 / narrowPrecisionToFloat(patternTransform.d())),
+ kCGPatternTilingConstantSpacing, true, &patternCallbacks));
+
+ if (!pattern)
+ return;
+
+ RetainPtr<CGColorSpaceRef> patternSpace = adoptCF(CGColorSpaceCreatePattern(0));
+
+ CGFloat alpha = 1;
+ RetainPtr<CGColorRef> color = adoptCF(CGColorCreateWithPattern(patternSpace.get(), pattern.get(), &alpha));
+ CGContextSetFillColorSpace(context, patternSpace.get());
+
+ // FIXME: Really want a public API for this. It is just CGContextSetBaseCTM(context, CGAffineTransformIdentiy).
+ wkSetBaseCTM(context, CGAffineTransformIdentity);
+ CGContextSetPatternPhase(context, CGSizeZero);
+
+ CGContextSetFillColorWithColor(context, color.get());
+ CGContextFillRect(context, CGContextGetClipBoundingBox(context));
+ }
+}
+
// Draws a filled rectangle with a stroked border.
void GraphicsContext::drawRect(const FloatRect& rect, float borderThickness)
{
Modified: trunk/Source/WebCore/platform/graphics/cg/ImageCG.cpp (190999 => 191000)
--- trunk/Source/WebCore/platform/graphics/cg/ImageCG.cpp 2015-10-13 18:49:58 UTC (rev 190999)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageCG.cpp 2015-10-13 19:03:37 UTC (rev 191000)
@@ -67,111 +67,14 @@
return originalImage;
}
-static void drawPatternCallback(void* info, CGContextRef context)
-{
- CGImageRef image = (CGImageRef)info;
- CGFloat height = CGImageGetHeight(image);
-#if PLATFORM(IOS)
- CGContextScaleCTM(context, 1, -1);
- CGContextTranslateCTM(context, 0, -height);
-#endif
- CGContextDrawImage(context, GraphicsContext(context).roundToDevicePixels(FloatRect(0, 0, CGImageGetWidth(image), height)), image);
-}
-
-static void patternReleaseCallback(void* info)
-{
- auto image = static_cast<CGImageRef>(info);
- callOnMainThread([image] {
- CGImageRelease(image);
- });
-}
-
void Image::drawPattern(GraphicsContext& ctxt, const FloatRect& tileRect, const AffineTransform& patternTransform,
const FloatPoint& phase, const FloatSize& spacing, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect, BlendMode blendMode)
{
if (!nativeImageForCurrentFrame())
return;
- if (!patternTransform.isInvertible())
- return;
+ ctxt.drawPattern(*this, tileRect, patternTransform, phase, spacing, styleColorSpace, op, destRect, blendMode);
- CGContextRef context = ctxt.platformContext();
- GraphicsContextStateSaver stateSaver(ctxt);
- CGContextClipToRect(context, destRect);
- ctxt.setCompositeOperation(op, blendMode);
- CGContextTranslateCTM(context, destRect.x(), destRect.y() + destRect.height());
- CGContextScaleCTM(context, 1, -1);
-
- // Compute the scaled tile size.
- float scaledTileHeight = tileRect.height() * narrowPrecisionToFloat(patternTransform.d());
-
- // We have to adjust the phase to deal with the fact we're in Cartesian space now (with the bottom left corner of destRect being
- // the origin).
- float adjustedX = phase.x() - destRect.x() + tileRect.x() * narrowPrecisionToFloat(patternTransform.a()); // We translated the context so that destRect.x() is the origin, so subtract it out.
- float adjustedY = destRect.height() - (phase.y() - destRect.y() + tileRect.y() * narrowPrecisionToFloat(patternTransform.d()) + scaledTileHeight);
-
- CGImageRef tileImage = nativeImageForCurrentFrame();
- float h = CGImageGetHeight(tileImage);
-
- RetainPtr<CGImageRef> subImage;
-#if PLATFORM(IOS)
- FloatSize imageSize = originalSize();
-#else
- FloatSize imageSize = size();
-#endif
- if (tileRect.size() == imageSize)
- subImage = tileImage;
- else {
- // Copying a sub-image out of a partially-decoded image stops the decoding of the original image. It should never happen
- // because sub-images are only used for border-image, which only renders when the image is fully decoded.
- ASSERT(h == height());
- subImage = adoptCF(CGImageCreateWithImageInRect(tileImage, tileRect));
- }
-
- // Adjust the color space.
- subImage = Image::imageWithColorSpace(subImage.get(), styleColorSpace);
-
- // If we need to paint gaps between tiles because we have a partially loaded image or non-zero spacing,
- // fall back to the less efficient CGPattern-based mechanism.
- float scaledTileWidth = tileRect.width() * narrowPrecisionToFloat(patternTransform.a());
- float w = CGImageGetWidth(tileImage);
- if (w == size().width() && h == size().height() && !spacing.width() && !spacing.height())
- CGContextDrawTiledImage(context, FloatRect(adjustedX, adjustedY, scaledTileWidth, scaledTileHeight), subImage.get());
- else {
- static const CGPatternCallbacks patternCallbacks = { 0, drawPatternCallback, patternReleaseCallback };
- CGAffineTransform matrix = CGAffineTransformMake(narrowPrecisionToCGFloat(patternTransform.a()), 0, 0, narrowPrecisionToCGFloat(patternTransform.d()), adjustedX, adjustedY);
- matrix = CGAffineTransformConcat(matrix, CGContextGetCTM(context));
- // The top of a partially-decoded image is drawn at the bottom of the tile. Map it to the top.
- matrix = CGAffineTransformTranslate(matrix, 0, size().height() - h);
-#if PLATFORM(IOS)
- matrix = CGAffineTransformScale(matrix, 1, -1);
- matrix = CGAffineTransformTranslate(matrix, 0, -h);
-#endif
- CGImageRef platformImage = CGImageRetain(subImage.get());
- RetainPtr<CGPatternRef> pattern = adoptCF(CGPatternCreate(platformImage, CGRectMake(0, 0, tileRect.width(), tileRect.height()), matrix,
- tileRect.width() + spacing.width() * (1 / narrowPrecisionToFloat(patternTransform.a())),
- tileRect.height() + spacing.height() * (1 / narrowPrecisionToFloat(patternTransform.d())),
- kCGPatternTilingConstantSpacing, true, &patternCallbacks));
-
- if (!pattern)
- return;
-
- RetainPtr<CGColorSpaceRef> patternSpace = adoptCF(CGColorSpaceCreatePattern(0));
-
- CGFloat alpha = 1;
- RetainPtr<CGColorRef> color = adoptCF(CGColorCreateWithPattern(patternSpace.get(), pattern.get(), &alpha));
- CGContextSetFillColorSpace(context, patternSpace.get());
-
- // FIXME: Really want a public API for this. It is just CGContextSetBaseCTM(context, CGAffineTransformIdentiy).
- wkSetBaseCTM(context, CGAffineTransformIdentity);
- CGContextSetPatternPhase(context, CGSizeZero);
-
- CGContextSetFillColorWithColor(context, color.get());
- CGContextFillRect(context, CGContextGetClipBoundingBox(context));
- }
-
- stateSaver.restore();
-
if (imageObserver())
imageObserver()->didDraw(this);
}