@@ -39,7 +39,7 @@ use texture_import::SharedTextureHandle;
3939pub ( crate )  use  context:: { CefContext ,  CefContextBuilder ,  InitError } ; 
4040
4141pub ( crate )  trait  CefEventHandler :  Clone  + Send  + Sync  + ' static  { 
42- 	fn  window_size ( & self )  -> WindowSize ; 
42+ 	fn  view_info ( & self )  -> ViewInfo ; 
4343	fn  draw < ' a > ( & self ,  frame_buffer :  FrameBufferRef < ' a > ) ; 
4444	#[ cfg( feature = "accelerated_paint" ) ]  
4545	fn  draw_gpu ( & self ,  shared_texture :  SharedTextureHandle ) ; 
@@ -53,21 +53,45 @@ pub(crate) trait CefEventHandler: Clone + Send + Sync + 'static {
5353} 
5454
5555#[ derive( Clone ,  Copy ) ]  
56- pub ( crate )  struct  WindowSize  { 
57- 	pub ( crate )  width :  usize , 
58- 	pub ( crate )  height :  usize , 
56+ pub ( crate )  struct  ViewInfo  { 
57+ 	width :  usize , 
58+ 	height :  usize , 
59+ 	scale :  f64 , 
5960} 
60- impl  WindowSize  { 
61- 	pub ( crate )  fn  new ( width :  usize ,  height :  usize )  -> Self  { 
62- 		Self  {  width,  height } 
61+ impl  ViewInfo  { 
62+ 	pub ( crate )  fn  new ( )  -> Self  { 
63+ 		Self  {  width :  1 ,  height :  1 ,  scale :  1.0  } 
64+ 	} 
65+ 	pub ( crate )  fn  apply_update ( & mut  self ,  update :  ViewInfoUpdate )  { 
66+ 		match  update { 
67+ 			ViewInfoUpdate :: Size  {  width,  height }  if  width > 0  && height > 0  => { 
68+ 				self . width  = width; 
69+ 				self . height  = height; 
70+ 			} 
71+ 			ViewInfoUpdate :: Scale ( scale)  if  scale > 0.0  => { 
72+ 				self . scale  = scale; 
73+ 			} 
74+ 			_ => { } 
75+ 		} 
76+ 	} 
77+ 	pub ( crate )  fn  scaled_width ( & self )  -> usize  { 
78+ 		( self . width  as  f64  / self . scale ) . round ( )  as  usize 
79+ 	} 
80+ 	pub ( crate )  fn  scaled_height ( & self )  -> usize  { 
81+ 		( self . height  as  f64  / self . scale ) . round ( )  as  usize 
6382	} 
6483} 
65- impl  From < winit :: dpi :: PhysicalSize < u32 > >  for  WindowSize  { 
66- 	fn  from ( size :  winit :: dpi :: PhysicalSize < u32 > )  -> Self  { 
67- 		Self :: new ( size . width as usize ,  size . height as usize ) 
84+ impl  Default  for  ViewInfo  { 
85+ 	fn  default ( )  -> Self  { 
86+ 		Self :: new ( ) 
6887	} 
6988} 
7089
90+ pub ( crate )  enum  ViewInfoUpdate  { 
91+ 	Size  {  width :  usize ,  height :  usize  } , 
92+ 	Scale ( f64 ) , 
93+ } 
94+ 7195#[ derive( Clone ) ]  
7296pub ( crate )  struct  Resource  { 
7397	pub ( crate )  reader :  ResourceReader , 
@@ -93,30 +117,30 @@ impl Read for ResourceReader {
93117pub ( crate )  struct  CefHandler  { 
94118	wgpu_context :  WgpuContext , 
95119	app_event_scheduler :  AppEventScheduler , 
96- 	window_size_receiver :  Arc < Mutex < WindowSizeReceiver > > , 
120+ 	view_info_receiver :  Arc < Mutex < ViewInfoReceiver > > , 
97121} 
98122
99123impl  CefHandler  { 
100- 	pub ( crate )  fn  new ( wgpu_context :  WgpuContext ,  app_event_scheduler :  AppEventScheduler ,  window_size_receiver :  Receiver < WindowSize > )  -> Self  { 
124+ 	pub ( crate )  fn  new ( wgpu_context :  WgpuContext ,  app_event_scheduler :  AppEventScheduler ,  view_info_receiver :  Receiver < ViewInfoUpdate > )  -> Self  { 
101125		Self  { 
102126			wgpu_context, 
103127			app_event_scheduler, 
104- 			window_size_receiver :  Arc :: new ( Mutex :: new ( WindowSizeReceiver :: new ( window_size_receiver ) ) ) , 
128+ 			view_info_receiver :  Arc :: new ( Mutex :: new ( ViewInfoReceiver :: new ( view_info_receiver ) ) ) , 
105129		} 
106130	} 
107131} 
108132
109133impl  CefEventHandler  for  CefHandler  { 
110- 	fn  window_size ( & self )  -> WindowSize  { 
111- 		let  Ok ( mut  guard)  = self . window_size_receiver . lock ( )  else  { 
112- 			tracing:: error!( "Failed to lock window_size_receiver " ) ; 
113- 			return  WindowSize :: new ( 1 , 1 ) ; 
134+ 	fn  view_info ( & self )  -> ViewInfo  { 
135+ 		let  Ok ( mut  guard)  = self . view_info_receiver . lock ( )  else  { 
136+ 			tracing:: error!( "Failed to lock view_info_receiver " ) ; 
137+ 			return  ViewInfo :: new ( ) ; 
114138		} ; 
115- 		let  WindowSizeReceiver  {  receiver,  window_size  }  = & mut  * guard; 
116- 		for  new_window_size  in  receiver. try_iter ( )  { 
117- 			* window_size = new_window_size ; 
139+ 		let  ViewInfoReceiver  {  receiver,  view_info  }  = & mut  * guard; 
140+ 		for  update  in  receiver. try_iter ( )  { 
141+ 			view_info . apply_update ( update ) ; 
118142		} 
119- 		* window_size 
143+ 		* view_info 
120144	} 
121145	fn  draw < ' a > ( & self ,  frame_buffer :  FrameBufferRef < ' a > )  { 
122146		let  width = frame_buffer. width ( )  as  u32 ; 
@@ -246,15 +270,12 @@ impl CefEventHandler for CefHandler {
246270	} 
247271} 
248272
249- struct  WindowSizeReceiver  { 
250- 	window_size : WindowSize , 
251- 	receiver :  Receiver < WindowSize > , 
273+ struct  ViewInfoReceiver  { 
274+ 	view_info : ViewInfo , 
275+ 	receiver :  Receiver < ViewInfoUpdate > , 
252276} 
253- impl  WindowSizeReceiver  { 
254- 	fn  new ( window_size_receiver :  Receiver < WindowSize > )  -> Self  { 
255- 		Self  { 
256- 			window_size :  WindowSize  {  width :  1 ,  height :  1  } , 
257- 			receiver :  window_size_receiver, 
258- 		} 
277+ impl  ViewInfoReceiver  { 
278+ 	fn  new ( receiver :  Receiver < ViewInfoUpdate > )  -> Self  { 
279+ 		Self  {  view_info :  ViewInfo :: new ( ) ,  receiver } 
259280	} 
260281} 
0 commit comments