~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/platform/graphics/filters/FETile.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008 Alex Mathews <possessedpenguinbob@gmail.com>
 
3
 * Copyright (C) 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
 * 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.
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#if ENABLE(FILTERS)
 
24
#include "FETile.h"
 
25
 
 
26
#include "AffineTransform.h"
 
27
#include "Filter.h"
 
28
#include "GraphicsContext.h"
 
29
#include "Pattern.h"
 
30
#include "RenderTreeAsText.h"
 
31
#include "SVGRenderingContext.h"
 
32
#include "TextStream.h"
 
33
 
 
34
namespace WebCore {
 
35
 
 
36
FETile::FETile(Filter* filter)
 
37
    : FilterEffect(filter)
 
38
{
 
39
}
 
40
 
 
41
PassRefPtr<FETile> FETile::create(Filter* filter)
 
42
{
 
43
    return adoptRef(new FETile(filter));
 
44
}
 
45
 
 
46
void FETile::platformApplySoftware()
 
47
{
 
48
// FIXME: See bug 47315. This is a hack to work around a compile failure, but is incorrect behavior otherwise.
 
49
#if ENABLE(SVG)
 
50
    FilterEffect* in = inputEffect(0);
 
51
 
 
52
    ImageBuffer* resultImage = createImageBufferResult();
 
53
    if (!resultImage)
 
54
        return;
 
55
 
 
56
    setIsAlphaImage(in->isAlphaImage());
 
57
 
 
58
    // Source input needs more attention. It has the size of the filterRegion but gives the
 
59
    // size of the cutted sourceImage back. This is part of the specification and optimization.
 
60
    FloatRect tileRect = in->maxEffectRect();
 
61
    FloatPoint inMaxEffectLocation = tileRect.location();
 
62
    FloatPoint maxEffectLocation = maxEffectRect().location();
 
63
    if (in->filterEffectType() == FilterEffectTypeSourceInput) {
 
64
        Filter* filter = this->filter();
 
65
        tileRect = filter->filterRegion();
 
66
        tileRect.scale(filter->filterResolution().width(), filter->filterResolution().height());
 
67
    }
 
68
 
 
69
    OwnPtr<ImageBuffer> tileImage;
 
70
    if (!SVGRenderingContext::createImageBufferForPattern(tileRect, tileRect, tileImage, ColorSpaceDeviceRGB, filter()->renderingMode()))
 
71
        return;
 
72
 
 
73
    GraphicsContext* tileImageContext = tileImage->context();
 
74
    tileImageContext->translate(-inMaxEffectLocation.x(), -inMaxEffectLocation.y());
 
75
    tileImageContext->drawImageBuffer(in->asImageBuffer(), ColorSpaceDeviceRGB, in->absolutePaintRect().location());
 
76
 
 
77
    RefPtr<Pattern> pattern = Pattern::create(tileImage->copyImage(CopyBackingStore), true, true);
 
78
 
 
79
    AffineTransform patternTransform;
 
80
    patternTransform.translate(inMaxEffectLocation.x() - maxEffectLocation.x(), inMaxEffectLocation.y() - maxEffectLocation.y());
 
81
    pattern->setPatternSpaceTransform(patternTransform);
 
82
    GraphicsContext* filterContext = resultImage->context();
 
83
    filterContext->setFillPattern(pattern);
 
84
    filterContext->fillRect(FloatRect(FloatPoint(), absolutePaintRect().size()));
 
85
#endif
 
86
}
 
87
 
 
88
void FETile::dump()
 
89
{
 
90
}
 
91
 
 
92
TextStream& FETile::externalRepresentation(TextStream& ts, int indent) const
 
93
{
 
94
    writeIndent(ts, indent);
 
95
    ts << "[feTile";
 
96
    FilterEffect::externalRepresentation(ts);
 
97
    ts << "]\n";
 
98
    inputEffect(0)->externalRepresentation(ts, indent + 1);
 
99
 
 
100
    return ts;
 
101
}
 
102
 
 
103
} // namespace WebCore
 
104
 
 
105
#endif // ENABLE(FILTERS)