1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 14:50:03 -04:00

Put everything in Context behind the same Mutex (#1050)

* Move all interior mutability from Context to CtxRef and make it a handle
* Rename `CtxRef` to `Context`
* The old `Context` is now `ContextImpl` and is non-pub
* Add benchmark Painter::rect

Co-authored-by: Daniel Keller <dklr433@gmail.com>
This commit is contained in:
Emil Ernerfeldt
2022-01-10 23:13:10 +01:00
committed by GitHub
parent 225d2b506d
commit d5673412dd
75 changed files with 550 additions and 495 deletions

View File

@@ -4,16 +4,16 @@ use egui::epaint::TextShape;
use egui_demo_lib::LOREM_IPSUM_LONG;
pub fn criterion_benchmark(c: &mut Criterion) {
let raw_input = egui::RawInput::default();
use egui::RawInput;
{
let mut ctx = egui::CtxRef::default();
let ctx = egui::Context::default();
let mut demo_windows = egui_demo_lib::DemoWindows::default();
// The most end-to-end benchmark.
c.bench_function("demo_with_tessellate__realistic", |b| {
b.iter(|| {
let (_output, shapes) = ctx.run(raw_input.clone(), |ctx| {
let (_output, shapes) = ctx.run(RawInput::default(), |ctx| {
demo_windows.ui(ctx);
});
ctx.tessellate(shapes)
@@ -22,13 +22,13 @@ pub fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("demo_no_tessellate", |b| {
b.iter(|| {
ctx.run(raw_input.clone(), |ctx| {
ctx.run(RawInput::default(), |ctx| {
demo_windows.ui(ctx);
})
})
});
let (_output, shapes) = ctx.run(raw_input.clone(), |ctx| {
let (_output, shapes) = ctx.run(RawInput::default(), |ctx| {
demo_windows.ui(ctx);
});
c.bench_function("demo_only_tessellate", |b| {
@@ -37,12 +37,12 @@ pub fn criterion_benchmark(c: &mut Criterion) {
}
if false {
let mut ctx = egui::CtxRef::default();
let ctx = egui::Context::default();
ctx.memory().set_everything_is_visible(true); // give us everything
let mut demo_windows = egui_demo_lib::DemoWindows::default();
c.bench_function("demo_full_no_tessellate", |b| {
b.iter(|| {
ctx.run(raw_input.clone(), |ctx| {
ctx.run(RawInput::default(), |ctx| {
demo_windows.ui(ctx);
})
})
@@ -50,8 +50,8 @@ pub fn criterion_benchmark(c: &mut Criterion) {
}
{
let mut ctx = egui::CtxRef::default();
let _ = ctx.run(raw_input, |ctx| {
let ctx = egui::Context::default();
let _ = ctx.run(RawInput::default(), |ctx| {
egui::CentralPanel::default().show(ctx, |ui| {
c.bench_function("label &str", |b| {
b.iter(|| {
@@ -67,6 +67,23 @@ pub fn criterion_benchmark(c: &mut Criterion) {
});
}
{
let ctx = egui::Context::default();
ctx.begin_frame(RawInput::default());
egui::CentralPanel::default().show(&ctx, |ui| {
c.bench_function("Painter::rect", |b| {
let painter = ui.painter();
let rect = ui.max_rect();
b.iter(|| {
painter.rect(rect, 2.0, egui::Color32::RED, (1.0, egui::Color32::WHITE));
})
});
});
// Don't call `end_frame` to not have to drain the huge paint list
}
{
let pixels_per_point = 1.0;
let wrap_width = 512.0;