Chromium Code Reviews| Index: base/gfx/bitmap_platform_device_win.cc |
| =================================================================== |
| --- base/gfx/bitmap_platform_device_win.cc (revision 2299) |
| +++ base/gfx/bitmap_platform_device_win.cc (working copy) |
| @@ -6,6 +6,7 @@ |
| #include "base/gfx/bitmap_header.h" |
| #include "base/logging.h" |
| +#include "base/process_util.h" |
| #include "SkMatrix.h" |
| #include "SkRegion.h" |
| #include "SkUtils.h" |
| @@ -98,6 +99,32 @@ |
| *pixel |= 0xFF000000; |
| } |
| +// Crashes the process. This is called when a bitmap allocation fails, and this |
| +// function tries to determine why it might have failed, and crash on different |
| +// lines. This allows us to see in crash dumps the most likely reason for the |
| +// failure. It takes |
|
Mike Belshe
2008/09/24 00:41:41
Incomplete sentence? "It takes"
|
| +void CrashForBitmapAllocationFailure(int w, int h) { |
| + // The maximum number of GDI objects per process is 10K. If we're very close |
| + // to that, it's probably the problem. |
| + const int kLotsOfGDIObjs = 9990; |
| + CHECK(GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS) < kLotsOfGDIObjs); |
| + |
| + // If the bitmap is ginormous, then we probably can't allocate it. |
| + // We use 64M pixels = 256MB @ 4 bytes per pixel. |
| + const int64 kGinormousBitmapPxl = 64000000; |
| + CHECK(static_cast<int64>(w) * static_cast<int64>(h) < kGinormousBitmapPxl); |
| + |
| + // If we're using a crazy amount of virtual address space, then maybe there |
| + // isn't enough for our bitmap. |
| + const int64 kLotsOfMem = 1500000000; // 1.5GB. |
|
Mike Belshe
2008/09/24 00:41:41
This is arbitrary, but I would have tripped this f
|
| + scoped_ptr<process_util::ProcessMetrics> process_metrics( |
| + process_util::ProcessMetrics::CreateProcessMetrics(GetCurrentProcess())); |
| + CHECK(process_metrics->GetPagefileUsage() < kLotsOfMem); |
| + |
| + // Everything else. |
| + CHECK(0); |
| +} |
| + |
| } // namespace |
| class BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData |
| @@ -270,7 +297,8 @@ |
| // bitmap here. This will cause us to crash later because the data pointer is |
| // NULL. To make sure that we can assign blame for those crashes to this code, |
| // we deliberately crash here, even in release mode. |
| - CHECK(hbitmap); |
| + if (!hbitmap) |
| + CrashForBitmapAllocationFailure(width, height); |
| bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| bitmap.setPixels(data); |