diff options
author | Steve Block <steveblock@google.com> | 2011-05-18 13:36:51 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-05-24 15:38:28 +0100 |
commit | 2fc2651226baac27029e38c9d6ef883fa32084db (patch) | |
tree | e396d4bf89dcce6ed02071be66212495b1df1dec /Source/WebCore/platform/graphics/skia | |
parent | b3725cedeb43722b3b175aaeff70552e562d2c94 (diff) | |
download | external_webkit-2fc2651226baac27029e38c9d6ef883fa32084db.zip external_webkit-2fc2651226baac27029e38c9d6ef883fa32084db.tar.gz external_webkit-2fc2651226baac27029e38c9d6ef883fa32084db.tar.bz2 |
Merge WebKit at r78450: Initial merge by git.
Change-Id: I6d3e5f1f868ec266a0aafdef66182ddc3f265dc1
Diffstat (limited to 'Source/WebCore/platform/graphics/skia')
10 files changed, 149 insertions, 137 deletions
diff --git a/Source/WebCore/platform/graphics/skia/FloatRectSkia.cpp b/Source/WebCore/platform/graphics/skia/FloatRectSkia.cpp index a10371f..23045ba 100644 --- a/Source/WebCore/platform/graphics/skia/FloatRectSkia.cpp +++ b/Source/WebCore/platform/graphics/skia/FloatRectSkia.cpp @@ -43,7 +43,7 @@ FloatRect::FloatRect(const SkRect& r) FloatRect::operator SkRect() const { - SkRect rect = { x(), y(), right(), bottom() }; + SkRect rect = { x(), y(), maxX(), maxY() }; return rect; } diff --git a/Source/WebCore/platform/graphics/skia/FontCustomPlatformData.cpp b/Source/WebCore/platform/graphics/skia/FontCustomPlatformData.cpp index 0b31dfa..0e68c21 100644 --- a/Source/WebCore/platform/graphics/skia/FontCustomPlatformData.cpp +++ b/Source/WebCore/platform/graphics/skia/FontCustomPlatformData.cpp @@ -65,7 +65,7 @@ FontCustomPlatformData::~FontCustomPlatformData() #endif } -FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, bool italic, FontOrientation orientation, FontRenderingMode mode) +FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, bool italic, FontOrientation orientation, FontWidthVariant, FontRenderingMode mode) { #if OS(WINDOWS) ASSERT(m_fontReference); @@ -114,13 +114,12 @@ FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, b // not allow access from CSS. static String createUniqueFontName() { - Vector<char> fontUuid(sizeof(GUID)); - CoCreateGuid(reinterpret_cast<GUID*>(fontUuid.data())); + GUID fontUuid; + CoCreateGuid(&fontUuid); - Vector<char> fontNameVector; - base64Encode(fontUuid, fontNameVector); - ASSERT(fontNameVector.size() < LF_FACESIZE); - return String(fontNameVector.data(), fontNameVector.size()); + String fontName = base64Encode(reinterpret_cast<char*>(&fontUuid), sizeof(fontUuid)); + ASSERT(fontName.length() < LF_FACESIZE); + return fontName; } #endif diff --git a/Source/WebCore/platform/graphics/skia/FontCustomPlatformData.h b/Source/WebCore/platform/graphics/skia/FontCustomPlatformData.h index 4228b40..2dee3ab 100644 --- a/Source/WebCore/platform/graphics/skia/FontCustomPlatformData.h +++ b/Source/WebCore/platform/graphics/skia/FontCustomPlatformData.h @@ -34,6 +34,7 @@ #include "FontOrientation.h" #include "FontRenderingMode.h" +#include "FontWidthVariant.h" #include <wtf/Forward.h> #include <wtf/Noncopyable.h> @@ -65,7 +66,7 @@ public: ~FontCustomPlatformData(); - FontPlatformData fontPlatformData(int size, bool bold, bool italic, FontOrientation = Horizontal, + FontPlatformData fontPlatformData(int size, bool bold, bool italic, FontOrientation = Horizontal, FontWidthVariant = RegularWidth, FontRenderingMode = NormalRenderingMode); static bool supportsFormat(const String&); diff --git a/Source/WebCore/platform/graphics/skia/GraphicsContext3DSkia.cpp b/Source/WebCore/platform/graphics/skia/GraphicsContext3DSkia.cpp index c4b753b..5950c35 100644 --- a/Source/WebCore/platform/graphics/skia/GraphicsContext3DSkia.cpp +++ b/Source/WebCore/platform/graphics/skia/GraphicsContext3DSkia.cpp @@ -26,7 +26,7 @@ #include "config.h" -#if ENABLE(3D_CANVAS) +#if ENABLE(WEBGL) #include "GraphicsContext3D.h" @@ -87,4 +87,4 @@ bool GraphicsContext3D::getImageData(Image* image, } // namespace WebCore -#endif // ENABLE(3D_CANVAS) +#endif // ENABLE(WEBGL) diff --git a/Source/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp b/Source/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp index 1a7112b..9f2ed32 100644 --- a/Source/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp +++ b/Source/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp @@ -309,20 +309,6 @@ void GraphicsContext::addInnerRoundedRectClip(const IntRect& rect, int thickness platformContext()->clipPathAntiAliased(path); } -void GraphicsContext::addPath(const Path& path) -{ - if (paintingDisabled()) - return; - platformContext()->addPath(*path.platformPath()); -} - -void GraphicsContext::beginPath() -{ - if (paintingDisabled()) - return; - platformContext()->beginPath(); -} - void GraphicsContext::clearPlatformShadow() { if (paintingDisabled()) @@ -431,11 +417,7 @@ void GraphicsContext::clipPath(const Path& pathToClip, WindRule clipRule) if (platformContext()->useGPU()) platformContext()->gpuCanvas()->clipPath(pathToClip); - // FIXME: Be smarter about this. - beginPath(); - addPath(pathToClip); - - SkPath path = platformContext()->currentPathInLocalCoordinates(); + SkPath path = *pathToClip.platformPath(); if (!isPathSkiaSafe(getCTM(), path)) return; @@ -738,17 +720,13 @@ void GraphicsContext::fillPath(const Path& pathToFill) if (paintingDisabled()) return; - // FIXME: Be smarter about this. - beginPath(); - addPath(pathToFill); - if (platformContext()->useGPU() && platformContext()->canAccelerate()) { platformContext()->prepareForHardwareDraw(); platformContext()->gpuCanvas()->fillPath(pathToFill); return; } - SkPath path = platformContext()->currentPathInLocalCoordinates(); + SkPath path = *pathToFill.platformPath(); if (!isPathSkiaSafe(getCTM(), path)) return; @@ -1204,11 +1182,7 @@ void GraphicsContext::strokePath(const Path& pathToStroke) if (paintingDisabled()) return; - // FIXME: Be smarter about this. - beginPath(); - addPath(pathToStroke); - - SkPath path = platformContext()->currentPathInLocalCoordinates(); + SkPath path = *pathToStroke.platformPath(); if (!isPathSkiaSafe(getCTM(), path)) return; diff --git a/Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp b/Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp index 2c489ef..2721523 100644 --- a/Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp +++ b/Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp @@ -2,11 +2,11 @@ * Copyright (c) 2008, Google Inc. All rights reserved. * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. 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 @@ -16,7 +16,7 @@ * * 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 @@ -162,12 +162,14 @@ void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable) } template <Multiply multiplied> -PassRefPtr<ByteArray> getImageData(const IntRect& rect, const SkBitmap& bitmap, +PassRefPtr<ByteArray> getImageData(const IntRect& rect, SkDevice& srcDevice, const IntSize& size) { RefPtr<ByteArray> result = ByteArray::create(rect.width() * rect.height() * 4); - if (bitmap.config() == SkBitmap::kNo_Config) { + SkBitmap::Config srcConfig = srcDevice.accessBitmap(false).config(); + + if (srcConfig == SkBitmap::kNo_Config) { // This is an empty SkBitmap that could not be configured. ASSERT(!size.width() || !size.height()); return result.release(); @@ -177,8 +179,8 @@ PassRefPtr<ByteArray> getImageData(const IntRect& rect, const SkBitmap& bitmap, if (rect.x() < 0 || rect.y() < 0 - || rect.right() > size.width() - || rect.bottom() > size.height()) + || rect.maxX() > size.width() + || rect.maxY() > size.height()) memset(data, 0, result->length()); int originX = rect.x(); @@ -187,12 +189,12 @@ PassRefPtr<ByteArray> getImageData(const IntRect& rect, const SkBitmap& bitmap, destX = -originX; originX = 0; } - int endX = rect.right(); + int endX = rect.maxX(); if (endX > size.width()) endX = size.width(); int numColumns = endX - originX; - if (numColumns <= 0) + if (numColumns <= 0) return result.release(); int originY = rect.y(); @@ -201,38 +203,42 @@ PassRefPtr<ByteArray> getImageData(const IntRect& rect, const SkBitmap& bitmap, destY = -originY; originY = 0; } - int endY = rect.bottom(); + int endY = rect.maxY(); if (endY > size.height()) endY = size.height(); int numRows = endY - originY; - if (numRows <= 0) + if (numRows <= 0) return result.release(); - ASSERT(bitmap.config() == SkBitmap::kARGB_8888_Config); - SkAutoLockPixels bitmapLock(bitmap); + ASSERT(srcConfig == SkBitmap::kARGB_8888_Config); unsigned destBytesPerRow = 4 * rect.width(); + + SkBitmap srcBitmap; + srcDevice.readPixels(SkIRect::MakeXYWH(originX, originY, numColumns, numRows), &srcBitmap); + unsigned char* destRow = data + destY * destBytesPerRow + destX * 4; + // Do conversion of byte order and alpha divide (if necessary) for (int y = 0; y < numRows; ++y) { - uint32_t* srcRow = bitmap.getAddr32(originX, originY + y); + SkPMColor* srcBitmapRow = srcBitmap.getAddr32(0, y); for (int x = 0; x < numColumns; ++x) { + SkPMColor srcPMColor = srcBitmapRow[x]; unsigned char* destPixel = &destRow[x * 4]; if (multiplied == Unmultiplied) { - SkColor color = srcRow[x]; - unsigned a = SkColorGetA(color); - destPixel[0] = a ? SkColorGetR(color) * 255 / a : 0; - destPixel[1] = a ? SkColorGetG(color) * 255 / a : 0; - destPixel[2] = a ? SkColorGetB(color) * 255 / a : 0; + unsigned char a = SkGetPackedA32(srcPMColor); + destPixel[0] = a ? SkGetPackedR32(srcPMColor) * 255 / a : 0; + destPixel[1] = a ? SkGetPackedG32(srcPMColor) * 255 / a : 0; + destPixel[2] = a ? SkGetPackedB32(srcPMColor) * 255 / a : 0; destPixel[3] = a; } else { // Input and output are both pre-multiplied, we just need to re-arrange the // bytes from the bitmap format to RGBA. - destPixel[0] = SkGetPackedR32(srcRow[x]); - destPixel[1] = SkGetPackedG32(srcRow[x]); - destPixel[2] = SkGetPackedB32(srcRow[x]); - destPixel[3] = SkGetPackedA32(srcRow[x]); + destPixel[0] = SkGetPackedR32(srcPMColor); + destPixel[1] = SkGetPackedG32(srcPMColor); + destPixel[2] = SkGetPackedB32(srcPMColor); + destPixel[3] = SkGetPackedA32(srcPMColor); } } destRow += destBytesPerRow; @@ -244,18 +250,18 @@ PassRefPtr<ByteArray> getImageData(const IntRect& rect, const SkBitmap& bitmap, PassRefPtr<ByteArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect) const { context()->platformContext()->syncSoftwareCanvas(); - return getImageData<Unmultiplied>(rect, *context()->platformContext()->bitmap(), m_size); + return getImageData<Unmultiplied>(rect, *context()->platformContext()->canvas()->getDevice(), m_size); } PassRefPtr<ByteArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect) const { context()->platformContext()->syncSoftwareCanvas(); - return getImageData<Premultiplied>(rect, *context()->platformContext()->bitmap(), m_size); + return getImageData<Premultiplied>(rect, *context()->platformContext()->canvas()->getDevice(), m_size); } template <Multiply multiplied> -void putImageData(ByteArray*& source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, - const SkBitmap& bitmap, const IntSize& size) +void putImageData(ByteArray*& source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, + SkDevice* dstDevice, const IntSize& size) { ASSERT(sourceRect.width() > 0); ASSERT(sourceRect.height() > 0); @@ -265,9 +271,9 @@ void putImageData(ByteArray*& source, const IntSize& sourceSize, const IntRect& ASSERT(destX >= 0); ASSERT(destX < size.width()); ASSERT(originX >= 0); - ASSERT(originX < sourceRect.right()); + ASSERT(originX < sourceRect.maxX()); - int endX = destPoint.x() + sourceRect.right(); + int endX = destPoint.x() + sourceRect.maxX(); ASSERT(endX <= size.width()); int numColumns = endX - destX; @@ -277,21 +283,33 @@ void putImageData(ByteArray*& source, const IntSize& sourceSize, const IntRect& ASSERT(destY >= 0); ASSERT(destY < size.height()); ASSERT(originY >= 0); - ASSERT(originY < sourceRect.bottom()); + ASSERT(originY < sourceRect.maxY()); - int endY = destPoint.y() + sourceRect.bottom(); + int endY = destPoint.y() + sourceRect.maxY(); ASSERT(endY <= size.height()); int numRows = endY - destY; - ASSERT(bitmap.config() == SkBitmap::kARGB_8888_Config); - SkAutoLockPixels bitmapLock(bitmap); - unsigned srcBytesPerRow = 4 * sourceSize.width(); - const unsigned char* srcRow = source->data() + originY * srcBytesPerRow + originX * 4; + SkBitmap deviceBitmap = dstDevice->accessBitmap(true); + SkAutoLockPixels deviceAutoLock(deviceBitmap); + // If the device's bitmap doesn't have pixels we will make a temp and call writePixels on the device. + bool temporaryBitmap = !deviceBitmap.getPixels(); + SkBitmap destBitmap; + + if (temporaryBitmap) { + destBitmap.setConfig(SkBitmap::kARGB_8888_Config, numColumns, numRows, srcBytesPerRow); + if (!destBitmap.allocPixels()) + CRASH(); + } else + deviceBitmap.extractSubset(&destBitmap, SkIRect::MakeXYWH(destX, destY, numColumns, numRows)); + + // Whether we made a temporary or not destBitmap is always configured to be written at 0,0 + SkAutoLockPixels destAutoLock(destBitmap); + const unsigned char* srcRow = source->data() + originY * srcBytesPerRow + originX * 4; for (int y = 0; y < numRows; ++y) { - uint32_t* destRow = bitmap.getAddr32(destX, destY + y); + SkPMColor* destRow = destBitmap.getAddr32(0, y); for (int x = 0; x < numColumns; ++x) { const unsigned char* srcPixel = &srcRow[x * 4]; if (multiplied == Unmultiplied) { @@ -301,22 +319,26 @@ void putImageData(ByteArray*& source, const IntSize& sourceSize, const IntRect& unsigned char b = SkMulDiv255Ceiling(srcPixel[2], alpha); destRow[x] = SkPackARGB32(alpha, r, g, b); } else - destRow[x] = SkPackARGB32(srcPixel[3], srcPixel[0], - srcPixel[1], srcPixel[2]); + destRow[x] = SkPackARGB32(srcPixel[3], srcPixel[0], srcPixel[1], srcPixel[2]); } srcRow += srcBytesPerRow; } + + // If we used a temporary then write it to the device + if (temporaryBitmap) + dstDevice->writePixels(destBitmap, destX, destY); } void ImageBuffer::putUnmultipliedImageData(ByteArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint) { - context()->platformContext()->prepareForSoftwareDraw(); - putImageData<Unmultiplied>(source, sourceSize, sourceRect, destPoint, *context()->platformContext()->bitmap(), m_size); + context()->platformContext()->syncSoftwareCanvas(); + putImageData<Unmultiplied>(source, sourceSize, sourceRect, destPoint, context()->platformContext()->canvas()->getDevice(), m_size); } void ImageBuffer::putPremultipliedImageData(ByteArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint) { - putImageData<Premultiplied>(source, sourceSize, sourceRect, destPoint, *context()->platformContext()->bitmap(), m_size); + context()->platformContext()->syncSoftwareCanvas(); + putImageData<Premultiplied>(source, sourceSize, sourceRect, destPoint, context()->platformContext()->canvas()->getDevice(), m_size); } String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const @@ -324,14 +346,27 @@ String ImageBuffer::toDataURL(const String& mimeType, const double* quality) con ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); Vector<unsigned char> encodedImage; + SkDevice* device = context()->platformContext()->canvas()->getDevice(); + SkBitmap bitmap = device->accessBitmap(false); + + // if we can't see the pixels directly, call readPixels() to get a copy. + // this could happen if the device is backed by a GPU. + bitmap.lockPixels(); // balanced by our destructor, or explicitly if getPixels() fails + if (!bitmap.getPixels()) { + bitmap.unlockPixels(); + SkIRect bounds = SkIRect::MakeWH(device->width(), device->height()); + if (!device->readPixels(bounds, &bitmap)) + return "data:,"; + } + if (mimeType == "image/jpeg") { int compressionQuality = JPEGImageEncoder::DefaultCompressionQuality; if (quality && *quality >= 0.0 && *quality <= 1.0) compressionQuality = static_cast<int>(*quality * 100 + 0.5); - if (!JPEGImageEncoder::encode(*context()->platformContext()->bitmap(), compressionQuality, &encodedImage)) + if (!JPEGImageEncoder::encode(bitmap, compressionQuality, &encodedImage)) return "data:,"; } else { - if (!PNGImageEncoder::encode(*context()->platformContext()->bitmap(), &encodedImage)) + if (!PNGImageEncoder::encode(bitmap, &encodedImage)) return "data:,"; ASSERT(mimeType == "image/png"); } diff --git a/Source/WebCore/platform/graphics/skia/IntRectSkia.cpp b/Source/WebCore/platform/graphics/skia/IntRectSkia.cpp index ea138ee..0024086 100644 --- a/Source/WebCore/platform/graphics/skia/IntRectSkia.cpp +++ b/Source/WebCore/platform/graphics/skia/IntRectSkia.cpp @@ -37,14 +37,14 @@ namespace WebCore { IntRect::operator SkIRect() const { - SkIRect rect = { x(), y(), right(), bottom() }; + SkIRect rect = { x(), y(), maxX(), maxY() }; return rect; } IntRect::operator SkRect() const { SkRect rect; - rect.set(SkIntToScalar(x()), SkIntToScalar(y()), SkIntToScalar(right()), SkIntToScalar(bottom())); + rect.set(SkIntToScalar(x()), SkIntToScalar(y()), SkIntToScalar(maxX()), SkIntToScalar(maxY())); return rect; } diff --git a/Source/WebCore/platform/graphics/skia/PathSkia.cpp b/Source/WebCore/platform/graphics/skia/PathSkia.cpp index 89323c4..6318c21 100644 --- a/Source/WebCore/platform/graphics/skia/PathSkia.cpp +++ b/Source/WebCore/platform/graphics/skia/PathSkia.cpp @@ -227,28 +227,20 @@ void Path::transform(const AffineTransform& xform) m_path->transform(xform); } -// Computes the bounding box for the stroke and style currently selected into -// the given bounding box. This also takes into account the stroke width. -static FloatRect boundingBoxForCurrentStroke(const GraphicsContext* context) -{ - SkPaint paint; - context->platformContext()->setupPaintForStroking(&paint, 0, 0); - SkPath boundingPath; - paint.getFillPath(context->platformContext()->currentPathInLocalCoordinates(), &boundingPath); - return boundingPath.getBounds(); -} - FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) { GraphicsContext* scratch = scratchContext(); scratch->save(); - scratch->beginPath(); - scratch->addPath(*this); if (applier) applier->strokeStyle(scratch); - FloatRect r = boundingBoxForCurrentStroke(scratch); + SkPaint paint; + scratch->platformContext()->setupPaintForStroking(&paint, 0, 0); + SkPath boundingPath; + paint.getFillPath(*platformPath(), &boundingPath); + + FloatRect r = boundingPath.getBounds(); scratch->restore(); return r; } diff --git a/Source/WebCore/platform/graphics/skia/PlatformContextSkia.cpp b/Source/WebCore/platform/graphics/skia/PlatformContextSkia.cpp index d852e9b..5e08b3c 100644 --- a/Source/WebCore/platform/graphics/skia/PlatformContextSkia.cpp +++ b/Source/WebCore/platform/graphics/skia/PlatformContextSkia.cpp @@ -51,6 +51,12 @@ #include "SkDashPathEffect.h" #include "SkShader.h" +#if ENABLE(SKIA_GPU) +#include "GrContext.h" +#include "SkGpuDevice.h" +#include "SkGpuDeviceFactory.h" +#endif + #include <wtf/MathExtras.h> #include <wtf/OwnArrayPtr.h> #include <wtf/Vector.h> @@ -62,6 +68,18 @@ namespace WebCore { +#if ENABLE(SKIA_GPU) +GrContext* GetGlobalGrContext() +{ + static GrContext* gGR; + if (!gGR) { + gGR = GrContext::CreateGLShaderContext(); + gGR->setTextureCacheLimits(512, 50 * 1024 * 1024); + } + return gGR; +} +#endif + extern bool isPathSkiaSafe(const SkMatrix& transform, const SkPath& path); // State ----------------------------------------------------------------------- @@ -266,7 +284,7 @@ void PlatformContextSkia::beginLayerClippedToImage(const FloatRect& rect, // create the resulting image. m_state->m_clip = rect; SkRect bounds = { SkFloatToScalar(rect.x()), SkFloatToScalar(rect.y()), - SkFloatToScalar(rect.right()), SkFloatToScalar(rect.bottom()) }; + SkFloatToScalar(rect.maxX()), SkFloatToScalar(rect.maxY()) }; canvas()->clipRect(bounds); canvas()->saveLayerAlpha(&bounds, 255, @@ -550,38 +568,12 @@ SkColor PlatformContextSkia::effectiveStrokeColor() const return m_state->applyAlpha(m_state->m_strokeColor); } -void PlatformContextSkia::beginPath() -{ - m_path.reset(); -} - -void PlatformContextSkia::addPath(const SkPath& path) -{ - m_path.addPath(path, m_canvas->getTotalMatrix()); -} - -SkPath PlatformContextSkia::currentPathInLocalCoordinates() const -{ - SkPath localPath = m_path; - const SkMatrix& matrix = m_canvas->getTotalMatrix(); - SkMatrix inverseMatrix; - if (!matrix.invert(&inverseMatrix)) - return SkPath(); - localPath.transform(inverseMatrix); - return localPath; -} - void PlatformContextSkia::canvasClipPath(const SkPath& path) { m_state->m_canvasClipApplied = true; m_canvas->clipPath(path); } -void PlatformContextSkia::setFillRule(SkPath::FillType fr) -{ - m_path.setFillType(fr); -} - void PlatformContextSkia::setFillShader(SkShader* fillShader) { if (fillShader) @@ -625,7 +617,11 @@ const SkBitmap* PlatformContextSkia::bitmap() const bool PlatformContextSkia::isPrinting() { +#if ENABLE(SKIA_GPU) + return true; +#else return m_canvas->getTopPlatformDevice().IsVectorial(); +#endif } void PlatformContextSkia::getImageResamplingHint(IntSize* srcSize, FloatSize* dstSize) const @@ -739,6 +735,19 @@ void PlatformContextSkia::setSharedGraphicsContext3D(SharedGraphicsContext3D* co m_gpuCanvas = new GLES2Canvas(context, drawingBuffer, size); m_uploadTexture.clear(); drawingBuffer->setWillPublishCallback(WillPublishCallbackImpl::create(this)); + +#if ENABLE(SKIA_GPU) + m_useGPU = false; + context->makeContextCurrent(); + m_gpuCanvas->bindFramebuffer(); + + GrContext* gr = GetGlobalGrContext(); + gr->resetContext(); + SkDeviceFactory* factory = new SkGpuDeviceFactory(gr, SkGpuDevice::Current3DApiRenderTarget()); + SkDevice* device = factory->newDevice(m_canvas, SkBitmap::kARGB_8888_Config, drawingBuffer->size().width(), drawingBuffer->size().height(), false, false); + m_canvas->setDevice(device)->unref(); + m_canvas->setDeviceFactory(factory); +#endif } else { syncSoftwareCanvas(); m_uploadTexture.clear(); @@ -750,8 +759,13 @@ void PlatformContextSkia::setSharedGraphicsContext3D(SharedGraphicsContext3D* co void PlatformContextSkia::prepareForSoftwareDraw() const { - if (!m_useGPU) + if (!m_useGPU) { +#if ENABLE(SKIA_GPU) + if (m_gpuCanvas) + m_gpuCanvas->context()->makeContextCurrent(); +#endif return; + } if (m_backingStoreState == Hardware) { // Depending on the blend mode we need to do one of a few things: @@ -804,8 +818,13 @@ void PlatformContextSkia::prepareForHardwareDraw() const void PlatformContextSkia::syncSoftwareCanvas() const { - if (!m_useGPU) + if (!m_useGPU) { +#if ENABLE(SKIA_GPU) + if (m_gpuCanvas) + m_gpuCanvas->bindFramebuffer(); +#endif return; + } if (m_backingStoreState == Hardware) readbackHardwareToSoftware(); @@ -865,7 +884,7 @@ void PlatformContextSkia::readbackHardwareToSoftware() const const SkBitmap& bitmap = m_canvas->getDevice()->accessBitmap(true); SkAutoLockPixels lock(bitmap); int width = bitmap.width(), height = bitmap.height(); - OwnArrayPtr<uint32_t> buf(new uint32_t[width]); + OwnArrayPtr<uint32_t> buf = adoptArrayPtr(new uint32_t[width]); SharedGraphicsContext3D* context = m_gpuCanvas->context(); m_gpuCanvas->bindFramebuffer(); // Flips the image vertically. diff --git a/Source/WebCore/platform/graphics/skia/PlatformContextSkia.h b/Source/WebCore/platform/graphics/skia/PlatformContextSkia.h index 0304486..d7dd6a9 100644 --- a/Source/WebCore/platform/graphics/skia/PlatformContextSkia.h +++ b/Source/WebCore/platform/graphics/skia/PlatformContextSkia.h @@ -118,7 +118,6 @@ public: void setAlpha(float); void setLineCap(SkPaint::Cap); void setLineJoin(SkPaint::Join); - void setFillRule(SkPath::FillType); void setXfermodeMode(SkXfermode::Mode); void setFillColor(SkColor); void setFillShader(SkShader*); @@ -137,10 +136,6 @@ public: float getAlpha() const; int getNormalizedAlpha() const; - void beginPath(); - void addPath(const SkPath&); - SkPath currentPathInLocalCoordinates() const; - void canvasClipPath(const SkPath&); // Returns the fill color. The returned color has it's alpha adjusted @@ -220,9 +215,6 @@ private: // mStateStack.back(). State* m_state; - // Current path in global coordinates. - SkPath m_path; - // Stores image sizes for a hint to compute image resampling modes. // Values are used in ImageSkia.cpp IntSize m_imageResamplingHintSrcSize; |