render: Use Rc<> for wgpu device and queue, so we can reuse them
This commit is contained in:
parent
1effedde2c
commit
1bde973615
|
@ -600,7 +600,7 @@ name = "exporter"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"image 0.23.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"image 0.23.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"indicatif 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"indicatif 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -11,6 +11,7 @@ use ruffle_render_wgpu::WgpuRenderBackend;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fs::create_dir_all;
|
use std::fs::create_dir_all;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::rc::Rc;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use walkdir::{DirEntry, WalkDir};
|
use walkdir::{DirEntry, WalkDir};
|
||||||
|
|
||||||
|
@ -38,19 +39,14 @@ struct Opt {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn take_screenshot(
|
fn take_screenshot(
|
||||||
adapter: &wgpu::Adapter,
|
device: Rc<wgpu::Device>,
|
||||||
|
queue: Rc<wgpu::Queue>,
|
||||||
swf_path: &Path,
|
swf_path: &Path,
|
||||||
frames: u32,
|
frames: u32,
|
||||||
progress: &Option<ProgressBar>,
|
progress: &Option<ProgressBar>,
|
||||||
) -> Result<Vec<RgbaImage>, Box<dyn std::error::Error>> {
|
) -> Result<Vec<RgbaImage>, Box<dyn std::error::Error>> {
|
||||||
let movie = SwfMovie::from_path(&swf_path)?;
|
let movie = SwfMovie::from_path(&swf_path)?;
|
||||||
|
|
||||||
let (device, queue) = block_on(adapter.request_device(&wgpu::DeviceDescriptor {
|
|
||||||
extensions: wgpu::Extensions {
|
|
||||||
anisotropic_filtering: false,
|
|
||||||
},
|
|
||||||
limits: wgpu::Limits::default(),
|
|
||||||
}));
|
|
||||||
let target = TextureTarget::new(&device, (movie.width(), movie.height()));
|
let target = TextureTarget::new(&device, (movie.width(), movie.height()));
|
||||||
let player = Player::new(
|
let player = Player::new(
|
||||||
Box::new(WgpuRenderBackend::new(device, queue, target)?),
|
Box::new(WgpuRenderBackend::new(device, queue, target)?),
|
||||||
|
@ -124,7 +120,8 @@ fn find_files(root: &Path, with_progress: bool) -> Vec<DirEntry> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn capture_single_swf(
|
fn capture_single_swf(
|
||||||
adapter: wgpu::Adapter,
|
device: Rc<wgpu::Device>,
|
||||||
|
queue: Rc<wgpu::Queue>,
|
||||||
swf: &Path,
|
swf: &Path,
|
||||||
frames: u32,
|
frames: u32,
|
||||||
output: Option<PathBuf>,
|
output: Option<PathBuf>,
|
||||||
|
@ -159,7 +156,7 @@ fn capture_single_swf(
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let frames = take_screenshot(&adapter, &swf, frames, &progress)?;
|
let frames = take_screenshot(device, queue, &swf, frames, &progress)?;
|
||||||
|
|
||||||
if let Some(progress) = &progress {
|
if let Some(progress) = &progress {
|
||||||
progress.set_message(&swf.file_stem().unwrap().to_string_lossy());
|
progress.set_message(&swf.file_stem().unwrap().to_string_lossy());
|
||||||
|
@ -200,7 +197,8 @@ fn capture_single_swf(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn capture_multiple_swfs(
|
fn capture_multiple_swfs(
|
||||||
adapter: wgpu::Adapter,
|
device: Rc<wgpu::Device>,
|
||||||
|
queue: Rc<wgpu::Queue>,
|
||||||
directory: &Path,
|
directory: &Path,
|
||||||
frames: u32,
|
frames: u32,
|
||||||
output: &Path,
|
output: &Path,
|
||||||
|
@ -223,7 +221,13 @@ fn capture_multiple_swfs(
|
||||||
};
|
};
|
||||||
|
|
||||||
for file in &files {
|
for file in &files {
|
||||||
let frames = take_screenshot(&adapter, &file.path(), frames, &progress)?;
|
let frames = take_screenshot(
|
||||||
|
device.clone(),
|
||||||
|
queue.clone(),
|
||||||
|
&file.path(),
|
||||||
|
frames,
|
||||||
|
&progress,
|
||||||
|
)?;
|
||||||
|
|
||||||
if let Some(progress) = &progress {
|
if let Some(progress) = &progress {
|
||||||
progress.set_message(&file.path().file_stem().unwrap().to_string_lossy());
|
progress.set_message(&file.path().file_stem().unwrap().to_string_lossy());
|
||||||
|
@ -293,10 +297,31 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
"This tool requires hardware acceleration, but no compatible graphics device was found."
|
"This tool requires hardware acceleration, but no compatible graphics device was found."
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
let (device, queue) = block_on(adapter.request_device(&wgpu::DeviceDescriptor {
|
||||||
|
extensions: wgpu::Extensions {
|
||||||
|
anisotropic_filtering: false,
|
||||||
|
},
|
||||||
|
limits: wgpu::Limits::default(),
|
||||||
|
}));
|
||||||
|
|
||||||
if opt.swf.is_file() {
|
if opt.swf.is_file() {
|
||||||
capture_single_swf(adapter, &opt.swf, opt.frames, opt.output_path, !opt.silent)?;
|
capture_single_swf(
|
||||||
|
Rc::new(device),
|
||||||
|
Rc::new(queue),
|
||||||
|
&opt.swf,
|
||||||
|
opt.frames,
|
||||||
|
opt.output_path,
|
||||||
|
!opt.silent,
|
||||||
|
)?;
|
||||||
} else if let Some(output) = opt.output_path {
|
} else if let Some(output) = opt.output_path {
|
||||||
capture_multiple_swfs(adapter, &opt.swf, opt.frames, &output, !opt.silent)?;
|
capture_multiple_swfs(
|
||||||
|
Rc::new(device),
|
||||||
|
Rc::new(queue),
|
||||||
|
&opt.swf,
|
||||||
|
opt.frames,
|
||||||
|
&output,
|
||||||
|
!opt.silent,
|
||||||
|
)?;
|
||||||
} else {
|
} else {
|
||||||
return Err("Output directory is required when exporting multiple files.".into());
|
return Err("Output directory is required when exporting multiple files.".into());
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ use crate::utils::{
|
||||||
};
|
};
|
||||||
use ruffle_core::color_transform::ColorTransform;
|
use ruffle_core::color_transform::ColorTransform;
|
||||||
use std::mem::replace;
|
use std::mem::replace;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
type Error = Box<dyn std::error::Error>;
|
type Error = Box<dyn std::error::Error>;
|
||||||
|
|
||||||
|
@ -35,8 +36,8 @@ mod shapes;
|
||||||
pub mod target;
|
pub mod target;
|
||||||
|
|
||||||
pub struct WgpuRenderBackend<T: RenderTarget> {
|
pub struct WgpuRenderBackend<T: RenderTarget> {
|
||||||
device: wgpu::Device,
|
device: Rc<wgpu::Device>,
|
||||||
queue: wgpu::Queue,
|
queue: Rc<wgpu::Queue>,
|
||||||
target: T,
|
target: T,
|
||||||
msaa_sample_count: u32,
|
msaa_sample_count: u32,
|
||||||
pipelines: Pipelines,
|
pipelines: Pipelines,
|
||||||
|
@ -137,12 +138,12 @@ impl WgpuRenderBackend<SwapChainTarget> {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let target = SwapChainTarget::new(window, size, &device);
|
let target = SwapChainTarget::new(window, size, &device);
|
||||||
Self::new(device, queue, target)
|
Self::new(Rc::new(device), Rc::new(queue), target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: RenderTarget> WgpuRenderBackend<T> {
|
impl<T: RenderTarget> WgpuRenderBackend<T> {
|
||||||
pub fn new(device: wgpu::Device, queue: wgpu::Queue, target: T) -> Result<Self, Error> {
|
pub fn new(device: Rc<wgpu::Device>, queue: Rc<wgpu::Queue>, target: T) -> Result<Self, Error> {
|
||||||
// TODO: Allow this to be set from command line/settings file.
|
// TODO: Allow this to be set from command line/settings file.
|
||||||
let msaa_sample_count = 4;
|
let msaa_sample_count = 4;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue