Chromium Code Reviews| Index: Source/core/platform/graphics/skia/ImageBufferSkia.cpp |
| diff --git a/Source/core/platform/graphics/skia/ImageBufferSkia.cpp b/Source/core/platform/graphics/skia/ImageBufferSkia.cpp |
| index 69464c730bc365519ba91d864583d131be64a74c..593498905f3a199d103c3288145aea0eb981b5b7 100644 |
| --- a/Source/core/platform/graphics/skia/ImageBufferSkia.cpp |
| +++ b/Source/core/platform/graphics/skia/ImageBufferSkia.cpp |
| @@ -193,6 +193,13 @@ GraphicsContext* ImageBuffer::context() const |
| return m_context.get(); |
| } |
| +static bool contextIsValid(const ImageBufferData* data) |
|
Stephen White
2013/05/24 17:51:01
I think this should be ImageBuffer::isValid(), and
|
| +{ |
| + if (data->m_layerBridge) |
| + return const_cast<Canvas2DLayerBridge*>(data->m_layerBridge.get())->contextIsValid(); |
| + return true; |
| +} |
| + |
| static SkBitmap deepSkBitmapCopy(const SkBitmap& bitmap) |
| { |
| SkBitmap tmp; |
| @@ -204,9 +211,12 @@ static SkBitmap deepSkBitmapCopy(const SkBitmap& bitmap) |
| PassRefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyBehavior, ScaleBehavior) const |
| { |
| - const SkBitmap& bitmap = *context()->bitmap(); |
| - // FIXME: Start honoring ScaleBehavior to scale 2x buffers down to 1x. |
| - return BitmapImage::create(NativeImageSkia::create(copyBehavior == CopyBackingStore ? deepSkBitmapCopy(bitmap) : bitmap, m_resolutionScale)); |
| + if (contextIsValid(&m_data)) { |
|
Stephen White
2013/05/24 17:51:01
Since this is the exceptional state, this should b
|
| + const SkBitmap& bitmap = *context()->bitmap(); |
| + // FIXME: Start honoring ScaleBehavior to scale 2x buffers down to 1x. |
| + return BitmapImage::create(NativeImageSkia::create(copyBehavior == CopyBackingStore ? deepSkBitmapCopy(bitmap) : bitmap, m_resolutionScale)); |
| + } |
| + return BitmapImage::create(NativeImageSkia::create()); |
| } |
| BackingStoreCopy ImageBuffer::fastCopyImageMode() |
| @@ -221,7 +231,7 @@ PlatformLayer* ImageBuffer::platformLayer() const |
| bool ImageBuffer::copyToPlatformTexture(GraphicsContext3D& context, Platform3DObject texture, GC3Denum internalFormat, GC3Denum destType, GC3Dint level, bool premultiplyAlpha, bool flipY) |
| { |
| - if (!m_data.m_layerBridge || !platformLayer()) |
| + if (!m_data.m_layerBridge || !platformLayer() || !contextIsValid(&m_data)) |
| return false; |
| Platform3DObject sourceTexture = m_data.m_layerBridge->backBufferTexture(); |
| @@ -261,23 +271,27 @@ static bool drawNeedsCopy(GraphicsContext* src, GraphicsContext* dst) |
| void ImageBuffer::draw(GraphicsContext* context, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect, |
| CompositeOperator op, BlendMode blendMode, bool useLowQualityScale) |
| { |
| - const SkBitmap& bitmap = *m_context->bitmap(); |
| - RefPtr<Image> image = BitmapImage::create(NativeImageSkia::create(drawNeedsCopy(m_context.get(), context) ? deepSkBitmapCopy(bitmap) : bitmap)); |
| - context->drawImage(image.get(), styleColorSpace, destRect, srcRect, op, blendMode, DoNotRespectImageOrientation, useLowQualityScale); |
| + if (contextIsValid(&m_data)) { |
|
Stephen White
2013/05/24 17:51:01
Same here:
if (!isValid())
return;
|
| + const SkBitmap& bitmap = *m_context->bitmap(); |
| + RefPtr<Image> image = BitmapImage::create(NativeImageSkia::create(drawNeedsCopy(m_context.get(), context) ? deepSkBitmapCopy(bitmap) : bitmap)); |
| + context->drawImage(image.get(), styleColorSpace, destRect, srcRect, op, blendMode, DoNotRespectImageOrientation, useLowQualityScale); |
| + } |
| } |
| void ImageBuffer::drawPattern(GraphicsContext* context, const FloatRect& srcRect, const AffineTransform& patternTransform, |
| const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect) |
| { |
| - const SkBitmap& bitmap = *m_context->bitmap(); |
| - RefPtr<Image> image = BitmapImage::create(NativeImageSkia::create(drawNeedsCopy(m_context.get(), context) ? deepSkBitmapCopy(bitmap) : bitmap)); |
| - image->drawPattern(context, srcRect, patternTransform, phase, styleColorSpace, op, destRect); |
| + if (contextIsValid(&m_data)) { |
|
Stephen White
2013/05/24 17:51:01
Same here (and more places below; I'll stop naggin
|
| + const SkBitmap& bitmap = *m_context->bitmap(); |
| + RefPtr<Image> image = BitmapImage::create(NativeImageSkia::create(drawNeedsCopy(m_context.get(), context) ? deepSkBitmapCopy(bitmap) : bitmap)); |
| + image->drawPattern(context, srcRect, patternTransform, phase, styleColorSpace, op, destRect); |
| + } |
| } |
| void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable) |
| { |
| // FIXME: Disable color space conversions on accelerated canvases (for now). |
| - if (context()->isAccelerated()) |
| + if (context()->isAccelerated() || !contextIsValid(&m_data)) |
| return; |
| const SkBitmap& bitmap = *context()->bitmap(); |
| @@ -332,16 +346,25 @@ PassRefPtr<Uint8ClampedArray> getImageData(const IntRect& rect, GraphicsContext* |
| PassRefPtr<Uint8ClampedArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect, CoordinateSystem) const |
| { |
| - return getImageData<Unmultiplied>(rect, context(), m_size); |
| + if (contextIsValid(&m_data)) |
| + return getImageData<Unmultiplied>(rect, context(), m_size); |
| + RefPtr<Uint8ClampedArray> result = Uint8ClampedArray::create(rect.width() * rect.height() * 4); |
| + return result.release(); |
| } |
| PassRefPtr<Uint8ClampedArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect, CoordinateSystem) const |
| { |
| - return getImageData<Premultiplied>(rect, context(), m_size); |
| + if (contextIsValid(&m_data)) |
| + return getImageData<Premultiplied>(rect, context(), m_size); |
| + RefPtr<Uint8ClampedArray> result = Uint8ClampedArray::create(rect.width() * rect.height() * 4); |
| + return result.release(); |
| } |
| void ImageBuffer::putByteArray(Multiply multiplied, Uint8ClampedArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem) |
| { |
| + if (!contextIsValid(&m_data)) |
| + return; |
| + |
| ASSERT(sourceRect.width() > 0); |
| ASSERT(sourceRect.height() > 0); |
| @@ -412,12 +435,13 @@ String ImageBuffer::toDataURL(const String& mimeType, const double* quality, Coo |
| { |
| ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
| - Vector<char> encodedImage; |
| - if (!encodeImage(*context()->bitmap(), mimeType, quality, &encodedImage)) |
| - return "data:,"; |
| - |
| Vector<char> base64Data; |
| - base64Encode(encodedImage, base64Data); |
| + if (contextIsValid(&m_data)) { |
| + Vector<char> encodedImage; |
| + if (!encodeImage(*context()->bitmap(), mimeType, quality, &encodedImage)) |
| + return "data:,"; |
| + base64Encode(encodedImage, base64Data); |
| + } |
| return "data:" + mimeType + ";base64," + base64Data; |
| } |