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 GrColorSpaceInfo_DEFINED 9 #define GrColorSpaceInfo_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 /** Describes the color space properties of a surface context. */ 17 class GrColorSpaceInfo { 18 public: 19 GrColorSpaceInfo() = default; 20 GrColorSpaceInfo(GrColorType, SkAlphaType, sk_sp<SkColorSpace>); 21 isLinearlyBlended()22 bool isLinearlyBlended() const { return fColorSpace && fColorSpace->gammaIsLinear(); } 23 colorSpace()24 SkColorSpace* colorSpace() const { return fColorSpace.get(); } refColorSpace()25 sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; } 26 27 GrColorSpaceXform* colorSpaceXformFromSRGB() const; refColorSpaceXformFromSRGB()28 sk_sp<GrColorSpaceXform> refColorSpaceXformFromSRGB() const { 29 return sk_ref_sp(this->colorSpaceXformFromSRGB()); 30 } 31 colorType()32 GrColorType colorType() const { return fColorType; } alphaType()33 SkAlphaType alphaType() const { return fAlphaType; } 34 isValid()35 bool isValid() const { 36 return fColorType != GrColorType::kUnknown && fAlphaType != kUnknown_SkAlphaType; 37 } 38 39 private: 40 sk_sp<SkColorSpace> fColorSpace; 41 mutable sk_sp<GrColorSpaceXform> fColorXformFromSRGB; 42 GrColorType fColorType = GrColorType::kUnknown; 43 SkAlphaType fAlphaType = kUnknown_SkAlphaType; 44 mutable bool fInitializedColorSpaceXformFromSRGB = false; 45 }; 46 47 #endif 48