|
1 | 1 | #include <devices/video/display.h>
|
2 | 2 | #include <loguru.hpp>
|
| 3 | +#include <emscripten.h> |
3 | 4 |
|
4 |
| -class Display::Impl { |
| 5 | +class Display::Impl |
| 6 | +{ |
5 | 7 | public:
|
| 8 | + std::unique_ptr<uint8_t[]> browser_framebuffer; |
| 9 | + int browser_framebuffer_size; |
| 10 | + int browser_framebuffer_pitch; |
6 | 11 | };
|
7 | 12 |
|
8 |
| -Display::Display(): impl(std::make_unique<Impl>()) { |
9 |
| - LOG_F(INFO, "Display::Display()"); |
| 13 | +Display::Display(): impl(std::make_unique<Impl>()) |
| 14 | +{ |
| 15 | + // No-op in JS |
10 | 16 | }
|
11 | 17 |
|
12 | 18 | Display::~Display() {
|
13 |
| - LOG_F(INFO, "Display::!Display()"); |
| 19 | + // No-op in JS |
14 | 20 | }
|
15 | 21 |
|
16 |
| -bool Display::configure(int width, int height) { |
17 |
| - LOG_F(INFO, "Display::configure(%d, %d)", width, height); |
| 22 | +bool Display::configure(int width, int height) |
| 23 | +{ |
| 24 | + impl->browser_framebuffer_pitch = width * 4; |
| 25 | + impl->browser_framebuffer_size = height * impl->browser_framebuffer_pitch; |
| 26 | + impl->browser_framebuffer = std::make_unique<uint8_t[]>(impl->browser_framebuffer_size); |
| 27 | + EM_ASM_({ workerApi.didOpenVideo($0, $1); }, width, height); |
18 | 28 | return true;
|
19 | 29 | }
|
20 | 30 |
|
21 |
| -void Display::handle_events(const WindowEvent& wnd_event) { |
22 |
| - LOG_F(INFO, "Display::handle_events()"); |
| 31 | +void Display::handle_events(const WindowEvent& wnd_event) |
| 32 | +{ |
| 33 | + // No-op in JS |
23 | 34 | }
|
24 | 35 |
|
25 |
| -void Display::blank() { |
26 |
| - LOG_F(INFO, "Display::blank()"); |
| 36 | +void Display::blank() |
| 37 | +{ |
| 38 | + // Replace contents with opaque black. |
| 39 | + uint8_t *browser_framebuffer = impl->browser_framebuffer.get(); |
| 40 | + int browser_framebuffer_size = impl->browser_framebuffer_size; |
| 41 | + for (int i = 0; i < browser_framebuffer_size; i += 4) { |
| 42 | + browser_framebuffer[i] = 0x00; |
| 43 | + browser_framebuffer[i + 1] = 0x00; |
| 44 | + browser_framebuffer[i + 2] = 0x00; |
| 45 | + browser_framebuffer[i + 3] = 0xff; |
| 46 | + } |
| 47 | + EM_ASM_({ workerApi.blit($0, $1); }, browser_framebuffer, browser_framebuffer_size); |
27 | 48 | }
|
28 | 49 |
|
29 |
| -void Display::update(std::function<void(uint8_t *dst_buf, int dst_pitch)> convert_fb_cb, bool draw_hw_cursor, int cursor_x, int cursor_y) { |
30 |
| - LOG_F(INFO, "Display::update()"); |
| 50 | +void Display::update(std::function<void(uint8_t *dst_buf, int dst_pitch)> convert_fb_cb, bool draw_hw_cursor, int cursor_x, int cursor_y) |
| 51 | +{ |
| 52 | + convert_fb_cb(impl->browser_framebuffer.get(), impl->browser_framebuffer_pitch); |
| 53 | + // TODO: has contents and avoid sending framebuffer if unchanged |
| 54 | + EM_ASM_({ workerApi.blit($0, $1); }, impl->browser_framebuffer.get(), impl->browser_framebuffer_size); |
31 | 55 | }
|
32 | 56 |
|
33 |
| -void Display::setup_hw_cursor(std::function<void(uint8_t *dst_buf, int dst_pitch)> draw_hw_cursor, int cursor_width, int cursor_height) { |
| 57 | +void Display::setup_hw_cursor(std::function<void(uint8_t *dst_buf, int dst_pitch)> draw_hw_cursor, int cursor_width, int cursor_height) |
| 58 | +{ |
34 | 59 | LOG_F(INFO, "Display::setup_hw_cursor()");
|
35 | 60 | }
|
0 commit comments