From c6374f7c12ef43dbed5ce6d7ae829d3cd43152e4 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Wed, 27 Mar 2013 18:14:27 +0200 Subject: [PATCH] Minor tweaks and fixes --- Common/Gfx/CanvasD2D.cpp | 6 +++--- Common/Gfx/CanvasD2D.h | 2 +- Common/Gfx/CanvasGDIP.cpp | 34 +++++++++++++++++++++------------- Common/Gfx/CanvasGDIP.h | 4 +++- Library/MeterString.cpp | 17 ++--------------- Library/MeterString.h | 1 - 6 files changed, 30 insertions(+), 34 deletions(-) diff --git a/Common/Gfx/CanvasD2D.cpp b/Common/Gfx/CanvasD2D.cpp index ab80c4e2..97d8092d 100644 --- a/Common/Gfx/CanvasD2D.cpp +++ b/Common/Gfx/CanvasD2D.cpp @@ -69,7 +69,7 @@ CanvasD2D::CanvasD2D() : Canvas(), CanvasD2D::~CanvasD2D() { - DiscardDeviceResources(); + Dispose(); Finalize(); } @@ -118,7 +118,7 @@ void CanvasD2D::Finalize() } } -void CanvasD2D::DiscardDeviceResources() +void CanvasD2D::Dispose() { SafeRelease(&m_Target); @@ -133,7 +133,7 @@ void CanvasD2D::Resize(int w, int h) { __super::Resize(w, h); - DiscardDeviceResources(); + Dispose(); m_Bitmap.Resize(w, h); diff --git a/Common/Gfx/CanvasD2D.h b/Common/Gfx/CanvasD2D.h index a4ae4dfb..625df54a 100644 --- a/Common/Gfx/CanvasD2D.h +++ b/Common/Gfx/CanvasD2D.h @@ -74,7 +74,7 @@ private: static bool Initialize(); static void Finalize(); - void DiscardDeviceResources(); + void Dispose(); bool BeginTargetDraw(); void EndTargetDraw(); diff --git a/Common/Gfx/CanvasGDIP.cpp b/Common/Gfx/CanvasGDIP.cpp index d798c037..e6c07d60 100644 --- a/Common/Gfx/CanvasGDIP.cpp +++ b/Common/Gfx/CanvasGDIP.cpp @@ -22,7 +22,7 @@ namespace Gfx { CanvasGDIP::CanvasGDIP() : Canvas(), m_Graphics(), - m_DoubleBuffer(), + m_Bitmap(), m_DIBSectionBuffer(), m_DIBSectionBufferPixels() { @@ -30,22 +30,30 @@ CanvasGDIP::CanvasGDIP() : Canvas(), CanvasGDIP::~CanvasGDIP() { - delete m_DoubleBuffer; - if (m_DIBSectionBuffer) DeleteObject(m_DIBSectionBuffer); + Dispose(); +} + +void CanvasGDIP::Dispose() +{ + delete m_Graphics; + m_Graphics = nullptr; + + delete m_Bitmap; + m_Bitmap = nullptr; + + if (m_DIBSectionBuffer) + { + DeleteObject(m_DIBSectionBuffer); + m_DIBSectionBuffer = nullptr; + m_DIBSectionBufferPixels = nullptr; + } } void CanvasGDIP::Resize(int w, int h) { __super::Resize(w, h); - delete m_Graphics; - - if (m_DIBSectionBuffer) - { - delete m_DoubleBuffer; - DeleteObject(m_DIBSectionBuffer); - m_DIBSectionBufferPixels = nullptr; - } + Dispose(); BITMAPV4HEADER bh = {sizeof(BITMAPV4HEADER)}; bh.bV4Width = w; @@ -67,14 +75,14 @@ void CanvasGDIP::Resize(int w, int h) 0); // Create GDI+ bitmap from the DIBSection pixels - m_DoubleBuffer = new Gdiplus::Bitmap( + m_Bitmap = new Gdiplus::Bitmap( w, h, w * 4, PixelFormat32bppPARGB, (BYTE*)m_DIBSectionBufferPixels); - m_Graphics = new Gdiplus::Graphics(m_DoubleBuffer); + m_Graphics = new Gdiplus::Graphics(m_Bitmap); } bool CanvasGDIP::BeginDraw() diff --git a/Common/Gfx/CanvasGDIP.h b/Common/Gfx/CanvasGDIP.h index ed3f1e3e..6723f948 100644 --- a/Common/Gfx/CanvasGDIP.h +++ b/Common/Gfx/CanvasGDIP.h @@ -64,8 +64,10 @@ public: private: CanvasGDIP(const CanvasGDIP& other) {} + void Dispose(); + Gdiplus::Graphics* m_Graphics; - Gdiplus::Bitmap* m_DoubleBuffer; + Gdiplus::Bitmap* m_Bitmap; HBITMAP m_DIBSectionBuffer; LPDWORD m_DIBSectionBufferPixels; diff --git a/Library/MeterString.cpp b/Library/MeterString.cpp index 7c45d650..fe1b4011 100644 --- a/Library/MeterString.cpp +++ b/Library/MeterString.cpp @@ -432,15 +432,12 @@ bool CMeterString::DrawString(Gfx::Canvas& canvas, RectF* rect) canvas.SetTextAntiAliasing(m_AntiAlias); - //CharacterRange range(0, stringLen); - //stringFormat.SetMeasurableCharacterRanges(1, &range); - m_TextFormat->SetTrimming( m_ClipType == CLIP_ON || (m_ClipType == CLIP_AUTO && (m_NeedsClipping || (m_WDefined && m_HDefined)))); - REAL x = (REAL)GetX(); - REAL y = (REAL)GetY(); + const REAL x = (REAL)GetX(); + const REAL y = (REAL)GetY(); if (rect) { @@ -598,15 +595,6 @@ void CMeterString::BindMeasures(CConfigParser& parser, const WCHAR* section) } } -/* -** Static function which frees the font cache. -** If collection is not NULL, frees the private font cache. -** -*/ -void CMeterString::FreeFontCache(PrivateFontCollection* collection) -{ -} - /* ** Static helper to log all installed font families. ** @@ -674,5 +662,4 @@ void CMeterString::InitializeStatic() void CMeterString::FinalizeStatic() { - FreeFontCache(); } diff --git a/Library/MeterString.h b/Library/MeterString.h index 9324210f..e675ae8a 100644 --- a/Library/MeterString.h +++ b/Library/MeterString.h @@ -40,7 +40,6 @@ public: virtual bool Draw(Gfx::Canvas& canvas); Gdiplus::RectF GetRect() { return m_Rect; } - static void FreeFontCache(Gdiplus::PrivateFontCollection* collection = NULL); static void EnumerateInstalledFontFamilies(); static void InitializeStatic();