2 * Copyright (C) 2008 Alex Mathews <possessedpenguinbob@gmail.com>
3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
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.
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.
15 * You should have received a copy of the GNU Library General Public License
16 * along 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.
24 #include "AffineTransform.h"
26 #include "GraphicsContext.h"
28 #include "RenderTreeAsText.h"
29 #include "SVGRenderingContext.h"
30 #include "TextStream.h"
34 FETile::FETile(Filter& filter)
35 : FilterEffect(filter)
39 Ref<FETile> FETile::create(Filter& filter)
41 return adoptRef(*new FETile(filter));
44 void FETile::platformApplySoftware()
46 // FIXME: See bug 47315. This is a hack to work around a compile failure, but is incorrect behavior otherwise.
47 FilterEffect* in = inputEffect(0);
49 ImageBuffer* resultImage = createImageBufferResult();
53 setIsAlphaImage(in->isAlphaImage());
55 // Source input needs more attention. It has the size of the filterRegion but gives the
56 // size of the cutted sourceImage back. This is part of the specification and optimization.
57 FloatRect tileRect = in->maxEffectRect();
58 FloatPoint inMaxEffectLocation = tileRect.location();
59 FloatPoint maxEffectLocation = maxEffectRect().location();
60 if (in->filterEffectType() == FilterEffectTypeSourceInput) {
61 Filter& filter = this->filter();
62 tileRect = filter.filterRegion();
63 tileRect.scale(filter.filterResolution().width(), filter.filterResolution().height());
66 auto tileImage = SVGRenderingContext::createImageBuffer(tileRect, tileRect, ColorSpaceDeviceRGB, filter().renderingMode());
70 GraphicsContext* tileImageContext = tileImage->context();
71 tileImageContext->translate(-inMaxEffectLocation.x(), -inMaxEffectLocation.y());
72 tileImageContext->drawImageBuffer(in->asImageBuffer(), ColorSpaceDeviceRGB, in->absolutePaintRect().location());
74 auto pattern = Pattern::create(tileImage->copyImage(CopyBackingStore), true, true);
76 AffineTransform patternTransform;
77 patternTransform.translate(inMaxEffectLocation.x() - maxEffectLocation.x(), inMaxEffectLocation.y() - maxEffectLocation.y());
78 pattern.get().setPatternSpaceTransform(patternTransform);
79 GraphicsContext* filterContext = resultImage->context();
80 filterContext->setFillPattern(WTF::move(pattern));
81 filterContext->fillRect(FloatRect(FloatPoint(), absolutePaintRect().size()));
88 TextStream& FETile::externalRepresentation(TextStream& ts, int indent) const
90 writeIndent(ts, indent);
92 FilterEffect::externalRepresentation(ts);
94 inputEffect(0)->externalRepresentation(ts, indent + 1);
99 } // namespace WebCore