@@ -3,21 +3,6 @@ use std::sync::Arc;
33use thiserror:: Error ;
44use winit:: window:: Window ;
55
6- pub ( crate ) struct FrameBuffer {
7- buffer : Vec < u8 > ,
8- width : usize ,
9- height : usize ,
10- }
11- impl std:: fmt:: Debug for FrameBuffer {
12- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
13- f. debug_struct ( "FrameBuffer" )
14- . field ( "width" , & self . width )
15- . field ( "height" , & self . height )
16- . field ( "len" , & self . buffer . len ( ) )
17- . finish ( )
18- }
19- }
20-
216pub ( crate ) struct FrameBufferRef < ' a > {
227 buffer : & ' a [ u8 ] ,
238 width : usize ,
@@ -70,38 +55,6 @@ pub(crate) enum FrameBufferError {
7055 InvalidSize { buffer_size : usize , expected_size : usize , width : usize , height : usize } ,
7156}
7257
73- impl FrameBuffer {
74- pub ( crate ) fn new ( buffer : Vec < u8 > , width : usize , height : usize ) -> Result < Self , FrameBufferError > {
75- let fb = Self { buffer, width, height } ;
76- fb. validate_size ( ) ?;
77- Ok ( fb)
78- }
79-
80- pub ( crate ) fn buffer ( & self ) -> & [ u8 ] {
81- & self . buffer
82- }
83-
84- pub ( crate ) fn width ( & self ) -> usize {
85- self . width
86- }
87-
88- pub ( crate ) fn height ( & self ) -> usize {
89- self . height
90- }
91-
92- fn validate_size ( & self ) -> Result < ( ) , FrameBufferError > {
93- if self . buffer . len ( ) != self . width * self . height * 4 {
94- Err ( FrameBufferError :: InvalidSize {
95- buffer_size : self . buffer . len ( ) ,
96- expected_size : self . width * self . height * 4 ,
97- width : self . width ,
98- height : self . height ,
99- } )
100- } else {
101- Ok ( ( ) )
102- }
103- }
104- }
10558#[ derive( Debug , Clone ) ]
10659pub ( crate ) struct WgpuContext {
10760 pub ( crate ) device : wgpu:: Device ,
@@ -265,38 +218,17 @@ impl GraphicsState {
265218 }
266219 }
267220
268- pub ( crate ) fn ui_texture_outdated ( & self , frame_buffer : & FrameBuffer ) -> bool {
269- let width = frame_buffer. width ( ) as u32 ;
270- let height = frame_buffer. height ( ) as u32 ;
271-
272- self . config . width != width || self . config . height != height
273- }
274-
275221 pub ( crate ) fn resize ( & mut self , width : u32 , height : u32 ) {
276222 if width > 0 && height > 0 && ( self . config . width != width || self . config . height != height) {
277223 self . config . width = width;
278224 self . config . height = height;
279225 self . surface . configure ( & self . context . device , & self . config ) ;
280- // let texture = self.context.device.create_texture(&wgpu::TextureDescriptor {
281- // label: Some("CEF Texture"),
282- // size: wgpu::Extent3d {
283- // width,
284- // height,
285- // depth_or_array_layers: 1,
286- // },
287- // mip_level_count: 1,
288- // sample_count: 1,
289- // dimension: wgpu::TextureDimension::D2,
290- // format: wgpu::TextureFormat::Bgra8UnormSrgb,
291- // usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
292- // view_formats: &[],
293- // });
294- // self.texture = Some(texture);
295226 }
296227 }
297228
298229 pub ( crate ) fn bind_texture ( & mut self , texture : & wgpu:: Texture ) {
299230 let bind_group = self . create_bindgroup ( texture) ;
231+ self . texture = Some ( texture. clone ( ) ) ;
300232
301233 self . bind_group = Some ( bind_group) ;
302234 }
0 commit comments