Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: printing/emf_win.cc

Issue 1406403007: Eliminate HICON leaks caused by creating icons from bitmap image. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use ScopedHICON instead of HICON. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "printing/emf_win.h" 5 #include "printing/emf_win.h"
6 6
7 #include "base/files/file.h" 7 #include "base/files/file.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 context_.Set(::CreateCompatibleDC(NULL)); 97 context_.Set(::CreateCompatibleDC(NULL));
98 if (!context_.IsValid()) { 98 if (!context_.IsValid()) {
99 NOTREACHED() << "Bitmap DC creation failed"; 99 NOTREACHED() << "Bitmap DC creation failed";
100 return; 100 return;
101 } 101 }
102 ::SetGraphicsMode(context_.Get(), GM_ADVANCED); 102 ::SetGraphicsMode(context_.Get(), GM_ADVANCED);
103 void* bits = NULL; 103 void* bits = NULL;
104 gfx::Rect bitmap_rect(raster_size); 104 gfx::Rect bitmap_rect(raster_size);
105 gfx::CreateBitmapHeader(raster_size.width(), raster_size.height(), 105 gfx::CreateBitmapHeader(raster_size.width(), raster_size.height(),
106 &header_.bmiHeader); 106 &header_.bmiHeader);
107 bitmap_.Set(::CreateDIBSection(context_.Get(), &header_, DIB_RGB_COLORS, 107 bitmap_.reset(CreateDIBSection(context_.Get(), &header_, DIB_RGB_COLORS,
108 &bits, NULL, 0)); 108 &bits, NULL, 0));
109 if (!bitmap_) 109 if (!bitmap_.is_valid())
110 NOTREACHED() << "Raster bitmap creation for printing failed"; 110 NOTREACHED() << "Raster bitmap creation for printing failed";
111 111
112 saved_object_ = ::SelectObject(context_.Get(), bitmap_); 112 saved_object_ = ::SelectObject(context_.Get(), bitmap_.get());
113 RECT rect = bitmap_rect.ToRECT(); 113 RECT rect = bitmap_rect.ToRECT();
114 ::FillRect(context_.Get(), &rect, 114 ::FillRect(context_.Get(), &rect,
115 static_cast<HBRUSH>(::GetStockObject(WHITE_BRUSH))); 115 static_cast<HBRUSH>(::GetStockObject(WHITE_BRUSH)));
116 } 116 }
117 117
118 ~RasterBitmap() { 118 ~RasterBitmap() {
119 ::SelectObject(context_.Get(), saved_object_); 119 ::SelectObject(context_.Get(), saved_object_);
120 } 120 }
121 121
122 HDC context() const { 122 HDC context() const {
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 RECT rect = page_bounds.ToRECT(); 597 RECT rect = page_bounds.ToRECT();
598 ::EnumEnhMetaFile(hdc, emf(), &RasterizeAlphaBlendProc, &bitmap_dc, &rect); 598 ::EnumEnhMetaFile(hdc, emf(), &RasterizeAlphaBlendProc, &bitmap_dc, &rect);
599 599
600 result->FinishDocument(); 600 result->FinishDocument();
601 601
602 return result.Pass(); 602 return result.Pass();
603 } 603 }
604 604
605 605
606 } // namespace printing 606 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698