This source file includes following definitions.
- draw
- drawPattern
#include "config.h"
#include "platform/graphics/GradientGeneratedImage.h"
#include "platform/geometry/FloatRect.h"
#include "platform/graphics/GraphicsContextStateSaver.h"
namespace WebCore {
void GradientGeneratedImage::draw(GraphicsContext* destContext, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator compositeOp, blink::WebBlendMode 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->setFillGradient(m_gradient);
destContext->fillRect(FloatRect(FloatPoint(), m_size));
}
void GradientGeneratedImage::drawPattern(GraphicsContext* destContext, const FloatRect& srcRect, const FloatSize& scale,
const FloatPoint& phase, CompositeOperator compositeOp, const FloatRect& destRect, blink::WebBlendMode blendMode, const IntSize& repeatSpacing)
{
float stepX = srcRect.width() + repeatSpacing.width();
float stepY = srcRect.height() + repeatSpacing.height();
int firstColumn = static_cast<int>(floorf((((destRect.x() - phase.x()) / scale.width()) - srcRect.x()) / srcRect.width()));
int firstRow = static_cast<int>(floorf((((destRect.y() - phase.y()) / scale.height()) - srcRect.y()) / srcRect.height()));
for (int i = firstColumn; ; ++i) {
float dstX = (srcRect.x() + i * stepX) * scale.width() + phase.x();
ASSERT(i > firstColumn || dstX <= destRect.x());
ASSERT(i == firstColumn || dstX > destRect.x());
if (dstX >= destRect.maxX())
break;
float dstMaxX = dstX + srcRect.width() * scale.width();
if (dstX < destRect.x())
dstX = destRect.x();
if (dstMaxX > destRect.maxX())
dstMaxX = destRect.maxX();
if (dstX >= dstMaxX)
continue;
FloatRect visibleSrcRect;
FloatRect tileDstRect;
tileDstRect.setX(dstX);
tileDstRect.setWidth(dstMaxX - dstX);
visibleSrcRect.setX((tileDstRect.x() - phase.x()) / scale.width() - i * stepX);
visibleSrcRect.setWidth(tileDstRect.width() / scale.width());
for (int j = firstRow; ; j++) {
float dstY = (srcRect.y() + j * stepY) * scale.height() + phase.y();
ASSERT(j > firstRow || dstY <= destRect.y());
ASSERT(j == firstRow || dstY > destRect.y());
if (dstY >= destRect.maxY())
break;
float dstMaxY = dstY + srcRect.height() * scale.height();
if (dstY < destRect.y())
dstY = destRect.y();
if (dstMaxY > destRect.maxY())
dstMaxY = destRect.maxY();
if (dstY >= dstMaxY)
continue;
tileDstRect.setY(dstY);
tileDstRect.setHeight(dstMaxY - dstY);
visibleSrcRect.setY((tileDstRect.y() - phase.y()) / scale.height() - j * stepY);
visibleSrcRect.setHeight(tileDstRect.height() / scale.height());
draw(destContext, tileDstRect, visibleSrcRect, compositeOp, blendMode);
}
}
}
}