Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "skia/ext/bitmap_platform_device_win.h" | 8 #include "skia/ext/bitmap_platform_device_win.h" |
| 9 | 9 |
| 10 #include "base/logging.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/process_util.h" | |
| 10 #include "skia/ext/bitmap_platform_device_data.h" | 13 #include "skia/ext/bitmap_platform_device_data.h" |
| 11 #include "third_party/skia/include/core/SkMatrix.h" | 14 #include "third_party/skia/include/core/SkMatrix.h" |
| 12 #include "third_party/skia/include/core/SkRefCnt.h" | 15 #include "third_party/skia/include/core/SkRefCnt.h" |
| 13 #include "third_party/skia/include/core/SkRegion.h" | 16 #include "third_party/skia/include/core/SkRegion.h" |
| 14 #include "third_party/skia/include/core/SkUtils.h" | 17 #include "third_party/skia/include/core/SkUtils.h" |
| 15 | 18 |
| 19 namespace { | |
| 20 // Crashes the process. This is called when a bitmap allocation fails, and this | |
| 21 // function tries to determine why it might have failed, and crash on different | |
| 22 // lines. This allows us to see in crash dumps the most likely reason for the | |
| 23 // failure. It takes the size of the bitmap we were trying to allocate as its | |
| 24 // arguments so we can check that as well. | |
| 25 void CrashForBitmapAllocationFailure(int w, int h) { | |
| 26 // The maximum number of GDI objects per process is 10K. If we're very close | |
| 27 // to that, it's probably the problem. | |
| 28 const int kLotsOfGDIObjs = 9990; | |
| 29 CHECK(GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS) < kLotsOfGDIObjs); | |
| 30 | |
| 31 // If the bitmap is ginormous, then we probably can't allocate it. | |
| 32 // 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
| |
| 33 const int64 kGinormousBitmapPxl = 64000000; | |
| 34 CHECK(static_cast<int64>(w) * static_cast<int64>(h) < kGinormousBitmapPxl); | |
| 35 | |
| 36 // If we're using a crazy amount of virtual address space, then maybe there | |
| 37 // isn't enough for our bitmap. | |
| 38 const int64 kLotsOfMem = 1500000000; // 1.5GB. | |
| 39 scoped_ptr<base::ProcessMetrics> process_metrics( | |
| 40 base::ProcessMetrics::CreateProcessMetrics(GetCurrentProcess())); | |
| 41 CHECK(process_metrics->GetPagefileUsage() < kLotsOfMem); | |
| 42 | |
| 43 // Everything else. | |
| 44 CHECK(0); | |
|
vandebo (ex-Chrome)
2011/10/28 17:09:06
nit: CHECK(false);
| |
| 45 } | |
| 46 | |
| 47 } | |
| 48 | |
| 16 namespace skia { | 49 namespace skia { |
| 17 | 50 |
| 18 BitmapPlatformDevice::BitmapPlatformDeviceData::BitmapPlatformDeviceData( | 51 BitmapPlatformDevice::BitmapPlatformDeviceData::BitmapPlatformDeviceData( |
| 19 HBITMAP hbitmap) | 52 HBITMAP hbitmap) |
| 20 : bitmap_context_(hbitmap), | 53 : bitmap_context_(hbitmap), |
| 21 hdc_(NULL), | 54 hdc_(NULL), |
| 22 config_dirty_(true) { // Want to load the config next time. | 55 config_dirty_(true) { // Want to load the config next time. |
| 23 // Initialize the clip region to the entire bitmap. | 56 // Initialize the clip region to the entire bitmap. |
| 24 BITMAP bitmap_data; | 57 BITMAP bitmap_data; |
| 25 if (GetObject(bitmap_context_, sizeof(BITMAP), &bitmap_data)) { | 58 if (GetObject(bitmap_context_, sizeof(BITMAP), &bitmap_data)) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 hdr.biYPelsPerMeter = 1; | 148 hdr.biYPelsPerMeter = 1; |
| 116 hdr.biClrUsed = 0; | 149 hdr.biClrUsed = 0; |
| 117 hdr.biClrImportant = 0; | 150 hdr.biClrImportant = 0; |
| 118 | 151 |
| 119 void* data = NULL; | 152 void* data = NULL; |
| 120 HBITMAP hbitmap = CreateDIBSection(screen_dc, | 153 HBITMAP hbitmap = CreateDIBSection(screen_dc, |
| 121 reinterpret_cast<BITMAPINFO*>(&hdr), 0, | 154 reinterpret_cast<BITMAPINFO*>(&hdr), 0, |
| 122 &data, | 155 &data, |
| 123 shared_section, 0); | 156 shared_section, 0); |
| 124 if (!hbitmap) { | 157 if (!hbitmap) { |
| 158 CrashForBitmapAllocationFailure(width, height); | |
| 125 return NULL; | 159 return NULL; |
| 126 } | 160 } |
| 127 | 161 |
| 128 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 162 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 129 bitmap.setPixels(data); | 163 bitmap.setPixels(data); |
| 130 bitmap.setIsOpaque(is_opaque); | 164 bitmap.setIsOpaque(is_opaque); |
| 131 | 165 |
| 132 // If we were given data, then don't clobber it! | 166 // If we were given data, then don't clobber it! |
| 133 if (!shared_section) { | 167 if (!shared_section) { |
| 134 if (is_opaque) { | 168 if (is_opaque) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 } | 290 } |
| 257 | 291 |
| 258 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( | 292 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( |
| 259 SkBitmap::Config config, int width, int height, bool isOpaque, | 293 SkBitmap::Config config, int width, int height, bool isOpaque, |
| 260 Usage /*usage*/) { | 294 Usage /*usage*/) { |
| 261 SkASSERT(config == SkBitmap::kARGB_8888_Config); | 295 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
| 262 return BitmapPlatformDevice::create(width, height, isOpaque, NULL); | 296 return BitmapPlatformDevice::create(width, height, isOpaque, NULL); |
| 263 } | 297 } |
| 264 | 298 |
| 265 } // namespace skia | 299 } // namespace skia |
| OLD | NEW |