Skip to content

Commit 1c34167

Browse files
committed
Cleanup code
1 parent 731fbf2 commit 1c34167

5 files changed

Lines changed: 10 additions & 86 deletions

File tree

desktop/src/app.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::CustomEvent;
2-
use crate::FrameBuffer;
32
use crate::WindowSize;
43
use crate::render::GraphicsState;
54
use crate::render::WgpuContext;
@@ -23,9 +22,9 @@ pub(crate) struct WinitApp {
2322
pub(crate) cef_context: cef::Context<cef::Initialized>,
2423
pub(crate) window: Option<Arc<Window>>,
2524
cef_schedule: Option<Instant>,
26-
ui_frame_buffer: Option<FrameBuffer>,
25+
_ui_frame_buffer: Option<wgpu::Texture>,
2726
window_size_sender: Sender<WindowSize>,
28-
_viewport_frame_buffer: Option<FrameBuffer>,
27+
_viewport_frame_buffer: Option<wgpu::Texture>,
2928
graphics_state: Option<GraphicsState>,
3029
event_loop_proxy: EventLoopProxy<CustomEvent>,
3130
wgpu_context: WgpuContext,
@@ -38,7 +37,7 @@ impl WinitApp {
3837
window: None,
3938
cef_schedule: Some(Instant::now()),
4039
_viewport_frame_buffer: None,
41-
ui_frame_buffer: None,
40+
_ui_frame_buffer: None,
4241
graphics_state: None,
4342
window_size_sender,
4443
event_loop_proxy,
@@ -50,8 +49,9 @@ impl WinitApp {
5049
impl ApplicationHandler<CustomEvent> for WinitApp {
5150
fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) {
5251
// Set a timeout in case we miss any cef schedule requests
53-
let timeout = Instant::now() + Duration::from_millis(100);
52+
let timeout = Instant::now() + Duration::from_millis(10);
5453
let wait_until = timeout.min(self.cef_schedule.unwrap_or(timeout));
54+
self.cef_context.work();
5555
event_loop.set_control_flow(ControlFlow::WaitUntil(wait_until));
5656
}
5757

@@ -89,18 +89,14 @@ impl ApplicationHandler<CustomEvent> for WinitApp {
8989
graphics_state.bind_texture(&texture);
9090
graphics_state.resize(width, height);
9191
}
92-
// self.ui_frame_buffer = Some(frame_buffer);
9392
if let Some(window) = &self.window {
9493
window.request_redraw();
9594
}
9695
}
9796
CustomEvent::ScheduleBrowserWork(instant) => {
98-
if let Some(graphics_state) = self.graphics_state.as_mut()
99-
&& let Some(frame_buffer) = &self.ui_frame_buffer
100-
&& graphics_state.ui_texture_outdated(frame_buffer)
101-
{
97+
if instant < Instant::now() {
10298
self.cef_context.work();
103-
let _ = self.event_loop_proxy.send_event(CustomEvent::ScheduleBrowserWork(Instant::now() + Duration::from_millis(1)));
99+
let _ = self.event_loop_proxy.send_event(CustomEvent::ScheduleBrowserWork(Instant::now() + Duration::from_millis(10)));
104100
}
105101
self.cef_schedule = Some(instant);
106102
}

desktop/src/cef.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::{
2-
CustomEvent, FrameBuffer, WgpuContext,
3-
render::{FrameBufferRef, GraphicsState},
4-
};
1+
use crate::{CustomEvent, WgpuContext, render::FrameBufferRef};
52
use std::{
63
sync::{Arc, Mutex, mpsc::Receiver},
74
time::Instant,

desktop/src/cef/internal/render_handler.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use cef::rc::{Rc, RcImpl};
22
use cef::sys::{_cef_render_handler_t, cef_base_ref_counted_t};
33
use cef::{Browser, ImplRenderHandler, PaintElementType, Rect, WrapRenderHandler};
44

5-
use crate::FrameBuffer;
65
use crate::cef::CefEventHandler;
76
use crate::render::FrameBufferRef;
87

desktop/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod cef;
99
use cef::{Setup, WindowSize};
1010

1111
mod render;
12-
use render::{FrameBuffer, WgpuContext};
12+
use render::WgpuContext;
1313

1414
mod app;
1515
use app::WinitApp;

desktop/src/render.rs

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,6 @@ use std::sync::Arc;
33
use thiserror::Error;
44
use 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-
216
pub(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)]
10659
pub(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

Comments
 (0)