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

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: 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/SkValue.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.type() == SkValue::Bytes
mtklein 2016/01/21 21:21:30 Guess we'd better put isData() out in public for n
hal.canary 2016/01/21 22:03:23 done
48 || val.type() == SkValue::U16s
49 || val.type() == SkValue::U32s
50 || val.type() == SkValue::F32s);
51 *dst = val.bytes(); // no ref taken
52 return true;
53 }
54
44 //////////////////////////////////////////////////////////////////////////////// 55 ////////////////////////////////////////////////////////////////////////////////
45 56
46 template<> SkValue SkToValue<SkMatrix>(const SkMatrix& mat) { 57 template<> SkValue SkToValue<SkMatrix>(const SkMatrix& mat) {
47 auto val = SkValue::Object(SkValue::Matrix); 58 auto val = SkValue::Object(SkValue::Matrix);
48 for (int i = 0; i < 9; ++i) { 59 for (int i = 0; i < 9; ++i) {
49 if (mat[i] != SkMatrix::I()[i]) { 60 if (mat[i] != SkMatrix::I()[i]) {
50 val.set(i, SkValue::FromF32(mat[i])); 61 val.set(i, SkValue::FromF32(mat[i]));
51 } 62 }
52 } 63 }
53 return val; 64 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); 131 case SkValue::ArithmeticXfermode: return from_value_ArithmeticXfermode(v al, dst);
121 case SkValue::LerpXfermode: return from_value_LerpXfermode(val, ds t); 132 case SkValue::LerpXfermode: return from_value_LerpXfermode(val, ds t);
122 case SkValue::PixelXorXfermode: return from_value_PixelXorXfermode(val , dst); 133 case SkValue::PixelXorXfermode: return from_value_PixelXorXfermode(val , dst);
123 case SkValue::ProcCoeffXfermode: return from_value_ProcCoeffXfermode(va l, dst); 134 case SkValue::ProcCoeffXfermode: return from_value_ProcCoeffXfermode(va l, dst);
124 default: REQUIRE(false); 135 default: REQUIRE(false);
125 } 136 }
126 } 137 }
127 138
128 //////////////////////////////////////////////////////////////////////////////// 139 ////////////////////////////////////////////////////////////////////////////////
129 140
141 enum { kEncoded, kUniqueID }; // SkValue::Image
mtklein 2016/01/21 21:21:29 ?
hal.canary 2016/01/21 22:03:23 moved.
142
143 template<> SkValue SkToValue<SkImage>(const SkImage* image) {
144 SkAutoTUnref<SkData> encoded(image->encode());
mtklein 2016/01/22 14:09:18 you know, this is probably the most controversial
145 if (!encoded || 0 == encoded->size()) {
mtklein 2016/01/21 21:21:30 why 0 == encoded->size()?
hal.canary 2016/01/21 22:03:23 removed.
146 return SkValue();
147 }
148 auto val = SkValue::Object(SkValue::Image);
149 val.set(kEncoded, SkValue::FromBytes(encoded));
150 val.set(kUniqueID, SkValue::FromU32(image->uniqueID()));
mtklein 2016/01/21 21:21:30 This seems like a bad idea, especially if we ignor
hal.canary 2016/01/21 22:03:23 a serializer can use them to de-dup images. Or an
mtklein 2016/01/22 14:09:18 this unique ID is not part of the value of the ima
151 return val;
152 }
153
154 template<> bool SkFromValue< SkAutoTUnref<SkImage> >(
mtklein 2016/01/21 21:21:30 template<> bool SkFromValue<SkAutoTUnref<SkImage>>
hal.canary 2016/01/21 22:03:23 yes but my *editor* doesn't know about how C++11 a
mtklein 2016/01/22 14:09:18 are you seriously proposing that we write code str
155 const SkValue& val, SkAutoTUnref<SkImage>* dst) {
156 REQUIRE(val.type() == SkValue::Image);
157 SkData* encoded;
158 REQUIRE(getT(val, kEncoded, &encoded));
159 dst->reset(SkImage::NewFromEncoded(encoded));
160 return true;
161 }
162
163 ////////////////////////////////////////////////////////////////////////////////
164
130 #undef REQUIRE 165 #undef REQUIRE
131 166
OLDNEW
« no previous file with comments | « src/core/SkValue.h ('k') | tests/ValueTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698