• 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& operator=(const GrColorInfo&);
24     GrColorInfo(GrColorType, SkAlphaType, sk_sp<SkColorSpace>);
25     /* implicit */ GrColorInfo(const SkColorInfo&);
26 
27     bool operator==(const GrColorInfo& that) const {
28         return  fColorType == that.fColorType &&
29                 fAlphaType == that.fAlphaType &&
30                 SkColorSpace::Equals(fColorSpace.get(), that.fColorSpace.get());
31     }
32     bool operator!=(const GrColorInfo& that) const { return !(*this == that); }
33 
makeColorType(GrColorType ct)34     GrColorInfo makeColorType(GrColorType ct) const {
35         return GrColorInfo(ct, fAlphaType, this->refColorSpace());
36     }
37 
isLinearlyBlended()38     bool isLinearlyBlended() const { return fColorSpace && fColorSpace->gammaIsLinear(); }
39 
colorSpace()40     SkColorSpace* colorSpace() const { return fColorSpace.get(); }
refColorSpace()41     sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; }
42 
colorSpaceXformFromSRGB()43     GrColorSpaceXform* colorSpaceXformFromSRGB() const { return fColorXformFromSRGB.get(); }
refColorSpaceXformFromSRGB()44     sk_sp<GrColorSpaceXform> refColorSpaceXformFromSRGB() const { return fColorXformFromSRGB; }
45 
colorType()46     GrColorType colorType() const { return fColorType; }
alphaType()47     SkAlphaType alphaType() const { return fAlphaType; }
48 
isAlphaOnly()49     bool isAlphaOnly() const { return GrColorTypeIsAlphaOnly(fColorType); }
50 
isValid()51     bool isValid() const {
52         return fColorType != GrColorType::kUnknown && fAlphaType != kUnknown_SkAlphaType;
53     }
54 
55 private:
56     sk_sp<SkColorSpace> fColorSpace;
57     sk_sp<GrColorSpaceXform> fColorXformFromSRGB;
58     GrColorType fColorType = GrColorType::kUnknown;
59     SkAlphaType fAlphaType = kUnknown_SkAlphaType;
60 };
61 
62 #endif
63