flag to use const& instead of const* for src-rect
BUG=skia:
Review URL: https://codereview.chromium.org/1272713005
diff --git a/src/c/sk_surface.cpp b/src/c/sk_surface.cpp
index 1e676ff..84a9c54 100644
--- a/src/c/sk_surface.cpp
+++ b/src/c/sk_surface.cpp
@@ -162,10 +162,6 @@
return reinterpret_cast<const SkRect&>(crect);
}
-static const SkRect* AsRect(const sk_rect_t* crect) {
- return reinterpret_cast<const SkRect*>(crect);
-}
-
static const SkPath& AsPath(const sk_path_t& cpath) {
return reinterpret_cast<const SkPath&>(cpath);
}
@@ -399,7 +395,16 @@
void sk_canvas_draw_image_rect(sk_canvas_t* ccanvas, const sk_image_t* cimage,
const sk_rect_t* csrcR, const sk_rect_t* cdstR,
const sk_paint_t* cpaint) {
- AsCanvas(ccanvas)->drawImageRect(AsImage(cimage), AsRect(csrcR), AsRect(*cdstR), AsPaint(cpaint));
+ SkCanvas* canvas = AsCanvas(ccanvas);
+ const SkImage* image = AsImage(cimage);
+ const SkRect& dst = AsRect(*cdstR);
+ const SkPaint* paint = AsPaint(cpaint);
+
+ if (csrcR) {
+ canvas->drawImageRect(image, AsRect(*csrcR), dst, paint);
+ } else {
+ canvas->drawImageRect(image, dst, paint);
+ }
}
void sk_canvas_draw_picture(sk_canvas_t* ccanvas, const sk_picture_t* cpicture,
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 342f79f..4f5e159 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -1846,6 +1846,7 @@
this->onDrawImage(image, x, y, paint);
}
+#ifdef SK_SUPPORT_LEGACY_SRCPTR_DRAWIMAGERECT
void SkCanvas::drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
const SkPaint* paint, SrcRectConstraint constraint) {
if (dst.isEmpty()) {
@@ -1853,20 +1854,47 @@
}
this->onDrawImageRect(image, src, dst, paint, constraint);
}
+void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
+ const SkPaint* paint, SrcRectConstraint constraint) {
+ if (bitmap.drawsNothing() || dst.isEmpty()) {
+ return;
+ }
+ this->onDrawBitmapRect(bitmap, src, dst, paint, constraint);
+}
+#endif
+
+void SkCanvas::drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst,
+ const SkPaint* paint, SrcRectConstraint constraint) {
+ if (dst.isEmpty() || src.isEmpty()) {
+ return;
+ }
+ this->onDrawImageRect(image, &src, dst, paint, constraint);
+}
void SkCanvas::drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst,
const SkPaint* paint, SrcRectConstraint constraint) {
- SkRect src = SkRect::Make(isrc);
- this->drawImageRect(image, &src, dst, paint, constraint);
+ this->drawImageRect(image, SkRect::Make(isrc), dst, paint, constraint);
}
+#ifdef SK_SUPPORT_LEGACY_SIMPLE_DRAWIMAGERECT
+void SkCanvas::drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint) {
+ this->drawImageRect(image, SkRect::MakeIWH(image->width(), image->height()), dst, paint);
+}
+#else
+void SkCanvas::drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint,
+ SrcRectConstraint constraint) {
+ this->drawImageRect(image, SkRect::MakeIWH(image->width(), image->height()), dst, paint,
+ constraint);
+}
+#endif
+
void SkCanvas::drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
const SkPaint* paint) {
if (dst.isEmpty()) {
return;
}
if (!SkNinePatchIter::Valid(image->width(), image->height(), center)) {
- this->drawImageRect(image, NULL, dst, paint);
+ this->drawImageRect(image, dst, paint);
}
this->onDrawImageNine(image, center, dst, paint);
}
@@ -1878,20 +1906,31 @@
this->onDrawBitmap(bitmap, dx, dy, paint);
}
-void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
+void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst,
const SkPaint* paint, SrcRectConstraint constraint) {
- if (bitmap.drawsNothing() || dst.isEmpty()) {
+ if (bitmap.drawsNothing() || dst.isEmpty() || src.isEmpty()) {
return;
}
- this->onDrawBitmapRect(bitmap, src, dst, paint, constraint);
+ this->onDrawBitmapRect(bitmap, &src, dst, paint, constraint);
}
void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst,
const SkPaint* paint, SrcRectConstraint constraint) {
- SkRect src = SkRect::Make(isrc);
- this->drawBitmapRect(bitmap, &src, dst, paint, constraint);
+ this->drawBitmapRect(bitmap, SkRect::Make(isrc), dst, paint, constraint);
}
+#ifdef SK_SUPPORT_LEGACY_SIMPLE_DRAWIMAGERECT
+void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint) {
+ this->drawBitmapRect(bitmap, SkRect::MakeIWH(bitmap.width(), bitmap.height()), dst, paint);
+}
+#else
+void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint,
+ SrcRectConstraint constraint) {
+ this->drawBitmapRect(bitmap, SkRect::MakeIWH(bitmap.width(), bitmap.height()), dst, paint,
+ constraint);
+}
+#endif
+
void SkCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst,
const SkPaint* paint) {
if (bitmap.drawsNothing() || dst.isEmpty()) {
@@ -1922,6 +1961,25 @@
this->onDrawAtlas(atlas, xform, tex, colors, count, mode, cull, paint);
}
+void SkCanvas::legacy_drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
+ const SkPaint* paint, SrcRectConstraint constraint) {
+ if (src) {
+ this->drawImageRect(image, *src, dst, paint, constraint);
+ } else {
+ this->drawImageRect(image, SkRect::MakeIWH(image->width(), image->height()),
+ dst, paint, constraint);
+ }
+}
+void SkCanvas::legacy_drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
+ const SkPaint* paint, SrcRectConstraint constraint) {
+ if (src) {
+ this->drawBitmapRect(bitmap, *src, dst, paint, constraint);
+ } else {
+ this->drawBitmapRect(bitmap, SkRect::MakeIWH(bitmap.width(), bitmap.height()),
+ dst, paint, constraint);
+ }
+}
+
//////////////////////////////////////////////////////////////////////////////
// These are the virtual drawing methods
//////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp
index 2338374..eb7c476 100644
--- a/src/core/SkPicturePlayback.cpp
+++ b/src/core/SkPicturePlayback.cpp
@@ -188,7 +188,7 @@
const SkRect* src = get_rect_ptr(reader); // may be null
const SkRect& dst = reader->skipT<SkRect>(); // required
SkCanvas::SrcRectConstraint constraint = (SkCanvas::SrcRectConstraint)reader->readInt();
- canvas->drawBitmapRect(bitmap, src, dst, paint, constraint);
+ canvas->legacy_drawBitmapRect(bitmap, src, dst, paint, constraint);
} break;
case DRAW_BITMAP_MATRIX: {
const SkPaint* paint = fPictureData->getPaint(reader);
@@ -260,7 +260,7 @@
// newer op-code stores the constraint explicitly
constraint = (SkCanvas::SrcRectConstraint)reader->readInt();
}
- canvas->drawImageRect(image, src, dst, paint, constraint);
+ canvas->legacy_drawImageRect(image, src, dst, paint, constraint);
} break;
case DRAW_OVAL: {
const SkPaint& paint = *fPictureData->getPaint(reader);
diff --git a/src/core/SkRecordDraw.cpp b/src/core/SkRecordDraw.cpp
index 25fc2d8..8c884d9 100644
--- a/src/core/SkRecordDraw.cpp
+++ b/src/core/SkRecordDraw.cpp
@@ -89,16 +89,16 @@
DRAW(DrawBitmap, drawBitmap(r.bitmap.shallowCopy(), r.left, r.top, r.paint));
DRAW(DrawBitmapNine, drawBitmapNine(r.bitmap.shallowCopy(), r.center, r.dst, r.paint));
DRAW(DrawBitmapRect,
- drawBitmapRect(r.bitmap.shallowCopy(), r.src, r.dst, r.paint,
+ legacy_drawBitmapRect(r.bitmap.shallowCopy(), r.src, r.dst, r.paint,
SkCanvas::kStrict_SrcRectConstraint));
DRAW(DrawBitmapRectFast,
- drawBitmapRect(r.bitmap.shallowCopy(), r.src, r.dst, r.paint,
+ legacy_drawBitmapRect(r.bitmap.shallowCopy(), r.src, r.dst, r.paint,
SkCanvas::kFast_SrcRectConstraint));
DRAW(DrawBitmapRectFixedSize,
- drawBitmapRect(r.bitmap.shallowCopy(), &r.src, r.dst, &r.paint, r.constraint));
+ legacy_drawBitmapRect(r.bitmap.shallowCopy(), &r.src, r.dst, &r.paint, r.constraint));
DRAW(DrawDRRect, drawDRRect(r.outer, r.inner, r.paint));
DRAW(DrawImage, drawImage(r.image, r.left, r.top, r.paint));
-DRAW(DrawImageRect, drawImageRect(r.image, r.src, r.dst, r.paint, r.constraint));
+DRAW(DrawImageRect, legacy_drawImageRect(r.image, r.src, r.dst, r.paint, r.constraint));
DRAW(DrawImageNine, drawImageNine(r.image, r.center, r.dst, r.paint));
DRAW(DrawOval, drawOval(r.oval, r.paint));
DRAW(DrawPaint, drawPaint(r.paint));
diff --git a/src/effects/SkBitmapSource.cpp b/src/effects/SkBitmapSource.cpp
index 859e8af..ecaffcf 100644
--- a/src/effects/SkBitmapSource.cpp
+++ b/src/effects/SkBitmapSource.cpp
@@ -84,7 +84,7 @@
paint.setFilterQuality(
fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.height() ?
kNone_SkFilterQuality : fFilterQuality);
- canvas.drawBitmapRect(fBitmap, &fSrcRect, dstRect, &paint, SkCanvas::kStrict_SrcRectConstraint);
+ canvas.drawBitmapRect(fBitmap, fSrcRect, dstRect, &paint, SkCanvas::kStrict_SrcRectConstraint);
*result = device.get()->accessBitmap(false);
offset->fX = dstIRect.fLeft;
diff --git a/src/effects/SkTestImageFilters.cpp b/src/effects/SkTestImageFilters.cpp
index cd277ec..43b43a5 100755
--- a/src/effects/SkTestImageFilters.cpp
+++ b/src/effects/SkTestImageFilters.cpp
@@ -69,9 +69,7 @@
}
OwnDeviceCanvas canvas(dev);
- SkRect r = SkRect::MakeWH(SkIntToScalar(src.width()),
- SkIntToScalar(src.height()));
- canvas.drawBitmapRect(tmp, r);
+ canvas.drawBitmapRect(tmp, SkRect::MakeIWH(src.width(), src.height()), nullptr);
*result = dev->accessBitmap(false);
}
return true;
diff --git a/src/gpu/GrRecordReplaceDraw.cpp b/src/gpu/GrRecordReplaceDraw.cpp
index e3936de..11eb38d 100644
--- a/src/gpu/GrRecordReplaceDraw.cpp
+++ b/src/gpu/GrRecordReplaceDraw.cpp
@@ -43,7 +43,7 @@
canvas->save();
canvas->setMatrix(SkMatrix::I());
- canvas->drawBitmapRect(bm, &src, dst, layer->paint(), SkCanvas::kStrict_SrcRectConstraint);
+ canvas->drawBitmapRect(bm, src, dst, layer->paint(), SkCanvas::kStrict_SrcRectConstraint);
canvas->restore();
} else {
canvas->drawSprite(bm,
diff --git a/src/pipe/SkGPipeRead.cpp b/src/pipe/SkGPipeRead.cpp
index ef1eeb3..29d798b 100644
--- a/src/pipe/SkGPipeRead.cpp
+++ b/src/pipe/SkGPipeRead.cpp
@@ -650,7 +650,7 @@
const SkRect* dst = skip<SkRect>(reader);
const SkBitmap* bitmap = holder.getBitmap();
if (state->shouldDraw()) {
- canvas->drawBitmapRect(*bitmap, src, *dst, hasPaint ? &state->paint() : NULL, constraint);
+ canvas->legacy_drawBitmapRect(*bitmap, src, *dst, hasPaint ? &state->paint() : NULL, constraint);
}
}
@@ -692,7 +692,7 @@
const SkImage* image = state->getImage(slot);
if (state->shouldDraw()) {
- canvas->drawImageRect(image, src, *dst, hasPaint ? &state->paint() : NULL, constraint);
+ canvas->legacy_drawImageRect(image, src, *dst, hasPaint ? &state->paint() : NULL, constraint);
}
}
diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp
index 8a4f817..6ccfb5e 100644
--- a/src/utils/SkDeferredCanvas.cpp
+++ b/src/utils/SkDeferredCanvas.cpp
@@ -872,7 +872,7 @@
}
AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint);
- this->drawingCanvas()->drawBitmapRect(bitmap, src, dst, paint, (SrcRectConstraint)constraint);
+ this->drawingCanvas()->legacy_drawBitmapRect(bitmap, src, dst, paint, (SrcRectConstraint)constraint);
this->recordedDrawCommand();
}
@@ -900,7 +900,7 @@
}
AutoImmediateDrawIfNeeded autoDraw(*this, image, paint);
- this->drawingCanvas()->drawImageRect(image, src, dst, paint, constraint);
+ this->drawingCanvas()->legacy_drawImageRect(image, src, dst, paint, constraint);
this->recordedDrawCommand();
}
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index b0e7b8f..7c378c9 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -534,7 +534,7 @@
lua2rect(L, 4, &dstR);
SkPaint paint;
- canvas->drawImageRect(image, srcRPtr, dstR, lua2OptionalPaint(L, 5, &paint));
+ canvas->legacy_drawImageRect(image, srcRPtr, dstR, lua2OptionalPaint(L, 5, &paint));
return 0;
}
diff --git a/src/utils/SkNWayCanvas.cpp b/src/utils/SkNWayCanvas.cpp
index 0efc98c..fb8d0ee 100644
--- a/src/utils/SkNWayCanvas.cpp
+++ b/src/utils/SkNWayCanvas.cpp
@@ -196,7 +196,7 @@
const SkPaint* paint, SrcRectConstraint constraint) {
Iter iter(fList);
while (iter.next()) {
- iter->drawBitmapRect(bitmap, src, dst, paint, (SrcRectConstraint)constraint);
+ iter->legacy_drawBitmapRect(bitmap, src, dst, paint, (SrcRectConstraint)constraint);
}
}
@@ -220,7 +220,7 @@
const SkPaint* paint, SrcRectConstraint constraint) {
Iter iter(fList);
while (iter.next()) {
- iter->drawImageRect(image, src, dst, paint, constraint);
+ iter->legacy_drawImageRect(image, src, dst, paint, constraint);
}
}
diff --git a/src/utils/android/SkAndroidSDKCanvas.cpp b/src/utils/android/SkAndroidSDKCanvas.cpp
index a6393d2..b05605b 100644
--- a/src/utils/android/SkAndroidSDKCanvas.cpp
+++ b/src/utils/android/SkAndroidSDKCanvas.cpp
@@ -147,7 +147,7 @@
const SkPaint* paint,
SkCanvas::SrcRectConstraint constraint) {
FILTER_PTR(paint);
- fProxyTarget->drawBitmapRect(bitmap, src, dst, filteredPaint, constraint);
+ fProxyTarget->legacy_drawBitmapRect(bitmap, src, dst, filteredPaint, constraint);
}
void SkAndroidSDKCanvas::onDrawBitmapNine(const SkBitmap& bitmap,
const SkIRect& center,
@@ -244,7 +244,7 @@
const SkPaint* paint,
SrcRectConstraint constraint) {
FILTER_PTR(paint);
- fProxyTarget->drawImageRect(image, in, out, filteredPaint, constraint);
+ fProxyTarget->legacy_drawImageRect(image, in, out, filteredPaint, constraint);
}
void SkAndroidSDKCanvas::onDrawPicture(const SkPicture* picture,
diff --git a/src/utils/debugger/SkDrawCommand.cpp b/src/utils/debugger/SkDrawCommand.cpp
index 15fc9ca..8e1612f 100644
--- a/src/utils/debugger/SkDrawCommand.cpp
+++ b/src/utils/debugger/SkDrawCommand.cpp
@@ -131,7 +131,7 @@
yScale * input.height());
canvas->clear(0xFFFFFFFF);
- canvas->drawBitmapRect(input, dst);
+ canvas->drawBitmapRect(input, dst, nullptr);
if (srcRect) {
SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
@@ -352,7 +352,7 @@
}
void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const {
- canvas->drawBitmapRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fConstraint);
+ canvas->legacy_drawBitmapRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fConstraint);
}
bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
@@ -405,7 +405,7 @@
}
void SkDrawImageRectCommand::execute(SkCanvas* canvas) const {
- canvas->drawImageRect(fImage, fSrc.getMaybeNull(), fDst, fPaint.getMaybeNull(), fConstraint);
+ canvas->legacy_drawImageRect(fImage, fSrc.getMaybeNull(), fDst, fPaint.getMaybeNull(), fConstraint);
}
bool SkDrawImageRectCommand::render(SkCanvas* canvas) const {