OLD | NEW |
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 #ifndef GrColorSpaceXform_DEFINED | 8 #ifndef GrColorSpaceXform_DEFINED |
9 #define GrColorSpaceXform_DEFINED | 9 #define GrColorSpaceXform_DEFINED |
10 | 10 |
11 #include "SkImageInfo.h" | 11 #include "SkMatrix44.h" |
12 #include "SkRefCnt.h" | 12 #include "SkRefCnt.h" |
13 | 13 |
14 class SkColorSpace; | 14 class SkColorSpace; |
15 class SkMatrix44; | |
16 | 15 |
17 /** | 16 /** |
18 * Represents a color gamut transformation (as a 4x4 color matrix) | 17 * Represents a color gamut transformation (as a 4x4 color matrix) |
19 */ | 18 */ |
20 class GrColorSpaceXform : public SkRefCnt { | 19 class GrColorSpaceXform : public SkRefCnt { |
21 public: | 20 public: |
22 GrColorSpaceXform(const SkMatrix44& srcToDst, SkAlphaType srcAlphaType); | 21 GrColorSpaceXform(const SkMatrix44& srcToDst); |
23 | 22 |
24 static sk_sp<GrColorSpaceXform> Make(SkColorSpace* src, SkColorSpace* dst, | 23 static sk_sp<GrColorSpaceXform> Make(SkColorSpace* src, SkColorSpace* dst); |
25 SkAlphaType srcAlphaType); | |
26 | 24 |
27 const float* srcToDst() { return fSrcToDst; } | 25 const SkMatrix44& srcToDst() { return fSrcToDst; } |
28 SkAlphaType alphaType() const { return fSrcAlphaType; } | |
29 | 26 |
30 /** | 27 /** |
31 * GrGLSLFragmentProcessor::GenKey() must call this and include the returned
value in its | 28 * GrGLSLFragmentProcessor::GenKey() must call this and include the returned
value in its |
32 * computed key. | 29 * computed key. |
33 */ | 30 */ |
34 static uint32_t XformKey(GrColorSpaceXform* xform) { | 31 static uint32_t XformKey(GrColorSpaceXform* xform) { |
35 if (!xform) { | 32 // Code generation changes if there is an xform, but it otherwise consta
nt |
36 return 0; | 33 return SkToBool(xform) ? 1 : 0; |
37 } | |
38 // Code generation just depends on whether the alpha type is premul or n
ot | |
39 return kPremul_SkAlphaType == xform->fSrcAlphaType ? 1 : 2; | |
40 } | 34 } |
41 | 35 |
42 private: | 36 private: |
43 // We store the column-major form of the srcToDst matrix, for easy uploading
to uniforms | 37 SkMatrix44 fSrcToDst; |
44 float fSrcToDst[16]; | |
45 | |
46 // Alpha type of the source. If it's premul, we need special handling | |
47 SkAlphaType fSrcAlphaType; | |
48 }; | 38 }; |
49 | 39 |
50 #endif | 40 #endif |
OLD | NEW |