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

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

Issue 12221116: Custom implementation of VectorPlatformDeviceEmf::drawBitmapRect, to shield it from changes in SkDe… (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 10 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/vector_platform_device_emf_win.h ('k') | no next file » | 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) 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 "skia/ext/vector_platform_device_emf_win.h" 5 #include "skia/ext/vector_platform_device_emf_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 254 }
255 default: 255 default:
256 SkASSERT(false); 256 SkASSERT(false);
257 break; 257 break;
258 } 258 }
259 } 259 }
260 EndPlatformPaint(); 260 EndPlatformPaint();
261 Cleanup(); 261 Cleanup();
262 } 262 }
263 263
264 void VectorPlatformDeviceEmf::drawBitmapRect(const SkDraw& draw,
265 const SkBitmap& bitmap,
266 const SkRect* src,
267 const SkRect& dst,
268 const SkPaint& paint) {
269 SkMatrix matrix;
270 SkRect bitmapBounds, tmpSrc, tmpDst;
271 SkBitmap tmpBitmap;
272
273 bitmapBounds.isetWH(bitmap.width(), bitmap.height());
274
275 // Compute matrix from the two rectangles
276 if (src) {
277 tmpSrc = *src;
278 } else {
279 tmpSrc = bitmapBounds;
280 }
281 matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit);
282
283 const SkBitmap* bitmapPtr = &bitmap;
284
285 // clip the tmpSrc to the bounds of the bitmap, and recompute dstRect if
286 // needed (if the src was clipped). No check needed if src==null.
287 if (src) {
288 if (!bitmapBounds.contains(*src)) {
289 if (!tmpSrc.intersect(bitmapBounds)) {
290 return; // nothing to draw
291 }
292 // recompute dst, based on the smaller tmpSrc
293 matrix.mapRect(&tmpDst, tmpSrc);
294 }
295
296 // since we may need to clamp to the borders of the src rect within
297 // the bitmap, we extract a subset.
298 // TODO: make sure this is handled in drawrect and remove it from here.
299 SkIRect srcIR;
300 tmpSrc.roundOut(&srcIR);
301 if (!bitmap.extractSubset(&tmpBitmap, srcIR)) {
302 return;
303 }
304 bitmapPtr = &tmpBitmap;
305
306 // Since we did an extract, we need to adjust the matrix accordingly
307 SkScalar dx = 0, dy = 0;
308 if (srcIR.fLeft > 0) {
309 dx = SkIntToScalar(srcIR.fLeft);
310 }
311 if (srcIR.fTop > 0) {
312 dy = SkIntToScalar(srcIR.fTop);
313 }
314 if (dx || dy) {
315 matrix.preTranslate(dx, dy);
316 }
317 }
318 this->drawBitmap(draw, *bitmapPtr, NULL, matrix, paint);
319 }
320
264 void VectorPlatformDeviceEmf::drawBitmap(const SkDraw& draw, 321 void VectorPlatformDeviceEmf::drawBitmap(const SkDraw& draw,
265 const SkBitmap& bitmap, 322 const SkBitmap& bitmap,
266 const SkIRect* srcRectOrNull, 323 const SkIRect* srcRectOrNull,
267 const SkMatrix& matrix, 324 const SkMatrix& matrix,
268 const SkPaint& paint) { 325 const SkPaint& paint) {
269 // Load the temporary matrix. This is what will translate, rotate and resize 326 // Load the temporary matrix. This is what will translate, rotate and resize
270 // the bitmap. 327 // the bitmap.
271 SkMatrix actual_transform(transform_); 328 SkMatrix actual_transform(transform_);
272 actual_transform.preConcat(matrix); 329 actual_transform.preConcat(matrix);
273 LoadTransformToDC(hdc_, actual_transform); 330 LoadTransformToDC(hdc_, actual_transform);
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 pixels, 978 pixels,
922 reinterpret_cast<const BITMAPINFO*>(&hdr), 979 reinterpret_cast<const BITMAPINFO*>(&hdr),
923 DIB_RGB_COLORS, 980 DIB_RGB_COLORS,
924 SRCCOPY); 981 SRCCOPY);
925 } 982 }
926 EndPlatformPaint(); 983 EndPlatformPaint();
927 Cleanup(); 984 Cleanup();
928 } 985 }
929 986
930 } // namespace skia 987 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/vector_platform_device_emf_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698