GeneratorGeneratedImage.cpp [plain text]
#include "config.h"
#include "GeneratorGeneratedImage.h"
#include "FloatRect.h"
#include "GraphicsContext.h"
#include "Length.h"
namespace WebCore {
void GeneratorGeneratedImage::draw(GraphicsContext* destContext, const FloatRect& destRect, const FloatRect& srcRect, ColorSpace, CompositeOperator compositeOp, BlendMode blendMode)
{
GraphicsContextStateSaver stateSaver(*destContext);
destContext->setCompositeOperation(compositeOp, blendMode);
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_gradient.get());
}
void GeneratorGeneratedImage::drawPattern(GraphicsContext* destContext, const FloatRect& srcRect, const AffineTransform& patternTransform,
const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator compositeOp, const FloatRect& destRect, BlendMode)
{
IntSize adjustedSize = m_size;
FloatRect adjustedSrcRect = srcRect;
m_gradient->adjustParametersForTiledDrawing(adjustedSize, adjustedSrcRect);
AffineTransform destContextCTM = destContext->getCTM(GraphicsContext::DefinitelyIncludeDeviceScale);
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);
unsigned generatorHash = m_gradient->hash();
if (!m_cachedImageBuffer || m_cachedGeneratorHash != generatorHash || m_cachedAdjustedSize != adjustedSize || !destContext->isCompatibleWithBuffer(m_cachedImageBuffer.get())) {
m_cachedImageBuffer = destContext->createCompatibleBuffer(adjustedSize, m_gradient->hasAlpha());
if (!m_cachedImageBuffer)
return;
m_cachedImageBuffer->context()->fillRect(FloatRect(FloatPoint(), adjustedSize), *m_gradient);
m_cachedGeneratorHash = generatorHash;
m_cachedAdjustedSize = adjustedSize;
}
m_cachedImageBuffer->drawPattern(destContext, adjustedSrcRect, adjustedPatternCTM, phase, styleColorSpace, compositeOp, destRect);
}
}