1 /* 2 * Copyright (C) 2010 University of Szeged 3 * Copyright (C) 2010 Zoltan Herczeg 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF SZEGED OR 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #ifndef FELighting_h 28 #define FELighting_h 29 30 #if ENABLE(FILTERS) 31 #include "Color.h" 32 #include "Filter.h" 33 #include "FilterEffect.h" 34 #include "LightSource.h" 35 #include <wtf/ByteArray.h> 36 #include <wtf/Platform.h> 37 38 // Common base class for FEDiffuseLighting and FESpecularLighting 39 40 namespace WebCore { 41 42 class FELighting : public FilterEffect { 43 public: 44 virtual void apply(); 45 determineAbsolutePaintRect()46 virtual void determineAbsolutePaintRect() { setAbsolutePaintRect(enclosingIntRect(maxEffectRect())); } 47 48 protected: 49 enum LightingType { 50 DiffuseLighting, 51 SpecularLighting 52 }; 53 54 struct LightingData { 55 // This structure contains only read-only (SMP safe) data 56 ByteArray* pixels; 57 float surfaceScale; 58 int widthMultipliedByPixelSize; 59 int widthDecreasedByOne; 60 int heightDecreasedByOne; 61 62 inline void topLeft(int offset, IntPoint& normalVector); 63 inline void topRow(int offset, IntPoint& normalVector); 64 inline void topRight(int offset, IntPoint& normalVector); 65 inline void leftColumn(int offset, IntPoint& normalVector); 66 inline void interior(int offset, IntPoint& normalVector); 67 inline void rightColumn(int offset, IntPoint& normalVector); 68 inline void bottomLeft(int offset, IntPoint& normalVector); 69 inline void bottomRow(int offset, IntPoint& normalVector); 70 inline void bottomRight(int offset, IntPoint& normalVector); 71 }; 72 73 FELighting(Filter*, LightingType, const Color&, float, float, float, float, float, float, PassRefPtr<LightSource>); 74 75 bool drawLighting(ByteArray*, int, int); 76 inline void inlineSetPixel(int offset, LightingData&, LightSource::PaintingData&, 77 int lightX, int lightY, float factorX, float factorY, IntPoint& normalVector); 78 79 // Not worth to inline every occurence of setPixel. 80 void setPixel(int offset, LightingData&, LightSource::PaintingData&, 81 int lightX, int lightY, float factorX, float factorY, IntPoint& normalVector); 82 83 #if CPU(ARM_NEON) && COMPILER(GCC) 84 void drawInteriorPixels(LightingData&, LightSource::PaintingData&); 85 #endif 86 87 LightingType m_lightingType; 88 RefPtr<LightSource> m_lightSource; 89 90 Color m_lightingColor; 91 float m_surfaceScale; 92 float m_diffuseConstant; 93 float m_specularConstant; 94 float m_specularExponent; 95 float m_kernelUnitLengthX; 96 float m_kernelUnitLengthY; 97 }; 98 99 } // namespace WebCore 100 101 #endif // ENABLE(FILTERS) 102 103 #endif // FELighting_h 104