*/
#include "SkRecord.h"
+#include <algorithm>
SkRecord::~SkRecord() {
Destroyer destroyer;
}
return bytes;
}
+
+void SkRecord::defrag() {
+ // Remove all the NoOps, preserving the order of other ops, e.g.
+ // Save, ClipRect, NoOp, DrawRect, NoOp, NoOp, Restore
+ // -> Save, ClipRect, DrawRect, Restore
+ Record* noops = std::remove_if(fRecords.get(), fRecords.get() + fCount,
+ [](Record op) { return op.type() == SkRecords::NoOp_Type; });
+ fCount = noops - fRecords.get();
+}
// need to iterate with a visitor to measure those they care for.
size_t bytesUsed() const;
+ // Rearrange and resize this record to eliminate any NoOps.
+ // May change count() and the indices of ops, but preserves their order.
+ void defrag();
+
private:
// An SkRecord is structured as an array of pointers into a big chunk of memory where
// records representing each canvas draw call are stored:
* 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 {
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>