From 39cf4a175628e4fd54a93c2c642df8af6325c148 Mon Sep 17 00:00:00 2001 From: Steve Block Date: Fri, 5 Feb 2010 16:13:18 +0000 Subject: Merge webkit.org at r54340 : Implement new Pattern methods for Android See http://trac.webkit.org/changeset/54203 Change-Id: Ib68d10f5b7d045b19ae815613ffb0ff836aafe56 --- .../graphics/android/GraphicsContextAndroid.cpp | 4 ++-- .../platform/graphics/android/PatternAndroid.cpp | 27 +++++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'WebCore/platform') diff --git a/WebCore/platform/graphics/android/GraphicsContextAndroid.cpp b/WebCore/platform/graphics/android/GraphicsContextAndroid.cpp index 76d3e73..c150ff4 100644 --- a/WebCore/platform/graphics/android/GraphicsContextAndroid.cpp +++ b/WebCore/platform/graphics/android/GraphicsContextAndroid.cpp @@ -333,8 +333,8 @@ static SkShader::TileMode SpreadMethod2TileMode(GradientSpreadMethod sm) { static void extactShader(SkPaint* paint, Pattern* pat, Gradient* grad) { if (pat) { - // createPlatformPattern() returns a new inst - paint->setShader(pat->createPlatformPattern(TransformationMatrix()))->safeUnref(); + // platformPattern() returns a cached obj + paint->setShader(pat->platformPattern(TransformationMatrix())); } else if (grad) { // grad->getShader() returns a cached obj GradientSpreadMethod sm = grad->spreadMethod(); diff --git a/WebCore/platform/graphics/android/PatternAndroid.cpp b/WebCore/platform/graphics/android/PatternAndroid.cpp index 58709fc..c80e0d1 100644 --- a/WebCore/platform/graphics/android/PatternAndroid.cpp +++ b/WebCore/platform/graphics/android/PatternAndroid.cpp @@ -40,16 +40,31 @@ static SkShader::TileMode toTileMode(bool doRepeat) { return doRepeat ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode; } -SkShader* Pattern::createPlatformPattern(const TransformationMatrix& ) const +void Pattern::platformDestroy() { + m_pattern->safeUnref(); + m_pattern = 0; +} + +SkShader* Pattern::platformPattern(const TransformationMatrix& ) +{ + if (m_pattern) + return m_pattern; + SkBitmapRef* ref = tileImage()->nativeImageForCurrentFrame(); if (!ref) return 0; - SkShader* s = SkShader::CreateBitmapShader(ref->bitmap(), - toTileMode(m_repeatX), - toTileMode(m_repeatY)); - s->setLocalMatrix(m_patternSpaceTransformation); - return s; + m_pattern = SkShader::CreateBitmapShader(ref->bitmap(), + toTileMode(m_repeatX), + toTileMode(m_repeatY)); + m_pattern->setLocalMatrix(m_patternSpaceTransformation); + return m_pattern; +} + +void Pattern::setPlatformPatternSpaceTransform() +{ + if (m_pattern) + m_pattern->setLocalMatrix(m_patternSpaceTransformation); } } //namespace -- cgit v1.1