Cocoa Port:

- Fixed dimension bug in VideoFilter::RunFilterCustom().
- Do some minor code cleanup of the video filters code.
- Fixed bug in setting GPU layer states where the Main and Sub GPUs were swapped.
- Add DS_DISPLAY_VERTICAL_GAP_TO_HEIGHT_RATIO token.
This commit is contained in:
rogerman 2013-01-09 08:31:21 +00:00
parent c5a389684a
commit a2315eb314
6 changed files with 50 additions and 48 deletions

View File

@ -150,6 +150,8 @@
#define GPU_DISPLAY_COLOR_DEPTH sizeof(UInt16) #define GPU_DISPLAY_COLOR_DEPTH sizeof(UInt16)
#define GPU_SCREEN_SIZE_BYTES (GPU_DISPLAY_WIDTH * GPU_DISPLAY_HEIGHT * GPU_DISPLAY_COLOR_DEPTH) // The numbers are: 256px width, 192px height, 16bit color depth #define GPU_SCREEN_SIZE_BYTES (GPU_DISPLAY_WIDTH * GPU_DISPLAY_HEIGHT * GPU_DISPLAY_COLOR_DEPTH) // The numbers are: 256px width, 192px height, 16bit color depth
#define DS_DISPLAY_VERTICAL_GAP_TO_HEIGHT_RATIO (21.0/46.0) // Based on the official DS specification: 21mm/46mm
#define WINDOW_STATUS_BAR_HEIGHT 24 // Height of an emulation window status bar in pixels. #define WINDOW_STATUS_BAR_HEIGHT 24 // Height of an emulation window status bar in pixels.
#define SPEED_SCALAR_QUARTER 0.25 // Speed scalar for quarter execution speed. #define SPEED_SCALAR_QUARTER 0.25 // Speed scalar for quarter execution speed.

View File

@ -1738,14 +1738,14 @@ bool GetGPULayerState(int gpuType, unsigned int i)
switch (gpuType) switch (gpuType)
{ {
case DS_GPU_TYPE_MAIN: case DS_GPU_TYPE_SUB:
if (SubScreen.gpu != nil) if (SubScreen.gpu != nil)
{ {
result = CommonSettings.dispLayers[SubScreen.gpu->core][i]; result = CommonSettings.dispLayers[SubScreen.gpu->core][i];
} }
break; break;
case DS_GPU_TYPE_SUB: case DS_GPU_TYPE_MAIN:
if (MainScreen.gpu != nil) if (MainScreen.gpu != nil)
{ {
result = CommonSettings.dispLayers[MainScreen.gpu->core][i]; result = CommonSettings.dispLayers[MainScreen.gpu->core][i];
@ -1770,11 +1770,11 @@ void SetGPUDisplayState(int gpuType, bool state)
{ {
switch (gpuType) switch (gpuType)
{ {
case DS_GPU_TYPE_MAIN: case DS_GPU_TYPE_SUB:
CommonSettings.showGpu.sub = state; CommonSettings.showGpu.sub = state;
break; break;
case DS_GPU_TYPE_SUB: case DS_GPU_TYPE_MAIN:
CommonSettings.showGpu.main = state; CommonSettings.showGpu.main = state;
break; break;
@ -1794,11 +1794,11 @@ bool GetGPUDisplayState(int gpuType)
switch (gpuType) switch (gpuType)
{ {
case DS_GPU_TYPE_MAIN: case DS_GPU_TYPE_SUB:
result = CommonSettings.showGpu.sub; result = CommonSettings.showGpu.sub;
break; break;
case DS_GPU_TYPE_SUB: case DS_GPU_TYPE_MAIN:
result = CommonSettings.showGpu.main; result = CommonSettings.showGpu.main;
break; break;

View File

@ -45,7 +45,7 @@
- (VideoFilterTypeID) typeID; - (VideoFilterTypeID) typeID;
- (NSString *) typeString; - (NSString *) typeString;
- (UInt32 *) srcBufferPtr; - (UInt32 *) srcBufferPtr;
- (UInt32 *) destBufferPtr; - (UInt32 *) dstBufferPtr;
- (NSSize) srcSize; - (NSSize) srcSize;
- (NSSize) destSize; - (NSSize) destSize;
+ (NSString *) typeStringByID:(VideoFilterTypeID)typeID; + (NSString *) typeStringByID:(VideoFilterTypeID)typeID;

View File

@ -119,8 +119,8 @@
- (NSBitmapImageRep *) bitmapImageRep - (NSBitmapImageRep *) bitmapImageRep
{ {
NSUInteger w = (NSUInteger)vf->GetDestWidth(); NSUInteger w = (NSUInteger)vf->GetDstWidth();
NSUInteger h = (NSUInteger)vf->GetDestHeight(); NSUInteger h = (NSUInteger)vf->GetDstHeight();
NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:w pixelsWide:w
@ -167,9 +167,9 @@
return (UInt32 *)vf->GetSrcBufferPtr(); return (UInt32 *)vf->GetSrcBufferPtr();
} }
- (UInt32 *) destBufferPtr - (UInt32 *) dstBufferPtr
{ {
return (UInt32 *)vf->GetDestBufferPtr(); return (UInt32 *)vf->GetDstBufferPtr();
} }
- (NSSize) srcSize - (NSSize) srcSize
@ -179,7 +179,7 @@
- (NSSize) destSize - (NSSize) destSize
{ {
return NSMakeSize((CGFloat)vf->GetDestWidth(), (CGFloat)vf->GetDestHeight()); return NSMakeSize((CGFloat)vf->GetDstWidth(), (CGFloat)vf->GetDstHeight());
} }
+ (NSString *) typeStringByID:(VideoFilterTypeID)typeID + (NSString *) typeStringByID:(VideoFilterTypeID)typeID

View File

@ -41,7 +41,7 @@ VideoFilter::VideoFilter(unsigned int srcWidth = 1,
_vfTypeID = typeID; _vfTypeID = typeID;
pthread_mutex_init(&_mutexSrc, NULL); pthread_mutex_init(&_mutexSrc, NULL);
pthread_mutex_init(&_mutexDest, NULL); pthread_mutex_init(&_mutexDst, NULL);
pthread_mutex_init(&_mutexTypeID, NULL); pthread_mutex_init(&_mutexTypeID, NULL);
pthread_mutex_init(&_mutexTypeString, NULL); pthread_mutex_init(&_mutexTypeString, NULL);
pthread_cond_init(&_condRunning, NULL); pthread_cond_init(&_condRunning, NULL);
@ -52,7 +52,7 @@ VideoFilter::VideoFilter(unsigned int srcWidth = 1,
for (unsigned int i = 0; i < numberThreads; i++) for (unsigned int i = 0; i < numberThreads; i++)
{ {
_vfThread[i].param.srcSurface = _vfSrcSurface; _vfThread[i].param.srcSurface = _vfSrcSurface;
_vfThread[i].param.destSurface = _vfDstSurface; _vfThread[i].param.dstSurface = _vfDstSurface;
_vfThread[i].param.filterFunction = NULL; _vfThread[i].param.filterFunction = NULL;
_vfThread[i].task = new Task; _vfThread[i].task = new Task;
@ -79,17 +79,17 @@ VideoFilter::~VideoFilter()
_vfThread.clear(); _vfThread.clear();
// Destroy everything else // Destroy everything else
pthread_mutex_lock(&this->_mutexDest); pthread_mutex_lock(&this->_mutexDst);
while (this->_isFilterRunning) while (this->_isFilterRunning)
{ {
pthread_cond_wait(&this->_condRunning, &this->_mutexDest); pthread_cond_wait(&this->_condRunning, &this->_mutexDst);
} }
free(_vfDstSurface.Surface); free(_vfDstSurface.Surface);
_vfDstSurface.Surface = NULL; _vfDstSurface.Surface = NULL;
pthread_mutex_unlock(&_mutexDest); pthread_mutex_unlock(&_mutexDst);
pthread_mutex_lock(&_mutexSrc); pthread_mutex_lock(&_mutexSrc);
@ -100,7 +100,7 @@ VideoFilter::~VideoFilter()
pthread_mutex_unlock(&_mutexSrc); pthread_mutex_unlock(&_mutexSrc);
pthread_mutex_destroy(&_mutexSrc); pthread_mutex_destroy(&_mutexSrc);
pthread_mutex_destroy(&_mutexDest); pthread_mutex_destroy(&_mutexDst);
pthread_mutex_destroy(&_mutexTypeID); pthread_mutex_destroy(&_mutexTypeID);
pthread_mutex_destroy(&_mutexTypeString); pthread_mutex_destroy(&_mutexTypeString);
pthread_cond_destroy(&_condRunning); pthread_cond_destroy(&_condRunning);
@ -225,7 +225,7 @@ bool VideoFilter::ChangeFilterByAttributes(const VideoFilterAttributes *vfAttr)
const char *typeString = vfAttr->typeString; const char *typeString = vfAttr->typeString;
const VideoFilterFunc filterFunction = vfAttr->filterFunction; const VideoFilterFunc filterFunction = vfAttr->filterFunction;
pthread_mutex_lock(&this->_mutexDest); pthread_mutex_lock(&this->_mutexDst);
uint32_t *newSurfaceBuffer = (uint32_t *)calloc(dstWidth * dstHeight, sizeof(uint32_t)); uint32_t *newSurfaceBuffer = (uint32_t *)calloc(dstWidth * dstHeight, sizeof(uint32_t));
if (newSurfaceBuffer == NULL) if (newSurfaceBuffer == NULL)
@ -246,20 +246,20 @@ bool VideoFilter::ChangeFilterByAttributes(const VideoFilterAttributes *vfAttr)
for (unsigned int i = 0; i < threadCount; i++) for (unsigned int i = 0; i < threadCount; i++)
{ {
SSurface &threadDstSurface = this->_vfThread[i].param.destSurface; SSurface &threadDstSurface = this->_vfThread[i].param.dstSurface;
threadDstSurface = this->_vfDstSurface; threadDstSurface = this->_vfDstSurface;
threadDstSurface.Height /= threadCount; threadDstSurface.Height /= threadCount;
if (i > 0) if (i > 0)
{ {
SSurface &prevThreadDstSurface = this->_vfThread[i - 1].param.destSurface; SSurface &prevThreadDstSurface = this->_vfThread[i - 1].param.dstSurface;
threadDstSurface.Surface = (unsigned char *)((uint32_t *)prevThreadDstSurface.Surface + (prevThreadDstSurface.Width * prevThreadDstSurface.Height)); threadDstSurface.Surface = (unsigned char *)((uint32_t *)prevThreadDstSurface.Surface + (prevThreadDstSurface.Width * prevThreadDstSurface.Height));
} }
this->_vfThread[i].param.filterFunction = this->_vfFunc; this->_vfThread[i].param.filterFunction = this->_vfFunc;
} }
pthread_mutex_unlock(&this->_mutexDest); pthread_mutex_unlock(&this->_mutexDst);
this->SetTypeID(typeID); this->SetTypeID(typeID);
this->SetTypeString(typeString); this->SetTypeString(typeString);
@ -283,7 +283,7 @@ bool VideoFilter::ChangeFilterByAttributes(const VideoFilterAttributes *vfAttr)
********************************************************************************************/ ********************************************************************************************/
uint32_t* VideoFilter::RunFilter() uint32_t* VideoFilter::RunFilter()
{ {
pthread_mutex_lock(&this->_mutexDest); pthread_mutex_lock(&this->_mutexDst);
this->_isFilterRunning = true; this->_isFilterRunning = true;
uint32_t *destBufPtr = (uint32_t *)this->_vfDstSurface.Surface; uint32_t *destBufPtr = (uint32_t *)this->_vfDstSurface.Surface;
@ -302,7 +302,7 @@ uint32_t* VideoFilter::RunFilter()
{ {
for (unsigned int i = 0; i < threadCount; i++) for (unsigned int i = 0; i < threadCount; i++)
{ {
this->_vfThread[i].task->execute(RunVideoFilterTask, &this->_vfThread[i].param); this->_vfThread[i].task->execute(&RunVideoFilterTask, &this->_vfThread[i].param);
} }
for (unsigned int i = 0; i < threadCount; i++) for (unsigned int i = 0; i < threadCount; i++)
@ -320,7 +320,7 @@ uint32_t* VideoFilter::RunFilter()
this->_isFilterRunning = false; this->_isFilterRunning = false;
pthread_cond_signal(&this->_condRunning); pthread_cond_signal(&this->_condRunning);
pthread_mutex_unlock(&this->_mutexDest); pthread_mutex_unlock(&this->_mutexDst);
return destBufPtr; return destBufPtr;
} }
@ -362,7 +362,7 @@ void VideoFilter::RunFilterCustom(const uint32_t *__restrict__ srcBuffer, uint32
const VideoFilterAttributes *vfAttr = &VideoFilterAttributesList[typeID]; const VideoFilterAttributes *vfAttr = &VideoFilterAttributesList[typeID];
const unsigned int dstWidth = srcWidth * vfAttr->scaleMultiply / vfAttr->scaleDivide; const unsigned int dstWidth = srcWidth * vfAttr->scaleMultiply / vfAttr->scaleDivide;
const unsigned int dstHeight = dstWidth * vfAttr->scaleMultiply / vfAttr->scaleDivide; const unsigned int dstHeight = srcHeight * vfAttr->scaleMultiply / vfAttr->scaleDivide;
const VideoFilterFunc filterFunction = vfAttr->filterFunction; const VideoFilterFunc filterFunction = vfAttr->filterFunction;
SSurface srcSurface = {(unsigned char *)srcBuffer, srcWidth*2, srcWidth, srcHeight}; SSurface srcSurface = {(unsigned char *)srcBuffer, srcWidth*2, srcWidth, srcHeight};
@ -450,11 +450,11 @@ uint32_t* VideoFilter::GetSrcBufferPtr()
return ptr; return ptr;
} }
uint32_t* VideoFilter::GetDestBufferPtr() uint32_t* VideoFilter::GetDstBufferPtr()
{ {
pthread_mutex_lock(&this->_mutexDest); pthread_mutex_lock(&this->_mutexDst);
uint32_t *ptr = (uint32_t *)this->_vfDstSurface.Surface; uint32_t *ptr = (uint32_t *)this->_vfDstSurface.Surface;
pthread_mutex_unlock(&this->_mutexDest); pthread_mutex_unlock(&this->_mutexDst);
return ptr; return ptr;
} }
@ -477,20 +477,20 @@ unsigned int VideoFilter::GetSrcHeight()
return height; return height;
} }
unsigned int VideoFilter::GetDestWidth() unsigned int VideoFilter::GetDstWidth()
{ {
pthread_mutex_lock(&this->_mutexDest); pthread_mutex_lock(&this->_mutexDst);
unsigned int width = this->_vfDstSurface.Width; unsigned int width = this->_vfDstSurface.Width;
pthread_mutex_unlock(&this->_mutexDest); pthread_mutex_unlock(&this->_mutexDst);
return width; return width;
} }
unsigned int VideoFilter::GetDestHeight() unsigned int VideoFilter::GetDstHeight()
{ {
pthread_mutex_lock(&this->_mutexDest); pthread_mutex_lock(&this->_mutexDst);
unsigned int height = this->_vfDstSurface.Height; unsigned int height = this->_vfDstSurface.Height;
pthread_mutex_unlock(&this->_mutexDest); pthread_mutex_unlock(&this->_mutexDst);
return height; return height;
} }
@ -500,7 +500,7 @@ static void* RunVideoFilterTask(void *arg)
{ {
VideoFilterThreadParam *param = (VideoFilterThreadParam *)arg; VideoFilterThreadParam *param = (VideoFilterThreadParam *)arg;
param->filterFunction(param->srcSurface, param->destSurface); param->filterFunction(param->srcSurface, param->dstSurface);
return NULL; return NULL;
} }

View File

@ -69,11 +69,11 @@ typedef struct
// Attributes list of known video filters, indexed using VideoFilterTypeID. // Attributes list of known video filters, indexed using VideoFilterTypeID.
const VideoFilterAttributes VideoFilterAttributesList[] = { const VideoFilterAttributes VideoFilterAttributesList[] = {
{VideoFilterTypeID_None, "None", NULL, 1, 1}, {VideoFilterTypeID_None, "None", NULL, 1, 1},
{VideoFilterTypeID_LQ2X, "LQ2X", &RenderLQ2X, 2, 1}, {VideoFilterTypeID_LQ2X, "LQ2x", &RenderLQ2X, 2, 1},
{VideoFilterTypeID_LQ2XS, "LQ2XS", &RenderLQ2XS, 2, 1}, {VideoFilterTypeID_LQ2XS, "LQ2xS", &RenderLQ2XS, 2, 1},
{VideoFilterTypeID_HQ2X, "HQ2X", &RenderHQ2X, 2, 1}, {VideoFilterTypeID_HQ2X, "HQ2x", &RenderHQ2X, 2, 1},
{VideoFilterTypeID_HQ2XS, "HQ2XS", &RenderHQ2XS, 2, 1}, {VideoFilterTypeID_HQ2XS, "HQ2xS", &RenderHQ2XS, 2, 1},
{VideoFilterTypeID_HQ4X, "HQ4X", &RenderHQ4X, 4, 1}, {VideoFilterTypeID_HQ4X, "HQ4x", &RenderHQ4X, 4, 1},
{VideoFilterTypeID_2xSaI, "2xSaI", &Render2xSaI, 2, 1}, {VideoFilterTypeID_2xSaI, "2xSaI", &Render2xSaI, 2, 1},
{VideoFilterTypeID_Super2xSaI, "Super 2xSaI", &RenderSuper2xSaI, 2, 1}, {VideoFilterTypeID_Super2xSaI, "Super 2xSaI", &RenderSuper2xSaI, 2, 1},
{VideoFilterTypeID_SuperEagle, "Super Eagle", &RenderSuperEagle, 2, 1}, {VideoFilterTypeID_SuperEagle, "Super Eagle", &RenderSuperEagle, 2, 1},
@ -86,13 +86,13 @@ const VideoFilterAttributes VideoFilterAttributesList[] = {
{VideoFilterTypeID_EPXPlus, "EPX+", &RenderEPXPlus, 2, 1}, {VideoFilterTypeID_EPXPlus, "EPX+", &RenderEPXPlus, 2, 1},
{VideoFilterTypeID_EPX1_5X, "EPX 1.5x", &RenderEPX_1Point5x, 3, 2}, {VideoFilterTypeID_EPX1_5X, "EPX 1.5x", &RenderEPX_1Point5x, 3, 2},
{VideoFilterTypeID_EPXPlus1_5X, "EPX+ 1.5x", &RenderEPXPlus_1Point5x, 3, 2}, {VideoFilterTypeID_EPXPlus1_5X, "EPX+ 1.5x", &RenderEPXPlus_1Point5x, 3, 2},
{VideoFilterTypeID_HQ4XS, "HQ4XS", &RenderHQ4XS, 4, 1} }; {VideoFilterTypeID_HQ4XS, "HQ4xS", &RenderHQ4XS, 4, 1} };
// Parameters struct for IPC // Parameters struct for IPC
typedef struct typedef struct
{ {
SSurface srcSurface; SSurface srcSurface;
SSurface destSurface; SSurface dstSurface;
VideoFilterFunc filterFunction; VideoFilterFunc filterFunction;
} VideoFilterThreadParam; } VideoFilterThreadParam;
@ -118,7 +118,7 @@ typedef struct
and then stores the resulting pixels into the destination buffer in RGBA8888 and then stores the resulting pixels into the destination buffer in RGBA8888
format. format.
6. At this point, the destination buffer pixels can be used. RunFilter() returns 6. At this point, the destination buffer pixels can be used. RunFilter() returns
a pointer to the destination buffer. Alternatively, GetDestBufferPtr() can be a pointer to the destination buffer. Alternatively, GetDstBufferPtr() can be
used to get the pointer. used to get the pointer.
Thread Safety: Thread Safety:
@ -138,7 +138,7 @@ private:
bool _isFilterRunning; bool _isFilterRunning;
pthread_mutex_t _mutexSrc; pthread_mutex_t _mutexSrc;
pthread_mutex_t _mutexDest; pthread_mutex_t _mutexDst;
pthread_mutex_t _mutexTypeID; pthread_mutex_t _mutexTypeID;
pthread_mutex_t _mutexTypeString; pthread_mutex_t _mutexTypeString;
pthread_cond_t _condRunning; pthread_cond_t _condRunning;
@ -162,11 +162,11 @@ public:
VideoFilterTypeID GetTypeID(); VideoFilterTypeID GetTypeID();
const char* GetTypeString(); const char* GetTypeString();
uint32_t* GetSrcBufferPtr(); uint32_t* GetSrcBufferPtr();
uint32_t* GetDestBufferPtr(); uint32_t* GetDstBufferPtr();
unsigned int GetSrcWidth(); unsigned int GetSrcWidth();
unsigned int GetSrcHeight(); unsigned int GetSrcHeight();
unsigned int GetDestWidth(); unsigned int GetDstWidth();
unsigned int GetDestHeight(); unsigned int GetDstHeight();
}; };
static void* RunVideoFilterTask(void *arg); static void* RunVideoFilterTask(void *arg);