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 #include "SkColorSpacePriv.h" 10 GrColorSpaceInfo(sk_sp<SkColorSpace> colorSpace,GrPixelConfig config)11GrColorSpaceInfo::GrColorSpaceInfo(sk_sp<SkColorSpace> colorSpace, GrPixelConfig config) 12 : fColorSpace(std::move(colorSpace)) 13 , fConfig(config) 14 , fInitializedColorSpaceXformFromSRGB(false) {} 15 colorSpaceXformFromSRGB() const16GrColorSpaceXform* 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