aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-07-01 13:56:53 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-07-01 13:56:53 -0700
commit64b4c789fd1721d6804ccb5a9ceae39df03a5711 (patch)
tree7b1cd391c0b0f1a15b7d21f710ee2ac3fc053d69
parent478c9e4851eff5feb74dd2f8a14143bec569e1a8 (diff)
Add support for drawBitmapRect() to SkMiniRecorder.
BUG=chromium:503705 Review URL: https://codereview.chromium.org/1220733006
-rw-r--r--src/core/SkMiniRecorder.cpp16
-rw-r--r--src/core/SkMiniRecorder.h18
-rw-r--r--src/core/SkRecordDraw.cpp9
-rw-r--r--src/core/SkRecorder.cpp1
-rw-r--r--src/core/SkRecords.h6
5 files changed, 44 insertions, 6 deletions
diff --git a/src/core/SkMiniRecorder.cpp b/src/core/SkMiniRecorder.cpp
index ff17edb257..538db087bf 100644
--- a/src/core/SkMiniRecorder.cpp
+++ b/src/core/SkMiniRecorder.cpp
@@ -72,6 +72,20 @@ SkMiniRecorder::~SkMiniRecorder() {
new (fBuffer.get()) Type(__VA_ARGS__); \
return true
+bool SkMiniRecorder::drawBitmapRectToRect(const SkBitmap& bm, const SkRect* src, const SkRect& dst,
+ const SkPaint* p, SkCanvas::DrawBitmapRectFlags flags) {
+ SkRect bounds;
+ if (!src) {
+ bm.getBounds(&bounds);
+ src = &bounds;
+ }
+ SkTLazy<SkPaint> defaultPaint;
+ if (!p) {
+ p = defaultPaint.init();
+ }
+ TRY_TO_STORE(DrawBitmapRectToRectFixedSize, *p, bm, *src, dst, flags);
+}
+
bool SkMiniRecorder::drawRect(const SkRect& rect, const SkPaint& paint) {
TRY_TO_STORE(DrawRect, paint, rect);
}
@@ -94,6 +108,7 @@ SkPicture* SkMiniRecorder::detachAsPicture(const SkRect& cull) {
switch (fState) {
case State::kEmpty: return SkRef(gEmptyPicture.get());
+ CASE(DrawBitmapRectToRectFixedSize);
CASE(DrawPath);
CASE(DrawRect);
CASE(DrawTextBlob);
@@ -114,6 +129,7 @@ void SkMiniRecorder::flushAndReset(SkCanvas* canvas) {
switch (fState) {
case State::kEmpty: return;
+ CASE(DrawBitmapRectToRectFixedSize);
CASE(DrawPath);
CASE(DrawRect);
CASE(DrawTextBlob);
diff --git a/src/core/SkMiniRecorder.h b/src/core/SkMiniRecorder.h
index 914eccc2e3..023e2ad55a 100644
--- a/src/core/SkMiniRecorder.h
+++ b/src/core/SkMiniRecorder.h
@@ -20,6 +20,8 @@ public:
~SkMiniRecorder();
// Try to record an op. Returns false on failure.
+ bool drawBitmapRectToRect(const SkBitmap&, const SkRect* src, const SkRect& dst,
+ const SkPaint*, SkCanvas::DrawBitmapRectFlags);
bool drawPath(const SkPath&, const SkPaint&);
bool drawRect(const SkRect&, const SkPaint&);
bool drawTextBlob(const SkTextBlob*, SkScalar x, SkScalar y, const SkPaint&);
@@ -34,16 +36,24 @@ public:
void flushAndReset(SkCanvas*);
private:
- enum class State { kEmpty, kDrawPath, kDrawRect, kDrawTextBlob };
+ enum class State {
+ kEmpty,
+ kDrawBitmapRectToRectFixedSize,
+ kDrawPath,
+ kDrawRect,
+ kDrawTextBlob,
+ };
State fState;
template <size_t A, size_t B>
struct Max { static const size_t val = A > B ? A : B; };
- static const size_t kInlineStorage = Max<sizeof(SkRecords::DrawPath),
- Max<sizeof(SkRecords::DrawRect),
- sizeof(SkRecords::DrawTextBlob)>::val>::val;
+ static const size_t kInlineStorage =
+ Max<sizeof(SkRecords::DrawBitmapRectToRectFixedSize),
+ Max<sizeof(SkRecords::DrawPath),
+ Max<sizeof(SkRecords::DrawRect),
+ sizeof(SkRecords::DrawTextBlob)>::val>::val>::val;
SkAlignedSStorage<kInlineStorage> fBuffer;
};
diff --git a/src/core/SkRecordDraw.cpp b/src/core/SkRecordDraw.cpp
index af71624474..118027b7a7 100644
--- a/src/core/SkRecordDraw.cpp
+++ b/src/core/SkRecordDraw.cpp
@@ -94,6 +94,8 @@ DRAW(DrawBitmapRectToRect,
DRAW(DrawBitmapRectToRectBleed,
drawBitmapRectToRect(r.bitmap.shallowCopy(), r.src, r.dst, r.paint,
SkCanvas::kBleed_DrawBitmapRectFlag));
+DRAW(DrawBitmapRectToRectFixedSize,
+ drawBitmapRectToRect(r.bitmap.shallowCopy(), &r.src, r.dst, &r.paint, r.flags));
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));
@@ -423,6 +425,9 @@ private:
Bounds bounds(const DrawBitmapRectToRectBleed& op) const {
return this->adjustAndMap(op.dst, op.paint);
}
+ Bounds bounds(const DrawBitmapRectToRectFixedSize& op) const {
+ return this->adjustAndMap(op.dst, &op.paint);
+ }
Bounds bounds(const DrawBitmapNine& op) const {
return this->adjustAndMap(op.dst, op.paint);
}
@@ -456,7 +461,7 @@ private:
dst.set(op.vertices, op.vertexCount);
return this->adjustAndMap(dst, &op.paint);
}
-
+
Bounds bounds(const DrawAtlas& op) const {
if (op.cull) {
return this->adjustAndMap(*op.cull, op.paint);
@@ -464,7 +469,7 @@ private:
return fCurrentClipBounds;
}
}
-
+
Bounds bounds(const DrawPicture& op) const {
SkRect dst = op.picture->cullRect();
op.matrix.mapRect(&dst);
diff --git a/src/core/SkRecorder.cpp b/src/core/SkRecorder.cpp
index a9d9ba9d14..775a7e0c55 100644
--- a/src/core/SkRecorder.cpp
+++ b/src/core/SkRecorder.cpp
@@ -178,6 +178,7 @@ void SkRecorder::onDrawBitmapRect(const SkBitmap& bitmap,
const SkRect& dst,
const SkPaint* paint,
DrawBitmapRectFlags flags) {
+ TRY_MINIRECORDER(drawBitmapRectToRect, bitmap, src, dst, paint, flags);
if (kBleed_DrawBitmapRectFlag == flags) {
APPEND(DrawBitmapRectToRectBleed,
this->copy(paint), bitmap, this->copy(src), dst);
diff --git a/src/core/SkRecords.h b/src/core/SkRecords.h
index 4c9833cfc0..b98b93c827 100644
--- a/src/core/SkRecords.h
+++ b/src/core/SkRecords.h
@@ -41,6 +41,7 @@ namespace SkRecords {
M(DrawBitmapNine) \
M(DrawBitmapRectToRect) \
M(DrawBitmapRectToRectBleed) \
+ M(DrawBitmapRectToRectFixedSize) \
M(DrawDrawable) \
M(DrawImage) \
M(DrawImageRect) \
@@ -282,6 +283,11 @@ RECORD4(DrawBitmapRectToRectBleed, Optional<SkPaint>, paint,
ImmutableBitmap, bitmap,
Optional<SkRect>, src,
SkRect, dst);
+RECORD5(DrawBitmapRectToRectFixedSize, SkPaint, paint,
+ ImmutableBitmap, bitmap,
+ SkRect, src,
+ SkRect, dst,
+ SkCanvas::DrawBitmapRectFlags, flags);
RECORD3(DrawDRRect, SkPaint, paint, SkRRect, outer, SkRRect, inner);
RECORD2(DrawDrawable, SkRect, worstCaseBounds, int32_t, index);
RECORD4(DrawImage, Optional<SkPaint>, paint,