Add support for drawBitmapRect() to SkMiniRecorder.
BUG=chromium:503705 Review URL: https://codereview.chromium.org/1220733006
This commit is contained in:
parent
478c9e4851
commit
64b4c789fd
@ -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);
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user