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

Side by Side Diff: src/core/SkValue.cpp

Issue 1585813004: SkValue: SkXfermode (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: space 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') | src/core/SkValueKeys.h » ('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 <unordered_map> 8 #include <unordered_map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "SkData.h" 11 #include "SkData.h"
12 #include "SkMatrix.h"
13 #include "SkValue.h" 12 #include "SkValue.h"
14 13
15 class SkValue::Obj { 14 class SkValue::Obj {
16 public: 15 public:
17 void set(SkValue::Key k, SkValue&& v) { fMap[k] = std::move(v); } 16 void set(SkValue::Key k, SkValue&& v) { fMap[k] = std::move(v); }
18 const SkValue* get(SkValue::Key k) const { 17 const SkValue* get(SkValue::Key k) const {
19 auto it = fMap.find(k); 18 auto it = fMap.find(k);
20 return it != fMap.end() ? &it->second : nullptr; 19 return it != fMap.end() ? &it->second : nullptr;
21 } 20 }
22 void foreach(std::function<void(Key, const SkValue&)> fn) const { 21 void foreach(std::function<void(Key, const SkValue&)> fn) const {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 SkValue val(type); 176 SkValue val(type);
178 val.fBytes = SkRef(data); 177 val.fBytes = SkRef(data);
179 SkASSERT(val.isData()); 178 SkASSERT(val.isData());
180 SkASSERT(0 == (reinterpret_cast<uintptr_t>(data->bytes()) & (sizeof(T)-1))); 179 SkASSERT(0 == (reinterpret_cast<uintptr_t>(data->bytes()) & (sizeof(T)-1)));
181 return val; 180 return val;
182 } 181 }
183 182
184 SkValue SkValue::FromU16s(SkData* d) { return FromTs<uint16_t>(U16s, d); } 183 SkValue SkValue::FromU16s(SkData* d) { return FromTs<uint16_t>(U16s, d); }
185 SkValue SkValue::FromU32s(SkData* d) { return FromTs<uint32_t>(U32s, d); } 184 SkValue SkValue::FromU32s(SkData* d) { return FromTs<uint32_t>(U32s, d); }
186 SkValue SkValue::FromF32s(SkData* d) { return FromTs< float>(F32s, d); } 185 SkValue SkValue::FromF32s(SkData* d) { return FromTs< float>(F32s, d); }
187
188 ////////////////////////////////////////////////////////////////////////////////
189
190 #define REQUIRE(cond) do { if (!(cond)) { SkASSERT(false); return false; } } whi le (false)
191
192 template<> SkValue SkToValue<SkMatrix>(const SkMatrix& mat) {
193 auto val = SkValue::Object(SkValue::Matrix);
194 for (int i = 0; i < 9; ++i) {
195 if (mat[i] != SkMatrix::I()[i]) {
196 val.set(i, SkValue::FromF32(mat[i]));
197 }
198 }
199 return val;
200 }
201
202 template<> bool SkFromValue<float>(const SkValue& val, float* f) {
203 REQUIRE(val.type() == SkValue::F32);
204 *f = val.f32();
205 return true;
206 }
207
208 template<> bool SkFromValue<SkMatrix>(const SkValue& val, SkMatrix* m){
209 REQUIRE(val.type() == SkValue::Matrix);
210
211 *m = SkMatrix::I();
212 for (int i = 0; i < 9; i++) {
213 if (auto v = val.get(i)) {
214 REQUIRE(SkFromValue(*v, &(*m)[i]));
215 }
216 }
217 return true;
218 }
219
220 #undef REQUIRE
OLDNEW
« no previous file with comments | « src/core/SkValue.h ('k') | src/core/SkValueKeys.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698