This source file includes following definitions.
- m_shouldCollectGradientAttributes
- removeAllClientsFromCache
- removeClientFromCache
- applyResource
- postApplyResource
- addStops
- platformSpreadMethodFromSVGType
#include "config.h"
#include "core/rendering/svg/RenderSVGResourceGradient.h"
#include "core/rendering/svg/RenderSVGShape.h"
#include "core/rendering/svg/SVGRenderSupport.h"
#include "platform/graphics/GraphicsContext.h"
namespace WebCore {
RenderSVGResourceGradient::RenderSVGResourceGradient(SVGGradientElement* node)
: RenderSVGResourceContainer(node)
, m_shouldCollectGradientAttributes(true)
{
}
void RenderSVGResourceGradient::removeAllClientsFromCache(bool markForInvalidation)
{
m_gradientMap.clear();
m_shouldCollectGradientAttributes = true;
markAllClientsForInvalidation(markForInvalidation ? RepaintInvalidation : ParentOnlyInvalidation);
}
void RenderSVGResourceGradient::removeClientFromCache(RenderObject* client, bool markForInvalidation)
{
ASSERT(client);
m_gradientMap.remove(client);
markClientForInvalidation(client, markForInvalidation ? RepaintInvalidation : ParentOnlyInvalidation);
}
bool RenderSVGResourceGradient::applyResource(RenderObject* object, RenderStyle* style, GraphicsContext*& context, unsigned short resourceMode)
{
ASSERT(object);
ASSERT(style);
ASSERT(context);
ASSERT(resourceMode != ApplyToDefaultMode);
clearInvalidationMask();
SVGGradientElement* gradientElement = toSVGGradientElement(element());
if (!gradientElement)
return false;
if (m_shouldCollectGradientAttributes) {
gradientElement->synchronizeAnimatedSVGAttribute(anyQName());
if (!collectGradientAttributes(gradientElement))
return false;
m_shouldCollectGradientAttributes = false;
}
FloatRect objectBoundingBox = object->objectBoundingBox();
if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && objectBoundingBox.isEmpty())
return false;
OwnPtr<GradientData>& gradientData = m_gradientMap.add(object, nullptr).storedValue->value;
if (!gradientData)
gradientData = adoptPtr(new GradientData);
bool isPaintingText = resourceMode & ApplyToTextMode;
if (!gradientData->gradient) {
buildGradient(gradientData.get());
if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && !objectBoundingBox.isEmpty()) {
gradientData->userspaceTransform.translate(objectBoundingBox.x(), objectBoundingBox.y());
gradientData->userspaceTransform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height());
}
AffineTransform gradientTransform;
calculateGradientTransform(gradientTransform);
gradientData->userspaceTransform *= gradientTransform;
if (isPaintingText) {
AffineTransform additionalTextTransform;
if (shouldTransformOnTextPainting(object, additionalTextTransform))
gradientData->userspaceTransform *= additionalTextTransform;
}
gradientData->gradient->setGradientSpaceTransform(gradientData->userspaceTransform);
}
if (!gradientData->gradient)
return false;
context->save();
if (isPaintingText)
context->setTextDrawingMode(resourceMode & ApplyToFillMode ? TextModeFill : TextModeStroke);
const SVGRenderStyle* svgStyle = style->svgStyle();
ASSERT(svgStyle);
if (resourceMode & ApplyToFillMode) {
context->setAlphaAsFloat(svgStyle->fillOpacity());
context->setFillGradient(gradientData->gradient);
context->setFillRule(svgStyle->fillRule());
} else if (resourceMode & ApplyToStrokeMode) {
if (svgStyle->vectorEffect() == VE_NON_SCALING_STROKE)
gradientData->gradient->setGradientSpaceTransform(transformOnNonScalingStroke(object, gradientData->userspaceTransform));
context->setAlphaAsFloat(svgStyle->strokeOpacity());
context->setStrokeGradient(gradientData->gradient);
SVGRenderSupport::applyStrokeStyleToContext(context, style, object);
}
return true;
}
void RenderSVGResourceGradient::postApplyResource(RenderObject*, GraphicsContext*& context, unsigned short resourceMode, const Path* path, const RenderSVGShape* shape)
{
ASSERT(context);
ASSERT(resourceMode != ApplyToDefaultMode);
if (resourceMode & ApplyToFillMode) {
if (path)
context->fillPath(*path);
else if (shape)
shape->fillShape(context);
}
if (resourceMode & ApplyToStrokeMode) {
if (path)
context->strokePath(*path);
else if (shape)
shape->strokeShape(context);
}
context->restore();
}
void RenderSVGResourceGradient::addStops(GradientData* gradientData, const Vector<Gradient::ColorStop>& stops) const
{
ASSERT(gradientData->gradient);
const Vector<Gradient::ColorStop>::const_iterator end = stops.end();
for (Vector<Gradient::ColorStop>::const_iterator it = stops.begin(); it != end; ++it)
gradientData->gradient->addColorStop(*it);
}
GradientSpreadMethod RenderSVGResourceGradient::platformSpreadMethodFromSVGType(SVGSpreadMethodType method) const
{
switch (method) {
case SVGSpreadMethodUnknown:
case SVGSpreadMethodPad:
return SpreadMethodPad;
case SVGSpreadMethodReflect:
return SpreadMethodReflect;
case SVGSpreadMethodRepeat:
return SpreadMethodRepeat;
}
ASSERT_NOT_REACHED();
return SpreadMethodPad;
}
}