1 /* 2 * Copyright (C) 2010 University of Szeged 3 * Copyright (C) 2010 Zoltan Herczeg 4 * Copyright (C) 2013 Google Inc. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 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. 14 * 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. 26 */ 27 28 #ifndef FELighting_h 29 #define FELighting_h 30 31 #include "core/platform/graphics/Color.h" 32 #include "core/platform/graphics/filters/Filter.h" 33 #include "core/platform/graphics/filters/FilterEffect.h" 34 #include "core/platform/graphics/filters/LightSource.h" 35 #include "core/platform/graphics/filters/PointLightSource.h" 36 #include "core/platform/graphics/filters/SpotLightSource.h" 37 #include "wtf/Uint8ClampedArray.h" 38 39 // Common base class for FEDiffuseLighting and FESpecularLighting 40 41 namespace WebCore { 42 43 struct FELightingPaintingDataForNeon; 44 45 class FELighting : public FilterEffect { 46 public: 47 virtual PassRefPtr<SkImageFilter> createImageFilter(SkiaImageFilterBuilder*) OVERRIDE; 48 49 virtual void determineAbsolutePaintRect() { setAbsolutePaintRect(enclosingIntRect(maxEffectRect())); } 50 51 protected: 52 static const int s_minimalRectDimension = 100 * 100; // Empirical data limit for parallel jobs 53 54 enum LightingType { 55 DiffuseLighting, 56 SpecularLighting 57 }; 58 59 struct LightingData { 60 // This structure contains only read-only (SMP safe) data 61 Uint8ClampedArray* pixels; 62 float surfaceScale; 63 int widthMultipliedByPixelSize; 64 int widthDecreasedByOne; 65 int heightDecreasedByOne; 66 67 inline void topLeft(int offset, IntPoint& normalVector); 68 inline void topRow(int offset, IntPoint& normalVector); 69 inline void topRight(int offset, IntPoint& normalVector); 70 inline void leftColumn(int offset, IntPoint& normalVector); 71 inline void interior(int offset, IntPoint& normalVector); 72 inline void rightColumn(int offset, IntPoint& normalVector); 73 inline void bottomLeft(int offset, IntPoint& normalVector); 74 inline void bottomRow(int offset, IntPoint& normalVector); 75 inline void bottomRight(int offset, IntPoint& normalVector); 76 }; 77 78 template<typename Type> 79 friend class ParallelJobs; 80 81 struct PlatformApplyGenericParameters { 82 FELighting* filter; 83 LightingData data; 84 LightSource::PaintingData paintingData; 85 int yStart; 86 int yEnd; 87 }; 88 89 static void platformApplyGenericWorker(PlatformApplyGenericParameters*); 90 static void platformApplyNeonWorker(FELightingPaintingDataForNeon*); 91 92 FELighting(Filter*, LightingType, const Color&, float, float, float, float, float, float, PassRefPtr<LightSource>); 93 94 bool drawLighting(Uint8ClampedArray*, int, int); 95 inline void inlineSetPixel(int offset, LightingData&, LightSource::PaintingData&, 96 int lightX, int lightY, float factorX, float factorY, IntPoint& normalVector); 97 98 // Not worth to inline every occurence of setPixel. 99 void setPixel(int offset, LightingData&, LightSource::PaintingData&, 100 int lightX, int lightY, float factorX, float factorY, IntPoint& normalVector); 101 102 inline void platformApply(LightingData&, LightSource::PaintingData&); 103 104 inline void platformApplyGenericPaint(LightingData&, LightSource::PaintingData&, int startX, int startY); 105 inline void platformApplyGeneric(LightingData&, LightSource::PaintingData&); 106 107 static int getPowerCoefficients(float exponent); 108 inline void platformApplyNeon(LightingData&, LightSource::PaintingData&); 109 110 LightingType m_lightingType; 111 RefPtr<LightSource> m_lightSource; 112 113 Color m_lightingColor; 114 float m_surfaceScale; 115 float m_diffuseConstant; 116 float m_specularConstant; 117 float m_specularExponent; 118 float m_kernelUnitLengthX; 119 float m_kernelUnitLengthY; 120 121 private: 122 virtual void applySoftware() OVERRIDE; 123 virtual bool applySkia() OVERRIDE; 124 }; 125 126 } // namespace WebCore 127 128 #endif // FELighting_h 129