mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:37:35 +00:00
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:
parent
7e5080ea53
commit
8ed5ed3ec0
7 changed files with 14 additions and 20 deletions
|
@ -11,7 +11,7 @@
|
||||||
static NonnullOwnPtr<GL::GLContext> create_testing_context()
|
static NonnullOwnPtr<GL::GLContext> create_testing_context()
|
||||||
{
|
{
|
||||||
auto bitmap = MUST(Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { 1, 1 }));
|
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);
|
GL::make_context_current(context);
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
static NonnullOwnPtr<GL::GLContext> create_testing_context(int width, int height)
|
static NonnullOwnPtr<GL::GLContext> create_testing_context(int width, int height)
|
||||||
{
|
{
|
||||||
auto bitmap = MUST(Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { width, 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);
|
GL::make_context_current(context);
|
||||||
|
|
||||||
// Assume some defaults for our testing contexts
|
// Assume some defaults for our testing contexts
|
||||||
|
|
|
@ -59,7 +59,7 @@ private:
|
||||||
constexpr u16 RENDER_WIDTH = 640;
|
constexpr u16 RENDER_WIDTH = 640;
|
||||||
constexpr u16 RENDER_HEIGHT = 480;
|
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_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);
|
start_timer(20);
|
||||||
|
|
||||||
|
|
|
@ -125,7 +125,7 @@ void Tubes::choose_new_direction_for_tube(Tube& tube)
|
||||||
ErrorOr<void> Tubes::create_buffer(Gfx::IntSize size)
|
ErrorOr<void> Tubes::create_buffer(Gfx::IntSize size)
|
||||||
{
|
{
|
||||||
m_bitmap = TRY(Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, 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 {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -921,11 +921,11 @@ void GLContext::build_extension_string()
|
||||||
m_extensions = String::join(' ', extensions);
|
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
|
// FIXME: Make driver selectable. This is currently hardcoded to LibSoftGPU
|
||||||
auto driver = MUST(GPU::Driver::try_create("softgpu"sv));
|
auto driver = TRY(GPU::Driver::try_create("softgpu"sv));
|
||||||
auto device = MUST(driver->try_create_device(bitmap.size()));
|
auto device = TRY(driver->try_create_device(bitmap.size()));
|
||||||
auto context = make<GLContext>(driver, move(device), bitmap);
|
auto context = make<GLContext>(driver, move(device), bitmap);
|
||||||
dbgln_if(GL_DEBUG, "GL::create_context({}) -> {:p}", bitmap.size(), context.ptr());
|
dbgln_if(GL_DEBUG, "GL::create_context({}) -> {:p}", bitmap.size(), context.ptr());
|
||||||
|
|
||||||
|
|
|
@ -532,7 +532,7 @@ private:
|
||||||
String m_extensions;
|
String m_extensions;
|
||||||
};
|
};
|
||||||
|
|
||||||
NonnullOwnPtr<GLContext> create_context(Gfx::Bitmap&);
|
ErrorOr<NonnullOwnPtr<GLContext>> create_context(Gfx::Bitmap&);
|
||||||
void make_context_current(GLContext*);
|
void make_context_current(GLContext*);
|
||||||
void present_context(GLContext*);
|
void present_context(GLContext*);
|
||||||
|
|
||||||
|
|
|
@ -41,18 +41,12 @@ JS::ThrowCompletionOr<JS::GCPtr<WebGLRenderingContext>> WebGLRenderingContext::c
|
||||||
return JS::GCPtr<WebGLRenderingContext> { nullptr };
|
return JS::GCPtr<WebGLRenderingContext> { nullptr };
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __serenity__
|
auto context_or_error = GL::create_context(*canvas_element.bitmap());
|
||||||
// FIXME: Make WebGL work on other platforms.
|
if (context_or_error.is_error()) {
|
||||||
(void)window;
|
fire_webgl_context_creation_error(canvas_element);
|
||||||
(void)context_attributes;
|
return JS::GCPtr<WebGLRenderingContext> { nullptr };
|
||||||
dbgln("FIXME: WebGL not supported on the current platform");
|
}
|
||||||
fire_webgl_context_creation_error(canvas_element);
|
return window.heap().allocate<WebGLRenderingContext>(window.realm(), window, canvas_element, context_or_error.release_value(), context_attributes, context_attributes);
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WebGLRenderingContext::WebGLRenderingContext(HTML::Window& window, HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters)
|
WebGLRenderingContext::WebGLRenderingContext(HTML::Window& window, HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue