Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 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 "GrColorSpaceInfo.h" |
Mike Klein | e03a176 | 2018-08-22 11:52:16 -0400 | [diff] [blame] | 9 | #include "SkColorSpacePriv.h" |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 10 | |
| 11 | GrColorSpaceInfo::GrColorSpaceInfo(sk_sp<SkColorSpace> colorSpace, GrPixelConfig config) |
| 12 | : fColorSpace(std::move(colorSpace)) |
| 13 | , fConfig(config) |
| 14 | , fInitializedColorSpaceXformFromSRGB(false) {} |
| 15 | |
| 16 | GrColorSpaceXform* GrColorSpaceInfo::colorSpaceXformFromSRGB() const { |
| 17 | // TODO: Make this atomic if we start accessing this on multiple threads. |
| 18 | if (!fInitializedColorSpaceXformFromSRGB) { |
Brian Osman | 08a50e0 | 2018-06-15 15:06:48 -0400 | [diff] [blame] | 19 | // sRGB sources are very common (SkColor, etc...), so we cache that transformation |
Mike Klein | e03a176 | 2018-08-22 11:52:16 -0400 | [diff] [blame] | 20 | fColorXformFromSRGB = GrColorSpaceXform::Make(sk_srgb_singleton(), kUnpremul_SkAlphaType, |
| 21 | fColorSpace.get(), kUnpremul_SkAlphaType); |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 22 | fInitializedColorSpaceXformFromSRGB = true; |
| 23 | } |
Brian Salomon | 4cbb6e6 | 2017-10-25 15:12:19 -0400 | [diff] [blame] | 24 | // You can't be color-space aware in legacy mode |
| 25 | SkASSERT(fColorSpace || !fColorXformFromSRGB); |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 26 | return fColorXformFromSRGB.get(); |
| 27 | } |