Chromium Code Reviews| Index: third_party/WebKit/Source/core/offscreencanvas/OffscreenCanvas.cpp |
| diff --git a/third_party/WebKit/Source/core/offscreencanvas/OffscreenCanvas.cpp b/third_party/WebKit/Source/core/offscreencanvas/OffscreenCanvas.cpp |
| index c94e05c81040f6398d1c29b041800fc63abdf881..77d7f13e078d21b7c8e3a78ab93c1895f5c001f5 100644 |
| --- a/third_party/WebKit/Source/core/offscreencanvas/OffscreenCanvas.cpp |
| +++ b/third_party/WebKit/Source/core/offscreencanvas/OffscreenCanvas.cpp |
| @@ -18,6 +18,8 @@ |
| #include "platform/graphics/ImageBuffer.h" |
| #include "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h" |
| #include "platform/graphics/StaticBitmapImage.h" |
| +#include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| +#include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" |
| #include "platform/image-encoders/ImageEncoderUtils.h" |
| #include "platform/instrumentation/tracing/TraceEvent.h" |
| #include "platform/wtf/MathExtras.h" |
| @@ -237,6 +239,40 @@ OffscreenCanvasFrameDispatcher* OffscreenCanvas::GetOrCreateFrameDispatcher() { |
| return frame_dispatcher_.get(); |
| } |
| +void OffscreenCanvas::DiscardImageBuffer() { |
| + image_buffer_.reset(); |
| + needs_matrix_clip_restore_ = true; |
| +} |
| + |
| +ImageBuffer* OffscreenCanvas::GetImageBuffer() const { |
| + if (!image_buffer_) { |
| + IntSize surface_size(width(), height()); |
| + OpacityMode opacity_mode = |
| + context_->CreationAttributes().hasAlpha() ? kNonOpaque : kOpaque; |
| + std::unique_ptr<ImageBufferSurface> surface; |
| + if (RuntimeEnabledFeatures::accelerated2dCanvasEnabled()) { |
| + surface.reset( |
| + new AcceleratedImageBufferSurface(surface_size, opacity_mode)); |
| + } |
| + |
| + if (!surface || !surface->IsValid()) { |
| + surface.reset(new UnacceleratedImageBufferSurface( |
| + surface_size, opacity_mode, kInitializeImagePixels)); |
| + } |
| + |
| + // argh. |
|
Justin Novosad
2017/05/01 15:18:57
Comment not useful.
fserb
2017/05/02 18:49:30
done
|
| + OffscreenCanvas* non_const_this = const_cast<OffscreenCanvas*>(this); |
|
Justin Novosad
2017/05/01 15:18:57
Another reason to remove "const" from the function
fserb
2017/05/02 18:49:30
done done
|
| + non_const_this->image_buffer_ = ImageBuffer::Create(std::move(surface)); |
| + |
| + if (needs_matrix_clip_restore_) { |
| + non_const_this->needs_matrix_clip_restore_ = false; |
| + context_->RestoreCanvasMatrixClipStack(image_buffer_->Canvas()); |
| + } |
| + } |
| + |
| + return image_buffer_.get(); |
| +} |
| + |
| ScriptPromise OffscreenCanvas::Commit(RefPtr<StaticBitmapImage> image, |
| bool is_web_gl_software_rendering, |
| ScriptState* script_state, |