| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright 2015 Google Inc. | 2  * Copyright 2015 Google Inc. | 
| 3  * | 3  * | 
| 4  * Use of this source code is governed by a BSD-style license that can be | 4  * Use of this source code is governed by a BSD-style license that can be | 
| 5  * found in the LICENSE file. | 5  * found in the LICENSE file. | 
| 6  */ | 6  */ | 
| 7 | 7 | 
| 8 #include "SkCommonFlagsConfig.h" | 8 #include "SkCommonFlagsConfig.h" | 
| 9 | 9 | 
| 10 #include <stdlib.h> | 10 #include <stdlib.h> | 
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 185         , fBackend(backend) | 185         , fBackend(backend) | 
| 186         , fViaParts(viaParts) { | 186         , fViaParts(viaParts) { | 
| 187 } | 187 } | 
| 188 SkCommandLineConfig::~SkCommandLineConfig() { | 188 SkCommandLineConfig::~SkCommandLineConfig() { | 
| 189 } | 189 } | 
| 190 | 190 | 
| 191 #if SK_SUPPORT_GPU | 191 #if SK_SUPPORT_GPU | 
| 192 SkCommandLineConfigGpu::SkCommandLineConfigGpu( | 192 SkCommandLineConfigGpu::SkCommandLineConfigGpu( | 
| 193     const SkString& tag, const SkTArray<SkString>& viaParts, | 193     const SkString& tag, const SkTArray<SkString>& viaParts, | 
| 194     ContextType contextType, bool useNVPR, bool useDIText, int samples, | 194     ContextType contextType, bool useNVPR, bool useDIText, int samples, | 
| 195     SkColorType colorType, sk_sp<SkColorSpace> colorSpace) | 195     SkColorType colorType, SkColorProfileType profileType) | 
| 196         : SkCommandLineConfig(tag, SkString("gpu"), viaParts) | 196         : SkCommandLineConfig(tag, SkString("gpu"), viaParts) | 
| 197         , fContextType(contextType) | 197         , fContextType(contextType) | 
| 198         , fUseNVPR(useNVPR) | 198         , fUseNVPR(useNVPR) | 
| 199         , fUseDIText(useDIText) | 199         , fUseDIText(useDIText) | 
| 200         , fSamples(samples) | 200         , fSamples(samples) | 
| 201         , fColorType(colorType) | 201         , fColorType(colorType) | 
| 202         , fColorSpace(std::move(colorSpace)) { | 202         , fProfileType(profileType) { | 
| 203 } | 203 } | 
| 204 static bool parse_option_int(const SkString& value, int* outInt) { | 204 static bool parse_option_int(const SkString& value, int* outInt) { | 
| 205     if (value.isEmpty()) { | 205     if (value.isEmpty()) { | 
| 206         return false; | 206         return false; | 
| 207     } | 207     } | 
| 208     char* endptr = nullptr; | 208     char* endptr = nullptr; | 
| 209     long intValue = strtol(value.c_str(), &endptr, 10); | 209     long intValue = strtol(value.c_str(), &endptr, 10); | 
| 210     if (*endptr != '\0') { | 210     if (*endptr != '\0') { | 
| 211         return false; | 211         return false; | 
| 212     } | 212     } | 
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 269 #ifdef SK_VULKAN | 269 #ifdef SK_VULKAN | 
| 270     if (value.equals("vulkan")) { | 270     if (value.equals("vulkan")) { | 
| 271         *outContextType = GrContextFactory::kVulkan_ContextType; | 271         *outContextType = GrContextFactory::kVulkan_ContextType; | 
| 272         return true; | 272         return true; | 
| 273     } | 273     } | 
| 274 #endif | 274 #endif | 
| 275     return false; | 275     return false; | 
| 276 } | 276 } | 
| 277 static bool parse_option_gpu_color(const SkString& value, | 277 static bool parse_option_gpu_color(const SkString& value, | 
| 278                                    SkColorType* outColorType, | 278                                    SkColorType* outColorType, | 
| 279                                    sk_sp<SkColorSpace>* outColorSpace) { | 279                                    SkColorProfileType* outProfileType) { | 
| 280     if (value.equals("8888")) { | 280     if (value.equals("8888")) { | 
| 281         *outColorType = kN32_SkColorType; | 281         *outColorType = kN32_SkColorType; | 
| 282         *outColorSpace = nullptr; | 282         *outProfileType = kLinear_SkColorProfileType; | 
| 283         return true; | 283         return true; | 
| 284     } | 284     } | 
| 285     if (value.equals("f16")) { | 285     if (value.equals("f16")) { | 
| 286         *outColorType = kRGBA_F16_SkColorType; | 286         *outColorType = kRGBA_F16_SkColorType; | 
| 287         *outColorSpace = nullptr; | 287         *outProfileType = kLinear_SkColorProfileType; | 
| 288         return true; | 288         return true; | 
| 289     } | 289     } | 
| 290     if (value.equals("srgb")) { | 290     if (value.equals("srgb")) { | 
| 291         *outColorType = kN32_SkColorType; | 291         *outColorType = kN32_SkColorType; | 
| 292         *outColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); | 292         *outProfileType = kSRGB_SkColorProfileType; | 
| 293         return true; | 293         return true; | 
| 294     } | 294     } | 
| 295     return false; | 295     return false; | 
| 296 } | 296 } | 
| 297 | 297 | 
| 298 SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag, | 298 SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag, | 
| 299                                                       const SkTArray<SkString>& 
     vias, | 299                                                       const SkTArray<SkString>& 
     vias, | 
| 300                                                       const SkString& options) { | 300                                                       const SkString& options) { | 
| 301     // Defaults for GPU backend. | 301     // Defaults for GPU backend. | 
| 302     bool seenAPI = false; | 302     bool seenAPI = false; | 
| 303     SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kNativeG
     L_ContextType; | 303     SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kNativeG
     L_ContextType; | 
| 304     bool seenUseNVPR = false; | 304     bool seenUseNVPR = false; | 
| 305     bool useNVPR = false; | 305     bool useNVPR = false; | 
| 306     bool seenUseDIText =false; | 306     bool seenUseDIText =false; | 
| 307     bool useDIText = false; | 307     bool useDIText = false; | 
| 308     bool seenSamples = false; | 308     bool seenSamples = false; | 
| 309     int samples = 0; | 309     int samples = 0; | 
| 310     bool seenColor = false; | 310     bool seenColor = false; | 
| 311     SkColorType colorType = kN32_SkColorType; | 311     SkColorType colorType = kN32_SkColorType; | 
| 312     sk_sp<SkColorSpace> colorSpace = nullptr; | 312     SkColorProfileType profileType = kLinear_SkColorProfileType; | 
| 313 | 313 | 
| 314     SkTArray<SkString> optionParts; | 314     SkTArray<SkString> optionParts; | 
| 315     SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts); | 315     SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts); | 
| 316     for (int i = 0; i < optionParts.count(); ++i) { | 316     for (int i = 0; i < optionParts.count(); ++i) { | 
| 317         SkTArray<SkString> keyValueParts; | 317         SkTArray<SkString> keyValueParts; | 
| 318         SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValu
     eParts); | 318         SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValu
     eParts); | 
| 319         if (keyValueParts.count() != 2) { | 319         if (keyValueParts.count() != 2) { | 
| 320             return nullptr; | 320             return nullptr; | 
| 321         } | 321         } | 
| 322         const SkString& key = keyValueParts[0]; | 322         const SkString& key = keyValueParts[0]; | 
| 323         const SkString& value = keyValueParts[1]; | 323         const SkString& value = keyValueParts[1]; | 
| 324         bool valueOk = false; | 324         bool valueOk = false; | 
| 325         if (key.equals("api") && !seenAPI) { | 325         if (key.equals("api") && !seenAPI) { | 
| 326             valueOk = parse_option_gpu_api(value, &contextType); | 326             valueOk = parse_option_gpu_api(value, &contextType); | 
| 327             seenAPI = true; | 327             seenAPI = true; | 
| 328         } else if (key.equals("nvpr") && !seenUseNVPR) { | 328         } else if (key.equals("nvpr") && !seenUseNVPR) { | 
| 329             valueOk = parse_option_bool(value, &useNVPR); | 329             valueOk = parse_option_bool(value, &useNVPR); | 
| 330             seenUseNVPR = true; | 330             seenUseNVPR = true; | 
| 331         } else if (key.equals("dit") && !seenUseDIText) { | 331         } else if (key.equals("dit") && !seenUseDIText) { | 
| 332             valueOk = parse_option_bool(value, &useDIText); | 332             valueOk = parse_option_bool(value, &useDIText); | 
| 333             seenUseDIText = true; | 333             seenUseDIText = true; | 
| 334         } else if (key.equals("samples") && !seenSamples) { | 334         } else if (key.equals("samples") && !seenSamples) { | 
| 335             valueOk = parse_option_int(value, &samples); | 335             valueOk = parse_option_int(value, &samples); | 
| 336             seenSamples = true; | 336             seenSamples = true; | 
| 337         } else if (key.equals("color") && !seenColor) { | 337         } else if (key.equals("color") && !seenColor) { | 
| 338             valueOk = parse_option_gpu_color(value, &colorType, &colorSpace); | 338             valueOk = parse_option_gpu_color(value, &colorType, &profileType); | 
| 339             seenColor = true; | 339             seenColor = true; | 
| 340         } | 340         } | 
| 341         if (!valueOk) { | 341         if (!valueOk) { | 
| 342             return nullptr; | 342             return nullptr; | 
| 343         } | 343         } | 
| 344     } | 344     } | 
| 345     return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useDIText
     , samples, | 345     return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useDIText
     , samples, | 
| 346                                       colorType, colorSpace); | 346                                       colorType, profileType); | 
| 347 } | 347 } | 
| 348 #endif | 348 #endif | 
| 349 | 349 | 
| 350 void ParseConfigs(const SkCommandLineFlags::StringArray& configs, | 350 void ParseConfigs(const SkCommandLineFlags::StringArray& configs, | 
| 351                   SkCommandLineConfigArray* outResult) { | 351                   SkCommandLineConfigArray* outResult) { | 
| 352     outResult->reset(); | 352     outResult->reset(); | 
| 353     for (int i = 0; i < configs.count(); ++i) { | 353     for (int i = 0; i < configs.count(); ++i) { | 
| 354         SkString extendedBackend; | 354         SkString extendedBackend; | 
| 355         SkString extendedOptions; | 355         SkString extendedOptions; | 
| 356         SkString simpleBackend; | 356         SkString simpleBackend; | 
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 402         if (extendedBackend.equals("gpu")) { | 402         if (extendedBackend.equals("gpu")) { | 
| 403             parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOpti
     ons); | 403             parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOpti
     ons); | 
| 404         } | 404         } | 
| 405 #endif | 405 #endif | 
| 406         if (!parsedConfig) { | 406         if (!parsedConfig) { | 
| 407             parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias); | 407             parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias); | 
| 408         } | 408         } | 
| 409         outResult->emplace_back(parsedConfig); | 409         outResult->emplace_back(parsedConfig); | 
| 410     } | 410     } | 
| 411 } | 411 } | 
| OLD | NEW | 
|---|