1 /* 2 * Copyright (C) 2011 Apple Inc. 3 * Copyright (C) 2010 Sencha, Inc. 4 * Copyright (C) 2010 Igalia S.L. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef ShadowBlur_h 30 #define ShadowBlur_h 31 32 #include "Color.h" 33 #include "ColorSpace.h" 34 #include "FloatRect.h" 35 #include "RoundedIntRect.h" 36 #include <wtf/Noncopyable.h> 37 38 namespace WebCore { 39 40 class AffineTransform; 41 class GraphicsContext; 42 class ImageBuffer; 43 44 class ShadowBlur { 45 WTF_MAKE_NONCOPYABLE(ShadowBlur); 46 public: 47 ShadowBlur(float radius, const FloatSize& offset, const Color&, ColorSpace); 48 setShadowsIgnoreTransforms(bool ignoreTransforms)49 void setShadowsIgnoreTransforms(bool ignoreTransforms) { m_shadowsIgnoreTransforms = ignoreTransforms; } shadowsIgnoreTransforms()50 bool shadowsIgnoreTransforms() const { return m_shadowsIgnoreTransforms; } 51 52 void drawRectShadow(GraphicsContext*, const FloatRect&, const RoundedIntRect::Radii&); 53 void drawInsetShadow(GraphicsContext*, const FloatRect&, const FloatRect& holeRect, const RoundedIntRect::Radii& holeRadii); 54 55 private: 56 void drawShadowBuffer(GraphicsContext*); 57 58 void adjustBlurRadius(GraphicsContext*); 59 void blurLayerImage(unsigned char*, const IntSize&, int stride); 60 61 enum ShadowDirection { 62 OuterShadow, 63 InnerShadow 64 }; 65 66 IntRect calculateLayerBoundingRect(GraphicsContext*, const FloatRect& layerArea, const IntRect& clipRect); 67 IntSize templateSize(const RoundedIntRect::Radii&) const; 68 69 void drawRectShadowWithoutTiling(GraphicsContext*, const FloatRect&, const RoundedIntRect::Radii&, const IntRect& layerRect); 70 void drawRectShadowWithTiling(GraphicsContext*, const FloatRect&, const RoundedIntRect::Radii&, const IntSize& shadowTemplateSize); 71 72 void drawInsetShadowWithoutTiling(GraphicsContext*, const FloatRect&, const FloatRect& holeRect, const RoundedIntRect::Radii&, const IntRect& layerRect); 73 void drawInsetShadowWithTiling(GraphicsContext*, const FloatRect&, const FloatRect& holeRect, const RoundedIntRect::Radii&, const IntSize& shadowTemplateSize); 74 75 void drawLayerPieces(GraphicsContext*, const FloatRect& shadowBounds, const RoundedIntRect::Radii&, float roundedRadius, const IntSize& templateSize, ShadowDirection); 76 77 void blurShadowBuffer(const IntSize& templateSize); 78 void blurAndColorShadowBuffer(const IntSize& templateSize); 79 80 enum ShadowType { 81 NoShadow, 82 SolidShadow, 83 BlurShadow 84 }; 85 86 ShadowType m_type; 87 88 Color m_color; 89 ColorSpace m_colorSpace; 90 float m_blurRadius; 91 FloatSize m_offset; 92 93 ImageBuffer* m_layerImage; // Buffer to where the temporary shadow will be drawn to. 94 95 FloatRect m_sourceRect; // Sub-rect of m_layerImage that contains the shadow pixels. 96 FloatPoint m_layerOrigin; // Top-left corner of the (possibly clipped) bounding rect to draw the shadow to. 97 FloatSize m_layerSize; // Size of m_layerImage pixels that need blurring. 98 FloatSize m_layerContextTranslation; // Translation to apply to m_layerContext for the shadow to be correctly clipped. 99 100 bool m_shadowsIgnoreTransforms; 101 }; 102 103 } // namespace WebCore 104 105 #endif // ShadowBlur_h 106