2021-11-09 12:40:13 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
2023-04-01 15:38:11 +00:00
|
|
|
Copyright (C) 2018-23 divingkatae and maximum
|
2021-11-09 12:40:13 +00:00
|
|
|
(theweirdo) spatium
|
|
|
|
|
|
|
|
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2024-03-08 07:23:58 +00:00
|
|
|
/** @file Video Controller base class implementation. */
|
2021-11-09 12:40:13 +00:00
|
|
|
|
2023-07-31 01:34:02 +00:00
|
|
|
#include <core/timermanager.h>
|
2023-11-03 07:21:33 +00:00
|
|
|
#include <devices/common/hwinterrupt.h>
|
2023-04-01 15:38:11 +00:00
|
|
|
#include <devices/video/videoctrl.h>
|
|
|
|
#include <memaccess.h>
|
2021-11-09 12:40:13 +00:00
|
|
|
|
|
|
|
#include <cinttypes>
|
|
|
|
|
2021-12-07 21:47:25 +00:00
|
|
|
VideoCtrlBase::VideoCtrlBase(int width, int height)
|
2021-11-09 12:40:13 +00:00
|
|
|
{
|
2023-07-27 00:40:32 +00:00
|
|
|
EventManager::get_instance()->add_window_handler(this, &VideoCtrlBase::handle_events);
|
2023-04-01 15:38:11 +00:00
|
|
|
|
|
|
|
this->create_display_window(width, height);
|
|
|
|
}
|
2021-11-09 12:40:13 +00:00
|
|
|
|
2023-04-01 15:38:11 +00:00
|
|
|
VideoCtrlBase::~VideoCtrlBase()
|
|
|
|
{
|
2024-03-08 07:23:58 +00:00
|
|
|
this->stop_refresh_task();
|
2023-04-01 15:38:11 +00:00
|
|
|
}
|
2021-11-09 12:40:13 +00:00
|
|
|
|
2023-07-27 00:40:32 +00:00
|
|
|
void VideoCtrlBase::handle_events(const WindowEvent& wnd_event) {
|
Make Emscripten build not depend on SDL2 or cubeb
While Emscripten has an SDL compabtility layer, it assumes that the
code is executing in the main browser process (and thus has access to
them DOM). The Infinite Mac project runs emulators in a worker thread
(for better performance) and has a custom API for the display, sound,
input, etc. Similarly, it does not need the cross-platform sound support
from cubeb, there there is a sound API as well.
This commit makes SDL (*_sdl.cpp) and cubeb-based (*_cubeb.cpp) code be
skipped when targeting Emscripten, and instead *_js.cpp files are used
instead (this is the cross-platform convention used by Chromium[^1], and
could be extended for other targets).
For hostevents.cpp and soundserver.cpp the entire file was replaced,
whereas for videoctrl.cpp there was enough shared logic that it was
kept, and the platform-specific bits were moved behind a Display class
that can have per-platform implementations. For cases where we need
additional private fields in the platform-specific classes, we use
a PIMPL pattern.
The *_js.cpp files with implementations are not included in this
commit, since they are closely tied to the Infinite Mac project, and
will live in its fork of DingusPPC.
[^1]: https://www.chromium.org/developers/design-documents/conventions-and-patterns-for-multi-platform-development/
2023-09-04 00:59:35 +00:00
|
|
|
this->display.handle_events(wnd_event);
|
2023-07-27 00:40:32 +00:00
|
|
|
}
|
|
|
|
|
Make Emscripten build not depend on SDL2 or cubeb
While Emscripten has an SDL compabtility layer, it assumes that the
code is executing in the main browser process (and thus has access to
them DOM). The Infinite Mac project runs emulators in a worker thread
(for better performance) and has a custom API for the display, sound,
input, etc. Similarly, it does not need the cross-platform sound support
from cubeb, there there is a sound API as well.
This commit makes SDL (*_sdl.cpp) and cubeb-based (*_cubeb.cpp) code be
skipped when targeting Emscripten, and instead *_js.cpp files are used
instead (this is the cross-platform convention used by Chromium[^1], and
could be extended for other targets).
For hostevents.cpp and soundserver.cpp the entire file was replaced,
whereas for videoctrl.cpp there was enough shared logic that it was
kept, and the platform-specific bits were moved behind a Display class
that can have per-platform implementations. For cases where we need
additional private fields in the platform-specific classes, we use
a PIMPL pattern.
The *_js.cpp files with implementations are not included in this
commit, since they are closely tied to the Infinite Mac project, and
will live in its fork of DingusPPC.
[^1]: https://www.chromium.org/developers/design-documents/conventions-and-patterns-for-multi-platform-development/
2023-09-04 00:59:35 +00:00
|
|
|
// TODO: consider renaming, since it's not always a window
|
2023-04-01 15:38:11 +00:00
|
|
|
void VideoCtrlBase::create_display_window(int width, int height)
|
|
|
|
{
|
Make Emscripten build not depend on SDL2 or cubeb
While Emscripten has an SDL compabtility layer, it assumes that the
code is executing in the main browser process (and thus has access to
them DOM). The Infinite Mac project runs emulators in a worker thread
(for better performance) and has a custom API for the display, sound,
input, etc. Similarly, it does not need the cross-platform sound support
from cubeb, there there is a sound API as well.
This commit makes SDL (*_sdl.cpp) and cubeb-based (*_cubeb.cpp) code be
skipped when targeting Emscripten, and instead *_js.cpp files are used
instead (this is the cross-platform convention used by Chromium[^1], and
could be extended for other targets).
For hostevents.cpp and soundserver.cpp the entire file was replaced,
whereas for videoctrl.cpp there was enough shared logic that it was
kept, and the platform-specific bits were moved behind a Display class
that can have per-platform implementations. For cases where we need
additional private fields in the platform-specific classes, we use
a PIMPL pattern.
The *_js.cpp files with implementations are not included in this
commit, since they are closely tied to the Infinite Mac project, and
will live in its fork of DingusPPC.
[^1]: https://www.chromium.org/developers/design-documents/conventions-and-patterns-for-multi-platform-development/
2023-09-04 00:59:35 +00:00
|
|
|
bool is_initialization = this->display.configure(width, height);
|
|
|
|
if (is_initialization) {
|
2023-04-01 15:38:11 +00:00
|
|
|
this->blank_on = true; // TODO: should be true!
|
|
|
|
this->blank_display();
|
2021-11-09 12:40:13 +00:00
|
|
|
}
|
|
|
|
|
2023-04-01 15:38:11 +00:00
|
|
|
this->active_width = width;
|
|
|
|
this->active_height = height;
|
2021-11-09 12:40:13 +00:00
|
|
|
}
|
|
|
|
|
2023-04-01 15:38:11 +00:00
|
|
|
void VideoCtrlBase::blank_display() {
|
Make Emscripten build not depend on SDL2 or cubeb
While Emscripten has an SDL compabtility layer, it assumes that the
code is executing in the main browser process (and thus has access to
them DOM). The Infinite Mac project runs emulators in a worker thread
(for better performance) and has a custom API for the display, sound,
input, etc. Similarly, it does not need the cross-platform sound support
from cubeb, there there is a sound API as well.
This commit makes SDL (*_sdl.cpp) and cubeb-based (*_cubeb.cpp) code be
skipped when targeting Emscripten, and instead *_js.cpp files are used
instead (this is the cross-platform convention used by Chromium[^1], and
could be extended for other targets).
For hostevents.cpp and soundserver.cpp the entire file was replaced,
whereas for videoctrl.cpp there was enough shared logic that it was
kept, and the platform-specific bits were moved behind a Display class
that can have per-platform implementations. For cases where we need
additional private fields in the platform-specific classes, we use
a PIMPL pattern.
The *_js.cpp files with implementations are not included in this
commit, since they are closely tied to the Infinite Mac project, and
will live in its fork of DingusPPC.
[^1]: https://www.chromium.org/developers/design-documents/conventions-and-patterns-for-multi-platform-development/
2023-09-04 00:59:35 +00:00
|
|
|
this->display.blank();
|
2021-11-09 12:40:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoCtrlBase::update_screen()
|
|
|
|
{
|
2023-04-01 15:38:11 +00:00
|
|
|
if (this->blank_on) {
|
Make Emscripten build not depend on SDL2 or cubeb
While Emscripten has an SDL compabtility layer, it assumes that the
code is executing in the main browser process (and thus has access to
them DOM). The Infinite Mac project runs emulators in a worker thread
(for better performance) and has a custom API for the display, sound,
input, etc. Similarly, it does not need the cross-platform sound support
from cubeb, there there is a sound API as well.
This commit makes SDL (*_sdl.cpp) and cubeb-based (*_cubeb.cpp) code be
skipped when targeting Emscripten, and instead *_js.cpp files are used
instead (this is the cross-platform convention used by Chromium[^1], and
could be extended for other targets).
For hostevents.cpp and soundserver.cpp the entire file was replaced,
whereas for videoctrl.cpp there was enough shared logic that it was
kept, and the platform-specific bits were moved behind a Display class
that can have per-platform implementations. For cases where we need
additional private fields in the platform-specific classes, we use
a PIMPL pattern.
The *_js.cpp files with implementations are not included in this
commit, since they are closely tied to the Infinite Mac project, and
will live in its fork of DingusPPC.
[^1]: https://www.chromium.org/developers/design-documents/conventions-and-patterns-for-multi-platform-development/
2023-09-04 00:59:35 +00:00
|
|
|
this->display.blank();
|
2023-04-01 15:38:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Make Emscripten build not depend on SDL2 or cubeb
While Emscripten has an SDL compabtility layer, it assumes that the
code is executing in the main browser process (and thus has access to
them DOM). The Infinite Mac project runs emulators in a worker thread
(for better performance) and has a custom API for the display, sound,
input, etc. Similarly, it does not need the cross-platform sound support
from cubeb, there there is a sound API as well.
This commit makes SDL (*_sdl.cpp) and cubeb-based (*_cubeb.cpp) code be
skipped when targeting Emscripten, and instead *_js.cpp files are used
instead (this is the cross-platform convention used by Chromium[^1], and
could be extended for other targets).
For hostevents.cpp and soundserver.cpp the entire file was replaced,
whereas for videoctrl.cpp there was enough shared logic that it was
kept, and the platform-specific bits were moved behind a Display class
that can have per-platform implementations. For cases where we need
additional private fields in the platform-specific classes, we use
a PIMPL pattern.
The *_js.cpp files with implementations are not included in this
commit, since they are closely tied to the Infinite Mac project, and
will live in its fork of DingusPPC.
[^1]: https://www.chromium.org/developers/design-documents/conventions-and-patterns-for-multi-platform-development/
2023-09-04 00:59:35 +00:00
|
|
|
int cursor_x = 0;
|
|
|
|
int cursor_y = 0;
|
2023-04-01 23:56:24 +00:00
|
|
|
if (this->cursor_on) {
|
Make Emscripten build not depend on SDL2 or cubeb
While Emscripten has an SDL compabtility layer, it assumes that the
code is executing in the main browser process (and thus has access to
them DOM). The Infinite Mac project runs emulators in a worker thread
(for better performance) and has a custom API for the display, sound,
input, etc. Similarly, it does not need the cross-platform sound support
from cubeb, there there is a sound API as well.
This commit makes SDL (*_sdl.cpp) and cubeb-based (*_cubeb.cpp) code be
skipped when targeting Emscripten, and instead *_js.cpp files are used
instead (this is the cross-platform convention used by Chromium[^1], and
could be extended for other targets).
For hostevents.cpp and soundserver.cpp the entire file was replaced,
whereas for videoctrl.cpp there was enough shared logic that it was
kept, and the platform-specific bits were moved behind a Display class
that can have per-platform implementations. For cases where we need
additional private fields in the platform-specific classes, we use
a PIMPL pattern.
The *_js.cpp files with implementations are not included in this
commit, since they are closely tied to the Infinite Mac project, and
will live in its fork of DingusPPC.
[^1]: https://www.chromium.org/developers/design-documents/conventions-and-patterns-for-multi-platform-development/
2023-09-04 00:59:35 +00:00
|
|
|
this->get_cursor_position(cursor_x, cursor_y);
|
2023-04-01 23:56:24 +00:00
|
|
|
}
|
2021-11-09 12:40:13 +00:00
|
|
|
|
Make Emscripten build not depend on SDL2 or cubeb
While Emscripten has an SDL compabtility layer, it assumes that the
code is executing in the main browser process (and thus has access to
them DOM). The Infinite Mac project runs emulators in a worker thread
(for better performance) and has a custom API for the display, sound,
input, etc. Similarly, it does not need the cross-platform sound support
from cubeb, there there is a sound API as well.
This commit makes SDL (*_sdl.cpp) and cubeb-based (*_cubeb.cpp) code be
skipped when targeting Emscripten, and instead *_js.cpp files are used
instead (this is the cross-platform convention used by Chromium[^1], and
could be extended for other targets).
For hostevents.cpp and soundserver.cpp the entire file was replaced,
whereas for videoctrl.cpp there was enough shared logic that it was
kept, and the platform-specific bits were moved behind a Display class
that can have per-platform implementations. For cases where we need
additional private fields in the platform-specific classes, we use
a PIMPL pattern.
The *_js.cpp files with implementations are not included in this
commit, since they are closely tied to the Infinite Mac project, and
will live in its fork of DingusPPC.
[^1]: https://www.chromium.org/developers/design-documents/conventions-and-patterns-for-multi-platform-development/
2023-09-04 00:59:35 +00:00
|
|
|
this->display.update(
|
2024-01-19 22:41:10 +00:00
|
|
|
this->convert_fb_cb, this->cursor_ovl_cb,
|
Make Emscripten build not depend on SDL2 or cubeb
While Emscripten has an SDL compabtility layer, it assumes that the
code is executing in the main browser process (and thus has access to
them DOM). The Infinite Mac project runs emulators in a worker thread
(for better performance) and has a custom API for the display, sound,
input, etc. Similarly, it does not need the cross-platform sound support
from cubeb, there there is a sound API as well.
This commit makes SDL (*_sdl.cpp) and cubeb-based (*_cubeb.cpp) code be
skipped when targeting Emscripten, and instead *_js.cpp files are used
instead (this is the cross-platform convention used by Chromium[^1], and
could be extended for other targets).
For hostevents.cpp and soundserver.cpp the entire file was replaced,
whereas for videoctrl.cpp there was enough shared logic that it was
kept, and the platform-specific bits were moved behind a Display class
that can have per-platform implementations. For cases where we need
additional private fields in the platform-specific classes, we use
a PIMPL pattern.
The *_js.cpp files with implementations are not included in this
commit, since they are closely tied to the Infinite Mac project, and
will live in its fork of DingusPPC.
[^1]: https://www.chromium.org/developers/design-documents/conventions-and-patterns-for-multi-platform-development/
2023-09-04 00:59:35 +00:00
|
|
|
this->cursor_on, cursor_x, cursor_y);
|
2021-11-09 12:40:13 +00:00
|
|
|
}
|
|
|
|
|
2023-07-31 01:34:02 +00:00
|
|
|
void VideoCtrlBase::start_refresh_task() {
|
2023-12-03 09:25:08 +00:00
|
|
|
this->display.configure(this->active_width, this->active_height);
|
|
|
|
|
2023-07-31 01:34:02 +00:00
|
|
|
uint64_t refresh_interval = static_cast<uint64_t>(1.0f / refresh_rate * NS_PER_SEC + 0.5);
|
|
|
|
this->refresh_task_id = TimerManager::get_instance()->add_cyclic_timer(
|
|
|
|
refresh_interval,
|
|
|
|
[this]() {
|
2023-08-01 15:37:50 +00:00
|
|
|
// assert VBL interrupt
|
2023-09-18 23:48:36 +00:00
|
|
|
this->vbl_cb(1);
|
2023-07-31 01:34:02 +00:00
|
|
|
this->update_screen();
|
|
|
|
}
|
|
|
|
);
|
2023-08-01 15:37:50 +00:00
|
|
|
|
2023-09-19 00:34:53 +00:00
|
|
|
if (vert_blank == 0) {
|
|
|
|
LOG_F(ERROR, "Vertical blank is 0. Using 25 instead.");
|
|
|
|
vert_blank = 25;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t vbl_duration = static_cast<uint64_t>((double)hori_total * vert_blank / this->pixel_clock * NS_PER_SEC + 0.5);
|
2023-08-01 15:37:50 +00:00
|
|
|
this->vbl_end_task_id = TimerManager::get_instance()->add_cyclic_timer(
|
|
|
|
refresh_interval,
|
|
|
|
refresh_interval + vbl_duration,
|
|
|
|
[this]() {
|
|
|
|
// deassert VBL interrupt
|
2023-09-18 23:48:36 +00:00
|
|
|
this->vbl_cb(0);
|
2023-08-01 15:37:50 +00:00
|
|
|
}
|
|
|
|
);
|
2023-07-31 01:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoCtrlBase::stop_refresh_task() {
|
|
|
|
if (this->refresh_task_id) {
|
|
|
|
TimerManager::get_instance()->cancel_timer(this->refresh_task_id);
|
2024-03-08 07:23:58 +00:00
|
|
|
this->refresh_task_id = 0;
|
2023-07-31 01:34:02 +00:00
|
|
|
}
|
2023-08-01 15:37:50 +00:00
|
|
|
if (this->vbl_end_task_id) {
|
|
|
|
TimerManager::get_instance()->cancel_timer(this->vbl_end_task_id);
|
2024-03-08 07:23:58 +00:00
|
|
|
this->vbl_end_task_id = 0;
|
2023-08-01 15:37:50 +00:00
|
|
|
}
|
2023-07-31 01:34:02 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 10:20:25 +00:00
|
|
|
void VideoCtrlBase::get_palette_color(uint8_t index, uint8_t& r, uint8_t& g,
|
2023-04-01 10:08:25 +00:00
|
|
|
uint8_t& b, uint8_t& a)
|
|
|
|
{
|
|
|
|
b = this->palette[index] & 0xFFU;
|
|
|
|
g = (this->palette[index] >> 8) & 0xFFU;
|
|
|
|
r = (this->palette[index] >> 16) & 0xFFU;
|
|
|
|
a = (this->palette[index] >> 24) & 0xFFU;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoCtrlBase::set_palette_color(uint8_t index, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
|
|
|
|
{
|
|
|
|
this->palette[index] = (a << 24) | (r << 16) | (g << 8) | b;
|
|
|
|
}
|
|
|
|
|
2023-04-01 23:56:24 +00:00
|
|
|
void VideoCtrlBase::setup_hw_cursor(int cursor_width, int cursor_height)
|
|
|
|
{
|
Make Emscripten build not depend on SDL2 or cubeb
While Emscripten has an SDL compabtility layer, it assumes that the
code is executing in the main browser process (and thus has access to
them DOM). The Infinite Mac project runs emulators in a worker thread
(for better performance) and has a custom API for the display, sound,
input, etc. Similarly, it does not need the cross-platform sound support
from cubeb, there there is a sound API as well.
This commit makes SDL (*_sdl.cpp) and cubeb-based (*_cubeb.cpp) code be
skipped when targeting Emscripten, and instead *_js.cpp files are used
instead (this is the cross-platform convention used by Chromium[^1], and
could be extended for other targets).
For hostevents.cpp and soundserver.cpp the entire file was replaced,
whereas for videoctrl.cpp there was enough shared logic that it was
kept, and the platform-specific bits were moved behind a Display class
that can have per-platform implementations. For cases where we need
additional private fields in the platform-specific classes, we use
a PIMPL pattern.
The *_js.cpp files with implementations are not included in this
commit, since they are closely tied to the Infinite Mac project, and
will live in its fork of DingusPPC.
[^1]: https://www.chromium.org/developers/design-documents/conventions-and-patterns-for-multi-platform-development/
2023-09-04 00:59:35 +00:00
|
|
|
this->display.setup_hw_cursor(
|
|
|
|
[this](uint8_t *dst_buf, int dst_pitch) {
|
|
|
|
this->draw_hw_cursor(dst_buf, dst_pitch);
|
|
|
|
},
|
|
|
|
cursor_width, cursor_height);
|
2023-04-01 23:56:24 +00:00
|
|
|
this->cursor_on = true;
|
|
|
|
}
|
|
|
|
|
2023-09-19 00:34:23 +00:00
|
|
|
void VideoCtrlBase::convert_frame_1bpp_indexed(uint8_t *dst_buf, int dst_pitch)
|
2021-12-07 21:47:25 +00:00
|
|
|
{
|
2023-09-19 00:34:23 +00:00
|
|
|
uint8_t *src_row, *dst_row;
|
|
|
|
int src_pitch;
|
|
|
|
|
|
|
|
src_pitch = this->fb_pitch - ((this->active_width + 7) >> 3);
|
|
|
|
dst_pitch = dst_pitch - 4 * this->active_width;
|
|
|
|
|
|
|
|
src_row = this->fb_ptr - 1;
|
|
|
|
dst_row = dst_buf;
|
|
|
|
for (int h = this->active_height; h > 0; h--) {
|
|
|
|
uint8_t bit = 0x00;
|
|
|
|
uint8_t c;
|
|
|
|
for (int x = this->active_width; x > 0; x--) {
|
|
|
|
if (!bit) {
|
|
|
|
src_row += 1;
|
|
|
|
bit = 0x80;
|
|
|
|
c = *src_row;
|
|
|
|
}
|
|
|
|
WRITE_DWORD_LE_A(dst_row, this->palette[!!(c & bit)]);
|
|
|
|
bit >>= 1;
|
|
|
|
dst_row += 4;
|
|
|
|
}
|
|
|
|
src_row += src_pitch;
|
|
|
|
dst_row += dst_pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoCtrlBase::convert_frame_2bpp_indexed(uint8_t *dst_buf, int dst_pitch)
|
|
|
|
{
|
|
|
|
uint8_t *src_row, *dst_row;
|
|
|
|
int src_pitch;
|
|
|
|
|
|
|
|
src_pitch = this->fb_pitch - (this->active_width >> 2);
|
|
|
|
dst_pitch = dst_pitch - 4 * this->active_width;
|
|
|
|
|
|
|
|
src_row = this->fb_ptr;
|
|
|
|
dst_row = dst_buf;
|
|
|
|
for (int h = this->active_height; h > 0; h--) {
|
|
|
|
uint8_t c;
|
|
|
|
for (int x = this->active_width >> 2; x > 0; x--) {
|
|
|
|
c = *src_row;
|
|
|
|
WRITE_DWORD_LE_A(dst_row, this->palette[c >> 6]);
|
|
|
|
dst_row += 4;
|
|
|
|
WRITE_DWORD_LE_A(dst_row, this->palette[(c >> 4) & 3]);
|
|
|
|
dst_row += 4;
|
|
|
|
WRITE_DWORD_LE_A(dst_row, this->palette[(c >> 2) & 3]);
|
|
|
|
dst_row += 4;
|
|
|
|
WRITE_DWORD_LE_A(dst_row, this->palette[c & 3]);
|
|
|
|
dst_row += 4;
|
|
|
|
src_row += 1;
|
|
|
|
}
|
|
|
|
src_row += src_pitch;
|
|
|
|
dst_row += dst_pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoCtrlBase::convert_frame_4bpp_indexed(uint8_t *dst_buf, int dst_pitch)
|
|
|
|
{
|
|
|
|
uint8_t *src_row, *dst_row;
|
|
|
|
int src_pitch;
|
|
|
|
|
|
|
|
src_pitch = this->fb_pitch - (this->active_width >> 1);
|
|
|
|
dst_pitch = dst_pitch - 4 * this->active_width;
|
|
|
|
|
|
|
|
src_row = this->fb_ptr;
|
|
|
|
dst_row = dst_buf;
|
|
|
|
for (int h = this->active_height; h > 0; h--) {
|
|
|
|
uint8_t c;
|
|
|
|
for (int x = this->active_width >> 1; x > 0; x--) {
|
|
|
|
c = *src_row;
|
|
|
|
WRITE_DWORD_LE_A(dst_row, this->palette[c >> 4]);
|
|
|
|
dst_row += 4;
|
|
|
|
WRITE_DWORD_LE_A(dst_row, this->palette[c & 15]);
|
|
|
|
dst_row += 4;
|
|
|
|
src_row += 1;
|
|
|
|
}
|
|
|
|
src_row += src_pitch;
|
|
|
|
dst_row += dst_pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoCtrlBase::convert_frame_8bpp_indexed(uint8_t *dst_buf, int dst_pitch)
|
|
|
|
{
|
|
|
|
uint8_t *src_row, *dst_row;
|
|
|
|
int src_pitch;
|
|
|
|
|
|
|
|
src_pitch = this->fb_pitch - this->active_width;
|
|
|
|
dst_pitch = dst_pitch - 4 * this->active_width;
|
|
|
|
|
|
|
|
src_row = this->fb_ptr;
|
|
|
|
dst_row = dst_buf;
|
|
|
|
for (int h = this->active_height; h > 0; h--) {
|
|
|
|
for (int x = this->active_width; x > 0; x--) {
|
|
|
|
WRITE_DWORD_LE_A(dst_row, this->palette[*src_row++]);
|
|
|
|
dst_row += 4;
|
|
|
|
}
|
|
|
|
src_row += src_pitch;
|
|
|
|
dst_row += dst_pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// alternative version to the above but only works for little endian host
|
|
|
|
void VideoCtrlBase::convert_frame_8bpp_32LE_indexed(uint8_t *dst_buf, int dst_pitch)
|
|
|
|
{
|
|
|
|
uint8_t *dst_row;
|
|
|
|
uint32_t *src_row;
|
|
|
|
int src_pitch;
|
|
|
|
|
|
|
|
src_pitch = this->fb_pitch - this->active_width;
|
|
|
|
dst_pitch = dst_pitch - 4 * this->active_width;
|
|
|
|
|
|
|
|
src_row = (uint32_t*)this->fb_ptr;
|
|
|
|
dst_row = dst_buf;
|
|
|
|
for (int h = this->active_height; h > 0; h--) {
|
|
|
|
for (int x = this->active_width >> 2; x > 0; x--) {
|
|
|
|
uint32_t pixels = *src_row++;
|
|
|
|
WRITE_DWORD_LE_A(dst_row , this->palette[(uint8_t)(pixels )]);
|
|
|
|
WRITE_DWORD_LE_A(dst_row + 4, this->palette[(uint8_t)(pixels >> 8)]);
|
|
|
|
WRITE_DWORD_LE_A(dst_row + 8, this->palette[(uint8_t)(pixels >> 16)]);
|
|
|
|
WRITE_DWORD_LE_A(dst_row + 12, this->palette[(uint8_t)(pixels >> 24)]);
|
|
|
|
dst_row += 16;
|
|
|
|
}
|
|
|
|
src_row = (uint32_t*)((uint8_t*)src_row + src_pitch);
|
|
|
|
dst_row += dst_pitch;
|
|
|
|
}
|
2021-12-07 21:47:25 +00:00
|
|
|
}
|
2023-09-19 00:34:23 +00:00
|
|
|
#endif
|
2021-12-07 21:47:25 +00:00
|
|
|
|
2023-09-19 00:34:23 +00:00
|
|
|
// RGB332
|
2021-11-09 12:40:13 +00:00
|
|
|
void VideoCtrlBase::convert_frame_8bpp(uint8_t *dst_buf, int dst_pitch)
|
|
|
|
{
|
2023-09-19 00:34:23 +00:00
|
|
|
uint8_t *src_row, *dst_row;
|
|
|
|
int src_pitch;
|
|
|
|
|
|
|
|
src_pitch = this->fb_pitch - this->active_width;
|
|
|
|
dst_pitch = dst_pitch - 4 * this->active_width;
|
|
|
|
|
|
|
|
src_row = this->fb_ptr;
|
|
|
|
dst_row = dst_buf;
|
|
|
|
for (int h = this->active_height; h > 0; h--) {
|
|
|
|
for (int x = this->active_width; x > 0; x--) {
|
|
|
|
uint32_t c = *src_row++;
|
|
|
|
uint32_t r = ((c << 16) & 0x00E00000) | ((c << 13) & 0x001C0000) | ((c << 10) & 0x00030000);
|
|
|
|
uint32_t g = ((c << 11) & 0x0000E000) | ((c << 8) & 0x00001C00) | ((c << 5) & 0x00000300);
|
|
|
|
uint32_t b = ((c << 6) & 0x000000C0) | ((c << 4) & 0x00000030) | ((c << 2) & 0x0000000C) | (c & 0x00000003);
|
|
|
|
WRITE_DWORD_LE_A(dst_row, r | g | b);
|
|
|
|
dst_row += 4;
|
|
|
|
}
|
|
|
|
src_row += src_pitch;
|
|
|
|
dst_row += dst_pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RGB555
|
|
|
|
void VideoCtrlBase::convert_frame_15bpp(uint8_t *dst_buf, int dst_pitch)
|
|
|
|
{
|
|
|
|
uint8_t *src_row, *dst_row;
|
|
|
|
int src_pitch;
|
|
|
|
|
|
|
|
src_pitch = this->fb_pitch - 2 * this->active_width;
|
|
|
|
dst_pitch = dst_pitch - 4 * this->active_width;
|
|
|
|
|
|
|
|
src_row = this->fb_ptr;
|
|
|
|
dst_row = dst_buf;
|
|
|
|
for (int h = this->active_height; h > 0; h--) {
|
|
|
|
for (int x = this->active_width; x > 0; x--) {
|
|
|
|
uint32_t c = *((uint16_t*)(src_row));
|
|
|
|
uint32_t r = ((c << 9) & 0x00F80000) | ((c << 4) & 0x00070000);
|
|
|
|
uint32_t g = ((c << 6) & 0x0000F800) | ((c << 1) & 0x00000700);
|
|
|
|
uint32_t b = ((c << 3) & 0x000000F8) | ((c >> 2) & 0x00000007);
|
|
|
|
WRITE_DWORD_LE_A(dst_row, r | g | b);
|
|
|
|
src_row += 2;
|
|
|
|
dst_row += 4;
|
|
|
|
}
|
|
|
|
src_row += src_pitch;
|
|
|
|
dst_row += dst_pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RGB555_BE
|
|
|
|
void VideoCtrlBase::convert_frame_15bpp_BE(uint8_t *dst_buf, int dst_pitch)
|
|
|
|
{
|
|
|
|
uint8_t *src_row, *dst_row;
|
|
|
|
int src_pitch;
|
|
|
|
|
|
|
|
src_pitch = this->fb_pitch - 2 * this->active_width;
|
|
|
|
dst_pitch = dst_pitch - 4 * this->active_width;
|
|
|
|
|
|
|
|
src_row = this->fb_ptr;
|
|
|
|
dst_row = dst_buf;
|
|
|
|
for (int h = this->active_height; h > 0; h--) {
|
|
|
|
for (int x = this->active_width; x > 0; x--) {
|
|
|
|
uint32_t c = READ_WORD_BE_A(src_row);
|
|
|
|
uint32_t r = ((c << 9) & 0x00F80000) | ((c << 4) & 0x00070000);
|
|
|
|
uint32_t g = ((c << 6) & 0x0000F800) | ((c << 1) & 0x00000700);
|
|
|
|
uint32_t b = ((c << 3) & 0x000000F8) | ((c >> 2) & 0x00000007);
|
|
|
|
WRITE_DWORD_LE_A(dst_row, r | g | b);
|
|
|
|
src_row += 2;
|
|
|
|
dst_row += 4;
|
|
|
|
}
|
|
|
|
src_row += src_pitch;
|
|
|
|
dst_row += dst_pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RGB565
|
|
|
|
void VideoCtrlBase::convert_frame_16bpp(uint8_t *dst_buf, int dst_pitch)
|
|
|
|
{
|
|
|
|
uint8_t *src_row, *dst_row;
|
2021-11-09 12:40:13 +00:00
|
|
|
int src_pitch;
|
|
|
|
|
2023-09-19 00:34:23 +00:00
|
|
|
src_pitch = this->fb_pitch - 2 * this->active_width;
|
|
|
|
dst_pitch = dst_pitch - 4 * this->active_width;
|
2021-11-09 12:40:13 +00:00
|
|
|
|
2023-09-19 00:34:23 +00:00
|
|
|
src_row = this->fb_ptr;
|
|
|
|
dst_row = dst_buf;
|
|
|
|
for (int h = this->active_height; h > 0; h--) {
|
|
|
|
for (int x = this->active_width; x > 0; x--) {
|
|
|
|
uint32_t c = *((uint16_t*)(src_row));
|
|
|
|
uint32_t r = ((c << 8) & 0x00F80000) | ((c << 3) & 0x00070000);
|
|
|
|
uint32_t g = ((c << 5) & 0x0000FC00) | ((c >> 1) & 0x00000300);
|
|
|
|
uint32_t b = ((c << 3) & 0x000000F8) | ((c >> 2) & 0x00000007);
|
|
|
|
WRITE_DWORD_LE_A(dst_row, r | g | b);
|
|
|
|
src_row += 2;
|
|
|
|
dst_row += 4;
|
|
|
|
}
|
|
|
|
src_row += src_pitch;
|
|
|
|
dst_row += dst_pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RGB888
|
|
|
|
void VideoCtrlBase::convert_frame_24bpp(uint8_t *dst_buf, int dst_pitch)
|
|
|
|
{
|
|
|
|
uint8_t *src_row, *dst_row;
|
|
|
|
int src_pitch;
|
|
|
|
|
|
|
|
src_pitch = this->fb_pitch - 3 * this->active_width;
|
|
|
|
dst_pitch = dst_pitch - 4 * this->active_width;
|
2021-11-09 12:40:13 +00:00
|
|
|
|
2023-09-19 00:34:23 +00:00
|
|
|
src_row = this->fb_ptr;
|
|
|
|
dst_row = dst_buf;
|
|
|
|
for (int h = this->active_height; h > 0; h--) {
|
|
|
|
for (int x = this->active_width; x > 0; x--) {
|
|
|
|
uint32_t c = (src_row[0] << 16) | (src_row[1] << 8) | src_row[2];
|
|
|
|
WRITE_DWORD_LE_A(dst_row, c);
|
|
|
|
src_row += 3;
|
2021-11-09 12:40:13 +00:00
|
|
|
dst_row += 4;
|
|
|
|
}
|
2023-09-19 00:34:23 +00:00
|
|
|
src_row += src_pitch;
|
|
|
|
dst_row += dst_pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ARGB8888
|
|
|
|
void VideoCtrlBase::convert_frame_32bpp(uint8_t *dst_buf, int dst_pitch)
|
|
|
|
{
|
|
|
|
uint32_t *src_row, *dst_row;
|
|
|
|
int src_pitch;
|
|
|
|
|
|
|
|
src_pitch = this->fb_pitch - 4 * this->active_width;
|
|
|
|
dst_pitch = dst_pitch - 4 * this->active_width;
|
|
|
|
|
|
|
|
src_row = (uint32_t*)this->fb_ptr;
|
|
|
|
dst_row = (uint32_t*)dst_buf;
|
|
|
|
for (int h = this->active_height; h > 0; h--) {
|
|
|
|
for (int x = this->active_width; x > 0; x--) {
|
|
|
|
uint32_t c = READ_DWORD_LE_A(src_row);
|
|
|
|
WRITE_DWORD_LE_A(dst_row, c);
|
|
|
|
src_row++;
|
|
|
|
dst_row++;
|
|
|
|
}
|
|
|
|
src_row = (uint32_t*)((uint8_t*)src_row + src_pitch);
|
|
|
|
dst_row = (uint32_t*)((uint8_t*)dst_row + dst_pitch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ARGB8888_BE
|
|
|
|
void VideoCtrlBase::convert_frame_32bpp_BE(uint8_t *dst_buf, int dst_pitch)
|
|
|
|
{
|
|
|
|
uint32_t *src_row, *dst_row;
|
|
|
|
int src_pitch;
|
|
|
|
|
|
|
|
src_pitch = this->fb_pitch - 4 * this->active_width;
|
|
|
|
dst_pitch = dst_pitch - 4 * this->active_width;
|
|
|
|
|
|
|
|
src_row = (uint32_t*)this->fb_ptr;
|
|
|
|
dst_row = (uint32_t*)dst_buf;
|
|
|
|
for (int h = this->active_height; h > 0; h--) {
|
|
|
|
for (int x = this->active_width; x > 0; x--) {
|
|
|
|
uint32_t c = READ_DWORD_BE_A(src_row);
|
|
|
|
WRITE_DWORD_LE_A(dst_row, c);
|
|
|
|
src_row++;
|
|
|
|
dst_row++;
|
|
|
|
}
|
|
|
|
src_row = (uint32_t*)((uint8_t*)src_row + src_pitch);
|
|
|
|
dst_row = (uint32_t*)((uint8_t*)dst_row + dst_pitch);
|
2021-11-09 12:40:13 +00:00
|
|
|
}
|
|
|
|
}
|