aboutsummaryrefslogtreecommitdiff
path: root/backends/platform
diff options
context:
space:
mode:
authorYotam Barnoy2010-05-17 07:22:26 +0000
committerYotam Barnoy2010-05-17 07:22:26 +0000
commit8b59e45e6e8ffdd733abaa53d6ee4eea7ee6bc5d (patch)
tree1b0381701b8260ad7e7fc4cf9809373ffb626a6b /backends/platform
parentf4eacd6cc626f6879f4621e493fc28ca6799f168 (diff)
downloadscummvm-rg350-8b59e45e6e8ffdd733abaa53d6ee4eea7ee6bc5d.tar.gz
scummvm-rg350-8b59e45e6e8ffdd733abaa53d6ee4eea7ee6bc5d.tar.bz2
scummvm-rg350-8b59e45e6e8ffdd733abaa53d6ee4eea7ee6bc5d.zip
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.
svn-id: r49055
Diffstat (limited to 'backends/platform')
-rw-r--r--backends/platform/psp/cursor.cpp1
-rw-r--r--backends/platform/psp/default_display_client.cpp1
-rw-r--r--backends/platform/psp/display_client.cpp2
-rw-r--r--backends/platform/psp/display_client.h1
-rw-r--r--backends/platform/psp/display_manager.cpp63
-rw-r--r--backends/platform/psp/display_manager.h5
-rw-r--r--backends/platform/psp/input.cpp1
-rw-r--r--backends/platform/psp/osys_psp.cpp1
-rw-r--r--backends/platform/psp/psp_main.cpp5
-rw-r--r--backends/platform/psp/pspkeyboard.cpp14
-rw-r--r--backends/platform/psp/pspkeyboard.h2
-rw-r--r--backends/platform/psp/trace.cpp6
-rw-r--r--backends/platform/psp/trace.h103
13 files changed, 134 insertions, 71 deletions
diff --git a/backends/platform/psp/cursor.cpp b/backends/platform/psp/cursor.cpp
index abd9166f7a..ae3b8f0050 100644
--- a/backends/platform/psp/cursor.cpp
+++ b/backends/platform/psp/cursor.cpp
@@ -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"
diff --git a/backends/platform/psp/default_display_client.cpp b/backends/platform/psp/default_display_client.cpp
index b6ce08ca49..4aa4f88c51 100644
--- a/backends/platform/psp/default_display_client.cpp
+++ b/backends/platform/psp/default_display_client.cpp
@@ -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"
diff --git a/backends/platform/psp/display_client.cpp b/backends/platform/psp/display_client.cpp
index ab4e649708..90c41e796d 100644
--- a/backends/platform/psp/display_client.cpp
+++ b/backends/platform/psp/display_client.cpp
@@ -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"
diff --git a/backends/platform/psp/display_client.h b/backends/platform/psp/display_client.h
index 8d0f827415..d05b0b046c 100644
--- a/backends/platform/psp/display_client.h
+++ b/backends/platform/psp/display_client.h
@@ -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
diff --git a/backends/platform/psp/display_manager.cpp b/backends/platform/psp/display_manager.cpp
index c11604c273..8d2ec597af 100644
--- a/backends/platform/psp/display_manager.cpp
+++ b/backends/platform/psp/display_manager.cpp
@@ -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 @@ const OSystem::GraphicsMode DisplayManager::_supportedModes[] = {
{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 @@ void MasterGuRenderer::guProgramDisplayBufferSizes() {
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 @@ inline void MasterGuRenderer::guPostRender() {
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 @@ inline void MasterGuRenderer::guPostRender() {
sceDisplayWaitVblankStart();
sceGuSwapBuffers();
+ _renderFinished = true;
+#endif /* !USE_DISPLAY_CALLBACK */
}
void MasterGuRenderer::guShutDown() {
@@ -164,11 +209,15 @@ void DisplayManager::init() {
_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::calculateScaleParams() {
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()) &&
diff --git a/backends/platform/psp/display_manager.h b/backends/platform/psp/display_manager.h
index 54b4b78938..6b81c69b72 100644
--- a/backends/platform/psp/display_manager.h
+++ b/backends/platform/psp/display_manager.h
@@ -36,10 +36,15 @@ public:
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;
diff --git a/backends/platform/psp/input.cpp b/backends/platform/psp/input.cpp
index 6e747a430f..4fe7cb3f92 100644
--- a/backends/platform/psp/input.cpp
+++ b/backends/platform/psp/input.cpp
@@ -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
diff --git a/backends/platform/psp/osys_psp.cpp b/backends/platform/psp/osys_psp.cpp
index db1f9fb716..58d98bc219 100644
--- a/backends/platform/psp/osys_psp.cpp
+++ b/backends/platform/psp/osys_psp.cpp
@@ -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"
diff --git a/backends/platform/psp/psp_main.cpp b/backends/platform/psp/psp_main.cpp
index 5a14abf4f7..e568184990 100644
--- a/backends/platform/psp/psp_main.cpp
+++ b/backends/platform/psp/psp_main.cpp
@@ -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>
diff --git a/backends/platform/psp/pspkeyboard.cpp b/backends/platform/psp/pspkeyboard.cpp
index 5cd46789a8..eb081fc5f4 100644
--- a/backends/platform/psp/pspkeyboard.cpp
+++ b/backends/platform/psp/pspkeyboard.cpp
@@ -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)))
diff --git a/backends/platform/psp/pspkeyboard.h b/backends/platform/psp/pspkeyboard.h
index 072bec6c27..a30e7d0f32 100644
--- a/backends/platform/psp/pspkeyboard.h
+++ b/backends/platform/psp/pspkeyboard.h
@@ -76,7 +76,7 @@ private:
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);
diff --git a/backends/platform/psp/trace.cpp b/backends/platform/psp/trace.cpp
index 872e1aabf4..4bf5450177 100644
--- a/backends/platform/psp/trace.cpp
+++ b/backends/platform/psp/trace.cpp
@@ -23,11 +23,11 @@
*
*/
-#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;
diff --git a/backends/platform/psp/trace.h b/backends/platform/psp/trace.h
index 5bb861e32d..1aad0f6781 100644
--- a/backends/platform/psp/trace.h
+++ b/backends/platform/psp/trace.h
@@ -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>
-
-// 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
+#include "common/str.h"
/* 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 @@ extern int psp_debug_indent;
#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)
-
-#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__ */
+void PSPDebugTrace(bool alsoToScreen, const char *format, ...);
-/* Debugging function calls */
-#ifdef __PSP_DEBUG_FUNCS__
+extern int psp_debug_indent;
// 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 @@ public:
}
};
+#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 @@ public:
#undef __PSP_PRINT_TO_FILE_AND_SCREEN__
#undef __PSP_DEBUG_FUNCS__
#undef __PSP_DEBUG_PRINT__
-
-#endif /* TRACE_H */