LibGL: Make GL::create_context fallible

Propagate errors in places that are already set up to handle them, like
WebGLRenderingContext and the Tubes demo, and convert other callers
to using MUST.
This commit is contained in:
Andrew Kaster 2022-09-16 05:58:30 -06:00 committed by Andreas Kling
parent 7e5080ea53
commit 8ed5ed3ec0
Notes: sideshowbarker 2024-07-18 00:54:03 +09:00
7 changed files with 14 additions and 20 deletions

View file

@ -11,7 +11,7 @@
static NonnullOwnPtr<GL::GLContext> create_testing_context()
{
auto bitmap = MUST(Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { 1, 1 }));
auto context = GL::create_context(*bitmap);
auto context = MUST(GL::create_context(*bitmap));
GL::make_context_current(context);
return context;
}

View file

@ -24,7 +24,7 @@
static NonnullOwnPtr<GL::GLContext> create_testing_context(int width, int height)
{
auto bitmap = MUST(Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { width, height }));
auto context = GL::create_context(*bitmap);
auto context = MUST(GL::create_context(*bitmap));
GL::make_context_current(context);
// Assume some defaults for our testing contexts

View file

@ -59,7 +59,7 @@ private:
constexpr u16 RENDER_WIDTH = 640;
constexpr u16 RENDER_HEIGHT = 480;
m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { RENDER_WIDTH, RENDER_HEIGHT }).release_value_but_fixme_should_propagate_errors();
m_context = GL::create_context(*m_bitmap);
m_context = MUST(GL::create_context(*m_bitmap));
start_timer(20);

View file

@ -125,7 +125,7 @@ void Tubes::choose_new_direction_for_tube(Tube& tube)
ErrorOr<void> Tubes::create_buffer(Gfx::IntSize size)
{
m_bitmap = TRY(Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, size));
m_gl_context = GL::create_context(*m_bitmap);
m_gl_context = TRY(GL::create_context(*m_bitmap));
return {};
}

View file

@ -921,11 +921,11 @@ void GLContext::build_extension_string()
m_extensions = String::join(' ', extensions);
}
NonnullOwnPtr<GLContext> create_context(Gfx::Bitmap& bitmap)
ErrorOr<NonnullOwnPtr<GLContext>> create_context(Gfx::Bitmap& bitmap)
{
// FIXME: Make driver selectable. This is currently hardcoded to LibSoftGPU
auto driver = MUST(GPU::Driver::try_create("softgpu"sv));
auto device = MUST(driver->try_create_device(bitmap.size()));
auto driver = TRY(GPU::Driver::try_create("softgpu"sv));
auto device = TRY(driver->try_create_device(bitmap.size()));
auto context = make<GLContext>(driver, move(device), bitmap);
dbgln_if(GL_DEBUG, "GL::create_context({}) -> {:p}", bitmap.size(), context.ptr());

View file

@ -532,7 +532,7 @@ private:
String m_extensions;
};
NonnullOwnPtr<GLContext> create_context(Gfx::Bitmap&);
ErrorOr<NonnullOwnPtr<GLContext>> create_context(Gfx::Bitmap&);
void make_context_current(GLContext*);
void present_context(GLContext*);

View file

@ -41,18 +41,12 @@ JS::ThrowCompletionOr<JS::GCPtr<WebGLRenderingContext>> WebGLRenderingContext::c
return JS::GCPtr<WebGLRenderingContext> { nullptr };
}
#ifndef __serenity__
// FIXME: Make WebGL work on other platforms.
(void)window;
(void)context_attributes;
dbgln("FIXME: WebGL not supported on the current platform");
fire_webgl_context_creation_error(canvas_element);
return JS::GCPtr<WebGLRenderingContext> { nullptr };
#else
// FIXME: LibGL currently doesn't propagate context creation errors.
auto context = GL::create_context(*canvas_element.bitmap());
return window.heap().allocate<WebGLRenderingContext>(window.realm(), window, canvas_element, move(context), context_attributes, context_attributes);
#endif
auto context_or_error = GL::create_context(*canvas_element.bitmap());
if (context_or_error.is_error()) {
fire_webgl_context_creation_error(canvas_element);
return JS::GCPtr<WebGLRenderingContext> { nullptr };
}
return window.heap().allocate<WebGLRenderingContext>(window.realm(), window, canvas_element, context_or_error.release_value(), context_attributes, context_attributes);
}
WebGLRenderingContext::WebGLRenderingContext(HTML::Window& window, HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters)