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" |
| 9 | |
| 10 | GrColorSpaceInfo::GrColorSpaceInfo(sk_sp<SkColorSpace> colorSpace, GrPixelConfig config) |
| 11 | : fColorSpace(std::move(colorSpace)) |
| 12 | , fConfig(config) |
| 13 | , fInitializedColorSpaceXformFromSRGB(false) {} |
| 14 | |
| 15 | GrColorSpaceXform* GrColorSpaceInfo::colorSpaceXformFromSRGB() const { |
| 16 | // TODO: Make this atomic if we start accessing this on multiple threads. |
| 17 | if (!fInitializedColorSpaceXformFromSRGB) { |
| 18 | // sRGB sources are very common (SkColor, etc...), so we cache that gamut transformation |
| 19 | auto srgbColorSpace = SkColorSpace::MakeSRGB(); |
Brian Osman | f06ead9 | 2017-10-30 13:47:41 -0400 | [diff] [blame] | 20 | fColorXformFromSRGB = GrColorSpaceXform::MakeGamutXform(srgbColorSpace.get(), |
| 21 | fColorSpace.get()); |
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 | } |