Home | History | Annotate | Download | only in filters
      1 /*
      2     Copyright (C) 2008 Alex Mathews <possessedpenguinbob (at) gmail.com>
      3                   2009 Dirk Schulze <krit (at) 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 "AffineTransform.h"
     27 #include "Filter.h"
     28 #include "GraphicsContext.h"
     29 #include "Pattern.h"
     30 #include "SVGRenderTreeAsText.h"
     31 
     32 namespace WebCore {
     33 
     34 FETile::FETile(FilterEffect* in)
     35     : FilterEffect()
     36     , m_in(in)
     37 {
     38 }
     39 
     40 PassRefPtr<FETile> FETile::create(FilterEffect* in)
     41 {
     42     return adoptRef(new FETile(in));
     43 }
     44 
     45 FloatRect FETile::uniteChildEffectSubregions(Filter* filter)
     46 {
     47     m_in->calculateEffectRect(filter);
     48     return filter->filterRegion();
     49 }
     50 
     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     setIsAlphaImage(m_in->isAlphaImage());
     62 
     63     IntRect tileRect = enclosingIntRect(m_in->scaledSubRegion());
     64 
     65     // Source input needs more attention. It has the size of the filterRegion but gives the
     66     // size of the cutted sourceImage back. This is part of the specification and optimization.
     67     if (m_in->isSourceInput()) {
     68         FloatRect filterRegion = filter->filterRegion();
     69         filterRegion.scale(filter->filterResolution().width(), filter->filterResolution().height());
     70         tileRect = enclosingIntRect(filterRegion);
     71     }
     72 
     73     OwnPtr<ImageBuffer> tileImage = ImageBuffer::create(tileRect.size());
     74     GraphicsContext* tileImageContext = tileImage->context();
     75     tileImageContext->drawImage(m_in->resultImage()->image(), DeviceColorSpace, IntPoint());
     76     RefPtr<Pattern> pattern = Pattern::create(tileImage->image(), true, true);
     77 
     78     AffineTransform matrix;
     79     matrix.translate(m_in->scaledSubRegion().x() - scaledSubRegion().x(), m_in->scaledSubRegion().y() - scaledSubRegion().y());
     80     pattern.get()->setPatternSpaceTransform(matrix);
     81 
     82     filterContext->setFillPattern(pattern);
     83     filterContext->fillRect(FloatRect(FloatPoint(), scaledSubRegion().size()));
     84 }
     85 
     86 void FETile::dump()
     87 {
     88 }
     89 
     90 TextStream& FETile::externalRepresentation(TextStream& ts) const
     91 {
     92     ts << "[type=TILE]";
     93     FilterEffect::externalRepresentation(ts);
     94     return ts;
     95 }
     96 
     97 } // namespace WebCore
     98 
     99 #endif // ENABLE(SVG) && ENABLE(FILTERS)
    100 
    101