[refactor] rename 'PaintBatches' to 'PaintJobs'
This commit is contained in:
parent
7565210b2d
commit
fccd135254
7 changed files with 45 additions and 43 deletions
|
@ -6,7 +6,7 @@ use crate::{layout::align_rect, paint::*, *};
|
|||
|
||||
#[derive(Clone, Copy, Default)]
|
||||
struct PaintStats {
|
||||
num_batches: usize,
|
||||
num_jobs: usize,
|
||||
num_primitives: usize,
|
||||
num_vertices: usize,
|
||||
num_triangles: usize,
|
||||
|
@ -168,15 +168,15 @@ impl Context {
|
|||
/// Call at the end of each frame.
|
||||
/// Returns what has happened this frame (`Output`) as well as what you need to paint.
|
||||
#[must_use]
|
||||
pub fn end_frame(&self) -> (Output, PaintBatches) {
|
||||
pub fn end_frame(&self) -> (Output, PaintJobs) {
|
||||
if self.input.wants_repaint() {
|
||||
self.request_repaint();
|
||||
}
|
||||
|
||||
self.memory().end_frame();
|
||||
let output: Output = std::mem::take(&mut self.output());
|
||||
let paint_batches = self.paint();
|
||||
(output, paint_batches)
|
||||
let paint_jobs = self.paint();
|
||||
(output, paint_jobs)
|
||||
}
|
||||
|
||||
fn drain_paint_lists(&self) -> Vec<(Rect, PaintCmd)> {
|
||||
|
@ -184,27 +184,27 @@ impl Context {
|
|||
self.graphics().drain(memory.areas.order()).collect()
|
||||
}
|
||||
|
||||
fn paint(&self) -> PaintBatches {
|
||||
fn paint(&self) -> PaintJobs {
|
||||
let mut paint_options = *self.paint_options.lock();
|
||||
paint_options.aa_size = 1.0 / self.pixels_per_point();
|
||||
paint_options.aa_size *= 1.5; // Looks better, but TODO: should not be needed
|
||||
let paint_commands = self.drain_paint_lists();
|
||||
let num_primitives = paint_commands.len();
|
||||
let batches =
|
||||
let paint_jobs =
|
||||
mesher::paint_commands_into_triangles(paint_options, self.fonts(), paint_commands);
|
||||
|
||||
{
|
||||
let mut stats = PaintStats::default();
|
||||
stats.num_batches = batches.len();
|
||||
stats.num_jobs = paint_jobs.len();
|
||||
stats.num_primitives = num_primitives;
|
||||
for (_, triangles) in &batches {
|
||||
for (_, triangles) in &paint_jobs {
|
||||
stats.num_vertices += triangles.vertices.len();
|
||||
stats.num_triangles += triangles.indices.len() / 3;
|
||||
}
|
||||
*self.paint_stats.lock() = stats;
|
||||
}
|
||||
|
||||
batches
|
||||
paint_jobs
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
@ -639,7 +639,7 @@ impl paint::PaintOptions {
|
|||
|
||||
impl PaintStats {
|
||||
pub fn ui(&self, ui: &mut Ui) {
|
||||
ui.add(label!("Batches: {}", self.num_batches))
|
||||
ui.add(label!("Jobs: {}", self.num_jobs))
|
||||
.tooltip_text("Number of separate clip rectanlges");
|
||||
ui.add(label!("Primitives: {}", self.num_primitives))
|
||||
.tooltip_text("Boxes, circles, text areas etc");
|
||||
|
|
|
@ -9,6 +9,6 @@ pub use {
|
|||
color::Color,
|
||||
command::{LineStyle, PaintCmd},
|
||||
fonts::{FontDefinitions, Fonts, TextStyle},
|
||||
mesher::{PaintBatches, PaintOptions, Path, Triangles, Vertex},
|
||||
mesher::{PaintJobs, PaintOptions, Path, Triangles, Vertex},
|
||||
texture_atlas::Texture,
|
||||
};
|
||||
|
|
|
@ -33,8 +33,10 @@ pub struct Triangles {
|
|||
pub vertices: Vec<Vertex>,
|
||||
}
|
||||
|
||||
pub type PaintJob = (Rect, Triangles);
|
||||
|
||||
/// Grouped by clip rectangles, in pixel coordinates
|
||||
pub type PaintBatches = Vec<(Rect, Triangles)>;
|
||||
pub type PaintJobs = Vec<PaintJob>;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
@ -680,20 +682,20 @@ pub fn paint_commands_into_triangles(
|
|||
) -> Vec<(Rect, Triangles)> {
|
||||
let mut reused_path = Path::default();
|
||||
|
||||
let mut batches = PaintBatches::default();
|
||||
let mut jobs = PaintJobs::default();
|
||||
for (clip_rect, cmd) in commands {
|
||||
// TODO: cull(clip_rect, cmd)
|
||||
|
||||
if batches.is_empty() || batches.last().unwrap().0 != clip_rect {
|
||||
batches.push((clip_rect, Triangles::default()));
|
||||
if jobs.is_empty() || jobs.last().unwrap().0 != clip_rect {
|
||||
jobs.push((clip_rect, Triangles::default()));
|
||||
}
|
||||
|
||||
let out = &mut batches.last_mut().unwrap().1;
|
||||
let out = &mut jobs.last_mut().unwrap().1;
|
||||
paint_command_into_triangles(&mut reused_path, options, fonts, cmd, out);
|
||||
}
|
||||
|
||||
if options.debug_paint_clip_rects {
|
||||
for (clip_rect, triangles) in &mut batches {
|
||||
for (clip_rect, triangles) in &mut jobs {
|
||||
paint_command_into_triangles(
|
||||
&mut reused_path,
|
||||
options,
|
||||
|
@ -709,5 +711,5 @@ pub fn paint_commands_into_triangles(
|
|||
}
|
||||
}
|
||||
|
||||
batches
|
||||
jobs
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use {
|
||||
egui::{
|
||||
math::clamp,
|
||||
paint::{PaintBatches, Triangles},
|
||||
paint::{PaintJobs, Triangles},
|
||||
Rect,
|
||||
},
|
||||
glium::{implement_vertex, index::PrimitiveType, program, texture, uniform, Frame, Surface},
|
||||
|
@ -181,24 +181,24 @@ impl Painter {
|
|||
self.current_texture_id = Some(texture.id);
|
||||
}
|
||||
|
||||
pub fn paint_batches(
|
||||
pub fn paint_jobs(
|
||||
&mut self,
|
||||
display: &glium::Display,
|
||||
batches: PaintBatches,
|
||||
jobs: PaintJobs,
|
||||
texture: &egui::Texture,
|
||||
) {
|
||||
self.upload_texture(display, texture);
|
||||
|
||||
let mut target = display.draw();
|
||||
target.clear_color(0.0, 0.0, 0.0, 0.0);
|
||||
for (clip_rect, triangles) in batches {
|
||||
self.paint_batch(&mut target, display, clip_rect, &triangles, texture)
|
||||
for (clip_rect, triangles) in jobs {
|
||||
self.paint_job(&mut target, display, clip_rect, &triangles, texture)
|
||||
}
|
||||
target.finish().unwrap();
|
||||
}
|
||||
|
||||
#[inline(never)] // Easier profiling
|
||||
fn paint_batch(
|
||||
fn paint_job(
|
||||
&mut self,
|
||||
target: &mut Frame,
|
||||
display: &glium::Display,
|
||||
|
|
|
@ -74,27 +74,27 @@ impl Backend {
|
|||
self.ctx.begin_frame(raw_input)
|
||||
}
|
||||
|
||||
pub fn end_frame(&mut self) -> Result<(egui::Output, egui::PaintBatches), JsValue> {
|
||||
pub fn end_frame(&mut self) -> Result<(egui::Output, egui::PaintJobs), JsValue> {
|
||||
let frame_start = self
|
||||
.frame_start
|
||||
.take()
|
||||
.expect("unmatched calls to begin_frame/end_frame");
|
||||
|
||||
let (output, batches) = self.ctx.end_frame();
|
||||
let (output, paint_jobs) = self.ctx.end_frame();
|
||||
|
||||
self.auto_save();
|
||||
|
||||
let now = now_sec();
|
||||
self.frame_times.add(now, (now - frame_start) as f32);
|
||||
|
||||
Ok((output, batches))
|
||||
Ok((output, paint_jobs))
|
||||
}
|
||||
|
||||
pub fn paint(&mut self, batches: egui::PaintBatches) -> Result<(), JsValue> {
|
||||
pub fn paint(&mut self, paint_jobs: egui::PaintJobs) -> Result<(), JsValue> {
|
||||
let bg_color = egui::color::TRANSPARENT; // Use background css color.
|
||||
self.painter.paint_batches(
|
||||
self.painter.paint_jobs(
|
||||
bg_color,
|
||||
batches,
|
||||
paint_jobs,
|
||||
self.ctx.texture(),
|
||||
self.ctx.pixels_per_point(),
|
||||
)
|
||||
|
@ -175,7 +175,7 @@ impl AppRunner {
|
|||
self.backend.canvas_id()
|
||||
}
|
||||
|
||||
pub fn logic(&mut self) -> Result<(egui::Output, egui::PaintBatches), JsValue> {
|
||||
pub fn logic(&mut self) -> Result<(egui::Output, egui::PaintJobs), JsValue> {
|
||||
resize_to_screen_size(self.backend.canvas_id());
|
||||
|
||||
let raw_input = self.web_input.new_frame();
|
||||
|
@ -186,13 +186,13 @@ impl AppRunner {
|
|||
|
||||
let mut ui = self.backend.begin_frame(raw_input);
|
||||
self.app.ui(&mut ui, &mut self.backend, &info);
|
||||
let (output, batches) = self.backend.end_frame()?;
|
||||
let (output, paint_jobs) = self.backend.end_frame()?;
|
||||
handle_output(&output);
|
||||
Ok((output, batches))
|
||||
Ok((output, paint_jobs))
|
||||
}
|
||||
|
||||
pub fn paint(&mut self, batches: egui::PaintBatches) -> Result<(), JsValue> {
|
||||
self.backend.paint(batches)
|
||||
pub fn paint(&mut self, paint_jobs: egui::PaintJobs) -> Result<(), JsValue> {
|
||||
self.backend.paint(paint_jobs)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -414,8 +414,8 @@ fn paint_and_schedule(runner_ref: AppRunnerRef) -> Result<(), JsValue> {
|
|||
let mut runner_lock = runner_ref.0.lock();
|
||||
if runner_lock.backend.run_mode() == RunMode::Continuous || runner_lock.needs_repaint {
|
||||
runner_lock.needs_repaint = false;
|
||||
let (output, batches) = runner_lock.logic()?;
|
||||
runner_lock.paint(batches)?;
|
||||
let (output, paint_jobs) = runner_lock.logic()?;
|
||||
runner_lock.paint(paint_jobs)?;
|
||||
runner_lock.needs_repaint = output.needs_repaint;
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -6,7 +6,7 @@ use {
|
|||
|
||||
use egui::{
|
||||
math::clamp,
|
||||
paint::{Color, PaintBatches, Texture, Triangles},
|
||||
paint::{Color, PaintJobs, Texture, Triangles},
|
||||
vec2,
|
||||
};
|
||||
|
||||
|
@ -149,10 +149,10 @@ impl Painter {
|
|||
self.current_texture_id = Some(texture.id);
|
||||
}
|
||||
|
||||
pub fn paint_batches(
|
||||
pub fn paint_jobs(
|
||||
&mut self,
|
||||
bg_color: Color,
|
||||
batches: PaintBatches,
|
||||
jobs: PaintJobs,
|
||||
texture: &Texture,
|
||||
pixels_per_point: f32,
|
||||
) -> Result<(), JsValue> {
|
||||
|
@ -205,7 +205,7 @@ impl Painter {
|
|||
);
|
||||
gl.clear(Gl::COLOR_BUFFER_BIT);
|
||||
|
||||
for (clip_rect, triangles) in batches {
|
||||
for (clip_rect, triangles) in jobs {
|
||||
let clip_min_x = pixels_per_point * clip_rect.min.x;
|
||||
let clip_min_y = pixels_per_point * clip_rect.min.y;
|
||||
let clip_max_x = pixels_per_point * clip_rect.max.x;
|
||||
|
|
|
@ -135,14 +135,14 @@ fn main() {
|
|||
.text_style(TextStyle::Monospace),
|
||||
);
|
||||
|
||||
let (output, paint_batches) = ctx.end_frame();
|
||||
let (output, paint_jobs) = ctx.end_frame();
|
||||
|
||||
frame_times.add(
|
||||
raw_input.time,
|
||||
(Instant::now() - egui_start).as_secs_f64() as f32,
|
||||
);
|
||||
|
||||
painter.paint_batches(&display, paint_batches, ctx.texture());
|
||||
painter.paint_jobs(&display, paint_jobs, ctx.texture());
|
||||
egui_glium::handle_output(output, &display, clipboard.as_mut());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue