| 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/platform_canvas_win.h" | 5 #include "PlatformCanvasWin.h" |
| 6 | 6 |
| 7 #include "base/gfx/bitmap_platform_device_win.h" | 7 #include "BitmapPlatformDeviceWin.h" |
| 8 |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| 10 | 11 |
| 11 #ifdef ARCH_CPU_64_BITS | |
| 12 #error This code does not work on x64. Please make sure all the base unit tests\ | |
| 13 pass before doing any real work. | |
| 14 #endif | |
| 15 | |
| 16 namespace gfx { | 12 namespace gfx { |
| 17 | 13 |
| 18 // Crashes the process. This is called when a bitmap allocation fails, and this | 14 // Crashes the process. This is called when a bitmap allocation fails, and this |
| 19 // function tries to determine why it might have failed, and crash on different | 15 // function tries to determine why it might have failed, and crash on different |
| 20 // lines. This allows us to see in crash dumps the most likely reason for the | 16 // lines. This allows us to see in crash dumps the most likely reason for the |
| 21 // failure. It takes the size of the bitmap we were trying to allocate as its | 17 // failure. It takes the size of the bitmap we were trying to allocate as its |
| 22 // arguments so we can check that as well. | 18 // arguments so we can check that as well. |
| 23 void CrashForBitmapAllocationFailure(int w, int h) { | 19 void CrashForBitmapAllocationFailure(int w, int h) { |
| 24 // The maximum number of GDI objects per process is 10K. If we're very close | 20 // The maximum number of GDI objects per process is 10K. If we're very close |
| 25 // to that, it's probably the problem. | 21 // to that, it's probably the problem. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 42 CHECK(0); | 38 CHECK(0); |
| 43 } | 39 } |
| 44 | 40 |
| 45 | 41 |
| 46 PlatformCanvasWin::PlatformCanvasWin() : SkCanvas() { | 42 PlatformCanvasWin::PlatformCanvasWin() : SkCanvas() { |
| 47 } | 43 } |
| 48 | 44 |
| 49 PlatformCanvasWin::PlatformCanvasWin(int width, int height, bool is_opaque) | 45 PlatformCanvasWin::PlatformCanvasWin(int width, int height, bool is_opaque) |
| 50 : SkCanvas() { | 46 : SkCanvas() { |
| 51 bool initialized = initialize(width, height, is_opaque, NULL); | 47 bool initialized = initialize(width, height, is_opaque, NULL); |
| 52 if (!initialized) | 48 if (!initialized) |
| 53 CrashForBitmapAllocationFailure(width, height); | 49 CrashForBitmapAllocationFailure(width, height); |
| 54 } | 50 } |
| 55 | 51 |
| 56 PlatformCanvasWin::PlatformCanvasWin(int width, | 52 PlatformCanvasWin::PlatformCanvasWin(int width, |
| 57 int height, | 53 int height, |
| 58 bool is_opaque, | 54 bool is_opaque, |
| 59 HANDLE shared_section) | 55 HANDLE shared_section) |
| 60 : SkCanvas() { | 56 : SkCanvas() { |
| 61 bool initialized = initialize(width, height, is_opaque, shared_section); | 57 bool initialized = initialize(width, height, is_opaque, shared_section); |
| 62 if (!initialized) | 58 if (!initialized) |
| 63 CrashForBitmapAllocationFailure(width, height); | 59 CrashForBitmapAllocationFailure(width, height); |
| 64 } | 60 } |
| 65 | 61 |
| 66 PlatformCanvasWin::~PlatformCanvasWin() { | 62 PlatformCanvasWin::~PlatformCanvasWin() { |
| 67 } | 63 } |
| 68 | 64 |
| 69 bool PlatformCanvasWin::initialize(int width, | 65 bool PlatformCanvasWin::initialize(int width, |
| 70 int height, | 66 int height, |
| 71 bool is_opaque, | 67 bool is_opaque, |
| 72 HANDLE shared_section) { | 68 HANDLE shared_section) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 89 // flushing will be done in onAccessBitmap | 85 // flushing will be done in onAccessBitmap |
| 90 } | 86 } |
| 91 | 87 |
| 92 PlatformDeviceWin& PlatformCanvasWin::getTopPlatformDevice() const { | 88 PlatformDeviceWin& PlatformCanvasWin::getTopPlatformDevice() const { |
| 93 // All of our devices should be our special PlatformDevice. | 89 // All of our devices should be our special PlatformDevice. |
| 94 SkCanvas::LayerIter iter(const_cast<PlatformCanvasWin*>(this), false); | 90 SkCanvas::LayerIter iter(const_cast<PlatformCanvasWin*>(this), false); |
| 95 return *static_cast<PlatformDeviceWin*>(iter.device()); | 91 return *static_cast<PlatformDeviceWin*>(iter.device()); |
| 96 } | 92 } |
| 97 | 93 |
| 98 SkDevice* PlatformCanvasWin::createDevice(SkBitmap::Config config, | 94 SkDevice* PlatformCanvasWin::createDevice(SkBitmap::Config config, |
| 99 int width, | 95 int width, |
| 100 int height, | 96 int height, |
| 101 bool is_opaque, bool isForLayer) { | 97 bool is_opaque, bool isForLayer) { |
| 102 DCHECK(config == SkBitmap::kARGB_8888_Config); | 98 DCHECK(config == SkBitmap::kARGB_8888_Config); |
| 103 return createPlatformDevice(width, height, is_opaque, NULL); | 99 return createPlatformDevice(width, height, is_opaque, NULL); |
| 104 } | 100 } |
| 105 | 101 |
| 106 SkDevice* PlatformCanvasWin::createPlatformDevice(int width, | 102 SkDevice* PlatformCanvasWin::createPlatformDevice(int width, |
| 107 int height, | 103 int height, |
| 108 bool is_opaque, | 104 bool is_opaque, |
| 109 HANDLE shared_section) { | 105 HANDLE shared_section) { |
| 110 HDC screen_dc = GetDC(NULL); | 106 HDC screen_dc = GetDC(NULL); |
| 111 SkDevice* device = BitmapPlatformDeviceWin::create(screen_dc, width, height, | 107 SkDevice* device = BitmapPlatformDeviceWin::create(screen_dc, width, height, |
| 112 is_opaque, shared_section); | 108 is_opaque, shared_section); |
| 113 ReleaseDC(NULL, screen_dc); | 109 ReleaseDC(NULL, screen_dc); |
| 114 return device; | 110 return device; |
| 115 } | 111 } |
| 116 | 112 |
| 117 SkDevice* PlatformCanvasWin::setBitmapDevice(const SkBitmap&) { | 113 SkDevice* PlatformCanvasWin::setBitmapDevice(const SkBitmap&) { |
| 118 NOTREACHED(); | 114 NOTREACHED(); |
| 119 return NULL; | 115 return NULL; |
| 120 } | 116 } |
| 121 | 117 |
| 122 } // namespace gfx | 118 } // namespace gfx |
| OLD | NEW |