From ca030169f785c630a5b5fb786ef394eb5ca1f387 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Fri, 9 Sep 2022 12:46:29 -0500 Subject: [PATCH] avm2: Implement BitmapData.rect and stub BitmapData.applyFilter These are the last BitmapData methods needed for Solarmax (the victory screen after beating the last level now renders). --- .../avm2/globals/flash/display/bitmapdata.rs | 33 ++++++++++++++++++ .../tests/swfs/avm2/bitmapdata_constr/Test.as | 8 ++++- .../swfs/avm2/bitmapdata_constr/output.txt | 4 +++ .../swfs/avm2/bitmapdata_constr/test.swf | Bin 1149 -> 1168 bytes 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/core/src/avm2/globals/flash/display/bitmapdata.rs b/core/src/avm2/globals/flash/display/bitmapdata.rs index 45a20d74e..5ba7042de 100644 --- a/core/src/avm2/globals/flash/display/bitmapdata.rs +++ b/core/src/avm2/globals/flash/display/bitmapdata.rs @@ -452,6 +452,37 @@ pub fn dispose<'gc>( Ok(Value::Undefined) } +/// Implement `BitmapData.rect` +pub fn rect<'gc>( + activation: &mut Activation<'_, 'gc, '_>, + this: Option>, + _args: &[Value<'gc>], +) -> Result, Error> { + if let Some(bitmap_data) = this.and_then(|this| this.as_bitmap_data()) { + let bd = bitmap_data.read(); + return Ok(activation + .avm2() + .classes() + .rectangle + .construct( + activation, + &[0.into(), 0.into(), bd.width().into(), bd.height().into()], + )? + .into()); + } + Ok(Value::Undefined) +} + +/// Implement `BitmapData.applyFilter` +pub fn apply_filter<'gc>( + _activation: &mut Activation<'_, 'gc, '_>, + _this: Option>, + _args: &[Value<'gc>], +) -> Result, Error> { + log::warn!("BitmapData.applyFilter: Not yet implemented"); + Ok(Value::Undefined) +} + /// Construct `BitmapData`'s class. pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> { let class = Class::new( @@ -476,6 +507,7 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc> )] = &[ ("width", Some(width), None), ("height", Some(height), None), + ("rect", Some(rect), None), ("transparent", Some(transparent), None), ]; write.define_public_builtin_instance_properties(mc, PUBLIC_INSTANCE_PROPERTIES); @@ -490,6 +522,7 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc> ("draw", draw), ("fillRect", fill_rect), ("dispose", dispose), + ("applyFilter", apply_filter), ]; write.define_public_builtin_instance_methods(mc, PUBLIC_INSTANCE_METHODS); diff --git a/tests/tests/swfs/avm2/bitmapdata_constr/Test.as b/tests/tests/swfs/avm2/bitmapdata_constr/Test.as index 1a33c2c31..1ce2f0d75 100644 --- a/tests/tests/swfs/avm2/bitmapdata_constr/Test.as +++ b/tests/tests/swfs/avm2/bitmapdata_constr/Test.as @@ -1,4 +1,4 @@ -package { +package { public class Test { } } @@ -14,6 +14,9 @@ trace(bd.width); trace("///bd.height;"); trace(bd.height); +trace("///bd.rect;"); +trace(bd.rect); + trace("///bd.transparent;"); trace(bd.transparent); @@ -29,6 +32,9 @@ trace(bd.width); trace("///bd.height;"); trace(bd.height); +trace("///bd.rect;"); +trace(bd.rect); + trace("///bd.transparent;"); trace(bd.transparent); diff --git a/tests/tests/swfs/avm2/bitmapdata_constr/output.txt b/tests/tests/swfs/avm2/bitmapdata_constr/output.txt index 73227c282..7ddca3683 100644 --- a/tests/tests/swfs/avm2/bitmapdata_constr/output.txt +++ b/tests/tests/swfs/avm2/bitmapdata_constr/output.txt @@ -3,6 +3,8 @@ 128 ///bd.height; 128 +///bd.rect; +(x=0, y=0, w=128, h=128) ///bd.transparent; true ///bd.getPixel(0,0); @@ -12,6 +14,8 @@ true 128 ///bd.height; 128 +///bd.rect; +(x=0, y=0, w=128, h=128) ///bd.transparent; false ///bd.getPixel(0,0); diff --git a/tests/tests/swfs/avm2/bitmapdata_constr/test.swf b/tests/tests/swfs/avm2/bitmapdata_constr/test.swf index 2b3745a9a996efeb2584d57d08e2beebd1799fce..17333b1c69bc728eee7b2f884341a2c8771edaaa 100644 GIT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