Changeset 107157 in webkit


Ignore:
Timestamp:
Feb 8, 2012 5:30:54 PM (12 years ago)
Author:
mdelaney@apple.com
Message:

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.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r107149 r107157  
     12012-02-08  Matthew Delaney  <mdelaney@apple.com>
     2
     3        GeneratorGeneratedImage::drawPattern does not factor in its destination context's scale when generating its image tiles
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=67729
     6        <rdar://problem/10087050>
     7
     8        Reviewed by Beth Dakin.
     9
     10        No new tests, current pixel tests will cover this. Though some pixel results might improve to become less pixel-y.
     11
     12        * platform/graphics/GeneratorGeneratedImage.cpp:
     13        (WebCore::GeneratorGeneratedImage::draw): Updated context to destContext for consistency.
     14        (WebCore::GeneratorGeneratedImage::drawPattern): Taught drawPattern about the destination
     15        scale factor to avoid having low-res generated images such as gradients in certain cases.
     16        * platform/graphics/GraphicsContext.cpp:
     17        (WebCore::GraphicsContext::createCompatibleBuffer): Have the image buffer match the
     18        context acceleration setting as well.
     19
    1202012-02-08  Adam Klein  <adamk@chromium.org>
    221
  • trunk/Source/WebCore/platform/graphics/GeneratorGeneratedImage.cpp

    r102893 r107157  
    3434namespace WebCore {
    3535
    36 void GeneratorGeneratedImage::draw(GraphicsContext* context, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace, CompositeOperator compositeOp)
     36void GeneratorGeneratedImage::draw(GraphicsContext* destContext, const FloatRect& destRect, const FloatRect& srcRect, ColorSpace, CompositeOperator compositeOp)
    3737{
    38     GraphicsContextStateSaver stateSaver(*context);
    39     context->setCompositeOperation(compositeOp);
    40     context->clip(dstRect);
    41     context->translate(dstRect.x(), dstRect.y());
    42     if (dstRect.size() != srcRect.size())
    43         context->scale(FloatSize(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height()));
    44     context->translate(-srcRect.x(), -srcRect.y());
    45     context->fillRect(FloatRect(FloatPoint(), m_size), *m_generator.get());
     38    GraphicsContextStateSaver stateSaver(*destContext);
     39    destContext->setCompositeOperation(compositeOp);
     40    destContext->clip(destRect);
     41    destContext->translate(destRect.x(), destRect.y());
     42    if (destRect.size() != srcRect.size())
     43        destContext->scale(FloatSize(destRect.width() / srcRect.width(), destRect.height() / srcRect.height()));
     44    destContext->translate(-srcRect.x(), -srcRect.y());
     45    destContext->fillRect(FloatRect(FloatPoint(), m_size), *m_generator.get());
    4646}
    4747
    48 void GeneratorGeneratedImage::drawPattern(GraphicsContext* context, const FloatRect& srcRect, const AffineTransform& patternTransform,
     48void GeneratorGeneratedImage::drawPattern(GraphicsContext* destContext, const FloatRect& srcRect, const AffineTransform& patternTransform,
    4949                                 const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator compositeOp, const FloatRect& destRect)
    5050{
     
    5454    m_generator->adjustParametersForTiledDrawing(adjustedSize, adjustedSrcRect);
    5555
     56    // Factor in the destination context's scale to generate at the best resolution
     57    AffineTransform destContextCTM = destContext->getCTM();
     58    double xScale = fabs(destContextCTM.xScale());
     59    double yScale = fabs(destContextCTM.yScale());
     60    AffineTransform adjustedPatternCTM = patternTransform;
     61    adjustedPatternCTM.scale(1.0 / xScale, 1.0 / yScale);
     62    adjustedSrcRect.scale(xScale, yScale);
     63
    5664    // Create a BitmapImage and call drawPattern on it.
    57     OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(adjustedSize, ColorSpaceDeviceRGB, context->isAcceleratedContext() ? Accelerated : Unaccelerated);
     65    OwnPtr<ImageBuffer> imageBuffer = destContext->createCompatibleBuffer(adjustedSize);
    5866    if (!imageBuffer)
    5967        return;
     
    6472
    6573    // Tile the image buffer into the context.
    66     imageBuffer->drawPattern(context, adjustedSrcRect, patternTransform, phase, styleColorSpace, compositeOp, destRect);
     74    imageBuffer->drawPattern(destContext, adjustedSrcRect, adjustedPatternCTM, phase, styleColorSpace, compositeOp, destRect);
    6775}
    6876
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp

    r101556 r107157  
    755755    IntSize scaledSize(static_cast<int>(ceil(size.width() * transform.xScale())), static_cast<int>(ceil(size.height() * transform.yScale())));
    756756
    757     OwnPtr<ImageBuffer> buffer = ImageBuffer::create(scaledSize);
     757    OwnPtr<ImageBuffer> buffer = ImageBuffer::create(scaledSize, ColorSpaceDeviceRGB, isAcceleratedContext() ? Accelerated : Unaccelerated);
    758758    if (!buffer)
    759759        return nullptr;
Note: See TracChangeset for help on using the changeset viewer.