Skip to content

obs-text: Render only when changed#10735

Open
exeldro wants to merge 1 commit intoobsproject:masterfrom
exeldro:text_render_on_change_only
Open

obs-text: Render only when changed#10735
exeldro wants to merge 1 commit intoobsproject:masterfrom
exeldro:text_render_on_change_only

Conversation

@exeldro
Copy link
Copy Markdown
Contributor

@exeldro exeldro commented May 27, 2024

Description

Render text only when changed

Motivation and Context

Rendering text can take lots of time (in my testing example 86 ms), so in case nothing changed, like for example a obs-websocket request to update the text to the same value, the rendering step can be skipped.

How Has This Been Tested?

On windows 11 by changing a text file without resulting text changes to be rendered and by calling SetInputSettings on obs-websockets

Types of changes

  • Performance enhancement (non-breaking change which improves efficiency)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

Copy link
Copy Markdown
Member

@RytoEX RytoEX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits. Don't know enough about these code changes to make a quick call, so hopefully someone else familiar with them can give it a look.

Comment thread plugins/obs-text/gdiplus/obs-text.cpp
Comment thread plugins/obs-text/gdiplus/obs-text.cpp
@WizardCM WizardCM added kind/bug Categorizes issue or PR as related to a bug. kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. labels Jun 8, 2024
@exeldro exeldro force-pushed the text_render_on_change_only branch from f84ac8f to 046c50c Compare June 8, 2024 23:21
@Warchamp7 Warchamp7 added this to the OBS Studio 32.2 milestone May 6, 2026
Copy link
Copy Markdown
Member

@RytoEX RytoEX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably fine as-is, as we'll be doing a pass with clang-format, but might as well add braces now if time permits.

Comment on lines +800 to +808
if (color != new_color || opacity != new_opacity ||
(gradient && color2 != new_color2) ||
(gradient && opacity2 != new_opacity2) ||
gradient_dir != new_grad_dir || vertical != new_vertical ||
bk_color != new_bk_color || bk_opacity != new_bk_opacity ||
use_extents != new_extents || wrap != new_extents_wrap ||
extents_cx != n_extents_cx || extents_cy != n_extents_cy ||
antialiasing != new_antialiasing)
needs_render = true;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (color != new_color || opacity != new_opacity ||
(gradient && color2 != new_color2) ||
(gradient && opacity2 != new_opacity2) ||
gradient_dir != new_grad_dir || vertical != new_vertical ||
bk_color != new_bk_color || bk_opacity != new_bk_opacity ||
use_extents != new_extents || wrap != new_extents_wrap ||
extents_cx != n_extents_cx || extents_cy != n_extents_cy ||
antialiasing != new_antialiasing)
needs_render = true;
if (color != new_color || opacity != new_opacity ||
(gradient && color2 != new_color2) ||
(gradient && opacity2 != new_opacity2) ||
gradient_dir != new_grad_dir || vertical != new_vertical ||
bk_color != new_bk_color || bk_opacity != new_bk_opacity ||
use_extents != new_extents || wrap != new_extents_wrap ||
extents_cx != n_extents_cx || extents_cy != n_extents_cy ||
antialiasing != new_antialiasing) {
needs_render = true;
}

Comment on lines +852 to +855
if (old_text != text || use_outline != new_outline ||
outline_color != new_o_color || outline_opacity != new_o_opacity ||
outline_size != roundf(float(new_o_size)))
needs_render = true;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (old_text != text || use_outline != new_outline ||
outline_color != new_o_color || outline_opacity != new_o_opacity ||
outline_size != roundf(float(new_o_size)))
needs_render = true;
if (old_text != text || use_outline != new_outline ||
outline_color != new_o_color || outline_opacity != new_o_opacity ||
outline_size != roundf(float(new_o_size))) {
needs_render = true;
}

Comment on lines +886 to +887
if (needs_render)
RenderText();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (needs_render)
RenderText();
if (needs_render) {
RenderText();
}

Comment on lines +911 to +912
if (old_text != text)
RenderText();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (old_text != text)
RenderText();
if (old_text != text) {
RenderText();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. kind/enhancement Enhancements are not bugs or new features but can improve usability or performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants