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 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB.  If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#include "config.h"
24
25#if ENABLE(FILTERS)
26#include "FEFlood.h"
27
28#include "Filter.h"
29#include "GraphicsContext.h"
30#include "TextStream.h"
31
32namespace WebCore {
33
34FEFlood::FEFlood(Filter* filter, const Color& floodColor, float floodOpacity)
35    : FilterEffect(filter)
36    , m_floodColor(floodColor)
37    , m_floodOpacity(floodOpacity)
38{
39}
40
41PassRefPtr<FEFlood> FEFlood::create(Filter* filter, const Color& floodColor, float floodOpacity)
42{
43    return adoptRef(new FEFlood(filter, floodColor, floodOpacity));
44}
45
46Color FEFlood::floodColor() const
47{
48    return m_floodColor;
49}
50
51bool FEFlood::setFloodColor(const Color& color)
52{
53    if (m_floodColor == color)
54        return false;
55    m_floodColor = color;
56    return true;
57}
58
59float FEFlood::floodOpacity() const
60{
61    return m_floodOpacity;
62}
63
64bool FEFlood::setFloodOpacity(float floodOpacity)
65{
66    if (m_floodOpacity == floodOpacity)
67        return false;
68    m_floodOpacity = floodOpacity;
69    return true;
70}
71
72void FEFlood::platformApplySoftware()
73{
74    ImageBuffer* resultImage = createImageBufferResult();
75    if (!resultImage)
76        return;
77
78    Color color = colorWithOverrideAlpha(floodColor().rgb(), floodOpacity());
79    resultImage->context()->fillRect(FloatRect(FloatPoint(), absolutePaintRect().size()), color, ColorSpaceDeviceRGB);
80}
81
82void FEFlood::dump()
83{
84}
85
86TextStream& FEFlood::externalRepresentation(TextStream& ts, int indent) const
87{
88    writeIndent(ts, indent);
89    ts << "[feFlood";
90    FilterEffect::externalRepresentation(ts);
91    ts << " flood-color=\"" << floodColor().nameForRenderTreeAsText() << "\" "
92       << "flood-opacity=\"" << floodOpacity() << "\"]\n";
93    return ts;
94}
95
96} // namespace WebCore
97
98#endif // ENABLE(FILTERS)
99