summaryrefslogtreecommitdiffstats
path: root/base/gfx
diff options
context:
space:
mode:
authorbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-24 15:04:46 +0000
committerbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-24 15:04:46 +0000
commit106b7fa4a08f6defa54512a0a93f7a773bc15e38 (patch)
treef4776a2aacc61b81a9febb15286ce5b053dc7cf6 /base/gfx
parentd430015b83deb8ce3fecb9a36a8a21c61a19afc6 (diff)
downloadchromium_src-106b7fa4a08f6defa54512a0a93f7a773bc15e38.zip
chromium_src-106b7fa4a08f6defa54512a0a93f7a773bc15e38.tar.gz
chromium_src-106b7fa4a08f6defa54512a0a93f7a773bc15e38.tar.bz2
When a bitmap allocation fails, do some checks that will crash in different
ways so we can get a better picture when looking at the crash reports of why the allocation might be failing. BUG=1275638 Review URL: http://codereview.chromium.org/3119 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2548 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/gfx')
-rw-r--r--base/gfx/bitmap_platform_device_win.cc31
1 files changed, 30 insertions, 1 deletions
diff --git a/base/gfx/bitmap_platform_device_win.cc b/base/gfx/bitmap_platform_device_win.cc
index b8d83c4..4214412 100644
--- a/base/gfx/bitmap_platform_device_win.cc
+++ b/base/gfx/bitmap_platform_device_win.cc
@@ -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,33 @@ void FixupAlphaBeforeCompositing(uint32_t* pixel) {
*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 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.
+ 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<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 +298,8 @@ BitmapPlatformDeviceWin* BitmapPlatformDeviceWin::create(HDC screen_dc,
// 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);