2 * Copyright (C) 2010 University of Szeged
3 * Copyright (C) 2010 Zoltan Herczeg
4 * Copyright (C) 2013 Google Inc. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "platform/graphics/Color.h"
32 #include "platform/graphics/filters/Filter.h"
33 #include "platform/graphics/filters/FilterEffect.h"
34 #include "platform/graphics/filters/LightSource.h"
35 #include "platform/graphics/filters/PointLightSource.h"
36 #include "platform/graphics/filters/SpotLightSource.h"
37 #include "wtf/Uint8ClampedArray.h"
39 // Common base class for FEDiffuseLighting and FESpecularLighting
43 class PLATFORM_EXPORT FELighting : public FilterEffect {
45 virtual PassRefPtr<SkImageFilter> createImageFilter(SkiaImageFilterBuilder*) OVERRIDE;
48 static const int s_minimalRectDimension = 100 * 100; // Empirical data limit for parallel jobs
56 // This structure contains only read-only (SMP safe) data
57 Uint8ClampedArray* pixels;
59 int widthMultipliedByPixelSize;
60 int widthDecreasedByOne;
61 int heightDecreasedByOne;
62 const LightSource* lightSource;
64 inline void topLeft(int offset, IntPoint& normalVector);
65 inline void topRow(int offset, IntPoint& normalVector);
66 inline void topRight(int offset, IntPoint& normalVector);
67 inline void leftColumn(int offset, IntPoint& normalVector);
68 inline void interior(int offset, IntPoint& normalVector);
69 inline void rightColumn(int offset, IntPoint& normalVector);
70 inline void bottomLeft(int offset, IntPoint& normalVector);
71 inline void bottomRow(int offset, IntPoint& normalVector);
72 inline void bottomRight(int offset, IntPoint& normalVector);
75 template<typename Type>
76 friend class ParallelJobs;
78 struct PlatformApplyGenericParameters {
81 LightSource::PaintingData paintingData;
86 virtual FloatRect mapPaintRect(const FloatRect&, bool forward = true) OVERRIDE FINAL;
87 virtual bool affectsTransparentPixels() OVERRIDE { return true; }
89 static void platformApplyGenericWorker(PlatformApplyGenericParameters*);
91 FELighting(Filter*, LightingType, const Color&, float, float, float, float, float, float, PassRefPtr<LightSource>);
93 bool drawLighting(Uint8ClampedArray*, int, int);
94 inline void inlineSetPixel(int offset, LightingData&, LightSource::PaintingData&,
95 int lightX, int lightY, float factorX, float factorY, IntPoint& normalVector);
97 // Not worth to inline every occurence of setPixel.
98 void setPixel(int offset, LightingData&, LightSource::PaintingData&,
99 int lightX, int lightY, float factorX, float factorY, IntPoint& normalVector);
101 inline void platformApply(LightingData&, LightSource::PaintingData&);
103 inline void platformApplyGenericPaint(LightingData&, LightSource::PaintingData&, int startX, int startY);
104 inline void platformApplyGeneric(LightingData&, LightSource::PaintingData&);
106 LightingType m_lightingType;
107 RefPtr<LightSource> m_lightSource;
109 Color m_lightingColor;
110 float m_surfaceScale;
111 float m_diffuseConstant;
112 float m_specularConstant;
113 float m_specularExponent;
114 float m_kernelUnitLengthX;
115 float m_kernelUnitLengthY;
118 virtual void applySoftware() OVERRIDE;
120 void getTransform(FloatPoint3D* scale, FloatSize* offset) const;
125 #endif // FELighting_h