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

Side by Side Diff: webkit/port/platform/graphics/skia/public/PlatformCanvasWin.cpp

Issue 11568: Move skia extensions from the port to skia/ext. (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
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 "PlatformCanvasWin.h"
6
7 #include "BitmapPlatformDeviceWin.h"
8
9 #include "base/logging.h"
10 #include "base/process_util.h"
11
12 namespace gfx {
13
14 // Crashes the process. This is called when a bitmap allocation fails, and this
15 // function tries to determine why it might have failed, and crash on different
16 // lines. This allows us to see in crash dumps the most likely reason for the
17 // failure. It takes the size of the bitmap we were trying to allocate as its
18 // arguments so we can check that as well.
19 void CrashForBitmapAllocationFailure(int w, int h) {
20 // The maximum number of GDI objects per process is 10K. If we're very close
21 // to that, it's probably the problem.
22 const int kLotsOfGDIObjs = 9990;
23 CHECK(GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS) < kLotsOfGDIObjs);
24
25 // If the bitmap is ginormous, then we probably can't allocate it.
26 // We use 64M pixels = 256MB @ 4 bytes per pixel.
27 const int64 kGinormousBitmapPxl = 64000000;
28 CHECK(static_cast<int64>(w) * static_cast<int64>(h) < kGinormousBitmapPxl);
29
30 // If we're using a crazy amount of virtual address space, then maybe there
31 // isn't enough for our bitmap.
32 const int64 kLotsOfMem = 1500000000; // 1.5GB.
33 scoped_ptr<base::ProcessMetrics> process_metrics(
34 base::ProcessMetrics::CreateProcessMetrics(GetCurrentProcess()));
35 CHECK(process_metrics->GetPagefileUsage() < kLotsOfMem);
36
37 // Everything else.
38 CHECK(0);
39 }
40
41
42 PlatformCanvasWin::PlatformCanvasWin() : SkCanvas() {
43 }
44
45 PlatformCanvasWin::PlatformCanvasWin(int width, int height, bool is_opaque)
46 : SkCanvas() {
47 bool initialized = initialize(width, height, is_opaque, NULL);
48 if (!initialized)
49 CrashForBitmapAllocationFailure(width, height);
50 }
51
52 PlatformCanvasWin::PlatformCanvasWin(int width,
53 int height,
54 bool is_opaque,
55 HANDLE shared_section)
56 : SkCanvas() {
57 bool initialized = initialize(width, height, is_opaque, shared_section);
58 if (!initialized)
59 CrashForBitmapAllocationFailure(width, height);
60 }
61
62 PlatformCanvasWin::~PlatformCanvasWin() {
63 }
64
65 bool PlatformCanvasWin::initialize(int width,
66 int height,
67 bool is_opaque,
68 HANDLE shared_section) {
69 SkDevice* device =
70 createPlatformDevice(width, height, is_opaque, shared_section);
71 if (!device)
72 return false;
73
74 setDevice(device);
75 device->unref(); // was created with refcount 1, and setDevice also refs
76 return true;
77 }
78
79 HDC PlatformCanvasWin::beginPlatformPaint() {
80 return getTopPlatformDevice().getBitmapDC();
81 }
82
83 void PlatformCanvasWin::endPlatformPaint() {
84 // we don't clear the DC here since it will be likely to be used again
85 // flushing will be done in onAccessBitmap
86 }
87
88 PlatformDeviceWin& PlatformCanvasWin::getTopPlatformDevice() const {
89 // All of our devices should be our special PlatformDevice.
90 SkCanvas::LayerIter iter(const_cast<PlatformCanvasWin*>(this), false);
91 return *static_cast<PlatformDeviceWin*>(iter.device());
92 }
93
94 SkDevice* PlatformCanvasWin::createDevice(SkBitmap::Config config,
95 int width,
96 int height,
97 bool is_opaque, bool isForLayer) {
98 DCHECK(config == SkBitmap::kARGB_8888_Config);
99 return createPlatformDevice(width, height, is_opaque, NULL);
100 }
101
102 SkDevice* PlatformCanvasWin::createPlatformDevice(int width,
103 int height,
104 bool is_opaque,
105 HANDLE shared_section) {
106 HDC screen_dc = GetDC(NULL);
107 SkDevice* device = BitmapPlatformDeviceWin::create(screen_dc, width, height,
108 is_opaque, shared_section);
109 ReleaseDC(NULL, screen_dc);
110 return device;
111 }
112
113 SkDevice* PlatformCanvasWin::setBitmapDevice(const SkBitmap&) {
114 NOTREACHED();
115 return NULL;
116 }
117
118 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698