| 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 |
#include "src/gpu/ganesh/GrColorInfo.h" |
| 9 |
|
| 10 |
#include "include/core/SkColorSpace.h" |
| 11 |
#include "include/core/SkImageInfo.h" |
| 12 |
#include "src/core/SkColorSpacePriv.h" |
| 13 |
|
| 14 |
#include <utility> |
| 15 |
|
| 16 |
GrColorInfo::GrColorInfo( |
| 17 |
GrColorType colorType, SkAlphaType alphaType, sk_sp<SkColorSpace> colorSpace) |
| 18 |
: fColorSpace(std::move(colorSpace)), fColorType(colorType), fAlphaType(alphaType) { |
| 19 |
// sRGB sources are very common (SkColor, etc...), so we cache that transformation |
| 20 |
fColorXformFromSRGB = GrColorSpaceXform::Make(sk_srgb_singleton(), kUnpremul_SkAlphaType, |
| 21 |
fColorSpace.get(), kUnpremul_SkAlphaType); |
| 22 |
} |
| 23 |
|
| 24 |
GrColorInfo::GrColorInfo(const SkColorInfo& ci) |
| 25 |
: GrColorInfo(SkColorTypeToGrColorType(ci.colorType()), |
| 26 |
ci.alphaType(), |
| 27 |
ci.refColorSpace()) {} |
| 28 |
|
| 29 |
GrColorInfo::GrColorInfo() = default; |
| 30 |
GrColorInfo::GrColorInfo(const GrColorInfo&) = default; |
| 31 |
GrColorInfo& GrColorInfo::operator=(const GrColorInfo&) = default; |
| 32 |
GrColorInfo::~GrColorInfo() = default; |
| 33 |
|
| 34 |
bool GrColorInfo::operator==(const GrColorInfo& that) const { |
| 35 |
return fColorType == that.fColorType && |
| 36 |
fAlphaType == that.fAlphaType && |
| 37 |
SkColorSpace::Equals(fColorSpace.get(), that.fColorSpace.get()); |
| 38 |
} |
| 39 |
|
| 40 |
GrColorInfo GrColorInfo::makeColorType(GrColorType ct) const { |
| 41 |
return GrColorInfo(ct, fAlphaType, this->refColorSpace()); |
| 42 |
} |
| 43 |
|
| 44 |
bool GrColorInfo::isLinearlyBlended() const { |
| 45 |
return fColorSpace && fColorSpace->gammaIsLinear(); |
| 46 |
} |
| 47 |
|
| 48 |
SkColorSpace* GrColorInfo::colorSpace() const { return fColorSpace.get(); } |
| 49 |
sk_sp<SkColorSpace> GrColorInfo::refColorSpace() const { return fColorSpace; } |