summaryrefslogtreecommitdiffstats
path: root/base/win/scoped_hdc.h
diff options
context:
space:
mode:
authoryosin@chromium.org <yosin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-04 04:43:12 +0000
committeryosin@chromium.org <yosin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-04 04:43:12 +0000
commit8fd0ed0167cd5d8dba2a8ee74001de63b3915029 (patch)
treed3e1449562ca67852963ce32d31ddc8c09399551 /base/win/scoped_hdc.h
parentcfe4943802cac9a65767b3597a9d455e6ffa4876 (diff)
downloadchromium_src-8fd0ed0167cd5d8dba2a8ee74001de63b3915029.zip
chromium_src-8fd0ed0167cd5d8dba2a8ee74001de63b3915029.tar.gz
chromium_src-8fd0ed0167cd5d8dba2a8ee74001de63b3915029.tar.bz2
1 Add ScopedGetDC and ScopedSelectObject
* To mark@, sky@ ** base/win/scoped_hdc.h ** base/win/scoped_select_object.h 2 Fix leak in printing * To kmadhusu@ ** Play object creation command in metafile once ** Fix trivial leaks 3 Fix leak in SKIA * To twiz@ ** Fix font leak BUG=98523 TEST=Manual on Win7 Review URL: http://codereview.chromium.org/8084018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103852 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/win/scoped_hdc.h')
-rw-r--r--base/win/scoped_hdc.h31
1 files changed, 29 insertions, 2 deletions
diff --git a/base/win/scoped_hdc.h b/base/win/scoped_hdc.h
index 73d369a7..8b316ca 100644
--- a/base/win/scoped_hdc.h
+++ b/base/win/scoped_hdc.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,12 +9,39 @@
#include <windows.h>
#include "base/basictypes.h"
+#include "base/logging.h"
namespace base {
namespace win {
// Like ScopedHandle but for HDC. Only use this on HDCs returned from
-// CreateCompatibleDC. For an HDC returned by GetDC, use ReleaseDC instead.
+// GetDC.
+class ScopedGetDC {
+ public:
+ explicit ScopedGetDC(HWND hwnd)
+ : hwnd_(hwnd),
+ hdc_(GetDC(hwnd)) {
+ DCHECK(!hwnd_ || IsWindow(hwnd_));
+ DCHECK(hdc_);
+ }
+
+ ~ScopedGetDC() {
+ if (hdc_)
+ ReleaseDC(hwnd_, hdc_);
+ }
+
+ operator HDC() { return hdc_; }
+
+ private:
+ HWND hwnd_;
+ HDC hdc_;
+ DISALLOW_COPY_AND_ASSIGN(ScopedGetDC);
+};
+
+// Like ScopedHandle but for HDC. Only use this on HDCs returned from
+// CreateCompatibleDC.
+// TODO(yosin) To eliminate confusion with ScopedGetDC, we should rename
+// ScopedHDC to ScopedCreateDC.
class ScopedHDC {
public:
ScopedHDC() : hdc_(NULL) { }