From 156d9de035224a88b7848c553b1839a49f004e6c Mon Sep 17 00:00:00 2001 From: Cary Clark Date: Tue, 28 Apr 2009 17:17:42 -0400 Subject: fix line dashing and patterns in svg remove unused methods in PlatformGraphicsContext.h make PlatformGraphicsContext constructors more similar set local matrix in pattern set dash path effect in graphics context --- .../graphics/android/GraphicsContextAndroid.cpp | 20 ++++++++++++++------ WebCore/platform/graphics/android/PatternAndroid.cpp | 5 ++--- .../graphics/android/PlatformGraphicsContext.cpp | 7 ++----- .../graphics/android/PlatformGraphicsContext.h | 3 --- 4 files changed, 18 insertions(+), 17 deletions(-) (limited to 'WebCore/platform/graphics/android') diff --git a/WebCore/platform/graphics/android/GraphicsContextAndroid.cpp b/WebCore/platform/graphics/android/GraphicsContextAndroid.cpp index 8800699..bd5baa0 100644 --- a/WebCore/platform/graphics/android/GraphicsContextAndroid.cpp +++ b/WebCore/platform/graphics/android/GraphicsContextAndroid.cpp @@ -84,6 +84,7 @@ public: struct State { SkPath* mPath; + SkPathEffect* mPathEffect; float mMiterLimit; float mAlpha; float mStrokeThickness; @@ -98,6 +99,7 @@ public: State() { mPath = NULL; // lazily allocated + mPathEffect = 0; mMiterLimit = 4; mAlpha = 1; mStrokeThickness = 0.0f; // Same as default in GraphicsContextPrivate.h @@ -114,10 +116,12 @@ public: State(const State& other) { memcpy(this, &other, sizeof(State)); mPath = deepCopyPtr(other.mPath); + mPathEffect->safeRef(); } ~State() { delete mPath; + mPathEffect->safeUnref(); } void setShadow(int radius, int dx, int dy, SkColor c) { @@ -269,6 +273,11 @@ public: rect->inset(-SK_ScalarHalf, -SK_ScalarHalf); } + SkPathEffect* pe = mState->mPathEffect; + if (pe) { + paint->setPathEffect(pe); + return false; + } switch (mCG->strokeStyle()) { case NoStroke: case SolidStroke: @@ -284,7 +293,7 @@ public: if (width > 0) { SkScalar intervals[] = { width, width }; - SkPathEffect* pe = new SkDashPathEffect(intervals, 2, 0); + pe = new SkDashPathEffect(intervals, 2, 0); paint->setPathEffect(pe)->unref(); // return true if we're basically a dotted dash of squares return RoundToInt(width) == RoundToInt(paint->getStrokeWidth()); @@ -963,8 +972,6 @@ void GraphicsContext::setLineDash(const DashArray& dashes, float dashOffset) if (paintingDisabled()) return; - // FIXME: This is lifted directly off SkiaSupport, lines 49-74 - // so it is not guaranteed to work correctly. size_t dashLength = dashes.size(); if (!dashLength) return; @@ -973,9 +980,10 @@ void GraphicsContext::setLineDash(const DashArray& dashes, float dashOffset) SkScalar* intervals = new SkScalar[count]; for (unsigned int i = 0; i < count; i++) - intervals[i] = dashes[i % dashLength]; -// FIXME: setDashPathEffect not defined -// platformContext()->setDashPathEffect(new SkDashPathEffect(intervals, count, dashOffset)); + intervals[i] = SkFloatToScalar(dashes[i % dashLength]); + SkPathEffect **effectPtr = &m_data->mState->mPathEffect; + (*effectPtr)->safeUnref(); + *effectPtr = new SkDashPathEffect(intervals, count, SkFloatToScalar(dashOffset)); delete[] intervals; } diff --git a/WebCore/platform/graphics/android/PatternAndroid.cpp b/WebCore/platform/graphics/android/PatternAndroid.cpp index ffdbbb1..ff2b522 100644 --- a/WebCore/platform/graphics/android/PatternAndroid.cpp +++ b/WebCore/platform/graphics/android/PatternAndroid.cpp @@ -40,14 +40,13 @@ static SkShader::TileMode toTileMode(bool doRepeat) { return doRepeat ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode; } -SkShader* Pattern::createPlatformPattern(const TransformationMatrix& transform) const +SkShader* Pattern::createPlatformPattern(const TransformationMatrix& ) const { SkBitmapRef* ref = tileImage()->nativeImageForCurrentFrame(); SkShader* s = SkShader::CreateBitmapShader(ref->bitmap(), toTileMode(m_repeatX), toTileMode(m_repeatY)); - - // TODO: do I treat transform as a local matrix??? + s->setLocalMatrix(m_patternSpaceTransformation); return s; } diff --git a/WebCore/platform/graphics/android/PlatformGraphicsContext.cpp b/WebCore/platform/graphics/android/PlatformGraphicsContext.cpp index b13f45f..e0aecfa 100644 --- a/WebCore/platform/graphics/android/PlatformGraphicsContext.cpp +++ b/WebCore/platform/graphics/android/PlatformGraphicsContext.cpp @@ -35,12 +35,9 @@ PlatformGraphicsContext::PlatformGraphicsContext(SkCanvas* canvas, WTF::Vector* buttons); ~PlatformGraphicsContext(); - void setupFillPaint(GraphicsContext*, SkPaint*); - void setupStrokePaint(GraphicsContext*, SkPaint*); - SkCanvas* mCanvas; bool deleteUs() const { return m_deleteCanvas; } -- cgit v1.1