| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_WIN_SCOPED_HDC_H_ | 5 #ifndef BASE_WIN_SCOPED_HDC_H_ |
| 6 #define BASE_WIN_SCOPED_HDC_H_ | 6 #define BASE_WIN_SCOPED_HDC_H_ |
| 7 | 7 |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 | 9 |
| 10 #include "base/debug/gdi_debug_util_win.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/win/scoped_handle.h" | 13 #include "base/win/scoped_handle.h" |
| 13 | 14 |
| 14 namespace base { | 15 namespace base { |
| 15 namespace win { | 16 namespace win { |
| 16 | 17 |
| 17 // Like ScopedHandle but for HDC. Only use this on HDCs returned from | 18 // Like ScopedHandle but for HDC. Only use this on HDCs returned from |
| 18 // GetDC. | 19 // GetDC. |
| 19 class ScopedGetDC { | 20 class ScopedGetDC { |
| 20 public: | 21 public: |
| 21 explicit ScopedGetDC(HWND hwnd) | 22 explicit ScopedGetDC(HWND hwnd) |
| 22 : hwnd_(hwnd), | 23 : hwnd_(hwnd), |
| 23 hdc_(GetDC(hwnd)) { | 24 hdc_(GetDC(hwnd)) { |
| 24 if (hwnd_) { | 25 if (hwnd_) { |
| 25 DCHECK(IsWindow(hwnd_)); | 26 DCHECK(IsWindow(hwnd_)); |
| 26 DCHECK(hdc_); | 27 DCHECK(hdc_); |
| 27 } else { | 28 } else { |
| 28 // If GetDC(NULL) returns NULL, something really bad has happened, like | 29 // If GetDC(NULL) returns NULL, something really bad has happened, like |
| 29 // GDI handle exhaustion. In this case Chrome is going to behave badly no | 30 // GDI handle exhaustion. In this case Chrome is going to behave badly no |
| 30 // matter what, so we may as well just force a crash now. | 31 // matter what, so we may as well just force a crash now. |
| 31 CHECK(hdc_); | 32 if (!hdc_) |
| 33 base::debug::CollectGDIUsageAndDie(); |
| 32 } | 34 } |
| 33 } | 35 } |
| 34 | 36 |
| 35 ~ScopedGetDC() { | 37 ~ScopedGetDC() { |
| 36 if (hdc_) | 38 if (hdc_) |
| 37 ReleaseDC(hwnd_, hdc_); | 39 ReleaseDC(hwnd_, hdc_); |
| 38 } | 40 } |
| 39 | 41 |
| 40 operator HDC() { return hdc_; } | 42 operator HDC() { return hdc_; } |
| 41 | 43 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 67 private: | 69 private: |
| 68 DISALLOW_IMPLICIT_CONSTRUCTORS(CreateDCTraits); | 70 DISALLOW_IMPLICIT_CONSTRUCTORS(CreateDCTraits); |
| 69 }; | 71 }; |
| 70 | 72 |
| 71 typedef GenericScopedHandle<CreateDCTraits, DummyVerifierTraits> ScopedCreateDC; | 73 typedef GenericScopedHandle<CreateDCTraits, DummyVerifierTraits> ScopedCreateDC; |
| 72 | 74 |
| 73 } // namespace win | 75 } // namespace win |
| 74 } // namespace base | 76 } // namespace base |
| 75 | 77 |
| 76 #endif // BASE_WIN_SCOPED_HDC_H_ | 78 #endif // BASE_WIN_SCOPED_HDC_H_ |
| OLD | NEW |