Chromium Code Reviews| Index: skia/ext/bitmap_platform_device_win.cc |
| diff --git a/skia/ext/bitmap_platform_device_win.cc b/skia/ext/bitmap_platform_device_win.cc |
| index 3a2a5b41f5f8a96a1ca2d6a0ce97a0fd4e59dc14..137ecf46aa621ce72f5f61935e25c129bafbed32 100644 |
| --- a/skia/ext/bitmap_platform_device_win.cc |
| +++ b/skia/ext/bitmap_platform_device_win.cc |
| @@ -7,12 +7,45 @@ |
| #include "skia/ext/bitmap_platform_device_win.h" |
| +#include "base/logging.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/process_util.h" |
| #include "skia/ext/bitmap_platform_device_data.h" |
| #include "third_party/skia/include/core/SkMatrix.h" |
| #include "third_party/skia/include/core/SkRefCnt.h" |
| #include "third_party/skia/include/core/SkRegion.h" |
| #include "third_party/skia/include/core/SkUtils.h" |
| +namespace { |
| +// 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 the size of the bitmap we were trying to allocate as its |
| +// arguments so we can check that as well. |
| +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. |
|
vandebo (ex-Chrome)
2011/10/28 17:09:06
nit: You don't use the 256MB number, so omit that
|
| + 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. |
| + scoped_ptr<base::ProcessMetrics> process_metrics( |
| + base::ProcessMetrics::CreateProcessMetrics(GetCurrentProcess())); |
| + CHECK(process_metrics->GetPagefileUsage() < kLotsOfMem); |
| + |
| + // Everything else. |
| + CHECK(0); |
|
vandebo (ex-Chrome)
2011/10/28 17:09:06
nit: CHECK(false);
|
| +} |
| + |
| +} |
| + |
| namespace skia { |
| BitmapPlatformDevice::BitmapPlatformDeviceData::BitmapPlatformDeviceData( |
| @@ -122,6 +155,7 @@ BitmapPlatformDevice* BitmapPlatformDevice::create( |
| &data, |
| shared_section, 0); |
| if (!hbitmap) { |
| + CrashForBitmapAllocationFailure(width, height); |
| return NULL; |
| } |