mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 14:42:44 +00:00 
			
		
		
		
	LibGfx+LibWeb: Propagate OOM when creating PaintStyles
This commit is contained in:
		
							parent
							
								
									f0a99634dd
								
							
						
					
					
						commit
						3a0a7e3e96
					
				
					 5 changed files with 21 additions and 21 deletions
				
			
		|  | @ -43,9 +43,9 @@ private: | ||||||
| 
 | 
 | ||||||
| class SolidColorPaintStyle final : public PaintStyle { | class SolidColorPaintStyle final : public PaintStyle { | ||||||
| public: | public: | ||||||
|     static NonnullRefPtr<SolidColorPaintStyle> create(Color color) |     static ErrorOr<NonnullRefPtr<SolidColorPaintStyle>> create(Color color) | ||||||
|     { |     { | ||||||
|         return adopt_ref(*new SolidColorPaintStyle(color)); |         return adopt_nonnull_ref_or_enomem(new (nothrow) SolidColorPaintStyle(color)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     virtual Color sample_color(IntPoint) const override { return m_color; } |     virtual Color sample_color(IntPoint) const override { return m_color; } | ||||||
|  | @ -91,9 +91,9 @@ private: | ||||||
| 
 | 
 | ||||||
| class LinearGradientPaintStyle final : public GradientPaintStyle { | class LinearGradientPaintStyle final : public GradientPaintStyle { | ||||||
| public: | public: | ||||||
|     static NonnullRefPtr<LinearGradientPaintStyle> create(float angle = 0.0f) |     static ErrorOr<ErrorOr<NonnullRefPtr<LinearGradientPaintStyle>>> create(float angle = 0.0f) | ||||||
|     { |     { | ||||||
|         return adopt_ref(*new LinearGradientPaintStyle(angle)); |         return adopt_nonnull_ref_or_enomem(new (nothrow) LinearGradientPaintStyle(angle)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|  | @ -109,9 +109,9 @@ private: | ||||||
| 
 | 
 | ||||||
| class ConicGradientPaintStyle final : public GradientPaintStyle { | class ConicGradientPaintStyle final : public GradientPaintStyle { | ||||||
| public: | public: | ||||||
|     static NonnullRefPtr<ConicGradientPaintStyle> create(IntPoint center, float start_angle = 0.0f) |     static ErrorOr<NonnullRefPtr<ConicGradientPaintStyle>> create(IntPoint center, float start_angle = 0.0f) | ||||||
|     { |     { | ||||||
|         return adopt_ref(*new ConicGradientPaintStyle(center, start_angle)); |         return adopt_nonnull_ref_or_enomem(new (nothrow) ConicGradientPaintStyle(center, start_angle)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|  | @ -129,9 +129,9 @@ private: | ||||||
| 
 | 
 | ||||||
| class RadialGradientPaintStyle final : public GradientPaintStyle { | class RadialGradientPaintStyle final : public GradientPaintStyle { | ||||||
| public: | public: | ||||||
|     static NonnullRefPtr<RadialGradientPaintStyle> create(IntPoint center, IntSize size) |     static ErrorOr<NonnullRefPtr<RadialGradientPaintStyle>> create(IntPoint center, IntSize size) | ||||||
|     { |     { | ||||||
|         return adopt_ref(*new RadialGradientPaintStyle(center, size)); |         return adopt_nonnull_ref_or_enomem(new (nothrow) RadialGradientPaintStyle(center, size)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|  | @ -153,9 +153,9 @@ private: | ||||||
| 
 | 
 | ||||||
| class CanvasLinearGradientPaintStyle final : public GradientPaintStyle { | class CanvasLinearGradientPaintStyle final : public GradientPaintStyle { | ||||||
| public: | public: | ||||||
|     static NonnullRefPtr<CanvasLinearGradientPaintStyle> create(FloatPoint p0, FloatPoint p1) |     static ErrorOr<NonnullRefPtr<CanvasLinearGradientPaintStyle>> create(FloatPoint p0, FloatPoint p1) | ||||||
|     { |     { | ||||||
|         return adopt_ref(*new CanvasLinearGradientPaintStyle(p0, p1)); |         return adopt_nonnull_ref_or_enomem(new (nothrow) CanvasLinearGradientPaintStyle(p0, p1)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|  | @ -173,9 +173,9 @@ private: | ||||||
| 
 | 
 | ||||||
| class CanvasConicGradientPaintStyle final : public GradientPaintStyle { | class CanvasConicGradientPaintStyle final : public GradientPaintStyle { | ||||||
| public: | public: | ||||||
|     static NonnullRefPtr<CanvasConicGradientPaintStyle> create(FloatPoint center, float start_angle = 0.0f) |     static ErrorOr<NonnullRefPtr<CanvasConicGradientPaintStyle>> create(FloatPoint center, float start_angle = 0.0f) | ||||||
|     { |     { | ||||||
|         return adopt_ref(*new CanvasConicGradientPaintStyle(center, start_angle)); |         return adopt_nonnull_ref_or_enomem(new (nothrow) CanvasConicGradientPaintStyle(center, start_angle)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|  | @ -193,9 +193,9 @@ private: | ||||||
| 
 | 
 | ||||||
| class CanvasRadialGradientPaintStyle final : public GradientPaintStyle { | class CanvasRadialGradientPaintStyle final : public GradientPaintStyle { | ||||||
| public: | public: | ||||||
|     static NonnullRefPtr<CanvasRadialGradientPaintStyle> create(FloatPoint start_center, float start_radius, FloatPoint end_center, float end_radius) |     static ErrorOr<NonnullRefPtr<CanvasRadialGradientPaintStyle>> create(FloatPoint start_center, float start_radius, FloatPoint end_center, float end_radius) | ||||||
|     { |     { | ||||||
|         return adopt_ref(*new CanvasRadialGradientPaintStyle(start_center, start_radius, end_center, end_radius)); |         return adopt_nonnull_ref_or_enomem(new (nothrow) CanvasRadialGradientPaintStyle(start_center, start_radius, end_center, end_radius)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|  |  | ||||||
|  | @ -45,7 +45,7 @@ NonnullRefPtr<Gfx::PaintStyle> CanvasState::FillOrStrokeStyle::to_gfx_paint_styl | ||||||
|     return m_fill_or_stroke_style.visit( |     return m_fill_or_stroke_style.visit( | ||||||
|         [&](Gfx::Color color) -> NonnullRefPtr<Gfx::PaintStyle> { |         [&](Gfx::Color color) -> NonnullRefPtr<Gfx::PaintStyle> { | ||||||
|             if (!m_color_paint_style) |             if (!m_color_paint_style) | ||||||
|                 m_color_paint_style = Gfx::SolidColorPaintStyle::create(color); |                 m_color_paint_style = Gfx::SolidColorPaintStyle::create(color).release_value_but_fixme_should_propagate_errors(); | ||||||
|             return m_color_paint_style.release_nonnull(); |             return m_color_paint_style.release_nonnull(); | ||||||
|         }, |         }, | ||||||
|         [&](auto handle) { |         [&](auto handle) { | ||||||
|  |  | ||||||
|  | @ -21,21 +21,21 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<CanvasGradient>> CanvasGradient::create_rad | ||||||
|     if (r1 < 0) |     if (r1 < 0) | ||||||
|         return WebIDL::IndexSizeError::create(realm, "The r1 passed is less than 0"); |         return WebIDL::IndexSizeError::create(realm, "The r1 passed is less than 0"); | ||||||
| 
 | 
 | ||||||
|     auto radial_gradient = Gfx::CanvasRadialGradientPaintStyle::create(Gfx::FloatPoint { x0, y0 }, r0, Gfx::FloatPoint { x1, y1 }, r1); |     auto radial_gradient = TRY_OR_THROW_OOM(realm.vm(), Gfx::CanvasRadialGradientPaintStyle::create(Gfx::FloatPoint { x0, y0 }, r0, Gfx::FloatPoint { x1, y1 }, r1)); | ||||||
|     return MUST_OR_THROW_OOM(realm.heap().allocate<CanvasGradient>(realm, realm, *radial_gradient)); |     return MUST_OR_THROW_OOM(realm.heap().allocate<CanvasGradient>(realm, realm, *radial_gradient)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createlineargradient
 | // https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createlineargradient
 | ||||||
| WebIDL::ExceptionOr<JS::NonnullGCPtr<CanvasGradient>> CanvasGradient::create_linear(JS::Realm& realm, double x0, double y0, double x1, double y1) | WebIDL::ExceptionOr<JS::NonnullGCPtr<CanvasGradient>> CanvasGradient::create_linear(JS::Realm& realm, double x0, double y0, double x1, double y1) | ||||||
| { | { | ||||||
|     auto linear_gradient = Gfx::CanvasLinearGradientPaintStyle::create(Gfx::FloatPoint { x0, y0 }, Gfx::FloatPoint { x1, y1 }); |     auto linear_gradient = TRY_OR_THROW_OOM(realm.vm(), Gfx::CanvasLinearGradientPaintStyle::create(Gfx::FloatPoint { x0, y0 }, Gfx::FloatPoint { x1, y1 })); | ||||||
|     return MUST_OR_THROW_OOM(realm.heap().allocate<CanvasGradient>(realm, realm, *linear_gradient)); |     return MUST_OR_THROW_OOM(realm.heap().allocate<CanvasGradient>(realm, realm, *linear_gradient)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createconicgradient
 | // https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createconicgradient
 | ||||||
| WebIDL::ExceptionOr<JS::NonnullGCPtr<CanvasGradient>> CanvasGradient::create_conic(JS::Realm& realm, double start_angle, double x, double y) | WebIDL::ExceptionOr<JS::NonnullGCPtr<CanvasGradient>> CanvasGradient::create_conic(JS::Realm& realm, double start_angle, double x, double y) | ||||||
| { | { | ||||||
|     auto conic_gradient = Gfx::CanvasConicGradientPaintStyle::create(Gfx::FloatPoint { x, y }, start_angle); |     auto conic_gradient = TRY_OR_THROW_OOM(realm.vm(), Gfx::CanvasConicGradientPaintStyle::create(Gfx::FloatPoint { x, y }, start_angle)); | ||||||
|     return MUST_OR_THROW_OOM(realm.heap().allocate<CanvasGradient>(realm, realm, *conic_gradient)); |     return MUST_OR_THROW_OOM(realm.heap().allocate<CanvasGradient>(realm, realm, *conic_gradient)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -125,7 +125,7 @@ WebIDL::ExceptionOr<JS::GCPtr<CanvasPattern>> CanvasPattern::create(JS::Realm& r | ||||||
|     auto const& bitmap = *image.visit([](auto const& source) -> Gfx::Bitmap const* { return source->bitmap(); }); |     auto const& bitmap = *image.visit([](auto const& source) -> Gfx::Bitmap const* { return source->bitmap(); }); | ||||||
| 
 | 
 | ||||||
|     // 6. Let pattern be a new CanvasPattern object with the image image and the repetition behavior given by repetition.
 |     // 6. Let pattern be a new CanvasPattern object with the image image and the repetition behavior given by repetition.
 | ||||||
|     auto pattern = CanvasPatternPaintStyle::create(bitmap, *repetition_value); |     auto pattern = TRY_OR_THROW_OOM(realm.vm(), CanvasPatternPaintStyle::create(bitmap, *repetition_value)); | ||||||
| 
 | 
 | ||||||
|     // FIXME: 7. If image is not origin-clean, then mark pattern as not origin-clean.
 |     // FIXME: 7. If image is not origin-clean, then mark pattern as not origin-clean.
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -21,9 +21,9 @@ public: | ||||||
|         NoRepeat |         NoRepeat | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     static NonnullRefPtr<CanvasPatternPaintStyle> create(Gfx::Bitmap const& bitmap, Repetition repetition) |     static ErrorOr<NonnullRefPtr<CanvasPatternPaintStyle>> create(Gfx::Bitmap const& bitmap, Repetition repetition) | ||||||
|     { |     { | ||||||
|         return adopt_ref(*new CanvasPatternPaintStyle(bitmap, repetition)); |         return adopt_nonnull_ref_or_enomem(new (nothrow) CanvasPatternPaintStyle(bitmap, repetition)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     virtual void paint(Gfx::IntRect physical_bounding_box, PaintFunction paint) const override; |     virtual void paint(Gfx::IntRect physical_bounding_box, PaintFunction paint) const override; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 MacDue
						MacDue