diff options
author | Steve Block <steveblock@google.com> | 2010-02-05 14:27:46 +0000 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-02-15 10:49:50 +0000 |
commit | 5e2bc6953fe6923165b8a5d7679939693a1d58d6 (patch) | |
tree | 6ccb8c24bc2bf5e8f413e6cfae250b729b426631 /WebCore/platform/graphics/skia | |
parent | 4a00f4fccc3cb7e9996749a05631f5d7b9de756e (diff) | |
download | external_webkit-5e2bc6953fe6923165b8a5d7679939693a1d58d6.zip external_webkit-5e2bc6953fe6923165b8a5d7679939693a1d58d6.tar.gz external_webkit-5e2bc6953fe6923165b8a5d7679939693a1d58d6.tar.bz2 |
Merge webkit.org at r54340 : Initial merge by git
Change-Id: Ib489d2ff91186ea3652522e1d586e54416a2cf44
Diffstat (limited to 'WebCore/platform/graphics/skia')
4 files changed, 91 insertions, 29 deletions
diff --git a/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp b/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp index 985442c..bd97ca2 100644 --- a/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp +++ b/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp @@ -31,6 +31,7 @@ #include "config.h" #include "GraphicsContext.h" +#include "AffineTransform.h" #include "Color.h" #include "FloatRect.h" #include "Gradient.h" @@ -439,6 +440,13 @@ void GraphicsContext::clipToImageBuffer(const FloatRect& rect, #endif } +void GraphicsContext::concatCTM(const AffineTransform& affine) +{ + if (paintingDisabled()) + return; + platformContext()->canvas()->concat(affine); +} + void GraphicsContext::concatCTM(const TransformationMatrix& xform) { if (paintingDisabled()) @@ -805,6 +813,17 @@ void GraphicsContext::fillRoundedRect(const IntRect& rect, platformContext()->canvas()->drawPath(path, paint); } +AffineTransform GraphicsContext::getAffineCTM() const +{ + const SkMatrix& m = platformContext()->canvas()->getTotalMatrix(); + return AffineTransform(SkScalarToDouble(m.getScaleX()), // a + SkScalarToDouble(m.getSkewY()), // b + SkScalarToDouble(m.getSkewX()), // c + SkScalarToDouble(m.getScaleY()), // d + SkScalarToDouble(m.getTranslateX()), // e + SkScalarToDouble(m.getTranslateY())); // f +} + TransformationMatrix GraphicsContext::getCTM() const { const SkMatrix& m = platformContext()->canvas()->getTotalMatrix(); @@ -978,9 +997,7 @@ void GraphicsContext::setPlatformFillPattern(Pattern* pattern) if (paintingDisabled()) return; - SkShader* pat = pattern->createPlatformPattern(getCTM()); - platformContext()->setFillShader(pat); - pat->safeUnref(); + platformContext()->setFillShader(pattern->platformPattern(getCTM())); } void GraphicsContext::setPlatformShadow(const IntSize& size, @@ -1065,9 +1082,7 @@ void GraphicsContext::setPlatformStrokePattern(Pattern* pattern) if (paintingDisabled()) return; - SkShader* pat = pattern->createPlatformPattern(getCTM()); - platformContext()->setStrokeShader(pat); - pat->safeUnref(); + platformContext()->setStrokeShader(pattern->platformPattern(getCTM())); } void GraphicsContext::setPlatformTextDrawingMode(int mode) diff --git a/WebCore/platform/graphics/skia/PathSkia.cpp b/WebCore/platform/graphics/skia/PathSkia.cpp index 2cbb759..fe4c3d0 100644 --- a/WebCore/platform/graphics/skia/PathSkia.cpp +++ b/WebCore/platform/graphics/skia/PathSkia.cpp @@ -30,6 +30,7 @@ #include "config.h" #include "Path.h" +#include "AffineTransform.h" #include "FloatRect.h" #include "ImageBuffer.h" #include "StrokeStyleApplier.h" @@ -214,6 +215,11 @@ void Path::apply(void* info, PathApplierFunction function) const } } +void Path::transform(const AffineTransform& xform) +{ + m_path->transform(xform); +} + void Path::transform(const TransformationMatrix& xform) { m_path->transform(xform); diff --git a/WebCore/platform/graphics/skia/PatternSkia.cpp b/WebCore/platform/graphics/skia/PatternSkia.cpp index 11b5cf1..b98825b 100644 --- a/WebCore/platform/graphics/skia/PatternSkia.cpp +++ b/WebCore/platform/graphics/skia/PatternSkia.cpp @@ -40,8 +40,17 @@ namespace WebCore { -PlatformPatternPtr Pattern::createPlatformPattern(const TransformationMatrix& patternTransform) const +void Pattern::platformDestroy() { + m_pattern->safeUnref(); + m_pattern = 0; +} + +PlatformPatternPtr Pattern::platformPattern(const TransformationMatrix& patternTransform) +{ + if (m_pattern) + return m_pattern; + // Note: patternTransform is ignored since it seems to be applied elsewhere // (when the pattern is used?). Applying it to the pattern (i.e. // shader->setLocalMatrix) results in a double transformation. This can be @@ -53,31 +62,42 @@ PlatformPatternPtr Pattern::createPlatformPattern(const TransformationMatrix& pa SkBitmap* bm = m_tileImage->nativeImageForCurrentFrame(); // If we don't have a bitmap, return a transparent shader. if (!bm) - return new SkColorShader(SkColorSetARGB(0, 0, 0, 0)); + m_pattern = new SkColorShader(SkColorSetARGB(0, 0, 0, 0)); - if (m_repeatX && m_repeatY) - return SkShader::CreateBitmapShader(*bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); + else if (m_repeatX && m_repeatY) + m_pattern = SkShader::CreateBitmapShader(*bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); - // Skia does not have a "draw the tile only once" option. Clamp_TileMode - // repeats the last line of the image after drawing one tile. To avoid - // filling the space with arbitrary pixels, this workaround forces the - // image to have a line of transparent pixels on the "repeated" edge(s), - // thus causing extra space to be transparent filled. - SkShader::TileMode tileModeX = m_repeatX ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode; - SkShader::TileMode tileModeY = m_repeatY ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode; - int expandW = m_repeatX ? 0 : 1; - int expandH = m_repeatY ? 0 : 1; + else { - // Create a transparent bitmap 1 pixel wider and/or taller than the - // original, then copy the orignal into it. - // FIXME: Is there a better way to pad (not scale) an image in skia? - SkBitmap bm2; - bm2.setConfig(bm->config(), bm->width() + expandW, bm->height() + expandH); - bm2.allocPixels(); - bm2.eraseARGB(0x00, 0x00, 0x00, 0x00); - SkCanvas canvas(bm2); - canvas.drawBitmap(*bm, 0, 0); - return SkShader::CreateBitmapShader(bm2, tileModeX, tileModeY); + // Skia does not have a "draw the tile only once" option. Clamp_TileMode + // repeats the last line of the image after drawing one tile. To avoid + // filling the space with arbitrary pixels, this workaround forces the + // image to have a line of transparent pixels on the "repeated" edge(s), + // thus causing extra space to be transparent filled. + SkShader::TileMode tileModeX = m_repeatX ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode; + SkShader::TileMode tileModeY = m_repeatY ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode; + int expandW = m_repeatX ? 0 : 1; + int expandH = m_repeatY ? 0 : 1; + + // Create a transparent bitmap 1 pixel wider and/or taller than the + // original, then copy the orignal into it. + // FIXME: Is there a better way to pad (not scale) an image in skia? + SkBitmap bm2; + bm2.setConfig(bm->config(), bm->width() + expandW, bm->height() + expandH); + bm2.allocPixels(); + bm2.eraseARGB(0x00, 0x00, 0x00, 0x00); + SkCanvas canvas(bm2); + canvas.drawBitmap(*bm, 0, 0); + m_pattern = SkShader::CreateBitmapShader(bm2, tileModeX, tileModeY); + } + m_pattern->setLocalMatrix(m_patternSpaceTransformation); + return m_pattern; +} + +void Pattern::setPlatformPatternSpaceTransform() +{ + if (m_pattern) + m_pattern->setLocalMatrix(m_patternSpaceTransformation); } } // namespace WebCore diff --git a/WebCore/platform/graphics/skia/TransformationMatrixSkia.cpp b/WebCore/platform/graphics/skia/TransformationMatrixSkia.cpp index 2d0f9f8..dc610d7 100644 --- a/WebCore/platform/graphics/skia/TransformationMatrixSkia.cpp +++ b/WebCore/platform/graphics/skia/TransformationMatrixSkia.cpp @@ -28,6 +28,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "config.h" +#include "AffineTransform.h" #include "TransformationMatrix.h" #include "SkiaUtils.h" @@ -54,4 +55,24 @@ TransformationMatrix::operator SkMatrix() const return result; } +AffineTransform::operator SkMatrix() const +{ + SkMatrix result; + + result.setScaleX(WebCoreDoubleToSkScalar(a())); + result.setSkewX(WebCoreDoubleToSkScalar(c())); + result.setTranslateX(WebCoreDoubleToSkScalar(e())); + + result.setScaleY(WebCoreDoubleToSkScalar(d())); + result.setSkewY(WebCoreDoubleToSkScalar(b())); + result.setTranslateY(WebCoreDoubleToSkScalar(f())); + + // FIXME: Set perspective properly. + result.setPerspX(0); + result.setPerspY(0); + result.set(SkMatrix::kMPersp2, SK_Scalar1); + + return result; +} + } // namespace WebCore |