Title: [91446] trunk/Source/WebCore
Revision
91446
Author
[email protected]
Date
2011-07-20 22:56:42 -0700 (Wed, 20 Jul 2011)

Log Message

Unreviewed, rolling out r91332.
http://trac.webkit.org/changeset/91332
https://bugs.webkit.org/show_bug.cgi?id=64925

Crashes css3/images/optimize-contrast-canvas.html on safari-
mac,chromium-mac (Requested by mikelawther on #webkit).

Patch by Sheriff Bot <[email protected]> on 2011-07-20

* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::makePresentationCopy):
(WebCore::HTMLCanvasElement::copiedImage):
* html/canvas/WebGLRenderingContext.cpp:
(WebCore::WebGLRenderingContext::videoFrameToImage):
* platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::drawImage):
* platform/graphics/GraphicsContext.h:
* platform/graphics/Image.h:
* platform/graphics/ImageBuffer.h:
* platform/graphics/cairo/ImageBufferCairo.cpp:
(WebCore::ImageBuffer::copyImage):
* platform/graphics/cg/GraphicsContextCG.cpp:
* platform/graphics/cg/ImageBufferCG.cpp:
(WebCore::ImageBuffer::copyImage):
(WebCore::cgImage):
(WebCore::ImageBuffer::draw):
(WebCore::ImageBuffer::drawPattern):
(WebCore::ImageBuffer::clip):
(WebCore::ImageBuffer::toDataURL):
* platform/graphics/cg/ImageCG.cpp:
(WebCore::imageWithColorSpace):
(WebCore::BitmapImage::draw):
(WebCore::Image::drawPattern):
* platform/graphics/filters/FETile.cpp:
(WebCore::FETile::apply):
* platform/graphics/qt/ImageBufferQt.cpp:
(WebCore::ImageBuffer::copyImage):
(WebCore::ImageBuffer::draw):
(WebCore::ImageBuffer::drawPattern):
* platform/graphics/skia/ImageBufferSkia.cpp:
(WebCore::ImageBuffer::copyImage):
* platform/graphics/wince/ImageBufferWinCE.cpp:
(WebCore::ImageBuffer::copyImage):
(WebCore::ImageBuffer::draw):
(WebCore::ImageBuffer::drawPattern):
* platform/graphics/wx/ImageBufferWx.cpp:
(WebCore::ImageBuffer::copyImage):
(WebCore::ImageBuffer::draw):
(WebCore::ImageBuffer::drawPattern):
* rendering/svg/RenderSVGResourcePattern.cpp:
(WebCore::RenderSVGResourcePattern::applyResource):
* svg/SVGFEImageElement.cpp:
(WebCore::SVGFEImageElement::build):
* svg/graphics/SVGImage.cpp:
(WebCore::SVGImage::nativeImageForCurrentFrame):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (91445 => 91446)


--- trunk/Source/WebCore/ChangeLog	2011-07-21 05:49:22 UTC (rev 91445)
+++ trunk/Source/WebCore/ChangeLog	2011-07-21 05:56:42 UTC (rev 91446)
@@ -1,3 +1,59 @@
+2011-07-20  Sheriff Bot  <[email protected]>
+
+        Unreviewed, rolling out r91332.
+        http://trac.webkit.org/changeset/91332
+        https://bugs.webkit.org/show_bug.cgi?id=64925
+
+        Crashes css3/images/optimize-contrast-canvas.html on safari-
+        mac,chromium-mac (Requested by mikelawther on #webkit).
+
+        * html/HTMLCanvasElement.cpp:
+        (WebCore::HTMLCanvasElement::makePresentationCopy):
+        (WebCore::HTMLCanvasElement::copiedImage):
+        * html/canvas/WebGLRenderingContext.cpp:
+        (WebCore::WebGLRenderingContext::videoFrameToImage):
+        * platform/graphics/GraphicsContext.cpp:
+        (WebCore::GraphicsContext::drawImage):
+        * platform/graphics/GraphicsContext.h:
+        * platform/graphics/Image.h:
+        * platform/graphics/ImageBuffer.h:
+        * platform/graphics/cairo/ImageBufferCairo.cpp:
+        (WebCore::ImageBuffer::copyImage):
+        * platform/graphics/cg/GraphicsContextCG.cpp:
+        * platform/graphics/cg/ImageBufferCG.cpp:
+        (WebCore::ImageBuffer::copyImage):
+        (WebCore::cgImage):
+        (WebCore::ImageBuffer::draw):
+        (WebCore::ImageBuffer::drawPattern):
+        (WebCore::ImageBuffer::clip):
+        (WebCore::ImageBuffer::toDataURL):
+        * platform/graphics/cg/ImageCG.cpp:
+        (WebCore::imageWithColorSpace):
+        (WebCore::BitmapImage::draw):
+        (WebCore::Image::drawPattern):
+        * platform/graphics/filters/FETile.cpp:
+        (WebCore::FETile::apply):
+        * platform/graphics/qt/ImageBufferQt.cpp:
+        (WebCore::ImageBuffer::copyImage):
+        (WebCore::ImageBuffer::draw):
+        (WebCore::ImageBuffer::drawPattern):
+        * platform/graphics/skia/ImageBufferSkia.cpp:
+        (WebCore::ImageBuffer::copyImage):
+        * platform/graphics/wince/ImageBufferWinCE.cpp:
+        (WebCore::ImageBuffer::copyImage):
+        (WebCore::ImageBuffer::draw):
+        (WebCore::ImageBuffer::drawPattern):
+        * platform/graphics/wx/ImageBufferWx.cpp:
+        (WebCore::ImageBuffer::copyImage):
+        (WebCore::ImageBuffer::draw):
+        (WebCore::ImageBuffer::drawPattern):
+        * rendering/svg/RenderSVGResourcePattern.cpp:
+        (WebCore::RenderSVGResourcePattern::applyResource):
+        * svg/SVGFEImageElement.cpp:
+        (WebCore::SVGFEImageElement::build):
+        * svg/graphics/SVGImage.cpp:
+        (WebCore::SVGImage::nativeImageForCurrentFrame):
+
 2011-07-20  Ryosuke Niwa  <[email protected]>
 
         Chromium build fix after r91440.

Modified: trunk/Source/WebCore/html/HTMLCanvasElement.cpp (91445 => 91446)


--- trunk/Source/WebCore/html/HTMLCanvasElement.cpp	2011-07-21 05:49:22 UTC (rev 91445)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.cpp	2011-07-21 05:56:42 UTC (rev 91446)
@@ -309,7 +309,7 @@
 {
     if (!m_presentedImage) {
         // The buffer contains the last presented data, so save a copy of it.
-        m_presentedImage = buffer()->copyImage(CopyBackingStore);
+        m_presentedImage = buffer()->copyImage();
     }
 }
 
@@ -472,7 +472,7 @@
     if (!m_copiedImage && buffer()) {
         if (m_context)
             m_context->paintRenderingResultsToCanvas();
-        m_copiedImage = buffer()->copyImage(CopyBackingStore);
+        m_copiedImage = buffer()->copyImage();
     }
     return m_copiedImage.get();
 }

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp (91445 => 91446)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp	2011-07-21 05:49:22 UTC (rev 91445)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp	2011-07-21 05:56:42 UTC (rev 91446)
@@ -3214,7 +3214,7 @@
     IntRect destRect(0, 0, size.width(), size.height());
     // FIXME: Turn this into a GPU-GPU texture copy instead of CPU readback.
     video->paintCurrentFrameInContext(buf->context(), destRect);
-    return buf->copyImage(CopyBackingStore);
+    return buf->copyImage();
 }
 
 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat,

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp (91445 => 91446)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp	2011-07-21 05:49:22 UTC (rev 91445)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp	2011-07-21 05:56:42 UTC (rev 91446)
@@ -351,6 +351,26 @@
     return m_state.paintingDisabled;
 }
 
+void GraphicsContext::drawImage(Image* image, ColorSpace styleColorSpace, const IntPoint& p, CompositeOperator op)
+{
+    drawImage(image, styleColorSpace, p, IntRect(0, 0, -1, -1), op);
+}
+
+void GraphicsContext::drawImage(Image* image, ColorSpace styleColorSpace, const IntRect& r, CompositeOperator op, bool useLowQualityScale)
+{
+    drawImage(image, styleColorSpace, r, IntRect(0, 0, -1, -1), op, useLowQualityScale);
+}
+
+void GraphicsContext::drawImage(Image* image, ColorSpace styleColorSpace, const IntPoint& dest, const IntRect& srcRect, CompositeOperator op)
+{
+    drawImage(image, styleColorSpace, IntRect(dest, srcRect.size()), srcRect, op);
+}
+
+void GraphicsContext::drawImage(Image* image, ColorSpace styleColorSpace, const IntRect& dest, const IntRect& srcRect, CompositeOperator op, bool useLowQualityScale)
+{
+    drawImage(image, styleColorSpace, FloatRect(dest), srcRect, op, useLowQualityScale);
+}
+
 #if !OS(WINCE) || (PLATFORM(QT) && !HAVE(QRAWFONT))
 void GraphicsContext::drawText(const Font& font, const TextRun& run, const FloatPoint& point, int from, int to)
 {
@@ -413,26 +433,6 @@
     fillRect(font.selectionRectForText(run, point, h, from, to), backgroundColor, colorSpace);
 }
 
-void GraphicsContext::drawImage(Image* image, ColorSpace styleColorSpace, const IntPoint& p, CompositeOperator op)
-{
-    drawImage(image, styleColorSpace, p, IntRect(0, 0, -1, -1), op);
-}
-
-void GraphicsContext::drawImage(Image* image, ColorSpace styleColorSpace, const IntRect& r, CompositeOperator op, bool useLowQualityScale)
-{
-    drawImage(image, styleColorSpace, r, IntRect(0, 0, -1, -1), op, useLowQualityScale);
-}
-
-void GraphicsContext::drawImage(Image* image, ColorSpace styleColorSpace, const IntPoint& dest, const IntRect& srcRect, CompositeOperator op)
-{
-    drawImage(image, styleColorSpace, IntRect(dest, srcRect.size()), srcRect, op);
-}
-
-void GraphicsContext::drawImage(Image* image, ColorSpace styleColorSpace, const IntRect& dest, const IntRect& srcRect, CompositeOperator op, bool useLowQualityScale)
-{
-    drawImage(image, styleColorSpace, FloatRect(dest), srcRect, op, useLowQualityScale);
-}
-
 void GraphicsContext::drawImage(Image* image, ColorSpace styleColorSpace, const FloatRect& dest, const FloatRect& src, CompositeOperator op, bool useLowQualityScale)
 {
     if (paintingDisabled() || !image)

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.h (91445 => 91446)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext.h	2011-07-21 05:49:22 UTC (rev 91445)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.h	2011-07-21 05:56:42 UTC (rev 91446)
@@ -265,8 +265,6 @@
         void applyFillPattern();
         void drawPath(const Path&);
         
-        void drawNativeImage(NativeImagePtr, const FloatSize& selfSize, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator = CompositeSourceOver);
-
         // Allow font smoothing (LCD antialiasing). Not part of the graphics state.
         void setAllowsFontSmoothing(bool);
         

Modified: trunk/Source/WebCore/platform/graphics/Image.h (91445 => 91446)


--- trunk/Source/WebCore/platform/graphics/Image.h	2011-07-21 05:49:22 UTC (rev 91445)
+++ trunk/Source/WebCore/platform/graphics/Image.h	2011-07-21 05:56:42 UTC (rev 91446)
@@ -141,7 +141,6 @@
     virtual CGImageRef getCGImageRef() { return 0; }
     virtual CGImageRef getFirstCGImageRefOfSize(const IntSize&) { return 0; }
     virtual RetainPtr<CFArrayRef> getCGImageArray() { return 0; }
-    static RetainPtr<CGImageRef> imageWithColorSpace(CGImageRef originalImage, ColorSpace);
 #endif
 
 #if PLATFORM(WIN)

Modified: trunk/Source/WebCore/platform/graphics/ImageBuffer.h (91445 => 91446)


--- trunk/Source/WebCore/platform/graphics/ImageBuffer.h	2011-07-21 05:49:22 UTC (rev 91445)
+++ trunk/Source/WebCore/platform/graphics/ImageBuffer.h	2011-07-21 05:56:42 UTC (rev 91446)
@@ -58,11 +58,6 @@
         Unaccelerated,
         Accelerated
     };
-    
-    enum BackingStoreCopy {
-        CopyBackingStore, // Guarantee subsequent draws don't affect the copy.
-        DontCopyBackingStore // Subsequent draws may affect the copy.
-    };
 
     class ImageBuffer {
         WTF_MAKE_NONCOPYABLE(ImageBuffer); WTF_MAKE_FAST_ALLOCATED;
@@ -88,7 +83,7 @@
         GraphicsContext* context() const;
 
         bool isAccelerated() const { return m_accelerateRendering; }
-        PassRefPtr<Image> copyImage(BackingStoreCopy copyPreference = CopyBackingStore) const;
+        PassRefPtr<Image> copyImage() const; // Return a new image that is a copy of the buffer.
 
         PassRefPtr<ByteArray> getUnmultipliedImageData(const IntRect&) const;
         PassRefPtr<ByteArray> getPremultipliedImageData(const IntRect&) const;
@@ -108,15 +103,14 @@
 #endif
 
     private:
-#if USE(CG)
-        NativeImagePtr copyNativeImage(BackingStoreCopy copyPreference = CopyBackingStore) const;
-#endif
-
         void clip(GraphicsContext*, const FloatRect&) const;
 
-        void draw(GraphicsContext*, ColorSpace, const FloatRect& destRect, const FloatRect& srcRect = FloatRect(0, 0, -1, -1), CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false);
-        void drawPattern(GraphicsContext*, const FloatRect& srcRect, const AffineTransform& patternTransform, const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator, const FloatRect& destRect);
-
+        // The draw method draws the contents of the buffer without copying it.
+        void draw(GraphicsContext*, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect = FloatRect(0, 0, -1, -1),
+                             CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false);
+        void drawPattern(GraphicsContext*, const FloatRect& srcRect, const AffineTransform& patternTransform,
+                         const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator, const FloatRect& destRect);
+        
         inline void genericConvertToLuminanceMask();
 
         friend class GraphicsContext;

Modified: trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp (91445 => 91446)


--- trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp	2011-07-21 05:49:22 UTC (rev 91445)
+++ trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp	2011-07-21 05:56:42 UTC (rev 91446)
@@ -86,9 +86,8 @@
     return m_context.get();
 }
 
-PassRefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyPreference) const
+PassRefPtr<Image> ImageBuffer::copyImage() const
 {
-    ASSERT(copyPreference == CopyBackingStore);
     // BitmapImage will release the passed in surface on destruction
     return BitmapImage::create(copyCairoImageSurface(m_data.m_surface).leakRef());
 }

Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp (91445 => 91446)


--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp	2011-07-21 05:49:22 UTC (rev 91445)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp	2011-07-21 05:56:42 UTC (rev 91446)
@@ -152,79 +152,6 @@
     m_data->m_userToDeviceTransformKnownToBeIdentity = false;
 }
 
-void GraphicsContext::drawNativeImage(NativeImagePtr imagePtr, const FloatSize& imageSize, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op)
-{
-    RetainPtr<CGImageRef> image(imagePtr);
-
-    float currHeight = CGImageGetHeight(image.get());
-    if (currHeight <= srcRect.y())
-        return;
-
-    CGContextRef context = platformContext();
-    CGContextSaveGState(context);
-
-    bool shouldUseSubimage = false;
-
-    // If the source rect is a subportion of the image, then we compute an inflated destination rect that will hold the entire image
-    // and then set a clip to the portion that we want to display.
-    FloatRect adjustedDestRect = destRect;
-
-    if (srcRect.size() != imageSize) {
-        CGInterpolationQuality interpolationQuality = CGContextGetInterpolationQuality(context);
-        // When the image is scaled using high-quality interpolation, we create a temporary CGImage
-        // containing only the portion we want to display. We need to do this because high-quality
-        // interpolation smoothes sharp edges, causing pixels from outside the source rect to bleed
-        // into the destination rect. See <rdar://problem/6112909>.
-        shouldUseSubimage = (interpolationQuality != kCGInterpolationNone) && (srcRect.size() != destRect.size() || !getCTM().isIdentityOrTranslationOrFlipped());
-        float xScale = srcRect.width() / destRect.width();
-        float yScale = srcRect.height() / destRect.height();
-        if (shouldUseSubimage) {
-            FloatRect subimageRect = srcRect;
-            float leftPadding = srcRect.x() - floorf(srcRect.x());
-            float topPadding = srcRect.y() - floorf(srcRect.y());
-
-            subimageRect.move(-leftPadding, -topPadding);
-            adjustedDestRect.move(-leftPadding / xScale, -topPadding / yScale);
-
-            subimageRect.setWidth(ceilf(subimageRect.width() + leftPadding));
-            adjustedDestRect.setWidth(subimageRect.width() / xScale);
-
-            subimageRect.setHeight(ceilf(subimageRect.height() + topPadding));
-            adjustedDestRect.setHeight(subimageRect.height() / yScale);
-
-            image.adoptCF(CGImageCreateWithImageInRect(image.get(), subimageRect));
-            if (currHeight < srcRect.maxY()) {
-                ASSERT(CGImageGetHeight(image.get()) == currHeight - CGRectIntegral(srcRect).origin.y);
-                adjustedDestRect.setHeight(CGImageGetHeight(image.get()) / yScale);
-            }
-        } else {
-            adjustedDestRect.setLocation(FloatPoint(destRect.x() - srcRect.x() / xScale, destRect.y() - srcRect.y() / yScale));
-            adjustedDestRect.setSize(FloatSize(imageSize.width() / xScale, imageSize.height() / yScale));
-        }
-
-        if (!destRect.contains(adjustedDestRect))
-            CGContextClipToRect(context, destRect);
-    }
-
-    // If the image is only partially loaded, then shrink the destination rect that we're drawing into accordingly.
-    if (!shouldUseSubimage && currHeight < imageSize.height())
-        adjustedDestRect.setHeight(adjustedDestRect.height() * currHeight / imageSize.height());
-
-    setPlatformCompositeOperation(op);
-
-    // Flip the coords.
-    CGContextScaleCTM(context, 1, -1);
-    adjustedDestRect.setY(-adjustedDestRect.maxY());
-    
-    // Adjust the color space.
-    image = Image::imageWithColorSpace(image.get(), styleColorSpace);
-
-    // Draw the image.
-    CGContextDrawImage(context, adjustedDestRect, image.get());
-
-    CGContextRestoreGState(context);
-}
-
 // Draws a filled rectangle with a stroked border.
 void GraphicsContext::drawRect(const IntRect& rect)
 {

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp (91445 => 91446)


--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp	2011-07-21 05:49:22 UTC (rev 91445)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp	2011-07-21 05:56:42 UTC (rev 91446)
@@ -177,74 +177,72 @@
     return m_context.get();
 }
 
-PassRefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyPreference) const
+PassRefPtr<Image> ImageBuffer::copyImage() const
 {
-    RetainPtr<CGImageRef> image = copyNativeImage(copyPreference);
+    // BitmapImage will release the passed in CGImage on destruction
+    CGImageRef ctxImage = 0;
+    if (!m_accelerateRendering)
+        ctxImage = CGBitmapContextCreateImage(context()->platformContext());
+#if USE(IOSURFACE_CANVAS_BACKING_STORE)
+    else
+        ctxImage = wkIOSurfaceContextCreateImage(context()->platformContext());
+#endif
+    return BitmapImage::create(ctxImage);
+}
 
-    if (!image)
-        return 0;
-
-    return BitmapImage::create(image.get());
+static CGImageRef cgImage(const IntSize& size, const ImageBufferData& data)
+{
+    return CGImageCreate(size.width(), size.height(), 8, 32, data.m_bytesPerRow,
+                         data.m_colorSpace, data.m_bitmapInfo, data.m_dataProvider.get(), 0, true, kCGRenderingIntentDefault);
 }
 
-NativeImagePtr ImageBuffer::copyNativeImage(BackingStoreCopy copyPreference) const
+void ImageBuffer::draw(GraphicsContext* destContext, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect,
+                       CompositeOperator op, bool useLowQualityScale)
 {
-    CGImageRef image = 0;
     if (!m_accelerateRendering) {
-        switch (copyPreference) {
-        case DontCopyBackingStore:
-            image = CGImageCreate(m_size.width(), m_size.height(), 8, 32, m_data.m_bytesPerRow, m_data.m_colorSpace, m_data.m_bitmapInfo, m_data.m_dataProvider.get(), 0, true, kCGRenderingIntentDefault);
-            break;
-        case CopyBackingStore:
-            image = CGBitmapContextCreateImage(context()->platformContext());
-            break;
-        default:
-            ASSERT_NOT_REACHED();
-            break;
+        if (destContext == context()) {
+            // We're drawing into our own buffer.  In order for this to work, we need to copy the source buffer first.
+            RefPtr<Image> copy = copyImage();
+            destContext->drawImage(copy.get(), ColorSpaceDeviceRGB, destRect, srcRect, op, useLowQualityScale);
+        } else {
+            RefPtr<Image> imageForRendering = BitmapImage::create(cgImage(m_size, m_data));
+            destContext->drawImage(imageForRendering.get(), styleColorSpace, destRect, srcRect, op, useLowQualityScale);
         }
+    } else {
+        RefPtr<Image> copy = copyImage();
+        ColorSpace colorSpace = (destContext == context()) ? ColorSpaceDeviceRGB : styleColorSpace;
+        destContext->drawImage(copy.get(), colorSpace, destRect, srcRect, op, useLowQualityScale);
     }
-#if USE(IOSURFACE_CANVAS_BACKING_STORE)
-    else
-        image = wkIOSurfaceContextCreateImage(context()->platformContext());
-#endif
-
-    return image;
 }
 
-void ImageBuffer::draw(GraphicsContext* destContext, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, bool useLowQualityScale)
+void ImageBuffer::drawPattern(GraphicsContext* destContext, const FloatRect& srcRect, const AffineTransform& patternTransform,
+                              const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect)
 {
-    ASSERT_UNUSED(useLowQualityScale, !useLowQualityScale);
-    ColorSpace colorSpace = (destContext == m_context) ? ColorSpaceDeviceRGB : styleColorSpace;
-
-    RetainPtr<CGImageRef> image;
-    if (destContext == m_context)
-        image.adoptCF(copyNativeImage(CopyBackingStore)); // Drawing into our own buffer, need to deep copy.
-    else
-        image.adoptCF(copyNativeImage(DontCopyBackingStore));
-
-    destContext->drawNativeImage(image.get(), m_size, colorSpace, destRect, srcRect, op);
-}
-
-void ImageBuffer::drawPattern(GraphicsContext* context, const FloatRect& srcRect, const AffineTransform& patternTransform, const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect)
-{
     if (!m_accelerateRendering) {
-        if (context == m_context) {
-            RefPtr<Image> copy = copyImage(CopyBackingStore); // Drawing into our own buffer, need to deep copy.
-            copy->drawPattern(context, srcRect, patternTransform, phase, styleColorSpace, op, destRect);
+        if (destContext == context()) {
+            // We're drawing into our own buffer.  In order for this to work, we need to copy the source buffer first.
+            RefPtr<Image> copy = copyImage();
+            copy->drawPattern(destContext, srcRect, patternTransform, phase, styleColorSpace, op, destRect);
         } else {
-            RefPtr<Image> imageForRendering = copyImage(DontCopyBackingStore);
-            imageForRendering->drawPattern(context, srcRect, patternTransform, phase, styleColorSpace, op, destRect);
+            RefPtr<Image> imageForRendering = BitmapImage::create(cgImage(m_size, m_data));
+            imageForRendering->drawPattern(destContext, srcRect, patternTransform, phase, styleColorSpace, op, destRect);
         }
     } else {
-        RefPtr<Image> copy = copyImage(CopyBackingStore);
-        copy->drawPattern(context, srcRect, patternTransform, phase, styleColorSpace, op, destRect);
+        RefPtr<Image> copy = copyImage();
+        copy->drawPattern(destContext, srcRect, patternTransform, phase, styleColorSpace, op, destRect);
     }
 }
 
 void ImageBuffer::clip(GraphicsContext* contextToClip, const FloatRect& rect) const
 {
     CGContextRef platformContextToClip = contextToClip->platformContext();
-    RetainPtr<CGImageRef> image(AdoptCF, copyNativeImage(DontCopyBackingStore));
+    RetainPtr<CGImageRef> image;
+    if (!m_accelerateRendering)
+        image.adoptCF(cgImage(m_size, m_data));
+#if USE(IOSURFACE_CANVAS_BACKING_STORE)
+    else
+        image.adoptCF(wkIOSurfaceContextCreateImage(context()->platformContext()));
+#endif
     CGContextTranslateCTM(platformContextToClip, rect.x(), rect.y() + rect.height());
     CGContextScaleCTM(platformContextToClip, 1, -1);
     CGContextClipToMask(platformContextToClip, FloatRect(FloatPoint(), rect.size()), image.get());
@@ -348,7 +346,13 @@
 {
     ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
 
-    RetainPtr<CGImageRef> image(AdoptCF, copyNativeImage(CopyBackingStore));
+    RetainPtr<CGImageRef> image;
+    if (!m_accelerateRendering)
+        image.adoptCF(CGBitmapContextCreateImage(context()->platformContext()));
+#if USE(IOSURFACE_CANVAS_BACKING_STORE)
+    else
+        image.adoptCF(wkIOSurfaceContextCreateImage(context()->platformContext()));
+#endif
 
     if (!image)
         return "data:,";

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageCG.cpp (91445 => 91446)


--- trunk/Source/WebCore/platform/graphics/cg/ImageCG.cpp	2011-07-21 05:49:22 UTC (rev 91445)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageCG.cpp	2011-07-21 05:56:42 UTC (rev 91446)
@@ -128,7 +128,7 @@
     }
 }
 
-RetainPtr<CGImageRef> Image::imageWithColorSpace(CGImageRef originalImage, ColorSpace colorSpace)
+static RetainPtr<CGImageRef> imageWithColorSpace(CGImageRef originalImage, ColorSpace colorSpace)
 {
     CGColorSpaceRef originalColorSpace = CGImageGetColorSpace(originalImage);
 
@@ -195,10 +195,74 @@
         return;
     }
 
+    float currHeight = CGImageGetHeight(image.get());
+    if (currHeight <= srcRect.y())
+        return;
+
+    CGContextRef context = ctxt->platformContext();
+    GraphicsContextStateSaver stateSaver(*ctxt);
+
+    bool shouldUseSubimage = false;
+
+    // If the source rect is a subportion of the image, then we compute an inflated destination rect that will hold the entire image
+    // and then set a clip to the portion that we want to display.
+    FloatRect adjustedDestRect = destRect;
     FloatSize selfSize = currentFrameSize();
+    if (srcRect.size() != selfSize) {
+        CGInterpolationQuality interpolationQuality = CGContextGetInterpolationQuality(context);
+        // When the image is scaled using high-quality interpolation, we create a temporary CGImage
+        // containing only the portion we want to display. We need to do this because high-quality
+        // interpolation smoothes sharp edges, causing pixels from outside the source rect to bleed
+        // into the destination rect. See <rdar://problem/6112909>.
+        shouldUseSubimage = (interpolationQuality != kCGInterpolationNone) && (srcRect.size() != destRect.size() || !ctxt->getCTM().isIdentityOrTranslationOrFlipped());
+        float xScale = srcRect.width() / destRect.width();
+        float yScale = srcRect.height() / destRect.height();
+        if (shouldUseSubimage) {
+            FloatRect subimageRect = srcRect;
+            float leftPadding = srcRect.x() - floorf(srcRect.x());
+            float topPadding = srcRect.y() - floorf(srcRect.y());
 
-    ctxt->drawNativeImage(image.get(), selfSize, styleColorSpace, destRect, srcRect, compositeOp);
+            subimageRect.move(-leftPadding, -topPadding);
+            adjustedDestRect.move(-leftPadding / xScale, -topPadding / yScale);
 
+            subimageRect.setWidth(ceilf(subimageRect.width() + leftPadding));
+            adjustedDestRect.setWidth(subimageRect.width() / xScale);
+
+            subimageRect.setHeight(ceilf(subimageRect.height() + topPadding));
+            adjustedDestRect.setHeight(subimageRect.height() / yScale);
+
+            image.adoptCF(CGImageCreateWithImageInRect(image.get(), subimageRect));
+            if (currHeight < srcRect.maxY()) {
+                ASSERT(CGImageGetHeight(image.get()) == currHeight - CGRectIntegral(srcRect).origin.y);
+                adjustedDestRect.setHeight(CGImageGetHeight(image.get()) / yScale);
+            }
+        } else {
+            adjustedDestRect.setLocation(FloatPoint(destRect.x() - srcRect.x() / xScale, destRect.y() - srcRect.y() / yScale));
+            adjustedDestRect.setSize(FloatSize(selfSize.width() / xScale, selfSize.height() / yScale));
+        }
+
+        if (!destRect.contains(adjustedDestRect))
+            CGContextClipToRect(context, destRect);
+    }
+
+    // If the image is only partially loaded, then shrink the destination rect that we're drawing into accordingly.
+    if (!shouldUseSubimage && currHeight < selfSize.height())
+        adjustedDestRect.setHeight(adjustedDestRect.height() * currHeight / selfSize.height());
+
+    ctxt->setCompositeOperation(compositeOp);
+
+    // Flip the coords.
+    CGContextScaleCTM(context, 1, -1);
+    adjustedDestRect.setY(-adjustedDestRect.maxY());
+
+    // Adjust the color space.
+    image = imageWithColorSpace(image.get(), styleColorSpace);
+
+    // Draw the image.
+    CGContextDrawImage(context, adjustedDestRect, image.get());
+
+    stateSaver.restore();
+
     if (imageObserver())
         imageObserver()->didDraw(this);
 }
@@ -249,7 +313,7 @@
     }
 
     // Adjust the color space.
-    subImage = Image::imageWithColorSpace(subImage.get(), styleColorSpace);
+    subImage = imageWithColorSpace(subImage.get(), styleColorSpace);
     
     // Leopard has an optimized call for the tiling of image patterns, but we can only use it if the image has been decoded enough that
     // its buffer is the same size as the overall image.  Because a partially decoded CGImageRef with a smaller width or height than the

Modified: trunk/Source/WebCore/platform/graphics/filters/FETile.cpp (91445 => 91446)


--- trunk/Source/WebCore/platform/graphics/filters/FETile.cpp	2011-07-21 05:49:22 UTC (rev 91445)
+++ trunk/Source/WebCore/platform/graphics/filters/FETile.cpp	2011-07-21 05:56:42 UTC (rev 91446)
@@ -79,7 +79,7 @@
     tileImageContext->translate(-inMaxEffectLocation.x(), -inMaxEffectLocation.y());
     tileImageContext->drawImageBuffer(in->asImageBuffer(), ColorSpaceDeviceRGB, in->absolutePaintRect().location());
 
-    RefPtr<Pattern> pattern = Pattern::create(tileImage->copyImage(CopyBackingStore), true, true);
+    RefPtr<Pattern> pattern = Pattern::create(tileImage->copyImage(), true, true);
 
     AffineTransform patternTransform;
     patternTransform.translate(inMaxEffectLocation.x() - maxEffectLocation.x(), inMaxEffectLocation.y() - maxEffectLocation.y());

Modified: trunk/Source/WebCore/platform/graphics/qt/ImageBufferQt.cpp (91445 => 91446)


--- trunk/Source/WebCore/platform/graphics/qt/ImageBufferQt.cpp	2011-07-21 05:49:22 UTC (rev 91445)
+++ trunk/Source/WebCore/platform/graphics/qt/ImageBufferQt.cpp	2011-07-21 05:56:42 UTC (rev 91446)
@@ -121,9 +121,8 @@
     return m_context.get();
 }
 
-PassRefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyPreference) const
+PassRefPtr<Image> ImageBuffer::copyImage() const
 {
-    ASSERT(copyPreference == CopyBackingStore);
     return StillImage::create(m_data.m_pixmap);
 }
 
@@ -132,7 +131,7 @@
 {
     if (destContext == context()) {
         // We're drawing into our own buffer.  In order for this to work, we need to copy the source buffer first.
-        RefPtr<Image> copy = copyImage(CopyBackingStore);
+        RefPtr<Image> copy = copyImage();
         destContext->drawImage(copy.get(), ColorSpaceDeviceRGB, destRect, srcRect, op, useLowQualityScale);
     } else
         destContext->drawImage(m_data.m_image.get(), styleColorSpace, destRect, srcRect, op, useLowQualityScale);
@@ -143,7 +142,7 @@
 {
     if (destContext == context()) {
         // We're drawing into our own buffer.  In order for this to work, we need to copy the source buffer first.
-        RefPtr<Image> copy = copyImage(CopyBackingStore);
+        RefPtr<Image> copy = copyImage();
         copy->drawPattern(destContext, srcRect, patternTransform, phase, styleColorSpace, op, destRect);
     } else
         m_data.m_image->drawPattern(destContext, srcRect, patternTransform, phase, styleColorSpace, op, destRect);

Modified: trunk/Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp (91445 => 91446)


--- trunk/Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp	2011-07-21 05:49:22 UTC (rev 91445)
+++ trunk/Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp	2011-07-21 05:56:42 UTC (rev 91446)
@@ -97,9 +97,8 @@
     return m_size.width() * m_size.height() * 4;
 }
 
-PassRefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyPreference) const
+PassRefPtr<Image> ImageBuffer::copyImage() const
 {
-    ASSERT(copyPreference == CopyBackingStore);
     m_context->platformContext()->makeGrContextCurrent();
     return BitmapImageSingleFrameSkia::create(*m_data.m_platformContext.bitmap(), true);
 }

Modified: trunk/Source/WebCore/platform/graphics/wince/ImageBufferWinCE.cpp (91445 => 91446)


--- trunk/Source/WebCore/platform/graphics/wince/ImageBufferWinCE.cpp	2011-07-21 05:49:22 UTC (rev 91445)
+++ trunk/Source/WebCore/platform/graphics/wince/ImageBufferWinCE.cpp	2011-07-21 05:56:42 UTC (rev 91446)
@@ -98,9 +98,8 @@
     return m_context.get();
 }
 
-PassRefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyPreference) const
+PassRefPtr<Image> ImageBuffer::copyImage() const
 {
-    ASSERT(copyPreference == CopyBackingStore);
     return adoptRef(new BufferedImage(&m_data));
 }
 
@@ -112,14 +111,14 @@
 void ImageBuffer::draw(GraphicsContext* context, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect,
                        CompositeOperator op , bool useLowQualityScale)
 {
-    RefPtr<Image> imageCopy = copyImage(CopyBackingStore);
+    RefPtr<Image> imageCopy = copyImage();
     context->drawImage(imageCopy.get(), styleColorSpace, destRect, srcRect, op, useLowQualityScale);
 }
 
 void ImageBuffer::drawPattern(GraphicsContext* context, const FloatRect& srcRect, const AffineTransform& patternTransform,
                               const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect)
 {
-    RefPtr<Image> imageCopy = copyImage(CopyBackingStore);
+    RefPtr<Image> imageCopy = copyImage();
     imageCopy->drawPattern(context, srcRect, patternTransform, phase, styleColorSpace, op, destRect);
 }
 

Modified: trunk/Source/WebCore/platform/graphics/wx/ImageBufferWx.cpp (91445 => 91446)


--- trunk/Source/WebCore/platform/graphics/wx/ImageBufferWx.cpp	2011-07-21 05:49:22 UTC (rev 91445)
+++ trunk/Source/WebCore/platform/graphics/wx/ImageBufferWx.cpp	2011-07-21 05:56:42 UTC (rev 91446)
@@ -88,9 +88,8 @@
     return String();
 }
 
-PassRefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyPreference) const
+PassRefPtr<Image> ImageBuffer::copyImage() const
 {
-    ASSERT(copyPreference == CopyBackingStore);
     notImplemented();
     return 0;
 }
@@ -103,14 +102,14 @@
 void ImageBuffer::draw(GraphicsContext* context, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect,
                        CompositeOperator op, bool useLowQualityScale)
 {
-    RefPtr<Image> imageCopy = copyImage(CopyBackingStore);
+    RefPtr<Image> imageCopy = copyImage();
     context->drawImage(imageCopy.get(), styleColorSpace, destRect, srcRect, op, useLowQualityScale);
 }
 
 void ImageBuffer::drawPattern(GraphicsContext* context, const FloatRect& srcRect, const AffineTransform& patternTransform,
                               const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect)
 {
-    RefPtr<Image> imageCopy = copyImage(CopyBackingStore);
+    RefPtr<Image> imageCopy = copyImage();
     imageCopy->drawPattern(context, srcRect, patternTransform, phase, styleColorSpace, op, destRect);
 }
 

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourcePattern.cpp (91445 => 91446)


--- trunk/Source/WebCore/rendering/svg/RenderSVGResourcePattern.cpp	2011-07-21 05:49:22 UTC (rev 91445)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourcePattern.cpp	2011-07-21 05:56:42 UTC (rev 91446)
@@ -124,7 +124,7 @@
         if (!tileImage)
             return false;
 
-        RefPtr<Image> copiedImage = tileImage->copyImage(CopyBackingStore);
+        RefPtr<Image> copiedImage = tileImage->copyImage();
         if (!copiedImage)
             return false;
 

Modified: trunk/Source/WebCore/svg/SVGFEImageElement.cpp (91445 => 91446)


--- trunk/Source/WebCore/svg/SVGFEImageElement.cpp	2011-07-21 05:49:22 UTC (rev 91445)
+++ trunk/Source/WebCore/svg/SVGFEImageElement.cpp	2011-07-21 05:56:42 UTC (rev 91446)
@@ -178,7 +178,7 @@
         SVGImageBufferTools::renderSubtreeToImageBuffer(m_targetImage.get(), renderer, contentTransformation);
     }
 
-    return FEImage::create(filter, m_targetImage ? m_targetImage->copyImage(CopyBackingStore) : m_cachedImage->image(), preserveAspectRatio());
+    return FEImage::create(filter, m_targetImage ? m_targetImage->copyImage() : m_cachedImage->image(), preserveAspectRatio());
 }
 
 void SVGFEImageElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const

Modified: trunk/Source/WebCore/svg/graphics/SVGImage.cpp (91445 => 91446)


--- trunk/Source/WebCore/svg/graphics/SVGImage.cpp	2011-07-21 05:49:22 UTC (rev 91445)
+++ trunk/Source/WebCore/svg/graphics/SVGImage.cpp	2011-07-21 05:56:42 UTC (rev 91446)
@@ -227,7 +227,7 @@
         if (!buffer) // failed to allocate image
             return 0;
         draw(buffer->context(), rect(), rect(), ColorSpaceDeviceRGB, CompositeSourceOver);
-        m_frameCache = buffer->copyImage(CopyBackingStore);
+        m_frameCache = buffer->copyImage();
     }
     return m_frameCache->nativeImageForCurrentFrame();
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to