LibWeb: Delegate painting surface allocation to canvas's active context

This change prepares for the addition of WebGL support, where painting
surface allocation process will differ from that of context2d.
This commit is contained in:
Aliaksandr Kalenik 2024-11-29 20:17:25 +01:00 committed by Alexander Kalenik
commit f719b05ab9
Notes: github-actions[bot] 2024-12-03 22:37:53 +00:00
8 changed files with 116 additions and 67 deletions

View file

@ -5,15 +5,12 @@
*/
#include <AK/OwnPtr.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Forward.h>
#include <LibWeb/WebGL/OpenGLContext.h>
namespace Web::WebGL {
OwnPtr<OpenGLContext> OpenGLContext::create(Gfx::PaintingSurface& bitmap)
OwnPtr<OpenGLContext> OpenGLContext::create()
{
(void)bitmap;
return {};
}

View file

@ -13,7 +13,7 @@ namespace Web::WebGL {
class OpenGLContext {
public:
static OwnPtr<OpenGLContext> create(Gfx::PaintingSurface&);
static OwnPtr<OpenGLContext> create();
virtual void present() = 0;
void clear_buffer_to_default_values();

View file

@ -39,14 +39,7 @@ JS::ThrowCompletionOr<GC::Ptr<WebGLRenderingContext>> WebGLRenderingContext::cre
// We should be coming here from getContext being called on a wrapped <canvas> element.
auto context_attributes = TRY(convert_value_to_context_attributes_dictionary(canvas_element.vm(), options));
bool created_surface = canvas_element.allocate_painting_surface(/* minimum_width= */ 1, /* minimum_height= */ 1);
if (!created_surface) {
fire_webgl_context_creation_error(canvas_element);
return GC::Ptr<WebGLRenderingContext> { nullptr };
}
VERIFY(canvas_element.surface());
auto context = OpenGLContext::create(*canvas_element.surface());
auto context = OpenGLContext::create();
if (!context) {
fire_webgl_context_creation_error(canvas_element);