1- use crate :: { CustomEvent , FrameBuffer } ;
1+ use crate :: {
2+ CustomEvent , FrameBuffer , WgpuContext ,
3+ render:: { FrameBufferRef , GraphicsState } ,
4+ } ;
25use std:: {
36 sync:: { Arc , Mutex , mpsc:: Receiver } ,
47 time:: Instant ,
@@ -14,7 +17,7 @@ use winit::event_loop::EventLoopProxy;
1417
1518pub ( crate ) trait CefEventHandler : Clone {
1619 fn window_size ( & self ) -> WindowSize ;
17- fn draw ( & self , frame_buffer : FrameBuffer ) ;
20+ fn draw < ' a > ( & self , frame_buffer : FrameBufferRef < ' a > ) ;
1821 /// Scheudule the main event loop to run the cef event loop after the timeout
1922 /// [`_cef_browser_process_handler_t::on_schedule_message_pump_work`] for more documentation.
2023 fn schedule_cef_message_loop_work ( & self , scheduled_time : Instant ) ;
@@ -36,6 +39,7 @@ impl WindowSize {
3639pub ( crate ) struct CefHandler {
3740 window_size_receiver : Arc < Mutex < WindowSizeReceiver > > ,
3841 event_loop_proxy : EventLoopProxy < CustomEvent > ,
42+ wgpu_context : WgpuContext ,
3943}
4044struct WindowSizeReceiver {
4145 receiver : Receiver < WindowSize > ,
@@ -50,10 +54,11 @@ impl WindowSizeReceiver {
5054 }
5155}
5256impl CefHandler {
53- pub ( crate ) fn new ( window_size_receiver : Receiver < WindowSize > , event_loop_proxy : EventLoopProxy < CustomEvent > ) -> Self {
57+ pub ( crate ) fn new ( window_size_receiver : Receiver < WindowSize > , event_loop_proxy : EventLoopProxy < CustomEvent > , wgpu_context : WgpuContext ) -> Self {
5458 Self {
5559 window_size_receiver : Arc :: new ( Mutex :: new ( WindowSizeReceiver :: new ( window_size_receiver) ) ) ,
5660 event_loop_proxy,
61+ wgpu_context,
5762 }
5863 }
5964}
@@ -70,8 +75,44 @@ impl CefEventHandler for CefHandler {
7075 }
7176 * window_size
7277 }
73- fn draw ( & self , frame_buffer : FrameBuffer ) {
74- let _ = self . event_loop_proxy . send_event ( CustomEvent :: UiUpdate ( frame_buffer) ) ;
78+ fn draw < ' a > ( & self , frame_buffer : FrameBufferRef < ' a > ) {
79+ let width = frame_buffer. width ( ) as u32 ;
80+ let height = frame_buffer. height ( ) as u32 ;
81+ let texture = self . wgpu_context . device . create_texture ( & wgpu:: TextureDescriptor {
82+ label : Some ( "CEF Texture" ) ,
83+ size : wgpu:: Extent3d {
84+ width,
85+ height,
86+ depth_or_array_layers : 1 ,
87+ } ,
88+ mip_level_count : 1 ,
89+ sample_count : 1 ,
90+ dimension : wgpu:: TextureDimension :: D2 ,
91+ format : wgpu:: TextureFormat :: Bgra8UnormSrgb ,
92+ usage : wgpu:: TextureUsages :: TEXTURE_BINDING | wgpu:: TextureUsages :: COPY_DST ,
93+ view_formats : & [ ] ,
94+ } ) ;
95+ self . wgpu_context . queue . write_texture (
96+ wgpu:: TexelCopyTextureInfo {
97+ texture : & texture,
98+ mip_level : 0 ,
99+ origin : wgpu:: Origin3d :: ZERO ,
100+ aspect : wgpu:: TextureAspect :: All ,
101+ } ,
102+ frame_buffer. buffer ( ) ,
103+ wgpu:: TexelCopyBufferLayout {
104+ offset : 0 ,
105+ bytes_per_row : Some ( 4 * width) ,
106+ rows_per_image : Some ( height) ,
107+ } ,
108+ wgpu:: Extent3d {
109+ width,
110+ height,
111+ depth_or_array_layers : 1 ,
112+ } ,
113+ ) ;
114+
115+ let _ = self . event_loop_proxy . send_event ( CustomEvent :: UiUpdate ( ( texture, width, height) ) ) ;
75116 }
76117
77118 fn schedule_cef_message_loop_work ( & self , scheduled_time : std:: time:: Instant ) {
0 commit comments