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 #include "skia/ext/bitmap_platform_device_data.h" | 9 #include "skia/ext/bitmap_platform_device_data.h" |
10 #include "skia/ext/platform_canvas.h" | 10 #include "skia/ext/platform_canvas.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 #ifndef NDEBUG | 135 #ifndef NDEBUG |
136 // If we were given data, then don't clobber it! | 136 // If we were given data, then don't clobber it! |
137 if (!shared_section && is_opaque) | 137 if (!shared_section && is_opaque) |
138 // To aid in finding bugs, we set the background color to something | 138 // To aid in finding bugs, we set the background color to something |
139 // obviously wrong so it will be noticable when it is not cleared | 139 // obviously wrong so it will be noticable when it is not cleared |
140 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green | 140 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green |
141 #endif | 141 #endif |
142 | 142 |
143 // The device object will take ownership of the HBITMAP. The initial refcount | 143 // The device object will take ownership of the HBITMAP. The initial refcount |
144 // of the data object will be 1, which is what the constructor expects. | 144 // of the data object will be 1, which is what the constructor expects. |
145 return new BitmapPlatformDevice(new BitmapPlatformDeviceData(hbitmap), | 145 return new BitmapPlatformDevice( |
146 bitmap); | 146 skia::AdoptRef(new BitmapPlatformDeviceData(hbitmap)), bitmap); |
147 } | 147 } |
148 | 148 |
149 // static | 149 // static |
150 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, | 150 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, |
151 bool is_opaque) { | 151 bool is_opaque) { |
152 return Create(width, height, is_opaque, NULL); | 152 return Create(width, height, is_opaque, NULL); |
153 } | 153 } |
154 | 154 |
155 // static | 155 // static |
156 BitmapPlatformDevice* BitmapPlatformDevice::CreateAndClear(int width, | 156 BitmapPlatformDevice* BitmapPlatformDevice::CreateAndClear(int width, |
157 int height, | 157 int height, |
158 bool is_opaque) { | 158 bool is_opaque) { |
159 BitmapPlatformDevice* device = BitmapPlatformDevice::Create(width, height, | 159 BitmapPlatformDevice* device = BitmapPlatformDevice::Create(width, height, |
160 is_opaque); | 160 is_opaque); |
161 if (device && !is_opaque) | 161 if (device && !is_opaque) |
162 device->accessBitmap(true).eraseARGB(0, 0, 0, 0); | 162 device->accessBitmap(true).eraseARGB(0, 0, 0, 0); |
163 return device; | 163 return device; |
164 } | 164 } |
165 | 165 |
166 // The device will own the HBITMAP, which corresponds to also owning the pixel | 166 // The device will own the HBITMAP, which corresponds to also owning the pixel |
167 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. | 167 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. |
168 BitmapPlatformDevice::BitmapPlatformDevice( | 168 BitmapPlatformDevice::BitmapPlatformDevice( |
169 BitmapPlatformDeviceData* data, | 169 const skia::RefPtr<BitmapPlatformDeviceData>& data, |
170 const SkBitmap& bitmap) | 170 const SkBitmap& bitmap) |
171 : SkDevice(bitmap), | 171 : SkDevice(bitmap), |
172 data_(data) { | 172 data_(data) { |
173 // The data object is already ref'ed for us by create(). | 173 // The data object is already ref'ed for us by create(). |
174 SkDEBUGCODE(begin_paint_count_ = 0); | 174 SkDEBUGCODE(begin_paint_count_ = 0); |
175 SetPlatformDevice(this, this); | 175 SetPlatformDevice(this, this); |
176 } | 176 } |
177 | 177 |
178 BitmapPlatformDevice::~BitmapPlatformDevice() { | 178 BitmapPlatformDevice::~BitmapPlatformDevice() { |
179 SkASSERT(begin_paint_count_ == 0); | 179 SkASSERT(begin_paint_count_ == 0); |
180 data_->unref(); | |
181 } | 180 } |
182 | 181 |
183 HDC BitmapPlatformDevice::BeginPlatformPaint() { | 182 HDC BitmapPlatformDevice::BeginPlatformPaint() { |
184 SkDEBUGCODE(begin_paint_count_++); | 183 SkDEBUGCODE(begin_paint_count_++); |
185 return data_->GetBitmapDC(); | 184 return data_->GetBitmapDC(); |
186 } | 185 } |
187 | 186 |
188 void BitmapPlatformDevice::EndPlatformPaint() { | 187 void BitmapPlatformDevice::EndPlatformPaint() { |
189 SkASSERT(begin_paint_count_--); | 188 SkASSERT(begin_paint_count_--); |
190 PlatformDevice::EndPlatformPaint(); | 189 PlatformDevice::EndPlatformPaint(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 return BitmapPlatformDevice::CreateAndClear(width, height, isOpaque); | 264 return BitmapPlatformDevice::CreateAndClear(width, height, isOpaque); |
266 } | 265 } |
267 | 266 |
268 // PlatformCanvas impl | 267 // PlatformCanvas impl |
269 | 268 |
270 SkCanvas* CreatePlatformCanvas(int width, | 269 SkCanvas* CreatePlatformCanvas(int width, |
271 int height, | 270 int height, |
272 bool is_opaque, | 271 bool is_opaque, |
273 HANDLE shared_section, | 272 HANDLE shared_section, |
274 OnFailureType failureType) { | 273 OnFailureType failureType) { |
275 SkDevice* dev = BitmapPlatformDevice::Create(width, | 274 skia::RefPtr<SkDevice> dev = skia::AdoptRef( |
276 height, | 275 BitmapPlatformDevice::Create(width, height, is_opaque, shared_section)); |
277 is_opaque, | |
278 shared_section); | |
279 return CreateCanvas(dev, failureType); | 276 return CreateCanvas(dev, failureType); |
280 } | 277 } |
281 | 278 |
282 // Port of PlatformBitmap to win | 279 // Port of PlatformBitmap to win |
283 | 280 |
284 PlatformBitmap::~PlatformBitmap() { | 281 PlatformBitmap::~PlatformBitmap() { |
285 if (surface_) | 282 if (surface_) |
286 DeleteDC(surface_); | 283 DeleteDC(surface_); |
287 | 284 |
288 HBITMAP hbitmap = (HBITMAP)platform_extra_; | 285 HBITMAP hbitmap = (HBITMAP)platform_extra_; |
(...skipping 12 matching lines...) Expand all Loading... |
301 // When the memory DC is created, its display surface is exactly one | 298 // When the memory DC is created, its display surface is exactly one |
302 // monochrome pixel wide and one monochrome pixel high. Since we select our | 299 // monochrome pixel wide and one monochrome pixel high. Since we select our |
303 // own bitmap, we must delete the previous one. | 300 // own bitmap, we must delete the previous one. |
304 DeleteObject(old_bitmap); | 301 DeleteObject(old_bitmap); |
305 // remember the hbitmap, so we can free it in our destructor | 302 // remember the hbitmap, so we can free it in our destructor |
306 platform_extra_ = (intptr_t)hbitmap; | 303 platform_extra_ = (intptr_t)hbitmap; |
307 return true; | 304 return true; |
308 } | 305 } |
309 | 306 |
310 } // namespace skia | 307 } // namespace skia |
OLD | NEW |