From: <man...@us...> - 2013-04-10 20:55:22
|
Revision: 1821 http://sourceforge.net/p/modplug/code/1821 Author: manxorist Date: 2013-04-10 20:55:15 +0000 (Wed, 10 Apr 2013) Log Message: ----------- [Imp] Speed up vu-meter drawing by using FillSolidRect instead of LineTo. In global vu-meter, only redraw the segments that actually changed since last update. Modified Paths: -------------- trunk/OpenMPT/mptrack/Ctrl_gen.cpp trunk/OpenMPT/mptrack/Ctrl_gen.h trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mainbar.cpp trunk/OpenMPT/mptrack/Mainbar.h trunk/OpenMPT/mptrack/Mainfrm.h Modified: trunk/OpenMPT/mptrack/Ctrl_gen.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_gen.cpp 2013-04-10 20:51:55 UTC (rev 1820) +++ trunk/OpenMPT/mptrack/Ctrl_gen.cpp 2013-04-10 20:55:15 UTC (rev 1821) @@ -604,11 +604,10 @@ { CRect rect; CPaintDC dc(this); - HDC hdc = dc.m_hDC; GetClientRect(&rect); - FillRect(hdc, &rect, CMainFrame::brushBlack); + dc.FillSolidRect(rect.left, rect.top, rect.Width(), rect.Height(), RGB(0,0,0)); m_nDisplayedVu = -1; - DrawVuMeter(hdc); + DrawVuMeter(dc, true); } @@ -623,22 +622,23 @@ if(curTime - lastVuUpdateTime >= TrackerSettings::Instance().VuMeterUpdateInterval || force) { CClientDC dc(this); - DrawVuMeter(dc.m_hDC); + DrawVuMeter(dc); lastVuUpdateTime = curTime; } } } -VOID CVuMeter::DrawVuMeter(HDC hdc) -//--------------------------------- +VOID CVuMeter::DrawVuMeter(CDC &dc, bool redraw) +//---------------------------------------------- { LONG vu; + LONG lastvu; CRect rect; GetClientRect(&rect); - HGDIOBJ oldpen = SelectObject(hdc, CMainFrame::penBlack); vu = (m_nVuMeter * (rect.bottom-rect.top)) >> 8; + lastvu = (m_nDisplayedVu * (rect.bottom-rect.top)) >> 8; int cy = rect.bottom - rect.top; if (cy < 1) cy = 1; for (int ry=rect.bottom-1; ry>rect.top; ry-=2) @@ -647,11 +647,8 @@ int n = Clamp((y0 * NUM_VUMETER_PENS) / cy, 0, NUM_VUMETER_PENS - 1); if (vu < y0) n += NUM_VUMETER_PENS; - - SelectObject(hdc, CMainFrame::gpenVuMeter[n]); - MoveToEx(hdc, rect.left, ry, NULL); - LineTo(hdc, rect.right, ry); + dc.FillSolidRect(rect.left, ry, rect.Width(), 1, CMainFrame::gcolrefVuMeter[n]); } - SelectObject(hdc, oldpen); m_nDisplayedVu = m_nVuMeter; } + Modified: trunk/OpenMPT/mptrack/Ctrl_gen.h =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_gen.h 2013-04-10 20:51:55 UTC (rev 1820) +++ trunk/OpenMPT/mptrack/Ctrl_gen.h 2013-04-10 20:55:15 UTC (rev 1821) @@ -24,7 +24,7 @@ VOID SetVuMeter(LONG lVuMeter, bool force=false); protected: - VOID DrawVuMeter(HDC hdc); + VOID DrawVuMeter(CDC &dc, bool redraw=false); protected: afx_msg void OnPaint(); Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-04-10 20:51:55 UTC (rev 1820) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-04-10 20:55:15 UTC (rev 1821) @@ -157,7 +157,7 @@ LPMODPLUGDIB CMainFrame::bmpVUMeters = NULL; LPMODPLUGDIB CMainFrame::bmpVisNode = NULL; LPMODPLUGDIB CMainFrame::bmpVisPcNode = NULL; -HPEN CMainFrame::gpenVuMeter[NUM_VUMETER_PENS*2]; +COLORREF CMainFrame::gcolrefVuMeter[NUM_VUMETER_PENS*2]; CInputHandler *CMainFrame::m_InputHandler = nullptr; //rewbs.customKeys CAutoSaver *CMainFrame::m_pAutoSaver = nullptr; //rewbs.autosave @@ -207,7 +207,7 @@ m_TotalSamplesRendered = 0; m_PendingNotificationSempahore = NULL; - MemsetZero(gpenVuMeter); + MemsetZero(gcolrefVuMeter); // Create Audio Critical Section MemsetZero(g_csAudio); @@ -453,10 +453,6 @@ DeleteGDIObject(penGraycc); DeleteGDIObject(penGrayff); - for (UINT i=0; i<NUM_VUMETER_PENS*2; i++) - { - DeleteGDIObject(gpenVuMeter[i]); - } #undef DeleteGDIObject return CMDIFrameWnd::DestroyWindow(); @@ -1209,11 +1205,6 @@ int r, g, b; int y; - if (gpenVuMeter[i]) - { - DeleteObject(gpenVuMeter[i]); - gpenVuMeter[i] = NULL; - } y = (i >= NUM_VUMETER_PENS) ? (i-NUM_VUMETER_PENS) : i; if (y < (NUM_VUMETER_PENS/2)) { @@ -1242,7 +1233,7 @@ g = (g*2)/5; b = (b*2)/5; } - gpenVuMeter[i] = CreatePen(PS_SOLID, 0, RGB(r, g, b)); + gcolrefVuMeter[i] = RGB(r, g, b); } // Sequence window { Modified: trunk/OpenMPT/mptrack/Mainbar.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mainbar.cpp 2013-04-10 20:51:55 UTC (rev 1820) +++ trunk/OpenMPT/mptrack/Mainbar.cpp 2013-04-10 20:55:15 UTC (rev 1821) @@ -1095,10 +1095,9 @@ { CRect rect; CPaintDC dc(this); - HDC hdc = dc.m_hDC; GetClientRect(&rect); - FillRect(hdc, &rect, CMainFrame::brushBlack); - DrawVuMeters(hdc); + dc.FillSolidRect(rect.left, rect.top, rect.Width(), rect.Height(), RGB(0,0,0)); + DrawVuMeters(dc, true); } @@ -1113,7 +1112,7 @@ if(curTime - lastVuUpdateTime >= TrackerSettings::Instance().VuMeterUpdateInterval || force) { CClientDC dc(this); - DrawVuMeters(dc.m_hDC); + DrawVuMeters(dc); lastVuUpdateTime = curTime; } } @@ -1121,8 +1120,8 @@ // Draw stereo VU -void CStereoVU::DrawVuMeters(HDC hdc) -//----------------------------------- +void CStereoVU::DrawVuMeters(CDC &dc, bool redraw) +//------------------------------------------------ { CRect rect; GetClientRect(&rect); @@ -1142,17 +1141,17 @@ rectR.left = mid + 1; } - HGDIOBJ oldPen = SelectObject(hdc, CMainFrame::penBlack); - DrawVuMeter(hdc, rectL, vuMeter[0]); - DrawVuMeter(hdc, rectR, vuMeter[1]); - SelectObject(hdc, oldPen); + DrawVuMeter(dc, rectL, 0, redraw); + DrawVuMeter(dc, rectR, 1, redraw); } // Draw a single VU Meter -void CStereoVU::DrawVuMeter(HDC hdc, const CRect &rect, uint32 vu) -//---------------------------------------------------------------- +void CStereoVU::DrawVuMeter(CDC &dc, const CRect &rect, int index, bool redraw) +//----------------------------------------------------------------------------- { + uint32 vu = vuMeter[index]; + if(CMainFrame::GetMainFrame()->GetSoundFilePlaying() == nullptr) { vu = 0; @@ -1175,10 +1174,10 @@ if(v <= rx && (!last || !clip)) pen += NUM_VUMETER_PENS; - SelectObject(hdc, CMainFrame::gpenVuMeter[pen]); - MoveToEx(hdc, rx, rect.top, NULL); - LineTo(hdc, rx, rect.bottom); + bool draw = redraw || (v < lastV[index] && v<=rx && rx<=lastV[index]) || (lastV[index] < v && lastV[index]<=rx && rx<=v); + if(draw) dc.FillSolidRect(rx, rect. top, 1, rect.Height(), CMainFrame::gcolrefVuMeter[pen]); } + lastV[index] = v; } else { const int cy = Util::Max(1, rect.Height()); @@ -1194,10 +1193,10 @@ if(v <= y0 && (!last || !clip)) pen += NUM_VUMETER_PENS; - SelectObject(hdc, CMainFrame::gpenVuMeter[pen]); - MoveToEx(hdc, rect.left, ry, NULL); - LineTo(hdc, rect.right, ry); + bool draw = redraw || (v < lastV[index] && v<=ry && ry<=lastV[index]) || (lastV[index] < v && lastV[index]<=ry && ry<=v); + if(draw) dc.FillSolidRect(rect.left, ry, rect.Width(), 1, CMainFrame::gcolrefVuMeter[pen]); } + lastV[index] = v; } } Modified: trunk/OpenMPT/mptrack/Mainbar.h =================================================================== --- trunk/OpenMPT/mptrack/Mainbar.h 2013-04-10 20:51:55 UTC (rev 1820) +++ trunk/OpenMPT/mptrack/Mainbar.h 2013-04-10 20:55:15 UTC (rev 1821) @@ -17,16 +17,17 @@ protected: uint32 vuMeter[2]; DWORD lastVuUpdateTime; + int lastV[2]; bool horizontal; public: - CStereoVU() { vuMeter[0] = vuMeter[1] = 0; lastVuUpdateTime = timeGetTime(); horizontal = true; } + CStereoVU() { vuMeter[0] = vuMeter[1] = 0; lastVuUpdateTime = timeGetTime(); horizontal = true; lastV[0] = lastV[1] = 0; } void SetVuMeter(uint32 left, uint32 right, bool force=false); void SetOrientation(bool h) { horizontal = h; } protected: - void DrawVuMeters(HDC hdc); - void DrawVuMeter(HDC hdc, const CRect &rect, uint32 vu); + void DrawVuMeters(CDC &dc, bool redraw=false); + void DrawVuMeter(CDC &dc, const CRect &rect, int index, bool redraw=false); protected: afx_msg void OnPaint(); Modified: trunk/OpenMPT/mptrack/Mainfrm.h =================================================================== --- trunk/OpenMPT/mptrack/Mainfrm.h 2013-04-10 20:51:55 UTC (rev 1820) +++ trunk/OpenMPT/mptrack/Mainfrm.h 2013-04-10 20:55:15 UTC (rev 1821) @@ -285,7 +285,7 @@ static HPEN penBlack, penDarkGray, penLightGray, penWhite, penHalfDarkGray, penSample, penEnvelope, penEnvelopeHighlight, penSeparator, penScratch, penGray00, penGray33, penGray40, penGray55, penGray80, penGray99, penGraycc, penGrayff; static HCURSOR curDragging, curNoDrop, curArrow, curNoDrop2, curVSplit; static MODPLUGDIB *bmpPatterns, *bmpNotes, *bmpVUMeters, *bmpVisNode, *bmpVisPcNode; - static HPEN gpenVuMeter[NUM_VUMETER_PENS * 2]; // General tab VU meters + static COLORREF gcolrefVuMeter[NUM_VUMETER_PENS * 2]; // General tab VU meters public: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |