GeneratorGeneratedImage::drawPattern does not factor in its destination context's...
authormdelaney@apple.com <mdelaney@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Feb 2012 01:30:54 +0000 (01:30 +0000)
committermdelaney@apple.com <mdelaney@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Feb 2012 01:30:54 +0000 (01:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=67729
<rdar://problem/10087050>

Reviewed by Beth Dakin.

No new tests, current pixel tests will cover this. Though some pixel results might improve to become less pixel-y.

* platform/graphics/GeneratorGeneratedImage.cpp:
(WebCore::GeneratorGeneratedImage::draw): Updated context to destContext for consistency.
(WebCore::GeneratorGeneratedImage::drawPattern): Taught drawPattern about the destination
scale factor to avoid having low-res generated images such as gradients in certain cases.
* platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::createCompatibleBuffer): Have the image buffer match the
context acceleration setting as well.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/GeneratorGeneratedImage.cpp
Source/WebCore/platform/graphics/GraphicsContext.cpp

index ae5726a..4c331ec 100644 (file)
@@ -1,3 +1,22 @@
+2012-02-08  Matthew Delaney  <mdelaney@apple.com>
+
+        GeneratorGeneratedImage::drawPattern does not factor in its destination context's scale when generating its image tiles
+
+        https://bugs.webkit.org/show_bug.cgi?id=67729
+        <rdar://problem/10087050>
+
+        Reviewed by Beth Dakin.
+
+        No new tests, current pixel tests will cover this. Though some pixel results might improve to become less pixel-y.
+
+        * platform/graphics/GeneratorGeneratedImage.cpp:
+        (WebCore::GeneratorGeneratedImage::draw): Updated context to destContext for consistency.
+        (WebCore::GeneratorGeneratedImage::drawPattern): Taught drawPattern about the destination
+        scale factor to avoid having low-res generated images such as gradients in certain cases.
+        * platform/graphics/GraphicsContext.cpp:
+        (WebCore::GraphicsContext::createCompatibleBuffer): Have the image buffer match the
+        context acceleration setting as well.
+
 2012-02-08  Adam Klein  <adamk@chromium.org>
 
         Simplify and correct mutation delivery timing for JSC
index a8e969c..ad1165f 100644 (file)
 
 namespace WebCore {
 
-void GeneratorGeneratedImage::draw(GraphicsContext* context, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace, CompositeOperator compositeOp)
+void GeneratorGeneratedImage::draw(GraphicsContext* destContext, const FloatRect& destRect, const FloatRect& srcRect, ColorSpace, CompositeOperator compositeOp)
 {
-    GraphicsContextStateSaver stateSaver(*context);
-    context->setCompositeOperation(compositeOp);
-    context->clip(dstRect);
-    context->translate(dstRect.x(), dstRect.y());
-    if (dstRect.size() != srcRect.size())
-        context->scale(FloatSize(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height()));
-    context->translate(-srcRect.x(), -srcRect.y());
-    context->fillRect(FloatRect(FloatPoint(), m_size), *m_generator.get());
+    GraphicsContextStateSaver stateSaver(*destContext);
+    destContext->setCompositeOperation(compositeOp);
+    destContext->clip(destRect);
+    destContext->translate(destRect.x(), destRect.y());
+    if (destRect.size() != srcRect.size())
+        destContext->scale(FloatSize(destRect.width() / srcRect.width(), destRect.height() / srcRect.height()));
+    destContext->translate(-srcRect.x(), -srcRect.y());
+    destContext->fillRect(FloatRect(FloatPoint(), m_size), *m_generator.get());
 }
 
-void GeneratorGeneratedImage::drawPattern(GraphicsContext* context, const FloatRect& srcRect, const AffineTransform& patternTransform,
+void GeneratorGeneratedImage::drawPattern(GraphicsContext* destContext, const FloatRect& srcRect, const AffineTransform& patternTransform,
                                  const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator compositeOp, const FloatRect& destRect)
 {
     // Allow the generator to provide visually-equivalent tiling parameters for better performance.
@@ -53,8 +53,16 @@ void GeneratorGeneratedImage::drawPattern(GraphicsContext* context, const FloatR
     FloatRect adjustedSrcRect = srcRect;
     m_generator->adjustParametersForTiledDrawing(adjustedSize, adjustedSrcRect);
 
+    // Factor in the destination context's scale to generate at the best resolution
+    AffineTransform destContextCTM = destContext->getCTM();
+    double xScale = fabs(destContextCTM.xScale());
+    double yScale = fabs(destContextCTM.yScale());
+    AffineTransform adjustedPatternCTM = patternTransform;
+    adjustedPatternCTM.scale(1.0 / xScale, 1.0 / yScale);
+    adjustedSrcRect.scale(xScale, yScale);
+
     // Create a BitmapImage and call drawPattern on it.
-    OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(adjustedSize, ColorSpaceDeviceRGB, context->isAcceleratedContext() ? Accelerated : Unaccelerated);
+    OwnPtr<ImageBuffer> imageBuffer = destContext->createCompatibleBuffer(adjustedSize);
     if (!imageBuffer)
         return;
 
@@ -63,7 +71,7 @@ void GeneratorGeneratedImage::drawPattern(GraphicsContext* context, const FloatR
     graphicsContext->fillRect(FloatRect(FloatPoint(), adjustedSize), *m_generator.get());
 
     // Tile the image buffer into the context.
-    imageBuffer->drawPattern(context, adjustedSrcRect, patternTransform, phase, styleColorSpace, compositeOp, destRect);
+    imageBuffer->drawPattern(destContext, adjustedSrcRect, adjustedPatternCTM, phase, styleColorSpace, compositeOp, destRect);
 }
 
 void GeneratedImage::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)
index 475fdb3..f77b8a1 100644 (file)
@@ -754,7 +754,7 @@ PassOwnPtr<ImageBuffer> GraphicsContext::createCompatibleBuffer(const IntSize& s
     AffineTransform transform = getCTM();
     IntSize scaledSize(static_cast<int>(ceil(size.width() * transform.xScale())), static_cast<int>(ceil(size.height() * transform.yScale())));
 
-    OwnPtr<ImageBuffer> buffer = ImageBuffer::create(scaledSize);
+    OwnPtr<ImageBuffer> buffer = ImageBuffer::create(scaledSize, ColorSpaceDeviceRGB, isAcceleratedContext() ? Accelerated : Unaccelerated);
     if (!buffer)
         return nullptr;