From 71d70d896fd6012eea94042e962dad2009086038 Mon Sep 17 00:00:00 2001 From: Matthew Parlane Date: Sun, 17 Nov 2013 10:34:34 +1300 Subject: [PATCH 1/2] Api was too confusing for people. --- Source/Core/VideoBackends/D3D/Src/Render.cpp | 1 + Source/Core/VideoBackends/D3D/Src/TextureCache.cpp | 1 + Source/Core/VideoBackends/OGL/Src/Render.cpp | 6 +++++- Source/Core/VideoBackends/OGL/Src/TextureCache.cpp | 5 +++-- Source/Core/VideoBackends/Software/Src/DebugUtil.cpp | 4 ++++ Source/Core/VideoBackends/Software/Src/SWRenderer.cpp | 2 ++ Source/Core/VideoCommon/Src/ImageWrite.cpp | 5 ----- 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/Src/Render.cpp b/Source/Core/VideoBackends/D3D/Src/Render.cpp index ae6d21ef03..18eb1e26cc 100644 --- a/Source/Core/VideoBackends/D3D/Src/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Src/Render.cpp @@ -701,6 +701,7 @@ bool Renderer::SaveScreenshot(const std::string &filename, const TargetRectangle memcpy(data, map.pData, map.RowPitch * rc.GetHeight()); saved_png = TextureToPng(data, map.RowPitch, filename.c_str(), rc.GetWidth(), rc.GetHeight(), false); + delete[] data; } D3D::context->Unmap(s_screenshot_texture, 0); diff --git a/Source/Core/VideoBackends/D3D/Src/TextureCache.cpp b/Source/Core/VideoBackends/D3D/Src/TextureCache.cpp index faf83c23ca..cfc25bd38f 100644 --- a/Source/Core/VideoBackends/D3D/Src/TextureCache.cpp +++ b/Source/Core/VideoBackends/D3D/Src/TextureCache.cpp @@ -71,6 +71,7 @@ bool TextureCache::TCacheEntry::Save(const char filename[], unsigned int level) memcpy(data, map.pData, map.RowPitch * desc.Height); saved_png = TextureToPng(data, map.RowPitch, filename, desc.Width, desc.Height); + delete[] data; } D3D::context->Unmap(pNewTexture, 0); } diff --git a/Source/Core/VideoBackends/OGL/Src/Render.cpp b/Source/Core/VideoBackends/OGL/Src/Render.cpp index 5a2e6dfe01..8f06c2547c 100644 --- a/Source/Core/VideoBackends/OGL/Src/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Src/Render.cpp @@ -1825,7 +1825,11 @@ bool Renderer::SaveScreenshot(const std::string &filename, const TargetRectangle // Turn image upside down FlipImageData(data, W, H, 4); - return TextureToPng(data, W*4, filename.c_str(), W, H, false); + bool success = TextureToPng(data, W*4, filename.c_str(), W, H, false); + delete[] data; + + return success; + } } diff --git a/Source/Core/VideoBackends/OGL/Src/TextureCache.cpp b/Source/Core/VideoBackends/OGL/Src/TextureCache.cpp index 0c4fe8a187..6d69c62ec0 100644 --- a/Source/Core/VideoBackends/OGL/Src/TextureCache.cpp +++ b/Source/Core/VideoBackends/OGL/Src/TextureCache.cpp @@ -78,8 +78,9 @@ bool SaveTexture(const char* filename, u32 textarget, u32 tex, int virtual_width delete[] data; return false; } - - return TextureToPng(data, width*4, filename, width, height, true); + bool success = TextureToPng(data, width * 4, filename, width, height, true); + delete[] data; + return success; #else return false; #endif diff --git a/Source/Core/VideoBackends/Software/Src/DebugUtil.cpp b/Source/Core/VideoBackends/Software/Src/DebugUtil.cpp index 3f21e6a758..106b32647c 100644 --- a/Source/Core/VideoBackends/Software/Src/DebugUtil.cpp +++ b/Source/Core/VideoBackends/Software/Src/DebugUtil.cpp @@ -57,6 +57,7 @@ void SaveTexture(const char* filename, u32 texmap, s32 mip) GetTextureRGBA(data, texmap, mip, width, height); (void)TextureToPng(data, width*4, filename, width, height, true); + delete[] data; } @@ -140,6 +141,7 @@ void DumpEfb(const char* filename) } (void)TextureToPng(data, EFB_WIDTH * 4, filename, EFB_WIDTH, EFB_HEIGHT, true); + delete[] data; } void DumpDepth(const char* filename) @@ -161,6 +163,7 @@ void DumpDepth(const char* filename) } (void)TextureToPng(data, EFB_WIDTH * 4, filename, EFB_WIDTH, EFB_HEIGHT, true); + delete[] data; } void DrawObjectBuffer(s16 x, s16 y, u8 *color, int bufferBase, int subBuffer, const char *name) @@ -241,6 +244,7 @@ void OnObjectEnd() (void)TextureToPng((u8*)ObjectBuffer[i], EFB_WIDTH * 4, filename.c_str(), EFB_WIDTH, EFB_HEIGHT, true); memset(ObjectBuffer[i], 0, sizeof(ObjectBuffer[i])); + } } diff --git a/Source/Core/VideoBackends/Software/Src/SWRenderer.cpp b/Source/Core/VideoBackends/Software/Src/SWRenderer.cpp index fc26a93ad5..5db452dd94 100644 --- a/Source/Core/VideoBackends/Software/Src/SWRenderer.cpp +++ b/Source/Core/VideoBackends/Software/Src/SWRenderer.cpp @@ -145,6 +145,8 @@ void SWRenderer::DrawTexture(u8 *texture, int width, int height) u8 *data = new u8[width * 4 * height]; memcpy(data, texture, sizeof(u8) * 4 * width * height); TextureToPng(data, width*4, s_sScreenshotName.c_str(), width, height, false); + delete[] data; + // Reset settings s_sScreenshotName.clear(); s_bScreenshot = false; diff --git a/Source/Core/VideoCommon/Src/ImageWrite.cpp b/Source/Core/VideoCommon/Src/ImageWrite.cpp index 5bf3f28e45..974efe7474 100644 --- a/Source/Core/VideoCommon/Src/ImageWrite.cpp +++ b/Source/Core/VideoCommon/Src/ImageWrite.cpp @@ -24,8 +24,6 @@ TextureToPng Inputs: data : This is an array of RGBA with 8 bits per channel. 4 bytes for each pixel. -data is a newly allocated memory and must have delete[] run on it before returning. - row_stride: Determines the amount of bytes per row of pixels. */ bool TextureToPng(u8* data, int row_stride, const char* filename, int width, int height, bool saveAlpha) @@ -109,8 +107,5 @@ finalise: if (info_ptr != NULL) png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); if (png_ptr != NULL) png_destroy_write_struct(&png_ptr, (png_infopp)NULL); - // Our duty to delete the inputted data. - delete[] data; - return success; } From 4a9c8e6f55312127e49a4202b0a2c0438d1de00f Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Sat, 16 Nov 2013 15:37:40 -0600 Subject: [PATCH 2/2] Change software rasterizer screenshot code due to change in api just now. --- Source/Core/VideoBackends/Software/Src/SWRenderer.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/Core/VideoBackends/Software/Src/SWRenderer.cpp b/Source/Core/VideoBackends/Software/Src/SWRenderer.cpp index 5db452dd94..1f5430ae49 100644 --- a/Source/Core/VideoBackends/Software/Src/SWRenderer.cpp +++ b/Source/Core/VideoBackends/Software/Src/SWRenderer.cpp @@ -142,11 +142,7 @@ void SWRenderer::DrawTexture(u8 *texture, int width, int height) if (s_bScreenshot) { std::lock_guard lk(s_criticalScreenshot); - u8 *data = new u8[width * 4 * height]; - memcpy(data, texture, sizeof(u8) * 4 * width * height); - TextureToPng(data, width*4, s_sScreenshotName.c_str(), width, height, false); - delete[] data; - + TextureToPng(texture, width*4, s_sScreenshotName.c_str(), width, height, false); // Reset settings s_sScreenshotName.clear(); s_bScreenshot = false;