| Index: third_party/WebKit/Source/modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.cpp
|
| diff --git a/third_party/WebKit/Source/modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.cpp b/third_party/WebKit/Source/modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.cpp
|
| index b91aa5a5eeb494b4fe567847df93faa38c5c60ea..334161f52cdb6f370fab8cc27b877408aea7a0b5 100644
|
| --- a/third_party/WebKit/Source/modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.cpp
|
| +++ b/third_party/WebKit/Source/modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.cpp
|
| @@ -5,16 +5,21 @@
|
| #include "modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h"
|
|
|
| #include "bindings/modules/v8/OffscreenCanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContext.h"
|
| +#include "bindings/modules/v8/V8WebGLTexture.h"
|
| #include "core/dom/ExecutionContext.h"
|
| #include "core/frame/ImageBitmap.h"
|
| #include "core/frame/Settings.h"
|
| #include "core/workers/WorkerGlobalScope.h"
|
| #include "core/workers/WorkerSettings.h"
|
| +#include "modules/webgl/WebGLContextGroup.h"
|
| #include "platform/graphics/ImageBuffer.h"
|
| #include "platform/graphics/StaticBitmapImage.h"
|
| +#include "platform/graphics/gpu/SharedGpuContext.h"
|
| +#include "platform/graphics/gpu/TextureImageBufferSurface.h"
|
| #include "platform/graphics/paint/PaintCanvas.h"
|
| #include "platform/wtf/Assertions.h"
|
| #include "platform/wtf/CurrentTime.h"
|
| +#include "third_party/skia/include/gpu/GrContext.h"
|
|
|
| namespace blink {
|
|
|
| @@ -26,23 +31,37 @@ OffscreenCanvasRenderingContext2D::OffscreenCanvasRenderingContext2D(
|
| const CanvasContextCreationAttributes& attrs)
|
| : CanvasRenderingContext(canvas, attrs) {
|
| ExecutionContext* execution_context = ExecutionContext::From(script_state);
|
| +
|
| if (execution_context->IsDocument()) {
|
| if (ToDocument(execution_context)
|
| ->GetSettings()
|
| ->GetDisableReadingFromCanvas())
|
| canvas->SetDisableReadingFromCanvasTrue();
|
| - return;
|
| + } else {
|
| + WorkerSettings* worker_settings =
|
| + ToWorkerGlobalScope(execution_context)->GetWorkerSettings();
|
| + if (worker_settings && worker_settings->DisableReadingFromCanvas())
|
| + canvas->SetDisableReadingFromCanvasTrue();
|
| }
|
|
|
| - WorkerSettings* worker_settings =
|
| - ToWorkerGlobalScope(execution_context)->GetWorkerSettings();
|
| - if (worker_settings && worker_settings->DisableReadingFromCanvas())
|
| - canvas->SetDisableReadingFromCanvasTrue();
|
| + if (attrs.hasTexture()) {
|
| + webgl_texture_ = V8WebGLTexture::toImplWithTypeCheck(
|
| + attrs.texture().GetIsolate(), attrs.texture().V8Value());
|
| + if (!webgl_texture_) {
|
| + // TODO(fserb): exception_state.ThrowTypeError("member texture is not of
|
| + // type WebGLTexture.");
|
| + DVLOG(1) << "member texture is not of type WebGLTexture.";
|
| + return;
|
| + }
|
| + DVLOG(1) << "OCRC2D with texture!";
|
| + GetImageBuffer();
|
| + }
|
| }
|
|
|
| DEFINE_TRACE(OffscreenCanvasRenderingContext2D) {
|
| CanvasRenderingContext::Trace(visitor);
|
| BaseRenderingContext2D::Trace(visitor);
|
| + visitor->Trace(webgl_texture_);
|
| }
|
|
|
| ScriptPromise OffscreenCanvasRenderingContext2D::commit(
|
| @@ -88,6 +107,9 @@ int OffscreenCanvasRenderingContext2D::Height() const {
|
| }
|
|
|
| bool OffscreenCanvasRenderingContext2D::HasImageBuffer() const {
|
| + if (webgl_texture_) {
|
| + return !!texture_image_buffer_;
|
| + }
|
| return host()->GetImageBuffer();
|
| }
|
|
|
| @@ -102,10 +124,31 @@ ColorBehavior OffscreenCanvasRenderingContext2D::DrawImageColorBehavior()
|
| }
|
|
|
| ImageBuffer* OffscreenCanvasRenderingContext2D::GetImageBuffer() const {
|
| + if (webgl_texture_) {
|
| + return const_cast<OffscreenCanvasRenderingContext2D*>(this)
|
| + ->CreateTextureImageBuffer();
|
| + }
|
| return const_cast<CanvasRenderingContextHost*>(host())
|
| ->GetOrCreateImageBuffer();
|
| }
|
|
|
| +ImageBuffer* OffscreenCanvasRenderingContext2D::CreateTextureImageBuffer() {
|
| + DCHECK(webgl_texture_);
|
| + if (!texture_image_buffer_) {
|
| + OpacityMode opacity_mode =
|
| + CreationAttributes().hasAlpha() ? kNonOpaque : kOpaque;
|
| +
|
| + std::unique_ptr<ImageBufferSurface> surface;
|
| + surface.reset(new TextureImageBufferSurface(
|
| + webgl_texture_->ContextGroup()->GetAGLInterface(),
|
| + webgl_texture_->GetTarget(), webgl_texture_->Object(), host()->Size(),
|
| + opacity_mode));
|
| + texture_image_buffer_ = ImageBuffer::Create(std::move(surface));
|
| + }
|
| +
|
| + return texture_image_buffer_.get();
|
| +}
|
| +
|
| RefPtr<StaticBitmapImage>
|
| OffscreenCanvasRenderingContext2D::TransferToStaticBitmapImage() {
|
| if (!GetImageBuffer())
|
| @@ -192,7 +235,15 @@ AffineTransform OffscreenCanvasRenderingContext2D::BaseTransform() const {
|
| return GetImageBuffer()->BaseTransform();
|
| }
|
|
|
| -void OffscreenCanvasRenderingContext2D::DidDraw(const SkIRect& dirty_rect) {}
|
| +void OffscreenCanvasRenderingContext2D::DidDraw(const SkIRect& dirty_rect) {
|
| + GrContext* gr_context = SharedGpuContext::Gr();
|
| + if (texture_image_buffer_ && gr_context) {
|
| + DVLOG(1) << "Flush";
|
| + gr_context->resetContext();
|
| + texture_image_buffer_->FlushGpu(kFlushReasonDrawImageOfWebGL);
|
| + DVLOG(1) << "EndFlush";
|
| + }
|
| +}
|
|
|
| bool OffscreenCanvasRenderingContext2D::StateHasFilter() {
|
| return GetState().HasFilterForOffscreenCanvas(host()->Size());
|
|
|