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. */
19class GrColorInfo {
20public:
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;
33 sk_sp<GrColorSpaceXform> refColorSpaceXformFromSRGB() const {
34 return sk_ref_sp(this->colorSpaceXformFromSRGB());
35 }
36
37 GrColorType colorType() const { return fColorType; }
38 SkAlphaType alphaType() const { return fAlphaType; }
39
40 bool isValid() const {
41 return fColorType != GrColorType::kUnknown && fAlphaType != kUnknown_SkAlphaType;
42 }
43
44private:
45 sk_sp<SkColorSpace> fColorSpace;
46 mutable sk_sp<GrColorSpaceXform> fColorXformFromSRGB;
47 GrColorType fColorType = GrColorType::kUnknown;
48 SkAlphaType fAlphaType = kUnknown_SkAlphaType;
49 mutable bool fInitializedColorSpaceXformFromSRGB = false;
50};
51
52#endif
53