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

Unified Diff: src/effects/SkToFromValue.cpp

Issue 1613053006: SkValue: to/from SkImage (Closed) Base URL: https://skia.googlesource.com/skia.git@skvalue_xfermode2
Patch Set: 2016-01-21 (Thursday) 17:20:39 EST Created 4 years, 11 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 | « src/core/SkValueKeys.h ('k') | tests/ValueTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « src/core/SkValueKeys.h ('k') | tests/ValueTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698