diff --git a/devices/video/display.h b/devices/video/display.h index 435b329..fc9f737 100644 --- a/devices/video/display.h +++ b/devices/video/display.h @@ -41,10 +41,13 @@ public: // Clears the display void blank(); - void update(std::function convert_fb_cb, bool draw_hw_cursor, int cursor_x, int cursor_y); + void update(std::function convert_fb_cb, + std::function cursor_ovl_cb, + bool draw_hw_cursor, int cursor_x, int cursor_y); void handle_events(const WindowEvent& wnd_event); - void setup_hw_cursor(std::function draw_hw_cursor, int cursor_width, int cursor_height); + void setup_hw_cursor(std::function draw_hw_cursor, + int cursor_width, int cursor_height); private: class Impl; // Holds private fields std::unique_ptr impl; diff --git a/devices/video/display_sdl.cpp b/devices/video/display_sdl.cpp index 4476a73..17df446 100644 --- a/devices/video/display_sdl.cpp +++ b/devices/video/display_sdl.cpp @@ -38,21 +38,17 @@ Display::Display(): impl(std::make_unique()) { } Display::~Display() { - if (impl->cursor_texture) { + if (impl->cursor_texture) SDL_DestroyTexture(impl->cursor_texture); - } - if (impl->disp_texture) { + if (impl->disp_texture) SDL_DestroyTexture(impl->disp_texture); - } - if (impl->renderer) { + if (impl->renderer) SDL_DestroyRenderer(impl->renderer); - } - if (impl->display_wnd) { + if (impl->display_wnd) SDL_DestroyWindow(impl->display_wnd); - } } bool Display::configure(int width, int height) { @@ -68,14 +64,12 @@ bool Display::configure(int width, int height) { ); impl->disp_wnd_id = SDL_GetWindowID(impl->display_wnd); - if (impl->display_wnd == NULL) { + if (impl->display_wnd == NULL) ABORT_F("Display: SDL_CreateWindow failed with %s", SDL_GetError()); - } impl->renderer = SDL_CreateRenderer(impl->display_wnd, -1, SDL_RENDERER_ACCELERATED); - if (impl->renderer == NULL) { + if (impl->renderer == NULL) ABORT_F("Display: SDL_CreateRenderer failed with %s", SDL_GetError()); - } is_initialization = true; } else { // resize display window @@ -83,9 +77,8 @@ bool Display::configure(int width, int height) { impl->resizing = true; } - if (impl->disp_texture) { + if (impl->disp_texture) SDL_DestroyTexture(impl->disp_texture); - } impl->disp_texture = SDL_CreateTexture( impl->renderer, @@ -94,9 +87,8 @@ bool Display::configure(int width, int height) { width, height ); - if (impl->disp_texture == NULL) { + if (impl->disp_texture == NULL) ABORT_F("Display: SDL_CreateTexture failed with %s", SDL_GetError()); - } return is_initialization; } @@ -114,6 +106,7 @@ void Display::blank() { } void Display::update(std::function convert_fb_cb, + std::function cursor_ovl_cb, bool draw_hw_cursor, int cursor_x, int cursor_y) { if (impl->resizing) return; @@ -126,6 +119,10 @@ void Display::update(std::function conver // texture update callback to get ARGB data from guest framebuffer convert_fb_cb(dst_buf, dst_pitch); + // overlay cursor data if requested + if (cursor_ovl_cb != nullptr) + cursor_ovl_cb(dst_buf, dst_pitch); + SDL_UnlockTexture(impl->disp_texture); SDL_RenderClear(impl->renderer); SDL_RenderCopy(impl->renderer, impl->disp_texture, NULL, NULL); @@ -145,9 +142,8 @@ void Display::setup_hw_cursor(std::functioncursor_texture) { + if (impl->cursor_texture) SDL_DestroyTexture(impl->cursor_texture); - } impl->cursor_texture = SDL_CreateTexture( impl->renderer, @@ -156,9 +152,8 @@ void Display::setup_hw_cursor(std::functioncursor_texture == NULL) { + if (impl->cursor_texture == NULL) ABORT_F("SDL_CreateTexture for HW cursor failed with %s", SDL_GetError()); - } SDL_LockTexture(impl->cursor_texture, NULL, (void **)&dst_buf, &dst_pitch); SDL_SetTextureBlendMode(impl->cursor_texture, SDL_BLENDMODE_BLEND); diff --git a/devices/video/videoctrl.cpp b/devices/video/videoctrl.cpp index 0a08284..9aadac9 100644 --- a/devices/video/videoctrl.cpp +++ b/devices/video/videoctrl.cpp @@ -74,7 +74,7 @@ void VideoCtrlBase::update_screen() } this->display.update( - this->convert_fb_cb, + this->convert_fb_cb, this->cursor_ovl_cb, this->cursor_on, cursor_x, cursor_y); } diff --git a/devices/video/videoctrl.h b/devices/video/videoctrl.h index 650c782..e9a3ca3 100644 --- a/devices/video/videoctrl.h +++ b/devices/video/videoctrl.h @@ -101,7 +101,8 @@ protected: this->int_ctrl->ack_int(this->irq_id, irq_line_state); }; - std::function convert_fb_cb; + std::function convert_fb_cb = nullptr; + std::function cursor_ovl_cb = nullptr; private: Display display;