aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
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 /src
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 'src')
-rw-r--r--src/core/SkRecord.cpp10
-rw-r--r--src/core/SkRecord.h4
-rw-r--r--src/core/SkRecordOpts.cpp2
3 files changed, 16 insertions, 0 deletions
diff --git a/src/core/SkRecord.cpp b/src/core/SkRecord.cpp
index 2d2fa58991..2e03e993b8 100644
--- a/src/core/SkRecord.cpp
+++ b/src/core/SkRecord.cpp
@@ -6,6 +6,7 @@
*/
#include "SkRecord.h"
+#include <algorithm>
SkRecord::~SkRecord() {
Destroyer destroyer;
@@ -30,3 +31,12 @@ size_t SkRecord::bytesUsed() const {
}
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();
+}
diff --git a/src/core/SkRecord.h b/src/core/SkRecord.h
index ee10b15784..8901d62e91 100644
--- a/src/core/SkRecord.h
+++ b/src/core/SkRecord.h
@@ -111,6 +111,10 @@ public:
// 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:
diff --git a/src/core/SkRecordOpts.cpp b/src/core/SkRecordOpts.cpp
index 8faa45ce56..04c72c32cc 100644
--- a/src/core/SkRecordOpts.cpp
+++ b/src/core/SkRecordOpts.cpp
@@ -22,6 +22,8 @@ void SkRecordOptimize(SkRecord* record) {
SkRecordNoopSaveLayerDrawRestores(record);
SkRecordMergeSvgOpacityAndFilterLayers(record);
+
+ record->defrag();
}
// Most of the optimizations in this file are pattern-based. These are all defined as structs with: