From 922a7ac6f65cec6830458eec3360050b038cee43 Mon Sep 17 00:00:00 2001 From: rogerman Date: Thu, 22 Dec 2016 22:16:56 -0800 Subject: [PATCH] GPU: Consolidate applying the master brightness into one place. --- desmume/src/GPU.cpp | 79 +++++++++++++++++++-------------------------- desmume/src/GPU.h | 5 ++- 2 files changed, 35 insertions(+), 49 deletions(-) diff --git a/desmume/src/GPU.cpp b/desmume/src/GPU.cpp index f97eaa614..4defbf787 100644 --- a/desmume/src/GPU.cpp +++ b/desmume/src/GPU.cpp @@ -4054,20 +4054,6 @@ void GPUEngineBase::_RenderLine_LayerOBJ(GPUEngineCompositorInfo &compInfo, item } } -template -void GPUEngineBase::_RenderLine_MasterBrightness(const size_t l) -{ - const NDSDisplayInfo &dispInfo = GPU->GetDisplayInfo(); - const GPUEngineCompositorInfo &compInfo = this->_currentCompositorInfo[l]; - void *dstColorLine = (this->isLineOutputNative[l]) ? ((u8 *)this->nativeBuffer + (compInfo.line.blockOffsetNative * dispInfo.pixelBytes)) : ((u8 *)this->customBuffer + (compInfo.line.blockOffsetCustom * dispInfo.pixelBytes)); - const size_t pixCount = (this->isLineOutputNative[l]) ? GPU_FRAMEBUFFER_NATIVE_WIDTH : compInfo.line.pixelCount; - - this->ApplyMasterBrightness(dstColorLine, - pixCount, - compInfo.renderState.masterBrightnessMode, - compInfo.renderState.masterBrightnessIntensity); -} - bool GPUEngineBase::WillApplyMasterBrightnessPerScanline() const { return this->_willApplyMasterBrightnessPerScanline; @@ -4078,6 +4064,37 @@ void GPUEngineBase::SetWillApplyMasterBrightnessPerScanline(bool willApply) this->_willApplyMasterBrightnessPerScanline = willApply; } +template +void GPUEngineBase::ApplyMasterBrightness() +{ + if (this->_willApplyMasterBrightnessPerScanline) + { + const bool isNativeSize = (this->nativeLineOutputCount == GPU_FRAMEBUFFER_NATIVE_HEIGHT); + + for (size_t line = 0; line < GPU_FRAMEBUFFER_NATIVE_HEIGHT; line++) + { + const NDSDisplayInfo &dispInfo = GPU->GetDisplayInfo(); + const GPUEngineCompositorInfo &compInfo = this->_currentCompositorInfo[line]; + void *dstColorLine = (isNativeSize) ? ((u8 *)this->nativeBuffer + (compInfo.line.blockOffsetNative * dispInfo.pixelBytes)) : ((u8 *)this->customBuffer + (compInfo.line.blockOffsetCustom * dispInfo.pixelBytes)); + const size_t pixCount = (isNativeSize) ? GPU_FRAMEBUFFER_NATIVE_WIDTH : compInfo.line.pixelCount; + + this->ApplyMasterBrightness(dstColorLine, + pixCount, + compInfo.renderState.masterBrightnessMode, + compInfo.renderState.masterBrightnessIntensity); + } + } + else + { + const GPUEngineCompositorInfo &compInfo = this->_currentCompositorInfo[0]; + + this->ApplyMasterBrightness(this->renderedBuffer, + this->renderedWidth * this->renderedHeight, + compInfo.renderState.masterBrightnessMode, + compInfo.renderState.masterBrightnessIntensity); + } +} + template void GPUEngineBase::ApplyMasterBrightness(void *dst, const size_t pixCount, const GPUMasterBrightMode mode, const u8 intensity) { @@ -5317,11 +5334,6 @@ void GPUEngineA::RenderLine(const size_t l) this->_RenderLine_DisplayCapture(l); } } - - if (this->_willApplyMasterBrightnessPerScanline) - { - this->_RenderLine_MasterBrightness(l); - } } template @@ -6787,11 +6799,6 @@ void GPUEngineB::RenderLine(const size_t l) default: break; } - - if (this->_willApplyMasterBrightnessPerScanline) - { - this->_RenderLine_MasterBrightness(l); - } } GPUSubsystem::GPUSubsystem() @@ -7494,17 +7501,7 @@ void GPUSubsystem::RenderLine(const size_t l, bool isFrameSkipRequested) { if (CommonSettings.showGpu.main) { - if (!this->_engineMain->WillApplyMasterBrightnessPerScanline()) - { - GPUMasterBrightMode mode; - u8 intensity; - - this->_engineMain->GetMasterBrightnessAtLineZero(mode, intensity); - this->_engineMain->ApplyMasterBrightness(this->_engineMain->renderedBuffer, - this->_engineMain->renderedWidth * this->_engineMain->renderedHeight, - mode, - intensity); - } + this->_engineMain->ApplyMasterBrightness(); } else { @@ -7513,17 +7510,7 @@ void GPUSubsystem::RenderLine(const size_t l, bool isFrameSkipRequested) if (CommonSettings.showGpu.sub) { - if (!this->_engineSub->WillApplyMasterBrightnessPerScanline()) - { - GPUMasterBrightMode mode; - u8 intensity; - - this->_engineSub->GetMasterBrightnessAtLineZero(mode, intensity); - this->_engineSub->ApplyMasterBrightness(this->_engineSub->renderedBuffer, - this->_engineSub->renderedWidth * this->_engineSub->renderedHeight, - mode, - intensity); - } + this->_engineSub->ApplyMasterBrightness(); } else { diff --git a/desmume/src/GPU.h b/desmume/src/GPU.h index 63fe95867..8712c1050 100644 --- a/desmume/src/GPU.h +++ b/desmume/src/GPU.h @@ -1359,9 +1359,7 @@ protected: template void _RenderLine_LayerBG(GPUEngineCompositorInfo &compInfo); template void _RenderLine_LayerOBJ(GPUEngineCompositorInfo &compInfo, itemsForPriority_t *__restrict item); - - template void _RenderLine_MasterBrightness(const size_t l); - + template FORCEINLINE void _RenderPixel(GPUEngineCompositorInfo &compInfo, const u16 srcColor16, const u8 srcAlpha); template FORCEINLINE void _RenderPixel3D(GPUEngineCompositorInfo &compInfo, const bool enableColorEffect, const FragmentColor srcColor32); @@ -1477,6 +1475,7 @@ public: bool WillApplyMasterBrightnessPerScanline() const; void SetWillApplyMasterBrightnessPerScanline(bool willApply); + template void ApplyMasterBrightness(); template void ApplyMasterBrightness(void *dst, const size_t pixCount, const GPUMasterBrightMode mode, const u8 intensity); const BGLayerInfo& GetBGLayerInfoByID(const GPULayerID layerID);