2011-01-30 Simon Fraser <simon.fraser@apple.com>

        Reviewed by Sam Weinig.

        Make ContextShadow code cross-platform
        https://bugs.webkit.org/show_bug.cgi?id=51312

        Add a new class, ShadowBlur, that contains most of the
        code from ContextShadow, but is fully cross-platform.
        It depends on one new method, GraphicsContext::clipBounds(),
        which platforms will have to implement.

        Add ShadowBlur to the Mac Xcode project, but don't use it
        anywhere yet.

        * WebCore.xcodeproj/project.pbxproj:
        * platform/graphics/GraphicsContext.cpp:
        (WebCore::GraphicsContext::clipBounds):
        * platform/graphics/GraphicsContext.h:
        * platform/graphics/ShadowBlur.cpp: Added.
        (WebCore::roundUpToMultipleOf32):
        (WebCore::ScratchBuffer::ScratchBuffer):
        (WebCore::ScratchBuffer::getScratchBuffer):
        (WebCore::ScratchBuffer::scheduleScratchBufferPurge):
        (WebCore::ScratchBuffer::timerFired):
        (WebCore::ScratchBuffer::clearScratchBuffer):
        (WebCore::ScratchBuffer::shared):
        (WebCore::ShadowBlur::ShadowBlur):
        (WebCore::ShadowBlur::blurLayerImage):
        (WebCore::ShadowBlur::adjustBlurDistance):
        (WebCore::ShadowBlur::calculateLayerBoundingRect):
        (WebCore::ShadowBlur::beginShadowLayer):
        (WebCore::ShadowBlur::endShadowLayer):
        (WebCore::ShadowBlur::drawRectShadow):
        (WebCore::ShadowBlur::drawRectShadowWithoutTiling):
        (WebCore::ShadowBlur::drawRectShadowWithTiling):
        (WebCore::ShadowBlur::clipBounds):
        * platform/graphics/ShadowBlur.h: Added.
        (WebCore::ShadowBlur::setShadowsIgnoreTransforms):
        (WebCore::ShadowBlur::shadowsIgnoreTransforms):
        * platform/graphics/cg/GraphicsContextCG.cpp:
        (WebCore::GraphicsContext::clipBounds):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@77097 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f43e2282
2011-01-30 Simon Fraser <simon.fraser@apple.com>
Reviewed by Sam Weinig.
Make ContextShadow code cross-platform
https://bugs.webkit.org/show_bug.cgi?id=51312
Add a new class, ShadowBlur, that contains most of the
code from ContextShadow, but is fully cross-platform.
It depends on one new method, GraphicsContext::clipBounds(),
which platforms will have to implement.
Add ShadowBlur to the Mac Xcode project, but don't use it
anywhere yet.
* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::clipBounds):
* platform/graphics/GraphicsContext.h:
* platform/graphics/ShadowBlur.cpp: Added.
(WebCore::roundUpToMultipleOf32):
(WebCore::ScratchBuffer::ScratchBuffer):
(WebCore::ScratchBuffer::getScratchBuffer):
(WebCore::ScratchBuffer::scheduleScratchBufferPurge):
(WebCore::ScratchBuffer::timerFired):
(WebCore::ScratchBuffer::clearScratchBuffer):
(WebCore::ScratchBuffer::shared):
(WebCore::ShadowBlur::ShadowBlur):
(WebCore::ShadowBlur::blurLayerImage):
(WebCore::ShadowBlur::adjustBlurDistance):
(WebCore::ShadowBlur::calculateLayerBoundingRect):
(WebCore::ShadowBlur::beginShadowLayer):
(WebCore::ShadowBlur::endShadowLayer):
(WebCore::ShadowBlur::drawRectShadow):
(WebCore::ShadowBlur::drawRectShadowWithoutTiling):
(WebCore::ShadowBlur::drawRectShadowWithTiling):
(WebCore::ShadowBlur::clipBounds):
* platform/graphics/ShadowBlur.h: Added.
(WebCore::ShadowBlur::setShadowsIgnoreTransforms):
(WebCore::ShadowBlur::shadowsIgnoreTransforms):
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::clipBounds):
2011-01-29 Simon Fraser <simon.fraser@apple.com>
Reviewed by Dan Bernstein.
......@@ -254,6 +254,8 @@
0C45342810CDBBFA00869157 /* JSWebGLUniformLocation.h in Headers */ = {isa = PBXBuildFile; fileRef = 0C45342610CDBBFA00869157 /* JSWebGLUniformLocation.h */; };
0F11A54F0F39233100C37884 /* RenderSelectionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F11A54E0F39233100C37884 /* RenderSelectionInfo.h */; };
0F15DA8A0F3AAEE70000CE47 /* AnimationControllerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F15DA890F3AAEE70000CE47 /* AnimationControllerPrivate.h */; };
0F3DD44F12F5EA1B000D9190 /* ShadowBlur.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F3DD44D12F5EA1B000D9190 /* ShadowBlur.cpp */; };
0F3DD45012F5EA1B000D9190 /* ShadowBlur.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F3DD44E12F5EA1B000D9190 /* ShadowBlur.h */; };
0F500AAF0F54DB1B00EEF928 /* TransformState.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F500AAE0F54DB1B00EEF928 /* TransformState.h */; };
0F500AB10F54DB3100EEF928 /* TransformState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F500AB00F54DB3100EEF928 /* TransformState.cpp */; };
0F56028F0E4B76580065B038 /* RenderMarquee.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F56028D0E4B76580065B038 /* RenderMarquee.h */; };
......@@ -6568,6 +6570,8 @@
0C45342610CDBBFA00869157 /* JSWebGLUniformLocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebGLUniformLocation.h; sourceTree = "<group>"; };
0F11A54E0F39233100C37884 /* RenderSelectionInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSelectionInfo.h; sourceTree = "<group>"; };
0F15DA890F3AAEE70000CE47 /* AnimationControllerPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AnimationControllerPrivate.h; path = animation/AnimationControllerPrivate.h; sourceTree = "<group>"; };
0F3DD44D12F5EA1B000D9190 /* ShadowBlur.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ShadowBlur.cpp; sourceTree = "<group>"; };
0F3DD44E12F5EA1B000D9190 /* ShadowBlur.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShadowBlur.h; sourceTree = "<group>"; };
0F500AAE0F54DB1B00EEF928 /* TransformState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TransformState.h; sourceTree = "<group>"; };
0F500AB00F54DB3100EEF928 /* TransformState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TransformState.cpp; sourceTree = "<group>"; };
0F56028D0E4B76580065B038 /* RenderMarquee.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderMarquee.h; sourceTree = "<group>"; };
......@@ -17537,6 +17541,8 @@
A73F95FD12C97BFE0031AAF9 /* RoundedIntRect.h */,
371F4FFB0D25E7F300ECE0D5 /* SegmentedFontData.cpp */,
371F4FFA0D25E7F300ECE0D5 /* SegmentedFontData.h */,
0F3DD44D12F5EA1B000D9190 /* ShadowBlur.cpp */,
0F3DD44E12F5EA1B000D9190 /* ShadowBlur.h */,
B2C3DA530D006CD600EF6F26 /* SimpleFontData.cpp */,
B2C3DA540D006CD600EF6F26 /* SimpleFontData.h */,
B23540F00D00782E002382FA /* StringTruncator.cpp */,
......@@ -22451,6 +22457,7 @@
E134F5AB12EE343F004EC58D /* IntRectHash.h in Headers */,
977E2DCE12F0E28300C13379 /* HTMLSourceTracker.h in Headers */,
977E2E0F12F0FC9C00C13379 /* XSSFilter.h in Headers */,
0F3DD45012F5EA1B000D9190 /* ShadowBlur.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -25148,6 +25155,7 @@
4F2D205512EAE7B3005C2874 /* InspectorAgent.cpp in Sources */,
977E2DCD12F0E28300C13379 /* HTMLSourceTracker.cpp in Sources */,
977E2E0E12F0FC9C00C13379 /* XSSFilter.cpp in Sources */,
0F3DD44F12F5EA1B000D9190 /* ShadowBlur.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -68,6 +68,8 @@ typedef void* PlatformContext;
// This class should be copyable since GraphicsContextQt keeps a stack of
// the shadow state for savePlatformState and restorePlatformState.
// This class is Deprecated. Platforms should migrate to ShadowBlur.
class ContextShadow {
public:
enum {
......
......@@ -565,6 +565,14 @@ void GraphicsContext::clipToImageBuffer(ImageBuffer* buffer, const FloatRect& re
buffer->clip(this, rect);
}
#if !PLATFORM(CG)
IntRect GraphicsContext::clipBounds() const
{
ASSERT_NOT_REACHED();
return IntRect();
}
#endif
TextDrawingModeFlags GraphicsContext::textDrawingMode() const
{
return m_state.textDrawingMode;
......
......@@ -320,6 +320,8 @@ namespace WebCore {
void clipPath(const Path&, WindRule);
void clipConvexPolygon(size_t numPoints, const FloatPoint*, bool antialias = true);
void clipToImageBuffer(ImageBuffer*, const FloatRect&);
IntRect clipBounds() const;
TextDrawingModeFlags textDrawingMode() const;
void setTextDrawingMode(TextDrawingModeFlags);
......@@ -373,7 +375,7 @@ namespace WebCore {
// This clip function is used only by <canvas> code. It allows
// implementations to handle clipping on the canvas differently since
// the disipline is different.
// the discipline is different.
void canvasClip(const Path&);
void clipOut(const Path&);
......
This diff is collapsed.
/*
* Copyright (C) 2011 Apple Inc.
* Copyright (C) 2010 Sencha, Inc.
* Copyright (C) 2010 Igalia S.L.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ShadowBlur_h
#define ShadowBlur_h
#include "Color.h"
#include "FloatRect.h"
#include "RoundedIntRect.h"
#include <wtf/Noncopyable.h>
namespace WebCore {
class AffineTransform;
class GraphicsContext;
class ImageBuffer;
class ShadowBlur {
WTF_MAKE_NONCOPYABLE(ShadowBlur);
public:
ShadowBlur(float radius, const FloatSize& offset, const Color&, ColorSpace);
void setShadowsIgnoreTransforms(bool ignoreTransforms) { m_shadowsIgnoreTransforms = ignoreTransforms; }
bool shadowsIgnoreTransforms() const { return m_shadowsIgnoreTransforms; }
void drawRectShadow(GraphicsContext*, const FloatRect&, const RoundedIntRect::Radii&);
private:
GraphicsContext* beginShadowLayer(GraphicsContext*, const FloatRect& layerArea);
void endShadowLayer(GraphicsContext*);
void adjustBlurDistance(GraphicsContext*);
void blurLayerImage(unsigned char*, const IntSize&, int stride);
IntRect calculateLayerBoundingRect(GraphicsContext*, const FloatRect& layerArea, const IntRect& clipRect);
void drawRectShadowWithoutTiling(GraphicsContext*, const FloatRect&, const RoundedIntRect::Radii&, float alpha);
void drawRectShadowWithTiling(GraphicsContext*, const FloatRect&, const RoundedIntRect::Radii&, float alpha, const IntSize& shadowTemplateSize);
enum ShadowType {
NoShadow,
SolidShadow,
BlurShadow
};
ShadowType m_type;
Color m_color;
ColorSpace m_colorSpace;
float m_blurRadius;
FloatSize m_offset;
ImageBuffer* m_layerImage; // Buffer to where the temporary shadow will be drawn to.
FloatRect m_sourceRect; // Sub-rect of m_layerImage that contains the shadow pixels.
FloatPoint m_layerOrigin; // Top-left corner of the (possibly clipped) bounding rect to draw the shadow to.
FloatSize m_layerSize; // Size of m_layerImage pixels that need blurring.
FloatSize m_layerContextTranslation; // Translation to apply to m_layerContext for the shadow to be correctly clipped.
bool m_shadowsIgnoreTransforms;
};
} // namespace WebCore
#endif // ShadowBlur_h
......@@ -727,6 +727,11 @@ void GraphicsContext::clipPath(const Path& path, WindRule clipRule)
CGContextClip(context);
}
IntRect GraphicsContext::clipBounds() const
{
return enclosingIntRect(CGContextGetClipBoundingBox(platformContext()));
}
void GraphicsContext::addInnerRoundedRectClip(const IntRect& rect, int thickness)
{
if (paintingDisabled())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment