Skip to content

Commit

Permalink
Rename Context::begin_frame/end_frame
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Sep 12, 2024
1 parent 43b1808 commit dd433ca
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
45 changes: 29 additions & 16 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ struct ContextImpl {
}

impl ContextImpl {
fn begin_pass_mut(&mut self, mut new_raw_input: RawInput) {
fn begin_pass(&mut self, mut new_raw_input: RawInput) {
let viewport_id = new_raw_input.viewport_id;
let parent_id = new_raw_input
.viewports
Expand Down Expand Up @@ -748,7 +748,7 @@ impl Context {
///
/// Put your widgets into a [`crate::SidePanel`], [`crate::TopBottomPanel`], [`crate::CentralPanel`], [`crate::Window`] or [`crate::Area`].
///
/// Instead of calling `run`, you can alternatively use [`Self::begin_frame`] and [`Context::end_frame`].
/// Instead of calling `run`, you can alternatively use [`Self::begin_pass`] and [`Context::end_pass`].
///
/// ```
/// // One egui context that you keep reusing:
Expand Down Expand Up @@ -788,9 +788,9 @@ impl Context {
output.platform_output.requested_discard = false;
});

self.begin_frame(new_input.take());
self.begin_pass(new_input.take());
run_ui(self);
output.append(self.end_frame());
output.append(self.end_pass());
debug_assert!(0 < output.platform_output.num_completed_passes);

if !output.platform_output.requested_discard {
Expand Down Expand Up @@ -829,23 +829,29 @@ impl Context {
///
/// // Each frame:
/// let input = egui::RawInput::default();
/// ctx.begin_frame(input);
/// ctx.begin_pass(input);
///
/// egui::CentralPanel::default().show(&ctx, |ui| {
/// ui.label("Hello egui!");
/// });
///
/// let full_output = ctx.end_frame();
/// let full_output = ctx.end_pass();
/// // handle full_output
/// ```
pub fn begin_frame(&self, new_input: RawInput) {
pub fn begin_pass(&self, new_input: RawInput) {
crate::profile_function!();

self.write(|ctx| ctx.begin_pass_mut(new_input));
self.write(|ctx| ctx.begin_pass(new_input));

// Plugins run just after the frame has started:
self.read(|ctx| ctx.plugins.clone()).on_begin_pass(self);
}

/// See [`Self::begin_pass`].
#[deprecated = "Renamed begin_pass"]
pub fn begin_frame(&self, new_input: RawInput) {
self.begin_pass(new_input);
}
}

/// ## Borrows parts of [`Context`]
Expand Down Expand Up @@ -946,15 +952,15 @@ impl Context {

/// Read-only access to [`PassState`].
///
/// This is only valid during the call to [`Self::run`] (between [`Self::begin_frame`] and [`Self::end_frame`]).
/// This is only valid during the call to [`Self::run`] (between [`Self::begin_pass`] and [`Self::end_pass`]).
#[inline]
pub(crate) fn pass_state<R>(&self, reader: impl FnOnce(&PassState) -> R) -> R {
self.write(move |ctx| reader(&ctx.viewport().this_pass))
}

/// Read-write access to [`PassState`].
///
/// This is only valid during the call to [`Self::run`] (between [`Self::begin_frame`] and [`Self::end_frame`]).
/// This is only valid during the call to [`Self::run`] (between [`Self::begin_pass`] and [`Self::end_pass`]).
#[inline]
pub(crate) fn pass_state_mut<R>(&self, writer: impl FnOnce(&mut PassState) -> R) -> R {
self.write(move |ctx| writer(&mut ctx.viewport().this_pass))
Expand Down Expand Up @@ -1430,7 +1436,7 @@ impl Context {

/// The current frame number for the current viewport.
///
/// Starts at zero, and is incremented at the end of [`Self::run`] or by [`Self::end_frame`].
/// Starts at zero, and is incremented at the end of [`Self::run`] or by [`Self::end_pass`].
///
/// Between calls to [`Self::run`], this is the frame number of the coming frame.
pub fn frame_nr(&self) -> u64 {
Expand All @@ -1439,7 +1445,7 @@ impl Context {

/// The current frame number.
///
/// Starts at zero, and is incremented at the end of [`Self::run`] or by [`Self::end_frame`].
/// Starts at zero, and is incremented at the end of [`Self::run`] or by [`Self::end_pass`].
///
/// Between calls to [`Self::run`], this is the frame number of the coming frame.
pub fn frame_nr_for(&self, id: ViewportId) -> u64 {
Expand Down Expand Up @@ -2032,9 +2038,9 @@ impl Context {
}

impl Context {
/// Call at the end of each frame if you called [`Context::begin_frame`].
/// Call at the end of each frame if you called [`Context::begin_pass`].
#[must_use]
pub fn end_frame(&self) -> FullOutput {
pub fn end_pass(&self) -> FullOutput {
crate::profile_function!();

if self.options(|o| o.zoom_with_keyboard) {
Expand All @@ -2050,6 +2056,13 @@ impl Context {
self.write(|ctx| ctx.end_pass())
}

/// Call at the end of each frame if you called [`Context::begin_pass`].
#[must_use]
#[deprecated = "Renamed end_pass"]
pub fn end_frame(&self) -> FullOutput {
self.end_pass()
}

/// Called at the end of the pass.
#[cfg(debug_assertions)]
fn debug_painting(&self) {
Expand Down Expand Up @@ -3362,7 +3375,7 @@ impl Context {
///
/// If this is the root viewport, this will return [`ViewportId::ROOT`].
///
/// Don't use this outside of `Self::run`, or after `Self::end_frame`.
/// Don't use this outside of `Self::run`, or after `Self::end_pass`.
pub fn viewport_id(&self) -> ViewportId {
self.read(|ctx| ctx.viewport_id())
}
Expand All @@ -3371,7 +3384,7 @@ impl Context {
///
/// If this is the root viewport, this will return [`ViewportId::ROOT`].
///
/// Don't use this outside of `Self::run`, or after `Self::end_frame`.
/// Don't use this outside of `Self::run`, or after `Self::end_pass`.
pub fn parent_viewport_id(&self) -> ViewportId {
self.read(|ctx| ctx.parent_viewport_id())
}
Expand Down
4 changes: 2 additions & 2 deletions crates/egui_demo_lib/benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {

{
let ctx = egui::Context::default();
ctx.begin_frame(RawInput::default());
ctx.begin_pass(RawInput::default());

egui::CentralPanel::default().show(&ctx, |ui| {
c.bench_function("Painter::rect", |b| {
Expand All @@ -81,7 +81,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
});
});

// Don't call `end_frame` to not have to drain the huge paint list
// Don't call `end_pass` to not have to drain the huge paint list
}

{
Expand Down

0 comments on commit dd433ca

Please sign in to comment.