Index: third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
diff --git a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
index c4f61a920737688205b7a09ae86f9296d2369585..4a58361e92026a4cfbb76b1c8e0bf8d4768a2a0b 100644 |
--- a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
+++ b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
@@ -128,13 +128,6 @@ bool canCreateImageBuffer(const IntSize& size) |
return true; |
} |
-PassRefPtr<Image> createTransparentImage(const IntSize& size) |
-{ |
- DCHECK(canCreateImageBuffer(size)); |
- sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(size.width(), size.height()); |
- return StaticBitmapImage::create(fromSkSp(surface->makeImageSnapshot())); |
-} |
- |
} // namespace |
inline HTMLCanvasElement::HTMLCanvasElement(Document& document) |
@@ -986,12 +979,12 @@ void HTMLCanvasElement::ensureUnacceleratedImageBuffer() |
m_didFailToCreateImageBuffer = !m_imageBuffer; |
} |
-PassRefPtr<Image> HTMLCanvasElement::copiedImage(SourceDrawingBuffer sourceBuffer, AccelerationHint hint) const |
+Image* HTMLCanvasElement::copiedImage(SourceDrawingBuffer sourceBuffer, AccelerationHint hint) const |
{ |
if (!isPaintable()) |
return nullptr; |
if (!m_context) |
- return createTransparentImage(size()); |
+ return ensureTransparentImage(); |
bool needToUpdate = !m_copiedImage; |
// The concept of SourceDrawingBuffer is valid on only WebGL. |
@@ -1001,7 +994,7 @@ PassRefPtr<Image> HTMLCanvasElement::copiedImage(SourceDrawingBuffer sourceBuffe |
m_copiedImage = buffer()->newImageSnapshot(hint, SnapshotReasonGetCopiedImage); |
updateExternallyAllocatedMemory(); |
} |
- return m_copiedImage; |
+ return m_copiedImage.get(); |
} |
void HTMLCanvasElement::discardImageBuffer() |
@@ -1073,7 +1066,7 @@ PassRefPtr<Image> HTMLCanvasElement::getSourceImageForCanvas(SourceImageStatus* |
if (!m_context) { |
*status = NormalSourceImageStatus; |
- return createTransparentImage(size()); |
+ return ensureTransparentImage(); |
} |
if (m_context->is3d()) { |
@@ -1200,4 +1193,14 @@ bool HTMLCanvasElement::createSurfaceLayer() |
return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height()); |
} |
+Image* HTMLCanvasElement::ensureTransparentImage() const |
+{ |
+ if (m_transparentImage && m_transparentImage->size() == size()) |
+ return m_transparentImage.get(); |
+ DCHECK(canCreateImageBuffer(size())); |
+ sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(size().width(), size().height()); |
+ m_transparentImage = StaticBitmapImage::create(fromSkSp(surface->makeImageSnapshot())); |
+ return m_transparentImage.get(); |
+} |
+ |
} // namespace blink |