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) 2013 Google Inc. All rights reserved.
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#include "platform/graphics/filters/FESpecularLighting.h"
25
26#include "platform/graphics/filters/LightSource.h"
27#include "platform/text/TextStream.h"
28
29namespace blink {
30
31FESpecularLighting::FESpecularLighting(Filter* filter, const Color& lightingColor, float surfaceScale,
32    float specularConstant, float specularExponent, float kernelUnitLengthX,
33    float kernelUnitLengthY, PassRefPtr<LightSource> lightSource)
34    : FELighting(filter, SpecularLighting, lightingColor, surfaceScale, 0, specularConstant, specularExponent, kernelUnitLengthX, kernelUnitLengthY, lightSource)
35{
36}
37
38PassRefPtr<FESpecularLighting> FESpecularLighting::create(Filter* filter, const Color& lightingColor,
39    float surfaceScale, float specularConstant, float specularExponent,
40    float kernelUnitLengthX, float kernelUnitLengthY, PassRefPtr<LightSource> lightSource)
41{
42    return adoptRef(new FESpecularLighting(filter, lightingColor, surfaceScale, specularConstant, specularExponent,
43        kernelUnitLengthX, kernelUnitLengthY, lightSource));
44}
45
46FESpecularLighting::~FESpecularLighting()
47{
48}
49
50Color FESpecularLighting::lightingColor() const
51{
52    return m_lightingColor;
53}
54
55bool FESpecularLighting::setLightingColor(const Color& lightingColor)
56{
57    if (m_lightingColor == lightingColor)
58        return false;
59    m_lightingColor = lightingColor;
60    return true;
61}
62
63float FESpecularLighting::surfaceScale() const
64{
65    return m_surfaceScale;
66}
67
68bool FESpecularLighting::setSurfaceScale(float surfaceScale)
69{
70    if (m_surfaceScale == surfaceScale)
71        return false;
72    m_surfaceScale = surfaceScale;
73    return true;
74}
75
76float FESpecularLighting::specularConstant() const
77{
78    return m_specularConstant;
79}
80
81bool FESpecularLighting::setSpecularConstant(float specularConstant)
82{
83    specularConstant = std::max(specularConstant, 0.0f);
84    if (m_specularConstant == specularConstant)
85        return false;
86    m_specularConstant = specularConstant;
87    return true;
88}
89
90float FESpecularLighting::specularExponent() const
91{
92    return m_specularExponent;
93}
94
95bool FESpecularLighting::setSpecularExponent(float specularExponent)
96{
97    specularExponent = std::min(std::max(specularExponent, 1.0f), 128.0f);
98    if (m_specularExponent == specularExponent)
99        return false;
100    m_specularExponent = specularExponent;
101    return true;
102}
103
104float FESpecularLighting::kernelUnitLengthX() const
105{
106    return m_kernelUnitLengthX;
107}
108
109bool FESpecularLighting::setKernelUnitLengthX(float kernelUnitLengthX)
110{
111    if (m_kernelUnitLengthX == kernelUnitLengthX)
112        return false;
113    m_kernelUnitLengthX = kernelUnitLengthX;
114    return true;
115}
116
117float FESpecularLighting::kernelUnitLengthY() const
118{
119    return m_kernelUnitLengthY;
120}
121
122bool FESpecularLighting::setKernelUnitLengthY(float kernelUnitLengthY)
123{
124    if (m_kernelUnitLengthY == kernelUnitLengthY)
125        return false;
126    m_kernelUnitLengthY = kernelUnitLengthY;
127    return true;
128}
129
130const LightSource* FESpecularLighting::lightSource() const
131{
132    return m_lightSource.get();
133}
134
135void FESpecularLighting::setLightSource(PassRefPtr<LightSource> lightSource)
136{
137    m_lightSource = lightSource;
138}
139
140TextStream& FESpecularLighting::externalRepresentation(TextStream& ts, int indent) const
141{
142    writeIndent(ts, indent);
143    ts << "[feSpecularLighting";
144    FilterEffect::externalRepresentation(ts);
145    ts << " surfaceScale=\"" << m_surfaceScale << "\" "
146       << "specualConstant=\"" << m_specularConstant << "\" "
147       << "specularExponent=\"" << m_specularExponent << "\"]\n";
148    inputEffect(0)->externalRepresentation(ts, indent + 1);
149    return ts;
150}
151
152} // namespace blink
153