Commit f352608a authored by Miguel Casas's avatar Miguel Casas Committed by Commit Bot

Canvas LowLatency: make getContext() idempotent

Canvas.getContext() method is idempotent, i.e. successive calls return
the same context over and over. When the context is lowLatency, however,
we think it's an OffscreenCanvas context and fail. This CL fixes
that and adds a LayoutTest to verify the new functionality.

Bug: 895551
Change-Id: I1ae140080915a277eb45ac01486e6c7c1464aefa
Reviewed-on: https://chromium-review.googlesource.com/c/1294090Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601652}
parent 916d7bb2
<!DOCTYPE html>
<title>Tests that lowLatency Canvas getContext() calls are idempotent.</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
test(function() {
canvas = document.createElement('canvas');
var ctx_2d = canvas.getContext('2d', {lowLatency : true});
assert_true(ctx_2d instanceof CanvasRenderingContext2D);
// TODO(mcasas): Check ctx_2d.getContextAttributes().lowLatency after
// https://github.com/whatwg/html/issues/2563.
var ctx_2d_second = canvas.getContext('2d', {lowLatency : true});
assert_equals(ctx_2d, ctx_2d_second);
var ctx_2d_third = canvas.getContext('2d');
assert_equals(ctx_2d, ctx_2d_third);
}, '2D Canvas getContext() is idempotent');
test(function() {
canvas = document.createElement('canvas');
var ctx_3d = canvas.getContext('webgl', {lowLatency : true});
assert_true(ctx_3d instanceof WebGLRenderingContext);
// TODO(mcasas): Check ctx_3d.getContextAttributes().lowLatency after
// https://github.com/whatwg/html/issues/4087.
var ctx_3d_second = canvas.getContext('webgl', {lowLatency : true});
assert_equals(ctx_3d, ctx_3d_second);
var ctx_3d_third = canvas.getContext('webgl');
assert_equals(ctx_3d, ctx_3d_third);
}, 'WebGL Canvas getContext() is idempotent');
</script>
...@@ -19,7 +19,7 @@ void HTMLCanvasElementModule::getContext( ...@@ -19,7 +19,7 @@ void HTMLCanvasElementModule::getContext(
const CanvasContextCreationAttributesModule& attributes, const CanvasContextCreationAttributesModule& attributes,
ExceptionState& exception_state, ExceptionState& exception_state,
RenderingContext& result) { RenderingContext& result) {
if (canvas.SurfaceLayerBridge()) { if (canvas.SurfaceLayerBridge() && !canvas.LowLatencyEnabled()) {
// The existence of canvas surfaceLayerBridge indicates that // The existence of canvas surfaceLayerBridge indicates that
// HTMLCanvasElement.transferControlToOffscreen() has been called. // HTMLCanvasElement.transferControlToOffscreen() has been called.
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
...@@ -31,9 +31,8 @@ void HTMLCanvasElementModule::getContext( ...@@ -31,9 +31,8 @@ void HTMLCanvasElementModule::getContext(
CanvasRenderingContext* context = canvas.GetCanvasRenderingContext( CanvasRenderingContext* context = canvas.GetCanvasRenderingContext(
type, ToCanvasContextCreationAttributes(attributes)); type, ToCanvasContextCreationAttributes(attributes));
if (context) { if (context)
context->SetCanvasGetContextResult(result); context->SetCanvasGetContextResult(result);
}
} }
OffscreenCanvas* HTMLCanvasElementModule::transferControlToOffscreen( OffscreenCanvas* HTMLCanvasElementModule::transferControlToOffscreen(
......
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