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 <psapi.h> |
| 6 |
5 #include "skia/ext/platform_canvas_win.h" | 7 #include "skia/ext/platform_canvas_win.h" |
6 | 8 |
7 #include "base/logging.h" | |
8 #include "base/process_util.h" | |
9 #include "skia/ext/bitmap_platform_device_win.h" | 9 #include "skia/ext/bitmap_platform_device_win.h" |
10 | 10 |
11 namespace skia { | 11 namespace skia { |
12 | 12 |
| 13 // Crash on failure. |
| 14 #define CHECK(condition) if (!(condition)) __debugbreak(); |
| 15 |
13 // Crashes the process. This is called when a bitmap allocation fails, and this | 16 // Crashes the process. This is called when a bitmap allocation fails, and this |
14 // function tries to determine why it might have failed, and crash on different | 17 // function tries to determine why it might have failed, and crash on different |
15 // lines. This allows us to see in crash dumps the most likely reason for the | 18 // lines. This allows us to see in crash dumps the most likely reason for the |
16 // failure. It takes the size of the bitmap we were trying to allocate as its | 19 // failure. It takes the size of the bitmap we were trying to allocate as its |
17 // arguments so we can check that as well. | 20 // arguments so we can check that as well. |
18 void CrashForBitmapAllocationFailure(int w, int h) { | 21 void CrashForBitmapAllocationFailure(int w, int h) { |
19 // The maximum number of GDI objects per process is 10K. If we're very close | 22 // The maximum number of GDI objects per process is 10K. If we're very close |
20 // to that, it's probably the problem. | 23 // to that, it's probably the problem. |
21 const int kLotsOfGDIObjs = 9990; | 24 const int kLotsOfGDIObjs = 9990; |
22 CHECK(GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS) < kLotsOfGDIObjs); | 25 CHECK(GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS) < kLotsOfGDIObjs); |
23 | 26 |
24 // If the bitmap is ginormous, then we probably can't allocate it. | 27 // If the bitmap is ginormous, then we probably can't allocate it. |
25 // We use 64M pixels = 256MB @ 4 bytes per pixel. | 28 // We use 64M pixels = 256MB @ 4 bytes per pixel. |
26 const int64 kGinormousBitmapPxl = 64000000; | 29 const __int64 kGinormousBitmapPxl = 64000000; |
27 CHECK(static_cast<int64>(w) * static_cast<int64>(h) < kGinormousBitmapPxl); | 30 CHECK(static_cast<__int64>(w) * static_cast<__int64>(h) < |
| 31 kGinormousBitmapPxl); |
28 | 32 |
29 // If we're using a crazy amount of virtual address space, then maybe there | 33 // If we're using a crazy amount of virtual address space, then maybe there |
30 // isn't enough for our bitmap. | 34 // isn't enough for our bitmap. |
31 const int64 kLotsOfMem = 1500000000; // 1.5GB. | 35 const __int64 kLotsOfMem = 1500000000; // 1.5GB. |
32 scoped_ptr<base::ProcessMetrics> process_metrics( | 36 PROCESS_MEMORY_COUNTERS pmc; |
33 base::ProcessMetrics::CreateProcessMetrics(GetCurrentProcess())); | 37 if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) |
34 CHECK(process_metrics->GetPagefileUsage() < kLotsOfMem); | 38 CHECK(pmc.PagefileUsage < kLotsOfMem); |
35 | 39 |
36 // Everything else. | 40 // Everything else. |
37 CHECK(0); | 41 CHECK(0); |
38 } | 42 } |
39 | 43 |
40 | |
41 PlatformCanvasWin::PlatformCanvasWin() : SkCanvas() { | 44 PlatformCanvasWin::PlatformCanvasWin() : SkCanvas() { |
42 } | 45 } |
43 | 46 |
44 PlatformCanvasWin::PlatformCanvasWin(int width, int height, bool is_opaque) | 47 PlatformCanvasWin::PlatformCanvasWin(int width, int height, bool is_opaque) |
45 : SkCanvas() { | 48 : SkCanvas() { |
46 bool initialized = initialize(width, height, is_opaque, NULL); | 49 bool initialized = initialize(width, height, is_opaque, NULL); |
47 if (!initialized) | 50 if (!initialized) |
48 CrashForBitmapAllocationFailure(width, height); | 51 CrashForBitmapAllocationFailure(width, height); |
49 } | 52 } |
50 | 53 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 PlatformDeviceWin& PlatformCanvasWin::getTopPlatformDevice() const { | 90 PlatformDeviceWin& PlatformCanvasWin::getTopPlatformDevice() const { |
88 // All of our devices should be our special PlatformDevice. | 91 // All of our devices should be our special PlatformDevice. |
89 SkCanvas::LayerIter iter(const_cast<PlatformCanvasWin*>(this), false); | 92 SkCanvas::LayerIter iter(const_cast<PlatformCanvasWin*>(this), false); |
90 return *static_cast<PlatformDeviceWin*>(iter.device()); | 93 return *static_cast<PlatformDeviceWin*>(iter.device()); |
91 } | 94 } |
92 | 95 |
93 SkDevice* PlatformCanvasWin::createDevice(SkBitmap::Config config, | 96 SkDevice* PlatformCanvasWin::createDevice(SkBitmap::Config config, |
94 int width, | 97 int width, |
95 int height, | 98 int height, |
96 bool is_opaque, bool isForLayer) { | 99 bool is_opaque, bool isForLayer) { |
97 DCHECK(config == SkBitmap::kARGB_8888_Config); | 100 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
98 return createPlatformDevice(width, height, is_opaque, NULL); | 101 return createPlatformDevice(width, height, is_opaque, NULL); |
99 } | 102 } |
100 | 103 |
101 SkDevice* PlatformCanvasWin::createPlatformDevice(int width, | 104 SkDevice* PlatformCanvasWin::createPlatformDevice(int width, |
102 int height, | 105 int height, |
103 bool is_opaque, | 106 bool is_opaque, |
104 HANDLE shared_section) { | 107 HANDLE shared_section) { |
105 HDC screen_dc = GetDC(NULL); | 108 HDC screen_dc = GetDC(NULL); |
106 SkDevice* device = BitmapPlatformDeviceWin::create(screen_dc, width, height, | 109 SkDevice* device = BitmapPlatformDeviceWin::create(screen_dc, width, height, |
107 is_opaque, shared_section); | 110 is_opaque, shared_section); |
108 ReleaseDC(NULL, screen_dc); | 111 ReleaseDC(NULL, screen_dc); |
109 return device; | 112 return device; |
110 } | 113 } |
111 | 114 |
112 SkDevice* PlatformCanvasWin::setBitmapDevice(const SkBitmap&) { | 115 SkDevice* PlatformCanvasWin::setBitmapDevice(const SkBitmap&) { |
113 NOTREACHED(); | 116 SkASSERT(false); // Should not be called. |
114 return NULL; | 117 return NULL; |
115 } | 118 } |
116 | 119 |
117 } // namespace skia | 120 } // namespace skia |
OLD | NEW |