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.
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.
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.
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.
25 #include "platform/graphics/filters/FEFlood.h"
27 #include "SkColorFilter.h"
28 #include "SkColorFilterImageFilter.h"
29 #include "SkFlattenableBuffers.h"
30 #include "platform/graphics/GraphicsContext.h"
31 #include "platform/graphics/filters/SkiaImageFilterBuilder.h"
32 #include "platform/text/TextStream.h"
33 #include "third_party/skia/include/core/SkDevice.h"
37 FEFlood::FEFlood(Filter* filter, const Color& floodColor, float floodOpacity)
38 : FilterEffect(filter)
39 , m_floodColor(floodColor)
40 , m_floodOpacity(floodOpacity)
42 FilterEffect::setOperatingColorSpace(ColorSpaceDeviceRGB);
45 PassRefPtr<FEFlood> FEFlood::create(Filter* filter, const Color& floodColor, float floodOpacity)
47 return adoptRef(new FEFlood(filter, floodColor, floodOpacity));
50 Color FEFlood::floodColor() const
55 bool FEFlood::setFloodColor(const Color& color)
57 if (m_floodColor == color)
63 float FEFlood::floodOpacity() const
65 return m_floodOpacity;
68 bool FEFlood::setFloodOpacity(float floodOpacity)
70 if (m_floodOpacity == floodOpacity)
72 m_floodOpacity = floodOpacity;
76 void FEFlood::applySoftware()
78 ImageBuffer* resultImage = createImageBufferResult();
82 Color color = floodColor().combineWithAlpha(floodOpacity());
83 resultImage->context()->fillRect(FloatRect(FloatPoint(), absolutePaintRect().size()), color);
84 FilterEffect::setResultColorSpace(ColorSpaceDeviceRGB);
87 PassRefPtr<SkImageFilter> FEFlood::createImageFilter(SkiaImageFilterBuilder* builder)
89 Color color = floodColor().combineWithAlpha(floodOpacity());
91 SkImageFilter::CropRect rect = getCropRect(builder->cropOffset());
92 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(color.rgb(), SkXfermode::kSrc_Mode));
93 return adoptRef(SkColorFilterImageFilter::Create(cf, 0, &rect));
96 TextStream& FEFlood::externalRepresentation(TextStream& ts, int indent) const
98 writeIndent(ts, indent);
100 FilterEffect::externalRepresentation(ts);
101 ts << " flood-color=\"" << floodColor().nameForRenderTreeAsText() << "\" "
102 << "flood-opacity=\"" << floodOpacity() << "\"]\n";