Commit 912c0fd2 authored by Juanmi Huertas's avatar Juanmi Huertas Committed by Commit Bot

Onscreen Canvas checks the settings from the global DOM page for webgl.

Canvas was not able to create a WebGL context when it was a canvas
located in a frameless html (as in a template).

This CL adds a way for the Html Canvas Element to check the global dom
settings.

Bug: 1137551
Change-Id: I986cc3ef294cd460b63c46abfeac900cba2bcc35
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2516884
Commit-Queue: Juanmi Huertas <juanmihd@chromium.org>
Reviewed-by: default avatarAaron Krajeski <aaronhk@chromium.org>
Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Reviewed-by: default avatarKai Ninomiya <kainino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823841}
parent d52aea10
......@@ -60,6 +60,7 @@
#include "third_party/blink/renderer/core/dom/element_traversal.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h"
#include "third_party/blink/renderer/core/fileapi/file.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/frame/settings.h"
......@@ -411,21 +412,20 @@ bool HTMLCanvasElement::IsAccelerated() const {
return context_ && context_->IsAccelerated();
}
Settings* HTMLCanvasElement::GetSettings() const {
auto* window = DynamicTo<LocalDOMWindow>(GetExecutionContext());
if (window && window->GetFrame())
return window->GetFrame()->GetSettings();
return nullptr;
}
bool HTMLCanvasElement::IsWebGL1Enabled() const {
Document& document = GetDocument();
LocalFrame* frame = document.GetFrame();
if (!frame)
return false;
Settings* settings = frame->GetSettings();
Settings* settings = GetSettings();
return settings && settings->GetWebGL1Enabled();
}
bool HTMLCanvasElement::IsWebGL2Enabled() const {
Document& document = GetDocument();
LocalFrame* frame = document.GetFrame();
if (!frame)
return false;
Settings* settings = frame->GetSettings();
Settings* settings = GetSettings();
return settings && settings->GetWebGL2Enabled();
}
......
......@@ -283,6 +283,10 @@ class CORE_EXPORT HTMLCanvasElement final
return DispatchEvent(*event);
}
// Gets the settings of this Html Canvas Element. If there is a frame, it will
// return the settings from the frame. If it is a frameless element it will
// try to fetch the global dom window and get the settings from there.
Settings* GetSettings() const;
bool IsWebGL1Enabled() const override;
bool IsWebGL2Enabled() const override;
bool IsWebGLBlocked() const override;
......
......@@ -1366,7 +1366,7 @@ void WebGLRenderingContextBase::SetupFlags() {
DCHECK(GetDrawingBuffer());
if (canvas()) {
synthesized_errors_to_console_ =
canvas()->GetDocument().GetSettings()->GetWebGLErrorsToConsoleEnabled();
canvas()->GetSettings()->GetWebGLErrorsToConsoleEnabled();
}
is_depth_stencil_supported_ =
......
Tests that canvas can create a webgl context in a template
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS successfullyParsed is true
TEST COMPLETE
PASS Canvas succesfully created a webgl context in a template.
<html>
<head>
<script src="../../resources/js-test.js"></script>
<script>
description('Tests that canvas can create a webgl context in a template');
function start()
{
const t0 = document.createElement('template')
t0.innerHTML=`<canvas></canvas>`
context = t0.content.firstElementChild.getContext('webgl')
if(context != null)
testPassed("Canvas succesfully created a webgl context in a template.");
else
testFailed("Canvas failed in creating a webgl context in a template.")
}
</script>
</head>
<body onload="start()">
<canvas id="example"></canvas>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment