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