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 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/debug/gdi_debug_util_win.h" | 9 #include "base/debug/gdi_debug_util_win.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 BitmapPlatformDevice::BitmapPlatformDevice( | 193 BitmapPlatformDevice::BitmapPlatformDevice( |
194 HBITMAP hbitmap, | 194 HBITMAP hbitmap, |
195 const SkBitmap& bitmap) | 195 const SkBitmap& bitmap) |
196 : SkBitmapDevice(bitmap), | 196 : SkBitmapDevice(bitmap), |
197 hbitmap_(hbitmap), | 197 hbitmap_(hbitmap), |
198 old_hbitmap_(NULL), | 198 old_hbitmap_(NULL), |
199 hdc_(NULL), | 199 hdc_(NULL), |
200 config_dirty_(true), // Want to load the config next time. | 200 config_dirty_(true), // Want to load the config next time. |
201 transform_(SkMatrix::I()) { | 201 transform_(SkMatrix::I()) { |
202 // The data object is already ref'ed for us by create(). | 202 // The data object is already ref'ed for us by create(). |
203 SkDEBUGCODE(begin_paint_count_ = 0); | |
204 if (hbitmap) { | 203 if (hbitmap) { |
205 SetPlatformDevice(this, this); | 204 SetPlatformDevice(this, this); |
206 // Initialize the clip region to the entire bitmap. | 205 // Initialize the clip region to the entire bitmap. |
207 BITMAP bitmap_data; | 206 BITMAP bitmap_data; |
208 if (GetObject(hbitmap_, sizeof(BITMAP), &bitmap_data)) { | 207 if (GetObject(hbitmap_, sizeof(BITMAP), &bitmap_data)) { |
209 SkIRect rect; | 208 SkIRect rect; |
210 rect.set(0, 0, bitmap_data.bmWidth, bitmap_data.bmHeight); | 209 rect.set(0, 0, bitmap_data.bmWidth, bitmap_data.bmHeight); |
211 clip_region_ = SkRegion(rect); | 210 clip_region_ = SkRegion(rect); |
212 } | 211 } |
213 } | 212 } |
214 } | 213 } |
215 | 214 |
216 BitmapPlatformDevice::~BitmapPlatformDevice() { | 215 BitmapPlatformDevice::~BitmapPlatformDevice() { |
217 SkASSERT(begin_paint_count_ == 0); | |
218 if (hdc_) | 216 if (hdc_) |
219 ReleaseBitmapDC(); | 217 ReleaseBitmapDC(); |
220 } | 218 } |
221 | 219 |
222 HDC BitmapPlatformDevice::BeginPlatformPaint() { | 220 HDC BitmapPlatformDevice::BeginPlatformPaint() { |
223 SkDEBUGCODE(begin_paint_count_++); | |
224 return GetBitmapDC(); | 221 return GetBitmapDC(); |
225 } | 222 } |
226 | 223 |
227 void BitmapPlatformDevice::EndPlatformPaint() { | |
228 SkASSERT(begin_paint_count_--); | |
229 PlatformDevice::EndPlatformPaint(); | |
230 } | |
231 | |
232 void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform, | 224 void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform, |
233 const SkRegion& region, | 225 const SkRegion& region, |
234 const SkClipStack&) { | 226 const SkClipStack&) { |
235 SetMatrixClip(transform, region); | 227 SetMatrixClip(transform, region); |
236 } | 228 } |
237 | 229 |
238 void BitmapPlatformDevice::DrawToHDC(HDC dc, int x, int y, | 230 void BitmapPlatformDevice::DrawToHDC(HDC dc, int x, int y, |
239 const RECT* src_rect) { | 231 const RECT* src_rect) { |
240 bool created_dc = !IsBitmapDCCreated(); | 232 bool created_dc = !IsBitmapDCCreated(); |
241 HDC source_dc = BeginPlatformPaint(); | 233 HDC source_dc = BeginPlatformPaint(); |
f(malita)
2016/03/29 17:31:07
Nit: use ScopedPlatformPaint here also?
tomhudson
2016/03/29 17:47:31
No; we're calling this->BeginPlatformPaint(), not
| |
242 | 234 |
243 RECT temp_rect; | 235 RECT temp_rect; |
244 if (!src_rect) { | 236 if (!src_rect) { |
245 temp_rect.left = 0; | 237 temp_rect.left = 0; |
246 temp_rect.right = width(); | 238 temp_rect.right = width(); |
247 temp_rect.top = 0; | 239 temp_rect.top = 0; |
248 temp_rect.bottom = height(); | 240 temp_rect.bottom = height(); |
249 src_rect = &temp_rect; | 241 src_rect = &temp_rect; |
250 } | 242 } |
251 | 243 |
(...skipping 26 matching lines...) Expand all Loading... | |
278 copy_height, | 270 copy_height, |
279 source_dc, | 271 source_dc, |
280 src_rect->left, | 272 src_rect->left, |
281 src_rect->top, | 273 src_rect->top, |
282 copy_width, | 274 copy_width, |
283 copy_height, | 275 copy_height, |
284 blend_function); | 276 blend_function); |
285 } | 277 } |
286 LoadTransformToDC(source_dc, transform_); | 278 LoadTransformToDC(source_dc, transform_); |
287 | 279 |
288 EndPlatformPaint(); | |
289 if (created_dc) | 280 if (created_dc) |
290 ReleaseBitmapDC(); | 281 ReleaseBitmapDC(); |
291 } | 282 } |
292 | 283 |
293 const SkBitmap& BitmapPlatformDevice::onAccessBitmap() { | 284 const SkBitmap& BitmapPlatformDevice::onAccessBitmap() { |
294 // FIXME(brettw) OPTIMIZATION: We should only flush if we know a GDI | 285 // FIXME(brettw) OPTIMIZATION: We should only flush if we know a GDI |
295 // operation has occurred on our DC. | 286 // operation has occurred on our DC. |
296 if (IsBitmapDCCreated()) | 287 if (IsBitmapDCCreated()) |
297 GdiFlush(); | 288 GdiFlush(); |
298 return SkBitmapDevice::onAccessBitmap(); | 289 return SkBitmapDevice::onAccessBitmap(); |
(...skipping 13 matching lines...) Expand all Loading... | |
312 int height, | 303 int height, |
313 bool is_opaque, | 304 bool is_opaque, |
314 HANDLE shared_section, | 305 HANDLE shared_section, |
315 OnFailureType failureType) { | 306 OnFailureType failureType) { |
316 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef( | 307 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef( |
317 BitmapPlatformDevice::Create(width, height, is_opaque, shared_section)); | 308 BitmapPlatformDevice::Create(width, height, is_opaque, shared_section)); |
318 return CreateCanvas(dev, failureType); | 309 return CreateCanvas(dev, failureType); |
319 } | 310 } |
320 | 311 |
321 } // namespace skia | 312 } // namespace skia |
OLD | NEW |