mirror of
https://github.com/reactos/reactos.git
synced 2025-05-08 03:07:05 +00:00
[MSPAINT] Add CachedBufferDIB function and use it
We do caching on buffering paint. This will improve performance a little. CORE-18867
This commit is contained in:
parent
c706222f3f
commit
2f856f6f0d
8 changed files with 73 additions and 9 deletions
|
@ -17,10 +17,17 @@ CCanvasWindow::CCanvasWindow()
|
||||||
, m_hitSelection(HIT_NONE)
|
, m_hitSelection(HIT_NONE)
|
||||||
, m_whereHit(HIT_NONE)
|
, m_whereHit(HIT_NONE)
|
||||||
, m_ptOrig { -1, -1 }
|
, m_ptOrig { -1, -1 }
|
||||||
|
, m_hbmCached(NULL)
|
||||||
{
|
{
|
||||||
::SetRectEmpty(&m_rcNew);
|
::SetRectEmpty(&m_rcNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CCanvasWindow::~CCanvasWindow()
|
||||||
|
{
|
||||||
|
if (m_hbmCached)
|
||||||
|
::DeleteObject(m_hbmCached);
|
||||||
|
}
|
||||||
|
|
||||||
VOID CCanvasWindow::drawZoomFrame(INT mouseX, INT mouseY)
|
VOID CCanvasWindow::drawZoomFrame(INT mouseX, INT mouseY)
|
||||||
{
|
{
|
||||||
// FIXME: Draw the border of the area that is to be zoomed in
|
// FIXME: Draw the border of the area that is to be zoomed in
|
||||||
|
@ -95,8 +102,8 @@ VOID CCanvasWindow::DoDraw(HDC hDC, RECT& rcClient, RECT& rcPaint)
|
||||||
{
|
{
|
||||||
// We use a memory bitmap to reduce flickering
|
// We use a memory bitmap to reduce flickering
|
||||||
HDC hdcMem = ::CreateCompatibleDC(hDC);
|
HDC hdcMem = ::CreateCompatibleDC(hDC);
|
||||||
HBITMAP hbm = ::CreateCompatibleBitmap(hDC, rcClient.right, rcClient.bottom);
|
m_hbmCached = CachedBufferDIB(m_hbmCached, rcClient.right, rcClient.bottom);
|
||||||
HGDIOBJ hbmOld = ::SelectObject(hdcMem, hbm);
|
HGDIOBJ hbmOld = ::SelectObject(hdcMem, m_hbmCached);
|
||||||
|
|
||||||
// Fill the background
|
// Fill the background
|
||||||
::FillRect(hdcMem, &rcPaint, (HBRUSH)(COLOR_APPWORKSPACE + 1));
|
::FillRect(hdcMem, &rcPaint, (HBRUSH)(COLOR_APPWORKSPACE + 1));
|
||||||
|
@ -164,7 +171,7 @@ VOID CCanvasWindow::DoDraw(HDC hDC, RECT& rcClient, RECT& rcPaint)
|
||||||
rcPaint.right - rcPaint.left, rcPaint.bottom - rcPaint.top,
|
rcPaint.right - rcPaint.left, rcPaint.bottom - rcPaint.top,
|
||||||
hdcMem, rcPaint.left, rcPaint.top, SRCCOPY);
|
hdcMem, rcPaint.left, rcPaint.top, SRCCOPY);
|
||||||
|
|
||||||
::DeleteObject(::SelectObject(hdcMem, hbmOld));
|
::SelectObject(hdcMem, hbmOld);
|
||||||
::DeleteDC(hdcMem);
|
::DeleteDC(hdcMem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
END_MSG_MAP()
|
END_MSG_MAP()
|
||||||
|
|
||||||
CCanvasWindow();
|
CCanvasWindow();
|
||||||
|
virtual ~CCanvasWindow();
|
||||||
|
|
||||||
BOOL m_drawing;
|
BOOL m_drawing;
|
||||||
|
|
||||||
|
@ -54,6 +55,7 @@ protected:
|
||||||
CANVAS_HITTEST m_hitSelection;
|
CANVAS_HITTEST m_hitSelection;
|
||||||
CANVAS_HITTEST m_whereHit;
|
CANVAS_HITTEST m_whereHit;
|
||||||
POINT m_ptOrig; // The origin of drag start
|
POINT m_ptOrig; // The origin of drag start
|
||||||
|
HBITMAP m_hbmCached; // The cached buffer bitmap
|
||||||
CRect m_rcNew;
|
CRect m_rcNew;
|
||||||
|
|
||||||
CANVAS_HITTEST CanvasHitTest(POINT pt);
|
CANVAS_HITTEST CanvasHitTest(POINT pt);
|
||||||
|
|
|
@ -59,6 +59,26 @@ CreateColorDIB(int width, int height, COLORREF rgb)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HBITMAP CachedBufferDIB(HBITMAP hbm, int minimalWidth, int minimalHeight)
|
||||||
|
{
|
||||||
|
if (minimalWidth <= 0)
|
||||||
|
minimalWidth = 1;
|
||||||
|
if (minimalHeight <= 0)
|
||||||
|
minimalHeight = 1;
|
||||||
|
|
||||||
|
BITMAP bm;
|
||||||
|
if (!GetObject(hbm, sizeof(bm), &bm))
|
||||||
|
hbm = NULL;
|
||||||
|
|
||||||
|
if (hbm && minimalWidth <= bm.bmWidth && minimalHeight <= bm.bmHeight)
|
||||||
|
return hbm;
|
||||||
|
|
||||||
|
if (hbm)
|
||||||
|
DeleteObject(hbm);
|
||||||
|
|
||||||
|
return CreateDIBWithProperties((minimalWidth * 3) / 2, (minimalHeight * 3) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
GetDIBWidth(HBITMAP hBitmap)
|
GetDIBWidth(HBITMAP hBitmap)
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
HBITMAP CreateDIBWithProperties(int width, int height);
|
HBITMAP CreateDIBWithProperties(int width, int height);
|
||||||
HBITMAP CreateColorDIB(int width, int height, COLORREF rgb);
|
HBITMAP CreateColorDIB(int width, int height, COLORREF rgb);
|
||||||
|
HBITMAP CachedBufferDIB(HBITMAP hbm, int minimalWidth, int minimalHeight);
|
||||||
|
|
||||||
static inline HBITMAP CopyDIBImage(HBITMAP hbm, INT cx = 0, INT cy = 0)
|
static inline HBITMAP CopyDIBImage(HBITMAP hbm, INT cx = 0, INT cy = 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,6 +14,17 @@ CMiniatureWindow miniature;
|
||||||
|
|
||||||
/* FUNCTIONS ********************************************************/
|
/* FUNCTIONS ********************************************************/
|
||||||
|
|
||||||
|
CMiniatureWindow::CMiniatureWindow()
|
||||||
|
: m_hbmCached(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CMiniatureWindow::~CMiniatureWindow()
|
||||||
|
{
|
||||||
|
if (m_hbmCached)
|
||||||
|
::DeleteObject(m_hbmCached);
|
||||||
|
}
|
||||||
|
|
||||||
HWND CMiniatureWindow::DoCreate(HWND hwndParent)
|
HWND CMiniatureWindow::DoCreate(HWND hwndParent)
|
||||||
{
|
{
|
||||||
if (m_hWnd)
|
if (m_hWnd)
|
||||||
|
@ -82,7 +93,8 @@ LRESULT CMiniatureWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
|
||||||
|
|
||||||
// Use a memory bitmap to reduce flickering
|
// Use a memory bitmap to reduce flickering
|
||||||
HDC hdcMem = ::CreateCompatibleDC(hDC);
|
HDC hdcMem = ::CreateCompatibleDC(hDC);
|
||||||
HGDIOBJ hbmOld = ::SelectObject(hdcMem, ::CreateCompatibleBitmap(hDC, rc.right, rc.bottom));
|
m_hbmCached = CachedBufferDIB(m_hbmCached, rc.right, rc.bottom);
|
||||||
|
HGDIOBJ hbmOld = ::SelectObject(hdcMem, m_hbmCached);
|
||||||
|
|
||||||
// FIXME: Consider aspect ratio
|
// FIXME: Consider aspect ratio
|
||||||
|
|
||||||
|
@ -100,7 +112,7 @@ LRESULT CMiniatureWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
|
||||||
::BitBlt(hDC, 0, 0, rc.right, rc.bottom, hdcMem, 0, 0, SRCCOPY);
|
::BitBlt(hDC, 0, 0, rc.right, rc.bottom, hdcMem, 0, 0, SRCCOPY);
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
::DeleteObject(::SelectObject(hdcMem, hbmOld));
|
::SelectObject(hdcMem, hbmOld);
|
||||||
::DeleteDC(hdcMem);
|
::DeleteDC(hdcMem);
|
||||||
|
|
||||||
EndPaint(&ps);
|
EndPaint(&ps);
|
||||||
|
|
|
@ -24,9 +24,14 @@ public:
|
||||||
MESSAGE_HANDLER(WM_GETMINMAXINFO, OnGetMinMaxInfo)
|
MESSAGE_HANDLER(WM_GETMINMAXINFO, OnGetMinMaxInfo)
|
||||||
END_MSG_MAP()
|
END_MSG_MAP()
|
||||||
|
|
||||||
|
CMiniatureWindow();
|
||||||
|
virtual ~CMiniatureWindow();
|
||||||
|
|
||||||
HWND DoCreate(HWND hwndParent);
|
HWND DoCreate(HWND hwndParent);
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
|
HBITMAP m_hbmCached; // Cached buffer bitmap
|
||||||
|
|
||||||
LRESULT OnMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
LRESULT OnMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||||
LRESULT OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
LRESULT OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||||
LRESULT OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
LRESULT OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||||
|
|
|
@ -21,6 +21,17 @@ CPaletteWindow paletteWindow;
|
||||||
|
|
||||||
/* FUNCTIONS ********************************************************/
|
/* FUNCTIONS ********************************************************/
|
||||||
|
|
||||||
|
CPaletteWindow::CPaletteWindow()
|
||||||
|
: m_hbmCached(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CPaletteWindow::~CPaletteWindow()
|
||||||
|
{
|
||||||
|
if (m_hbmCached)
|
||||||
|
::DeleteObject(m_hbmCached);
|
||||||
|
}
|
||||||
|
|
||||||
static VOID drawColorBox(HDC hDC, LPCRECT prc, COLORREF rgbColor, UINT nBorder)
|
static VOID drawColorBox(HDC hDC, LPCRECT prc, COLORREF rgbColor, UINT nBorder)
|
||||||
{
|
{
|
||||||
RECT rc = *prc;
|
RECT rc = *prc;
|
||||||
|
@ -76,8 +87,8 @@ LRESULT CPaletteWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& b
|
||||||
/* To avoid flickering, we use a memory bitmap.
|
/* To avoid flickering, we use a memory bitmap.
|
||||||
The left and top values are zeros in client rectangle */
|
The left and top values are zeros in client rectangle */
|
||||||
HDC hMemDC = ::CreateCompatibleDC(hDC);
|
HDC hMemDC = ::CreateCompatibleDC(hDC);
|
||||||
HBITMAP hbm = ::CreateCompatibleBitmap(hDC, rcClient.right, rcClient.bottom);
|
m_hbmCached = CachedBufferDIB(m_hbmCached, rcClient.right, rcClient.bottom);
|
||||||
HGDIOBJ hbmOld = ::SelectObject(hMemDC, hbm);
|
HGDIOBJ hbmOld = ::SelectObject(hMemDC, m_hbmCached);
|
||||||
|
|
||||||
/* Fill the background (since WM_ERASEBKGND handling is disabled) */
|
/* Fill the background (since WM_ERASEBKGND handling is disabled) */
|
||||||
::FillRect(hMemDC, &rcClient, (HBRUSH)(COLOR_3DFACE + 1));
|
::FillRect(hMemDC, &rcClient, (HBRUSH)(COLOR_3DFACE + 1));
|
||||||
|
@ -121,7 +132,7 @@ LRESULT CPaletteWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& b
|
||||||
/* Transfer bits (hDC <-- hMemDC) */
|
/* Transfer bits (hDC <-- hMemDC) */
|
||||||
::BitBlt(hDC, 0, 0, rcClient.right, rcClient.bottom, hMemDC, 0, 0, SRCCOPY);
|
::BitBlt(hDC, 0, 0, rcClient.right, rcClient.bottom, hMemDC, 0, 0, SRCCOPY);
|
||||||
|
|
||||||
::DeleteObject(::SelectObject(hMemDC, hbmOld));
|
::SelectObject(hMemDC, hbmOld);
|
||||||
::DeleteDC(hMemDC);
|
::DeleteDC(hMemDC);
|
||||||
EndPaint(&ps);
|
EndPaint(&ps);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -30,6 +30,12 @@ public:
|
||||||
MESSAGE_HANDLER(WM_PALETTEMODELPALETTECHANGED, OnPaletteModelPaletteChanged)
|
MESSAGE_HANDLER(WM_PALETTEMODELPALETTECHANGED, OnPaletteModelPaletteChanged)
|
||||||
END_MSG_MAP()
|
END_MSG_MAP()
|
||||||
|
|
||||||
|
CPaletteWindow();
|
||||||
|
virtual ~CPaletteWindow();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
HBITMAP m_hbmCached; // Cached buffer bitmap
|
||||||
|
|
||||||
LRESULT OnEraseBkgnd(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
LRESULT OnEraseBkgnd(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||||
LRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
LRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||||
LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||||
|
|
Loading…
Reference in a new issue