aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/core/SkRecord.h2
-rw-r--r--src/core/SkRecordDraw.cpp1
-rw-r--r--src/core/SkRecorder.cpp8
-rw-r--r--src/core/SkRecorder.h2
-rw-r--r--src/core/SkRecords.h20
-rw-r--r--tests/RecorderTest.cpp23
6 files changed, 50 insertions, 6 deletions
diff --git a/src/core/SkRecord.h b/src/core/SkRecord.h
index 6c5177eefb..96da69b12e 100644
--- a/src/core/SkRecord.h
+++ b/src/core/SkRecord.h
@@ -64,7 +64,7 @@ public:
// 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);
}
diff --git a/src/core/SkRecordDraw.cpp b/src/core/SkRecordDraw.cpp
index ac463194a6..c3c767ce77 100644
--- a/src/core/SkRecordDraw.cpp
+++ b/src/core/SkRecordDraw.cpp
@@ -64,6 +64,7 @@ DRAW(DrawOval, drawOval(r.oval, r.paint));
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));
diff --git a/src/core/SkRecorder.cpp b/src/core/SkRecorder.cpp
index 255eb393b3..19d60d5bf8 100644
--- a/src/core/SkRecorder.cpp
+++ b/src/core/SkRecorder.cpp
@@ -57,12 +57,12 @@ T* SkRecorder::copy(const T* src) {
// 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;
@@ -72,7 +72,7 @@ T* SkRecorder::copy(const T src[], unsigned count) {
// 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;
}
@@ -187,7 +187,7 @@ void SkRecorder::onDrawTextOnPath(const void* text, size_t byteLength, const SkP
}
void SkRecorder::onDrawPicture(const SkPicture* picture) {
- picture->draw(this);
+ APPEND(DrawPicture, picture);
}
void SkRecorder::drawVertices(VertexMode vmode,
diff --git a/src/core/SkRecorder.h b/src/core/SkRecorder.h
index 6eba19e5e7..437113829a 100644
--- a/src/core/SkRecorder.h
+++ b/src/core/SkRecorder.h
@@ -105,7 +105,7 @@ private:
T* copy(const T*);
template <typename T>
- T* copy(const T[], unsigned count);
+ T* copy(const T[], size_t count);
SkRecord* fRecord;
};
diff --git a/src/core/SkRecords.h b/src/core/SkRecords.h
index e6d98f7a1d..1de1675452 100644
--- a/src/core/SkRecords.h
+++ b/src/core/SkRecords.h
@@ -9,6 +9,24 @@
#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 {
@@ -46,6 +64,7 @@ namespace SkRecords {
M(DrawPaint) \
M(DrawPath) \
M(DrawPatch) \
+ M(DrawPicture) \
M(DrawPoints) \
M(DrawPosText) \
M(DrawPosTextH) \
@@ -219,6 +238,7 @@ RECORD2(DrawOval, SkPaint, paint, SkRect, oval);
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,
diff --git a/tests/RecorderTest.cpp b/tests/RecorderTest.cpp
index 5fcac4d93e..1ca9206b47 100644
--- a/tests/RecorderTest.cpp
+++ b/tests/RecorderTest.cpp
@@ -7,6 +7,7 @@
#include "Test.h"
+#include "SkPictureRecorder.h"
#include "SkRecord.h"
#include "SkRecorder.h"
#include "SkRecords.h"
@@ -67,3 +68,25 @@ DEF_TEST(Recorder_RefLeaking, r) {
}
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());
+}