Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(409)

Side by Side Diff: base/gfx/platform_canvas_win.cc

Issue 11244: Move PlatformCanvas and PlatformDevice from base/gfx to webkit/port. I left h... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/gfx/platform_canvas_win.h ('k') | base/gfx/platform_device.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/gfx/platform_canvas_win.h"
6
7 #include "base/gfx/bitmap_platform_device_win.h"
8 #include "base/logging.h"
9 #include "base/process_util.h"
10
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 {
17
18 // 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
20 // 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
22 // arguments so we can check that as well.
23 void CrashForBitmapAllocationFailure(int w, int h) {
24 // The maximum number of GDI objects per process is 10K. If we're very close
25 // to that, it's probably the problem.
26 const int kLotsOfGDIObjs = 9990;
27 CHECK(GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS) < kLotsOfGDIObjs);
28
29 // If the bitmap is ginormous, then we probably can't allocate it.
30 // We use 64M pixels = 256MB @ 4 bytes per pixel.
31 const int64 kGinormousBitmapPxl = 64000000;
32 CHECK(static_cast<int64>(w) * static_cast<int64>(h) < kGinormousBitmapPxl);
33
34 // If we're using a crazy amount of virtual address space, then maybe there
35 // isn't enough for our bitmap.
36 const int64 kLotsOfMem = 1500000000; // 1.5GB.
37 scoped_ptr<base::ProcessMetrics> process_metrics(
38 base::ProcessMetrics::CreateProcessMetrics(GetCurrentProcess()));
39 CHECK(process_metrics->GetPagefileUsage() < kLotsOfMem);
40
41 // Everything else.
42 CHECK(0);
43 }
44
45
46 PlatformCanvasWin::PlatformCanvasWin() : SkCanvas() {
47 }
48
49 PlatformCanvasWin::PlatformCanvasWin(int width, int height, bool is_opaque)
50 : SkCanvas() {
51 bool initialized = initialize(width, height, is_opaque, NULL);
52 if (!initialized)
53 CrashForBitmapAllocationFailure(width, height);
54 }
55
56 PlatformCanvasWin::PlatformCanvasWin(int width,
57 int height,
58 bool is_opaque,
59 HANDLE shared_section)
60 : SkCanvas() {
61 bool initialized = initialize(width, height, is_opaque, shared_section);
62 if (!initialized)
63 CrashForBitmapAllocationFailure(width, height);
64 }
65
66 PlatformCanvasWin::~PlatformCanvasWin() {
67 }
68
69 bool PlatformCanvasWin::initialize(int width,
70 int height,
71 bool is_opaque,
72 HANDLE shared_section) {
73 SkDevice* device =
74 createPlatformDevice(width, height, is_opaque, shared_section);
75 if (!device)
76 return false;
77
78 setDevice(device);
79 device->unref(); // was created with refcount 1, and setDevice also refs
80 return true;
81 }
82
83 HDC PlatformCanvasWin::beginPlatformPaint() {
84 return getTopPlatformDevice().getBitmapDC();
85 }
86
87 void PlatformCanvasWin::endPlatformPaint() {
88 // we don't clear the DC here since it will be likely to be used again
89 // flushing will be done in onAccessBitmap
90 }
91
92 PlatformDeviceWin& PlatformCanvasWin::getTopPlatformDevice() const {
93 // All of our devices should be our special PlatformDevice.
94 SkCanvas::LayerIter iter(const_cast<PlatformCanvasWin*>(this), false);
95 return *static_cast<PlatformDeviceWin*>(iter.device());
96 }
97
98 SkDevice* PlatformCanvasWin::createDevice(SkBitmap::Config config,
99 int width,
100 int height,
101 bool is_opaque, bool isForLayer) {
102 DCHECK(config == SkBitmap::kARGB_8888_Config);
103 return createPlatformDevice(width, height, is_opaque, NULL);
104 }
105
106 SkDevice* PlatformCanvasWin::createPlatformDevice(int width,
107 int height,
108 bool is_opaque,
109 HANDLE shared_section) {
110 HDC screen_dc = GetDC(NULL);
111 SkDevice* device = BitmapPlatformDeviceWin::create(screen_dc, width, height,
112 is_opaque, shared_section);
113 ReleaseDC(NULL, screen_dc);
114 return device;
115 }
116
117 SkDevice* PlatformCanvasWin::setBitmapDevice(const SkBitmap&) {
118 NOTREACHED();
119 return NULL;
120 }
121
122 } // namespace gfx
OLDNEW
« no previous file with comments | « base/gfx/platform_canvas_win.h ('k') | base/gfx/platform_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698