Commit ba5c0881 authored by Patrick To's avatar Patrick To Committed by Commit Bot

Return a WebGL context if requesting xr compatibility fails

If the xrCompatible flag is set on the attributes when creating a WebGL
context and we cannot be xr compatible, today's behavior returns a null
context. Instead, a WebGL context should be created and returned with
the xrCompatible flag set to false.

XRSystem::MakeXrCompatible* is also changed to return kNotCompatible on
failure. This previously returned kAlreadyCompatible because MacOS
doesn't have a VR service, so MakeXrCompatible fails. This caused tests
on MacOS to fail since null was being returned when requesting a WebGL
context.

Bug: 1086697
Change-Id: Ida9b99b334a85f12c6313bc700cd02e7e5bda8db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2264599Reviewed-by: default avatarAlexander Cooper <alcooper@chromium.org>
Reviewed-by: default avatarBrandon Jones <bajones@chromium.org>
Commit-Queue: Patrick To <patrto@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#782612}
parent 86652806
......@@ -98,30 +98,32 @@ static bool ShouldCreateContext(
CanvasRenderingContext* WebGLRenderingContext::Factory::Create(
CanvasRenderingContextHost* host,
const CanvasContextCreationAttributesCore& attrs) {
// Create a copy of attrs so flags can be modified if needed before passing
// into the WebGLRenderingContext constructor.
CanvasContextCreationAttributesCore attribs = attrs;
// The xr_compatible attribute needs to be handled before creating the context
// because the GPU process may potentially be restarted in order to be XR
// compatible. This scenario occurs if the GPU process is not using the GPU
// that the VR headset is plugged into. If the GPU process is restarted, the
// WebGraphicsContext3DProvider must be created using the new one.
if (attrs.xr_compatible &&
if (attribs.xr_compatible &&
!WebGLRenderingContextBase::MakeXrCompatibleSync(host)) {
// If the xr_compatible attribute is requested and we're not able to be xr
// compatible, fail and don't create the context.
// TODO(http://crbug.com/1086697): Create a WebGL context with xrCompatible
// set to false
return nullptr;
// If xr compatibility is requested and we can't be xr compatible, return a
// context with the flag set to false.
attribs.xr_compatible = false;
}
bool using_gpu_compositing;
std::unique_ptr<WebGraphicsContext3DProvider> context_provider(
CreateWebGraphicsContext3DProvider(
host, attrs, Platform::kWebGL1ContextType, &using_gpu_compositing));
host, attribs, Platform::kWebGL1ContextType, &using_gpu_compositing));
if (!ShouldCreateContext(context_provider.get()))
return nullptr;
WebGLRenderingContext* rendering_context =
MakeGarbageCollected<WebGLRenderingContext>(
host, std::move(context_provider), using_gpu_compositing, attrs);
host, std::move(context_provider), using_gpu_compositing, attribs);
if (!rendering_context->GetDrawingBuffer()) {
host->HostDispatchEvent(
WebGLContextEvent::Create(event_type_names::kWebglcontextcreationerror,
......
......@@ -1199,17 +1199,13 @@ void XRSystem::MakeXrCompatibleAsync(
if (service_.is_bound()) {
service_->MakeXrCompatible(std::move(callback));
} else {
// If the service cannot be created, any sessions that can be supported will
// be managed entirely in Blink and thus cannot have an incompatible context
std::move(callback).Run(
device::mojom::XrCompatibleResult::kAlreadyCompatible);
std::move(callback).Run(device::mojom::XrCompatibleResult::kNotCompatible);
}
}
void XRSystem::MakeXrCompatibleSync(
device::mojom::XrCompatibleResult* xr_compatible_result) {
// See the comment in MakeXrCompatibleAsync().
*xr_compatible_result = device::mojom::XrCompatibleResult::kAlreadyCompatible;
*xr_compatible_result = device::mojom::XrCompatibleResult::kNotCompatible;
TryEnsureService();
if (service_.is_bound())
......
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