aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-08-22 11:44:26 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-08-22 11:44:26 -0700
commit5f0e82204ecca0805a7689cdba5f802458e103f4 (patch)
tree2343461173da35e4df8ec89d362e870b513bc8b7
parent3e42a4638559d71481ba598857f2d0c715c8d4b3 (diff)
Support comment groups in SkRecord.
This should fix the failing paint-command-log-nodes.html layout test. BUG=406425 R=tomhudson@chromium.org Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/501533003
-rw-r--r--src/core/SkRecordDraw.cpp4
-rw-r--r--src/core/SkRecorder.cpp19
-rw-r--r--src/core/SkRecorder.h4
-rw-r--r--src/core/SkRecords.h8
-rw-r--r--tests/RecorderTest.cpp19
5 files changed, 54 insertions, 0 deletions
diff --git a/src/core/SkRecordDraw.cpp b/src/core/SkRecordDraw.cpp
index 5dd2ba3296..1101fb424d 100644
--- a/src/core/SkRecordDraw.cpp
+++ b/src/core/SkRecordDraw.cpp
@@ -71,6 +71,10 @@ DRAW(ClipRRect, clipRRect(r.rrect, r.op, r.doAA));
DRAW(ClipRect, clipRect(r.rect, r.op, r.doAA));
DRAW(ClipRegion, clipRegion(r.region, r.op));
+DRAW(BeginCommentGroup, beginCommentGroup(r.description));
+DRAW(AddComment, addComment(r.key, r.value));
+DRAW(EndCommentGroup, endCommentGroup());
+
DRAW(DrawBitmap, drawBitmap(shallow_copy(r.bitmap), r.left, r.top, r.paint));
DRAW(DrawBitmapMatrix, drawBitmapMatrix(shallow_copy(r.bitmap), r.matrix, r.paint));
DRAW(DrawBitmapNine, drawBitmapNine(shallow_copy(r.bitmap), r.center, r.dst, r.paint));
diff --git a/src/core/SkRecorder.cpp b/src/core/SkRecorder.cpp
index 2e14c3e25d..df3e1d8fa5 100644
--- a/src/core/SkRecorder.cpp
+++ b/src/core/SkRecorder.cpp
@@ -82,6 +82,13 @@ char* SkRecorder::copy(const char src[], size_t count) {
return dst;
}
+// As above, assuming and copying a terminating \0.
+template <>
+char* SkRecorder::copy(const char* src) {
+ return this->copy(src, strlen(src)+1);
+}
+
+
void SkRecorder::clear(SkColor color) {
APPEND(Clear, color);
}
@@ -276,3 +283,15 @@ void SkRecorder::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
INHERITED(onClipRegion, deviceRgn, op);
APPEND(ClipRegion, this->devBounds(), delay_copy(deviceRgn), op);
}
+
+void SkRecorder::beginCommentGroup(const char* description) {
+ APPEND(BeginCommentGroup, this->copy(description));
+}
+
+void SkRecorder::addComment(const char* key, const char* value) {
+ APPEND(AddComment, this->copy(key), this->copy(value));
+}
+
+void SkRecorder::endCommentGroup() {
+ APPEND(EndCommentGroup);
+}
diff --git a/src/core/SkRecorder.h b/src/core/SkRecorder.h
index 8b1430d533..23ecdf6aab 100644
--- a/src/core/SkRecorder.h
+++ b/src/core/SkRecorder.h
@@ -107,6 +107,10 @@ public:
void onPushCull(const SkRect& cullRect) SK_OVERRIDE;
void onPopCull() SK_OVERRIDE;
+ void beginCommentGroup(const char*) SK_OVERRIDE;
+ void addComment(const char*, const char*) SK_OVERRIDE;
+ void endCommentGroup() SK_OVERRIDE;
+
private:
template <typename T>
T* copy(const T*);
diff --git a/src/core/SkRecords.h b/src/core/SkRecords.h
index f3d96d4aa9..f216897dca 100644
--- a/src/core/SkRecords.h
+++ b/src/core/SkRecords.h
@@ -37,6 +37,9 @@ namespace SkRecords {
M(ClipRect) \
M(ClipRegion) \
M(Clear) \
+ M(BeginCommentGroup) \
+ M(AddComment) \
+ M(EndCommentGroup) \
M(DrawBitmap) \
M(DrawBitmapMatrix) \
M(DrawBitmapNine) \
@@ -211,6 +214,11 @@ RECORD4(ClipRect, SkIRect, devBounds, SkRect, rect, SkRegion::Op, op, bool
RECORD3(ClipRegion, SkIRect, devBounds, SkRegion, region, SkRegion::Op, op);
RECORD1(Clear, SkColor, color);
+
+RECORD1(BeginCommentGroup, PODArray<char>, description);
+RECORD2(AddComment, PODArray<char>, key, PODArray<char>, value);
+RECORD0(EndCommentGroup);
+
// While not strictly required, if you have an SkPaint, it's fastest to put it first.
RECORD4(DrawBitmap, Optional<SkPaint>, paint,
ImmutableBitmap, bitmap,
diff --git a/tests/RecorderTest.cpp b/tests/RecorderTest.cpp
index 1ca9206b47..21a897ca8b 100644
--- a/tests/RecorderTest.cpp
+++ b/tests/RecorderTest.cpp
@@ -49,6 +49,25 @@ DEF_TEST(Recorder, r) {
REPORTER_ASSERT(r, 1 == tally.count<SkRecords::DrawRect>());
}
+// All of Skia will work fine without support for comment groups, but
+// Chrome's inspector can break. This serves as a simple regression test.
+DEF_TEST(Recorder_CommentGroups, r) {
+ SkRecord record;
+ SkRecorder recorder(&record, 1920, 1080);
+
+ recorder.beginCommentGroup("test");
+ recorder.addComment("foo", "bar");
+ recorder.addComment("baz", "quux");
+ recorder.endCommentGroup();
+
+ Tally tally;
+ tally.apply(record);
+
+ REPORTER_ASSERT(r, 1 == tally.count<SkRecords::BeginCommentGroup>());
+ REPORTER_ASSERT(r, 2 == tally.count<SkRecords::AddComment>());
+ REPORTER_ASSERT(r, 1 == tally.count<SkRecords::EndCommentGroup>());
+}
+
// Regression test for leaking refs held by optional arguments.
DEF_TEST(Recorder_RefLeaking, r) {
// We use SaveLayer to test: