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 #include <windows.h> | 5 #include <windows.h> |
6 #include <psapi.h> | 6 #include <psapi.h> |
7 | 7 |
| 8 #include "base/logging.h" |
| 9 #include "base/debug/alias.h" |
8 #include "skia/ext/bitmap_platform_device_win.h" | 10 #include "skia/ext/bitmap_platform_device_win.h" |
9 #include "skia/ext/bitmap_platform_device_data.h" | 11 #include "skia/ext/bitmap_platform_device_data.h" |
10 #include "skia/ext/platform_canvas.h" | 12 #include "skia/ext/platform_canvas.h" |
11 #include "third_party/skia/include/core/SkMatrix.h" | 13 #include "third_party/skia/include/core/SkMatrix.h" |
12 #include "third_party/skia/include/core/SkRefCnt.h" | 14 #include "third_party/skia/include/core/SkRefCnt.h" |
13 #include "third_party/skia/include/core/SkRegion.h" | 15 #include "third_party/skia/include/core/SkRegion.h" |
14 #include "third_party/skia/include/core/SkUtils.h" | 16 #include "third_party/skia/include/core/SkUtils.h" |
15 | 17 |
16 namespace { | 18 namespace { |
17 | 19 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 hdr.biBitCount = 32; | 52 hdr.biBitCount = 32; |
51 hdr.biCompression = BI_RGB; // no compression | 53 hdr.biCompression = BI_RGB; // no compression |
52 hdr.biSizeImage = 0; | 54 hdr.biSizeImage = 0; |
53 hdr.biXPelsPerMeter = 1; | 55 hdr.biXPelsPerMeter = 1; |
54 hdr.biYPelsPerMeter = 1; | 56 hdr.biYPelsPerMeter = 1; |
55 hdr.biClrUsed = 0; | 57 hdr.biClrUsed = 0; |
56 hdr.biClrImportant = 0; | 58 hdr.biClrImportant = 0; |
57 | 59 |
58 HBITMAP hbitmap = CreateDIBSection(NULL, reinterpret_cast<BITMAPINFO*>(&hdr), | 60 HBITMAP hbitmap = CreateDIBSection(NULL, reinterpret_cast<BITMAPINFO*>(&hdr), |
59 0, data, shared_section, 0); | 61 0, data, shared_section, 0); |
| 62 |
| 63 // If this call fails, we're gonna crash hard. Try to get some useful |
| 64 // information out before we crash for post-mortem analysis. |
| 65 if (!hbitmap) { |
| 66 // Make sure parameters are saved in the minidump. |
| 67 base::debug::Alias(&width); |
| 68 base::debug::Alias(&height); |
| 69 |
| 70 int last_error = GetLastError(); |
| 71 base::debug::Alias(&last_error); |
| 72 |
| 73 int num_gdi_handles = GetGuiResources(GetCurrentProcess(), |
| 74 GR_GDIOBJECTS); |
| 75 if (num_gdi_handles == 0) { |
| 76 int get_gui_resources_error = GetLastError(); |
| 77 base::debug::Alias(&get_gui_resources_error); |
| 78 CHECK(false); |
| 79 } |
| 80 |
| 81 base::debug::Alias(&num_gdi_handles); |
| 82 const int kLotsOfHandles = 9990; |
| 83 if (num_gdi_handles > kLotsOfHandles) |
| 84 CHECK(false); |
| 85 |
| 86 PROCESS_MEMORY_COUNTERS_EX pmc; |
| 87 pmc.cb = sizeof(pmc); |
| 88 if (!GetProcessMemoryInfo(GetCurrentProcess(), |
| 89 reinterpret_cast<PROCESS_MEMORY_COUNTERS*>(&pmc), |
| 90 sizeof(pmc))) { |
| 91 CHECK(false); |
| 92 } |
| 93 const size_t kLotsOfMemory = 1500 * 1024 * 1024; // 1.5GB |
| 94 if (pmc.PagefileUsage > kLotsOfMemory) |
| 95 CHECK(false); |
| 96 if (pmc.PrivateUsage > kLotsOfMemory) |
| 97 CHECK(false); |
| 98 |
| 99 // Huh, that's weird. We don't have crazy handle count, we don't have |
| 100 // ridiculous memory usage. Try to allocate a small bitmap and see if that |
| 101 // fails too. |
| 102 hdr.biWidth = 5; |
| 103 hdr.biHeight = 5; |
| 104 void* small_data; |
| 105 HBITMAP small_bitmap = CreateDIBSection( |
| 106 NULL, reinterpret_cast<BITMAPINFO*>(&hdr), |
| 107 0, &small_data, shared_section, 0); |
| 108 if (!small_bitmap) |
| 109 CHECK(false); |
| 110 BITMAP bitmap_data; |
| 111 if (GetObject(small_bitmap, sizeof(BITMAP), &bitmap_data)) { |
| 112 if (!DeleteObject(small_bitmap)) |
| 113 CHECK(false); |
| 114 } |
| 115 // No idea what's going on. Die! |
| 116 CHECK(false); |
| 117 } |
60 return hbitmap; | 118 return hbitmap; |
61 } | 119 } |
62 | 120 |
63 PlatformBitmapPixelRef::PlatformBitmapPixelRef(HBITMAP bitmap_handle, | 121 PlatformBitmapPixelRef::PlatformBitmapPixelRef(HBITMAP bitmap_handle, |
64 void* pixels) | 122 void* pixels) |
65 : bitmap_handle_(bitmap_handle), | 123 : bitmap_handle_(bitmap_handle), |
66 pixels_(pixels) { | 124 pixels_(pixels) { |
67 setPreLocked(pixels, NULL); | 125 setPreLocked(pixels, NULL); |
68 } | 126 } |
69 | 127 |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | 405 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
348 // PlatformBitmapPixelRef takes ownership of |hbitmap|. | 406 // PlatformBitmapPixelRef takes ownership of |hbitmap|. |
349 bitmap_.setPixelRef( | 407 bitmap_.setPixelRef( |
350 skia::AdoptRef(new PlatformBitmapPixelRef(hbitmap, data)).get()); | 408 skia::AdoptRef(new PlatformBitmapPixelRef(hbitmap, data)).get()); |
351 bitmap_.lockPixels(); | 409 bitmap_.lockPixels(); |
352 | 410 |
353 return true; | 411 return true; |
354 } | 412 } |
355 | 413 |
356 } // namespace skia | 414 } // namespace skia |
OLD | NEW |