Allow evaluation choice of Lazy or Eager evaluation for SkDeferredCanvas.
Eager is used for drawing to a non-recording canvas to reduce the number of
all operations.
Lazy is used for drawing to a recording canvas to reduce the amount decode/encode
that happens.
R=reed@google.com
Change-Id: I7837c4f6e5911c153e0796162e1170edbc34839e
Reviewed-on: https://skia-review.googlesource.com/9839
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Error ViaDefer::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
auto size = src.size();
return draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error {
- SkDeferredCanvas deferred(canvas);
+ SkDeferredCanvas deferred(canvas, SkDeferredCanvas::kEager);
return src.draw(&deferred);
});
}
if (kNo_Tiling == fTilingMode) {
SkDebugfDumper dumper;
SkDumpCanvas dump(&dumper);
- SkDeferredCanvas deferred(canvas);
+ SkDeferredCanvas deferred(canvas, SkDeferredCanvas::kEager);
SkCanvas* c = fUseDeferredCanvas ? &deferred : canvas;
this->INHERITED::draw(c); // no looping or surfaces needed
} else {
#include "SkDeferredCanvas.h"
#include "SkDrawable.h"
#include "SkPath.h"
+#include "SkRSXform.h"
#include "SkRRect.h"
#include "SkSurface.h"
#include "SkTextBlob.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
-SkDeferredCanvas::SkDeferredCanvas(SkCanvas* canvas)
- : INHERITED(canvas->getBaseLayerSize().width(), canvas->getBaseLayerSize().height()) {
+SkDeferredCanvas::SkDeferredCanvas(SkCanvas* canvas, EvalType evalType)
+ : INHERITED(canvas->getBaseLayerSize().width(), canvas->getBaseLayerSize().height())
+ , fCanvas(nullptr) // must be here for reset to work.
+ , fEvalType(evalType)
+{
this->reset(canvas);
}
#include "SkCanvasPriv.h"
void SkDeferredCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
const SkPaint* paint) {
-#if 0
- SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect());
- picture->playback(this);
-#else
- this->flush_before_saves();
- fCanvas->drawPicture(picture, matrix, paint);
-#endif
+ if (kEager == fEvalType) {
+ SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect());
+ picture->playback(this);
+ } else {
+ this->flush_before_saves();
+ fCanvas->drawPicture(picture, matrix, paint);
+ }
}
void SkDeferredCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
- // TODO: investigate culling and applying concat to the matrix
-#if 0
- drawable->draw(this, matrix);
-#else
- this->flush_before_saves();
- fCanvas->drawDrawable(drawable, matrix);
-#endif
+ if (kEager == fEvalType) {
+ // TODO: investigate culling and applying concat to the matrix
+ drawable->draw(this, matrix);
+ } else {
+ this->flush_before_saves();
+ fCanvas->drawDrawable(drawable, matrix);
+ }
}
void SkDeferredCanvas::onDrawAtlas(const SkImage* image, const SkRSXform xform[],
class SK_API SkDeferredCanvas : public SkNoDrawCanvas {
public:
- SkDeferredCanvas(SkCanvas* = nullptr);
+ enum EvalType {kEager, kLazy};
+ // There are two strategies for evaluating of sub-drawings (pictures and drawables).
+ // * kEager - a sub-drawing is expanded using the using the SkDeferredCanvas. This has
+ // the advantage of optimizing the sub drawing, and is used when the underlying
+ // SkCanvas is drawing and not recording.
+ // * kLazy - a sub-drawing is not expanded, but passed directly to the underlying SkCanvas.
+ // This has the advantage of not expanding the sub drawing and then immediately
+ // re-encoding it, and is used for recording canvases.
+ SkDeferredCanvas(SkCanvas*, EvalType);
~SkDeferredCanvas() override;
void reset(SkCanvas*);
class Iter;
private:
- SkCanvas* fCanvas{nullptr};
-
enum Type {
kSave_Type,
kClipRect_Type,
}
void setConcat(const SkMatrix&);
};
- SkTDArray<Rec> fRecs;
void push_save();
void push_cliprect(const SkRect&);
void internal_flush_translate(SkScalar* x, SkScalar* y, const SkRect* boundsOrNull);
+ SkTDArray<Rec> fRecs;
+ SkCanvas* fCanvas;
+ const EvalType fEvalType;
+
typedef SkNoDrawCanvas INHERITED;
};
SkDebugfDumper dumper;
SkDumpCanvas dumpC(&dumper);
- SkDeferredCanvas canvas(&dumpC);
+ SkDeferredCanvas canvas(&dumpC, SkDeferredCanvas::kEager);
SkPaint paint;
// paint.setShader(SkShader::MakeColorShader(SK_ColorRED));
}
if (FLAGS_defer) {
SkPictureRecorder recorder;
- SkDeferredCanvas deferred(recorder.beginRecording(src->cullRect()));
+ SkDeferredCanvas deferred(recorder.beginRecording(src->cullRect()),
+ SkDeferredCanvas::kEager);
src->playback(&deferred);
src = recorder.finishRecordingAsPicture();
}