| 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/debug/gdi_debug_util_win.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/debug/alias.h" | |
| 10 #include "skia/ext/bitmap_platform_device_win.h" | 10 #include "skia/ext/bitmap_platform_device_win.h" |
| 11 #include "skia/ext/platform_canvas.h" | 11 #include "skia/ext/platform_canvas.h" |
| 12 #include "third_party/skia/include/core/SkMatrix.h" | 12 #include "third_party/skia/include/core/SkMatrix.h" |
| 13 #include "third_party/skia/include/core/SkRefCnt.h" | 13 #include "third_party/skia/include/core/SkRefCnt.h" |
| 14 #include "third_party/skia/include/core/SkRegion.h" | 14 #include "third_party/skia/include/core/SkRegion.h" |
| 15 #include "third_party/skia/include/core/SkUtils.h" | 15 #include "third_party/skia/include/core/SkUtils.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 HBITMAP CreateHBitmap(int width, int height, bool is_opaque, | 19 HBITMAP CreateHBitmap(int width, int height, bool is_opaque, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 34 hdr.biCompression = BI_RGB; // no compression | 34 hdr.biCompression = BI_RGB; // no compression |
| 35 hdr.biSizeImage = 0; | 35 hdr.biSizeImage = 0; |
| 36 hdr.biXPelsPerMeter = 1; | 36 hdr.biXPelsPerMeter = 1; |
| 37 hdr.biYPelsPerMeter = 1; | 37 hdr.biYPelsPerMeter = 1; |
| 38 hdr.biClrUsed = 0; | 38 hdr.biClrUsed = 0; |
| 39 hdr.biClrImportant = 0; | 39 hdr.biClrImportant = 0; |
| 40 | 40 |
| 41 HBITMAP hbitmap = CreateDIBSection(NULL, reinterpret_cast<BITMAPINFO*>(&hdr), | 41 HBITMAP hbitmap = CreateDIBSection(NULL, reinterpret_cast<BITMAPINFO*>(&hdr), |
| 42 0, data, shared_section, 0); | 42 0, data, shared_section, 0); |
| 43 | 43 |
| 44 #if !defined(_WIN64) |
| 44 // If this call fails, we're gonna crash hard. Try to get some useful | 45 // If this call fails, we're gonna crash hard. Try to get some useful |
| 45 // information out before we crash for post-mortem analysis. | 46 // information out before we crash for post-mortem analysis. |
| 46 if (!hbitmap) { | 47 if (!hbitmap) |
| 47 // Make sure parameters are saved in the minidump. | 48 base::debug::GDIBitmapAllocFailure(&hdr, shared_section); |
| 48 base::debug::Alias(&width); | 49 #endif |
| 49 base::debug::Alias(&height); | |
| 50 | 50 |
| 51 int last_error = GetLastError(); | |
| 52 base::debug::Alias(&last_error); | |
| 53 | |
| 54 int num_gdi_handles = GetGuiResources(GetCurrentProcess(), | |
| 55 GR_GDIOBJECTS); | |
| 56 if (num_gdi_handles == 0) { | |
| 57 int get_gui_resources_error = GetLastError(); | |
| 58 base::debug::Alias(&get_gui_resources_error); | |
| 59 CHECK(false); | |
| 60 } | |
| 61 | |
| 62 base::debug::Alias(&num_gdi_handles); | |
| 63 const int kLotsOfHandles = 9990; | |
| 64 if (num_gdi_handles > kLotsOfHandles) | |
| 65 CHECK(false); | |
| 66 | |
| 67 PROCESS_MEMORY_COUNTERS_EX pmc; | |
| 68 pmc.cb = sizeof(pmc); | |
| 69 if (!GetProcessMemoryInfo(GetCurrentProcess(), | |
| 70 reinterpret_cast<PROCESS_MEMORY_COUNTERS*>(&pmc), | |
| 71 sizeof(pmc))) { | |
| 72 CHECK(false); | |
| 73 } | |
| 74 const size_t kLotsOfMemory = 1500 * 1024 * 1024; // 1.5GB | |
| 75 if (pmc.PagefileUsage > kLotsOfMemory) | |
| 76 CHECK(false); | |
| 77 if (pmc.PrivateUsage > kLotsOfMemory) | |
| 78 CHECK(false); | |
| 79 | |
| 80 // Huh, that's weird. We don't have crazy handle count, we don't have | |
| 81 // ridiculous memory usage. Try to allocate a small bitmap and see if that | |
| 82 // fails too. | |
| 83 hdr.biWidth = 5; | |
| 84 hdr.biHeight = 5; | |
| 85 void* small_data; | |
| 86 HBITMAP small_bitmap = CreateDIBSection( | |
| 87 NULL, reinterpret_cast<BITMAPINFO*>(&hdr), | |
| 88 0, &small_data, shared_section, 0); | |
| 89 if (!small_bitmap) | |
| 90 CHECK(false); | |
| 91 BITMAP bitmap_data; | |
| 92 if (GetObject(small_bitmap, sizeof(BITMAP), &bitmap_data)) { | |
| 93 if (!DeleteObject(small_bitmap)) | |
| 94 CHECK(false); | |
| 95 } | |
| 96 // No idea what's going on. Die! | |
| 97 CHECK(false); | |
| 98 } | |
| 99 return hbitmap; | 51 return hbitmap; |
| 100 } | 52 } |
| 101 | 53 |
| 102 } // namespace | 54 } // namespace |
| 103 | 55 |
| 104 namespace skia { | 56 namespace skia { |
| 105 | 57 |
| 106 HDC BitmapPlatformDevice::GetBitmapDC() { | 58 HDC BitmapPlatformDevice::GetBitmapDC() { |
| 107 if (!hdc_) { | 59 if (!hdc_) { |
| 108 hdc_ = CreateCompatibleDC(NULL); | 60 hdc_ = CreateCompatibleDC(NULL); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 platform_extra_ = reinterpret_cast<intptr_t>(stock_bitmap); | 312 platform_extra_ = reinterpret_cast<intptr_t>(stock_bitmap); |
| 361 | 313 |
| 362 if (!InstallHBitmapPixels(&bitmap_, width, height, is_opaque, data, hbitmap)) | 314 if (!InstallHBitmapPixels(&bitmap_, width, height, is_opaque, data, hbitmap)) |
| 363 return false; | 315 return false; |
| 364 bitmap_.lockPixels(); | 316 bitmap_.lockPixels(); |
| 365 | 317 |
| 366 return true; | 318 return true; |
| 367 } | 319 } |
| 368 | 320 |
| 369 } // namespace skia | 321 } // namespace skia |
| OLD | NEW |