aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/RecordTest.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-11-19 07:23:49 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-11-19 07:23:49 -0800
commitc3c6194ba2b90fde57d8d0bc1d6302656f0dae27 (patch)
tree52446ca72e146435b47a63afd39f4d15f0d0c474 /tests/RecordTest.cpp
parenta2e3e0f7f8ceed2ab152428d7ee2812ad8c842c3 (diff)
Add SkRecord::defrag().
Called by SkRecordOptimize(), this moves all the NoOps to the end and slices them off. This implementation with std::remove_if() is linear and doesn't malloc. No diffs: https://gold.skia.org/search2?issue=1461663003&unt=true&query=source_type%3Dgm&master=false BUG=skia: Review URL: https://codereview.chromium.org/1461663003
Diffstat (limited to 'tests/RecordTest.cpp')
-rw-r--r--tests/RecordTest.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/tests/RecordTest.cpp b/tests/RecordTest.cpp
index 9e02c882db..e613b425fd 100644
--- a/tests/RecordTest.cpp
+++ b/tests/RecordTest.cpp
@@ -5,13 +5,14 @@
* found in the LICENSE file.
*/
-#include "Test.h"
-
+#include "RecordTestUtils.h"
#include "SkBitmap.h"
#include "SkImageInfo.h"
-#include "SkShader.h"
#include "SkRecord.h"
#include "SkRecords.h"
+#include "SkShader.h"
+#include "Test.h"
+
// Sums the area of any DrawRect command it sees.
class AreaSummer {
@@ -76,6 +77,25 @@ DEF_TEST(Record, r) {
REPORTER_ASSERT(r, summer.area() == 500);
}
+DEF_TEST(Record_defrag, r) {
+ SkRecord record;
+ APPEND(record, SkRecords::Save);
+ APPEND(record, SkRecords::ClipRect);
+ APPEND(record, SkRecords::NoOp);
+ APPEND(record, SkRecords::DrawRect);
+ APPEND(record, SkRecords::NoOp);
+ APPEND(record, SkRecords::NoOp);
+ APPEND(record, SkRecords::Restore);
+ REPORTER_ASSERT(r, record.count() == 7);
+
+ record.defrag();
+ REPORTER_ASSERT(r, record.count() == 4);
+ assert_type<SkRecords::Save >(r, record, 0);
+ assert_type<SkRecords::ClipRect>(r, record, 1);
+ assert_type<SkRecords::DrawRect>(r, record, 2);
+ assert_type<SkRecords::Restore >(r, record, 3);
+}
+
#undef APPEND
template <typename T>