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/core/SkColorSpacePriv.h"
9 #include "src/gpu/GrColorSpaceInfo.h"
10
GrColorSpaceInfo(GrColorType colorType,SkAlphaType alphaType,sk_sp<SkColorSpace> colorSpace)11 GrColorSpaceInfo::GrColorSpaceInfo(GrColorType colorType,
12 SkAlphaType alphaType,
13 sk_sp<SkColorSpace> colorSpace)
14 : fColorSpace(std::move(colorSpace)), fColorType(colorType), fAlphaType(alphaType) {}
15
colorSpaceXformFromSRGB() const16 GrColorSpaceXform* GrColorSpaceInfo::colorSpaceXformFromSRGB() const {
17 // TODO: Make this atomic if we start accessing this on multiple threads.
18 if (!fInitializedColorSpaceXformFromSRGB) {
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 fInitializedColorSpaceXformFromSRGB = true;
23 }
24 // You can't be color-space aware in legacy mode
25 SkASSERT(fColorSpace || !fColorXformFromSRGB);
26 return fColorXformFromSRGB.get();
27 }
28