Chromium Code Reviews| 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 bfd4ac0787e2ea883278e4d58ee0d8d7ac8ddab9..44415e10ae66d1d5b8383b120b094ef40d3e8766 100644 |
| --- a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
| +++ b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
| @@ -128,14 +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()); |
| - surface->getCanvas()->clear(SK_ColorTRANSPARENT); |
| - return StaticBitmapImage::create(fromSkSp(surface->makeImageSnapshot())); |
| -} |
| - |
| } // namespace |
| inline HTMLCanvasElement::HTMLCanvasElement(Document& document) |
| @@ -980,12 +972,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. |
| @@ -995,7 +987,7 @@ PassRefPtr<Image> HTMLCanvasElement::copiedImage(SourceDrawingBuffer sourceBuffe |
| m_copiedImage = buffer()->newImageSnapshot(hint, SnapshotReasonGetCopiedImage); |
| updateExternallyAllocatedMemory(); |
| } |
| - return m_copiedImage; |
| + return m_copiedImage.get(); |
| } |
| void HTMLCanvasElement::discardImageBuffer() |
| @@ -1067,7 +1059,7 @@ PassRefPtr<Image> HTMLCanvasElement::getSourceImageForCanvas(SourceImageStatus* |
| if (!m_context) { |
| *status = NormalSourceImageStatus; |
| - return createTransparentImage(size()); |
| + return ensureTransparentImage(); |
| } |
| if (m_context->is3d()) { |
| @@ -1194,4 +1186,15 @@ 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()); |
| + surface->getCanvas()->clear(SK_ColorTRANSPARENT); |
| + m_transparentImage = StaticBitmapImage::create(fromSkSp(surface->makeImageSnapshot())); |
| + return m_transparentImage.get(); |
|
Ken Russell (switch to Gerrit)
2016/07/06 21:37:04
This seems to introduce a bunch of caching problem
hajimehoshi
2016/07/07 10:53:06
Even when the content is changed, as long as the s
|
| +} |
| + |
| } // namespace blink |