From 71f5b0e7da72aa979bc9839fe42f1492988b7eb6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 24 Oct 2010 22:41:46 +0000 Subject: [PATCH] Do nothing in wxMemoryDC::SelectObject() if the bitmap is already selected. It doesn't make sense to make a copy of the bitmap in order to select it into wxMemoryDC if it's already selected into it. See #11640. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65913 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- interface/wx/dcmemory.h | 12 ++++++++---- src/common/dcbase.cpp | 6 ++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/interface/wx/dcmemory.h b/interface/wx/dcmemory.h index 08985012bc..100fc9beea 100644 --- a/interface/wx/dcmemory.h +++ b/interface/wx/dcmemory.h @@ -81,13 +81,17 @@ public: should use when you select a bitmap because you want to modify it, e.g. drawing on this DC. - Using SelectObjectAsSource() when modifying the bitmap may incurr some + Using SelectObjectAsSource() when modifying the bitmap may incur some problems related to wxBitmap being a reference counted object (see @ref overview_refcount). - Also, before using the updated bitmap data, make sure to select it out - of context first (for example by selecting ::wxNullBitmap into the device - context). + Before using the updated bitmap data, make sure to select it out of + context first either by selecting ::wxNullBitmap into the device + context or destroying the device context entirely. + + If the bitmap is already selected in this device context, nothing is + done. If it is selected in another context, the function asserts and + drawing on the bitmap won't work correctly. @see wxDC::DrawBitmap() */ diff --git a/src/common/dcbase.cpp b/src/common/dcbase.cpp index d65b47e3e6..5cad40cfee 100644 --- a/src/common/dcbase.cpp +++ b/src/common/dcbase.cpp @@ -236,6 +236,12 @@ wxMemoryDC::wxMemoryDC(wxDC *dc) void wxMemoryDC::SelectObject(wxBitmap& bmp) { + if ( bmp.IsSameAs(GetSelectedBitmap()) ) + { + // Nothing to do, this bitmap is already selected. + return; + } + // make sure that the given wxBitmap is not sharing its data with other // wxBitmap instances as its contents will be modified by any drawing // operation done on this DC -- 2.45.2