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 "platform/graphics/GraphicsContext.h"
30 #include "platform/graphics/filters/SkiaImageFilterBuilder.h"
31 #include "platform/text/TextStream.h"
32 #include "third_party/skia/include/core/SkDevice.h"
36 FEFlood::FEFlood(Filter* filter, const Color& floodColor, float floodOpacity)
37 : FilterEffect(filter)
38 , m_floodColor(floodColor)
39 , m_floodOpacity(floodOpacity)
41 FilterEffect::setOperatingColorSpace(ColorSpaceDeviceRGB);
44 PassRefPtr<FEFlood> FEFlood::create(Filter* filter, const Color& floodColor, float floodOpacity)
46 return adoptRef(new FEFlood(filter, floodColor, floodOpacity));
49 Color FEFlood::floodColor() const
54 bool FEFlood::setFloodColor(const Color& color)
56 if (m_floodColor == color)
62 float FEFlood::floodOpacity() const
64 return m_floodOpacity;
67 bool FEFlood::setFloodOpacity(float floodOpacity)
69 if (m_floodOpacity == floodOpacity)
71 m_floodOpacity = floodOpacity;
75 void FEFlood::applySoftware()
77 ImageBuffer* resultImage = createImageBufferResult();
81 Color color = floodColor().combineWithAlpha(floodOpacity());
82 resultImage->context()->fillRect(FloatRect(FloatPoint(), absolutePaintRect().size()), color);
83 FilterEffect::setResultColorSpace(ColorSpaceDeviceRGB);
86 PassRefPtr<SkImageFilter> FEFlood::createImageFilter(SkiaImageFilterBuilder* builder)
88 Color color = floodColor().combineWithAlpha(floodOpacity());
90 SkImageFilter::CropRect rect = getCropRect(builder->cropOffset());
91 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(color.rgb(), SkXfermode::kSrc_Mode));
92 return adoptRef(SkColorFilterImageFilter::Create(cf, 0, &rect));
95 TextStream& FEFlood::externalRepresentation(TextStream& ts, int indent) const
97 writeIndent(ts, indent);
99 FilterEffect::externalRepresentation(ts);
100 ts << " flood-color=\"" << floodColor().nameForRenderTreeAsText() << "\" "
101 << "flood-opacity=\"" << floodOpacity() << "\"]\n";