diff --git a/desmume/src/cocoa/cocoa_globals.h b/desmume/src/cocoa/cocoa_globals.h index d761327a2..34c339186 100644 --- a/desmume/src/cocoa/cocoa_globals.h +++ b/desmume/src/cocoa/cocoa_globals.h @@ -150,6 +150,8 @@ #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 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 SPEED_SCALAR_QUARTER 0.25 // Speed scalar for quarter execution speed. diff --git a/desmume/src/cocoa/cocoa_output.mm b/desmume/src/cocoa/cocoa_output.mm index 48d25d650..b3e29f1b4 100644 --- a/desmume/src/cocoa/cocoa_output.mm +++ b/desmume/src/cocoa/cocoa_output.mm @@ -1738,14 +1738,14 @@ bool GetGPULayerState(int gpuType, unsigned int i) switch (gpuType) { - case DS_GPU_TYPE_MAIN: + case DS_GPU_TYPE_SUB: if (SubScreen.gpu != nil) { result = CommonSettings.dispLayers[SubScreen.gpu->core][i]; } break; - case DS_GPU_TYPE_SUB: + case DS_GPU_TYPE_MAIN: if (MainScreen.gpu != nil) { result = CommonSettings.dispLayers[MainScreen.gpu->core][i]; @@ -1770,11 +1770,11 @@ void SetGPUDisplayState(int gpuType, bool state) { switch (gpuType) { - case DS_GPU_TYPE_MAIN: + case DS_GPU_TYPE_SUB: CommonSettings.showGpu.sub = state; break; - case DS_GPU_TYPE_SUB: + case DS_GPU_TYPE_MAIN: CommonSettings.showGpu.main = state; break; @@ -1794,11 +1794,11 @@ bool GetGPUDisplayState(int gpuType) switch (gpuType) { - case DS_GPU_TYPE_MAIN: + case DS_GPU_TYPE_SUB: result = CommonSettings.showGpu.sub; break; - case DS_GPU_TYPE_SUB: + case DS_GPU_TYPE_MAIN: result = CommonSettings.showGpu.main; break; diff --git a/desmume/src/cocoa/cocoa_videofilter.h b/desmume/src/cocoa/cocoa_videofilter.h index 5079b8d09..30f7490f6 100644 --- a/desmume/src/cocoa/cocoa_videofilter.h +++ b/desmume/src/cocoa/cocoa_videofilter.h @@ -45,7 +45,7 @@ - (VideoFilterTypeID) typeID; - (NSString *) typeString; - (UInt32 *) srcBufferPtr; -- (UInt32 *) destBufferPtr; +- (UInt32 *) dstBufferPtr; - (NSSize) srcSize; - (NSSize) destSize; + (NSString *) typeStringByID:(VideoFilterTypeID)typeID; diff --git a/desmume/src/cocoa/cocoa_videofilter.mm b/desmume/src/cocoa/cocoa_videofilter.mm index ef17ad942..bc53bab39 100644 --- a/desmume/src/cocoa/cocoa_videofilter.mm +++ b/desmume/src/cocoa/cocoa_videofilter.mm @@ -119,8 +119,8 @@ - (NSBitmapImageRep *) bitmapImageRep { - NSUInteger w = (NSUInteger)vf->GetDestWidth(); - NSUInteger h = (NSUInteger)vf->GetDestHeight(); + NSUInteger w = (NSUInteger)vf->GetDstWidth(); + NSUInteger h = (NSUInteger)vf->GetDstHeight(); NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:w @@ -167,9 +167,9 @@ return (UInt32 *)vf->GetSrcBufferPtr(); } -- (UInt32 *) destBufferPtr +- (UInt32 *) dstBufferPtr { - return (UInt32 *)vf->GetDestBufferPtr(); + return (UInt32 *)vf->GetDstBufferPtr(); } - (NSSize) srcSize @@ -179,7 +179,7 @@ - (NSSize) destSize { - return NSMakeSize((CGFloat)vf->GetDestWidth(), (CGFloat)vf->GetDestHeight()); + return NSMakeSize((CGFloat)vf->GetDstWidth(), (CGFloat)vf->GetDstHeight()); } + (NSString *) typeStringByID:(VideoFilterTypeID)typeID diff --git a/desmume/src/cocoa/videofilter.cpp b/desmume/src/cocoa/videofilter.cpp index ba0ed9145..e1c5df998 100644 --- a/desmume/src/cocoa/videofilter.cpp +++ b/desmume/src/cocoa/videofilter.cpp @@ -41,7 +41,7 @@ VideoFilter::VideoFilter(unsigned int srcWidth = 1, _vfTypeID = typeID; pthread_mutex_init(&_mutexSrc, NULL); - pthread_mutex_init(&_mutexDest, NULL); + pthread_mutex_init(&_mutexDst, NULL); pthread_mutex_init(&_mutexTypeID, NULL); pthread_mutex_init(&_mutexTypeString, NULL); pthread_cond_init(&_condRunning, NULL); @@ -52,7 +52,7 @@ VideoFilter::VideoFilter(unsigned int srcWidth = 1, for (unsigned int i = 0; i < numberThreads; i++) { _vfThread[i].param.srcSurface = _vfSrcSurface; - _vfThread[i].param.destSurface = _vfDstSurface; + _vfThread[i].param.dstSurface = _vfDstSurface; _vfThread[i].param.filterFunction = NULL; _vfThread[i].task = new Task; @@ -79,17 +79,17 @@ VideoFilter::~VideoFilter() _vfThread.clear(); // Destroy everything else - pthread_mutex_lock(&this->_mutexDest); + pthread_mutex_lock(&this->_mutexDst); while (this->_isFilterRunning) { - pthread_cond_wait(&this->_condRunning, &this->_mutexDest); + pthread_cond_wait(&this->_condRunning, &this->_mutexDst); } free(_vfDstSurface.Surface); _vfDstSurface.Surface = NULL; - pthread_mutex_unlock(&_mutexDest); + pthread_mutex_unlock(&_mutexDst); pthread_mutex_lock(&_mutexSrc); @@ -100,7 +100,7 @@ VideoFilter::~VideoFilter() pthread_mutex_unlock(&_mutexSrc); pthread_mutex_destroy(&_mutexSrc); - pthread_mutex_destroy(&_mutexDest); + pthread_mutex_destroy(&_mutexDst); pthread_mutex_destroy(&_mutexTypeID); pthread_mutex_destroy(&_mutexTypeString); pthread_cond_destroy(&_condRunning); @@ -225,7 +225,7 @@ bool VideoFilter::ChangeFilterByAttributes(const VideoFilterAttributes *vfAttr) const char *typeString = vfAttr->typeString; 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)); if (newSurfaceBuffer == NULL) @@ -246,20 +246,20 @@ bool VideoFilter::ChangeFilterByAttributes(const VideoFilterAttributes *vfAttr) 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.Height /= threadCount; 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)); } this->_vfThread[i].param.filterFunction = this->_vfFunc; } - pthread_mutex_unlock(&this->_mutexDest); + pthread_mutex_unlock(&this->_mutexDst); this->SetTypeID(typeID); this->SetTypeString(typeString); @@ -283,7 +283,7 @@ bool VideoFilter::ChangeFilterByAttributes(const VideoFilterAttributes *vfAttr) ********************************************************************************************/ uint32_t* VideoFilter::RunFilter() { - pthread_mutex_lock(&this->_mutexDest); + pthread_mutex_lock(&this->_mutexDst); this->_isFilterRunning = true; uint32_t *destBufPtr = (uint32_t *)this->_vfDstSurface.Surface; @@ -302,7 +302,7 @@ uint32_t* VideoFilter::RunFilter() { 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++) @@ -320,7 +320,7 @@ uint32_t* VideoFilter::RunFilter() this->_isFilterRunning = false; pthread_cond_signal(&this->_condRunning); - pthread_mutex_unlock(&this->_mutexDest); + pthread_mutex_unlock(&this->_mutexDst); return destBufPtr; } @@ -362,7 +362,7 @@ void VideoFilter::RunFilterCustom(const uint32_t *__restrict__ srcBuffer, uint32 const VideoFilterAttributes *vfAttr = &VideoFilterAttributesList[typeID]; 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; SSurface srcSurface = {(unsigned char *)srcBuffer, srcWidth*2, srcWidth, srcHeight}; @@ -450,11 +450,11 @@ uint32_t* VideoFilter::GetSrcBufferPtr() 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; - pthread_mutex_unlock(&this->_mutexDest); + pthread_mutex_unlock(&this->_mutexDst); return ptr; } @@ -477,20 +477,20 @@ unsigned int VideoFilter::GetSrcHeight() 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; - pthread_mutex_unlock(&this->_mutexDest); + pthread_mutex_unlock(&this->_mutexDst); 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; - pthread_mutex_unlock(&this->_mutexDest); + pthread_mutex_unlock(&this->_mutexDst); return height; } @@ -500,7 +500,7 @@ static void* RunVideoFilterTask(void *arg) { VideoFilterThreadParam *param = (VideoFilterThreadParam *)arg; - param->filterFunction(param->srcSurface, param->destSurface); + param->filterFunction(param->srcSurface, param->dstSurface); return NULL; } diff --git a/desmume/src/cocoa/videofilter.h b/desmume/src/cocoa/videofilter.h index 87d141960..83770793a 100644 --- a/desmume/src/cocoa/videofilter.h +++ b/desmume/src/cocoa/videofilter.h @@ -69,11 +69,11 @@ typedef struct // Attributes list of known video filters, indexed using VideoFilterTypeID. const VideoFilterAttributes VideoFilterAttributesList[] = { {VideoFilterTypeID_None, "None", NULL, 1, 1}, - {VideoFilterTypeID_LQ2X, "LQ2X", &RenderLQ2X, 2, 1}, - {VideoFilterTypeID_LQ2XS, "LQ2XS", &RenderLQ2XS, 2, 1}, - {VideoFilterTypeID_HQ2X, "HQ2X", &RenderHQ2X, 2, 1}, - {VideoFilterTypeID_HQ2XS, "HQ2XS", &RenderHQ2XS, 2, 1}, - {VideoFilterTypeID_HQ4X, "HQ4X", &RenderHQ4X, 4, 1}, + {VideoFilterTypeID_LQ2X, "LQ2x", &RenderLQ2X, 2, 1}, + {VideoFilterTypeID_LQ2XS, "LQ2xS", &RenderLQ2XS, 2, 1}, + {VideoFilterTypeID_HQ2X, "HQ2x", &RenderHQ2X, 2, 1}, + {VideoFilterTypeID_HQ2XS, "HQ2xS", &RenderHQ2XS, 2, 1}, + {VideoFilterTypeID_HQ4X, "HQ4x", &RenderHQ4X, 4, 1}, {VideoFilterTypeID_2xSaI, "2xSaI", &Render2xSaI, 2, 1}, {VideoFilterTypeID_Super2xSaI, "Super 2xSaI", &RenderSuper2xSaI, 2, 1}, {VideoFilterTypeID_SuperEagle, "Super Eagle", &RenderSuperEagle, 2, 1}, @@ -86,13 +86,13 @@ const VideoFilterAttributes VideoFilterAttributesList[] = { {VideoFilterTypeID_EPXPlus, "EPX+", &RenderEPXPlus, 2, 1}, {VideoFilterTypeID_EPX1_5X, "EPX 1.5x", &RenderEPX_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 typedef struct { SSurface srcSurface; - SSurface destSurface; + SSurface dstSurface; VideoFilterFunc filterFunction; } VideoFilterThreadParam; @@ -118,7 +118,7 @@ typedef struct and then stores the resulting pixels into the destination buffer in RGBA8888 format. 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. Thread Safety: @@ -138,7 +138,7 @@ private: bool _isFilterRunning; pthread_mutex_t _mutexSrc; - pthread_mutex_t _mutexDest; + pthread_mutex_t _mutexDst; pthread_mutex_t _mutexTypeID; pthread_mutex_t _mutexTypeString; pthread_cond_t _condRunning; @@ -162,11 +162,11 @@ public: VideoFilterTypeID GetTypeID(); const char* GetTypeString(); uint32_t* GetSrcBufferPtr(); - uint32_t* GetDestBufferPtr(); + uint32_t* GetDstBufferPtr(); unsigned int GetSrcWidth(); unsigned int GetSrcHeight(); - unsigned int GetDestWidth(); - unsigned int GetDestHeight(); + unsigned int GetDstWidth(); + unsigned int GetDstHeight(); }; static void* RunVideoFilterTask(void *arg);