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

Unified Diff: src/core/SkImageFilter.cpp

Issue 395273002: factor out flattening/unflattening of common fields from SkImageFilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use SkAutoSTarray Created 6 years, 5 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 | « include/core/SkImageFilter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkImageFilter.cpp
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index 8a0e734b245fd7562c4d6135d8cce9e8a308be3c..3eb688e2c74d9848cfdd5a0028ecf159db7edfa7 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -21,6 +21,55 @@
#include "SkGr.h"
#endif
+SkImageFilter::Common::~Common() {
+ for (int i = 0; i < fInputs.count(); ++i) {
+ SkSafeUnref(fInputs[i]);
+ }
+}
+
+void SkImageFilter::Common::allocInputs(int count) {
+ const size_t size = count * sizeof(SkImageFilter*);
+ fInputs.reset(count);
+ sk_bzero(fInputs.get(), size);
+}
+
+void SkImageFilter::Common::detachInputs(SkImageFilter** inputs) {
+ const size_t size = fInputs.count() * sizeof(SkImageFilter*);
+ memcpy(inputs, fInputs.get(), size);
+ sk_bzero(fInputs.get(), size);
+}
+
+bool SkImageFilter::Common::unflatten(SkReadBuffer& buffer, int expectedCount) {
+ int count = buffer.readInt();
Stephen White 2014/07/18 15:14:55 I think we should bail if the count is negative he
+ if (expectedCount < 0) { // means the caller doesn't care how many
+ expectedCount = count;
+ }
+ if (!buffer.validate(count == expectedCount)) {
+ return false;
+ }
+
+ this->allocInputs(count);
+ for (int i = 0; i < count; i++) {
+ if (buffer.readBool()) {
+ fInputs[i] = buffer.readImageFilter();
+ }
+ if (!buffer.isValid()) {
+ return false;
+ }
+ }
+ SkRect rect;
+ buffer.readRect(&rect);
+ if (!buffer.isValid() || !buffer.validate(SkIsValidRect(rect))) {
+ return false;
+ }
+
+ uint32_t flags = buffer.readUInt();
+ fCropRect = CropRect(rect, flags);
+ return buffer.isValid();
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
SkImageFilter::Cache* gExternalCache;
SkImageFilter::SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRect)
@@ -41,26 +90,12 @@ SkImageFilter::~SkImageFilter() {
}
SkImageFilter::SkImageFilter(int inputCount, SkReadBuffer& buffer) {
- fInputCount = buffer.readInt();
- if (buffer.validate((fInputCount >= 0) && ((inputCount < 0) || (fInputCount == inputCount)))) {
- fInputs = new SkImageFilter*[fInputCount];
- for (int i = 0; i < fInputCount; i++) {
- if (buffer.readBool()) {
- fInputs[i] = buffer.readImageFilter();
- } else {
- fInputs[i] = NULL;
- }
- if (!buffer.isValid()) {
- fInputCount = i; // Do not use fInputs past that point in the destructor
- break;
- }
- }
- SkRect rect;
- buffer.readRect(&rect);
- if (buffer.isValid() && buffer.validate(SkIsValidRect(rect))) {
- uint32_t flags = buffer.readUInt();
- fCropRect = CropRect(rect, flags);
- }
+ Common common;
+ if (common.unflatten(buffer, inputCount)) {
+ fCropRect = common.cropRect();
+ fInputCount = common.inputCount();
+ fInputs = SkNEW_ARRAY(SkImageFilter*, fInputCount);
+ common.detachInputs(fInputs);
} else {
fInputCount = 0;
fInputs = NULL;
« no previous file with comments | « include/core/SkImageFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698