diff options
author | Steve Block <steveblock@google.com> | 2010-08-27 11:02:25 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-09-02 17:17:20 +0100 |
commit | e8b154fd68f9b33be40a3590e58347f353835f5c (patch) | |
tree | 0733ce26384183245aaa5656af26c653636fe6c1 /WebCore/platform/graphics/skia | |
parent | da56157816334089526a7a115a85fd85a6e9a1dc (diff) | |
download | external_webkit-e8b154fd68f9b33be40a3590e58347f353835f5c.zip external_webkit-e8b154fd68f9b33be40a3590e58347f353835f5c.tar.gz external_webkit-e8b154fd68f9b33be40a3590e58347f353835f5c.tar.bz2 |
Merge WebKit at r66079 : Initial merge by git
Change-Id: Ie2e1440fb9d487d24e52c247342c076fecaecac7
Diffstat (limited to 'WebCore/platform/graphics/skia')
8 files changed, 62 insertions, 40 deletions
diff --git a/WebCore/platform/graphics/skia/BitmapImageSingleFrameSkia.h b/WebCore/platform/graphics/skia/BitmapImageSingleFrameSkia.h index 9fb6a8b..553f203 100644 --- a/WebCore/platform/graphics/skia/BitmapImageSingleFrameSkia.h +++ b/WebCore/platform/graphics/skia/BitmapImageSingleFrameSkia.h @@ -46,9 +46,10 @@ namespace WebCore { // is that NativeImagePtr = NativeImageSkia, yet callers have SkBitmap. class BitmapImageSingleFrameSkia : public Image { public: - // Creates a new Image, by copying the pixel values out of |bitmap|. - // If creation failed, returns null. - static PassRefPtr<BitmapImageSingleFrameSkia> create(const SkBitmap&); + // Creates a new Image from the given SkBitmap. If "copyPixels" is true, a + // deep copy is done. Otherwise, a shallow copy is done (pixel data is + // ref'ed). + static PassRefPtr<BitmapImageSingleFrameSkia> create(const SkBitmap&, bool copyPixels); virtual bool isBitmapImage() const { return true; } @@ -77,8 +78,8 @@ protected: private: NativeImageSkia m_nativeImage; - // Use create(). - BitmapImageSingleFrameSkia() { } + // Creates a new Image from the given SkBitmap, using a shallow copy. + explicit BitmapImageSingleFrameSkia(const SkBitmap&); }; } // namespace WebCore diff --git a/WebCore/platform/graphics/skia/GraphicsContext3DSkia.cpp b/WebCore/platform/graphics/skia/GraphicsContext3DSkia.cpp index ee0a874..61039f2 100644 --- a/WebCore/platform/graphics/skia/GraphicsContext3DSkia.cpp +++ b/WebCore/platform/graphics/skia/GraphicsContext3DSkia.cpp @@ -31,6 +31,7 @@ #include "GraphicsContext3D.h" #include "Image.h" +#include "ImageSource.h" #include "NativeImageSkia.h" #include <algorithm> @@ -43,27 +44,28 @@ bool GraphicsContext3D::getImageData(Image* image, bool premultiplyAlpha, Vector<uint8_t>& outputVector) { - if (!image) + if (!image || !image->data()) return false; - NativeImageSkia* skiaImage = image->nativeImageForCurrentFrame(); - if (!skiaImage) + ImageSource decoder(false); + decoder.setData(image->data(), true); + if (!decoder.frameCount() || !decoder.frameIsCompleteAtIndex(0)) return false; - SkBitmap::Config skiaConfig = skiaImage->config(); - // FIXME: must support more image configurations. + bool hasAlpha = decoder.frameHasAlphaAtIndex(0); + OwnPtr<NativeImageSkia> pixels(decoder.createFrameAtIndex(0)); + if (!pixels.get() || !pixels->isDataComplete() || !pixels->width() || !pixels->height()) + return false; + SkBitmap::Config skiaConfig = pixels->config(); if (skiaConfig != SkBitmap::kARGB_8888_Config) return false; - SkBitmap& skiaImageRef = *skiaImage; + SkBitmap& skiaImageRef = *pixels; SkAutoLockPixels lock(skiaImageRef); - int height = skiaImage->height(); - int rowBytes = skiaImage->rowBytes(); - ASSERT(rowBytes == skiaImage->width() * 4); - uint8_t* pixels = reinterpret_cast<uint8_t*>(skiaImage->getPixels()); - outputVector.resize(rowBytes * height); + ASSERT(pixels->rowBytes() == pixels->width() * 4); + outputVector.resize(pixels->rowBytes() * pixels->height()); AlphaOp neededAlphaOp = kAlphaDoNothing; - if (!premultiplyAlpha) - // FIXME: must fetch the image data before the premultiplication step - neededAlphaOp = kAlphaDoUnmultiply; - return packPixels(pixels, kSourceFormatBGRA8, skiaImage->width(), height, 0, + if (hasAlpha && premultiplyAlpha) + neededAlphaOp = kAlphaDoPremultiply; + return packPixels(reinterpret_cast<const uint8_t*>(pixels->getPixels()), + kSourceFormatBGRA8, pixels->width(), pixels->height(), 0, format, type, neededAlphaOp, outputVector.data()); } diff --git a/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp b/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp index fe7f6ce..1b20e26 100644 --- a/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp +++ b/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp @@ -323,7 +323,6 @@ void GraphicsContext::addPath(const Path& path) { if (paintingDisabled()) return; - platformContext()->prepareForSoftwareDraw(); platformContext()->addPath(*path.platformPath()); } @@ -331,7 +330,6 @@ void GraphicsContext::beginPath() { if (paintingDisabled()) return; - platformContext()->prepareForSoftwareDraw(); platformContext()->beginPath(); } @@ -783,7 +781,7 @@ void GraphicsContext::fillRect(const FloatRect& rect) } #if USE(GLES2_RENDERING) - if (platformContext()->useGPU() && !m_common->state.fillPattern && !m_common->state.fillGradient) { + if (platformContext()->useGPU() && !m_common->state.fillPattern && !m_common->state.fillGradient && !platformContext()->getDrawLooper()) { platformContext()->prepareForHardwareDraw(); platformContext()->gpuCanvas()->fillRect(rect); return; diff --git a/WebCore/platform/graphics/skia/ImageBufferSkia.cpp b/WebCore/platform/graphics/skia/ImageBufferSkia.cpp index a63eec5..9403406 100644 --- a/WebCore/platform/graphics/skia/ImageBufferSkia.cpp +++ b/WebCore/platform/graphics/skia/ImageBufferSkia.cpp @@ -89,12 +89,13 @@ GraphicsContext* ImageBuffer::context() const bool ImageBuffer::drawsUsingCopy() const { - return true; + return false; } PassRefPtr<Image> ImageBuffer::copyImage() const { - return BitmapImageSingleFrameSkia::create(*m_data.m_platformContext.bitmap()); + m_context->platformContext()->syncSoftwareCanvas(); + return BitmapImageSingleFrameSkia::create(*m_data.m_platformContext.bitmap(), true); } void ImageBuffer::clip(GraphicsContext* context, const FloatRect& rect) const @@ -107,15 +108,15 @@ void ImageBuffer::clip(GraphicsContext* context, const FloatRect& rect) const void ImageBuffer::draw(GraphicsContext* context, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, bool useLowQualityScale) { - RefPtr<Image> imageCopy = copyImage(); - context->drawImage(imageCopy.get(), styleColorSpace, destRect, srcRect, op, useLowQualityScale); + RefPtr<Image> image = BitmapImageSingleFrameSkia::create(*m_data.m_platformContext.bitmap(), context == m_context); + context->drawImage(image.get(), styleColorSpace, destRect, srcRect, op, useLowQualityScale); } void ImageBuffer::drawPattern(GraphicsContext* context, const FloatRect& srcRect, const AffineTransform& patternTransform, const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect) { - RefPtr<Image> imageCopy = copyImage(); - imageCopy->drawPattern(context, srcRect, patternTransform, phase, styleColorSpace, op, destRect); + RefPtr<Image> image = BitmapImageSingleFrameSkia::create(*m_data.m_platformContext.bitmap(), context == m_context); + image->drawPattern(context, srcRect, patternTransform, phase, styleColorSpace, op, destRect); } void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable) diff --git a/WebCore/platform/graphics/skia/ImageSkia.cpp b/WebCore/platform/graphics/skia/ImageSkia.cpp index b514b1a..1ff87cc 100644 --- a/WebCore/platform/graphics/skia/ImageSkia.cpp +++ b/WebCore/platform/graphics/skia/ImageSkia.cpp @@ -419,8 +419,9 @@ static void drawBitmapGLES2(GraphicsContext* ctxt, NativeImageSkia* bitmap, cons ASSERT(bitmap->config() == SkBitmap::kARGB_8888_Config); ASSERT(bitmap->rowBytes() == bitmap->width() * 4); texture = gpuCanvas->createTexture(bitmap, GLES2Texture::BGRA8, bitmap->width(), bitmap->height()); - ASSERT(bitmap->pixelRef()); - texture->load(bitmap->pixelRef()->pixels()); + SkAutoLockPixels lock(*bitmap); + ASSERT(bitmap->getPixels()); + texture->load(bitmap->getPixels()); } gpuCanvas->drawTexturedRect(texture, srcRect, dstRect, styleColorSpace, compositeOp); } @@ -516,11 +517,19 @@ void BitmapImageSingleFrameSkia::draw(GraphicsContext* ctxt, WebCoreCompositeToSkiaComposite(compositeOp)); } -PassRefPtr<BitmapImageSingleFrameSkia> BitmapImageSingleFrameSkia::create(const SkBitmap& bitmap) +BitmapImageSingleFrameSkia::BitmapImageSingleFrameSkia(const SkBitmap& bitmap) + : m_nativeImage(bitmap) { - RefPtr<BitmapImageSingleFrameSkia> image(adoptRef(new BitmapImageSingleFrameSkia())); - bitmap.copyTo(&image->m_nativeImage, bitmap.config()); - return image.release(); +} + +PassRefPtr<BitmapImageSingleFrameSkia> BitmapImageSingleFrameSkia::create(const SkBitmap& bitmap, bool copyPixels) +{ + if (copyPixels) { + SkBitmap temp; + bitmap.copyTo(&temp, bitmap.config()); + return adoptRef(new BitmapImageSingleFrameSkia(temp)); + } + return adoptRef(new BitmapImageSingleFrameSkia(bitmap)); } } // namespace WebCore diff --git a/WebCore/platform/graphics/skia/NativeImageSkia.cpp b/WebCore/platform/graphics/skia/NativeImageSkia.cpp index 007a32c..28e0758 100644 --- a/WebCore/platform/graphics/skia/NativeImageSkia.cpp +++ b/WebCore/platform/graphics/skia/NativeImageSkia.cpp @@ -46,6 +46,14 @@ NativeImageSkia::NativeImageSkia() { } +NativeImageSkia::NativeImageSkia(const SkBitmap& other) + : SkBitmap(other), + m_isDataComplete(false), + m_lastRequestSize(0, 0), + m_resizeRequests(0) +{ +} + int NativeImageSkia::decodedSize() const { return getSize() + m_resizedImage.getSize(); diff --git a/WebCore/platform/graphics/skia/NativeImageSkia.h b/WebCore/platform/graphics/skia/NativeImageSkia.h index 0718836..e26a5ea 100644 --- a/WebCore/platform/graphics/skia/NativeImageSkia.h +++ b/WebCore/platform/graphics/skia/NativeImageSkia.h @@ -43,6 +43,11 @@ class NativeImageSkia : public SkBitmap { public: NativeImageSkia(); + // This constructor does a shallow copy of the passed-in SkBitmap (ie., it + // references the same pixel data and bumps the refcount). Use only when + // you want sharing semantics. + explicit NativeImageSkia(const SkBitmap&); + // Returns the number of bytes of image data. This includes the cached // resized version if there is one. int decodedSize() const; diff --git a/WebCore/platform/graphics/skia/PlatformContextSkia.cpp b/WebCore/platform/graphics/skia/PlatformContextSkia.cpp index 1161224..b9de0a2 100644 --- a/WebCore/platform/graphics/skia/PlatformContextSkia.cpp +++ b/WebCore/platform/graphics/skia/PlatformContextSkia.cpp @@ -733,11 +733,7 @@ void PlatformContextSkia::prepareForSoftwareDraw() const if (m_state->m_xferMode == SkXfermode::kSrcOver_Mode) { // Last drawn on hardware; clear out the canvas. - m_canvas->save(); - SkRect bounds = {0, 0, m_canvas->getDevice()->width(), m_canvas->getDevice()->height()}; - m_canvas->clipRect(bounds, SkRegion::kReplace_Op); - m_canvas->drawARGB(0, 0, 0, 0, SkXfermode::kClear_Mode); - m_canvas->restore(); + m_canvas->getDevice()->eraseColor(0); // Start compositing into the empty canvas. m_backingStoreState = Mixed; } else { @@ -753,6 +749,8 @@ void PlatformContextSkia::prepareForSoftwareDraw() const readbackHardwareToSoftware(); m_backingStoreState = Software; } + } else if (m_backingStoreState == None) { + m_backingStoreState = Software; } } |