diff options
Diffstat (limited to 'webkit/port/svg')
-rw-r--r-- | webkit/port/svg/graphics/skia/RenderPathSkia.cpp | 77 | ||||
-rw-r--r-- | webkit/port/svg/graphics/skia/SVGPaintServerGradientSkia.cpp | 229 | ||||
-rw-r--r-- | webkit/port/svg/graphics/skia/SVGPaintServerPatternSkia.cpp | 86 | ||||
-rw-r--r-- | webkit/port/svg/graphics/skia/SVGPaintServerSkia.cpp | 75 | ||||
-rw-r--r-- | webkit/port/svg/graphics/skia/SVGResourceFilterSkia.cpp | 54 | ||||
-rw-r--r-- | webkit/port/svg/graphics/skia/SVGResourceMaskerSkia.cpp | 58 | ||||
-rw-r--r-- | webkit/port/svg/graphics/skia/SkiaSupport.cpp | 117 | ||||
-rw-r--r-- | webkit/port/svg/graphics/skia/SkiaSupport.h | 43 |
8 files changed, 739 insertions, 0 deletions
diff --git a/webkit/port/svg/graphics/skia/RenderPathSkia.cpp b/webkit/port/svg/graphics/skia/RenderPathSkia.cpp new file mode 100644 index 0000000..1212969 --- /dev/null +++ b/webkit/port/svg/graphics/skia/RenderPathSkia.cpp @@ -0,0 +1,77 @@ +// Copyright 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" +#include "GraphicsContext.h" +#include "PlatformContextSkia.h" +#include "RenderPath.h" +#include "SkiaSupport.h" +#include "SkiaUtils.h" +#include "SkPaint.h" +#include "SkPath.h" +#include "SVGPaintServer.h" + +#if ENABLE(SVG) + +namespace WebCore { + +bool RenderPath::strokeContains(const FloatPoint& point, bool requiresStroke) const +{ + if (path().isEmpty()) + return false; + + if (requiresStroke && !SVGPaintServer::strokePaintServer(style(), this)) + return false; + + GraphicsContext* scratch = scratchContext(); + scratch->save(); + applyStrokeStyleToContext(scratch, style(), this); + + SkPaint paint; + scratch->platformContext()->setupPaintForStroking(&paint, 0, 0); + SkPath strokePath; + paint.getFillPath(*path().platformPath(), &strokePath); + bool contains = SkPathContainsPoint(&strokePath, point, + SkPath::kWinding_FillType); + + scratch->restore(); + return contains; +} + +FloatRect RenderPath::strokeBBox() const +{ + if (style()->svgStyle()->hasStroke()) + return strokeBoundingBox(path(), style(), this); + + return path().boundingRect(); +} + +} + +#endif // ENABLE(SVG) diff --git a/webkit/port/svg/graphics/skia/SVGPaintServerGradientSkia.cpp b/webkit/port/svg/graphics/skia/SVGPaintServerGradientSkia.cpp new file mode 100644 index 0000000..3b8b61b --- /dev/null +++ b/webkit/port/svg/graphics/skia/SVGPaintServerGradientSkia.cpp @@ -0,0 +1,229 @@ +// Copyright 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 "SVGPaintServerGradient.h" +#include "SVGPaintServerLinearGradient.h" +#include "SVGPaintServerRadialGradient.h" + +#include "GraphicsContext.h" +#include "Path.h" +#include "PlatformContextSkia.h" +#include "RenderObject.h" +#include "RenderPath.h" +#include "RenderStyle.h" +#include "SVGGradientElement.h" +#include "SkiaSupport.h" + +#include "SkGradientShader.h" +#include "SkPath.h" +#include "SkMatrix.h" +#include "SkiaUtils.h" + +namespace WebCore { + +// Helper class used by linear & radial gradient +class SkiaGradientBuilder +{ +public: + SkiaGradientBuilder(const Vector<SVGGradientStop>& stops, float opacity) { + count_ = stops.size(); + unsigned cur = 0; + + // If the gradient doesn't span the full width, add pseudo-stops + // at the endpoints + if (stops[0].first > 0) { + count_++; + cur++; + } + + if (stops[stops.size()-1].first < 1) + count_++; + + colors_ = new SkColor[count_]; + pos_ = new SkScalar[count_]; + float last = 0.0; + + // Loop through the WebKit-provided array of SVG gradient stops and + // put it in a format suitable for providing to Skia + for (unsigned i = 0; i < stops.size(); ++i, ++cur) { + float offset = stops[i].first; + Color color = stops[i].second; + + colors_[cur]=SkColorSetARGB(static_cast<int>(opacity*color.alpha()), + color.red(), + color.green(), + color.blue()); + last=pos_[cur]=std::max(last, offset); + } + + if (stops[0].first > 0) { + colors_[0] = colors_[1]; + pos_[0] = 0; + } + if (stops[stops.size()-1].first < 1) { + colors_[count_-1] = colors_[count_-2]; + pos_[count_-1] = 1; + } + } + + ~SkiaGradientBuilder() { + delete[] colors_; + delete[] pos_; + } + + const SkColor* colors() const { return colors_; } + const SkScalar* pos() const { return pos_; } + unsigned count() const { return count_; } + +private: + SkColor* colors_; + SkScalar* pos_; + unsigned count_; +}; + +bool SVGPaintServerGradient::setup(GraphicsContext*& context, + const RenderObject* object, + SVGPaintTargetType type, + bool isPaintingText) const +{ + m_ownerElement->buildGradient(); + + RenderStyle* style = object->style(); + bool isFilled = + (type & ApplyToFillTargetType) && + style->svgStyle()->hasFill(); + bool isStroked = + (type & ApplyToStrokeTargetType) && + style->svgStyle()->hasStroke(); + + if(!gradientStops().size()) + return false; + + if(gradientStops().size()==1) { + context->setFillColor(gradientStops()[0].second); + return true; + } + + // Create a gradient builder helper to generate the data + // we'll need to provide Skia + SkiaGradientBuilder builder(gradientStops(), + isFilled ? style->svgStyle()->fillOpacity() : + style->svgStyle()->strokeOpacity()); + + SkShader::TileMode tile_mode; + + // Convert SVG spread modes to Skia tile modes + switch(spreadMethod()) + { + default: + case SpreadMethodPad: + tile_mode = SkShader::kClamp_TileMode; break; + case SpreadMethodReflect: + tile_mode = SkShader::kMirror_TileMode; break; + case SpreadMethodRepeat: + tile_mode = SkShader::kRepeat_TileMode; break; + } + + SkShader* shader = NULL; + + SkMatrix matrix; + + // Calculate a matrix to transform a gradient to fit the bounding box + if (boundingBoxMode()) { + matrix.reset(); + SkRect rc = boundingBoxForCurrentStroke(context); + + matrix.preTranslate(rc.fLeft, rc.fTop); + matrix.preScale(rc.width(), rc.height()); + matrix.preConcat(gradientTransform()); + } else + matrix = gradientTransform(); + + if (this->type() == LinearGradientPaintServer) { + const SVGPaintServerLinearGradient* linear = + static_cast<const SVGPaintServerLinearGradient*>(this); + + SkPoint pts[2]; + + pts[0].fX = linear->gradientStart().x(); + pts[0].fY = linear->gradientStart().y(); + pts[1].fX = linear->gradientEnd().x(); + pts[1].fY = linear->gradientEnd().y(); + + shader = SkGradientShader::CreateLinear(pts, + builder.colors(), builder.pos(), builder.count(), tile_mode); + } else if (this->type() == RadialGradientPaintServer) { + const SVGPaintServerRadialGradient* radial = + static_cast<const SVGPaintServerRadialGradient*>(this); + + SkPoint center; + SkScalar radius; + + center.fX = radial->gradientCenter().x(); + center.fY = radial->gradientCenter().y(); + radius = radial->gradientRadius(); + + shader = SkGradientShader::CreateRadial( + center, radius, builder.colors(), builder.pos(), + builder.count(), tile_mode); + + } else { + return false; + } + + if (isPaintingText) { + if (isFilled) { + context->setTextDrawingMode(cTextFill); + } + + if (isStroked) { + context->setTextDrawingMode(cTextStroke); + } + } + + if (isStroked) { + applyStrokeStyleToContext(context, style, object); + } + + if (shader) { + shader->setLocalMatrix(matrix); + context->platformContext()->setGradient(shader); + + return true; + } + + return false; +} + +} // namespace WebCore + +#endif diff --git a/webkit/port/svg/graphics/skia/SVGPaintServerPatternSkia.cpp b/webkit/port/svg/graphics/skia/SVGPaintServerPatternSkia.cpp new file mode 100644 index 0000000..8400633 --- /dev/null +++ b/webkit/port/svg/graphics/skia/SVGPaintServerPatternSkia.cpp @@ -0,0 +1,86 @@ +// Copyright 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 "GraphicsContext.h" +#include "ImageBuffer.h" +#include "RenderObject.h" +#include "Pattern.h" +#include "SVGPatternElement.h" +#include "SVGPaintServerPattern.h" +#include "SkiaSupport.h" + +#include "SkShader.h" +#include "SkiaUtils.h" + +namespace WebCore { + +bool SVGPaintServerPattern::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const +{ + RenderStyle* style = object->style(); + + // Build pattern tile, passing destination object bounding box + FloatRect targetRect; + if (isPaintingText) { + IntRect textBoundary = const_cast<RenderObject*>(object)->absoluteBoundingBoxRect(); + targetRect = object->absoluteTransform().inverse().mapRect(textBoundary); + } else + targetRect = object->relativeBBox(false); + + m_ownerElement->buildPattern(targetRect); + + if (!tile()) + return false; + + AffineTransform transform = patternTransform(); + transform.translate(patternBoundaries().x(), patternBoundaries().y()); + + RefPtr<Pattern> pattern(Pattern::create(tile()->image(), true, true)); + + if ((type & ApplyToFillTargetType) && style->svgStyle()->hasFill()) { + context->setFillPattern(pattern); + if (isPaintingText) + context->setTextDrawingMode(cTextFill); + } + + if ((type & ApplyToStrokeTargetType) && style->svgStyle()->hasStroke()) { + context->setStrokePattern(pattern); + applyStrokeStyleToContext(context, style, object); + if (isPaintingText) + context->setTextDrawingMode(cTextStroke); + } + + return true; +} + +} // namespace WebCore + +#endif diff --git a/webkit/port/svg/graphics/skia/SVGPaintServerSkia.cpp b/webkit/port/svg/graphics/skia/SVGPaintServerSkia.cpp new file mode 100644 index 0000000..79776d8 --- /dev/null +++ b/webkit/port/svg/graphics/skia/SVGPaintServerSkia.cpp @@ -0,0 +1,75 @@ +// Copyright 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 "SVGPaintServer.h" + +#include "GraphicsContext.h" +#include "RenderPath.h" +#include "PlatformContextSkia.h" +#include "SkiaUtils.h" + +namespace WebCore { + +void SVGPaintServer::draw(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type) const +{ + if (!setup(context, object, type)) + return; + + renderPath(context, object, type); + teardown(context, object, type); +} + +void SVGPaintServer::teardown(GraphicsContext*& context, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const +{ + // WebKit implicitly expects us to reset the path. + // For example in fillAndStrokePath() of RenderPath.cpp the path is + // added back to the context after filling. This is because internally it + // calls CGContextFillPath() which closes the path. + context->beginPath(); + context->platformContext()->setGradient(NULL); + context->platformContext()->setPattern(NULL); +} + +void SVGPaintServer::renderPath(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type) const +{ + RenderStyle* renderStyle = object ? object->style() : NULL; + + if ((type & ApplyToFillTargetType) && (!renderStyle || renderStyle->svgStyle()->hasFill())) + context->fillPath(); + + if ((type & ApplyToStrokeTargetType) && (!renderStyle || renderStyle->svgStyle()->hasStroke())) + context->strokePath(); +} + +} // namespace WebCore + +#endif diff --git a/webkit/port/svg/graphics/skia/SVGResourceFilterSkia.cpp b/webkit/port/svg/graphics/skia/SVGResourceFilterSkia.cpp new file mode 100644 index 0000000..4f9aea7 --- /dev/null +++ b/webkit/port/svg/graphics/skia/SVGResourceFilterSkia.cpp @@ -0,0 +1,54 @@ +// Copyright 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) && ENABLE(SVG_FILTERS) +#include "NotImplemented.h" +#include "SVGResourceFilter.h" + +namespace WebCore { + +SVGResourceFilterPlatformData* SVGResourceFilter::createPlatformData() +{ + return 0; +} + +void SVGResourceFilter::prepareFilter(GraphicsContext*&, const FloatRect&) +{ + notImplemented(); +} + +void SVGResourceFilter::applyFilter(GraphicsContext*&, const FloatRect&) +{ + notImplemented(); +} + +} + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/webkit/port/svg/graphics/skia/SVGResourceMaskerSkia.cpp b/webkit/port/svg/graphics/skia/SVGResourceMaskerSkia.cpp new file mode 100644 index 0000000..e430633 --- /dev/null +++ b/webkit/port/svg/graphics/skia/SVGResourceMaskerSkia.cpp @@ -0,0 +1,58 @@ +// Copyright 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) +{ + // TODO(jhaas): implement me +#if 0 + cairo_t* cr = context->platformContext(); + cairo_surface_t* surface = mask()->surface(); + if (!surface) + return; + cairo_pattern_t* mask = cairo_pattern_create_for_surface(surface); + cairo_mask(cr, mask); + cairo_pattern_destroy(mask); +#endif + notImplemented(); +} + +} // namespace WebCore + +#endif diff --git a/webkit/port/svg/graphics/skia/SkiaSupport.cpp b/webkit/port/svg/graphics/skia/SkiaSupport.cpp new file mode 100644 index 0000000..2c3fe0d --- /dev/null +++ b/webkit/port/svg/graphics/skia/SkiaSupport.cpp @@ -0,0 +1,117 @@ +// Copyright 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. + +// Helper methods for Skia SVG rendering, inspired by CgSupport.* + + + +#include "config.h" +#if ENABLE(SVG) +#include "SkiaSupport.h" + +#include "ImageBuffer.h" +#include "GraphicsContext.h" +#include "RenderStyle.h" +#include "RenderPath.h" +#include "SVGPaintServer.h" +#include "SVGRenderStyle.h" + +#include "SkiaUtils.h" +#include "SkDashPathEffect.h" + +namespace WebCore { + +void applyStrokeStyleToContext(GraphicsContext* context, const RenderStyle* style, const RenderObject* object) +{ + const SVGRenderStyle* svgStyle = style->svgStyle(); + + context->setStrokeThickness(SVGRenderStyle::cssPrimitiveToLength(object, svgStyle->strokeWidth(), 1.0)); + + context->setLineCap(svgStyle->capStyle()); + context->setLineJoin(svgStyle->joinStyle()); + + if (svgStyle->joinStyle() == MiterJoin) + context->setMiterLimit(svgStyle->strokeMiterLimit()); + + const DashArray& dashes = dashArrayFromRenderingStyle(style); + float dashOffset = SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeDashOffset(), 0.0); + + unsigned int dashLength = !dashes.isEmpty() ? dashes.size() : 0; + if(dashLength) { + unsigned int count = (dashLength % 2) == 0 ? dashLength : dashLength * 2; + SkScalar* intervals = new SkScalar[count]; + + for(unsigned int i = 0; i < count; i++) + intervals[i] = dashes[i % dashLength]; + + context->platformContext()->setDashPathEffect(new SkDashPathEffect(intervals, count, dashOffset)); + + delete[] intervals; + } +} + +GraphicsContext* scratchContext() +{ + static ImageBuffer* scratch = NULL; + if (!scratch) + scratch = ImageBuffer::create(IntSize(1, 1), false).release(); + // We don't bother checking for failure creating the ImageBuffer, since our + // ImageBuffer initializer won't fail. + return scratch->context(); +} + +FloatRect boundingBoxForCurrentStroke(const GraphicsContext* context) +{ + SkPaint paint; + context->platformContext()->setupPaintForStroking(&paint, 0, 0); + SkPath boundingPath; + paint.getFillPath(*context->platformContext()->currentPath(), + &boundingPath); + SkRect r; + boundingPath.computeBounds(&r, SkPath::kExact_BoundsType); + return r; +} + +FloatRect strokeBoundingBox(const Path& path, RenderStyle* style, + const RenderObject* object) +{ + GraphicsContext* scratch = scratchContext(); + scratch->save(); + scratch->beginPath(); + scratch->addPath(path); + applyStrokeStyleToContext(scratch, style, object); + + FloatRect r = boundingBoxForCurrentStroke(scratch); + scratch->restore(); + return r; +} + +} + +#endif // ENABLE(SVG) diff --git a/webkit/port/svg/graphics/skia/SkiaSupport.h b/webkit/port/svg/graphics/skia/SkiaSupport.h new file mode 100644 index 0000000..c4e7547 --- /dev/null +++ b/webkit/port/svg/graphics/skia/SkiaSupport.h @@ -0,0 +1,43 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Helper methods for Skia SVG rendering, inspired by CgSupport.* + +#ifndef SkiaSupport_h +#define SkiaSupport_h + +#if ENABLE(SVG) + +#include "SVGResource.h" + +namespace WebCore { + +class Path; +class FloatRect; +class RenderStyle; +class RenderObject; +class GraphicsContext; + +void applyStrokeStyleToContext(GraphicsContext*, const RenderStyle*, const RenderObject*); +void applyFillStyleToContext(GraphicsContext*, const RenderStyle*, const RenderObject*); + +// Returns a statically allocated 1x1 GraphicsContext intended for temporary +// operations. Please save() the state and restore() it when you're done with +// the context. +GraphicsContext* scratchContext(); + +// Computes the bounding box for the stroke and style currently selected into +// the given bounding box. This also takes into account the stroke width. +FloatRect boundingBoxForCurrentStroke(const GraphicsContext* context); + +// Returns the bounding box for the given path of the given style, including the +// stroke width. +FloatRect strokeBoundingBox(const Path& path, RenderStyle*, const RenderObject*); + +} + + +#endif // ENABLE(SVG) +#endif // #ifndef SkiaSupport_h + |