1 /*
2 Copyright (C) 2008 Alex Mathews <possessedpenguinbob@gmail.com>
3 2009 Dirk Schulze <krit@webkit.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 aint with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19 */
20
21 #include "config.h"
22
23 #if ENABLE(SVG) && ENABLE(FILTERS)
24 #include "SVGFETile.h"
25
26 #include "Filter.h"
27 #include "GraphicsContext.h"
28 #include "Pattern.h"
29 #include "TransformationMatrix.h"
30 #include "SVGRenderTreeAsText.h"
31
32 namespace WebCore {
33
FETile(FilterEffect * in)34 FETile::FETile(FilterEffect* in)
35 : FilterEffect()
36 , m_in(in)
37 {
38 }
39
create(FilterEffect * in)40 PassRefPtr<FETile> FETile::create(FilterEffect* in)
41 {
42 return adoptRef(new FETile(in));
43 }
44
uniteChildEffectSubregions(Filter * filter)45 FloatRect FETile::uniteChildEffectSubregions(Filter* filter)
46 {
47 m_in->calculateEffectRect(filter);
48 return filter->filterRegion();
49 }
50
apply(Filter * filter)51 void FETile::apply(Filter* filter)
52 {
53 m_in->apply(filter);
54 if (!m_in->resultImage())
55 return;
56
57 GraphicsContext* filterContext = getEffectContext();
58 if (!filterContext)
59 return;
60
61 IntRect tileRect = enclosingIntRect(m_in->subRegion());
62
63 // Source input needs more attention. It has the size of the filterRegion but gives the
64 // size of the cutted sourceImage back. This is part of the specification and optimization.
65 if (m_in->isSourceInput())
66 tileRect = enclosingIntRect(filter->filterRegion());
67
68 OwnPtr<ImageBuffer> tileImage = ImageBuffer::create(tileRect.size());
69 GraphicsContext* tileImageContext = tileImage->context();
70 tileImageContext->drawImage(m_in->resultImage()->image(), IntPoint());
71 RefPtr<Pattern> pattern = Pattern::create(tileImage->image(), true, true);
72
73 TransformationMatrix matrix;
74 matrix.translate(m_in->subRegion().x() - subRegion().x(), m_in->subRegion().y() - subRegion().y());
75 pattern.get()->setPatternSpaceTransform(matrix);
76
77 filterContext->setFillPattern(pattern);
78 filterContext->fillRect(FloatRect(FloatPoint(), subRegion().size()));
79 }
80
dump()81 void FETile::dump()
82 {
83 }
84
externalRepresentation(TextStream & ts) const85 TextStream& FETile::externalRepresentation(TextStream& ts) const
86 {
87 ts << "[type=TILE]";
88 FilterEffect::externalRepresentation(ts);
89 return ts;
90 }
91
92 } // namespace WebCore
93
94 #endif // ENABLE(SVG) && ENABLE(FILTERS)
95
96