• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
3  *               2009 Dirk Schulze <krit@webkit.org>
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #include "config.h"
28 
29 #if ENABLE(SVG)
30 #include "SVGResourceMasker.h"
31 
32 #include "CanvasPixelArray.h"
33 #include "Image.h"
34 #include "ImageBuffer.h"
35 #include "ImageData.h"
36 #include "GraphicsContext.h"
37 #include "RenderObject.h"
38 #include "SVGMaskElement.h"
39 #include "SVGRenderSupport.h"
40 #include "SVGRenderStyle.h"
41 #include "TextStream.h"
42 
43 using namespace std;
44 
45 namespace WebCore {
46 
SVGResourceMasker(const SVGMaskElement * ownerElement)47 SVGResourceMasker::SVGResourceMasker(const SVGMaskElement* ownerElement)
48     : SVGResource()
49     , m_ownerElement(ownerElement)
50     , m_emptyMask(false)
51 {
52 }
53 
~SVGResourceMasker()54 SVGResourceMasker::~SVGResourceMasker()
55 {
56 }
57 
invalidate()58 void SVGResourceMasker::invalidate()
59 {
60     SVGResource::invalidate();
61     m_mask.clear();
62     m_emptyMask = false;
63 }
64 
maskerBoundingBox(const FloatRect & objectBoundingBox) const65 FloatRect SVGResourceMasker::maskerBoundingBox(const FloatRect& objectBoundingBox) const
66 {
67     return m_ownerElement->maskBoundingBox(objectBoundingBox);
68 }
69 
applyMask(GraphicsContext * context,const RenderObject * object)70 bool SVGResourceMasker::applyMask(GraphicsContext* context, const RenderObject* object)
71 {
72     if (!m_mask && !m_emptyMask)
73         m_mask = m_ownerElement->drawMaskerContent(object, m_maskRect, m_emptyMask);
74 
75     if (!m_mask)
76         return false;
77 
78     context->clipToImageBuffer(m_maskRect, m_mask.get());
79     return true;
80 }
81 
externalRepresentation(TextStream & ts) const82 TextStream& SVGResourceMasker::externalRepresentation(TextStream& ts) const
83 {
84     ts << "[type=MASKER]";
85     return ts;
86 }
87 
getMaskerById(Document * document,const AtomicString & id,const RenderObject * object)88 SVGResourceMasker* getMaskerById(Document* document, const AtomicString& id, const RenderObject* object)
89 {
90     SVGResource* resource = getResourceById(document, id, object);
91     if (resource && resource->isMasker())
92         return static_cast<SVGResourceMasker*>(resource);
93 
94     return 0;
95 }
96 
97 } // namespace WebCore
98 
99 #endif
100