diff --git a/Cargo.lock b/Cargo.lock index 68695896f..b24c050ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3105,6 +3105,7 @@ dependencies = [ "jpeg-decoder", "log", "png", + "smallvec", "swf", ] diff --git a/core/src/avm1/globals/movie_clip.rs b/core/src/avm1/globals/movie_clip.rs index 702bbf5ab..bc9781aba 100644 --- a/core/src/avm1/globals/movie_clip.rs +++ b/core/src/avm1/globals/movie_clip.rs @@ -14,9 +14,9 @@ use crate::display_object::{ }; use crate::ecma_conversions::f64_to_wrapping_i32; use crate::prelude::*; -use crate::shape_utils::DrawCommand; use crate::vminterface::Instantiator; use gc_arena::MutationContext; +use ruffle_render::shape_utils::DrawCommand; use swf::{ FillStyle, Fixed8, Gradient, GradientInterpolation, GradientRecord, GradientSpread, LineCapStyle, LineJoinStyle, LineStyle, Twips, diff --git a/core/src/avm2/globals/flash/display/graphics.rs b/core/src/avm2/globals/flash/display/graphics.rs index 2013d95bd..7e89130aa 100644 --- a/core/src/avm2/globals/flash/display/graphics.rs +++ b/core/src/avm2/globals/flash/display/graphics.rs @@ -10,9 +10,9 @@ use crate::avm2::Namespace; use crate::avm2::QName; use crate::display_object::TDisplayObject; use crate::drawing::Drawing; -use crate::shape_utils::DrawCommand; use crate::string::WStr; use gc_arena::{GcCell, MutationContext}; +use ruffle_render::shape_utils::DrawCommand; use std::f64::consts::FRAC_1_SQRT_2; use swf::{Color, FillStyle, Fixed8, LineCapStyle, LineJoinStyle, LineStyle, Twips}; diff --git a/core/src/backend/render.rs b/core/src/backend/render.rs index 9522fee04..177c49f45 100644 --- a/core/src/backend/render.rs +++ b/core/src/backend/render.rs @@ -3,11 +3,11 @@ mod null; pub use null::{NullBitmapSource, NullRenderer}; pub use ruffle_render::utils::{determine_jpeg_tag_format, remove_invalid_jpeg_data}; -use crate::shape_utils::DistilledShape; pub use crate::transform::Transform; use downcast_rs::Downcast; use ruffle_render::bitmap::{Bitmap, BitmapHandle, BitmapInfo, BitmapSource}; use ruffle_render::matrix::Matrix; +use ruffle_render::shape_utils::DistilledShape; use ruffle_render::utils; pub use swf; diff --git a/core/src/backend/render/null.rs b/core/src/backend/render/null.rs index 27e081830..e7e34d472 100644 --- a/core/src/backend/render/null.rs +++ b/core/src/backend/render/null.rs @@ -1,8 +1,8 @@ use crate::backend::render::{Error, RenderBackend, ShapeHandle}; -use crate::shape_utils::DistilledShape; use crate::transform::Transform; use ruffle_render::bitmap::{Bitmap, BitmapHandle, BitmapInfo, BitmapSource}; use ruffle_render::matrix::Matrix; +use ruffle_render::shape_utils::DistilledShape; use swf::Color; pub struct NullBitmapSource; diff --git a/core/src/display_object/edit_text.rs b/core/src/display_object/edit_text.rs index d42bf08ec..e10a61916 100644 --- a/core/src/display_object/edit_text.rs +++ b/core/src/display_object/edit_text.rs @@ -20,13 +20,13 @@ use crate::events::{ButtonKeyCode, ClipEvent, ClipEventResult, KeyCode}; use crate::font::{round_down_to_pixel, Glyph, TextRenderSettings}; use crate::html::{BoxBounds, FormatSpans, LayoutBox, LayoutContent, TextFormat}; use crate::prelude::*; -use crate::shape_utils::DrawCommand; use crate::string::{utils as string_utils, AvmString, WStr, WString}; use crate::tag_utils::SwfMovie; use crate::transform::Transform; use crate::vminterface::{AvmObject, AvmType, Instantiator}; use chrono::Utc; use gc_arena::{Collect, Gc, GcCell, MutationContext}; +use ruffle_render::shape_utils::DrawCommand; use std::{cell::Ref, cell::RefMut, sync::Arc}; use swf::Twips; diff --git a/core/src/display_object/graphic.rs b/core/src/display_object/graphic.rs index 4a634323c..89aad7006 100644 --- a/core/src/display_object/graphic.rs +++ b/core/src/display_object/graphic.rs @@ -192,7 +192,7 @@ impl<'gc> TDisplayObject<'gc> for Graphic<'gc> { } } else { let shape = &self.0.read().static_data.shape; - return crate::shape_utils::shape_hit_test(shape, point, &local_matrix); + return ruffle_render::shape_utils::shape_hit_test(shape, point, &local_matrix); } } diff --git a/core/src/display_object/morph_shape.rs b/core/src/display_object/morph_shape.rs index 90cd2ed79..8d78fdfd9 100644 --- a/core/src/display_object/morph_shape.rs +++ b/core/src/display_object/morph_shape.rs @@ -116,7 +116,11 @@ impl<'gc> TDisplayObject<'gc> for MorphShape<'gc> { if let Some(frame) = self.0.read().static_data.frames.borrow().get(&self.ratio()) { let local_matrix = self.global_to_local_matrix(); let point = local_matrix * point; - return crate::shape_utils::shape_hit_test(&frame.shape, point, &local_matrix); + return ruffle_render::shape_utils::shape_hit_test( + &frame.shape, + point, + &local_matrix, + ); } else { log::warn!("Missing ratio for morph shape"); } @@ -293,7 +297,7 @@ impl MorphShapeStatic { line_styles, }; - let bounds = crate::shape_utils::calculate_shape_bounds(&shape[..]); + let bounds = ruffle_render::shape_utils::calculate_shape_bounds(&shape[..]); let shape = swf::Shape { version: 4, id: 0, diff --git a/core/src/display_object/text.rs b/core/src/display_object/text.rs index 73bd9e80b..b46ae6a4f 100644 --- a/core/src/display_object/text.rs +++ b/core/src/display_object/text.rs @@ -201,7 +201,7 @@ impl<'gc> TDisplayObject<'gc> for Text<'gc> { let glyph_shape = glyph.as_shape(); let glyph_bounds: BoundingBox = (&glyph_shape.shape_bounds).into(); if glyph_bounds.contains(point) - && crate::shape_utils::shape_hit_test( + && ruffle_render::shape_utils::shape_hit_test( &glyph_shape, point, &local_matrix, diff --git a/core/src/drawing.rs b/core/src/drawing.rs index 5587322ed..7732c29a3 100644 --- a/core/src/drawing.rs +++ b/core/src/drawing.rs @@ -1,9 +1,9 @@ use crate::backend::render::ShapeHandle; use crate::context::RenderContext; -use crate::shape_utils::{DistilledShape, DrawCommand, DrawPath}; use gc_arena::Collect; use ruffle_render::bitmap::{BitmapInfo, BitmapSource}; use ruffle_render::bounding_box::BoundingBox; +use ruffle_render::shape_utils::{DistilledShape, DrawCommand, DrawPath}; use std::cell::Cell; use swf::{FillStyle, LineStyle, Twips}; @@ -304,7 +304,7 @@ impl Drawing { point: (Twips, Twips), local_matrix: &ruffle_render::matrix::Matrix, ) -> bool { - use crate::shape_utils; + use ruffle_render::shape_utils; for path in &self.paths { match path { DrawingPath::Fill(fill) => { diff --git a/core/src/font.rs b/core/src/font.rs index a446023e3..a29f5cd1a 100644 --- a/core/src/font.rs +++ b/core/src/font.rs @@ -432,7 +432,9 @@ impl Glyph { pub fn as_shape(&self) -> Ref<'_, swf::Shape> { let mut write = self.shape.borrow_mut(); if write.is_none() { - *write = Some(crate::shape_utils::swf_glyph_to_shape(&self.swf_glyph)); + *write = Some(ruffle_render::shape_utils::swf_glyph_to_shape( + &self.swf_glyph, + )); } drop(write); let read = self.shape.borrow(); diff --git a/core/src/html/layout.rs b/core/src/html/layout.rs index 876dc9961..6dbc3802d 100644 --- a/core/src/html/layout.rs +++ b/core/src/html/layout.rs @@ -5,10 +5,10 @@ use crate::drawing::Drawing; use crate::font::{EvalParameters, Font}; use crate::html::dimensions::{BoxBounds, Position, Size}; use crate::html::text_format::{FormatSpans, TextFormat, TextSpan}; -use crate::shape_utils::DrawCommand; use crate::string::{utils as string_utils, WStr}; use crate::tag_utils::SwfMovie; use gc_arena::Collect; +use ruffle_render::shape_utils::DrawCommand; use std::cmp::{max, min}; use std::sync::Arc; use swf::Twips; diff --git a/core/src/lib.rs b/core/src/lib.rs index d529b5d33..3c8db2e2a 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -32,7 +32,6 @@ pub mod loader; mod locale; mod player; mod prelude; -pub mod shape_utils; pub mod string; pub mod tag_utils; pub mod timer; diff --git a/render/Cargo.toml b/render/Cargo.toml index d9a3979e7..f246a80e9 100644 --- a/render/Cargo.toml +++ b/render/Cargo.toml @@ -12,6 +12,7 @@ log = "0.4" gif = "0.11.4" png = { version = "0.17.5" } flate2 = "1.0.24" +smallvec = { version = "1.9.0", features = ["union"] } [dependencies.jpeg-decoder] version = "0.2.6" diff --git a/render/canvas/src/lib.rs b/render/canvas/src/lib.rs index b82c7a0fa..75d3b3f1f 100644 --- a/render/canvas/src/lib.rs +++ b/render/canvas/src/lib.rs @@ -1,10 +1,10 @@ use fnv::FnvHashMap; use ruffle_core::backend::render::{NullBitmapSource, RenderBackend, ShapeHandle, Transform}; use ruffle_core::color_transform::ColorTransform; -use ruffle_core::shape_utils::{DistilledShape, DrawCommand, LineScaleMode, LineScales}; use ruffle_core::swf::{self, Color}; use ruffle_render::bitmap::{Bitmap, BitmapFormat, BitmapHandle, BitmapSource}; use ruffle_render::matrix::Matrix; +use ruffle_render::shape_utils::{DistilledShape, DrawCommand, LineScaleMode, LineScales}; use ruffle_web_common::{JsError, JsResult}; use wasm_bindgen::{Clamped, JsCast}; use web_sys::{ @@ -375,7 +375,7 @@ impl RenderBackend for WebCanvasRenderBackend { } fn register_glyph_shape(&mut self, glyph: &swf::Glyph) -> ShapeHandle { - let shape = ruffle_core::shape_utils::swf_glyph_to_shape(glyph); + let shape = ruffle_render::shape_utils::swf_glyph_to_shape(glyph); self.register_shape((&shape).into(), &NullBitmapSource) } @@ -740,7 +740,7 @@ fn swf_shape_to_canvas_commands( bitmaps: &FnvHashMap, context: &CanvasRenderingContext2d, ) -> ShapeData { - use ruffle_core::shape_utils::DrawPath; + use ruffle_render::shape_utils::DrawPath; use swf::{FillStyle, LineCapStyle, LineJoinStyle}; // Some browsers will vomit if you try to load/draw an image with 0 width/height. diff --git a/render/common_tess/src/lib.rs b/render/common_tess/src/lib.rs index 492547092..75b7f5194 100644 --- a/render/common_tess/src/lib.rs +++ b/render/common_tess/src/lib.rs @@ -5,9 +5,9 @@ use lyon::tessellation::{ FillTessellator, FillVertex, StrokeTessellator, StrokeVertex, StrokeVertexConstructor, }; use lyon::tessellation::{FillOptions, StrokeOptions}; -use ruffle_core::shape_utils::{DistilledShape, DrawCommand, DrawPath}; use ruffle_core::swf; use ruffle_render::bitmap::{BitmapHandle, BitmapSource}; +use ruffle_render::shape_utils::{DistilledShape, DrawCommand, DrawPath}; pub struct ShapeTessellator { fill_tess: FillTessellator, diff --git a/render/src/lib.rs b/render/src/lib.rs index 982de9447..12c715baa 100644 --- a/render/src/lib.rs +++ b/render/src/lib.rs @@ -2,4 +2,5 @@ pub mod bitmap; pub mod bounding_box; pub mod error; pub mod matrix; +pub mod shape_utils; pub mod utils; diff --git a/core/src/shape_utils.rs b/render/src/shape_utils.rs similarity index 99% rename from core/src/shape_utils.rs rename to render/src/shape_utils.rs index 1d17b31d1..ecbcf0e25 100644 --- a/core/src/shape_utils.rs +++ b/render/src/shape_utils.rs @@ -1,5 +1,5 @@ -use ruffle_render::bounding_box::BoundingBox; -use ruffle_render::matrix::Matrix; +use crate::bounding_box::BoundingBox; +use crate::matrix::Matrix; use smallvec::SmallVec; use swf::{CharacterId, FillStyle, LineStyle, Shape, ShapeRecord, Twips}; diff --git a/render/webgl/src/lib.rs b/render/webgl/src/lib.rs index 2e17f54dd..2bfa2d5a4 100644 --- a/render/webgl/src/lib.rs +++ b/render/webgl/src/lib.rs @@ -1,9 +1,9 @@ use bytemuck::{Pod, Zeroable}; use fnv::FnvHashMap; use ruffle_core::backend::render::{NullBitmapSource, RenderBackend, ShapeHandle, Transform}; -use ruffle_core::shape_utils::DistilledShape; use ruffle_core::swf::{self, Color}; use ruffle_render::bitmap::{Bitmap, BitmapFormat, BitmapHandle, BitmapSource}; +use ruffle_render::shape_utils::DistilledShape; use ruffle_render_common_tess::{ Gradient as TessGradient, GradientType, ShapeTessellator, Vertex as TessVertex, }; @@ -703,7 +703,7 @@ impl RenderBackend for WebGlRenderBackend { } fn register_glyph_shape(&mut self, glyph: &swf::Glyph) -> ShapeHandle { - let shape = ruffle_core::shape_utils::swf_glyph_to_shape(glyph); + let shape = ruffle_render::shape_utils::swf_glyph_to_shape(glyph); let handle = ShapeHandle(self.meshes.len()); let mesh = self.register_shape_internal((&shape).into(), &NullBitmapSource); self.meshes.push(mesh); diff --git a/render/wgpu/src/lib.rs b/render/wgpu/src/lib.rs index d078487cc..17840da0c 100644 --- a/render/wgpu/src/lib.rs +++ b/render/wgpu/src/lib.rs @@ -9,9 +9,9 @@ use enum_map::Enum; use fnv::FnvHashMap; use ruffle_core::backend::render::{RenderBackend, ShapeHandle, Transform}; use ruffle_core::color_transform::ColorTransform; -use ruffle_core::shape_utils::DistilledShape; use ruffle_core::swf::{self, Color}; use ruffle_render::bitmap::{Bitmap, BitmapHandle, BitmapSource}; +use ruffle_render::shape_utils::DistilledShape; use ruffle_render_common_tess::{ DrawType as TessDrawType, Gradient as TessGradient, GradientType, ShapeTessellator, Vertex as TessVertex, @@ -897,7 +897,7 @@ impl RenderBackend for WgpuRenderBackend { } fn register_glyph_shape(&mut self, glyph: &swf::Glyph) -> ShapeHandle { - let shape = ruffle_core::shape_utils::swf_glyph_to_shape(glyph); + let shape = ruffle_render::shape_utils::swf_glyph_to_shape(glyph); let handle = ShapeHandle(self.meshes.len()); let mesh = self.register_shape_internal( (&shape).into(),