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

Side by Side Diff: src/gpu/GrColorSpaceXform.cpp

Issue 2185533005: Simplify color space xform storage and usage (float[] vs. SkMatrix44) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add comment Created 4 years, 4 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 | « include/gpu/GrColorSpaceXform.h ('k') | src/gpu/effects/GrBicubicEffect.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 "GrColorSpaceXform.h" 8 #include "GrColorSpaceXform.h"
9 #include "SkColorSpace.h" 9 #include "SkColorSpace.h"
10 #include "SkMatrix44.h"
10 11
11 static inline bool sk_float_almost_equals(float x, float y, float tol) { 12 static inline bool sk_float_almost_equals(float x, float y, float tol) {
12 return sk_float_abs(x - y) <= tol; 13 return sk_float_abs(x - y) <= tol;
13 } 14 }
14 15
15 static inline bool matrix_is_almost_identity(const SkMatrix44& m, 16 static inline bool matrix_is_almost_identity(const SkMatrix44& m,
16 SkMScalar tol = SK_MScalar1 / (1 << 12)) { 17 SkMScalar tol = SK_MScalar1 / (1 << 12)) {
17 return 18 return
18 sk_float_almost_equals(m.getFloat(0, 0), 1.0f, tol) && 19 sk_float_almost_equals(m.getFloat(0, 0), 1.0f, tol) &&
19 sk_float_almost_equals(m.getFloat(0, 1), 0.0f, tol) && 20 sk_float_almost_equals(m.getFloat(0, 1), 0.0f, tol) &&
20 sk_float_almost_equals(m.getFloat(0, 2), 0.0f, tol) && 21 sk_float_almost_equals(m.getFloat(0, 2), 0.0f, tol) &&
21 sk_float_almost_equals(m.getFloat(0, 3), 0.0f, tol) && 22 sk_float_almost_equals(m.getFloat(0, 3), 0.0f, tol) &&
22 sk_float_almost_equals(m.getFloat(1, 0), 0.0f, tol) && 23 sk_float_almost_equals(m.getFloat(1, 0), 0.0f, tol) &&
23 sk_float_almost_equals(m.getFloat(1, 1), 1.0f, tol) && 24 sk_float_almost_equals(m.getFloat(1, 1), 1.0f, tol) &&
24 sk_float_almost_equals(m.getFloat(1, 2), 0.0f, tol) && 25 sk_float_almost_equals(m.getFloat(1, 2), 0.0f, tol) &&
25 sk_float_almost_equals(m.getFloat(1, 3), 0.0f, tol) && 26 sk_float_almost_equals(m.getFloat(1, 3), 0.0f, tol) &&
26 sk_float_almost_equals(m.getFloat(2, 0), 0.0f, tol) && 27 sk_float_almost_equals(m.getFloat(2, 0), 0.0f, tol) &&
27 sk_float_almost_equals(m.getFloat(2, 1), 0.0f, tol) && 28 sk_float_almost_equals(m.getFloat(2, 1), 0.0f, tol) &&
28 sk_float_almost_equals(m.getFloat(2, 2), 1.0f, tol) && 29 sk_float_almost_equals(m.getFloat(2, 2), 1.0f, tol) &&
29 sk_float_almost_equals(m.getFloat(2, 3), 0.0f, tol) && 30 sk_float_almost_equals(m.getFloat(2, 3), 0.0f, tol) &&
30 sk_float_almost_equals(m.getFloat(3, 0), 0.0f, tol) && 31 sk_float_almost_equals(m.getFloat(3, 0), 0.0f, tol) &&
31 sk_float_almost_equals(m.getFloat(3, 1), 0.0f, tol) && 32 sk_float_almost_equals(m.getFloat(3, 1), 0.0f, tol) &&
32 sk_float_almost_equals(m.getFloat(3, 2), 0.0f, tol) && 33 sk_float_almost_equals(m.getFloat(3, 2), 0.0f, tol) &&
33 sk_float_almost_equals(m.getFloat(3, 3), 1.0f, tol); 34 sk_float_almost_equals(m.getFloat(3, 3), 1.0f, tol);
34 } 35 }
35 36
37 GrColorSpaceXform::GrColorSpaceXform(const SkMatrix44& srcToDst) {
38 srcToDst.asColMajorf(fSrcToDst);
39 }
40
36 sk_sp<GrColorSpaceXform> GrColorSpaceXform::Make(SkColorSpace* src, SkColorSpace * dst) { 41 sk_sp<GrColorSpaceXform> GrColorSpaceXform::Make(SkColorSpace* src, SkColorSpace * dst) {
37 if (!src || !dst) { 42 if (!src || !dst) {
38 // Invalid 43 // Invalid
39 return nullptr; 44 return nullptr;
40 } 45 }
41 46
42 if (src == dst) { 47 if (src == dst) {
43 // Quick equality check - no conversion needed in this case 48 // Quick equality check - no conversion needed in this case
44 return nullptr; 49 return nullptr;
45 } 50 }
46 51
47 SkMatrix44 srcToDst(SkMatrix44::kUninitialized_Constructor); 52 SkMatrix44 srcToDst(SkMatrix44::kUninitialized_Constructor);
48 if (!dst->xyz().invert(&srcToDst)) { 53 if (!dst->xyz().invert(&srcToDst)) {
49 return nullptr; 54 return nullptr;
50 } 55 }
51 srcToDst.postConcat(src->xyz()); 56 srcToDst.postConcat(src->xyz());
52 57
53 if (matrix_is_almost_identity(srcToDst)) { 58 if (matrix_is_almost_identity(srcToDst)) {
54 return nullptr; 59 return nullptr;
55 } 60 }
56 61
57 return sk_make_sp<GrColorSpaceXform>(srcToDst); 62 return sk_make_sp<GrColorSpaceXform>(srcToDst);
58 } 63 }
OLDNEW
« no previous file with comments | « include/gpu/GrColorSpaceXform.h ('k') | src/gpu/effects/GrBicubicEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698