LibWeb: Remove ImageData's create_with_size() and use create() instead

Removes ImageData::create_with_size() and redirects previous usage to
ImageData::create().
This commit is contained in:
Kenneth Myhra 2024-03-23 21:59:12 +01:00 committed by Andreas Kling
parent 8a1e88677f
commit 51847bbebf
Notes: sideshowbarker 2024-07-16 23:59:28 +09:00
5 changed files with 5 additions and 26 deletions

View file

@ -15,7 +15,7 @@ class CanvasImageData {
public:
virtual ~CanvasImageData() = default;
virtual JS::GCPtr<ImageData> create_image_data(int width, int height) const = 0;
virtual WebIDL::ExceptionOr<JS::NonnullGCPtr<ImageData>> create_image_data(int width, int height) const = 0;
virtual WebIDL::ExceptionOr<JS::GCPtr<ImageData>> get_image_data(int x, int y, int width, int height) const = 0;
virtual void put_image_data(ImageData const&, float x, float y) = 0;

View file

@ -374,9 +374,9 @@ void CanvasRenderingContext2D::fill(Path2D& path, StringView fill_rule)
return fill_internal(transformed_path, parse_fill_rule(fill_rule));
}
JS::GCPtr<ImageData> CanvasRenderingContext2D::create_image_data(int width, int height) const
WebIDL::ExceptionOr<JS::NonnullGCPtr<ImageData>> CanvasRenderingContext2D::create_image_data(int width, int height) const
{
return ImageData::create_with_size(realm(), width, height);
return ImageData::create(realm(), width, height);
}
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-getimagedata
@ -392,7 +392,7 @@ WebIDL::ExceptionOr<JS::GCPtr<ImageData>> CanvasRenderingContext2D::get_image_da
// 3. Let imageData be a new ImageData object.
// 4. Initialize imageData given sw, sh, settings set to settings, and defaultColorSpace set to this's color space.
auto image_data = ImageData::create_with_size(realm(), width, height);
auto image_data = TRY(ImageData::create(realm(), width, height));
// NOTE: We don't attempt to create the underlying bitmap here; if it doesn't exist, it's like copying only transparent black pixels (which is a no-op).
if (!canvas_element().bitmap())

View file

@ -80,7 +80,7 @@ public:
virtual void fill(StringView fill_rule) override;
virtual void fill(Path2D& path, StringView fill_rule) override;
virtual JS::GCPtr<ImageData> create_image_data(int width, int height) const override;
virtual WebIDL::ExceptionOr<JS::NonnullGCPtr<ImageData>> create_image_data(int width, int height) const override;
virtual WebIDL::ExceptionOr<JS::GCPtr<ImageData>> get_image_data(int x, int y, int width, int height) const override;
virtual void put_image_data(ImageData const&, float x, float y) override;

View file

@ -37,25 +37,6 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<ImageData>> ImageData::construct_impl(JS::R
return ImageData::create(realm, sw, sh, settings);
}
JS::GCPtr<ImageData> ImageData::create_with_size(JS::Realm& realm, int width, int height)
{
if (width <= 0 || height <= 0)
return nullptr;
if (width > 16384 || height > 16384)
return nullptr;
auto data_or_error = JS::Uint8ClampedArray::create(realm, width * height * 4);
if (data_or_error.is_error())
return nullptr;
auto data = JS::NonnullGCPtr<JS::Uint8ClampedArray>(*data_or_error.release_value());
auto bitmap_or_error = Gfx::Bitmap::create_wrapper(Gfx::BitmapFormat::RGBA8888, Gfx::IntSize(width, height), 1, width * sizeof(u32), data->data().data());
if (bitmap_or_error.is_error())
return nullptr;
return realm.heap().allocate<ImageData>(realm, realm, bitmap_or_error.release_value(), move(data));
}
ImageData::ImageData(JS::Realm& realm, NonnullRefPtr<Gfx::Bitmap> bitmap, JS::NonnullGCPtr<JS::Uint8ClampedArray> data)
: PlatformObject(realm)
, m_bitmap(move(bitmap))

View file

@ -25,8 +25,6 @@ public:
[[nodiscard]] static WebIDL::ExceptionOr<JS::NonnullGCPtr<ImageData>> create(JS::Realm&, u32 sw, u32 sh, Optional<ImageDataSettings> const& settings = {});
[[nodiscard]] static WebIDL::ExceptionOr<JS::NonnullGCPtr<ImageData>> construct_impl(JS::Realm&, u32 sw, u32 sh, Optional<ImageDataSettings> const& settings = {});
static JS::GCPtr<ImageData> create_with_size(JS::Realm&, int width, int height);
virtual ~ImageData() override;
unsigned width() const;