diff options
author | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-14 03:37:14 +0000 |
---|---|---|
committer | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-14 03:37:14 +0000 |
commit | 46db9f43fe29b92895d3138a22d3bc042632135a (patch) | |
tree | 00d16d75a583afb05e3df73d76ff04b0b5562bb6 | |
parent | c6aef90f9f927ac75bb99d6d77782fc33c37769d (diff) | |
download | chromium_src-46db9f43fe29b92895d3138a22d3bc042632135a.zip chromium_src-46db9f43fe29b92895d3138a22d3bc042632135a.tar.gz chromium_src-46db9f43fe29b92895d3138a22d3bc042632135a.tar.bz2 |
Make scoped dc objects smarter
So we don't destroy the dc with gdi objects selected.
Also remove implicit conversion to HDC.
BUG=110113,113683
TEST=chrome runs, base unittests green.
Review URL: https://chromiumcodereview.appspot.com/9212020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121840 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/base.gyp | 1 | ||||
-rw-r--r-- | base/base.gypi | 1 | ||||
-rw-r--r-- | base/win/scoped_hdc.cc | 116 | ||||
-rw-r--r-- | base/win/scoped_hdc.h | 112 | ||||
-rw-r--r-- | base/win/scoped_hdc_unittest.cc | 88 | ||||
-rw-r--r-- | chrome/browser/aeropeek_manager.cc | 8 | ||||
-rw-r--r-- | chrome/browser/ui/window_snapshot/window_snapshot_win.cc | 33 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper_win.cc | 12 | ||||
-rw-r--r-- | chrome/service/cloud_print/print_system_win.cc | 31 | ||||
-rw-r--r-- | printing/emf_win_unittest.cc | 8 | ||||
-rw-r--r-- | remoting/host/disconnect_window_win.cc | 4 | ||||
-rw-r--r-- | ui/gfx/native_theme_win.cc | 18 |
12 files changed, 328 insertions, 104 deletions
diff --git a/base/base.gyp b/base/base.gyp index 324c812..359426a 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -260,6 +260,7 @@ 'win/sampling_profiler_unittest.cc', 'win/scoped_bstr_unittest.cc', 'win/scoped_comptr_unittest.cc', + 'win/scoped_hdc_unittest.cc', 'win/scoped_variant_unittest.cc', 'win/win_util_unittest.cc', 'win/wrapped_window_proc_unittest.cc', diff --git a/base/base.gypi b/base/base.gypi index 36400ed..3374515 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -404,6 +404,7 @@ 'win/scoped_comptr.h', 'win/scoped_gdi_object.h', 'win/scoped_handle.h', + 'win/scoped_hdc.cc', 'win/scoped_hdc.h', 'win/scoped_hglobal.h', 'win/scoped_select_object.h', diff --git a/base/win/scoped_hdc.cc b/base/win/scoped_hdc.cc new file mode 100644 index 0000000..f767a82 --- /dev/null +++ b/base/win/scoped_hdc.cc @@ -0,0 +1,116 @@ +// Copyright (c) 2012 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. + +#include "base/win/scoped_hdc.h" + +#include "base/logging.h" + +namespace base { +namespace win { + +ScopedDC::ScopedDC(HDC hdc) + : hdc_(hdc), + bitmap_(0), + font_(0), + brush_(0), + pen_(0), + region_(0) { +} + +ScopedDC::~ScopedDC() {} + +void ScopedDC::SelectBitmap(HBITMAP bitmap) { + Select(bitmap, &bitmap_); +} + +void ScopedDC::SelectFont(HFONT font) { + Select(font, &font_); +} + +void ScopedDC::SelectBrush(HBRUSH brush) { + Select(brush, &brush_); +} + +void ScopedDC::SelectPen(HPEN pen) { + Select(pen, &pen_); +} + +void ScopedDC::SelectRegion(HRGN region) { + Select(region, ®ion_); +} + +void ScopedDC::Close() { + if (!hdc_) + return; + ResetObjects(); + DisposeDC(hdc_); +} + +void ScopedDC::Reset(HDC hdc) { + Close(); + hdc_ = hdc; +} + +void ScopedDC::ResetObjects() { + if (bitmap_) { + SelectObject(hdc_, bitmap_); + bitmap_ = 0; + } + if (font_) { + SelectObject(hdc_, font_); + font_ = 0; + } + if (brush_) { + SelectObject(hdc_, brush_); + brush_ = 0; + } + if (pen_) { + SelectObject(hdc_, pen_); + pen_ = 0; + } + if (region_) { + SelectObject(hdc_, region_); + region_ = 0; + } +} + +void ScopedDC::Select(HGDIOBJ object, HGDIOBJ* holder) { + HGDIOBJ old = SelectObject(hdc_, object); + DCHECK(old); + // We only want to store the first |old| object. + if (!*holder) + *holder = old; +} + +ScopedGetDC::ScopedGetDC(HWND hwnd) : ScopedDC(GetDC(hwnd)), hwnd_(hwnd) { +} + +ScopedGetDC::~ScopedGetDC() { + Close(); +} + +void ScopedGetDC::DisposeDC(HDC hdc) { + ReleaseDC(hwnd_, hdc); +} + +ScopedCreateDC::ScopedCreateDC() : ScopedDC(0) { +} + +ScopedCreateDC::ScopedCreateDC(HDC hdc) : ScopedDC(hdc) { +} + +ScopedCreateDC::~ScopedCreateDC() { + Close(); +} + +void ScopedCreateDC::Set(HDC hdc) { + Reset(hdc); +} + +void ScopedCreateDC::DisposeDC(HDC hdc) { + DeleteDC(hdc); +} + +} // namespace win +} // namespace base diff --git a/base/win/scoped_hdc.h b/base/win/scoped_hdc.h index 9e2ea62..2a93b95 100644 --- a/base/win/scoped_hdc.h +++ b/base/win/scoped_hdc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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,69 +9,91 @@ #include <windows.h> #include "base/basictypes.h" -#include "base/logging.h" +#include "base/compiler_specific.h" namespace base { namespace win { -// Like ScopedHandle but for HDC. Only use this on HDCs returned from -// GetDC. -class ScopedGetDC { +// The ScopedGetDC and ScopedCreateDC classes manage the default GDI objects +// that are initially selected into a DC. They help you avoid the following +// common mistake: +// +// HDC hdc = GetDC(NULL); +// SelectObject(hdc, new_bitmap); +// .. drawing code here .. +// ReleaseDC(hdc); <--- error: the DC has a custom object still selected! +// +// This code should be: +// +// HDC hdc = GetDC(NULL); +// HGDIOBJ old_obj = SelectObject(hdc, new_bitmap); +// .. drawing code here .. +// SelectObject(hdc, old_obj); +// ReleaseDC(hdc); <--- ok to release now. +// +// But why work so hard? Use our handy classes: +// +// ScopedGetDC dc(NULL); +// dc.SelectBitmap(hdc, new_bitmap); +// .. drawing here +// .. when dc goes out of scope it will select the original object before +// .. being released. +// +class ScopedDC { public: - explicit ScopedGetDC(HWND hwnd) - : hwnd_(hwnd), - hdc_(GetDC(hwnd)) { - DCHECK(!hwnd_ || IsWindow(hwnd_)); - DCHECK(hdc_); - } + virtual ~ScopedDC(); + + virtual void DisposeDC(HDC hdc) = 0; + + HDC get() { return hdc_; } - ~ScopedGetDC() { - if (hdc_) - ReleaseDC(hwnd_, hdc_); - } + void SelectBitmap(HBITMAP bitmap); + void SelectFont(HFONT font); + void SelectBrush(HBRUSH brush); + void SelectPen(HPEN pen); + void SelectRegion(HRGN region); - operator HDC() { return hdc_; } + protected: + ScopedDC(HDC hdc); + void Close(); + void Reset(HDC hdc); private: - HWND hwnd_; + void ResetObjects(); + void Select(HGDIOBJ object, HGDIOBJ* holder); + HDC hdc_; + HGDIOBJ bitmap_; + HGDIOBJ font_; + HGDIOBJ brush_; + HGDIOBJ pen_; + HGDIOBJ region_; +}; + +// Creates and manages an HDC obtained by GetDC. +class ScopedGetDC : public ScopedDC { + public: + explicit ScopedGetDC(HWND hwnd); + virtual ~ScopedGetDC(); + private: + virtual void DisposeDC(HDC hdc) OVERRIDE; + + HWND hwnd_; DISALLOW_COPY_AND_ASSIGN(ScopedGetDC); }; // Like ScopedHandle but for HDC. Only use this on HDCs returned from // CreateCompatibleDC, CreateDC and CreateIC. -class ScopedCreateDC { +class ScopedCreateDC : public ScopedDC { public: - ScopedCreateDC() : hdc_(NULL) { } - explicit ScopedCreateDC(HDC h) : hdc_(h) { } - - ~ScopedCreateDC() { - Close(); - } - - HDC Get() { - return hdc_; - } - - void Set(HDC h) { - Close(); - hdc_ = h; - } - - operator HDC() { return hdc_; } + ScopedCreateDC(); + explicit ScopedCreateDC(HDC hdc); + virtual ~ScopedCreateDC(); + void Set(HDC hdc); private: - void Close() { -#ifdef NOGDI - assert(false); -#else - if (hdc_) - DeleteDC(hdc_); -#endif // NOGDI - } - - HDC hdc_; + virtual void DisposeDC(HDC hdc) OVERRIDE; DISALLOW_COPY_AND_ASSIGN(ScopedCreateDC); }; diff --git a/base/win/scoped_hdc_unittest.cc b/base/win/scoped_hdc_unittest.cc new file mode 100644 index 0000000..014a1d1 --- /dev/null +++ b/base/win/scoped_hdc_unittest.cc @@ -0,0 +1,88 @@ +// Copyright (c) 2012 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. + +#include <windows.h> + +#include "base/basictypes.h" +#include "base/win/scoped_hdc.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +// Helper class that allows testing ScopedDC<T>. +class TestScopedDC : public base::win::ScopedDC { + public: + explicit TestScopedDC(HDC hdc) + : ScopedDC(hdc) { + } + + virtual ~TestScopedDC() { + Close(); + } + + private: + virtual void DisposeDC(HDC hdc) OVERRIDE { + // We leak the DC, so we can test its state. The test itself + // will dispose of the dc later. + } + + DISALLOW_COPY_AND_ASSIGN(TestScopedDC); +}; + +bool IsValidDC(HDC hdc) { + // The theory here is that any (cheap) GDI operation should fail for + // an invalid dc. + return GetCurrentObject(hdc, OBJ_BITMAP) != NULL; +} + +} // namespace + +TEST(BaseWinScopedDC, CreateDestroy) { + HDC hdc1; + { + base::win::ScopedGetDC dc1(NULL); + hdc1 = dc1.get(); + EXPECT_TRUE(IsValidDC(hdc1)); + } + EXPECT_FALSE(IsValidDC(hdc1)); + + HDC hdc2 = CreateDC(L"DISPLAY", NULL, NULL, NULL); + ASSERT_TRUE(IsValidDC(hdc2)); + { + base::win::ScopedCreateDC dc2(hdc2); + EXPECT_TRUE(IsValidDC(hdc2)); + } + EXPECT_FALSE(IsValidDC(hdc2)); +} + +TEST(BaseWinScopedDC, SelectObjects) { + HDC hdc = CreateCompatibleDC(NULL); + ASSERT_TRUE(IsValidDC(hdc)); + HGDIOBJ bitmap = GetCurrentObject(hdc, OBJ_BITMAP); + HGDIOBJ brush = GetCurrentObject(hdc, OBJ_BRUSH); + HGDIOBJ pen = GetCurrentObject(hdc, OBJ_PEN); + HGDIOBJ font = GetCurrentObject(hdc, OBJ_FONT); + + HBITMAP compat_bitmap = CreateCompatibleBitmap(hdc, 24, 24); + ASSERT_TRUE(compat_bitmap != NULL); + HBRUSH solid_brush = CreateSolidBrush(RGB(22, 33, 44)); + ASSERT_TRUE(solid_brush != NULL); + + { + TestScopedDC dc2(hdc); + dc2.SelectBitmap(compat_bitmap); + dc2.SelectBrush(solid_brush); + EXPECT_TRUE(bitmap != GetCurrentObject(hdc, OBJ_BITMAP)); + EXPECT_TRUE(brush != GetCurrentObject(hdc, OBJ_BRUSH)); + } + + EXPECT_TRUE(bitmap == GetCurrentObject(hdc, OBJ_BITMAP)); + EXPECT_TRUE(brush == GetCurrentObject(hdc, OBJ_BRUSH)); + EXPECT_TRUE(pen == GetCurrentObject(hdc, OBJ_PEN)); + EXPECT_TRUE(font == GetCurrentObject(hdc, OBJ_FONT)); + + EXPECT_TRUE(DeleteDC(hdc)); + EXPECT_TRUE(DeleteObject(compat_bitmap)); + EXPECT_TRUE(DeleteObject(solid_brush)); +} diff --git a/chrome/browser/aeropeek_manager.cc b/chrome/browser/aeropeek_manager.cc index b387364..f701d74 100644 --- a/chrome/browser/aeropeek_manager.cc +++ b/chrome/browser/aeropeek_manager.cc @@ -211,7 +211,7 @@ void SendThumbnailCallback( // We can delete this DIB after sending it to Windows since Windows creates // a copy of the DIB and use it. base::win::ScopedCreateDC hdc(CreateCompatibleDC(NULL)); - if (!hdc.Get()) { + if (!hdc.get()) { LOG(ERROR) << "cannot create a memory DC: " << GetLastError(); return; } @@ -222,7 +222,7 @@ void SendThumbnailCallback( void* bitmap_data = NULL; base::win::ScopedBitmap bitmap( - CreateDIBSection(hdc, reinterpret_cast<BITMAPINFO*>(&header), + CreateDIBSection(hdc.get(), reinterpret_cast<BITMAPINFO*>(&header), DIB_RGB_COLORS, &bitmap_data, NULL, 0)); if (!bitmap.Get() || !bitmap_data) { @@ -274,7 +274,7 @@ void SendLivePreviewCallback( // We don't need to paste this tab image onto the frame image since Windows // automatically pastes it for us. base::win::ScopedCreateDC hdc(CreateCompatibleDC(NULL)); - if (!hdc.Get()) { + if (!hdc.get()) { LOG(ERROR) << "cannot create a memory DC: " << GetLastError(); return; } @@ -285,7 +285,7 @@ void SendLivePreviewCallback( void* bitmap_data = NULL; base::win::ScopedBitmap bitmap( - CreateDIBSection(hdc.Get(), reinterpret_cast<BITMAPINFO*>(&header), + CreateDIBSection(hdc.get(), reinterpret_cast<BITMAPINFO*>(&header), DIB_RGB_COLORS, &bitmap_data, NULL, 0)); if (!bitmap.Get() || !bitmap_data) { LOG(ERROR) << "cannot create a bitmap: " << GetLastError(); diff --git a/chrome/browser/ui/window_snapshot/window_snapshot_win.cc b/chrome/browser/ui/window_snapshot/window_snapshot_win.cc index f3c5269..d38ed5c 100644 --- a/chrome/browser/ui/window_snapshot/window_snapshot_win.cc +++ b/chrome/browser/ui/window_snapshot/window_snapshot_win.cc @@ -43,36 +43,29 @@ bool GrabWindowSnapshot(gfx::NativeWindow window_handle, &hdr); unsigned char *bit_ptr = NULL; base::win::ScopedBitmap bitmap( - CreateDIBSection(mem_hdc, + CreateDIBSection(mem_hdc.get(), reinterpret_cast<BITMAPINFO*>(&hdr), DIB_RGB_COLORS, reinterpret_cast<void **>(&bit_ptr), NULL, 0)); - base::win::ScopedSelectObject select_bitmap(mem_hdc, bitmap); + base::win::ScopedSelectObject select_bitmap(mem_hdc.get(), bitmap); // Clear the bitmap to white (so that rounded corners on windows // show up on a white background, and strangely-shaped windows // look reasonable). Not capturing an alpha mask saves a // bit of space. - PatBlt(mem_hdc, 0, 0, snapshot_bounds.width(), snapshot_bounds.height(), + PatBlt(mem_hdc.get(), 0, 0, snapshot_bounds.width(), snapshot_bounds.height(), WHITENESS); - // Grab a copy of the window - // First, see if PrintWindow is defined (it's not in Windows 2000). - typedef BOOL (WINAPI *PrintWindowPointer)(HWND, HDC, UINT); - PrintWindowPointer print_window = - reinterpret_cast<PrintWindowPointer>( - GetProcAddress(GetModuleHandle(L"User32.dll"), "PrintWindow")); - - // If PrintWindow is defined, use it. It will work on partially - // obscured windows, and works better for out of process sub-windows. - // Otherwise grab the bits we can get with BitBlt; it's better - // than nothing and will work fine in the average case (window is - // completely on screen). - if (snapshot_bounds.origin() == gfx::Point() && print_window) - (*print_window)(window_handle, mem_hdc, 0); - else - BitBlt(mem_hdc, 0, 0, snapshot_bounds.width(), snapshot_bounds.height(), - window_hdc, snapshot_bounds.x(), snapshot_bounds.y(), SRCCOPY); + + if (snapshot_bounds.origin() != gfx::Point()) { + BitBlt(mem_hdc.get(), + 0, 0, snapshot_bounds.width(), snapshot_bounds.height(), + window_hdc, + snapshot_bounds.x(), snapshot_bounds.y(), + SRCCOPY); + } else if (!PrintWindow(window_handle, mem_hdc.get(), 0)) { + NOTREACHED(); + } // We now have a copy of the window contents in a DIB, so // encode it into a useful format for posting to the bug report diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc index 3ed93fd..1cac932 100644 --- a/chrome/renderer/print_web_view_helper_win.cc +++ b/chrome/renderer/print_web_view_helper_win.cc @@ -279,23 +279,23 @@ Metafile* PrintWebViewHelper::RenderPage( // Page used alpha blend, but printer doesn't support it. Rewrite the // metafile and flatten out the transparency. base::win::ScopedGetDC screen_dc(NULL); - base::win::ScopedCreateDC bitmap_dc(CreateCompatibleDC(screen_dc)); - if (!bitmap_dc) + base::win::ScopedCreateDC bitmap_dc(CreateCompatibleDC(screen_dc.get())); + if (!bitmap_dc.get()) NOTREACHED() << "Bitmap DC creation failed"; - SetGraphicsMode(bitmap_dc, GM_ADVANCED); + SetGraphicsMode(bitmap_dc.get(), GM_ADVANCED); void* bits = NULL; BITMAPINFO hdr; gfx::CreateBitmapHeader(page_size.width(), page_size.height(), &hdr.bmiHeader); base::win::ScopedBitmap hbitmap(CreateDIBSection( - bitmap_dc, &hdr, DIB_RGB_COLORS, &bits, NULL, 0)); + bitmap_dc.get(), &hdr, DIB_RGB_COLORS, &bits, NULL, 0)); if (!hbitmap) NOTREACHED() << "Raster bitmap creation for printing failed"; - base::win::ScopedSelectObject selectBitmap(bitmap_dc, hbitmap); + base::win::ScopedSelectObject selectBitmap(bitmap_dc.get(), hbitmap); RECT rect = { 0, 0, page_size.width(), page_size.height() }; HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH)); - FillRect(bitmap_dc, &rect, whiteBrush); + FillRect(bitmap_dc.get(), &rect, whiteBrush); Metafile* metafile2(new printing::NativeMetafile); metafile2->Init(); diff --git a/chrome/service/cloud_print/print_system_win.cc b/chrome/service/cloud_print/print_system_win.cc index d9d7dbf..7ab5b21 100644 --- a/chrome/service/cloud_print/print_system_win.cc +++ b/chrome/service/cloud_print/print_system_win.cc @@ -406,10 +406,10 @@ class PrintSystemWin : public PrintSystem { HDC dc = CreateDC(L"WINSPOOL", UTF8ToWide(printer_name).c_str(), NULL, pt_dev_mode.dm_); - if (!dc) { - NOTREACHED(); + if (!dc) return false; - } + + printer_dc_.Set(dc); hr = E_FAIL; DOCINFO di = {0}; di.cbSize = sizeof(DOCINFO); @@ -419,8 +419,7 @@ class PrintSystemWin : public PrintSystem { if (job_id_ <= 0) return false; - printer_dc_.Set(dc); - saved_dc_ = SaveDC(printer_dc_.Get()); + saved_dc_ = SaveDC(printer_dc_.get()); print_data_file_path_ = print_data_file_path; delegate_ = delegate; RenderNextPDFPages(); @@ -440,18 +439,18 @@ class PrintSystemWin : public PrintSystem { } void PreparePageDCForPrinting(HDC, double scale_factor) { - SetGraphicsMode(printer_dc_.Get(), GM_ADVANCED); + SetGraphicsMode(printer_dc_.get(), GM_ADVANCED); // Setup the matrix to translate and scale to the right place. Take in // account the scale factor. // Note that the printing output is relative to printable area of // the page. That is 0,0 is offset by PHYSICALOFFSETX/Y from the page. - int offset_x = ::GetDeviceCaps(printer_dc_.Get(), PHYSICALOFFSETX); - int offset_y = ::GetDeviceCaps(printer_dc_.Get(), PHYSICALOFFSETY); + int offset_x = ::GetDeviceCaps(printer_dc_.get(), PHYSICALOFFSETX); + int offset_y = ::GetDeviceCaps(printer_dc_.get(), PHYSICALOFFSETY); XFORM xform = {0}; xform.eDx = static_cast<float>(-offset_x); xform.eDy = static_cast<float>(-offset_y); xform.eM11 = xform.eM22 = 1.0 / scale_factor; - SetWorldTransform(printer_dc_.Get(), &xform); + SetWorldTransform(printer_dc_.get(), &xform); } // ServiceUtilityProcessHost::Client implementation. @@ -459,8 +458,8 @@ class PrintSystemWin : public PrintSystem { const printing::Emf& metafile, int highest_rendered_page_number, double scale_factor) OVERRIDE { - PreparePageDCForPrinting(printer_dc_.Get(), scale_factor); - metafile.SafePlayback(printer_dc_.Get()); + PreparePageDCForPrinting(printer_dc_.get(), scale_factor); + metafile.SafePlayback(printer_dc_.get()); bool done_printing = (highest_rendered_page_number != last_page_printed_ + kPageCountPerBatch); last_page_printed_ = highest_rendered_page_number; @@ -514,8 +513,8 @@ class PrintSystemWin : public PrintSystem { // If there is no delegate, then there is nothing pending to process. if (!delegate_) return; - RestoreDC(printer_dc_.Get(), saved_dc_); - EndDoc(printer_dc_.Get()); + RestoreDC(printer_dc_.get(), saved_dc_); + EndDoc(printer_dc_.get()); if (-1 == last_page_printed_) { delegate_->OnJobSpoolFailed(); } else { @@ -532,9 +531,9 @@ class PrintSystemWin : public PrintSystem { std::vector<printing::PageRange> page_ranges; page_ranges.push_back(range); - int printer_dpi = ::GetDeviceCaps(printer_dc_.Get(), LOGPIXELSX); - int dc_width = GetDeviceCaps(printer_dc_.Get(), PHYSICALWIDTH); - int dc_height = GetDeviceCaps(printer_dc_.Get(), PHYSICALHEIGHT); + int printer_dpi = ::GetDeviceCaps(printer_dc_.get(), LOGPIXELSX); + int dc_width = GetDeviceCaps(printer_dc_.get(), PHYSICALWIDTH); + int dc_height = GetDeviceCaps(printer_dc_.get(), PHYSICALHEIGHT); gfx::Rect render_area(0, 0, dc_width, dc_height); g_service_process->io_thread()->message_loop_proxy()->PostTask( FROM_HERE, diff --git a/printing/emf_win_unittest.cc b/printing/emf_win_unittest.cc index add23f9..5ed83d1 100644 --- a/printing/emf_win_unittest.cc +++ b/printing/emf_win_unittest.cc @@ -127,7 +127,7 @@ TEST_F(EmfPrintingTest, Enumerate) { TEST_F(EmfPrintingTest, PageBreak) { base::win::ScopedCreateDC dc( CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL)); - if (!dc.Get()) + if (!dc.get()) return; uint32 size; std::vector<BYTE> data; @@ -153,11 +153,11 @@ TEST_F(EmfPrintingTest, PageBreak) { DOCINFO di = {0}; di.cbSize = sizeof(DOCINFO); di.lpszDocName = L"Test Job"; - int job_id = ::StartDoc(dc.Get(), &di); + int job_id = ::StartDoc(dc.get(), &di); Emf emf; EXPECT_TRUE(emf.InitFromData(&data.front(), size)); - EXPECT_TRUE(emf.SafePlayback(dc.Get())); - ::EndDoc(dc.Get()); + EXPECT_TRUE(emf.SafePlayback(dc.get())); + ::EndDoc(dc.get()); // Since presumably the printer is not real, let us just delete the job from // the queue. HANDLE printer = NULL; diff --git a/remoting/host/disconnect_window_win.cc b/remoting/host/disconnect_window_win.cc index a9f7742..63d420f 100644 --- a/remoting/host/disconnect_window_win.cc +++ b/remoting/host/disconnect_window_win.cc @@ -214,8 +214,8 @@ static int GetControlTextWidth(HWND control) { if (result) { base::win::ScopedGetDC dc(control); base::win::ScopedSelectObject font( - dc, (HFONT)SendMessage(control, WM_GETFONT, 0, 0)); - DrawText(dc, text, -1, &rect, DT_CALCRECT|DT_SINGLELINE); + dc.get(), (HFONT)SendMessage(control, WM_GETFONT, 0, 0)); + DrawText(dc.get(), text, -1, &rect, DT_CALCRECT|DT_SINGLELINE); } return rect.right; } diff --git a/ui/gfx/native_theme_win.cc b/ui/gfx/native_theme_win.cc index 66a9130..bba3ad1 100644 --- a/ui/gfx/native_theme_win.cc +++ b/ui/gfx/native_theme_win.cc @@ -635,18 +635,18 @@ HRESULT NativeThemeWin::PaintMenuArrow(HDC hdc, base::win::ScopedCreateDC mem_dc(CreateCompatibleDC(hdc)); base::win::ScopedBitmap mem_bitmap(CreateCompatibleBitmap(hdc, r.width(), r.height())); - base::win::ScopedSelectObject select_bitmap(mem_dc, mem_bitmap); + base::win::ScopedSelectObject select_bitmap(mem_dc.get(), mem_bitmap); // Copy and horizontally mirror the background from hdc into mem_dc. Use // a negative-width source rect, starting at the rightmost pixel. - StretchBlt(mem_dc, 0, 0, r.width(), r.height(), + StretchBlt(mem_dc.get(), 0, 0, r.width(), r.height(), hdc, r.right()-1, r.y(), -r.width(), r.height(), SRCCOPY); // Draw the arrow. RECT theme_rect = {0, 0, r.width(), r.height()}; - HRESULT result = draw_theme_(handle, mem_dc, MENU_POPUPSUBMENU, + HRESULT result = draw_theme_(handle, mem_dc.get(), MENU_POPUPSUBMENU, state_id, &theme_rect, NULL); // Copy and mirror the result back into mem_dc. StretchBlt(hdc, r.x(), r.y(), r.width(), r.height(), - mem_dc, r.width()-1, 0, -r.width(), r.height(), SRCCOPY); + mem_dc.get(), r.width()-1, 0, -r.width(), r.height(), SRCCOPY); return result; } } @@ -1668,9 +1668,9 @@ HRESULT NativeThemeWin::PaintFrameControl(HDC hdc, return E_OUTOFMEMORY; base::win::ScopedCreateDC bitmap_dc(CreateCompatibleDC(NULL)); - base::win::ScopedSelectObject select_bitmap(bitmap_dc, mask_bitmap); + base::win::ScopedSelectObject select_bitmap(bitmap_dc.get(), mask_bitmap); RECT local_rect = { 0, 0, width, height }; - DrawFrameControl(bitmap_dc, &local_rect, type, state); + DrawFrameControl(bitmap_dc.get(), &local_rect, type, state); // We're going to use BitBlt with a b&w mask. This results in using the dest // dc's text color for the black bits in the mask, and the dest dc's @@ -1699,7 +1699,11 @@ HRESULT NativeThemeWin::PaintFrameControl(HDC hdc, } COLORREF old_bg_color = SetBkColor(hdc, GetSysColor(bg_color_key)); COLORREF old_text_color = SetTextColor(hdc, GetSysColor(text_color_key)); - BitBlt(hdc, rect.x(), rect.y(), width, height, bitmap_dc, 0, 0, SRCCOPY); + BitBlt(hdc, + rect.x(), rect.y(), width, height, + bitmap_dc.get(), + 0, 0, + SRCCOPY); SetBkColor(hdc, old_bg_color); SetTextColor(hdc, old_text_color); |