Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / graphics / filters / FETile.cpp
1 /*
2  * Copyright (C) 2008 Alex Mathews <possessedpenguinbob@gmail.com>
3  * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
4  * Copyright (C) 2013 Google Inc. All rights reserved.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #include "config.h"
23 #include "platform/graphics/filters/FETile.h"
24
25 #include "SkTileImageFilter.h"
26
27 #include "platform/graphics/filters/Filter.h"
28 #include "platform/graphics/filters/SkiaImageFilterBuilder.h"
29 #include "platform/text/TextStream.h"
30
31 namespace blink {
32
33 FETile::FETile(Filter* filter)
34     : FilterEffect(filter)
35 {
36 }
37
38 PassRefPtr<FETile> FETile::create(Filter* filter)
39 {
40     return adoptRef(new FETile(filter));
41 }
42
43 FloatRect FETile::mapPaintRect(const FloatRect& rect, bool forward)
44 {
45     return forward ? maxEffectRect() : inputEffect(0)->maxEffectRect();
46 }
47
48 static FloatRect getRect(FilterEffect* effect)
49 {
50     FloatRect result = effect->filter()->filterRegion();
51     FloatRect boundaries = effect->effectBoundaries();
52     if (effect->hasX())
53         result.setX(boundaries.x());
54     if (effect->hasY())
55         result.setY(boundaries.y());
56     if (effect->hasWidth())
57         result.setWidth(boundaries.width());
58     if (effect->hasHeight())
59         result.setHeight(boundaries.height());
60     return result;
61 }
62
63 PassRefPtr<SkImageFilter> FETile::createImageFilter(SkiaImageFilterBuilder* builder)
64 {
65     RefPtr<SkImageFilter> input(builder->build(inputEffect(0), operatingColorSpace()));
66     FloatRect srcRect = inputEffect(0) ? getRect(inputEffect(0)) : filter()->filterRegion();
67     FloatRect dstRect = getRect(this);
68     return adoptRef(SkTileImageFilter::Create(srcRect, dstRect, input.get()));
69 }
70
71 TextStream& FETile::externalRepresentation(TextStream& ts, int indent) const
72 {
73     writeIndent(ts, indent);
74     ts << "[feTile";
75     FilterEffect::externalRepresentation(ts);
76     ts << "]\n";
77     inputEffect(0)->externalRepresentation(ts, indent + 1);
78
79     return ts;
80 }
81
82 } // namespace blink