-
-
Notifications
You must be signed in to change notification settings - Fork 96
Refactor SDL/FreeRTOS implementation to support macOS simulator properly #653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KenVanHoeylandt
wants to merge
2
commits into
main
Choose a base branch
from
macos-simulator-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| #include "sdl_bridge.h" | ||
| #include "sdl_input.h" | ||
|
|
||
| #include <tactility/error.h> | ||
|
|
||
| #include <chrono> | ||
| #include <condition_variable> | ||
| #include <mutex> | ||
|
|
||
| namespace { | ||
|
|
||
| struct PresentJob { | ||
| Device* device; | ||
| void* internal; | ||
| int32_t x_start; | ||
| int32_t y_start; | ||
| int32_t x_end; | ||
| int32_t y_end; | ||
| const void* color_data; | ||
| error_t result; | ||
| }; | ||
|
|
||
| std::mutex job_mutex; | ||
| std::condition_variable job_ready_cv; | ||
| std::condition_variable job_done_cv; | ||
| bool job_pending = false; | ||
| bool job_done = false; | ||
| PresentJob pending_job; | ||
|
|
||
| } | ||
|
|
||
| error_t sdl_bridge_present(Device* device, void* internal, int32_t x_start, int32_t y_start, int32_t x_end, int32_t y_end, const void* color_data) { | ||
| std::unique_lock<std::mutex> lock(job_mutex); | ||
|
|
||
| pending_job = { device, internal, x_start, y_start, x_end, y_end, color_data, ERROR_NONE }; | ||
| job_pending = true; | ||
| job_done = false; | ||
| job_ready_cv.notify_one(); | ||
|
|
||
| job_done_cv.wait(lock, [] { return job_done; }); | ||
| return pending_job.result; | ||
| } | ||
|
|
||
| void sdl_bridge_run_main_loop() { | ||
| while (true) { | ||
| sdl_input_pump(); | ||
|
|
||
| std::unique_lock<std::mutex> lock(job_mutex); | ||
| if (job_ready_cv.wait_for(lock, std::chrono::milliseconds(1), [] { return job_pending; })) { | ||
| PresentJob job = pending_job; | ||
| lock.unlock(); | ||
|
|
||
| job.result = sdl_display_execute_draw_bitmap(job.device, job.internal, job.x_start, job.y_start, job.x_end, job.y_end, job.color_data); | ||
|
|
||
| lock.lock(); | ||
| pending_job.result = job.result; | ||
| job_pending = false; | ||
| job_done = true; | ||
| lock.unlock(); | ||
| job_done_cv.notify_one(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| #pragma once | ||
|
|
||
| #include <tactility/error.h> | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| struct Device; | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Runs forever, pumping SDL input and executing display present jobs submitted via | ||
| * sdl_bridge_present(). Must be called exactly once, from the real OS main thread: macOS requires | ||
| * SDL/Cocoa window creation, event pumping and rendering to happen there, but FreeRTOS tasks | ||
| * (including the lvgl task that owns display flush and indev polling) run on separate pthreads | ||
| * spawned by the FreeRTOS POSIX port, not on that thread. | ||
| */ | ||
| void sdl_bridge_run_main_loop(void); | ||
|
|
||
| /** | ||
| * @brief Hands a display flush off to the main thread and blocks until it has finished copying | ||
| * the pixel data out (see sdl_display_execute_draw_bitmap() in sdl_display.cpp). Called from the | ||
| * lvgl task. Must block: the caller's pixel buffer is single-buffered and gets reused as soon as | ||
| * this returns. | ||
| */ | ||
| error_t sdl_bridge_present(struct Device* device, void* internal, int32_t x_start, int32_t y_start, int32_t x_end, int32_t y_end, const void* color_data); | ||
|
|
||
| /** | ||
| * @brief Implemented in sdl_display.cpp: the actual SDL work behind a display flush (lazy window | ||
| * init on first call, SDL_UpdateTexture, present). Only ever called from sdl_bridge_run_main_loop() | ||
| * on the main thread. | ||
| */ | ||
| error_t sdl_display_execute_draw_bitmap(struct Device* device, void* internal, int32_t x_start, int32_t y_start, int32_t x_end, int32_t y_end, const void* color_data); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.