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

Side by Side Diff: skia/ext/platform_canvas_win.cc

Issue 125109: Refactor the PlatformContext layer to have only one class. (Closed)
Patch Set: Created 11 years, 6 months 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
« no previous file with comments | « skia/ext/platform_canvas_win.h ('k') | skia/ext/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
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 <windows.h> 5 #include <windows.h>
6 #include <psapi.h> 6 #include <psapi.h>
7 7
8 #include "skia/ext/platform_canvas_win.h"
9
10 #include "skia/ext/bitmap_platform_device_win.h" 8 #include "skia/ext/bitmap_platform_device_win.h"
9 #include "skia/ext/platform_canvas.h"
11 10
12 namespace skia { 11 namespace skia {
13 12
14 // Crash on failure. 13 // Crash on failure.
15 #define CHECK(condition) if (!(condition)) __debugbreak(); 14 #define CHECK(condition) if (!(condition)) __debugbreak();
16 15
17 // 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
18 // 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
19 // 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
20 // 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
(...skipping 26 matching lines...) Expand all
47 } 46 }
48 47
49 // Crashes the process. This is called when a bitmap allocation fails but 48 // Crashes the process. This is called when a bitmap allocation fails but
50 // unlike its cousin CrashForBitmapAllocationFailure() it tries to detect if 49 // unlike its cousin CrashForBitmapAllocationFailure() it tries to detect if
51 // the issue was a non-valid shared bitmap handle. 50 // the issue was a non-valid shared bitmap handle.
52 __declspec(noinline) void CrashIfInvalidSection(HANDLE shared_section) { 51 __declspec(noinline) void CrashIfInvalidSection(HANDLE shared_section) {
53 DWORD handle_info = 0; 52 DWORD handle_info = 0;
54 CHECK(::GetHandleInformation(shared_section, &handle_info) == TRUE); 53 CHECK(::GetHandleInformation(shared_section, &handle_info) == TRUE);
55 } 54 }
56 55
57 PlatformCanvasWin::PlatformCanvasWin() : SkCanvas() { 56 PlatformCanvas::PlatformCanvas() : SkCanvas() {
58 } 57 }
59 58
60 PlatformCanvasWin::PlatformCanvasWin(int width, int height, bool is_opaque) 59 PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque)
61 : SkCanvas() { 60 : SkCanvas() {
62 bool initialized = initialize(width, height, is_opaque, NULL); 61 bool initialized = initialize(width, height, is_opaque, NULL);
63 if (!initialized) 62 if (!initialized)
64 CrashForBitmapAllocationFailure(width, height); 63 CrashForBitmapAllocationFailure(width, height);
65 } 64 }
66 65
67 PlatformCanvasWin::PlatformCanvasWin(int width, 66 PlatformCanvas::PlatformCanvas(int width,
68 int height, 67 int height,
69 bool is_opaque, 68 bool is_opaque,
70 HANDLE shared_section) 69 HANDLE shared_section)
71 : SkCanvas() { 70 : SkCanvas() {
72 bool initialized = initialize(width, height, is_opaque, shared_section); 71 bool initialized = initialize(width, height, is_opaque, shared_section);
73 if (!initialized) { 72 if (!initialized) {
74 CrashIfInvalidSection(shared_section); 73 CrashIfInvalidSection(shared_section);
75 CrashForBitmapAllocationFailure(width, height); 74 CrashForBitmapAllocationFailure(width, height);
76 } 75 }
77 } 76 }
78 77
79 PlatformCanvasWin::~PlatformCanvasWin() { 78 PlatformCanvas::~PlatformCanvas() {
80 } 79 }
81 80
82 bool PlatformCanvasWin::initialize(int width, 81 bool PlatformCanvas::initialize(int width,
83 int height, 82 int height,
84 bool is_opaque, 83 bool is_opaque,
85 HANDLE shared_section) { 84 HANDLE shared_section) {
86 SkDevice* device = 85 SkDevice* device = BitmapPlatformDevice::create(width, height,
87 createPlatformDevice(width, height, is_opaque, shared_section); 86 is_opaque, shared_section);
88 if (!device) 87 if (!device)
89 return false; 88 return false;
90 89
91 setDevice(device); 90 setDevice(device);
92 device->unref(); // was created with refcount 1, and setDevice also refs 91 device->unref(); // was created with refcount 1, and setDevice also refs
93 return true; 92 return true;
94 } 93 }
95 94
96 HDC PlatformCanvasWin::beginPlatformPaint() { 95 HDC PlatformCanvas::beginPlatformPaint() {
97 return getTopPlatformDevice().getBitmapDC(); 96 return getTopPlatformDevice().getBitmapDC();
98 } 97 }
99 98
100 void PlatformCanvasWin::endPlatformPaint() { 99 void PlatformCanvas::endPlatformPaint() {
101 // we don't clear the DC here since it will be likely to be used again 100 // we don't clear the DC here since it will be likely to be used again
102 // flushing will be done in onAccessBitmap 101 // flushing will be done in onAccessBitmap
103 } 102 }
104 103
105 PlatformDeviceWin& PlatformCanvasWin::getTopPlatformDevice() const { 104 SkDevice* PlatformCanvas::createDevice(SkBitmap::Config config,
106 // All of our devices should be our special PlatformDevice. 105 int width,
107 SkCanvas::LayerIter iter(const_cast<PlatformCanvasWin*>(this), false); 106 int height,
108 return *static_cast<PlatformDeviceWin*>(iter.device()); 107 bool is_opaque, bool isForLayer) {
109 }
110
111 SkDevice* PlatformCanvasWin::createDevice(SkBitmap::Config config,
112 int width,
113 int height,
114 bool is_opaque, bool isForLayer) {
115 SkASSERT(config == SkBitmap::kARGB_8888_Config); 108 SkASSERT(config == SkBitmap::kARGB_8888_Config);
116 return createPlatformDevice(width, height, is_opaque, NULL); 109 return BitmapPlatformDevice::create(width, height, is_opaque, NULL);
117 }
118
119 SkDevice* PlatformCanvasWin::createPlatformDevice(int width,
120 int height,
121 bool is_opaque,
122 HANDLE shared_section) {
123 HDC screen_dc = GetDC(NULL);
124 SkDevice* device = BitmapPlatformDeviceWin::create(screen_dc, width, height,
125 is_opaque, shared_section);
126 ReleaseDC(NULL, screen_dc);
127 return device;
128 }
129
130 SkDevice* PlatformCanvasWin::setBitmapDevice(const SkBitmap&) {
131 SkASSERT(false); // Should not be called.
132 return NULL;
133 }
134
135 // static
136 size_t PlatformCanvasWin::StrideForWidth(unsigned width) {
137 return 4 * width;
138 } 110 }
139 111
140 } // namespace skia 112 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/platform_canvas_win.h ('k') | skia/ext/platform_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698