Fix SkDeferredCanvas for use on android.

BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3030

Change-Id: Ie55023257736a12360a233d01096462ba2eb3e74
Reviewed-on: https://skia-review.googlesource.com/3030
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Mike Reed <reed@google.com>
This commit is contained in:
Herb Derby 2016-10-06 14:33:43 -04:00 committed by Skia Commit-Bot
parent 8f18643867
commit 1356978f15
3 changed files with 30 additions and 13 deletions

View File

@ -1515,7 +1515,7 @@ protected:
const SkPaint*,
const SkShadowParams& params);
#endif
// Returns the canvas to be used by DrawIter. Default implementation
// returns this. Subclasses that encapsulate an indirect canvas may
// need to overload this method. The impl must keep track of this, as it
@ -1567,7 +1567,7 @@ private:
SkPaint fDefaultPaint;
bool fDone;
};
static bool BoundsAffectsClip(SaveLayerFlags);
static SaveLayerFlags LegacySaveFlagsToSaveLayerFlags(uint32_t legacySaveFlags);
@ -1637,6 +1637,7 @@ private:
friend class SkPictureImageFilter; // SkCanvas(SkBaseDevice*, SkSurfaceProps*, InitFlags)
friend class SkPictureRecord; // predrawNotify (why does it need it? <reed>)
friend class SkPicturePlayback; // SaveFlagsToSaveLayerFlags
friend class SkDeferredCanvas; // For use of resetForNextPicture
enum InitFlags {
kDefault_InitFlags = 0,

View File

@ -31,7 +31,7 @@ bool SkDeferredCanvas::Rec::isConcat(SkMatrix* m) const {
void SkDeferredCanvas::Rec::setConcat(const SkMatrix& m) {
SkASSERT(m.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask));
if (m.getType() <= SkMatrix::kTranslate_Mask) {
fType = kTrans_Type;
fData.fTranslate.set(m.getTranslateX(), m.getTranslateY());
@ -45,12 +45,24 @@ void SkDeferredCanvas::Rec::setConcat(const SkMatrix& m) {
///////////////////////////////////////////////////////////////////////////////////////////////////
SkDeferredCanvas::SkDeferredCanvas(SkCanvas* canvas)
: INHERITED(canvas->getBaseLayerSize().width(), canvas->getBaseLayerSize().height())
, fCanvas(canvas)
{}
: SkCanvas({0,0,1,1}, SkCanvas::kConservativeRasterClip_InitFlag) {
this->reset(canvas);
}
SkDeferredCanvas::~SkDeferredCanvas() {}
void SkDeferredCanvas::reset(SkCanvas* canvas) {
if (fCanvas) {
this->flush();
fCanvas = nullptr;
}
fRecs.reset();
if (canvas) {
this->resetForNextPicture(SkIRect::MakeSize(canvas->getBaseLayerSize()));
fCanvas = canvas;
}
}
void SkDeferredCanvas::push_save() {
Rec* r = fRecs.append();
r->fType = kSave_Type;
@ -434,7 +446,7 @@ void SkDeferredCanvas::onDrawImageLattice(const SkImage* image, const Lattice& l
}
void SkDeferredCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
const SkPaint& paint) {
const SkPaint& paint) {
this->flush_translate(&x, &y, paint);
fCanvas->drawText(text, byteLength, x, y, paint);
}
@ -480,7 +492,7 @@ void SkDeferredCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScal
#include "SkCanvasPriv.h"
void SkDeferredCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
const SkPaint* paint) {
#if 1
#if 0
SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect());
picture->playback(this);
#else
@ -491,7 +503,7 @@ void SkDeferredCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* m
void SkDeferredCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
// TODO: investigate culling and applying concat to the matrix
#if 1
#if 0
drawable->draw(this, matrix);
#else
this->flush_before_saves();
@ -525,7 +537,9 @@ void SkDeferredCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor color
}
void SkDeferredCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* data) {
fCanvas->drawAnnotation(rect, key, data);
SkRect modRect = rect;
this->flush_check(&modRect, nullptr, kNoClip_Flag);
fCanvas->drawAnnotation(modRect, key, data);
}
#ifdef SK_SUPPORT_LEGACY_DRAWFILTER

View File

@ -14,9 +14,11 @@
class SK_API SkDeferredCanvas : public SkCanvas {
public:
SkDeferredCanvas(SkCanvas*);
SkDeferredCanvas(SkCanvas* = nullptr);
~SkDeferredCanvas() override;
void reset(SkCanvas*);
#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
SkDrawFilter* setDrawFilter(SkDrawFilter*) override;
#endif
@ -106,7 +108,7 @@ protected:
class Iter;
private:
SkCanvas* fCanvas;
SkCanvas* fCanvas{nullptr};
enum Type {
kSave_Type,
@ -137,7 +139,7 @@ private:
void push_save();
void push_cliprect(const SkRect&);
bool push_concat(const SkMatrix&);
void emit(const Rec& rec);
void flush_all();