GrColorSpaceInfo.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #ifndef GrColorSpaceInfo_DEFINED
  8. #define GrColorSpaceInfo_DEFINED
  9. #include "include/core/SkColorSpace.h"
  10. #include "include/core/SkRefCnt.h"
  11. #include "include/gpu/GrTypes.h"
  12. #include "src/gpu/GrColorSpaceXform.h"
  13. /** Describes the color space properties of a surface context. */
  14. class GrColorSpaceInfo {
  15. public:
  16. GrColorSpaceInfo() = default;
  17. GrColorSpaceInfo(GrColorType, SkAlphaType, sk_sp<SkColorSpace>);
  18. bool isLinearlyBlended() const { return fColorSpace && fColorSpace->gammaIsLinear(); }
  19. SkColorSpace* colorSpace() const { return fColorSpace.get(); }
  20. sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; }
  21. GrColorSpaceXform* colorSpaceXformFromSRGB() const;
  22. sk_sp<GrColorSpaceXform> refColorSpaceXformFromSRGB() const {
  23. return sk_ref_sp(this->colorSpaceXformFromSRGB());
  24. }
  25. GrColorType colorType() const { return fColorType; }
  26. SkAlphaType alphaType() const { return fAlphaType; }
  27. bool isValid() const {
  28. return fColorType != GrColorType::kUnknown && fAlphaType != kUnknown_SkAlphaType;
  29. }
  30. private:
  31. sk_sp<SkColorSpace> fColorSpace;
  32. mutable sk_sp<GrColorSpaceXform> fColorXformFromSRGB;
  33. GrColorType fColorType = GrColorType::kUnknown;
  34. SkAlphaType fAlphaType = kUnknown_SkAlphaType;
  35. mutable bool fInitializedColorSpaceXformFromSRGB = false;
  36. };
  37. #endif