Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/gfx/bitmap_platform_device_win.h" | 5 #include "base/gfx/bitmap_platform_device_win.h" |
| 6 | 6 |
| 7 #include "base/gfx/bitmap_header.h" | 7 #include "base/gfx/bitmap_header.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/process_util.h" | |
| 9 #include "SkMatrix.h" | 10 #include "SkMatrix.h" |
| 10 #include "SkRegion.h" | 11 #include "SkRegion.h" |
| 11 #include "SkUtils.h" | 12 #include "SkUtils.h" |
| 12 | 13 |
| 13 namespace gfx { | 14 namespace gfx { |
| 14 | 15 |
| 15 // When Windows draws text, is sets the fourth byte (which Skia uses for alpha) | 16 // When Windows draws text, is sets the fourth byte (which Skia uses for alpha) |
| 16 // to zero. This means that if we try compositing with text that Windows has | 17 // to zero. This means that if we try compositing with text that Windows has |
| 17 // drawn, we get invalid color values (if the alpha is 0, the other channels | 18 // drawn, we get invalid color values (if the alpha is 0, the other channels |
| 18 // should be 0 since Skia uses premultiplied colors) and strange results. | 19 // should be 0 since Skia uses premultiplied colors) and strange results. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 } | 92 } |
| 92 | 93 |
| 93 // See the declaration of kMagicTransparencyColor at the top of the file. | 94 // See the declaration of kMagicTransparencyColor at the top of the file. |
| 94 void FixupAlphaBeforeCompositing(uint32_t* pixel) { | 95 void FixupAlphaBeforeCompositing(uint32_t* pixel) { |
| 95 if (*pixel == kMagicTransparencyColor) | 96 if (*pixel == kMagicTransparencyColor) |
| 96 *pixel = 0; | 97 *pixel = 0; |
| 97 else | 98 else |
| 98 *pixel |= 0xFF000000; | 99 *pixel |= 0xFF000000; |
| 99 } | 100 } |
| 100 | 101 |
| 102 // Crashes the process. This is called when a bitmap allocation fails, and this | |
| 103 // function tries to determine why it might have failed, and crash on different | |
| 104 // lines. This allows us to see in crash dumps the most likely reason for the | |
| 105 // failure. It takes | |
|
Mike Belshe
2008/09/24 00:41:41
Incomplete sentence? "It takes"
| |
| 106 void CrashForBitmapAllocationFailure(int w, int h) { | |
| 107 // The maximum number of GDI objects per process is 10K. If we're very close | |
| 108 // to that, it's probably the problem. | |
| 109 const int kLotsOfGDIObjs = 9990; | |
| 110 CHECK(GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS) < kLotsOfGDIObjs); | |
| 111 | |
| 112 // If the bitmap is ginormous, then we probably can't allocate it. | |
| 113 // We use 64M pixels = 256MB @ 4 bytes per pixel. | |
| 114 const int64 kGinormousBitmapPxl = 64000000; | |
| 115 CHECK(static_cast<int64>(w) * static_cast<int64>(h) < kGinormousBitmapPxl); | |
| 116 | |
| 117 // If we're using a crazy amount of virtual address space, then maybe there | |
| 118 // isn't enough for our bitmap. | |
| 119 const int64 kLotsOfMem = 1500000000; // 1.5GB. | |
|
Mike Belshe
2008/09/24 00:41:41
This is arbitrary, but I would have tripped this f
| |
| 120 scoped_ptr<process_util::ProcessMetrics> process_metrics( | |
| 121 process_util::ProcessMetrics::CreateProcessMetrics(GetCurrentProcess())); | |
| 122 CHECK(process_metrics->GetPagefileUsage() < kLotsOfMem); | |
| 123 | |
| 124 // Everything else. | |
| 125 CHECK(0); | |
| 126 } | |
| 127 | |
| 101 } // namespace | 128 } // namespace |
| 102 | 129 |
| 103 class BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData | 130 class BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData |
| 104 : public base::RefCounted<BitmapPlatformDeviceWinData> { | 131 : public base::RefCounted<BitmapPlatformDeviceWinData> { |
| 105 public: | 132 public: |
| 106 explicit BitmapPlatformDeviceWinData(HBITMAP hbitmap); | 133 explicit BitmapPlatformDeviceWinData(HBITMAP hbitmap); |
| 107 | 134 |
| 108 // Create/destroy hdc_, which is the memory DC for our bitmap data. | 135 // Create/destroy hdc_, which is the memory DC for our bitmap data. |
| 109 HDC GetBitmapDC(); | 136 HDC GetBitmapDC(); |
| 110 void ReleaseBitmapDC(); | 137 void ReleaseBitmapDC(); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 void* data; | 290 void* data; |
| 264 HBITMAP hbitmap = CreateDIBSection(screen_dc, | 291 HBITMAP hbitmap = CreateDIBSection(screen_dc, |
| 265 reinterpret_cast<BITMAPINFO*>(&hdr), 0, | 292 reinterpret_cast<BITMAPINFO*>(&hdr), 0, |
| 266 &data, | 293 &data, |
| 267 shared_section, 0); | 294 shared_section, 0); |
| 268 | 295 |
| 269 // If we run out of GDI objects or some other error occurs, we won't get a | 296 // If we run out of GDI objects or some other error occurs, we won't get a |
| 270 // bitmap here. This will cause us to crash later because the data pointer is | 297 // bitmap here. This will cause us to crash later because the data pointer is |
| 271 // NULL. To make sure that we can assign blame for those crashes to this code, | 298 // NULL. To make sure that we can assign blame for those crashes to this code, |
| 272 // we deliberately crash here, even in release mode. | 299 // we deliberately crash here, even in release mode. |
| 273 CHECK(hbitmap); | 300 if (!hbitmap) |
| 301 CrashForBitmapAllocationFailure(width, height); | |
| 274 | 302 |
| 275 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 303 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 276 bitmap.setPixels(data); | 304 bitmap.setPixels(data); |
| 277 bitmap.setIsOpaque(is_opaque); | 305 bitmap.setIsOpaque(is_opaque); |
| 278 | 306 |
| 279 if (is_opaque) { | 307 if (is_opaque) { |
| 280 #ifndef NDEBUG | 308 #ifndef NDEBUG |
| 281 // To aid in finding bugs, we set the background color to something | 309 // To aid in finding bugs, we set the background color to something |
| 282 // obviously wrong so it will be noticable when it is not cleared | 310 // obviously wrong so it will be noticable when it is not cleared |
| 283 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green | 311 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 for (int j = 0; j < width; j++) { | 477 for (int j = 0; j < width; j++) { |
| 450 adjustor(data + j); | 478 adjustor(data + j); |
| 451 } | 479 } |
| 452 data += row_words; | 480 data += row_words; |
| 453 } | 481 } |
| 454 } | 482 } |
| 455 } | 483 } |
| 456 | 484 |
| 457 } // namespace gfx | 485 } // namespace gfx |
| 458 | 486 |
| OLD | NEW |