// Allocate contiguous space for count Ts, to be freed when the SkRecord is destroyed.
// Here T can be any class, not just those from SkRecords. Throws on failure.
template <typename T>
- T* alloc(unsigned count = 1) {
+ T* alloc(size_t count = 1) {
return (T*)fAlloc.allocThrow(sizeof(T) * count);
}
DRAW(DrawPaint, drawPaint(r.paint));
DRAW(DrawPath, drawPath(r.path, r.paint));
DRAW(DrawPatch, drawPatch(r.patch, r.paint));
+DRAW(DrawPicture, drawPicture(r.picture));
DRAW(DrawPoints, drawPoints(r.mode, r.count, r.pts, r.paint));
DRAW(DrawPosText, drawPosText(r.text, r.byteLength, r.pos, r.paint));
DRAW(DrawPosTextH, drawPosTextH(r.text, r.byteLength, r.xpos, r.y, r.paint));
// This copy() is for arrays.
// It will work with POD or non-POD, though currently we only use it for POD.
template <typename T>
-T* SkRecorder::copy(const T src[], unsigned count) {
+T* SkRecorder::copy(const T src[], size_t count) {
if (NULL == src) {
return NULL;
}
T* dst = fRecord->alloc<T>(count);
- for (unsigned i = 0; i < count; i++) {
+ for (size_t i = 0; i < count; i++) {
SkNEW_PLACEMENT_ARGS(dst + i, T, (src[i]));
}
return dst;
// This measured around 2x faster for copying code points,
// but I found no corresponding speedup for other arrays.
template <>
-char* SkRecorder::copy(const char src[], unsigned count) {
+char* SkRecorder::copy(const char src[], size_t count) {
if (NULL == src) {
return NULL;
}
}
void SkRecorder::onDrawPicture(const SkPicture* picture) {
- picture->draw(this);
+ APPEND(DrawPicture, picture);
}
void SkRecorder::drawVertices(VertexMode vmode,
T* copy(const T*);
template <typename T>
- T* copy(const T[], unsigned count);
+ T* copy(const T[], size_t count);
SkRecord* fRecord;
};
#define SkRecords_DEFINED
#include "SkCanvas.h"
+#include "SkPicture.h"
+
+class SkPictureBox {
+public:
+ SkPictureBox(const SkPicture* obj) : fObj(SkRef(obj)) {}
+ SkPictureBox(const SkPictureBox& src) : fObj(SkRef(src.fObj)) {}
+ ~SkPictureBox() { fObj->unref(); }
+
+ SkPictureBox& operator=(const SkPictureBox& src) {
+ SkRefCnt_SafeAssign(fObj, src.fObj);
+ return *this;
+ }
+
+ operator const SkPicture*() const { return fObj; }
+
+private:
+ const SkPicture* fObj;
+};
namespace SkRecords {
M(DrawPaint) \
M(DrawPath) \
M(DrawPatch) \
+ M(DrawPicture) \
M(DrawPoints) \
M(DrawPosText) \
M(DrawPosTextH) \
RECORD1(DrawPaint, SkPaint, paint);
RECORD2(DrawPath, SkPaint, paint, SkPath, path);
RECORD2(DrawPatch, SkPaint, paint, SkPatch, patch);
+RECORD1(DrawPicture, SkPictureBox, picture);
RECORD4(DrawPoints, SkPaint, paint, SkCanvas::PointMode, mode, size_t, count, SkPoint*, pts);
RECORD4(DrawPosText, SkPaint, paint,
PODArray<char>, text,
#include "Test.h"
+#include "SkPictureRecorder.h"
#include "SkRecord.h"
#include "SkRecorder.h"
#include "SkRecords.h"
}
REPORTER_ASSERT(r, paint.getShader()->unique());
}
+
+DEF_TEST(Recorder_RefPictures, r) {
+ SkAutoTUnref<SkPicture> pic;
+
+ {
+ SkPictureRecorder pr;
+ SkCanvas* canvas = pr.beginRecording(100, 100);
+ canvas->drawColor(SK_ColorRED);
+ pic.reset(pr.endRecording());
+ }
+ REPORTER_ASSERT(r, pic->unique());
+
+ {
+ SkRecord record;
+ SkRecorder recorder(&record, 100, 100);
+ recorder.drawPicture(pic);
+ // the recorder should now also be an owner
+ REPORTER_ASSERT(r, !pic->unique());
+ }
+ // the recorder destructor should have released us (back to unique)
+ REPORTER_ASSERT(r, pic->unique());
+}