const uint16_t indices[], int indexCount,
const SkPaint& paint);
+ /** Send a blob of data to the canvas.
+ For canvases that draw, this call is effectively a no-op, as the data
+ is not parsed, but just ignored. However, this call exists for
+ subclasses like SkPicture's recording canvas, that can store the data
+ and then play it back later (via another call to drawData).
+ */
+ virtual void drawData(const void* data, size_t length);
+
//////////////////////////////////////////////////////////////////////////
/** Get the current bounder object.
kDrawText_Verb,
kDrawPicture_Verb,
kDrawShape_Verb,
- kDrawVertices_Verb
+ kDrawVertices_Verb,
+ kDrawData_Verb
};
/** Subclasses of this are installed on the DumpCanvas, and then called for
const SkColor colors[], SkXfermode* xmode,
const uint16_t indices[], int indexCount,
const SkPaint& paint);
+ virtual void drawData(const void*, size_t);
private:
Dumper* fDumper;
const SkColor colors[], SkXfermode* xmode,
const uint16_t indices[], int indexCount,
const SkPaint& paint);
-
+ virtual void drawData(const void* data, size_t length);
+
virtual SkBounder* setBounder(SkBounder* bounder);
virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter);
#include "SampleCode.h"
+#include "SkDumpCanvas.h"
#include "SkView.h"
#include "SkCanvas.h"
#include "Sk64.h"
#include "SkGradientShader.h"
#include "SkGraphics.h"
#include "SkImageDecoder.h"
-#include "SkKernel33MaskFilter.h"
#include "SkPath.h"
#include "SkPicture.h"
#include "SkRandom.h"
canvas->drawBitmap(fBitmap, 0, 0, NULL);
canvas->restore();
+ const char beforeStr[] = "before circle";
+ const char afterStr[] = "after circle";
+
paint.setAntiAlias(true);
paint.setColor(SK_ColorRED);
+ canvas->drawData(beforeStr, sizeof(beforeStr));
canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
SkIntToScalar(40), paint);
+ canvas->drawData(afterStr, sizeof(afterStr));
paint.setColor(SK_ColorBLACK);
paint.setTextSize(SkIntToScalar(40));
canvas->drawText("Picture", 7, SkIntToScalar(50), SkIntToScalar(62),
paint);
+
}
virtual void onDraw(SkCanvas* canvas) {
canvas->translate(-SkIntToScalar(100), 0);
canvas->drawPicture(*pict);
canvas->restore();
+
+ if (false) {
+ SkDebugfDumper dumper;
+ SkDumpCanvas dumpCanvas(&dumper);
+ dumpCanvas.drawPicture(*pict);
+ }
// test that we can re-record a subpicture, and see the results
ITER_END
}
+void SkCanvas::drawData(const void* data, size_t length) {
+ // do nothing. Subclasses may do something with the data
+}
+
//////////////////////////////////////////////////////////////////////////////
// These methods are NOT virtual, and therefore must call back into virtual
// methods, rather than actually drawing themselves.
DRAW_BITMAP,
DRAW_BITMAP_MATRIX,
DRAW_BITMAP_RECT,
+ DRAW_DATA,
DRAW_PAINT,
DRAW_PATH,
DRAW_PICTURE,
const SkMatrix* matrix = getMatrix();
canvas.drawBitmapMatrix(bitmap, *matrix, paint);
} break;
+ case DRAW_DATA: {
+ size_t length = getInt();
+ canvas.drawData(fReader.skip(length), length);
+ // skip handles padding the read out to a multiple of 4
+ } break;
case DRAW_PAINT:
canvas.drawPaint(*getPaint());
break;
}
}
+void SkPictureRecord::drawData(const void* data, size_t length) {
+ addDraw(DRAW_DATA);
+ addInt(length);
+ fWriter.writePad(data, length);
+}
+
///////////////////////////////////////////////////////////////////////////////
void SkPictureRecord::reset() {
const SkColor colors[], SkXfermode*,
const uint16_t indices[], int indexCount,
const SkPaint&);
+ virtual void drawData(const void*, size_t);
void addFontMetricsTopBottom(const SkPaint& paint, SkScalar baselineY);
SkScalarToFloat(vertices[0].fY));
}
+void SkDumpCanvas::drawData(const void* data, size_t length) {
+// this->dump(kDrawData_Verb, NULL, "drawData(%d)", length);
+ this->dump(kDrawData_Verb, NULL, "drawData(%d) %.*s", length,
+ SkMin32(length, 64), data);
+}
+
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
xmode, indices, indexCount, paint);
}
+void SkProxyCanvas::drawData(const void* data, size_t length) {
+ fProxy->drawData(data, length);
+}
+
SkBounder* SkProxyCanvas::setBounder(SkBounder* bounder) {
return fProxy->setBounder(bounder);
}