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

Unified Diff: src/core/SkXfermode.cpp

Issue 395603002: Simplify flattening to just write enough to call the factory (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 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
Index: src/core/SkXfermode.cpp
diff --git a/src/core/SkXfermode.cpp b/src/core/SkXfermode.cpp
index 0811808d46c3e72813b4c972337b4d662dcf0cee..501c19227626a07ce8f0e8df5ffb4e3502b987c8 100644
--- a/src/core/SkXfermode.cpp
+++ b/src/core/SkXfermode.cpp
@@ -1240,6 +1240,7 @@ GrEffect* XferEffect::TestCreate(SkRandom* rand,
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
+#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
SkProcCoeffXfermode::SkProcCoeffXfermode(SkReadBuffer& buffer) : INHERITED(buffer) {
uint32_t mode32 = buffer.read32() % SK_ARRAY_COUNT(gProcCoeffs);
if (mode32 >= SK_ARRAY_COUNT(gProcCoeffs)) {
@@ -1254,6 +1255,19 @@ SkProcCoeffXfermode::SkProcCoeffXfermode(SkReadBuffer& buffer) : INHERITED(buffe
fSrcCoeff = rec.fSC;
fDstCoeff = rec.fDC;
}
+#endif
+
+SkFlattenable* SkProcCoeffXfermode::CreateProc(SkReadBuffer& buffer) {
+ uint32_t mode32 = buffer.read32();
+ if (!buffer.validate(mode32 >= SK_ARRAY_COUNT(gProcCoeffs))) {
+ return NULL;
+ }
+ return SkXfermode::Create((SkXfermode::Mode)mode32);
+}
+
+void SkProcCoeffXfermode::flatten(SkWriteBuffer& buffer) const {
+ buffer.write32(fMode);
+}
bool SkProcCoeffXfermode::asMode(Mode* mode) const {
if (mode) {
@@ -1376,11 +1390,6 @@ bool SkProcCoeffXfermode::asNewEffect(GrEffect** effect, GrTexture* background)
}
#endif
-void SkProcCoeffXfermode::flatten(SkWriteBuffer& buffer) const {
- this->INHERITED::flatten(buffer);
- buffer.write32(fMode);
-}
-
const char* SkXfermode::ModeName(Mode mode) {
SkASSERT((unsigned) mode <= (unsigned)kLastMode);
const char* gModeStrings[] = {
@@ -1437,12 +1446,18 @@ public:
private:
SkClearXfermode(const ProcCoeff& rec) : SkProcCoeffXfermode(rec, kClear_Mode) {}
- SkClearXfermode(SkReadBuffer& buffer)
- : SkProcCoeffXfermode(buffer) {}
+#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
+ SkClearXfermode(SkReadBuffer& buffer) : SkProcCoeffXfermode(buffer) {}
+#endif
+ virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE {}
typedef SkProcCoeffXfermode INHERITED;
};
+SkFlattenable* SkClearXfermode::CreateProc(SkReadBuffer& buffer) {
+ return SkXfermode::Create(kClear_Mode);
+}
+
void SkClearXfermode::xfer32(SkPMColor* SK_RESTRICT dst,
const SkPMColor* SK_RESTRICT, int count,
const SkAlpha* SK_RESTRICT aa) const {
@@ -1502,12 +1517,18 @@ public:
private:
SkSrcXfermode(const ProcCoeff& rec) : SkProcCoeffXfermode(rec, kSrc_Mode) {}
- SkSrcXfermode(SkReadBuffer& buffer)
- : SkProcCoeffXfermode(buffer) {}
+#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
+ SkSrcXfermode(SkReadBuffer& buffer) : SkProcCoeffXfermode(buffer) {}
+#endif
+ virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE {}
typedef SkProcCoeffXfermode INHERITED;
};
+SkFlattenable* SkSrcXfermode::CreateProc(SkReadBuffer& buffer) {
+ return SkXfermode::Create(kSrc_Mode);
+}
+
void SkSrcXfermode::xfer32(SkPMColor* SK_RESTRICT dst,
const SkPMColor* SK_RESTRICT src, int count,
const SkAlpha* SK_RESTRICT aa) const {
@@ -1571,11 +1592,18 @@ public:
private:
SkDstInXfermode(const ProcCoeff& rec) : SkProcCoeffXfermode(rec, kDstIn_Mode) {}
+#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
SkDstInXfermode(SkReadBuffer& buffer) : INHERITED(buffer) {}
+#endif
+ virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE {}
typedef SkProcCoeffXfermode INHERITED;
};
+SkFlattenable* SkDstInXfermode::CreateProc(SkReadBuffer&) {
+ return SkXfermode::Create(kDstIn_Mode);
+}
+
void SkDstInXfermode::xfer32(SkPMColor* SK_RESTRICT dst,
const SkPMColor* SK_RESTRICT src, int count,
const SkAlpha* SK_RESTRICT aa) const {
@@ -1617,12 +1645,18 @@ public:
private:
SkDstOutXfermode(const ProcCoeff& rec) : SkProcCoeffXfermode(rec, kDstOut_Mode) {}
- SkDstOutXfermode(SkReadBuffer& buffer)
- : INHERITED(buffer) {}
+#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
+ SkDstOutXfermode(SkReadBuffer& buffer) : INHERITED(buffer) {}
+#endif
+ virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE {}
typedef SkProcCoeffXfermode INHERITED;
};
+SkFlattenable* SkDstOutXfermode::CreateProc(SkReadBuffer&) {
+ return SkXfermode::Create(kDstOut_Mode);
+}
+
void SkDstOutXfermode::xfer32(SkPMColor* SK_RESTRICT dst,
const SkPMColor* SK_RESTRICT src, int count,
const SkAlpha* SK_RESTRICT aa) const {
@@ -1692,7 +1726,7 @@ SkXfermode* create_mode(int iMode) {
break;
default:
// no special-case, just rely in the rec and its function-ptrs
- xfer = SkProcCoeffXfermode::Create(rec, mode);
+ xfer = SkNEW_ARGS(SkProcCoeffXfermode, (rec, mode));
break;
}
}

Powered by Google App Engine
This is Rietveld 408576698