mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:37:45 +00:00
Userland: Piano: Optimize repaints
The Piano application used to perform very poorly due to unnecessary draw calls. This is solved with two optimziations: 1. Don't draw the widgets as often as possible. The widgets are instead at least updated every 150ms, except for other events. 2. Don't re-draw the entire piano roll sheet. The piano roll background, excluding in-motion objects (notes, the play cursor), is only re-drawn when its "viewport" changes. A minor drawback of this change is that notes will appear on top of the pitch labels if placed at the left edge of the roll. This is IMO acceptable or may be changed by moving the text to the "foreground".
This commit is contained in:
parent
511ffa8d68
commit
c1345bda3e
3 changed files with 79 additions and 19 deletions
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2019-2020, William McPherson <willmcpherson2@gmail.com>
|
||||
* Copyright (c) 2021, kleines Filmröllchen <malu.bertsch@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -64,7 +65,6 @@ int main(int argc, char** argv)
|
|||
while (!Core::EventLoop::current().was_exit_requested()) {
|
||||
track_manager.fill_buffer(buffer);
|
||||
audio->write(reinterpret_cast<u8*>(buffer.data()), buffer_size);
|
||||
Core::EventLoop::current().post_event(main_widget, make<Core::CustomEvent>(0));
|
||||
Core::EventLoop::wake();
|
||||
|
||||
if (need_to_write_wav) {
|
||||
|
@ -84,6 +84,11 @@ int main(int argc, char** argv)
|
|||
});
|
||||
audio_thread->start();
|
||||
|
||||
auto main_widget_updater = Core::Timer::construct(150, [&] {
|
||||
Core::EventLoop::current().post_event(main_widget, make<Core::CustomEvent>(0));
|
||||
});
|
||||
main_widget_updater->start();
|
||||
|
||||
auto menubar = GUI::Menubar::construct();
|
||||
|
||||
auto& app_menu = menubar->add_menu("File");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue