summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoredisonn@google.com <edisonn@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-12 18:26:15 +0000
committeredisonn@google.com <edisonn@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-12 18:26:15 +0000
commit3849fb743df6e05f6fd08da8734d1cf2e2285bd4 (patch)
treec730a6b63ea121f13eae38297164cab19fdcba4b
parentf6f5229d7f4d04116f06823f5719b3c65f959617 (diff)
downloadchromium_src-3849fb743df6e05f6fd08da8734d1cf2e2285bd4.zip
chromium_src-3849fb743df6e05f6fd08da8734d1cf2e2285bd4.tar.gz
chromium_src-3849fb743df6e05f6fd08da8734d1cf2e2285bd4.tar.bz2
Custom implementation of VectorPlatformDeviceEmf::drawBitmapRect, to shield it from changes in SkDevice::drawBitmapRect
Review URL: https://chromiumcodereview.appspot.com/12221116 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181955 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--skia/ext/vector_platform_device_emf_win.cc57
-rw-r--r--skia/ext/vector_platform_device_emf_win.h3
2 files changed, 60 insertions, 0 deletions
diff --git a/skia/ext/vector_platform_device_emf_win.cc b/skia/ext/vector_platform_device_emf_win.cc
index cd22efd2..bcbc27a 100644
--- a/skia/ext/vector_platform_device_emf_win.cc
+++ b/skia/ext/vector_platform_device_emf_win.cc
@@ -261,6 +261,63 @@ void VectorPlatformDeviceEmf::drawPath(const SkDraw& draw,
Cleanup();
}
+void VectorPlatformDeviceEmf::drawBitmapRect(const SkDraw& draw,
+ const SkBitmap& bitmap,
+ const SkRect* src,
+ const SkRect& dst,
+ const SkPaint& paint) {
+ SkMatrix matrix;
+ SkRect bitmapBounds, tmpSrc, tmpDst;
+ SkBitmap tmpBitmap;
+
+ bitmapBounds.isetWH(bitmap.width(), bitmap.height());
+
+ // Compute matrix from the two rectangles
+ if (src) {
+ tmpSrc = *src;
+ } else {
+ tmpSrc = bitmapBounds;
+ }
+ matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit);
+
+ const SkBitmap* bitmapPtr = &bitmap;
+
+ // clip the tmpSrc to the bounds of the bitmap, and recompute dstRect if
+ // needed (if the src was clipped). No check needed if src==null.
+ if (src) {
+ if (!bitmapBounds.contains(*src)) {
+ if (!tmpSrc.intersect(bitmapBounds)) {
+ return; // nothing to draw
+ }
+ // recompute dst, based on the smaller tmpSrc
+ matrix.mapRect(&tmpDst, tmpSrc);
+ }
+
+ // since we may need to clamp to the borders of the src rect within
+ // the bitmap, we extract a subset.
+ // TODO: make sure this is handled in drawrect and remove it from here.
+ SkIRect srcIR;
+ tmpSrc.roundOut(&srcIR);
+ if (!bitmap.extractSubset(&tmpBitmap, srcIR)) {
+ return;
+ }
+ bitmapPtr = &tmpBitmap;
+
+ // Since we did an extract, we need to adjust the matrix accordingly
+ SkScalar dx = 0, dy = 0;
+ if (srcIR.fLeft > 0) {
+ dx = SkIntToScalar(srcIR.fLeft);
+ }
+ if (srcIR.fTop > 0) {
+ dy = SkIntToScalar(srcIR.fTop);
+ }
+ if (dx || dy) {
+ matrix.preTranslate(dx, dy);
+ }
+ }
+ this->drawBitmap(draw, *bitmapPtr, NULL, matrix, paint);
+}
+
void VectorPlatformDeviceEmf::drawBitmap(const SkDraw& draw,
const SkBitmap& bitmap,
const SkIRect* srcRectOrNull,
diff --git a/skia/ext/vector_platform_device_emf_win.h b/skia/ext/vector_platform_device_emf_win.h
index af0e429..461dddc 100644
--- a/skia/ext/vector_platform_device_emf_win.h
+++ b/skia/ext/vector_platform_device_emf_win.h
@@ -44,6 +44,9 @@ class VectorPlatformDeviceEmf : public SkDevice, public PlatformDevice {
const SkPaint& paint,
const SkMatrix* prePathMatrix = NULL,
bool pathIsMutable = false) OVERRIDE;
+ virtual void drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
+ const SkRect* src, const SkRect& dst,
+ const SkPaint& paint) SK_OVERRIDE;
virtual void drawBitmap(const SkDraw& draw, const SkBitmap& bitmap,
const SkIRect* srcRectOrNull,
const SkMatrix& matrix,