Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / graphics / filters / SourceAlpha.cpp
1 /*
2  * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
3  * Copyright (C) 2013 Google Inc. All rights reserved.
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 #include "platform/graphics/filters/SourceAlpha.h"
23
24 #include "platform/graphics/Color.h"
25 #include "platform/graphics/filters/Filter.h"
26 #include "platform/graphics/filters/SkiaImageFilterBuilder.h"
27 #include "platform/graphics/filters/SourceGraphic.h"
28 #include "platform/text/TextStream.h"
29 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h"
30 #include "third_party/skia/include/effects/SkColorMatrixFilter.h"
31 #include "wtf/text/WTFString.h"
32
33 namespace blink {
34
35 PassRefPtr<SourceAlpha> SourceAlpha::create(Filter* filter)
36 {
37     return adoptRef(new SourceAlpha(filter));
38 }
39
40 const AtomicString& SourceAlpha::effectName()
41 {
42     DEFINE_STATIC_LOCAL(const AtomicString, s_effectName, ("SourceAlpha", AtomicString::ConstructFromLiteral));
43     return s_effectName;
44 }
45
46 FloatRect SourceAlpha::determineAbsolutePaintRect(const FloatRect& requestedRect)
47 {
48     FloatRect srcRect = filter()->sourceImageRect();
49     srcRect.intersect(requestedRect);
50     addAbsolutePaintRect(srcRect);
51     return srcRect;
52 }
53
54 PassRefPtr<SkImageFilter> SourceAlpha::createImageFilter(SkiaImageFilterBuilder* builder)
55 {
56     RefPtr<SkImageFilter> sourceGraphic(builder->build(builder->sourceGraphic(), operatingColorSpace()));
57     SkScalar matrix[20] = {
58         0, 0, 0, 0, 0,
59         0, 0, 0, 0, 0,
60         0, 0, 0, 0, 0,
61         0, 0, 0, SK_Scalar1, 0
62     };
63     RefPtr<SkColorFilter> colorFilter(adoptRef(SkColorMatrixFilter::Create(matrix)));
64     return adoptRef(SkColorFilterImageFilter::Create(colorFilter.get(), sourceGraphic.get()));
65 }
66
67 TextStream& SourceAlpha::externalRepresentation(TextStream& ts, int indent) const
68 {
69     writeIndent(ts, indent);
70     ts << "[SourceAlpha]\n";
71     return ts;
72 }
73
74 } // namespace blink