Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1763)

Unified Diff: tests/RecordTest.cpp

Issue 228723003: Start on some unwritten SkRecord TODOs: (Closed) Base URL: https://skia.googlesource.com/skia.git@record-culling
Patch Set: rebase Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/record/SkRecorder.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/RecordTest.cpp
diff --git a/tests/RecordTest.cpp b/tests/RecordTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..1214b1a5de78d461ad31ecc410887b3680704c62
--- /dev/null
+++ b/tests/RecordTest.cpp
@@ -0,0 +1,48 @@
+#include "Test.h"
+
+#include "SkRecord.h"
+#include "SkRecords.h"
+
+// Adds the area of any DrawRect command it sees into area.
+class AreaSummer {
+public:
+ explicit AreaSummer(int* area) : fArea(area) {}
+
+ template <typename T> void operator()(const T&) { }
+
+private:
+ int* fArea;
+};
+template <> void AreaSummer::operator()(const SkRecords::DrawRect& record) {
+ *fArea += (int) (record.rect.width() * record.rect.height());
+}
+
+// Scales out the bottom-right corner of any DrawRect command it sees by 2x.
+struct Stretch {
+ template <typename T> void operator()(T*) {}
+};
+template <> void Stretch::operator()(SkRecords::DrawRect* record) {
+ record->rect.fRight *= 2;
+ record->rect.fBottom *= 2;
+}
+
+// Basic tests for the low-level SkRecord code.
+DEF_TEST(Record, r) {
+ SkRecord record;
+
+ // Add a simple DrawRect command.
+ SkRect rect = SkRect::MakeWH(10, 10);
+ SkPaint paint;
+ SkNEW_PLACEMENT_ARGS(record.append<SkRecords::DrawRect>(), SkRecords::DrawRect, (rect, paint));
+
+ // Its area should be 100.
+ int area = 0;
+ record.visit(AreaSummer(&area));
+ REPORTER_ASSERT(r, area == 100);
+
+ // Scale 2x. Now it's area should be 400.
+ record.mutate(Stretch());
+ area = 0;
+ record.visit(AreaSummer(&area));
+ REPORTER_ASSERT(r, area == 400);
+}
« no previous file with comments | « src/record/SkRecorder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698