Skip to content
Merged
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
10 changes: 6 additions & 4 deletions core/src/display_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use ruffle_render::transform::{Transform, TransformStack};
use std::cell::{Cell, Ref, RefCell, RefMut};
use std::fmt::Debug;
use std::hash::Hash;
use std::num::NonZero;
use std::sync::Arc;
use swf::{ColorTransform, Fixed8};

Expand Down Expand Up @@ -162,15 +163,16 @@ impl BitmapCache {
} else {
actual_width < 2880 && actual_height < 2880
};

if renderer.is_offscreen_supported()
&& actual_width > 0
&& actual_height > 0
&& let Some(actual_width) = NonZero::new(actual_width)
&& let Some(actual_height) = NonZero::new(actual_height)
&& acceptable_size
{
let handle = renderer.create_empty_texture(actual_width, actual_height);
self.bitmap = handle.ok().map(|handle| BitmapInfo {
width: actual_width,
height: actual_height,
width: actual_width.get(),
height: actual_height.get(),
handle,
});
} else {
Expand Down
10 changes: 8 additions & 2 deletions render/canvas/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use ruffle_render::transform::Transform;
use ruffle_web_common::{JsError, JsResult};
use std::any::Any;
use std::borrow::Cow;
use std::num::NonZeroU32;
use std::sync::Arc;
use swf::{BlendMode, Color, ColorTransform, Point, Twips};
use wasm_bindgen::{Clamped, JsCast, JsValue};
Expand Down Expand Up @@ -585,8 +586,13 @@ impl RenderBackend for WebCanvasRenderBackend {
Err(Error::Unimplemented("Sync handle resolution".into()))
}

fn create_empty_texture(&mut self, width: u32, height: u32) -> Result<BitmapHandle, Error> {
let bitmap_data = BitmapData::empty(width, height).map_err(Error::JavascriptError)?;
fn create_empty_texture(
&mut self,
width: NonZeroU32,
height: NonZeroU32,
) -> Result<BitmapHandle, Error> {
let bitmap_data =
BitmapData::empty(width.get(), height.get()).map_err(Error::JavascriptError)?;
Ok(BitmapHandle(Arc::new(bitmap_data)))
}
}
Expand Down
7 changes: 6 additions & 1 deletion render/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::any::Any;
use std::borrow::Cow;
use std::cell::RefCell;
use std::fmt::Debug;
use std::num::NonZeroU32;
use std::rc::Rc;
use std::sync::Arc;
use swf::{Color, Rectangle, Twips};
Expand Down Expand Up @@ -76,7 +77,11 @@ pub trait RenderBackend: Any {
cache_entries: Vec<BitmapCacheEntry>,
);

fn create_empty_texture(&mut self, width: u32, height: u32) -> Result<BitmapHandle, Error>;
fn create_empty_texture(
&mut self,
width: NonZeroU32,
height: NonZeroU32,
) -> Result<BitmapHandle, Error>;

fn register_bitmap(&mut self, bitmap: Bitmap<'_>) -> Result<BitmapHandle, Error>;
fn update_texture(
Expand Down
7 changes: 6 additions & 1 deletion render/src/backend/null.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::borrow::Cow;
use std::num::NonZeroU32;
use std::sync::Arc;

use crate::backend::{
Expand Down Expand Up @@ -135,7 +136,11 @@
))
}

fn create_empty_texture(&mut self, _width: u32, _height: u32) -> Result<BitmapHandle, Error> {
fn create_empty_texture(
&mut self,
_width: NonZeroU32,
_height: NonZeroU32,
) -> Result<BitmapHandle, Error> {

Check warning on line 143 in render/src/backend/null.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered lines (139–143)
Ok(BitmapHandle(Arc::new(NullBitmapHandle)))
}
}
3 changes: 0 additions & 3 deletions render/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ pub enum Error {
#[error("Bitmap texture is larger than the rendering device supports")]
TooLarge,

#[error("Bitmap texture has a size of 0 and is invalid")]
InvalidSize,

#[error("Unknown bitmap format")]
UnknownType,

Expand Down
9 changes: 5 additions & 4 deletions render/webgl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use ruffle_render::transform::Transform;
use ruffle_web_common::{JsError, JsResult};
use std::any::Any;
use std::borrow::Cow;
use std::num::NonZeroU32;
use std::sync::Arc;
use swf::{BlendMode, Color, Twips};
use thiserror::Error;
Expand Down Expand Up @@ -1222,8 +1223,8 @@ impl RenderBackend for WebGlRenderBackend {

fn create_empty_texture(
&mut self,
width: u32,
height: u32,
width: NonZeroU32,
height: NonZeroU32,
) -> Result<BitmapHandle, BitmapError> {
let texture = self
.gl
Expand All @@ -1243,8 +1244,8 @@ impl RenderBackend for WebGlRenderBackend {

Ok(BitmapHandle(Arc::new(RegistryData {
gl: self.gl.clone(),
width,
height,
width: width.get(),
height: height.get(),
texture,
})))
}
Expand Down
11 changes: 6 additions & 5 deletions render/wgpu/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use ruffle_render::tessellator::ShapeTessellator;
use std::any::Any;
use std::borrow::Cow;
use std::cell::Cell;
use std::num::NonZeroU32;
use std::sync::Arc;
use swf::Color;
use tracing::instrument;
Expand Down Expand Up @@ -1011,12 +1012,12 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {

fn create_empty_texture(
&mut self,
width: u32,
height: u32,
width: NonZeroU32,
height: NonZeroU32,
) -> Result<BitmapHandle, BitmapError> {
if width == 0 || height == 0 {
return Err(BitmapError::InvalidSize);
}
let width = width.get();
let height = height.get();

if width > self.descriptors.limits.max_texture_dimension_2d
|| height > self.descriptors.limits.max_texture_dimension_2d
{
Expand Down
Loading