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

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

Issue 2323003002: Cache the inverse matrix on SkColorSpace. Rename xyz() to toXYZ(). (Closed)
Patch Set: Remove xyz() again Created 4 years, 3 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/SkColorSpace_Base.h ('k') | tests/ColorSpaceTest.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 "SkColorSpace_Base.h"
10 #include "SkMatrix44.h" 11 #include "SkMatrix44.h"
11 12
12 static inline bool sk_float_almost_equals(float x, float y, float tol) { 13 static inline bool sk_float_almost_equals(float x, float y, float tol) {
13 return sk_float_abs(x - y) <= tol; 14 return sk_float_abs(x - y) <= tol;
14 } 15 }
15 16
16 static inline bool matrix_is_almost_identity(const SkMatrix44& m, 17 static inline bool matrix_is_almost_identity(const SkMatrix44& m,
17 SkMScalar tol = SK_MScalar1 / (1 << 12)) { 18 SkMScalar tol = SK_MScalar1 / (1 << 12)) {
18 return 19 return
19 sk_float_almost_equals(m.getFloat(0, 0), 1.0f, tol) && 20 sk_float_almost_equals(m.getFloat(0, 0), 1.0f, tol) &&
(...skipping 24 matching lines...) Expand all
44 if (!src || !dst) { 45 if (!src || !dst) {
45 // Invalid 46 // Invalid
46 return nullptr; 47 return nullptr;
47 } 48 }
48 49
49 if (src == dst) { 50 if (src == dst) {
50 // Quick equality check - no conversion needed in this case 51 // Quick equality check - no conversion needed in this case
51 return nullptr; 52 return nullptr;
52 } 53 }
53 54
54 SkMatrix44 srcToDst(SkMatrix44::kUninitialized_Constructor); 55 SkMatrix44 srcToDst = as_CSB(dst)->fromXYZD50();
55 if (!dst->xyz().invert(&srcToDst)) { 56 srcToDst.postConcat(src->toXYZD50());
56 return nullptr;
57 }
58 srcToDst.postConcat(src->xyz());
59 57
60 if (matrix_is_almost_identity(srcToDst)) { 58 if (matrix_is_almost_identity(srcToDst)) {
61 return nullptr; 59 return nullptr;
62 } 60 }
63 61
64 return sk_make_sp<GrColorSpaceXform>(srcToDst, srcAlphaType); 62 return sk_make_sp<GrColorSpaceXform>(srcToDst, srcAlphaType);
65 } 63 }
OLDNEW
« no previous file with comments | « src/core/SkColorSpace_Base.h ('k') | tests/ColorSpaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698