1 /* 2 * Copyright 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "ColorSpaces.h" 18 19 namespace android { 20 namespace renderengine { 21 namespace skia { 22 toSkColorSpace(ui::Dataspace dataspace)23sk_sp<SkColorSpace> toSkColorSpace(ui::Dataspace dataspace) { 24 skcms_Matrix3x3 gamut; 25 switch (dataspace & HAL_DATASPACE_STANDARD_MASK) { 26 case HAL_DATASPACE_STANDARD_BT709: 27 gamut = SkNamedGamut::kSRGB; 28 break; 29 case HAL_DATASPACE_STANDARD_BT2020: 30 gamut = SkNamedGamut::kRec2020; 31 break; 32 case HAL_DATASPACE_STANDARD_DCI_P3: 33 gamut = SkNamedGamut::kDisplayP3; 34 break; 35 default: 36 gamut = SkNamedGamut::kSRGB; 37 break; 38 } 39 40 switch (dataspace & HAL_DATASPACE_TRANSFER_MASK) { 41 case HAL_DATASPACE_TRANSFER_LINEAR: 42 return SkColorSpace::MakeRGB(SkNamedTransferFn::kLinear, gamut); 43 case HAL_DATASPACE_TRANSFER_SRGB: 44 return SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, gamut); 45 case HAL_DATASPACE_TRANSFER_ST2084: 46 return SkColorSpace::MakeRGB(SkNamedTransferFn::kPQ, gamut); 47 case HAL_DATASPACE_TRANSFER_HLG: 48 return SkColorSpace::MakeRGB(SkNamedTransferFn::kHLG, gamut); 49 default: 50 return SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, gamut); 51 } 52 } 53 54 } // namespace skia 55 } // namespace renderengine 56 } // namespace android