• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(GrColorType, SkAlphaType, sk_sp<SkColorSpace>);
24     /* implicit */ GrColorInfo(const SkColorInfo&);
25 
isLinearlyBlended()26     bool isLinearlyBlended() const { return fColorSpace && fColorSpace->gammaIsLinear(); }
27 
colorSpace()28     SkColorSpace* colorSpace() const { return fColorSpace.get(); }
refColorSpace()29     sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; }
30 
31     GrColorSpaceXform* colorSpaceXformFromSRGB() const;
refColorSpaceXformFromSRGB()32     sk_sp<GrColorSpaceXform> refColorSpaceXformFromSRGB() const {
33         return sk_ref_sp(this->colorSpaceXformFromSRGB());
34     }
35 
colorType()36     GrColorType colorType() const { return fColorType; }
alphaType()37     SkAlphaType alphaType() const { return fAlphaType; }
38 
isValid()39     bool isValid() const {
40         return fColorType != GrColorType::kUnknown && fAlphaType != kUnknown_SkAlphaType;
41     }
42 
43 private:
44     sk_sp<SkColorSpace> fColorSpace;
45     mutable sk_sp<GrColorSpaceXform> fColorXformFromSRGB;
46     GrColorType fColorType = GrColorType::kUnknown;
47     SkAlphaType fAlphaType = kUnknown_SkAlphaType;
48     mutable bool fInitializedColorSpaceXformFromSRGB = false;
49 };
50 
51 #endif
52