[Scummvm-cvs-logs] SF.net SVN: scummvm:[49055] scummvm/trunk/backends/platform/psp

Bluddy at users.sourceforge.net Bluddy at users.sourceforge.net
Mon May 17 09:22:26 CEST 2010


Revision: 49055
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49055&view=rev
Author:   Bluddy
Date:     2010-05-17 07:22:26 +0000 (Mon, 17 May 2010)

Log Message:
-----------
PSP: added option for render by callback and fixed up and cleaned up debug mechanism. This allows for about 4% speedup since we no longer need to wait for VSYNC in our main thread. I'll activate it as soon as I've tested it out properly.

Modified Paths:
--------------
    scummvm/trunk/backends/platform/psp/cursor.cpp
    scummvm/trunk/backends/platform/psp/default_display_client.cpp
    scummvm/trunk/backends/platform/psp/display_client.cpp
    scummvm/trunk/backends/platform/psp/display_client.h
    scummvm/trunk/backends/platform/psp/display_manager.cpp
    scummvm/trunk/backends/platform/psp/display_manager.h
    scummvm/trunk/backends/platform/psp/input.cpp
    scummvm/trunk/backends/platform/psp/osys_psp.cpp
    scummvm/trunk/backends/platform/psp/psp_main.cpp
    scummvm/trunk/backends/platform/psp/pspkeyboard.cpp
    scummvm/trunk/backends/platform/psp/pspkeyboard.h
    scummvm/trunk/backends/platform/psp/trace.cpp
    scummvm/trunk/backends/platform/psp/trace.h

Modified: scummvm/trunk/backends/platform/psp/cursor.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/cursor.cpp	2010-05-17 04:02:49 UTC (rev 49054)
+++ scummvm/trunk/backends/platform/psp/cursor.cpp	2010-05-17 07:22:26 UTC (rev 49055)
@@ -24,6 +24,7 @@
  */
 
 #include "common/scummsys.h"
+#include "backends/platform/psp/psppixelformat.h"
 #include "backends/platform/psp/display_client.h"
 #include "backends/platform/psp/default_display_client.h"
 #include "backends/platform/psp/cursor.h"

Modified: scummvm/trunk/backends/platform/psp/default_display_client.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/default_display_client.cpp	2010-05-17 04:02:49 UTC (rev 49054)
+++ scummvm/trunk/backends/platform/psp/default_display_client.cpp	2010-05-17 07:22:26 UTC (rev 49055)
@@ -24,6 +24,7 @@
  */
 
 #include "common/scummsys.h"
+#include "backends/platform/psp/psppixelformat.h"
 #include "backends/platform/psp/display_client.h"
 #include "backends/platform/psp/default_display_client.h"
 

Modified: scummvm/trunk/backends/platform/psp/display_client.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/display_client.cpp	2010-05-17 04:02:49 UTC (rev 49054)
+++ scummvm/trunk/backends/platform/psp/display_client.cpp	2010-05-17 07:22:26 UTC (rev 49055)
@@ -24,10 +24,12 @@
  */
 
 #include <pspgu.h>
+#include <pspkerneltypes.h>
 #include <pspdisplay.h>
 #include <psputils.h>
 
 #include "common/scummsys.h"
+#include "backends/platform/psp/psppixelformat.h"
 #include "backends/platform/psp/display_client.h"
 #include "backends/platform/psp/display_manager.h"
 #include "backends/platform/psp/memory.h"

Modified: scummvm/trunk/backends/platform/psp/display_client.h
===================================================================
--- scummvm/trunk/backends/platform/psp/display_client.h	2010-05-17 04:02:49 UTC (rev 49054)
+++ scummvm/trunk/backends/platform/psp/display_client.h	2010-05-17 07:22:26 UTC (rev 49055)
@@ -29,7 +29,6 @@
 #include "common/singleton.h"
 #include "graphics/surface.h"
 #include "common/system.h"
-#include "backends/platform/psp/psppixelformat.h"
 #include "backends/platform/psp/memory.h"
 
 #define MAX_TEXTURE_SIZE 512

Modified: scummvm/trunk/backends/platform/psp/display_manager.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/display_manager.cpp	2010-05-17 04:02:49 UTC (rev 49054)
+++ scummvm/trunk/backends/platform/psp/display_manager.cpp	2010-05-17 07:22:26 UTC (rev 49055)
@@ -25,13 +25,17 @@
 
 #include <pspgu.h>
 #include <pspdisplay.h>
+#include <pspthreadman.h>
 
 #include "common/scummsys.h"
 #include "backends/base-backend.h"
+#include "backends/platform/psp/psppixelformat.h"
 #include "backends/platform/psp/display_client.h"
 #include "backends/platform/psp/default_display_client.h"
 #include "backends/platform/psp/cursor.h"
 #include "backends/platform/psp/pspkeyboard.h"
+
+//#define USE_DISPLAY_CALLBACK	// to use callback for finishing the render
 #include "backends/platform/psp/display_manager.h"
 
 #define PSP_BUFFER_WIDTH (512)
@@ -56,9 +60,45 @@
 	{0, 0, 0}
 };
 
+bool MasterGuRenderer::_renderFinished = true;	// synchronizes the callback thread
 
 // Class MasterGuRenderer ----------------------------------------------
 
+void MasterGuRenderer::setupCallbackThread() {
+	DEBUG_ENTER_FUNC();
+	int thid = sceKernelCreateThread("displayCbThread", guCallbackThread, 0x11, 4*1024, THREAD_ATTR_USER, 0);
+	
+	PSP_DEBUG_PRINT("Display CB thread id is %x\n", thid);
+	
+	if (thid >= 0) {
+		sceKernelStartThread(thid, 0, 0);
+	} else 
+		PSP_ERROR("failed to create display callback thread\n");
+}
+
+// thread that reacts to the callback
+int MasterGuRenderer::guCallbackThread(SceSize, void *) {
+	DEBUG_ENTER_FUNC();
+	
+	if (sceGuSetCallback(GU_CALLBACK_FINISH, guDisplayCallback) != 0) {
+		PSP_ERROR("Warning: previous display callback found.\n");
+	}
+	PSP_DEBUG_PRINT("set callback. Going to sleep\n");
+
+	sceKernelSleepThreadCB();	// sleep until we get a callback
+	return 0;
+}
+
+// This callback is called when the render is finished. It swaps the buffers
+void MasterGuRenderer::guDisplayCallback(int) {
+	if (_renderFinished == true)
+		PSP_ERROR("callback thread found wrong value[true] in _renderFinished\n");
+		
+	sceDisplayWaitVblankStart();	// wait for v-blank without eating main thread cycles
+	sceGuSwapBuffers();
+	_renderFinished = true;	// Only this thread can set the variable to true
+}
+
 void MasterGuRenderer::guInit() {
 	DEBUG_ENTER_FUNC();
 
@@ -110,6 +150,8 @@
 inline void MasterGuRenderer::guPreRender() {
 	DEBUG_ENTER_FUNC();
 
+	_renderFinished = false;	// set to synchronize with callback thread
+	
 #ifdef ENABLE_RENDER_MEASURE
 	_lastRenderTime = g_system->getMillis();
 #endif /* ENABLE_RENDER_MEASURE */
@@ -132,7 +174,8 @@
 	DEBUG_ENTER_FUNC();
 
 	sceGuFinish();
-	sceGuSync(0, 0);
+#ifndef USE_DISPLAY_CALLBACK
+	sceGuSync(0, 0);	
 
 #ifdef ENABLE_RENDER_MEASURE
 	uint32 now = g_system->getMillis();
@@ -141,6 +184,8 @@
 
 	sceDisplayWaitVblankStart();
 	sceGuSwapBuffers();
+	_renderFinished = true;
+#endif /* !USE_DISPLAY_CALLBACK */	
 }
 
 void MasterGuRenderer::guShutDown() {
@@ -164,11 +209,15 @@
 	_overlay->init();
 	_cursor->init();
 
+
 	_masterGuRenderer.guInit();				// start up the renderer
+#ifdef USE_DISPLAY_CALLBACK
+	_masterGuRenderer.setupCallbackThread();
+#endif
+	
 }
 
 void DisplayManager::setSizeAndPixelFormat(uint width, uint height, const Graphics::PixelFormat *format) {
-
 	DEBUG_ENTER_FUNC();
 	PSP_DEBUG_PRINT("w[%u], h[%u], pformat[%p]\n", width, height, format);
 
@@ -248,9 +297,15 @@
 void DisplayManager::renderAll() {
 	DEBUG_ENTER_FUNC();
 
-	if (!isTimeToUpdate()) {
+#ifdef USE_DISPLAY_CALLBACK
+	if (!_masterGuRenderer.isRenderFinished()) {
+		PSP_DEBUG_PRINT("Callback render not finished.\n");
 		return;
-	}
+	}	
+#endif /* USE_DISPLAY_CALLBACK */
+	
+	if (!isTimeToUpdate()) 
+		return;
 
 	if (!_screen->isDirty() &&
 	        (!_overlay->isDirty()) &&

Modified: scummvm/trunk/backends/platform/psp/display_manager.h
===================================================================
--- scummvm/trunk/backends/platform/psp/display_manager.h	2010-05-17 04:02:49 UTC (rev 49054)
+++ scummvm/trunk/backends/platform/psp/display_manager.h	2010-05-17 07:22:26 UTC (rev 49055)
@@ -36,10 +36,15 @@
 	void guPreRender();
 	void guPostRender();
 	void guShutDown();
+	bool isRenderFinished() { return _renderFinished; }
+	void setupCallbackThread();
 private:
 	static uint32 _displayList[];
 	uint32 _lastRenderTime;					// For measuring rendering
 	void guProgramDisplayBufferSizes();
+	static bool _renderFinished;
+	static int guCallbackThread(SceSize, void *);
+	static void guDisplayCallback(int);
 };
 
 class Screen;

Modified: scummvm/trunk/backends/platform/psp/input.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/input.cpp	2010-05-17 04:02:49 UTC (rev 49054)
+++ scummvm/trunk/backends/platform/psp/input.cpp	2010-05-17 07:22:26 UTC (rev 49055)
@@ -31,6 +31,7 @@
 
 #include "backends/platform/psp/trace.h"
 
+#include "backends/platform/psp/psppixelformat.h"
 #include "backends/platform/psp/input.h"
 
 // Defines for working with PSP buttons

Modified: scummvm/trunk/backends/platform/psp/osys_psp.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/osys_psp.cpp	2010-05-17 04:02:49 UTC (rev 49054)
+++ scummvm/trunk/backends/platform/psp/osys_psp.cpp	2010-05-17 07:22:26 UTC (rev 49055)
@@ -34,6 +34,7 @@
 #include "common/events.h"
 #include "common/scummsys.h"
 
+#include "backends/platform/psp/psppixelformat.h"
 #include "backends/platform/psp/osys_psp.h"
 #include "backends/platform/psp/powerman.h"
 

Modified: scummvm/trunk/backends/platform/psp/psp_main.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/psp_main.cpp	2010-05-17 04:02:49 UTC (rev 49054)
+++ scummvm/trunk/backends/platform/psp/psp_main.cpp	2010-05-17 07:22:26 UTC (rev 49055)
@@ -41,8 +41,9 @@
 #include "backends/platform/psp/powerman.h"
 
 #include "backends/plugins/psp/psp-provider.h"
-#include "osys_psp.h"
-#include "./trace.h"
+#include "backends/platform/psp/psppixelformat.h"
+#include "backends/platform/psp/osys_psp.h"
+#include "backends/platform/psp/trace.h"
 
 #ifdef ENABLE_PROFILING
 	#include <pspprof.h>

Modified: scummvm/trunk/backends/platform/psp/pspkeyboard.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/pspkeyboard.cpp	2010-05-17 04:02:49 UTC (rev 49054)
+++ scummvm/trunk/backends/platform/psp/pspkeyboard.cpp	2010-05-17 07:22:26 UTC (rev 49055)
@@ -29,18 +29,22 @@
 #define PSP_KB_SHELL_PATH 	"ms0:/psp/game4xx/scummvm-solid/"	/* path to kbd.zip */
 #endif
 
-//#define __PSP_DEBUG_FUNCS__	/* For debugging the stack */
-//#define __PSP_DEBUG_PRINT__
 
-#include "backends/platform/psp/trace.h"
 #include <malloc.h>
-#include "pspkernel.h"
-#include "png.h"
+#include <pspkernel.h>
+#include <png.h>
+
+#include "backends/platform/psp/psppixelformat.h"
 #include "backends/platform/psp/pspkeyboard.h"
 #include "common/keyboard.h"
 #include "common/fs.h"
 #include "common/unzip.h"
 
+//#define __PSP_DEBUG_FUNCS__	/* For debugging the stack */
+//#define __PSP_DEBUG_PRINT__
+
+#include "backends/platform/psp/trace.h"
+
 #define PSP_SCREEN_WIDTH 480
 #define PSP_SCREEN_HEIGHT 272
 #define K(x)	((short)(Common::KEYCODE_INVALID + (x)))

Modified: scummvm/trunk/backends/platform/psp/pspkeyboard.h
===================================================================
--- scummvm/trunk/backends/platform/psp/pspkeyboard.h	2010-05-17 04:02:49 UTC (rev 49054)
+++ scummvm/trunk/backends/platform/psp/pspkeyboard.h	2010-05-17 07:22:26 UTC (rev 49055)
@@ -76,7 +76,7 @@
 	GuRenderer _renderer;
 
 	int loadPngImage(Common::SeekableReadStream *file, Buffer &buffer, Palette &palette);
-	int getPngImageSize(Common::SeekableReadStream *, uint32 *png_width, uint32 *png_height, u32 *paletteSize);
+	int getPngImageSize(Common::SeekableReadStream *, uint32 *png_width, uint32 *png_height, uint32 *paletteSize);
 	uint32 convert_pow2(uint32 size);
 	void increaseKeyboardLocationX(int amount);		// Move keyboard onscreen
 	void increaseKeyboardLocationY(int amount);

Modified: scummvm/trunk/backends/platform/psp/trace.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/trace.cpp	2010-05-17 04:02:49 UTC (rev 49054)
+++ scummvm/trunk/backends/platform/psp/trace.cpp	2010-05-17 07:22:26 UTC (rev 49055)
@@ -23,12 +23,12 @@
  *
  */
 
-#define TRACE_C
+
 #include <pspkernel.h>
 #include <pspdebug.h>
-#include "backends/platform/psp/trace.h"
+#include <stdarg.h>
+#include <stdio.h>
 
-
 int psp_debug_indent = 0;
 
 void PSPDebugTrace(bool alsoToScreen, const char *format, ...) {

Modified: scummvm/trunk/backends/platform/psp/trace.h
===================================================================
--- scummvm/trunk/backends/platform/psp/trace.h	2010-05-17 04:02:49 UTC (rev 49054)
+++ scummvm/trunk/backends/platform/psp/trace.h	2010-05-17 07:22:26 UTC (rev 49055)
@@ -24,47 +24,19 @@
  */
 
 
-#ifndef TRACE_H
-#define TRACE_H
+// This section can only be included once
+#ifndef PSP_TRACE_H
+#define PSP_TRACE_H
 
-#include <stdio.h>
-#include <psptypes.h>
-#include <stdarg.h>
+#include "common/str.h"
 
-// Use these defines for debugging
-
-//#define __PSP_PRINT_TO_FILE__
-//#define __PSP_PRINT_TO_FILE_AND_SCREEN__
-//#define __PSP_DEBUG_FUNCS__	/* can put this locally too */
-//#define __PSP_DEBUG_PRINT__
-
-void PSPDebugTrace(bool alsoToScreen, const char *format, ...);
-
-#ifndef TRACE_C
-extern int psp_debug_indent;
-#endif
-
-// From here on, we allow multiple definitions
-#undef __PSP_PRINT__
-#undef PSP_ERROR
-#undef __PSP_INDENT__
-#undef PSP_INFO_PRINT
-#undef PSP_INFO_PRINT_INDENT
-#undef PSP_DEBUG_PRINT
-#undef PSP_DEBUG_PRINT_FUNC
-#undef PSP_DEBUG_PRINT_SAMELN
-#undef PSP_DEBUG_DO
-#undef DEBUG_ENTER_FUNC
-#undef DEBUG_EXIT_FUNC
-#undef INLINE
-
 /* Choose to print to file/screen/both */
 #ifdef __PSP_PRINT_TO_FILE__
-#define __PSP_PRINT__(format,...)			PSPDebugTrace(false, format, ## __VA_ARGS__)
+	#define __PSP_PRINT__(format,...)			PSPDebugTrace(false, format, ## __VA_ARGS__)
 #elif defined __PSP_PRINT_TO_FILE_AND_SCREEN__
-#define __PSP_PRINT__(format,...)			PSPDebugTrace(true, format, ## __VA_ARGS__)
+	#define __PSP_PRINT__(format,...)			PSPDebugTrace(true, format, ## __VA_ARGS__)
 #else /* default - print to screen */
-#define __PSP_PRINT__(format,...)			fprintf(stderr, format, ## __VA_ARGS__)
+	#define __PSP_PRINT__(format,...)			fprintf(stderr, format, ## __VA_ARGS__)
 #endif /* PSP_PRINT_TO_FILE/SCREEN */
 
 /* Error function */
@@ -80,28 +52,13 @@
 #define PSP_INFO_PRINT_INDENT(format,...)		{ __PSP_INDENT__; \
 												__PSP_PRINT__(format, ## __VA_ARGS__); }
 
-#ifdef __PSP_DEBUG_PRINT__
-/* printf with indents */
-#define PSP_DEBUG_PRINT_SAMELN(format,...)	__PSP_PRINT__(format, ## __VA_ARGS__)
-#define PSP_DEBUG_PRINT(format,...)			{ __PSP_INDENT__; \
-												__PSP_PRINT__(format, ## __VA_ARGS__); }
-#define PSP_DEBUG_PRINT_FUNC(format,...)	{ __PSP_INDENT__; \
-												__PSP_PRINT__("In %s: " format, __PRETTY_FUNCTION__, ## __VA_ARGS__); }
-#define PSP_DEBUG_DO(x)						(x)
+void PSPDebugTrace(bool alsoToScreen, const char *format, ...);
 
-#else	/* no debug print */
-#define PSP_DEBUG_PRINT_SAMELN(format,...)
-#define PSP_DEBUG_PRINT(format,...)
-#define PSP_DEBUG_PRINT_FUNC(format,...)
-#define PSP_DEBUG_DO(x)
-#endif /* __PSP_DEBUG_PRINT__ */
+extern int psp_debug_indent;
 
-/* Debugging function calls */
-#ifdef __PSP_DEBUG_FUNCS__
-
 // We use this class to print out function calls on the stack in an easy way.
 //
-#include "common/str.h"
+
 class PSPStackDebugFuncs {
     Common::String _name;
 
@@ -119,7 +76,45 @@
 	}
 };
 
+#endif /* PSP_TRACE_H */
+
+
+
+
+// From here on, we allow multiple redefinitions
+
+// Use these defines for debugging
+
+//#define __PSP_PRINT_TO_FILE__
+//#define __PSP_PRINT_TO_FILE_AND_SCREEN__
+//#define __PSP_DEBUG_FUNCS__	/* can put this locally too */
+//#define __PSP_DEBUG_PRINT__
+
+#undef PSP_DEBUG_PRINT
+#undef PSP_DEBUG_PRINT_FUNC
+#undef PSP_DEBUG_PRINT_SAMELN
+#undef PSP_DEBUG_DO
+#undef DEBUG_ENTER_FUNC
+#undef DEBUG_EXIT_FUNC
+
+#ifdef __PSP_DEBUG_PRINT__
+/* printf with indents */
+#define PSP_DEBUG_PRINT_SAMELN(format,...)	__PSP_PRINT__(format, ## __VA_ARGS__)
+#define PSP_DEBUG_PRINT(format,...)			PSP_INFO_PRINT_INDENT(format, ## __VA_ARGS__)
+#define PSP_DEBUG_PRINT_FUNC(format,...)	{ __PSP_INDENT__; \
+												__PSP_PRINT__("In %s: " format, __PRETTY_FUNCTION__, ## __VA_ARGS__); }
+#define PSP_DEBUG_DO(x)						(x)
+
+#else	/* no debug print */
+	#define PSP_DEBUG_PRINT_SAMELN(format,...)
+	#define PSP_DEBUG_PRINT(format,...)
+	#define PSP_DEBUG_PRINT_FUNC(format,...)
+	#define PSP_DEBUG_DO(x)
+#endif /* __PSP_DEBUG_PRINT__ */
+
 /* We don't need anything but this line at the beginning of each function to debug function calls */
+/* Debugging function calls */
+#ifdef __PSP_DEBUG_FUNCS__
 	#define DEBUG_ENTER_FUNC()		volatile PSPStackDebugFuncs __foo(__PRETTY_FUNCTION__)
 #else /* Don't debug function calls */
 	#define DEBUG_ENTER_FUNC()
@@ -130,5 +125,3 @@
 #undef __PSP_PRINT_TO_FILE_AND_SCREEN__
 #undef __PSP_DEBUG_FUNCS__
 #undef __PSP_DEBUG_PRINT__
-
-#endif /* TRACE_H */


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list