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) < kGinormousBitmapPxl); |
28 | 31 |
29 // If we're using a crazy amount of virtual address space, then maybe there | 32 // If we're using a crazy amount of virtual address space, then maybe there |
30 // isn't enough for our bitmap. | 33 // isn't enough for our bitmap. |
31 const int64 kLotsOfMem = 1500000000; // 1.5GB. | 34 const __int64 kLotsOfMem = 1500000000; // 1.5GB. |
32 scoped_ptr<base::ProcessMetrics> process_metrics( | 35 PROCESS_MEMORY_COUNTERS pmc; |
33 base::ProcessMetrics::CreateProcessMetrics(GetCurrentProcess())); | 36 if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) |
34 CHECK(process_metrics->GetPagefileUsage() < kLotsOfMem); | 37 CHECK(pmc.PagefileUsage < kLotsOfMem); |
35 | 38 |
36 // Everything else. | 39 // Everything else. |
37 CHECK(0); | 40 CHECK(0); |
38 } | 41 } |
39 | 42 |
40 | |
41 PlatformCanvasWin::PlatformCanvasWin() : SkCanvas() { | 43 PlatformCanvasWin::PlatformCanvasWin() : SkCanvas() { |
42 } | 44 } |
43 | 45 |
44 PlatformCanvasWin::PlatformCanvasWin(int width, int height, bool is_opaque) | 46 PlatformCanvasWin::PlatformCanvasWin(int width, int height, bool is_opaque) |
45 : SkCanvas() { | 47 : SkCanvas() { |
46 bool initialized = initialize(width, height, is_opaque, NULL); | 48 bool initialized = initialize(width, height, is_opaque, NULL); |
47 if (!initialized) | 49 if (!initialized) |
48 CrashForBitmapAllocationFailure(width, height); | 50 CrashForBitmapAllocationFailure(width, height); |
49 } | 51 } |
50 | 52 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 PlatformDeviceWin& PlatformCanvasWin::getTopPlatformDevice() const { | 89 PlatformDeviceWin& PlatformCanvasWin::getTopPlatformDevice() const { |
88 // All of our devices should be our special PlatformDevice. | 90 // All of our devices should be our special PlatformDevice. |
89 SkCanvas::LayerIter iter(const_cast<PlatformCanvasWin*>(this), false); | 91 SkCanvas::LayerIter iter(const_cast<PlatformCanvasWin*>(this), false); |
90 return *static_cast<PlatformDeviceWin*>(iter.device()); | 92 return *static_cast<PlatformDeviceWin*>(iter.device()); |
91 } | 93 } |
92 | 94 |
93 SkDevice* PlatformCanvasWin::createDevice(SkBitmap::Config config, | 95 SkDevice* PlatformCanvasWin::createDevice(SkBitmap::Config config, |
94 int width, | 96 int width, |
95 int height, | 97 int height, |
96 bool is_opaque, bool isForLayer) { | 98 bool is_opaque, bool isForLayer) { |
97 DCHECK(config == SkBitmap::kARGB_8888_Config); | 99 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
98 return createPlatformDevice(width, height, is_opaque, NULL); | 100 return createPlatformDevice(width, height, is_opaque, NULL); |
99 } | 101 } |
100 | 102 |
101 SkDevice* PlatformCanvasWin::createPlatformDevice(int width, | 103 SkDevice* PlatformCanvasWin::createPlatformDevice(int width, |
102 int height, | 104 int height, |
103 bool is_opaque, | 105 bool is_opaque, |
104 HANDLE shared_section) { | 106 HANDLE shared_section) { |
105 HDC screen_dc = GetDC(NULL); | 107 HDC screen_dc = GetDC(NULL); |
106 SkDevice* device = BitmapPlatformDeviceWin::create(screen_dc, width, height, | 108 SkDevice* device = BitmapPlatformDeviceWin::create(screen_dc, width, height, |
107 is_opaque, shared_section); | 109 is_opaque, shared_section); |
108 ReleaseDC(NULL, screen_dc); | 110 ReleaseDC(NULL, screen_dc); |
109 return device; | 111 return device; |
110 } | 112 } |
111 | 113 |
112 SkDevice* PlatformCanvasWin::setBitmapDevice(const SkBitmap&) { | 114 SkDevice* PlatformCanvasWin::setBitmapDevice(const SkBitmap&) { |
113 NOTREACHED(); | 115 SkASSERT(false); // Should not be called. |
114 return NULL; | 116 return NULL; |
115 } | 117 } |
116 | 118 |
117 } // namespace skia | 119 } // namespace skia |
OLD | NEW |