Chromium Code Reviews| Index: Source/core/html/HTMLCanvasElement.cpp |
| diff --git a/Source/core/html/HTMLCanvasElement.cpp b/Source/core/html/HTMLCanvasElement.cpp |
| index 398e2314071092d48ecda73f84c3e49c5c430842..3ec6cb1e4baadd0c25e3f4d3b55d9efe1f64266a 100644 |
| --- a/Source/core/html/HTMLCanvasElement.cpp |
| +++ b/Source/core/html/HTMLCanvasElement.cpp |
| @@ -82,7 +82,7 @@ bool canCreateImageBuffer(const IntSize& deviceSize) |
| return false; |
| if (deviceSize.width() > MaxSkiaDim || deviceSize.height() > MaxSkiaDim) |
| return false; |
| - if (!deviceSize.width() || !deviceSize.height()) |
| + if (deviceSize.isEmpty()) |
| return false; |
| return true; |
| } |
| @@ -410,16 +410,11 @@ const AtomicString HTMLCanvasElement::imageSourceURL() const |
| String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double* quality, SourceDrawingBuffer sourceBuffer) const |
| { |
| - if (m_size.isEmpty() || !canCreateImageBuffer(size())) |
| + if (!buffer()) |
| return String("data:,"); |
| String encodingMimeType = toEncodingMimeType(mimeType); |
| - if (!m_context) { |
| - RefPtrWillBeRawPtr<ImageData> imageData = ImageData::create(m_size); |
| - return ImageEncoder::toDataURL(ImageEncoder::RawImageBytes(imageData->size(), imageData->data()->data()), encodingMimeType, quality); |
| - } |
| - |
| - if (m_context->is3d()) { |
| + if (m_context && m_context->is3d()) { |
| // Get non-premultiplied data because of inaccurate premultiplied alpha conversion of buffer()->toDataURL(). |
| RefPtrWillBeRawPtr<ImageData> imageData = |
| toWebGLRenderingContext(m_context.get())->paintRenderingResultsToImageData(sourceBuffer); |
| @@ -554,8 +549,9 @@ PassOwnPtr<ImageBufferSurface> HTMLCanvasElement::createImageBufferSurface(const |
| void HTMLCanvasElement::createImageBuffer() |
| { |
| + ASSERT(m_context); |
| createImageBufferInternal(); |
| - if (m_didFailToCreateImageBuffer && m_context && m_context->is2d()) |
| + if (m_didFailToCreateImageBuffer && m_context->is2d()) |
| toCanvasRenderingContext2D(m_context.get())->loseContext(); |
| } |
| @@ -651,7 +647,7 @@ void HTMLCanvasElement::updateExternallyAllocatedMemory() const |
| GraphicsContext* HTMLCanvasElement::drawingContext() const |
| { |
| - return buffer() ? m_imageBuffer->context() : 0; |
| + return buffer() && m_imageBuffer ? m_imageBuffer->context() : 0; |
| } |
| GraphicsContext* HTMLCanvasElement::existingDrawingContext() const |
| @@ -664,6 +660,16 @@ GraphicsContext* HTMLCanvasElement::existingDrawingContext() const |
| ImageBuffer* HTMLCanvasElement::buffer() const |
| { |
| + if (!m_context) { |
| + if (!canCreateImageBuffer(size())) |
| + return nullptr; |
| + m_noContextImageBuffer = ImageBuffer::create(size(), NonOpaque); |
|
Justin Novosad
2014/11/27 18:58:35
Please explain how this code helps. It seems waste
Justin Novosad
2014/11/27 19:04:29
Ironically, the title of this change is "Don't mak
dshwang
2014/11/27 19:34:28
That's good question.
Two reason:
1. this method r
Justin Novosad
2014/11/27 20:18:15
That is a problem. We cannot guarantee that this m
dshwang
2014/11/27 20:42:17
That's true, but in that sense, most of layout tes
dshwang
2014/11/28 07:49:44
Let me explain more in the case of context.drawIma
|
| + return m_noContextImageBuffer.get(); |
| + } |
| + if (m_noContextImageBuffer) { |
| + m_noContextImageBuffer.clear(); |
| + const_cast<HTMLCanvasElement*>(this)->clearCopiedImage(); |
| + } |
| if (!hasImageBuffer() && !m_didFailToCreateImageBuffer) |
| const_cast<HTMLCanvasElement*>(this)->createImageBuffer(); |
| return m_imageBuffer.get(); |
| @@ -671,10 +677,11 @@ ImageBuffer* HTMLCanvasElement::buffer() const |
| void HTMLCanvasElement::ensureUnacceleratedImageBuffer() |
| { |
| + ASSERT(m_context); |
| if ((hasImageBuffer() && !m_imageBuffer->isAccelerated()) || m_didFailToCreateImageBuffer) |
| return; |
| discardImageBuffer(); |
| - OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque : Opaque; |
| + OpacityMode opacityMode = m_context->hasAlpha() ? NonOpaque : Opaque; |
| m_imageBuffer = ImageBuffer::create(size(), opacityMode); |
| m_didFailToCreateImageBuffer = !m_imageBuffer; |
| } |
| @@ -754,10 +761,10 @@ PassRefPtr<Image> HTMLCanvasElement::getSourceImageForCanvas(SourceImageMode mod |
| *status = ExternalSourceImageStatus; |
| // can't create SkImage from WebGLImageBufferSurface (contains only SkBitmap) |
| - return m_imageBuffer->copyImage(DontCopyBackingStore, Unscaled); |
| + return buffer()->copyImage(DontCopyBackingStore, Unscaled); |
|
Justin Novosad
2014/11/27 18:58:35
I think this CL is a good opportunity to fix somet
dshwang
2014/11/27 19:34:28
That's good idea, but many const methods call buff
Justin Novosad
2014/11/27 20:18:15
Acknowledged.
|
| } |
| - RefPtr<SkImage> image = m_imageBuffer->newImageSnapshot(); |
| + RefPtr<SkImage> image = buffer()->newImageSnapshot(); |
| if (image) { |
| *status = NormalSourceImageStatus; |