Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Rename BitmapData->BitmapRawData, wrap it in new BitmapData #18754

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions core/src/avm1/globals/bitmap_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::avm1::globals::color_transform::ColorTransformObject;
use crate::avm1::object::NativeObject;
use crate::avm1::property_decl::{define_properties_on, Declaration};
use crate::avm1::{Activation, Attribute, Error, Object, ScriptObject, TObject, Value};
use crate::bitmap::bitmap_data::{BitmapData, BitmapDataWrapper};
use crate::bitmap::bitmap_data::BitmapData;
use crate::bitmap::bitmap_data::{BitmapDataDrawError, IBitmapDrawable};
use crate::bitmap::bitmap_data::{ChannelOptions, ThresholdOperation};
use crate::bitmap::{is_size_valid, operations};
Expand All @@ -16,7 +16,7 @@ use crate::display_object::DisplayObject;
use crate::string::StringContext;
use crate::swf::BlendMode;
use crate::{avm1_stub, avm_error};
use gc_arena::{GcCell, Mutation};
use gc_arena::Mutation;
use ruffle_render::transform::Transform;

const PROTO_DECLS: &[Declaration] = declare_properties! {
Expand Down Expand Up @@ -70,10 +70,7 @@ fn new_bitmap_data<'gc>(
Attribute::DONT_ENUM | Attribute::DONT_DELETE,
);
}
object.set_native(
gc_context,
NativeObject::BitmapData(BitmapDataWrapper::new(GcCell::new(gc_context, bitmap_data))),
);
object.set_native(gc_context, NativeObject::BitmapData(bitmap_data));
object
}

Expand Down Expand Up @@ -103,13 +100,16 @@ fn constructor<'gc>(
return Ok(Value::Undefined);
}

let bitmap_data = BitmapData::new(width, height, transparency, fill_color);
let bitmap_data = BitmapData::new(
activation.context.gc_context,
width,
height,
transparency,
fill_color,
);
this.set_native(
activation.context.gc_context,
NativeObject::BitmapData(BitmapDataWrapper::new(GcCell::new(
activation.context.gc_context,
bitmap_data,
))),
NativeObject::BitmapData(bitmap_data),
);
Ok(this.into())
}
Expand Down Expand Up @@ -405,7 +405,7 @@ fn clone<'gc>(
return Ok(new_bitmap_data(
activation.context.gc_context,
this.get_local_stored("__proto__", activation, false),
bitmap_data.clone_data(activation.context.renderer),
bitmap_data.clone_data(activation.context.gc_context, activation.context.renderer),
)
.into());
}
Expand Down Expand Up @@ -1464,6 +1464,7 @@ fn compare<'gc>(
}

match operations::compare(
activation.context.gc_context,
activation.context.renderer,
this_bitmap_data,
other_bitmap_data,
Expand Down Expand Up @@ -1505,6 +1506,7 @@ fn load_bitmap<'gc>(

let transparency = true;
let bitmap_data = BitmapData::new_with_pixels(
activation.context.gc_context,
bitmap.width(),
bitmap.height(),
transparency,
Expand Down
4 changes: 2 additions & 2 deletions core/src/avm1/globals/displacement_map_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::avm1::function::{Executable, FunctionObject};
use crate::avm1::object::NativeObject;
use crate::avm1::property_decl::{define_properties_on, Declaration};
use crate::avm1::{Activation, Error, Object, ScriptObject, TObject, Value};
use crate::bitmap::bitmap_data::BitmapDataWrapper;
use crate::bitmap::bitmap_data::BitmapData;
use crate::context::UpdateContext;
use crate::string::{AvmString, FromWStr, StringContext, WStr};
use gc_arena::{Collect, GcCell, Mutation};
Expand Down Expand Up @@ -77,7 +77,7 @@ impl From<Mode> for DisplacementMapFilterMode {
#[derive(Clone, Collect, Debug, Default)]
#[collect(no_drop)]
struct DisplacementMapFilterData<'gc> {
map_bitmap: Option<BitmapDataWrapper<'gc>>,
map_bitmap: Option<BitmapData<'gc>>,
#[collect(require_static)]
map_point: Point<i32>,
component_x: i32,
Expand Down
4 changes: 2 additions & 2 deletions core/src/avm1/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::avm1::globals::xml_socket::XmlSocket;
use crate::avm1::object::array_object::ArrayObject;
use crate::avm1::object::super_object::SuperObject;
use crate::avm1::{Activation, Attribute, Error, ScriptObject, StageObject, Value};
use crate::bitmap::bitmap_data::BitmapDataWrapper;
use crate::bitmap::bitmap_data::BitmapData;
use crate::display_object::DisplayObject;
use crate::display_object::TDisplayObject;
use crate::html::TextFormat;
Expand Down Expand Up @@ -61,7 +61,7 @@ pub enum NativeObject<'gc> {
Transform(TransformObject<'gc>),
TextFormat(Gc<'gc, RefCell<TextFormat>>),
NetStream(NetStream<'gc>),
BitmapData(BitmapDataWrapper<'gc>),
BitmapData(BitmapData<'gc>),
Xml(Xml<'gc>),
XmlNode(XmlNode<'gc>),
SharedObject(GcCell<'gc, SharedObject>),
Expand Down
10 changes: 5 additions & 5 deletions core/src/avm2/globals/flash/display/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ruffle_wstr::WStr;

use crate::avm2::error::make_error_2008;
use crate::avm2::parameters::ParametersExt;
use crate::bitmap::bitmap_data::BitmapDataWrapper;
use crate::bitmap::bitmap_data::BitmapData;
use crate::character::Character;
use crate::display_object::{Bitmap, TDisplayObject};

Expand All @@ -26,7 +26,7 @@ pub fn bitmap_allocator<'gc>(
let orig_class = class;
while let Some(class) = class_def {
if class == bitmap_cls {
let bitmap_data = BitmapDataWrapper::dummy(activation.context.gc_context);
let bitmap_data = BitmapData::dummy(activation.context.gc_context);
let display_object = Bitmap::new_with_bitmap_data(
activation.context.gc_context,
0,
Expand Down Expand Up @@ -58,7 +58,7 @@ pub fn bitmap_allocator<'gc>(
let new_bitmap_data = fill_bitmap_data_from_symbol(activation, &compressed);
let bitmap_data_obj = BitmapDataObject::from_bitmap_data_internal(
activation,
BitmapDataWrapper::dummy(activation.context.gc_context),
BitmapData::dummy(activation.context.gc_context),
bitmapdata_cls,
)?;
bitmap_data_obj.init_bitmap_data(activation.context.gc_context, new_bitmap_data);
Expand Down Expand Up @@ -116,7 +116,7 @@ pub fn get_bitmap_data<'gc>(
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
if let Some(bitmap) = this.as_display_object().and_then(|dobj| dobj.as_bitmap()) {
let mut value = bitmap.bitmap_data_wrapper().object2();
let mut value = bitmap.bitmap_data().object2();

// AS3 expects an unset BitmapData to be null, not 'undefined'
if matches!(value, Value::Undefined) {
Expand All @@ -141,7 +141,7 @@ pub fn set_bitmap_data<'gc>(
bitmap_data.as_bitmap_data().expect("Must be a BitmapData")
} else {
// Passing null results in a dummy BitmapData being set.
BitmapDataWrapper::dummy(activation.gc())
BitmapData::dummy(activation.gc())
};

bitmap.set_bitmap_data(activation.context, bitmap_data);
Expand Down
59 changes: 26 additions & 33 deletions core/src/avm2/globals/flash/display/bitmap_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ use crate::avm2::value::Value;
use crate::avm2::vector::VectorStorage;
use crate::avm2::Error;
use crate::avm2_stub_method;
use crate::bitmap::bitmap_data::{
BitmapData, BitmapDataWrapper, ChannelOptions, ThresholdOperation,
};
use crate::bitmap::bitmap_data::{BitmapData, ChannelOptions, ThresholdOperation};
use crate::bitmap::bitmap_data::{BitmapDataDrawError, IBitmapDrawable};
use crate::bitmap::{is_size_valid, operations};
use crate::character::{Character, CompressedBitmap};
use crate::display_object::TDisplayObject;
use crate::ecma_conversions::round_to_even;
use crate::swf::BlendMode;
use gc_arena::GcCell;
use ruffle_render::filters::Filter;
use ruffle_render::transform::Transform;
use std::str::FromStr;
Expand Down Expand Up @@ -69,21 +66,18 @@ fn get_rectangle_x_y_width_height<'gc>(
pub fn fill_bitmap_data_from_symbol<'gc>(
activation: &mut Activation<'_, 'gc>,
bd: &CompressedBitmap,
) -> BitmapDataWrapper<'gc> {
) -> BitmapData<'gc> {
let bitmap = bd.decode().expect("Failed to decode BitmapData");
let new_bitmap_data = GcCell::new(
BitmapData::new_with_pixels(
activation.context.gc_context,
BitmapData::new_with_pixels(
bitmap.width(),
bitmap.height(),
true,
bitmap
.as_colors()
.map(crate::bitmap::bitmap_data::Color::from)
.collect(),
),
);
BitmapDataWrapper::new(new_bitmap_data)
bitmap.width(),
bitmap.height(),
true,
bitmap
.as_colors()
.map(crate::bitmap::bitmap_data::Color::from)
.collect(),
)
}

/// Implements `flash.display.BitmapData`'s 'init' method (invoked from the AS3 constructor)
Expand All @@ -92,7 +86,7 @@ pub fn init<'gc>(
this: Object<'gc>,
args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
// We set the underlying BitmapData instance - we start out with a dummy BitmapDataWrapper,
// We set the underlying BitmapData instance - we start out with a dummy BitmapData,
// which makes custom classes see a disposed BitmapData before they call super()
let name = this.instance_class().name();
let character = activation
Expand Down Expand Up @@ -140,8 +134,13 @@ pub fn init<'gc>(
)?));
}

let new_bitmap_data = BitmapData::new(width, height, transparency, fill_color);
BitmapDataWrapper::new(GcCell::new(activation.context.gc_context, new_bitmap_data))
BitmapData::new(
activation.context.gc_context,
width,
height,
transparency,
fill_color,
)
};

new_bitmap_data.init_object2(activation.context.gc_context, this);
Expand Down Expand Up @@ -842,7 +841,7 @@ pub fn hit_test<'gc>(
.as_display_object()
.and_then(|dobj| dobj.as_bitmap())
{
let other_bmd = bitmap.bitmap_data_wrapper();
let other_bmd = bitmap.bitmap_data();
other_bmd.check_valid(activation)?;
let second_point = args.get_object(activation, 3, "secondBitmapDataPoint")?;
let second_point = (
Expand Down Expand Up @@ -1192,14 +1191,12 @@ pub fn clone<'gc>(
) -> Result<Value<'gc>, Error<'gc>> {
if let Some(bitmap_data) = this.as_bitmap_data() {
if !bitmap_data.disposed() {
let new_bitmap_data = bitmap_data.clone_data(activation.context.renderer);
let new_bitmap_data =
bitmap_data.clone_data(activation.context.gc_context, activation.context.renderer);

let class = activation.avm2().classes().bitmapdata;
let new_bitmap_data_object = BitmapDataObject::from_bitmap_data_internal(
activation,
BitmapDataWrapper::new(GcCell::new(activation.context.gc_context, new_bitmap_data)),
class,
)?;
let new_bitmap_data_object =
BitmapDataObject::from_bitmap_data_internal(activation, new_bitmap_data, class)?;

return Ok(new_bitmap_data_object.into());
}
Expand Down Expand Up @@ -1457,18 +1454,14 @@ pub fn compare<'gc>(
}

match operations::compare(
activation.context.gc_context,
activation.context.renderer,
this_bitmap_data,
other_bitmap_data,
) {
Some(bitmap_data) => {
let class = activation.avm2().classes().bitmapdata;
Ok(BitmapDataObject::from_bitmap_data_internal(
activation,
BitmapDataWrapper::new(GcCell::new(activation.context.gc_context, bitmap_data)),
class,
)?
.into())
Ok(BitmapDataObject::from_bitmap_data_internal(activation, bitmap_data, class)?.into())
}
None => Ok(EQUIVALENT.into()),
}
Expand Down
8 changes: 2 additions & 6 deletions core/src/avm2/globals/flash/display3D/textures/texture.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use gc_arena::GcCell;

use ruffle_render::backend::Context3DTextureFormat;

use super::atf_jpegxr::do_compressed_upload;
Expand All @@ -11,7 +9,6 @@ use crate::avm2::Value;
use crate::avm2::{Error, Object};
use crate::avm2_stub_method;
use crate::bitmap::bitmap_data::BitmapData;
use crate::bitmap::bitmap_data::BitmapDataWrapper;
use crate::bitmap::bitmap_data::Color;

pub fn do_copy<'gc>(
Expand All @@ -32,7 +29,7 @@ pub fn do_copy<'gc>(
return Ok(());
}

// FIXME - see if we can avoid this intermediate BitmapDataWrapper, and copy
// FIXME - see if we can avoid this intermediate BitmapData, and copy
// directly from a buffer to the target GPU texture
let bitmap_data = match texture.original_format() {
Context3DTextureFormat::Bgra => {
Expand All @@ -51,8 +48,7 @@ pub fn do_copy<'gc>(
})
.collect();

let bitmap_data = BitmapData::new_with_pixels(width, height, true, colors);
BitmapDataWrapper::new(GcCell::new(activation.context.gc_context, bitmap_data))
BitmapData::new_with_pixels(activation.context.gc_context, width, height, true, colors)
}
_ => {
tracing::warn!(
Expand Down
6 changes: 3 additions & 3 deletions core/src/avm2/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::avm2::vtable::{ClassBoundMethod, VTable};
use crate::avm2::Error;
use crate::avm2::Multiname;
use crate::avm2::Namespace;
use crate::bitmap::bitmap_data::BitmapDataWrapper;
use crate::bitmap::bitmap_data::BitmapData;
use crate::display_object::DisplayObject;
use crate::html::TextFormat;
use crate::streams::NetStream;
Expand Down Expand Up @@ -1259,7 +1259,7 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
None
}

fn as_bitmap_data(&self) -> Option<BitmapDataWrapper<'gc>> {
fn as_bitmap_data(&self) -> Option<BitmapData<'gc>> {
None
}

Expand All @@ -1273,7 +1273,7 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
/// This should only be called to initialize the association between an AVM
/// object and it's associated bitmap data. This association should not be
/// reinitialized later.
fn init_bitmap_data(&self, _mc: &Mutation<'gc>, _new_bitmap: BitmapDataWrapper<'gc>) {}
fn init_bitmap_data(&self, _mc: &Mutation<'gc>, _new_bitmap: BitmapData<'gc>) {}

/// Get this objects `DateObject`, if it has one.
fn as_date_object(&self) -> Option<DateObject<'gc>> {
Expand Down
Loading