1 /* 2 * Copyright 2015 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 "include/private/base/SkOnce.h" 9 #include "src/base/SkHalf.h" 10 #include "src/core/SkCpu.h" 11 #include "src/core/SkOpts.h" 12 13 #if defined(SK_ARM_HAS_NEON) 14 #if defined(SK_ARM_HAS_CRC32) 15 #define SK_OPTS_NS neon_and_crc32 16 #else 17 #define SK_OPTS_NS neon 18 #endif 19 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SKX 20 #define SK_OPTS_NS skx 21 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX2 22 #define SK_OPTS_NS avx2 23 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX 24 #define SK_OPTS_NS avx 25 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE42 26 #define SK_OPTS_NS sse42 27 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE41 28 #define SK_OPTS_NS sse41 29 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3 30 #define SK_OPTS_NS ssse3 31 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE3 32 #define SK_OPTS_NS sse3 33 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 34 #define SK_OPTS_NS sse2 35 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE1 36 #define SK_OPTS_NS sse 37 #else 38 #define SK_OPTS_NS portable 39 #endif 40 41 #include "src/core/SkCubicSolver.h" 42 #include "src/opts/SkBitmapProcState_opts.h" 43 #include "src/opts/SkBlitMask_opts.h" 44 #include "src/opts/SkBlitRow_opts.h" 45 #include "src/opts/SkChecksum_opts.h" 46 #include "src/opts/SkRasterPipeline_opts.h" 47 #include "src/opts/SkSwizzler_opts.h" 48 #include "src/opts/SkUtils_opts.h" 49 #include "src/opts/SkVM_opts.h" 50 #include "src/opts/SkXfermode_opts.h" 51 52 namespace SkOpts { 53 // Define default function pointer values here... 54 // If our global compile options are set high enough, these defaults might even be 55 // CPU-specialized, e.g. a typical x86-64 machine might start with SSE2 defaults. 56 // They'll still get a chance to be replaced with even better ones, e.g. using SSE4.1. 57 #define DEFINE_DEFAULT(name) decltype(name) name = SK_OPTS_NS::name 58 DEFINE_DEFAULT(create_xfermode); 59 60 DEFINE_DEFAULT(blit_mask_d32_a8); 61 62 DEFINE_DEFAULT(blit_row_color32); 63 DEFINE_DEFAULT(blit_row_s32a_opaque); 64 65 DEFINE_DEFAULT(RGBA_to_BGRA); 66 DEFINE_DEFAULT(RGBA_to_rgbA); 67 DEFINE_DEFAULT(RGBA_to_bgrA); 68 DEFINE_DEFAULT(RGB_to_RGB1); 69 DEFINE_DEFAULT(RGB_to_BGR1); 70 DEFINE_DEFAULT(gray_to_RGB1); 71 DEFINE_DEFAULT(grayA_to_RGBA); 72 DEFINE_DEFAULT(grayA_to_rgbA); 73 DEFINE_DEFAULT(inverted_CMYK_to_RGB1); 74 DEFINE_DEFAULT(inverted_CMYK_to_BGR1); 75 76 DEFINE_DEFAULT(memset16); 77 DEFINE_DEFAULT(memset32); 78 DEFINE_DEFAULT(memset64); 79 80 DEFINE_DEFAULT(rect_memset16); 81 DEFINE_DEFAULT(rect_memset32); 82 DEFINE_DEFAULT(rect_memset64); 83 84 DEFINE_DEFAULT(cubic_solver); 85 86 DEFINE_DEFAULT(hash_fn); 87 88 DEFINE_DEFAULT(S32_alpha_D32_filter_DX); 89 DEFINE_DEFAULT(S32_alpha_D32_filter_DXDY); 90 91 DEFINE_DEFAULT(interpret_skvm); 92 #undef DEFINE_DEFAULT 93 94 size_t raster_pipeline_lowp_stride = SK_OPTS_NS::raster_pipeline_lowp_stride(); 95 size_t raster_pipeline_highp_stride = SK_OPTS_NS::raster_pipeline_highp_stride(); 96 97 #define M(st) (StageFn)SK_OPTS_NS::st, 98 StageFn ops_highp[] = { SK_RASTER_PIPELINE_OPS_ALL(M) }; 99 StageFn just_return_highp = (StageFn)SK_OPTS_NS::just_return; 100 void (*start_pipeline_highp)(size_t, size_t, size_t, size_t, SkRasterPipelineStage*) = 101 SK_OPTS_NS::start_pipeline; 102 #undef M 103 104 #define M(st) (StageFn)SK_OPTS_NS::lowp::st, 105 StageFn ops_lowp[] = { SK_RASTER_PIPELINE_OPS_LOWP(M) }; 106 StageFn just_return_lowp = (StageFn)SK_OPTS_NS::lowp::just_return; 107 void (*start_pipeline_lowp)(size_t, size_t, size_t, size_t, SkRasterPipelineStage*) = 108 SK_OPTS_NS::lowp::start_pipeline; 109 #undef M 110 111 // Each Init_foo() is defined in src/opts/SkOpts_foo.cpp. 112 void Init_ssse3(); 113 void Init_sse42(); 114 void Init_avx(); 115 void Init_hsw(); 116 void Init_skx(); 117 void Init_erms(); 118 void Init_crc32(); 119 init()120 static void init() { 121 #if defined(SK_ENABLE_OPTIMIZE_SIZE) 122 // All Init_foo functions are omitted when optimizing for size 123 #elif defined(SK_CPU_X86) 124 #if SK_CPU_SSE_LEVEL < SK_CPU_SSE_LEVEL_SSSE3 125 if (SkCpu::Supports(SkCpu::SSSE3)) { Init_ssse3(); } 126 #endif 127 128 #if SK_CPU_SSE_LEVEL < SK_CPU_SSE_LEVEL_SSE42 129 if (SkCpu::Supports(SkCpu::SSE42)) { Init_sse42(); } 130 #endif 131 132 #if SK_CPU_SSE_LEVEL < SK_CPU_SSE_LEVEL_AVX 133 if (SkCpu::Supports(SkCpu::AVX)) { Init_avx(); } 134 if (SkCpu::Supports(SkCpu::HSW)) { Init_hsw(); } 135 #endif 136 137 #if SK_CPU_SSE_LEVEL < SK_CPU_SSE_LEVEL_SKX 138 if (SkCpu::Supports(SkCpu::SKX)) { Init_skx(); } 139 #endif 140 141 if (SkCpu::Supports(SkCpu::ERMS)) { Init_erms(); } 142 143 #elif defined(SK_CPU_ARM64) 144 if (SkCpu::Supports(SkCpu::CRC32)) { Init_crc32(); } 145 146 #endif 147 } 148 Init()149 void Init() { 150 static SkOnce once; 151 once(init); 152 } 153 } // namespace SkOpts 154