summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/canvas/offscreencanvas
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-05-15 10:20:33 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-05-15 10:28:57 +0000
commitd17ea114e5ef69ad5d5d7413280a13e6428098aa (patch)
tree2c01a75df69f30d27b1432467cfe7c1467a498da /chromium/third_party/blink/renderer/modules/canvas/offscreencanvas
parent8c5c43c7b138c9b4b0bf56d946e61d3bbc111bec (diff)
downloadqtwebengine-chromium-d17ea114e5ef69ad5d5d7413280a13e6428098aa.tar.gz
BASELINE: Update Chromium to 67.0.3396.47
Change-Id: Idcb1341782e417561a2473eeecc82642dafda5b7 Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'chromium/third_party/blink/renderer/modules/canvas/offscreencanvas')
-rw-r--r--chromium/third_party/blink/renderer/modules/canvas/offscreencanvas/offscreen_canvas_module.cc36
-rw-r--r--chromium/third_party/blink/renderer/modules/canvas/offscreencanvas/offscreen_canvas_module.h33
-rw-r--r--chromium/third_party/blink/renderer/modules/canvas/offscreencanvas/offscreen_canvas_module.idl16
-rw-r--r--chromium/third_party/blink/renderer/modules/canvas/offscreencanvas/offscreen_canvas_test.cc117
4 files changed, 202 insertions, 0 deletions
diff --git a/chromium/third_party/blink/renderer/modules/canvas/offscreencanvas/offscreen_canvas_module.cc b/chromium/third_party/blink/renderer/modules/canvas/offscreencanvas/offscreen_canvas_module.cc
new file mode 100644
index 00000000000..d22e4d6f043
--- /dev/null
+++ b/chromium/third_party/blink/renderer/modules/canvas/offscreencanvas/offscreen_canvas_module.cc
@@ -0,0 +1,36 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "third_party/blink/renderer/modules/canvas/offscreencanvas/offscreen_canvas_module.h"
+
+#include "third_party/blink/renderer/core/execution_context/execution_context.h"
+#include "third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.h"
+#include "third_party/blink/renderer/modules/canvas/htmlcanvas/canvas_context_creation_attributes_helpers.h"
+#include "third_party/blink/renderer/modules/canvas/htmlcanvas/canvas_context_creation_attributes_module.h"
+#include "third_party/blink/renderer/modules/canvas/offscreencanvas2d/offscreen_canvas_rendering_context_2d.h"
+
+namespace blink {
+
+void OffscreenCanvasModule::getContext(
+ ExecutionContext* execution_context,
+ OffscreenCanvas& offscreen_canvas,
+ const String& id,
+ const CanvasContextCreationAttributesModule& attributes,
+ ExceptionState& exception_state,
+ OffscreenRenderingContext& result) {
+ if (offscreen_canvas.IsNeutered()) {
+ exception_state.ThrowDOMException(kInvalidStateError,
+ "OffscreenCanvas object is detached");
+ return;
+ }
+
+ // OffscreenCanvas cannot be transferred after getContext, so this execution
+ // context will always be the right one from here on.
+ CanvasRenderingContext* context = offscreen_canvas.GetCanvasRenderingContext(
+ execution_context, id, ToCanvasContextCreationAttributes(attributes));
+ if (context)
+ context->SetOffscreenCanvasGetContextResult(result);
+}
+
+} // namespace blink
diff --git a/chromium/third_party/blink/renderer/modules/canvas/offscreencanvas/offscreen_canvas_module.h b/chromium/third_party/blink/renderer/modules/canvas/offscreencanvas/offscreen_canvas_module.h
new file mode 100644
index 00000000000..eba50624b8c
--- /dev/null
+++ b/chromium/third_party/blink/renderer/modules/canvas/offscreencanvas/offscreen_canvas_module.h
@@ -0,0 +1,33 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_CANVAS_OFFSCREENCANVAS_OFFSCREEN_CANVAS_MODULE_H_
+#define THIRD_PARTY_BLINK_RENDERER_MODULES_CANVAS_OFFSCREENCANVAS_OFFSCREEN_CANVAS_MODULE_H_
+
+#include "third_party/blink/renderer/bindings/core/v8/exception_state.h"
+#include "third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.h"
+#include "third_party/blink/renderer/modules/modules_export.h"
+#include "third_party/blink/renderer/platform/wtf/allocator.h"
+#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
+
+namespace blink {
+
+class CanvasContextCreationAttributesModule;
+class OffscreenCanvas;
+
+class MODULES_EXPORT OffscreenCanvasModule {
+ STATIC_ONLY(OffscreenCanvasModule);
+
+ public:
+ static void getContext(ExecutionContext*,
+ OffscreenCanvas&,
+ const String&,
+ const CanvasContextCreationAttributesModule&,
+ ExceptionState&,
+ OffscreenRenderingContext&);
+};
+
+} // namespace blink
+
+#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_CANVAS_OFFSCREENCANVAS_OFFSCREEN_CANVAS_MODULE_H_
diff --git a/chromium/third_party/blink/renderer/modules/canvas/offscreencanvas/offscreen_canvas_module.idl b/chromium/third_party/blink/renderer/modules/canvas/offscreencanvas/offscreen_canvas_module.idl
new file mode 100644
index 00000000000..d7d5fc99904
--- /dev/null
+++ b/chromium/third_party/blink/renderer/modules/canvas/offscreencanvas/offscreen_canvas_module.idl
@@ -0,0 +1,16 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// https://html.spec.whatwg.org/multipage/scripting.html#the-offscreencanvas-interface
+
+typedef (OffscreenCanvasRenderingContext2D or
+ WebGLRenderingContext or
+ WebGL2RenderingContext) OffscreenRenderingContext;
+enum OffscreenRenderingContextType { "2d", "webgl", "webgl2" };
+
+[
+ ImplementedAs=OffscreenCanvasModule
+] partial interface OffscreenCanvas {
+ [CallWith=ExecutionContext, RaisesException, RuntimeEnabled=OffscreenCanvas] OffscreenRenderingContext? getContext(OffscreenRenderingContextType contextType, optional CanvasContextCreationAttributesModule attributes);
+};
diff --git a/chromium/third_party/blink/renderer/modules/canvas/offscreencanvas/offscreen_canvas_test.cc b/chromium/third_party/blink/renderer/modules/canvas/offscreencanvas/offscreen_canvas_test.cc
new file mode 100644
index 00000000000..450e5461f09
--- /dev/null
+++ b/chromium/third_party/blink/renderer/modules/canvas/offscreencanvas/offscreen_canvas_test.cc
@@ -0,0 +1,117 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/blink/public/mojom/page/page_visibility_state.mojom-blink.h"
+#include "third_party/blink/renderer/core/dom/document.h"
+#include "third_party/blink/renderer/core/frame/local_frame_view.h"
+#include "third_party/blink/renderer/core/frame/settings.h"
+#include "third_party/blink/renderer/core/html/canvas/html_canvas_element.h"
+#include "third_party/blink/renderer/core/loader/empty_clients.h"
+#include "third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.h"
+#include "third_party/blink/renderer/core/testing/page_test_base.h"
+#include "third_party/blink/renderer/modules/canvas/htmlcanvas/html_canvas_element_module.h"
+#include "third_party/blink/renderer/modules/canvas/offscreencanvas2d/offscreen_canvas_rendering_context_2d.h"
+#include "third_party/blink/renderer/platform/graphics/gpu/shared_gpu_context.h"
+#include "third_party/blink/renderer/platform/graphics/test/fake_gles2_interface.h"
+#include "third_party/blink/renderer/platform/graphics/test/fake_web_graphics_context_3d_provider.h"
+#include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
+
+using testing::Mock;
+
+namespace blink {
+
+class OffscreenCanvasTest : public PageTestBase {
+ protected:
+ OffscreenCanvasTest();
+ void SetUp() override;
+ void TearDown() override;
+
+ HTMLCanvasElement& CanvasElement() const { return *canvas_element_; }
+ OffscreenCanvas& OSCanvas() const { return *offscreen_canvas_; }
+ OffscreenCanvasFrameDispatcher* Dispatcher() const {
+ return offscreen_canvas_->GetOrCreateFrameDispatcher();
+ }
+ OffscreenCanvasRenderingContext2D& Context() const { return *context_; }
+ ScriptState* GetScriptState() const {
+ return ToScriptStateForMainWorld(GetDocument().GetFrame());
+ }
+ ScopedTestingPlatformSupport<TestingPlatformSupport>& platform() {
+ return platform_;
+ }
+
+ private:
+ Persistent<HTMLCanvasElement> canvas_element_;
+ Persistent<OffscreenCanvas> offscreen_canvas_;
+ Persistent<OffscreenCanvasRenderingContext2D> context_;
+ ScopedTestingPlatformSupport<TestingPlatformSupport> platform_;
+ FakeGLES2Interface gl_;
+};
+
+OffscreenCanvasTest::OffscreenCanvasTest() = default;
+
+void OffscreenCanvasTest::SetUp() {
+ auto factory = [](FakeGLES2Interface* gl, bool* gpu_compositing_disabled)
+ -> std::unique_ptr<WebGraphicsContext3DProvider> {
+ *gpu_compositing_disabled = false;
+ gl->SetIsContextLost(false);
+ return std::make_unique<FakeWebGraphicsContext3DProvider>(gl);
+ };
+ SharedGpuContext::SetContextProviderFactoryForTesting(
+ WTF::BindRepeating(factory, WTF::Unretained(&gl_)));
+ Page::PageClients page_clients;
+ FillWithEmptyClients(page_clients);
+ PageTestBase::SetupPageWithClients(&page_clients);
+ SetHtmlInnerHTML("<body><canvas id='c'></canvas></body>");
+ canvas_element_ = ToHTMLCanvasElement(GetElementById("c"));
+ DummyExceptionStateForTesting exception_state;
+ offscreen_canvas_ = HTMLCanvasElementModule::transferControlToOffscreen(
+ *canvas_element_, exception_state);
+ CanvasContextCreationAttributesCore attrs;
+ context_ = static_cast<OffscreenCanvasRenderingContext2D*>(
+ offscreen_canvas_->GetCanvasRenderingContext(&GetDocument(), String("2d"),
+ attrs));
+}
+
+void OffscreenCanvasTest::TearDown() {
+ SharedGpuContext::ResetForTesting();
+}
+
+TEST_F(OffscreenCanvasTest, AnimationNotInitiallySuspended) {
+ ScriptState::Scope scope(GetScriptState());
+ EXPECT_FALSE(Dispatcher()->IsAnimationSuspended());
+}
+
+TEST_F(OffscreenCanvasTest, AnimationActiveAfterCommit) {
+ ScriptState::Scope scope(GetScriptState());
+ DummyExceptionStateForTesting exception_state;
+ EXPECT_FALSE(Dispatcher()->NeedsBeginFrame());
+ Context().commit(GetScriptState(), exception_state);
+ platform()->RunUntilIdle();
+ EXPECT_TRUE(Dispatcher()->NeedsBeginFrame());
+}
+
+TEST_F(OffscreenCanvasTest, AnimationSuspendedWhilePlaceholderHidden) {
+ ScriptState::Scope scope(GetScriptState());
+ DummyExceptionStateForTesting exception_state;
+
+ // Do a commit and run it to completion so that the frame dispatcher
+ // instance becomes known to OffscreenCanvas (async).
+ Context().commit(GetScriptState(), exception_state); // necessary
+ platform()->RunUntilIdle();
+ EXPECT_FALSE(Dispatcher()->IsAnimationSuspended());
+
+ // Change visibility to hidden -> animation should be suspended
+ GetPage().SetVisibilityState(mojom::PageVisibilityState::kHidden, false);
+ platform()->RunUntilIdle();
+ EXPECT_TRUE(Dispatcher()->IsAnimationSuspended());
+
+ // Change visibility to visible -> animation should resume
+ GetPage().SetVisibilityState(mojom::PageVisibilityState::kVisible, false);
+ platform()->RunUntilIdle();
+ EXPECT_FALSE(Dispatcher()->IsAnimationSuspended());
+}
+
+} // namespace blink