1 | /* |
---|---|
2 | * Copyright 2017 Google Inc. |
3 | * |
4 | * Use of this source code is governed by a BSD-style license that can be |
5 | * found in the LICENSE file. |
6 | */ |
7 | |
8 | #ifndef GrColorInfo_DEFINED |
9 | #define GrColorInfo_DEFINED |
10 | |
11 | #include "include/core/SkColorSpace.h" |
12 | #include "include/core/SkRefCnt.h" |
13 | #include "include/gpu/GrTypes.h" |
14 | #include "src/gpu/GrColorSpaceXform.h" |
15 | |
16 | /** |
17 | * All the info needed to interpret a color: Color type + alpha type + color space. Also caches |
18 | * the GrColorSpaceXform from sRGB. */ |
19 | class GrColorInfo { |
20 | public: |
21 | GrColorInfo() = default; |
22 | GrColorInfo(const GrColorInfo&); |
23 | GrColorInfo& operator=(const GrColorInfo&); |
24 | GrColorInfo(GrColorType, SkAlphaType, sk_sp<SkColorSpace>); |
25 | /* implicit */ GrColorInfo(const SkColorInfo&); |
26 | |
27 | bool isLinearlyBlended() const { return fColorSpace && fColorSpace->gammaIsLinear(); } |
28 | |
29 | SkColorSpace* colorSpace() const { return fColorSpace.get(); } |
30 | sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; } |
31 | |
32 | GrColorSpaceXform* colorSpaceXformFromSRGB() const { return fColorXformFromSRGB.get(); } |
33 | sk_sp<GrColorSpaceXform> refColorSpaceXformFromSRGB() const { return fColorXformFromSRGB; } |
34 | |
35 | GrColorType colorType() const { return fColorType; } |
36 | SkAlphaType alphaType() const { return fAlphaType; } |
37 | |
38 | bool isValid() const { |
39 | return fColorType != GrColorType::kUnknown && fAlphaType != kUnknown_SkAlphaType; |
40 | } |
41 | |
42 | private: |
43 | sk_sp<SkColorSpace> fColorSpace; |
44 | sk_sp<GrColorSpaceXform> fColorXformFromSRGB; |
45 | GrColorType fColorType = GrColorType::kUnknown; |
46 | SkAlphaType fAlphaType = kUnknown_SkAlphaType; |
47 | }; |
48 | |
49 | #endif |
50 |