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/GrColorInfo.h" |
9 | |
10 | #include "src/core/SkColorSpacePriv.h" |
11 | |
12 | GrColorInfo::GrColorInfo( |
13 | GrColorType colorType, SkAlphaType alphaType, sk_sp<SkColorSpace> colorSpace) |
14 | : fColorSpace(std::move(colorSpace)), fColorType(colorType), fAlphaType(alphaType) {} |
15 | |
16 | GrColorInfo::GrColorInfo(const SkColorInfo& ci) |
17 | : GrColorInfo(SkColorTypeToGrColorType(ci.colorType()), |
18 | ci.alphaType(), |
19 | ci.refColorSpace()) {} |
20 | |
21 | GrColorInfo::GrColorInfo(const GrColorInfo&) = default; |
22 | GrColorInfo& GrColorInfo::operator=(const GrColorInfo&) = default; |
23 | |
24 | GrColorSpaceXform* GrColorInfo::colorSpaceXformFromSRGB() const { |
25 | // TODO: Make this atomic if we start accessing this on multiple threads. |
26 | if (!fInitializedColorSpaceXformFromSRGB) { |
27 | // sRGB sources are very common (SkColor, etc...), so we cache that transformation |
28 | fColorXformFromSRGB = GrColorSpaceXform::Make(sk_srgb_singleton(), kUnpremul_SkAlphaType, |
29 | fColorSpace.get(), kUnpremul_SkAlphaType); |
30 | fInitializedColorSpaceXformFromSRGB = true; |
31 | } |
32 | // You can't be color-space aware in legacy mode |
33 | SkASSERT(fColorSpace || !fColorXformFromSRGB); |
34 | return fColorXformFromSRGB.get(); |
35 | } |
36 | |