Skip to content

Commit ec5b725

Browse files
core: Store BitmapDataObject instead of Avm2Object in BitmapData
1 parent 6bc4edc commit ec5b725

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

core/src/avm2/globals/flash/display/bitmap.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn bitmap_allocator<'gc>(
5656
let new_bitmap_data = fill_bitmap_data_from_symbol(activation, bitmap.compressed());
5757
let bitmap_data_obj =
5858
BitmapDataObject::from_bitmap_data(activation.context, new_bitmap_data);
59-
new_bitmap_data.init_object2(activation.gc(), bitmap_data_obj.into());
59+
new_bitmap_data.init_object2(activation.gc(), bitmap_data_obj);
6060

6161
let child = Bitmap::new_with_bitmap_data(
6262
activation.gc(),
@@ -124,12 +124,12 @@ pub fn get_bitmap_data<'gc>(
124124
let this = this.as_object().unwrap();
125125

126126
if let Some(bitmap) = this.as_display_object().and_then(|dobj| dobj.as_bitmap()) {
127-
let mut value = bitmap.bitmap_data().object2();
127+
let value = bitmap
128+
.bitmap_data()
129+
.object2()
130+
.map(|o| o.into())
131+
.unwrap_or(Value::Null);
128132

129-
// AS3 expects an unset BitmapData to be null, not 'undefined'
130-
if matches!(value, Value::Undefined) {
131-
value = Value::Null;
132-
}
133133
return Ok(value);
134134
}
135135

core/src/avm2/globals/flash/display/bitmap_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub fn init<'gc>(
142142
)
143143
};
144144

145-
new_bitmap_data.init_object2(activation.gc(), this);
145+
new_bitmap_data.init_object2(activation.gc(), bitmap_data_obj);
146146
bitmap_data_obj.init_bitmap_data(activation.gc(), new_bitmap_data);
147147

148148
Ok(Value::Undefined)

core/src/avm2/object/bitmapdata_object.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<'gc> BitmapDataObject<'gc> {
8080
},
8181
));
8282

83-
bitmap_data.init_object2(mc, instance.into());
83+
bitmap_data.init_object2(mc, instance);
8484

8585
instance
8686
}
@@ -101,7 +101,7 @@ impl<'gc> BitmapDataObject<'gc> {
101101
}
102102

103103
/// This should only be called to initialize the association between an AVM
104-
/// object and it's associated bitmap data. This association should not be
104+
/// object and its associated bitmap data. This association should not be
105105
/// reinitialized later.
106106
pub fn init_bitmap_data(self, mc: &Mutation<'gc>, new_bitmap: BitmapData<'gc>) {
107107
unlock!(Gc::write(mc, self.0), BitmapDataObjectData, bitmap_data).set(new_bitmap);

core/src/bitmap/bitmap_data.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::avm2::{Object as Avm2Object, Value as Avm2Value};
1+
use crate::avm2::object::BitmapDataObject;
22
use crate::context::RenderContext;
33
use crate::display_object::{DisplayObject, DisplayObjectWeak, TDisplayObject};
44
use bitflags::bitflags;
@@ -300,7 +300,7 @@ impl<'gc> BitmapData<'gc> {
300300
self.0.width()
301301
}
302302

303-
pub fn object2(&self) -> Avm2Value<'gc> {
303+
pub fn object2(&self) -> Option<BitmapDataObject<'gc>> {
304304
self.0.object2()
305305
}
306306

@@ -323,7 +323,7 @@ impl<'gc> BitmapData<'gc> {
323323
self.0.dispose(mc);
324324
}
325325

326-
pub fn init_object2(&self, mc: &Mutation<'gc>, object: Avm2Object<'gc>) {
326+
pub fn init_object2(&self, mc: &Mutation<'gc>, object: BitmapDataObject<'gc>) {
327327
self.0.init_object2(mc, object);
328328
}
329329

@@ -389,7 +389,7 @@ pub struct BitmapRawData<'gc> {
389389
///
390390
/// AVM1 cannot retrieve `BitmapData` back from the display object tree, so
391391
/// this does not need to hold an AVM1 object.
392-
avm2_object: Option<Avm2Object<'gc>>,
392+
avm2_object: Option<BitmapDataObject<'gc>>,
393393

394394
/// A list of display objects that are backed by this BitmapData
395395
display_objects: Vec<DisplayObjectWeak<'gc>>,
@@ -417,7 +417,7 @@ pub enum DirtyState {
417417
}
418418

419419
mod wrapper {
420-
use crate::avm2::{Object as Avm2Object, Value as Avm2Value};
420+
use crate::avm2::object::BitmapDataObject;
421421
use crate::context::RenderContext;
422422
use crate::display_object::DisplayObjectWeak;
423423
use gc_arena::barrier::Write;
@@ -611,7 +611,7 @@ mod wrapper {
611611
self.0.borrow().width
612612
}
613613

614-
pub fn object2(&self) -> Avm2Value<'gc> {
614+
pub fn object2(&self) -> Option<BitmapDataObject<'gc>> {
615615
self.0.borrow().object2()
616616
}
617617

@@ -643,8 +643,8 @@ mod wrapper {
643643
self.0.borrow_mut(mc).dispose();
644644
}
645645

646-
pub fn init_object2(&self, mc: &Mutation<'gc>, object: Avm2Object<'gc>) {
647-
self.0.borrow_mut(mc).avm2_object = Some(object)
646+
pub fn init_object2(&self, mc: &Mutation<'gc>, object: BitmapDataObject<'gc>) {
647+
self.0.borrow_mut(mc).avm2_object = Some(object);
648648
}
649649

650650
pub fn remove_display_object(&self, mc: &Mutation<'gc>, callback: DisplayObjectWeak<'gc>) {
@@ -934,14 +934,12 @@ impl<'gc> BitmapRawData<'gc> {
934934
}
935935
}
936936

937-
pub fn object2(&self) -> Avm2Value<'gc> {
937+
pub fn object2(&self) -> Option<BitmapDataObject<'gc>> {
938938
self.avm2_object
939-
.map(|o| o.into())
940-
.unwrap_or(Avm2Value::Null)
941939
}
942940

943-
pub fn init_object2(&mut self, object: Avm2Object<'gc>) {
944-
self.avm2_object = Some(object)
941+
pub fn init_object2(&mut self, object: BitmapDataObject<'gc>) {
942+
self.avm2_object = Some(object);
945943
}
946944
}
947945

0 commit comments

Comments
 (0)