Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
CTTE: RenderSVGResourceMasker always has an SVGMaskElement.
<https://webkit.org/b/121344>

Reviewed by Brent Fulgham.

This renderer is never anonymous. Tighten things up with a maskElement()
reference getter. Removed some unnecessary null checks and assertions.

Canonical link: https://commits.webkit.org/139306@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@155749 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Andreas Kling committed Sep 14, 2013
1 parent e529d0a commit f01878a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
10 changes: 10 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,13 @@
2013-09-13 Andreas Kling <akling@apple.com>

CTTE: RenderSVGResourceMasker always has an SVGMaskElement.
<https://webkit.org/b/121344>

Reviewed by Brent Fulgham.

This renderer is never anonymous. Tighten things up with a maskElement()
reference getter. Removed some unnecessary null checks and assertions.

2013-09-13 Commit Queue <commit-queue@webkit.org>

Unreviewed, rolling out r155738.
Expand Down
25 changes: 9 additions & 16 deletions Source/WebCore/rendering/svg/RenderSVGResourceMasker.cpp
Expand Up @@ -41,8 +41,8 @@ namespace WebCore {

RenderSVGResourceType RenderSVGResourceMasker::s_resourceType = MaskerResourceType;

RenderSVGResourceMasker::RenderSVGResourceMasker(SVGMaskElement* node)
: RenderSVGResourceContainer(node)
RenderSVGResourceMasker::RenderSVGResourceMasker(SVGMaskElement& element)
: RenderSVGResourceContainer(&element)
{
}

Expand Down Expand Up @@ -84,18 +84,14 @@ bool RenderSVGResourceMasker::applyResource(RenderObject* object, RenderStyle*,
FloatRect repaintRect = object->repaintRectInLocalCoordinates();

if (!maskerData->maskImage && !repaintRect.isEmpty()) {
SVGMaskElement* maskElement = toSVGMaskElement(element());
if (!maskElement)
return false;

ASSERT(style());
const SVGRenderStyle* svgStyle = style()->svgStyle();
ASSERT(svgStyle);
ColorSpace colorSpace = svgStyle->colorInterpolation() == CI_LINEARRGB ? ColorSpaceLinearRGB : ColorSpaceDeviceRGB;
if (!SVGRenderingContext::createImageBuffer(repaintRect, absoluteTransform, maskerData->maskImage, colorSpace, Unaccelerated))
return false;

if (!drawContentIntoMaskImage(maskerData, colorSpace, maskElement, object)) {
if (!drawContentIntoMaskImage(maskerData, colorSpace, object)) {
maskerData->maskImage.clear();
}
}
Expand All @@ -107,22 +103,22 @@ bool RenderSVGResourceMasker::applyResource(RenderObject* object, RenderStyle*,
return true;
}

bool RenderSVGResourceMasker::drawContentIntoMaskImage(MaskerData* maskerData, ColorSpace colorSpace, const SVGMaskElement* maskElement, RenderObject* object)
bool RenderSVGResourceMasker::drawContentIntoMaskImage(MaskerData* maskerData, ColorSpace colorSpace, RenderObject* object)
{
GraphicsContext* maskImageContext = maskerData->maskImage->context();
ASSERT(maskImageContext);

// Eventually adjust the mask image context according to the target objectBoundingBox.
AffineTransform maskContentTransformation;
if (maskElement->maskContentUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
if (maskElement().maskContentUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
FloatRect objectBoundingBox = object->objectBoundingBox();
maskContentTransformation.translate(objectBoundingBox.x(), objectBoundingBox.y());
maskContentTransformation.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height());
maskImageContext->concatCTM(maskContentTransformation);
}

// Draw the content into the ImageBuffer.
for (Node* node = maskElement->firstChild(); node; node = node->nextSibling()) {
for (Node* node = maskElement().firstChild(); node; node = node->nextSibling()) {
RenderObject* renderer = node->renderer();
if (!node->isSVGElement() || !renderer)
continue;
Expand Down Expand Up @@ -151,7 +147,7 @@ bool RenderSVGResourceMasker::drawContentIntoMaskImage(MaskerData* maskerData, C

void RenderSVGResourceMasker::calculateMaskContentRepaintRect()
{
for (Node* childNode = element()->firstChild(); childNode; childNode = childNode->nextSibling()) {
for (Node* childNode = maskElement().firstChild(); childNode; childNode = childNode->nextSibling()) {
RenderObject* renderer = childNode->renderer();
if (!childNode->isSVGElement() || !renderer)
continue;
Expand All @@ -164,11 +160,8 @@ void RenderSVGResourceMasker::calculateMaskContentRepaintRect()

FloatRect RenderSVGResourceMasker::resourceBoundingBox(RenderObject* object)
{
SVGMaskElement* maskElement = toSVGMaskElement(element());
ASSERT(maskElement);

FloatRect objectBoundingBox = object->objectBoundingBox();
FloatRect maskBoundaries = SVGLengthContext::resolveRectangle<SVGMaskElement>(maskElement, maskElement->maskUnits(), objectBoundingBox);
FloatRect maskBoundaries = SVGLengthContext::resolveRectangle<SVGMaskElement>(&maskElement(), maskElement().maskUnits(), objectBoundingBox);

// Resource was not layouted yet. Give back clipping rect of the mask.
if (selfNeedsLayout())
Expand All @@ -178,7 +171,7 @@ FloatRect RenderSVGResourceMasker::resourceBoundingBox(RenderObject* object)
calculateMaskContentRepaintRect();

FloatRect maskRect = m_maskContentBoundaries;
if (maskElement->maskContentUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
if (maskElement().maskContentUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
AffineTransform transform;
transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height());
Expand Down
14 changes: 9 additions & 5 deletions Source/WebCore/rendering/svg/RenderSVGResourceMasker.h
Expand Up @@ -40,24 +40,28 @@ struct MaskerData {

class RenderSVGResourceMasker FINAL : public RenderSVGResourceContainer {
public:
RenderSVGResourceMasker(SVGMaskElement*);
explicit RenderSVGResourceMasker(SVGMaskElement&);
virtual ~RenderSVGResourceMasker();

virtual const char* renderName() const { return "RenderSVGResourceMasker"; }
SVGMaskElement& maskElement() const { return toSVGMaskElement(*RenderSVGResourceContainer::element()); }

virtual void removeAllClientsFromCache(bool markForInvalidation = true);
virtual void removeClientFromCache(RenderObject*, bool markForInvalidation = true);
virtual bool applyResource(RenderObject*, RenderStyle*, GraphicsContext*&, unsigned short resourceMode);
virtual FloatRect resourceBoundingBox(RenderObject*);

SVGUnitTypes::SVGUnitType maskUnits() const { return toSVGMaskElement(element())->maskUnits(); }
SVGUnitTypes::SVGUnitType maskContentUnits() const { return toSVGMaskElement(element())->maskContentUnits(); }
SVGUnitTypes::SVGUnitType maskUnits() const { return maskElement().maskUnits(); }
SVGUnitTypes::SVGUnitType maskContentUnits() const { return maskElement().maskContentUnits(); }

virtual RenderSVGResourceType resourceType() const { return s_resourceType; }
static RenderSVGResourceType s_resourceType;

private:
bool drawContentIntoMaskImage(MaskerData*, ColorSpace, const SVGMaskElement*, RenderObject*);
void element() const WTF_DELETED_FUNCTION;

virtual const char* renderName() const OVERRIDE { return "RenderSVGResourceMasker"; }

bool drawContentIntoMaskImage(MaskerData*, ColorSpace, RenderObject*);
void calculateMaskContentRepaintRect();

FloatRect m_maskContentBoundaries;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/rendering/svg/SVGResources.cpp
Expand Up @@ -653,7 +653,7 @@ void SVGResources::dump(const RenderObject* object)
fprintf(stderr, " |-> Filter : %p (node=%p)\n", filter, filter->element());
#endif
if (RenderSVGResourceMasker* masker = m_clipperFilterMaskerData->masker)
fprintf(stderr, " |-> Masker : %p (node=%p)\n", masker, masker->element());
fprintf(stderr, " |-> Masker : %p (node=%p)\n", masker, &masker->maskElement());
}

if (m_markerData) {
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/svg/SVGMaskElement.cpp
Expand Up @@ -159,7 +159,7 @@ void SVGMaskElement::childrenChanged(const ChildChange& change)

RenderObject* SVGMaskElement::createRenderer(RenderArena* arena, RenderStyle*)
{
return new (arena) RenderSVGResourceMasker(this);
return new (arena) RenderSVGResourceMasker(*this);
}

bool SVGMaskElement::selfHasRelativeLengths() const
Expand Down

0 comments on commit f01878a

Please sign in to comment.