render: Make RenderBackend::update_texture() take a Bitmap (like register_bitmap())
This commit is contained in:
parent
c9a2c636c9
commit
493971ab8a
|
@ -602,7 +602,16 @@ impl<'gc> BitmapData<'gc> {
|
|||
let handle = self.bitmap_handle(renderer).unwrap();
|
||||
match &self.dirty_state {
|
||||
DirtyState::CpuModified(region) => {
|
||||
if let Err(e) = renderer.update_texture(&handle, self.pixels_rgba(), *region) {
|
||||
if let Err(e) = renderer.update_texture(
|
||||
&handle,
|
||||
Bitmap::new(
|
||||
self.width(),
|
||||
self.height(),
|
||||
BitmapFormat::Rgba,
|
||||
self.pixels_rgba(),
|
||||
),
|
||||
*region,
|
||||
) {
|
||||
tracing::error!("Failed to update dirty bitmap {:?}: {:?}", handle, e);
|
||||
}
|
||||
self.dirty_state = DirtyState::Clean;
|
||||
|
|
|
@ -4,7 +4,7 @@ use ruffle_render::backend::{
|
|||
Context3D, RenderBackend, ShapeHandle, ShapeHandleImpl, ViewportDimensions,
|
||||
};
|
||||
use ruffle_render::bitmap::{
|
||||
Bitmap, BitmapFormat, BitmapHandle, BitmapHandleImpl, BitmapSource, PixelRegion, SyncHandle,
|
||||
Bitmap, BitmapHandle, BitmapHandleImpl, BitmapSource, PixelRegion, SyncHandle,
|
||||
};
|
||||
use ruffle_render::commands::{CommandHandler, CommandList};
|
||||
use ruffle_render::error::Error;
|
||||
|
@ -467,17 +467,11 @@ impl RenderBackend for WebCanvasRenderBackend {
|
|||
fn update_texture(
|
||||
&mut self,
|
||||
handle: &BitmapHandle,
|
||||
rgba: Vec<u8>,
|
||||
bitmap: Bitmap,
|
||||
_region: PixelRegion,
|
||||
) -> Result<(), Error> {
|
||||
let data = as_bitmap_data(handle);
|
||||
data.update_pixels(Bitmap::new(
|
||||
data.bitmap.width(),
|
||||
data.bitmap.height(),
|
||||
BitmapFormat::Rgba,
|
||||
rgba,
|
||||
))
|
||||
.map_err(Error::JavascriptError)?;
|
||||
data.update_pixels(bitmap).map_err(Error::JavascriptError)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -58,8 +58,8 @@ pub trait RenderBackend: Downcast {
|
|||
fn register_bitmap(&mut self, bitmap: Bitmap) -> Result<BitmapHandle, Error>;
|
||||
fn update_texture(
|
||||
&mut self,
|
||||
bitmap: &BitmapHandle,
|
||||
rgba: Vec<u8>,
|
||||
handle: &BitmapHandle,
|
||||
bitmap: Bitmap,
|
||||
region: PixelRegion,
|
||||
) -> Result<(), Error>;
|
||||
|
||||
|
|
|
@ -74,8 +74,8 @@ impl RenderBackend for NullRenderer {
|
|||
|
||||
fn update_texture(
|
||||
&mut self,
|
||||
_bitmap: &BitmapHandle,
|
||||
_rgba: Vec<u8>,
|
||||
_handle: &BitmapHandle,
|
||||
_bitmap: Bitmap,
|
||||
_region: PixelRegion,
|
||||
) -> Result<(), Error> {
|
||||
Ok(())
|
||||
|
|
|
@ -1033,25 +1033,29 @@ impl RenderBackend for WebGlRenderBackend {
|
|||
fn update_texture(
|
||||
&mut self,
|
||||
handle: &BitmapHandle,
|
||||
rgba: Vec<u8>,
|
||||
bitmap: Bitmap,
|
||||
_region: PixelRegion,
|
||||
) -> Result<(), BitmapError> {
|
||||
let data = as_registry_data(handle);
|
||||
let texture = &data.texture;
|
||||
let texture = &as_registry_data(handle).texture;
|
||||
|
||||
self.gl.bind_texture(Gl::TEXTURE_2D, Some(texture));
|
||||
|
||||
let (format, bitmap) = match bitmap.format() {
|
||||
BitmapFormat::Rgb | BitmapFormat::Yuv420p => (Gl::RGB, bitmap.to_rgb()),
|
||||
BitmapFormat::Rgba | BitmapFormat::Yuva420p => (Gl::RGBA, bitmap.to_rgba()),
|
||||
};
|
||||
|
||||
self.gl
|
||||
.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_u8_array(
|
||||
Gl::TEXTURE_2D,
|
||||
0,
|
||||
Gl::RGBA as i32,
|
||||
data.bitmap.width() as i32,
|
||||
data.bitmap.height() as i32,
|
||||
format as i32,
|
||||
bitmap.width() as i32,
|
||||
bitmap.height() as i32,
|
||||
0,
|
||||
Gl::RGBA,
|
||||
format,
|
||||
Gl::UNSIGNED_BYTE,
|
||||
Some(&rgba),
|
||||
Some(bitmap.data()),
|
||||
)
|
||||
.into_js_result()
|
||||
.map_err(|e| BitmapError::JavascriptError(e.into()))?;
|
||||
|
|
|
@ -515,16 +515,17 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
|
|||
fn update_texture(
|
||||
&mut self,
|
||||
handle: &BitmapHandle,
|
||||
rgba: Vec<u8>,
|
||||
bitmap: Bitmap,
|
||||
region: PixelRegion,
|
||||
) -> Result<(), BitmapError> {
|
||||
let texture = as_texture(handle);
|
||||
|
||||
let extent = wgpu::Extent3d {
|
||||
width: region.width(),
|
||||
height: region.height(),
|
||||
width: bitmap.width(),
|
||||
height: bitmap.height(),
|
||||
depth_or_array_layers: 1,
|
||||
};
|
||||
let bitmap = bitmap.to_rgba();
|
||||
|
||||
self.descriptors.queue.write_texture(
|
||||
wgpu::ImageCopyTexture {
|
||||
|
@ -537,8 +538,7 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
|
|||
},
|
||||
aspect: wgpu::TextureAspect::All,
|
||||
},
|
||||
&rgba[(region.y_min * texture.width * 4) as usize
|
||||
..(region.y_max * texture.width * 4) as usize],
|
||||
bitmap.data(),
|
||||
wgpu::ImageDataLayout {
|
||||
offset: (region.x_min * 4) as wgpu::BufferAddress,
|
||||
bytes_per_row: NonZeroU32::new(4 * texture.width),
|
||||
|
|
|
@ -81,7 +81,12 @@ impl VideoBackend for SoftwareVideoBackend {
|
|||
let handle = if let Some(bitmap) = stream.bitmap.clone() {
|
||||
renderer.update_texture(
|
||||
&bitmap,
|
||||
frame.rgba,
|
||||
Bitmap::new(
|
||||
frame.width.into(),
|
||||
frame.height.into(),
|
||||
BitmapFormat::Rgba,
|
||||
frame.rgba,
|
||||
),
|
||||
PixelRegion::for_whole_size(frame.width.into(), frame.height.into()),
|
||||
)?;
|
||||
bitmap
|
||||
|
|
Loading…
Reference in New Issue