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 "third_party/blink/renderer/platform/graphics/filters/fe_flood.h"
25 
26 #include "third_party/blink/renderer/platform/wtf/text/text_stream.h"
27 #include "third_party/skia/include/core/SkColorFilter.h"
28 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h"
29 
30 namespace blink {
31 
FEFlood(Filter * filter,const Color & flood_color,float flood_opacity)32 FEFlood::FEFlood(Filter* filter, const Color& flood_color, float flood_opacity)
33     : FilterEffect(filter),
34       flood_color_(flood_color),
35       flood_opacity_(flood_opacity) {
36   FilterEffect::SetOperatingInterpolationSpace(kInterpolationSpaceSRGB);
37 }
38 
FloodColor() const39 Color FEFlood::FloodColor() const {
40   return flood_color_;
41 }
42 
SetFloodColor(const Color & color)43 bool FEFlood::SetFloodColor(const Color& color) {
44   if (flood_color_ == color)
45     return false;
46   flood_color_ = color;
47   return true;
48 }
49 
FloodOpacity() const50 float FEFlood::FloodOpacity() const {
51   return flood_opacity_;
52 }
53 
SetFloodOpacity(float flood_opacity)54 bool FEFlood::SetFloodOpacity(float flood_opacity) {
55   if (flood_opacity_ == flood_opacity)
56     return false;
57   flood_opacity_ = flood_opacity;
58   return true;
59 }
60 
CreateImageFilter()61 sk_sp<PaintFilter> FEFlood::CreateImageFilter() {
62   Color color = FloodColor().CombineWithAlpha(FloodOpacity());
63   PaintFilter::CropRect rect = GetCropRect();
64   return sk_make_sp<ColorFilterPaintFilter>(
65       SkColorFilters::Blend(color.Rgb(), SkBlendMode::kSrc), nullptr, &rect);
66 }
67 
ExternalRepresentation(WTF::TextStream & ts,int indent) const68 WTF::TextStream& FEFlood::ExternalRepresentation(WTF::TextStream& ts,
69                                                  int indent) const {
70   WriteIndent(ts, indent);
71   ts << "[feFlood";
72   FilterEffect::ExternalRepresentation(ts);
73   ts << " flood-color=\"" << FloodColor().NameForLayoutTreeAsText() << "\" "
74      << "flood-opacity=\"" << FloodOpacity() << "\"]\n";
75   return ts;
76 }
77 
78 }  // namespace blink
79