]> git.saurik.com Git - wxWidgets.git/commitdiff
Made DC cacheing less obstrusive
authorJulian Smart <julian@anthemion.co.uk>
Wed, 11 Jul 2001 20:22:44 +0000 (20:22 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Wed, 11 Jul 2001 20:22:44 +0000 (20:22 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10974 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/dc.tex
samples/dragimag/dragimag.cpp
src/msw/app.cpp
src/msw/dc.cpp

index d8e91ef275679303661423216c19b74816b35810..94354be9345ad80d7f94373a23758950dcd165cf 100644 (file)
@@ -104,8 +104,8 @@ and the background colour set to WHITE.
 This sequence of operations ensures that the source's transparent area need not be black,
 and logical functions are supported.
 
 This sequence of operations ensures that the source's transparent area need not be black,
 and logical functions are supported.
 
-{\bf Note:} on Windows, blitting with masks can be speeded up considerably by using 
-\helpref{DC cacheing}{wxdcenablecache}. You can also influence whether MaskBlt
+{\bf Note:} on Windows, blitting with masks can be speeded up considerably by compiling
+wxWindows with the wxUSE\_DC\_CACHE option enabled. You can also influence whether MaskBlt
 or the explicit mask blitting code above is used, by using \helpref{wxSystemOptions}{wxsystemoptions} and
 setting the {\bf no-maskblt} option to 1.
 
 or the explicit mask blitting code above is used, by using \helpref{wxSystemOptions}{wxsystemoptions} and
 setting the {\bf no-maskblt} option to 1.
 
@@ -128,6 +128,7 @@ See \helpref{wxMemoryDC}{wxmemorydc} for typical usage.
 
 \helpref{wxMemoryDC}{wxmemorydc}, \helpref{wxBitmap}{wxbitmap}, \helpref{wxMask}{wxmask}
 
 
 \helpref{wxMemoryDC}{wxmemorydc}, \helpref{wxBitmap}{wxbitmap}, \helpref{wxMask}{wxmask}
 
+\begin{comment}
 \membersection{wxDC::CacheEnabled}\label{wxdccacheenabled}
 
 \func{static bool}{CacheEnabled}{\void}
 \membersection{wxDC::CacheEnabled}\label{wxdccacheenabled}
 
 \func{static bool}{CacheEnabled}{\void}
@@ -143,6 +144,7 @@ wxUSE\_DC\_CACHEING preprocessor symbol for portability.
 \wxheading{See also}
 
 \helpref{wxDC::EnableCache}{wxdcenablecache}, \helpref{wxDC::ClearCache}
 \wxheading{See also}
 
 \helpref{wxDC::EnableCache}{wxdcenablecache}, \helpref{wxDC::ClearCache}
+\end{comment}
 
 \membersection{wxDC::CalcBoundingBox}\label{wxdccalcboundingbox}
 
 
 \membersection{wxDC::CalcBoundingBox}\label{wxdccalcboundingbox}
 
@@ -162,6 +164,7 @@ Adds the specified point to the bounding box which can be retrieved with
 
 Clears the device context using the current background brush.
 
 
 Clears the device context using the current background brush.
 
+\begin{comment}
 \membersection{wxDC::ClearCache}\label{wxdcclearcache}
 
 \func{static void}{ClearCache}{\void}
 \membersection{wxDC::ClearCache}\label{wxdcclearcache}
 
 \func{static void}{ClearCache}{\void}
@@ -179,6 +182,7 @@ wxUSE\_DC\_CACHEING preprocessor symbol for portability.
 \wxheading{See also}
 
 \helpref{wxDC::EnableCache}{wxdcenablecache}, \helpref{wxDC::CacheEnabled}
 \wxheading{See also}
 
 \helpref{wxDC::EnableCache}{wxdcenablecache}, \helpref{wxDC::CacheEnabled}
+\end{comment}
 
 \membersection{wxDC::CrossHair}\label{wxdccrosshair}
 
 
 \membersection{wxDC::CrossHair}\label{wxdccrosshair}
 
@@ -417,6 +421,7 @@ text more precisely.
 but it is ignored by wxMSW. Thus, you should avoid using logical functions
 with this function in portable programs.
 
 but it is ignored by wxMSW. Thus, you should avoid using logical functions
 with this function in portable programs.
 
+\begin{comment}
 \membersection{wxDC::EnableCache}\label{wxdcenablecache}
 
 \func{static void}{EnableCache}{\param{bool}{ enableCache}}
 \membersection{wxDC::EnableCache}\label{wxdcenablecache}
 
 \func{static void}{EnableCache}{\param{bool}{ enableCache}}
@@ -431,6 +436,7 @@ wxUSE\_DC\_CACHEING preprocessor symbol for portability.
 \wxheading{See also}
 
 \helpref{wxDC::CacheEnabled}{wxdccacheenabled}, \helpref{wxDC::ClearCache}
 \wxheading{See also}
 
 \helpref{wxDC::CacheEnabled}{wxdccacheenabled}, \helpref{wxDC::ClearCache}
+\end{comment}
 
 \membersection{wxDC::EndDoc}\label{wxdcenddoc}
 
 
 \membersection{wxDC::EndDoc}\label{wxdcenddoc}
 
index 43a115629fd72d85f28b25ec5c73bc4fe4576c42..fd7d182c44af00dbbefdbd312c04091c246f3b25 100644 (file)
@@ -101,9 +101,6 @@ void MyCanvas::OnEraseBackground(wxEraseEvent& event)
             wxClientDC dc(this);
             wxGetApp().TileBitmap(rect, dc, wxGetApp().GetBackgroundBitmap());
         }
             wxClientDC dc(this);
             wxGetApp().TileBitmap(rect, dc, wxGetApp().GetBackgroundBitmap());
         }
-#if wxUSE_DC_CACHEING
-        wxDC::ClearCache();
-#endif
     }
     else
         event.Skip(); // The official way of doing it
     }
     else
         event.Skip(); // The official way of doing it
@@ -281,9 +278,6 @@ void MyCanvas::DrawShapes(wxDC& dc)
           shape->Draw(dc);
         node = node->Next();
     }
           shape->Draw(dc);
         node = node->Next();
     }
-#if wxUSE_DC_CACHEING
-    wxDC::ClearCache();
-#endif
 }
 
 void MyCanvas::EraseShape(DragShape* shape, wxDC& dc)
 }
 
 void MyCanvas::EraseShape(DragShape* shape, wxDC& dc)
@@ -385,12 +379,6 @@ bool MyApp::OnInit()
     wxImage::AddHandler( new wxPNGHandler );
 #endif
 
     wxImage::AddHandler( new wxPNGHandler );
 #endif
 
-    // The DC cache is an efficiency measure to be used
-    // when a lot of masked blitting is done
-#if wxUSE_DC_CACHEING
-    wxDC::EnableCache(TRUE);
-#endif
-
     wxImage image;
     if (image.LoadFile("backgrnd.png", wxBITMAP_TYPE_PNG))
     {
     wxImage image;
     if (image.LoadFile("backgrnd.png", wxBITMAP_TYPE_PNG))
     {
@@ -445,9 +433,6 @@ bool MyApp::OnInit()
 
 int MyApp::OnExit()
 {
 
 int MyApp::OnExit()
 {
-#if wxUSE_DC_CACHEING
-    wxDC::ClearCache();
-#endif
     return 0;
 }
 
     return 0;
 }
 
index 7cfe66ae9e5325a3870653b86e2c5bbf4adfc865..7c9aa3741f93799b8a4027bf12e426c1f1377c4b 100644 (file)
@@ -1112,6 +1112,14 @@ void wxApp::OnIdle(wxIdleEvent& event)
     wxLog::FlushActive();
 #endif // wxUSE_LOG
 
     wxLog::FlushActive();
 #endif // wxUSE_LOG
 
+#if wxUSE_DC_CACHEING
+    // automated DC cache management: clear the cached DCs and bitmap
+    // if it's likely that the app has finished with them, that is, we
+    // get an idle event and we're not dragging anything.
+    if (!::GetKeyState(MK_LBUTTON) && !::GetKeyState(MK_MBUTTON) && ::GetKeyState(MK_RBUTTON))
+        wxDC::ClearCache();
+#endif // wxUSE_DC_CACHEING
+
     // Send OnIdle events to all windows
     if ( SendIdleEvents() )
     {
     // Send OnIdle events to all windows
     if ( SendIdleEvents() )
     {
index a9cfabdf120850dbf0297200847df0ca5f981e7a..33417c540af9f176a6505f50f2917350d9bb6606 100644 (file)
@@ -42,6 +42,7 @@
 
 #include "wx/sysopt.h"
 #include "wx/dcprint.h"
 
 #include "wx/sysopt.h"
 #include "wx/dcprint.h"
+#include "wx/module.h"
 
 #include <string.h>
 #include <math.h>
 
 #include <string.h>
 #include <math.h>
@@ -1985,6 +1986,19 @@ void wxDC::ClearCache()
     sm_dcCache.DeleteContents(FALSE);
 }
 
     sm_dcCache.DeleteContents(FALSE);
 }
 
+// Clean up cache at app exit
+class wxDCModule : public wxModule
+{
+public:
+    virtual bool OnInit() { return TRUE; }
+    virtual void OnExit() { wxDC::ClearCache(); }
+
+private:
+    DECLARE_DYNAMIC_CLASS(wxDCModule)
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxDCModule, wxModule)
+
 #endif
     // wxUSE_DC_CACHEING
 
 #endif
     // wxUSE_DC_CACHEING