mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-28 13:28:01 +03:00
rsx_debugger: replace malloc with buffer cache
This also fixes a memory leak.
This commit is contained in:
parent
bc487f43f7
commit
d3b7a5146c
1 changed files with 11 additions and 14 deletions
|
@ -476,19 +476,15 @@ namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a new buffer that can be passed to QImage.
|
* Fill a buffer that can be passed to QImage.
|
||||||
*/
|
*/
|
||||||
u8* convert_to_QImage_buffer(rsx::surface_color_format format, std::span<const std::byte> orig_buffer, usz width, usz height) noexcept
|
void convert_to_QImage_buffer(rsx::surface_color_format format, std::span<const std::byte> orig_buffer, std::vector<u8>& buffer, usz width, usz height) noexcept
|
||||||
{
|
{
|
||||||
if (width == 0 || height == 0)
|
buffer.resize(width * height * 4);
|
||||||
{
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
u8* buffer = static_cast<u8*>(std::malloc(width * height * 4));
|
if (buffer.empty())
|
||||||
if (!buffer)
|
|
||||||
{
|
{
|
||||||
return nullptr;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (u32 i = 0; i < width * height; i++)
|
for (u32 i = 0; i < width * height; i++)
|
||||||
|
@ -500,7 +496,6 @@ namespace
|
||||||
buffer[2 + i * 4] = colors[2];
|
buffer[2 + i * 4] = colors[2];
|
||||||
buffer[3 + i * 4] = 255;
|
buffer[3 + i * 4] = 255;
|
||||||
}
|
}
|
||||||
return buffer;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -525,8 +520,9 @@ void rsx_debugger::OnClickDrawCalls()
|
||||||
{
|
{
|
||||||
if (width && height && !draw_call.color_buffer[i].empty())
|
if (width && height && !draw_call.color_buffer[i].empty())
|
||||||
{
|
{
|
||||||
unsigned char* buffer = convert_to_QImage_buffer(draw_call.state.surface_color(), draw_call.color_buffer[i], width, height);
|
std::vector<u8>& buffer = buffers[i]->cache;
|
||||||
buffers[i]->showImage(QImage(buffer, static_cast<int>(width), static_cast<int>(height), QImage::Format_RGB32, [](void* buffer){ std::free(buffer); }, buffer));
|
convert_to_QImage_buffer(draw_call.state.surface_color(), draw_call.color_buffer[i], buffer, width, height);
|
||||||
|
buffers[i]->showImage(QImage(buffer.data(), static_cast<int>(width), static_cast<int>(height), QImage::Format_RGB32));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -577,7 +573,8 @@ void rsx_debugger::OnClickDrawCalls()
|
||||||
if (width && height && !draw_call.depth_stencil[1].empty())
|
if (width && height && !draw_call.depth_stencil[1].empty())
|
||||||
{
|
{
|
||||||
const std::span<const std::byte> orig_buffer = draw_call.depth_stencil[1];
|
const std::span<const std::byte> orig_buffer = draw_call.depth_stencil[1];
|
||||||
u8* buffer = static_cast<u8*>(std::malloc(4ULL * width * height));
|
std::vector<u8>& buffer = m_buffer_stencil->cache;
|
||||||
|
buffer.resize(4ULL * width * height);
|
||||||
|
|
||||||
for (u32 row = 0; row < height; row++)
|
for (u32 row = 0; row < height; row++)
|
||||||
{
|
{
|
||||||
|
@ -590,7 +587,7 @@ void rsx_debugger::OnClickDrawCalls()
|
||||||
buffer[4 * col + 3 + width * row * 4] = 255;
|
buffer[4 * col + 3 + width * row * 4] = 255;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_buffer_stencil->showImage(QImage(buffer, static_cast<int>(width), static_cast<int>(height), QImage::Format_RGB32));
|
m_buffer_stencil->showImage(QImage(buffer.data(), static_cast<int>(width), static_cast<int>(height), QImage::Format_RGB32));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue