Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / graphics / filters / FEFlood.cpp
1 /*
2  * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
4  * Copyright (C) 2005 Eric Seidel <eric@webkit.org>
5  * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
6  * Copyright (C) 2013 Google Inc. All rights reserved.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB.  If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23
24 #include "config.h"
25 #include "platform/graphics/filters/FEFlood.h"
26
27 #include "SkColorFilter.h"
28 #include "SkColorFilterImageFilter.h"
29 #include "platform/graphics/filters/SkiaImageFilterBuilder.h"
30 #include "platform/text/TextStream.h"
31
32 namespace blink {
33
34 FEFlood::FEFlood(Filter* filter, const Color& floodColor, float floodOpacity)
35     : FilterEffect(filter)
36     , m_floodColor(floodColor)
37     , m_floodOpacity(floodOpacity)
38 {
39     FilterEffect::setOperatingColorSpace(ColorSpaceDeviceRGB);
40 }
41
42 PassRefPtr<FEFlood> FEFlood::create(Filter* filter, const Color& floodColor, float floodOpacity)
43 {
44     return adoptRef(new FEFlood(filter, floodColor, floodOpacity));
45 }
46
47 Color FEFlood::floodColor() const
48 {
49     return m_floodColor;
50 }
51
52 bool FEFlood::setFloodColor(const Color& color)
53 {
54     if (m_floodColor == color)
55         return false;
56     m_floodColor = color;
57     return true;
58 }
59
60 float FEFlood::floodOpacity() const
61 {
62     return m_floodOpacity;
63 }
64
65 bool FEFlood::setFloodOpacity(float floodOpacity)
66 {
67     if (m_floodOpacity == floodOpacity)
68         return false;
69     m_floodOpacity = floodOpacity;
70     return true;
71 }
72
73 PassRefPtr<SkImageFilter> FEFlood::createImageFilter(SkiaImageFilterBuilder* builder)
74 {
75     Color color = floodColor().combineWithAlpha(floodOpacity());
76
77     SkImageFilter::CropRect rect = getCropRect(builder->cropOffset());
78     SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(color.rgb(), SkXfermode::kSrc_Mode));
79     return adoptRef(SkColorFilterImageFilter::Create(cf, 0, &rect));
80 }
81
82 TextStream& FEFlood::externalRepresentation(TextStream& ts, int indent) const
83 {
84     writeIndent(ts, indent);
85     ts << "[feFlood";
86     FilterEffect::externalRepresentation(ts);
87     ts << " flood-color=\"" << floodColor().nameForRenderTreeAsText() << "\" "
88        << "flood-opacity=\"" << floodOpacity() << "\"]\n";
89     return ts;
90 }
91
92 } // namespace blink