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

Side by Side Diff: skia/ext/skia_utils_win.cc

Issue 2365903002: Fix GDI leak in NativeThemeWin::PaintIndirect (Closed)
Patch Set: Created 4 years, 2 months 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "skia/ext/skia_utils_win.h" 5 #include "skia/ext/skia_utils_win.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <windows.h> 8 #include <windows.h>
9 9
10 #include "base/debug/gdi_debug_util_win.h" 10 #include "base/debug/gdi_debug_util_win.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 188
189 SkBitmap MapPlatformBitmap(HDC context) { 189 SkBitmap MapPlatformBitmap(HDC context) {
190 BITMAP backing; 190 BITMAP backing;
191 const SkImageInfo size(PrepareAllocation(context, &backing)); 191 const SkImageInfo size(PrepareAllocation(context, &backing));
192 SkBitmap bitmap; 192 SkBitmap bitmap;
193 if (!size.isEmpty()) 193 if (!size.isEmpty())
194 bitmap.installPixels(size, backing.bmBits, size.minRowBytes()); 194 bitmap.installPixels(size, backing.bmBits, size.minRowBytes());
195 return bitmap; 195 return bitmap;
196 } 196 }
197 197
198 HDC CreateOffscreenSurface(int width, int height) { 198 HDC CreateOffscreenSurface(base::win::ScopedBitmap* bitmap,
199 HBITMAP bitmap = nullptr; 199 int width,
200 200 int height) {
201 DCHECK(bitmap);
Peter Kasting 2016/09/23 18:45:00 Nit: Blank line below this
Rafał Chłodnicki 2016/09/26 10:12:09 Done.
201 // If this process doesn't have access to GDI, we'll have to use a shared 202 // If this process doesn't have access to GDI, we'll have to use a shared
202 // memory segment instead. 203 // memory segment instead.
203 if (!base::win::IsUser32AndGdi32Available()) 204 if (!base::win::IsUser32AndGdi32Available())
204 return nullptr; 205 return nullptr;
205 206
206 bitmap = CreateHBitmap(width, height, false, nullptr, nullptr);
207 if (!bitmap)
208 return nullptr;
209
210 base::win::ScopedCreateDC scoped_hdc(CreateCompatibleDC(nullptr)); 207 base::win::ScopedCreateDC scoped_hdc(CreateCompatibleDC(nullptr));
211 if (!scoped_hdc.IsValid()) 208 if (!scoped_hdc.IsValid())
212 return nullptr; 209 return nullptr;
210
213 InitializeDC(scoped_hdc.Get()); 211 InitializeDC(scoped_hdc.Get());
214 HRGN clip = CreateRectRgn(0, 0, width, height); 212 HRGN clip = CreateRectRgn(0, 0, width, height);
215 if ((SelectClipRgn(scoped_hdc.Get(), clip) == ERROR) || 213 if (SelectClipRgn(scoped_hdc.Get(), clip) == ERROR || !DeleteObject(clip))
Peter Kasting 2016/09/23 18:45:00 Nit: Removing the second set of parnes was good, I
Rafał Chłodnicki 2016/09/26 10:12:09 Done.
216 (!DeleteObject(clip)))
217 return nullptr; 214 return nullptr;
218 215
219 SelectObject(scoped_hdc.Get(), bitmap); 216 bitmap->reset(CreateHBitmap(width, height, false, nullptr, nullptr));
217 if (!bitmap->is_valid())
218 return nullptr;
219
220 SelectObject(scoped_hdc.Get(), bitmap->get());
220 221
221 // The caller must call DeleteDC(hdc) on this object once done with it. 222 // The caller must call DeleteDC(hdc) on this object once done with it.
222 return scoped_hdc.Take(); 223 return scoped_hdc.Take();
223 } 224 }
224 225
225 void CreateBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr) { 226 void CreateBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr) {
226 CreateBitmapHeaderWithColorDepth(width, height, 32, hdr); 227 CreateBitmapHeaderWithColorDepth(width, height, 32, hdr);
227 } 228 }
228 229
229 HBITMAP CreateHBitmap(int width, int height, bool is_opaque, 230 HBITMAP CreateHBitmap(int width, int height, bool is_opaque,
(...skipping 13 matching lines...) Expand all
243 // If CreateDIBSection() failed, try to get some useful information out 244 // If CreateDIBSection() failed, try to get some useful information out
244 // before we crash for post-mortem analysis. 245 // before we crash for post-mortem analysis.
245 if (!hbitmap) 246 if (!hbitmap)
246 base::debug::GDIBitmapAllocFailure(&hdr, shared_section); 247 base::debug::GDIBitmapAllocFailure(&hdr, shared_section);
247 248
248 return hbitmap; 249 return hbitmap;
249 } 250 }
250 251
251 } // namespace skia 252 } // namespace skia
252 253
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698