Skip to content

Commit

Permalink
core: Place jpegxr texture support behind feature flag (#13348)
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepycatcoding authored Sep 29, 2023
1 parent c3d0540 commit f140e7a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 7 deletions.
3 changes: 2 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ egui_extras = { git = "https://github.com/emilk/egui", rev = "98087029e020a1b2d7
png = { version = "0.17.10", optional = true }
flv-rs = { path = "../flv" }
async-channel = "1.9.0"
jpegxr = { git = "https://github.com/ruffle-rs/jpegxr", branch = "ruffle" }
jpegxr = { git = "https://github.com/ruffle-rs/jpegxr", branch = "ruffle", optional = true }
image = { version = "0.24.7", default-features = false, features = ["tiff"] }

[target.'cfg(not(target_family = "wasm"))'.dependencies.futures]
Expand All @@ -78,6 +78,7 @@ audio = ["dasp"]
known_stubs = ["linkme"]
default_compatibility_rules = []
egui = ["dep:egui", "dep:egui_extras", "png"]
jpegxr = ["dep:jpegxr"]

[build-dependencies]
build_playerglobal = { path = "build_playerglobal" }
18 changes: 15 additions & 3 deletions core/src/avm2/globals/flash/display3D/textures/texture.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::io::Cursor;

use gc_arena::GcCell;
use ruffle_render::atf::ATFTexture;
use ruffle_render::backend::Context3DTextureFormat;

use crate::avm2::object::TextureObject;
Expand Down Expand Up @@ -69,13 +66,28 @@ pub fn do_copy<'gc>(
Ok(())
}

#[cfg(not(feature = "jpegxr"))]
pub(super) fn do_compressed_upload<'gc>(
_: &mut Activation<'_, 'gc>,
_: TextureObject<'gc>,
_: Object<'gc>,
_: usize,
_: bool,
) -> Result<(), Error<'gc>> {
Err("Support for compressed textures not compiled in.".into())
}

#[cfg(feature = "jpegxr")]
pub(super) fn do_compressed_upload<'gc>(
activation: &mut Activation<'_, 'gc>,
texture: TextureObject<'gc>,
data: Object<'gc>,
byte_array_offset: usize,
is_cube: bool,
) -> Result<(), Error<'gc>> {
use ruffle_render::atf::ATFTexture;
use std::io::Cursor;

let atf_texture =
ATFTexture::from_bytes(&data.as_bytearray().unwrap().bytes()[byte_array_offset..])
.expect("Failed to parse ATF texture");
Expand Down
2 changes: 1 addition & 1 deletion desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ embed-resource = "2"
vergen = { version = "8.2.5", features = ["build", "git", "gitcl", "cargo"] }

[features]
default = ["software_video"]
default = ["software_video", "ruffle_core/jpegxr"]

# core features
avm_debug = ["ruffle_core/avm_debug"]
Expand Down
2 changes: 1 addition & 1 deletion tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ url = "2.4.1"
# Enable running image comparison tests. This is off by default,
# since the images we compare against are generated on CI, and may
# not match your local machine's Vulkan version / image output.
imgtests = ["ruffle_video_software"]
imgtests = ["ruffle_video_software", "ruffle_core/jpegxr"]
lzma = ["ruffle_core/lzma"]

[dev-dependencies]
Expand Down
Binary file modified tests/tests/swfs/avm2/stage3d_texture_bytearray/output.expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions tests/tests/swfs/avm2/stage3d_texture_bytearray/test.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
num_frames = 1

[image_comparisons.output]
tolerance = 2

[player_options]
with_renderer = { optional = true, sample_count = 1 }
2 changes: 1 addition & 1 deletion web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ publish = false # This crate is useless alone, people should use the npm package
crate-type = ["cdylib", "rlib"]

[features]
default = ["canvas", "console_error_panic_hook", "webgl", "wgpu-webgl"]
default = ["canvas", "console_error_panic_hook", "webgl", "wgpu-webgl", "ruffle_core/jpegxr"]

# core features
avm_debug = ["ruffle_core/avm_debug"]
Expand Down

0 comments on commit f140e7a

Please sign in to comment.