diff options
author | Feng Qian <> | 2009-04-10 18:11:29 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-04-10 18:11:29 -0700 |
commit | 8f72e70a9fd78eec56623b3a62e68f16b7b27e28 (patch) | |
tree | 181bf9a400c30a1bf34ea6d72560e8d00111d549 /WebCore/svg/graphics | |
parent | 7ed56f225e0ade046e1c2178977f72b2d896f196 (diff) | |
download | external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.zip external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.tar.gz external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.tar.bz2 |
AI 145796: Land the WebKit merge @r42026.
Automated import of CL 145796
Diffstat (limited to 'WebCore/svg/graphics')
-rw-r--r-- | WebCore/svg/graphics/SVGImage.cpp | 10 | ||||
-rw-r--r-- | WebCore/svg/graphics/SVGPaintServer.cpp | 18 | ||||
-rw-r--r-- | WebCore/svg/graphics/SVGPaintServerGradient.cpp | 71 | ||||
-rw-r--r-- | WebCore/svg/graphics/SVGPaintServerGradient.h | 4 | ||||
-rw-r--r-- | WebCore/svg/graphics/SVGPaintServerPattern.cpp | 7 | ||||
-rw-r--r-- | WebCore/svg/graphics/SVGResourceClipper.cpp | 2 | ||||
-rw-r--r-- | WebCore/svg/graphics/SVGResourceMarker.cpp | 6 | ||||
-rw-r--r-- | WebCore/svg/graphics/SVGResourceMasker.cpp | 47 | ||||
-rw-r--r-- | WebCore/svg/graphics/cairo/SVGResourceMaskerCairo.cpp | 48 | ||||
-rw-r--r-- | WebCore/svg/graphics/cg/SVGResourceMaskerCg.cpp | 42 | ||||
-rw-r--r-- | WebCore/svg/graphics/cg/SVGResourceMaskerCg.mm | 128 | ||||
-rw-r--r-- | WebCore/svg/graphics/filters/cg/SVGFEHelpersCg.mm | 2 | ||||
-rw-r--r-- | WebCore/svg/graphics/qt/SVGResourceMaskerQt.cpp | 38 | ||||
-rw-r--r-- | WebCore/svg/graphics/skia/SVGResourceMaskerSkia.cpp | 49 |
14 files changed, 106 insertions, 366 deletions
diff --git a/WebCore/svg/graphics/SVGImage.cpp b/WebCore/svg/graphics/SVGImage.cpp index d315dfa..067f645 100644 --- a/WebCore/svg/graphics/SVGImage.cpp +++ b/WebCore/svg/graphics/SVGImage.cpp @@ -103,7 +103,7 @@ void SVGImage::setContainerSize(const IntSize& containerSize) if (containerSize.width() <= 0 || containerSize.height() <= 0) return; - if (!m_frame || !m_frame->document()) + if (!m_frame) return; SVGSVGElement* rootElement = static_cast<SVGDocument*>(m_frame->document())->rootElement(); if (!rootElement) @@ -114,7 +114,7 @@ void SVGImage::setContainerSize(const IntSize& containerSize) bool SVGImage::usesContainerSize() const { - if (!m_frame || !m_frame->document()) + if (!m_frame) return false; SVGSVGElement* rootElement = static_cast<SVGDocument*>(m_frame->document())->rootElement(); if (!rootElement) @@ -125,7 +125,7 @@ bool SVGImage::usesContainerSize() const IntSize SVGImage::size() const { - if (!m_frame || !m_frame->document()) + if (!m_frame) return IntSize(); SVGSVGElement* rootElement = static_cast<SVGDocument*>(m_frame->document())->rootElement(); @@ -151,7 +151,7 @@ IntSize SVGImage::size() const bool SVGImage::hasRelativeWidth() const { - if (!m_frame || !m_frame->document()) + if (!m_frame) return false; SVGSVGElement* rootElement = static_cast<SVGDocument*>(m_frame->document())->rootElement(); if (!rootElement) @@ -162,7 +162,7 @@ bool SVGImage::hasRelativeWidth() const bool SVGImage::hasRelativeHeight() const { - if (!m_frame || !m_frame->document()) + if (!m_frame) return false; SVGSVGElement* rootElement = static_cast<SVGDocument*>(m_frame->document())->rootElement(); if (!rootElement) diff --git a/WebCore/svg/graphics/SVGPaintServer.cpp b/WebCore/svg/graphics/SVGPaintServer.cpp index 4e7a8cf..0fcd722 100644 --- a/WebCore/svg/graphics/SVGPaintServer.cpp +++ b/WebCore/svg/graphics/SVGPaintServer.cpp @@ -37,6 +37,10 @@ #include "SVGStyledElement.h" #include "SVGURIReference.h" +#if PLATFORM(SKIA) +#include "PlatformContextSkia.h" +#endif + namespace WebCore { SVGPaintServer::SVGPaintServer() @@ -82,7 +86,7 @@ SVGPaintServer* SVGPaintServer::fillPaintServer(const RenderStyle* style, const AtomicString id(SVGURIReference::getTarget(fill->uri())); fillPaintServer = getPaintServerById(item->document(), id); - SVGElement* svgElement = static_cast<SVGElement*>(item->element()); + SVGElement* svgElement = static_cast<SVGElement*>(item->node()); ASSERT(svgElement && svgElement->document() && svgElement->isStyled()); if (item->isRenderPath() && fillPaintServer) @@ -123,7 +127,7 @@ SVGPaintServer* SVGPaintServer::strokePaintServer(const RenderStyle* style, cons AtomicString id(SVGURIReference::getTarget(stroke->uri())); strokePaintServer = getPaintServerById(item->document(), id); - SVGElement* svgElement = static_cast<SVGElement*>(item->element()); + SVGElement* svgElement = static_cast<SVGElement*>(item->node()); ASSERT(svgElement && svgElement->document() && svgElement->isStyled()); if (item->isRenderPath() && strokePaintServer) @@ -179,9 +183,9 @@ void SVGPaintServer::renderPath(GraphicsContext*& context, const RenderObject* p context->strokePath(); } -void SVGPaintServer::teardown(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool) const -{ #if PLATFORM(SKIA) +void SVGPaintServer::teardown(GraphicsContext*& context, const RenderObject*, SVGPaintTargetType, bool) const +{ // FIXME: Move this into the GraphicsContext // WebKit implicitly expects us to reset the path. // For example in fillAndStrokePath() of RenderPath.cpp the path is @@ -190,8 +194,12 @@ void SVGPaintServer::teardown(GraphicsContext*&, const RenderObject*, SVGPaintTa context->beginPath(); context->platformContext()->setGradient(0); context->platformContext()->setPattern(0); -#endif } +#else +void SVGPaintServer::teardown(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool) const +{ +} +#endif DashArray dashArrayFromRenderingStyle(const RenderStyle* style) { diff --git a/WebCore/svg/graphics/SVGPaintServerGradient.cpp b/WebCore/svg/graphics/SVGPaintServerGradient.cpp index b06eca1..eb0d80b 100644 --- a/WebCore/svg/graphics/SVGPaintServerGradient.cpp +++ b/WebCore/svg/graphics/SVGPaintServerGradient.cpp @@ -40,11 +40,6 @@ #include "SVGRenderSupport.h" #include "SVGRenderTreeAsText.h" -#if PLATFORM(CG) -#include <wtf/MathExtras.h> -#include <wtf/RetainPtr.h> -#endif - using namespace std; namespace WebCore { @@ -76,10 +71,8 @@ static TextStream& operator<<(TextStream& ts, const Vector<SVGGradientStop>& l) } SVGPaintServerGradient::SVGPaintServerGradient(const SVGGradientElement* owner) - : m_spreadMethod(SpreadMethodPad) - , m_boundingBoxMode(true) + : m_boundingBoxMode(true) , m_ownerElement(owner) - #if PLATFORM(CG) , m_savedContext(0) , m_imageBuffer(0) @@ -102,16 +95,6 @@ void SVGPaintServerGradient::setGradient(PassRefPtr<Gradient> gradient) m_gradient = gradient; } -GradientSpreadMethod SVGPaintServerGradient::spreadMethod() const -{ - return m_spreadMethod; -} - -void SVGPaintServerGradient::setGradientSpreadMethod(const GradientSpreadMethod& method) -{ - m_spreadMethod = method; -} - bool SVGPaintServerGradient::boundingBoxMode() const { return m_boundingBoxMode; @@ -133,8 +116,6 @@ void SVGPaintServerGradient::setGradientTransform(const TransformationMatrix& tr } #if PLATFORM(CG) -// Helper function for text painting in CG -// This Cg specific code should move to GraphicsContext and Font* in a next step. static inline const RenderObject* findTextRootObject(const RenderObject* start) { while (start && !start->isSVGText()) @@ -174,7 +155,7 @@ static inline bool createMaskAndSwapContextForTextGradient( return true; } -static inline void clipToTextMask(GraphicsContext* context, +static inline TransformationMatrix clipToTextMask(GraphicsContext* context, OwnPtr<ImageBuffer>& imageBuffer, const RenderObject* object, const SVGPaintServerGradient* gradientServer) { @@ -193,11 +174,13 @@ static inline void clipToTextMask(GraphicsContext* context, context->clipToImageBuffer(textBoundary, imageBuffer.get()); context->concatCTM(transform); + TransformationMatrix matrix; if (gradientServer->boundingBoxMode()) { - context->translate(maskBBox.x(), maskBBox.y()); - context->scale(FloatSize(maskBBox.width(), maskBBox.height())); + matrix.translate(maskBBox.x(), maskBBox.y()); + matrix.scaleNonUniform(maskBBox.width(), maskBBox.height()); } - context->concatCTM(gradientServer->gradientTransform()); + matrix.multiply(gradientServer->gradientTransform()); + return matrix; } #endif @@ -234,25 +217,29 @@ bool SVGPaintServerGradient::setup(GraphicsContext*& context, const RenderObject applyStrokeStyleToContext(context, object->style(), object); } + TransformationMatrix matrix; + // CG platforms will handle the gradient space transform for text in + // teardown, so we don't apply it here. For non-CG platforms, we + // want the text bounding box applied to the gradient space transform now, + // so the gradient shader can use it. +#if PLATFORM(CG) if (boundingBoxMode() && !isPaintingText) { +#else + if (boundingBoxMode()) { +#endif FloatRect bbox = object->relativeBBox(false); - // Don't use gradientes for 1d objects like horizontal/vertical + // Don't use gradients for 1d objects like horizontal/vertical // lines or rectangles without width or height. if (bbox.width() == 0 || bbox.height() == 0) { Color color(0, 0, 0); context->setStrokeColor(color); return true; } - context->translate(bbox.x(), bbox.y()); - context->scale(FloatSize(bbox.width(), bbox.height())); - - // With scaling the context, the strokeThickness is scaled too. We have to - // undo this. - float strokeThickness = std::max((context->strokeThickness() / ((bbox.width() + bbox.height()) / 2) - 0.001f), 0.f); - context->setStrokeThickness(strokeThickness); + matrix.translate(bbox.x(), bbox.y()); + matrix.scaleNonUniform(bbox.width(), bbox.height()); } - context->concatCTM(gradientTransform()); - context->setSpreadMethod(spreadMethod()); + matrix.multiply(gradientTransform()); + m_gradient->setGradientSpaceTransform(matrix); return true; } @@ -262,15 +249,19 @@ void SVGPaintServerGradient::teardown(GraphicsContext*& context, const RenderObj #if PLATFORM(CG) // renderPath() is not used when painting text, so we paint the gradient during teardown() if (isPaintingText && m_savedContext) { + // Restore on-screen drawing context context = m_savedContext; m_savedContext = 0; - clipToTextMask(context, m_imageBuffer, object, this); + TransformationMatrix matrix = clipToTextMask(context, m_imageBuffer, object, this); + m_gradient->setGradientSpaceTransform(matrix); + context->setFillGradient(m_gradient); + + FloatRect maskBBox = const_cast<RenderObject*>(findTextRootObject(object))->relativeBBox(false); + + context->fillRect(maskBBox); - // finally fill the text clip with the shading - CGContextDrawShading(context->platformContext(), m_gradient->platformGradient()); - m_imageBuffer.clear(); // we're done with our text mask buffer } #endif @@ -284,8 +275,8 @@ TextStream& SVGPaintServerGradient::externalRepresentation(TextStream& ts) const // abstract, don't stream type ts << "[stops=" << gradientStops() << "]"; - if (spreadMethod() != SpreadMethodPad) - ts << "[method=" << spreadMethod() << "]"; + if (m_gradient->spreadMethod() != SpreadMethodPad) + ts << "[method=" << m_gradient->spreadMethod() << "]"; if (!boundingBoxMode()) ts << " [bounding box mode=" << boundingBoxMode() << "]"; if (!gradientTransform().isIdentity()) diff --git a/WebCore/svg/graphics/SVGPaintServerGradient.h b/WebCore/svg/graphics/SVGPaintServerGradient.h index 16dab0b..b24c417 100644 --- a/WebCore/svg/graphics/SVGPaintServerGradient.h +++ b/WebCore/svg/graphics/SVGPaintServerGradient.h @@ -52,9 +52,6 @@ namespace WebCore { void setGradient(PassRefPtr<Gradient>); Gradient* gradient() const; - GradientSpreadMethod spreadMethod() const; - void setGradientSpreadMethod(const GradientSpreadMethod&); - // Gradient start and end points are percentages when used in boundingBox mode. // For instance start point with value (0,0) is top-left and end point with // value (100, 100) is bottom-right. BoundingBox mode is enabled by default. @@ -78,7 +75,6 @@ namespace WebCore { private: Vector<SVGGradientStop> m_stops; RefPtr<Gradient> m_gradient; - GradientSpreadMethod m_spreadMethod; bool m_boundingBoxMode; TransformationMatrix m_gradientTransform; const SVGGradientElement* m_ownerElement; diff --git a/WebCore/svg/graphics/SVGPaintServerPattern.cpp b/WebCore/svg/graphics/SVGPaintServerPattern.cpp index 5926aad..a2ac5df 100644 --- a/WebCore/svg/graphics/SVGPaintServerPattern.cpp +++ b/WebCore/svg/graphics/SVGPaintServerPattern.cpp @@ -115,8 +115,6 @@ bool SVGPaintServerPattern::setup(GraphicsContext*& context, const RenderObject* return false; context->save(); - context->translate(patternBoundaries().x(), patternBoundaries().y()); - context->concatCTM(patternTransform()); ASSERT(!m_pattern); @@ -160,6 +158,11 @@ bool SVGPaintServerPattern::setup(GraphicsContext*& context, const RenderObject* applyStrokeStyleToContext(context, object->style(), object); } + TransformationMatrix matrix; + matrix.translate(patternBoundaries().x(), patternBoundaries().y()); + matrix.multiply(patternTransform()); + m_pattern->setPatternSpaceTransform(matrix); + if (isPaintingText) { context->setTextDrawingMode(isFilled ? cTextFill : cTextStroke); #if PLATFORM(CG) diff --git a/WebCore/svg/graphics/SVGResourceClipper.cpp b/WebCore/svg/graphics/SVGResourceClipper.cpp index 51bda0d..5998afb 100644 --- a/WebCore/svg/graphics/SVGResourceClipper.cpp +++ b/WebCore/svg/graphics/SVGResourceClipper.cpp @@ -72,7 +72,7 @@ void SVGResourceClipper::applyClip(GraphicsContext* context, const FloatRect& bo if (clipData.bboxUnits) { TransformationMatrix transform; transform.translate(boundingBox.x(), boundingBox.y()); - transform.scale(boundingBox.width(), boundingBox.height()); + transform.scaleNonUniform(boundingBox.width(), boundingBox.height()); clipPath.transform(transform); } context->addPath(clipPath); diff --git a/WebCore/svg/graphics/SVGResourceMarker.cpp b/WebCore/svg/graphics/SVGResourceMarker.cpp index c50f5e3..112e4d6 100644 --- a/WebCore/svg/graphics/SVGResourceMarker.cpp +++ b/WebCore/svg/graphics/SVGResourceMarker.cpp @@ -82,14 +82,14 @@ void SVGResourceMarker::draw(GraphicsContext* context, const FloatRect& rect, do // the translation performed on the viewport itself. TransformationMatrix viewportTransform; if (m_useStrokeWidth) - viewportTransform.scale(strokeWidth, strokeWidth); + viewportTransform.scaleNonUniform(strokeWidth, strokeWidth); viewportTransform *= m_marker->viewportTransform(); double refX, refY; - viewportTransform.map(m_refX, m_refY, &refX, &refY); + viewportTransform.map(m_refX, m_refY, refX, refY); transform.translate(-refX, -refY); if (m_useStrokeWidth) - transform.scale(strokeWidth, strokeWidth); + transform.scaleNonUniform(strokeWidth, strokeWidth); // FIXME: PaintInfo should be passed into this method instead of being created here // FIXME: bounding box fractions are lost diff --git a/WebCore/svg/graphics/SVGResourceMasker.cpp b/WebCore/svg/graphics/SVGResourceMasker.cpp index 842f04f..8642e1e 100644 --- a/WebCore/svg/graphics/SVGResourceMasker.cpp +++ b/WebCore/svg/graphics/SVGResourceMasker.cpp @@ -28,9 +28,18 @@ #if ENABLE(SVG) #include "SVGResourceMasker.h" +#include "CanvasPixelArray.h" +#include "Image.h" #include "ImageBuffer.h" +#include "ImageData.h" +#include "GraphicsContext.h" +#include "SVGMaskElement.h" +#include "SVGRenderSupport.h" +#include "SVGRenderStyle.h" #include "TextStream.h" +#include <wtf/ByteArray.h> + using namespace std; namespace WebCore { @@ -51,6 +60,44 @@ void SVGResourceMasker::invalidate() m_mask.clear(); } +void SVGResourceMasker::applyMask(GraphicsContext* context, const FloatRect& boundingBox) +{ + if (!m_mask) + m_mask.set(m_ownerElement->drawMaskerContent(boundingBox, m_maskRect).release()); + + if (!m_mask) + return; + + IntSize imageSize(m_mask->size()); + IntRect intImageRect(0, 0, imageSize.width(), imageSize.height()); + + // Create new ImageBuffer to apply luminance + auto_ptr<ImageBuffer> luminancedImage(ImageBuffer::create(imageSize, false)); + if (!luminancedImage.get()) + return; + + PassRefPtr<CanvasPixelArray> srcPixelArray(m_mask->getImageData(intImageRect)->data()); + PassRefPtr<ImageData> destImageData(luminancedImage->getImageData(intImageRect)); + + for (unsigned pixelOffset = 0; pixelOffset < srcPixelArray->length(); pixelOffset++) { + unsigned pixelByteOffset = pixelOffset * 4; + + unsigned char r = 0, g = 0, b = 0, a = 0; + srcPixelArray->get(pixelByteOffset, r); + srcPixelArray->get(pixelByteOffset + 1, g); + srcPixelArray->get(pixelByteOffset + 2, b); + srcPixelArray->get(pixelByteOffset + 3, a); + + double luma = (r * 0.2125 + g * 0.7154 + b * 0.0721) * ((double)a / 255.0); + + destImageData->data()->set(pixelByteOffset + 3, luma); + } + + luminancedImage->putImageData(destImageData.get(), intImageRect, IntPoint(0, 0)); + + context->clipToImageBuffer(m_maskRect, luminancedImage.get()); +} + TextStream& SVGResourceMasker::externalRepresentation(TextStream& ts) const { ts << "[type=MASKER]"; diff --git a/WebCore/svg/graphics/cairo/SVGResourceMaskerCairo.cpp b/WebCore/svg/graphics/cairo/SVGResourceMaskerCairo.cpp deleted file mode 100644 index 1f690b5..0000000 --- a/WebCore/svg/graphics/cairo/SVGResourceMaskerCairo.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2007 Alp Toker <alp@atoker.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#if ENABLE(SVG) -#include "SVGResourceMasker.h" -#include "Image.h" -#include "ImageBuffer.h" -#include "GraphicsContext.h" - -#include <cairo.h> - -namespace WebCore { - -void SVGResourceMasker::applyMask(GraphicsContext* context, const FloatRect& boundingBox) -{ - if (!m_mask) - return; - - cairo_t* cr = context->platformContext(); - cairo_surface_t* surface = m_mask->image()->nativeImageForCurrentFrame(); - if (!surface) - return; - cairo_pattern_t* mask = cairo_pattern_create_for_surface(surface); - cairo_mask(cr, mask); - cairo_pattern_destroy(mask); -} - -} // namespace WebCore - -#endif diff --git a/WebCore/svg/graphics/cg/SVGResourceMaskerCg.cpp b/WebCore/svg/graphics/cg/SVGResourceMaskerCg.cpp deleted file mode 100644 index 4d2100b..0000000 --- a/WebCore/svg/graphics/cg/SVGResourceMaskerCg.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2007 Apple Inc. - * - * 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 COMPUTER, 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. - */ - - -#include "config.h" - -#if ENABLE(SVG) -#include "SVGResourceMasker.h" -#include "NotImplemented.h" - -namespace WebCore { - -void SVGResourceMasker::applyMask(GraphicsContext*, const FloatRect&) -{ - notImplemented(); -} - -} // namespace WebCore - -#endif // ENABLE(SVG) diff --git a/WebCore/svg/graphics/cg/SVGResourceMaskerCg.mm b/WebCore/svg/graphics/cg/SVGResourceMaskerCg.mm deleted file mode 100644 index 9793ba0..0000000 --- a/WebCore/svg/graphics/cg/SVGResourceMaskerCg.mm +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) 2005, 2006 Alexander Kellett <lypanov@kde.org> - * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> - * - * 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 COMPUTER, 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. - */ - -#include "config.h" - -#if ENABLE(SVG) -#import "SVGResourceMasker.h" - -#import "BlockExceptions.h" -#import "GraphicsContext.h" -#import "ImageBuffer.h" -#import "SVGMaskElement.h" -#import "SVGRenderSupport.h" -#import "SVGRenderStyle.h" -#import "SVGResourceFilter.h" -#import <QuartzCore/CIFilter.h> -#import <QuartzCore/CoreImage.h> - -using namespace std; - -namespace WebCore { - -static CIImage* applyLuminanceToAlphaFilter(CIImage* inputImage) -{ - CIFilter* luminanceToAlpha = [CIFilter filterWithName:@"CIColorMatrix"]; - [luminanceToAlpha setDefaults]; - CGFloat alpha[4] = {0.2125f, 0.7154f, 0.0721f, 0.0f}; - CGFloat zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - [luminanceToAlpha setValue:inputImage forKey:@"inputImage"]; - [luminanceToAlpha setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputRVector"]; - [luminanceToAlpha setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputGVector"]; - [luminanceToAlpha setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputBVector"]; - [luminanceToAlpha setValue:[CIVector vectorWithValues:alpha count:4] forKey:@"inputAVector"]; - [luminanceToAlpha setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputBiasVector"]; - return [luminanceToAlpha valueForKey:@"outputImage"]; -} - -static CIImage* applyExpandAlphatoGrayscaleFilter(CIImage* inputImage) -{ - CIFilter* alphaToGrayscale = [CIFilter filterWithName:@"CIColorMatrix"]; - CGFloat zero[4] = {0, 0, 0, 0}; - [alphaToGrayscale setDefaults]; - [alphaToGrayscale setValue:inputImage forKey:@"inputImage"]; - [alphaToGrayscale setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputRVector"]; - [alphaToGrayscale setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputGVector"]; - [alphaToGrayscale setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputBVector"]; - [alphaToGrayscale setValue:[CIVector vectorWithX:0.0f Y:0.0f Z:0.0f W:1.0f] forKey:@"inputAVector"]; - [alphaToGrayscale setValue:[CIVector vectorWithX:1.0f Y:1.0f Z:1.0f W:0.0f] forKey:@"inputBiasVector"]; - return [alphaToGrayscale valueForKey:@"outputImage"]; -} - -static CIImage* transformImageIntoGrayscaleMask(CIImage* inputImage) -{ - CIFilter* blackBackground = [CIFilter filterWithName:@"CIConstantColorGenerator"]; - [blackBackground setValue:[CIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.0f] forKey:@"inputColor"]; - - CIFilter* layerOverBlack = [CIFilter filterWithName:@"CISourceOverCompositing"]; - [layerOverBlack setValue:[blackBackground valueForKey:@"outputImage"] forKey:@"inputBackgroundImage"]; - [layerOverBlack setValue:inputImage forKey:@"inputImage"]; - - CIImage* luminanceAlpha = applyLuminanceToAlphaFilter([layerOverBlack valueForKey:@"outputImage"]); - CIImage* luminanceAsGrayscale = applyExpandAlphatoGrayscaleFilter(luminanceAlpha); - CIImage* alphaAsGrayscale = applyExpandAlphatoGrayscaleFilter(inputImage); - - CIFilter* multipliedGrayscale = [CIFilter filterWithName:@"CIMultiplyCompositing"]; - [multipliedGrayscale setValue:luminanceAsGrayscale forKey:@"inputBackgroundImage"]; - [multipliedGrayscale setValue:alphaAsGrayscale forKey:@"inputImage"]; - return [multipliedGrayscale valueForKey:@"outputImage"]; -} - -void SVGResourceMasker::applyMask(GraphicsContext* context, const FloatRect& boundingBox) -{ - if (!m_mask) - m_mask.set(m_ownerElement->drawMaskerContent(boundingBox, m_maskRect).release()); - - if (!m_mask) - return; - - IntSize maskSize(static_cast<int>(m_maskRect.width()), static_cast<int>(m_maskRect.height())); - clampImageBufferSizeToViewport(m_ownerElement->document()->renderer(), maskSize); - - // Create new graphics context in gray scale mode for image rendering - auto_ptr<ImageBuffer> grayScaleImage(ImageBuffer::create(maskSize, true)); - if (!grayScaleImage.get()) - return; - - BEGIN_BLOCK_OBJC_EXCEPTIONS - CGContextRef grayScaleContext = grayScaleImage->context()->platformContext(); - CIContext* ciGrayscaleContext = [CIContext contextWithCGContext:grayScaleContext options:nil]; - - // Transform colorized mask to gray scale - CIImage* colorMask = [CIImage imageWithCGImage:m_mask->image()->getCGImageRef()]; - if (!colorMask) - return; - - CIImage* grayScaleMask = transformImageIntoGrayscaleMask(colorMask); - [ciGrayscaleContext drawImage:grayScaleMask atPoint:CGPointZero fromRect:CGRectMake(0, 0, maskSize.width(), maskSize.height())]; - - CGContextClipToMask(context->platformContext(), m_maskRect, grayScaleImage->image()->getCGImageRef()); - END_BLOCK_OBJC_EXCEPTIONS -} - -} // namespace WebCore - -#endif // ENABLE(SVG) diff --git a/WebCore/svg/graphics/filters/cg/SVGFEHelpersCg.mm b/WebCore/svg/graphics/filters/cg/SVGFEHelpersCg.mm index 0f2eb75..399d4c1 100644 --- a/WebCore/svg/graphics/filters/cg/SVGFEHelpersCg.mm +++ b/WebCore/svg/graphics/filters/cg/SVGFEHelpersCg.mm @@ -59,7 +59,7 @@ CIVector* getVectorForChannel(ChannelSelectorType channel) CIColor* ciColor(const Color& c) { - CGColorRef colorCG = cgColor(c); + CGColorRef colorCG = createCGColor(c); CIColor* colorCI = [CIColor colorWithCGColor:colorCG]; CGColorRelease(colorCG); return colorCI; diff --git a/WebCore/svg/graphics/qt/SVGResourceMaskerQt.cpp b/WebCore/svg/graphics/qt/SVGResourceMaskerQt.cpp deleted file mode 100644 index 2b89bac..0000000 --- a/WebCore/svg/graphics/qt/SVGResourceMaskerQt.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org> - - This file is part of the KDE project - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - aint with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "config.h" - -#if ENABLE(SVG) -#include "SVGResourceMasker.h" - -namespace WebCore { - -void SVGResourceMasker::applyMask(GraphicsContext*, const FloatRect&) -{ - // FIXME: implement me :-) -} - -} // namespace WebCore - -#endif - -// vim:ts=4:noet diff --git a/WebCore/svg/graphics/skia/SVGResourceMaskerSkia.cpp b/WebCore/svg/graphics/skia/SVGResourceMaskerSkia.cpp deleted file mode 100644 index 06e6833..0000000 --- a/WebCore/svg/graphics/skia/SVGResourceMaskerSkia.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2008, Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT - * OWNER 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. - */ - -#include "config.h" - -#if ENABLE(SVG) -#include "SVGResourceMasker.h" -#include "ImageBuffer.h" -#include "GraphicsContext.h" - -#include "NotImplemented.h" - -namespace WebCore { - -void SVGResourceMasker::applyMask(GraphicsContext*, const FloatRect& boundingBox) -{ - notImplemented(); -} - -} // namespace WebCore - -#endif |