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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/core/SkValueKeys.h ('k') | tests/ValueTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkArithmeticMode.h" 8 #include "SkArithmeticMode.h"
9 #include "SkData.h"
10 #include "SkImage.h"
9 #include "SkLerpXfermode.h" 11 #include "SkLerpXfermode.h"
10 #include "SkMatrix.h" 12 #include "SkMatrix.h"
11 #include "SkPixelXorXfermode.h" 13 #include "SkPixelXorXfermode.h"
12 #include "SkToFromValue.h" 14 #include "SkToFromValue.h"
13 #include "SkValueKeys.h" 15 #include "SkValueKeys.h"
14 #include "SkXfermode.h" 16 #include "SkXfermode.h"
15 17
16 //////////////////////////////////////////////////////////////////////////////// 18 ////////////////////////////////////////////////////////////////////////////////
17 19
18 #define REQUIRE(cond) do { if (!(cond)) { SkASSERT(false); return false; } } whi le (false) 20 #define REQUIRE(cond) do { if (!(cond)) { SkASSERT(false); return false; } } whi le (false)
(...skipping 15 matching lines...) Expand all
34 *x = val.s32(); 36 *x = val.s32();
35 return true; 37 return true;
36 } 38 }
37 39
38 template<> bool SkFromValue<uint32_t>(const SkValue& val, uint32_t* x) { 40 template<> bool SkFromValue<uint32_t>(const SkValue& val, uint32_t* x) {
39 REQUIRE(val.type() == SkValue::U32); 41 REQUIRE(val.type() == SkValue::U32);
40 *x = val.u32(); 42 *x = val.u32();
41 return true; 43 return true;
42 } 44 }
43 45
46 template<> bool SkFromValue<SkData*>(const SkValue& val, SkData** dst) {
47 REQUIRE(val.isData());
48 *dst = val.bytes(); // no ref taken
49 return true;
50 }
51
44 //////////////////////////////////////////////////////////////////////////////// 52 ////////////////////////////////////////////////////////////////////////////////
45 53
46 template<> SkValue SkToValue<SkMatrix>(const SkMatrix& mat) { 54 template<> SkValue SkToValue<SkMatrix>(const SkMatrix& mat) {
47 auto val = SkValue::Object(SkValue::Matrix); 55 auto val = SkValue::Object(SkValue::Matrix);
48 for (int i = 0; i < 9; ++i) { 56 for (int i = 0; i < 9; ++i) {
49 if (mat[i] != SkMatrix::I()[i]) { 57 if (mat[i] != SkMatrix::I()[i]) {
50 val.set(i, SkValue::FromF32(mat[i])); 58 val.set(i, SkValue::FromF32(mat[i]));
51 } 59 }
52 } 60 }
53 return val; 61 return val;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 case SkValue::ArithmeticXfermode: return from_value_ArithmeticXfermode(v al, dst); 128 case SkValue::ArithmeticXfermode: return from_value_ArithmeticXfermode(v al, dst);
121 case SkValue::LerpXfermode: return from_value_LerpXfermode(val, ds t); 129 case SkValue::LerpXfermode: return from_value_LerpXfermode(val, ds t);
122 case SkValue::PixelXorXfermode: return from_value_PixelXorXfermode(val , dst); 130 case SkValue::PixelXorXfermode: return from_value_PixelXorXfermode(val , dst);
123 case SkValue::ProcCoeffXfermode: return from_value_ProcCoeffXfermode(va l, dst); 131 case SkValue::ProcCoeffXfermode: return from_value_ProcCoeffXfermode(va l, dst);
124 default: REQUIRE(false); 132 default: REQUIRE(false);
125 } 133 }
126 } 134 }
127 135
128 //////////////////////////////////////////////////////////////////////////////// 136 ////////////////////////////////////////////////////////////////////////////////
129 137
138 template<> SkValue SkToValue<SkImage>(const SkImage* image) {
139 SkAutoTUnref<SkData> encoded(image->encode());
140 if (!encoded) {
141 return SkValue();
142 }
143 using namespace SkValueKeys::Image;
144 auto val = SkValue::Object(SkValue::Image);
145 val.set(kEncoded, SkValue::FromBytes(encoded));
146 val.set(kUniqueID, SkValue::FromU32(image->uniqueID()));
147 return val;
148 }
149
150 template<> bool SkFromValue< SkAutoTUnref<SkImage> >(
151 const SkValue& val, SkAutoTUnref<SkImage>* dst) {
152 REQUIRE(val.type() == SkValue::Image);
153 SkData* encoded;
154 REQUIRE(getT(val, SkValueKeys::Image::kEncoded, &encoded));
155 dst->reset(SkImage::NewFromEncoded(encoded));
156 return true;
157 }
158
159 ////////////////////////////////////////////////////////////////////////////////
160
130 #undef REQUIRE 161 #undef REQUIRE
131 162
OLDNEW
« 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