OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bitmap_platform_device_win.h" | 8 #include "skia/ext/bitmap_platform_device_win.h" |
9 | 9 |
10 #include "skia/ext/bitmap_platform_device_data.h" | 10 #include "skia/ext/bitmap_platform_device_data.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 80 |
81 // Transform. | 81 // Transform. |
82 LoadTransformToDC(hdc_, transform_); | 82 LoadTransformToDC(hdc_, transform_); |
83 LoadClippingRegionToDC(hdc_, clip_region_, transform_); | 83 LoadClippingRegionToDC(hdc_, clip_region_, transform_); |
84 } | 84 } |
85 | 85 |
86 // We use this static factory function instead of the regular constructor so | 86 // We use this static factory function instead of the regular constructor so |
87 // that we can create the pixel data before calling the constructor. This is | 87 // that we can create the pixel data before calling the constructor. This is |
88 // required so that we can call the base class' constructor with the pixel | 88 // required so that we can call the base class' constructor with the pixel |
89 // data. | 89 // data. |
90 BitmapPlatformDevice* BitmapPlatformDevice::create( | 90 BitmapPlatformDevice* BitmapPlatformDevice::Create( |
91 HDC screen_dc, | 91 HDC screen_dc, |
92 int width, | 92 int width, |
93 int height, | 93 int height, |
94 bool is_opaque, | 94 bool is_opaque, |
95 HANDLE shared_section) { | 95 HANDLE shared_section) { |
96 SkBitmap bitmap; | 96 SkBitmap bitmap; |
97 | 97 |
98 // CreateDIBSection appears to get unhappy if we create an empty bitmap, so | 98 // CreateDIBSection appears to get unhappy if we create an empty bitmap, so |
99 // just create a minimal bitmap | 99 // just create a minimal bitmap |
100 if ((width == 0) || (height == 0)) { | 100 if ((width == 0) || (height == 0)) { |
(...skipping 20 matching lines...) Expand all Loading... |
121 &data, | 121 &data, |
122 shared_section, 0); | 122 shared_section, 0); |
123 if (!hbitmap) { | 123 if (!hbitmap) { |
124 return NULL; | 124 return NULL; |
125 } | 125 } |
126 | 126 |
127 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 127 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
128 bitmap.setPixels(data); | 128 bitmap.setPixels(data); |
129 bitmap.setIsOpaque(is_opaque); | 129 bitmap.setIsOpaque(is_opaque); |
130 | 130 |
| 131 #ifndef NDEBUG |
131 // If we were given data, then don't clobber it! | 132 // If we were given data, then don't clobber it! |
132 if (!shared_section) { | 133 if (!shared_section && is_opaque) |
133 if (is_opaque) { | 134 // To aid in finding bugs, we set the background color to something |
134 #ifndef NDEBUG | 135 // obviously wrong so it will be noticable when it is not cleared |
135 // To aid in finding bugs, we set the background color to something | 136 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green |
136 // obviously wrong so it will be noticable when it is not cleared | |
137 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green | |
138 #endif | 137 #endif |
139 } else { | |
140 bitmap.eraseARGB(0, 0, 0, 0); | |
141 } | |
142 } | |
143 | 138 |
144 // The device object will take ownership of the HBITMAP. The initial refcount | 139 // The device object will take ownership of the HBITMAP. The initial refcount |
145 // of the data object will be 1, which is what the constructor expects. | 140 // of the data object will be 1, which is what the constructor expects. |
146 return new BitmapPlatformDevice(new BitmapPlatformDeviceData(hbitmap), | 141 return new BitmapPlatformDevice(new BitmapPlatformDeviceData(hbitmap), |
147 bitmap); | 142 bitmap); |
148 } | 143 } |
149 | 144 |
150 // static | 145 // static |
151 BitmapPlatformDevice* BitmapPlatformDevice::create(int width, | 146 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, |
152 int height, | 147 int height, |
153 bool is_opaque, | 148 bool is_opaque, |
154 HANDLE shared_section) { | 149 HANDLE shared_section) { |
155 HDC screen_dc = GetDC(NULL); | 150 HDC screen_dc = GetDC(NULL); |
156 BitmapPlatformDevice* device = BitmapPlatformDevice::create( | 151 BitmapPlatformDevice* device = BitmapPlatformDevice::Create( |
157 screen_dc, width, height, is_opaque, shared_section); | 152 screen_dc, width, height, is_opaque, shared_section); |
158 ReleaseDC(NULL, screen_dc); | 153 ReleaseDC(NULL, screen_dc); |
159 return device; | 154 return device; |
160 } | 155 } |
161 | 156 |
| 157 // static |
| 158 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, |
| 159 bool is_opaque) { |
| 160 return Create(width, height, is_opaque, NULL); |
| 161 } |
| 162 |
| 163 // static |
| 164 BitmapPlatformDevice* BitmapPlatformDevice::CreateAndClear(int width, |
| 165 int height, |
| 166 bool is_opaque) { |
| 167 BitmapPlatformDevice* device = BitmapPlatformDevice::Create(width, height, |
| 168 is_opaque); |
| 169 if (!is_opaque) |
| 170 device->accessBitmap(true).eraseARGB(0, 0, 0, 0); |
| 171 return device; |
| 172 } |
| 173 |
162 // The device will own the HBITMAP, which corresponds to also owning the pixel | 174 // The device will own the HBITMAP, which corresponds to also owning the pixel |
163 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. | 175 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. |
164 BitmapPlatformDevice::BitmapPlatformDevice( | 176 BitmapPlatformDevice::BitmapPlatformDevice( |
165 BitmapPlatformDeviceData* data, | 177 BitmapPlatformDeviceData* data, |
166 const SkBitmap& bitmap) | 178 const SkBitmap& bitmap) |
167 : SkDevice(bitmap), | 179 : SkDevice(bitmap), |
168 data_(data) { | 180 data_(data) { |
169 // The data object is already ref'ed for us by create(). | 181 // The data object is already ref'ed for us by create(). |
170 SkDEBUGCODE(begin_paint_count_ = 0); | 182 SkDEBUGCODE(begin_paint_count_ = 0); |
171 SetPlatformDevice(this, this); | 183 SetPlatformDevice(this, this); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 // operation has occurred on our DC. | 264 // operation has occurred on our DC. |
253 if (data_->IsBitmapDCCreated()) | 265 if (data_->IsBitmapDCCreated()) |
254 GdiFlush(); | 266 GdiFlush(); |
255 return *bitmap; | 267 return *bitmap; |
256 } | 268 } |
257 | 269 |
258 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( | 270 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( |
259 SkBitmap::Config config, int width, int height, bool isOpaque, | 271 SkBitmap::Config config, int width, int height, bool isOpaque, |
260 Usage /*usage*/) { | 272 Usage /*usage*/) { |
261 SkASSERT(config == SkBitmap::kARGB_8888_Config); | 273 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
262 return BitmapPlatformDevice::create(width, height, isOpaque, NULL); | 274 SkDevice* bitmap_device = BitmapPlatformDevice::CreateAndClear(width, height, |
| 275 isOpaque); |
| 276 return bitmap_device; |
263 } | 277 } |
264 | 278 |
265 } // namespace skia | 279 } // namespace skia |
OLD | NEW |