2 * Copyright (C) 2011 Apple Inc.
3 * Copyright (C) 2010 Sencha, Inc.
4 * Copyright (C) 2010 Igalia S.L.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
33 #include "ColorSpace.h"
34 #include "FloatRect.h"
35 #include "RoundedRect.h"
36 #include <wtf/Noncopyable.h>
40 class AffineTransform;
41 class GraphicsContext;
45 WTF_MAKE_NONCOPYABLE(ShadowBlur);
53 ShadowBlur(const FloatSize& radius, const FloatSize& offset, const Color&, ColorSpace);
56 void setShadowValues(const FloatSize&, const FloatSize& , const Color&, ColorSpace, bool ignoreTransforms = false);
58 void setShadowsIgnoreTransforms(bool ignoreTransforms) { m_shadowsIgnoreTransforms = ignoreTransforms; }
59 bool shadowsIgnoreTransforms() const { return m_shadowsIgnoreTransforms; }
61 GraphicsContext* beginShadowLayer(GraphicsContext*, const FloatRect& layerArea);
62 void endShadowLayer(GraphicsContext*);
64 void drawRectShadow(GraphicsContext*, const FloatRect&, const RoundedRect::Radii&);
65 void drawInsetShadow(GraphicsContext*, const FloatRect&, const FloatRect& holeRect, const RoundedRect::Radii& holeRadii);
67 void blurLayerImage(unsigned char*, const IntSize&, int stride);
71 ShadowType type() const { return m_type; }
73 #if PLATFORM(QT) || USE(CAIRO)
74 bool mustUseShadowBlur(GraphicsContext*) const;
78 void updateShadowBlurValues();
80 void drawShadowBuffer(GraphicsContext*);
82 void adjustBlurRadius(GraphicsContext*);
84 enum ShadowDirection {
89 IntRect calculateLayerBoundingRect(GraphicsContext*, const FloatRect& layerArea, const IntRect& clipRect);
90 IntSize templateSize(const IntSize& blurredEdgeSize, const RoundedRect::Radii&) const;
92 void drawRectShadowWithoutTiling(GraphicsContext*, const FloatRect&, const RoundedRect::Radii&, const IntRect& layerRect);
93 void drawRectShadowWithTiling(GraphicsContext*, const FloatRect&, const RoundedRect::Radii&, const IntSize& shadowTemplateSize, const IntSize& blurredEdgeSize);
95 void drawInsetShadowWithoutTiling(GraphicsContext*, const FloatRect&, const FloatRect& holeRect, const RoundedRect::Radii&, const IntRect& layerRect);
96 void drawInsetShadowWithTiling(GraphicsContext*, const FloatRect&, const FloatRect& holeRect, const RoundedRect::Radii&, const IntSize& shadowTemplateSize, const IntSize& blurredEdgeSize);
98 void drawLayerPieces(GraphicsContext*, const FloatRect& shadowBounds, const RoundedRect::Radii&, const IntSize& roundedRadius, const IntSize& templateSize, ShadowDirection);
100 void blurShadowBuffer(const IntSize& templateSize);
101 void blurAndColorShadowBuffer(const IntSize& templateSize);
103 IntSize blurredEdgeSize() const;
109 ColorSpace m_colorSpace;
110 FloatSize m_blurRadius;
113 ImageBuffer* m_layerImage; // Buffer to where the temporary shadow will be drawn to.
115 FloatRect m_sourceRect; // Sub-rect of m_layerImage that contains the shadow pixels.
116 FloatPoint m_layerOrigin; // Top-left corner of the (possibly clipped) bounding rect to draw the shadow to.
117 FloatSize m_layerSize; // Size of m_layerImage pixels that need blurring.
118 FloatSize m_layerContextTranslation; // Translation to apply to m_layerContext for the shadow to be correctly clipped.
120 bool m_shadowsIgnoreTransforms;
123 } // namespace WebCore
125 #endif // ShadowBlur_h