Index: src/effects/SkToFromValue.cpp |
diff --git a/src/effects/SkToFromValue.cpp b/src/effects/SkToFromValue.cpp |
index b981d1715ee4d475f9b90363cdb10a301e0e74cb..15a67472ef838b16f26662fbcff29fd26ae2f2f0 100644 |
--- a/src/effects/SkToFromValue.cpp |
+++ b/src/effects/SkToFromValue.cpp |
@@ -6,6 +6,8 @@ |
*/ |
#include "SkArithmeticMode.h" |
+#include "SkData.h" |
+#include "SkImage.h" |
#include "SkLerpXfermode.h" |
#include "SkMatrix.h" |
#include "SkPixelXorXfermode.h" |
@@ -41,6 +43,12 @@ template<> bool SkFromValue<uint32_t>(const SkValue& val, uint32_t* x) { |
return true; |
} |
+template<> bool SkFromValue<SkData*>(const SkValue& val, SkData** dst) { |
+ REQUIRE(val.isData()); |
+ *dst = val.bytes(); // no ref taken |
+ return true; |
+} |
+ |
//////////////////////////////////////////////////////////////////////////////// |
template<> SkValue SkToValue<SkMatrix>(const SkMatrix& mat) { |
@@ -127,5 +135,28 @@ template<> bool SkFromValue< SkAutoTUnref<SkXfermode> >( |
//////////////////////////////////////////////////////////////////////////////// |
+template<> SkValue SkToValue<SkImage>(const SkImage* image) { |
+ SkAutoTUnref<SkData> encoded(image->encode()); |
+ if (!encoded) { |
+ return SkValue(); |
+ } |
+ using namespace SkValueKeys::Image; |
+ auto val = SkValue::Object(SkValue::Image); |
+ val.set(kEncoded, SkValue::FromBytes(encoded)); |
+ val.set(kUniqueID, SkValue::FromU32(image->uniqueID())); |
+ return val; |
+} |
+ |
+template<> bool SkFromValue< SkAutoTUnref<SkImage> >( |
+ const SkValue& val, SkAutoTUnref<SkImage>* dst) { |
+ REQUIRE(val.type() == SkValue::Image); |
+ SkData* encoded; |
+ REQUIRE(getT(val, SkValueKeys::Image::kEncoded, &encoded)); |
+ dst->reset(SkImage::NewFromEncoded(encoded)); |
+ return true; |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+ |
#undef REQUIRE |