• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "src/core/SkOpts.h"
8 
9 #include "include/private/base/SkFeatures.h"
10 #include "src/core/SkCpu.h"
11 #include "src/core/SkOptsTargets.h"
12 
13 #define SK_OPTS_TARGET SK_OPTS_TARGET_DEFAULT
14 #include "src/opts/SkOpts_SetTarget.h"
15 
16 #include "src/opts/SkRasterPipeline_opts.h"  // IWYU pragma: keep
17 
18 #include "src/opts/SkOpts_RestoreTarget.h"
19 
20 namespace SkOpts {
21     // Define default function pointer values here...
22     // If our global compile options are set high enough, these defaults might even be
23     // CPU-specialized, e.g. a typical x86-64 machine might start with SSE2 defaults.
24     // They'll still get a chance to be replaced with even better ones, e.g. using SSE4.1.
25     size_t raster_pipeline_lowp_stride  = SK_OPTS_NS::raster_pipeline_lowp_stride();
26     size_t raster_pipeline_highp_stride = SK_OPTS_NS::raster_pipeline_highp_stride();
27 
28 #define M(st) (StageFn)SK_OPTS_NS::st,
29     StageFn ops_highp[] = { SK_RASTER_PIPELINE_OPS_ALL(M) };
30     StageFn just_return_highp = (StageFn)SK_OPTS_NS::just_return;
31     void (*start_pipeline_highp)(size_t, size_t, size_t, size_t, SkRasterPipelineStage*,
32                                  SkSpan<SkRasterPipeline_MemoryCtxPatch>,
33                                  uint8_t*) =
34             SK_OPTS_NS::start_pipeline;
35 #undef M
36 
37 #define M(st) (StageFn)SK_OPTS_NS::lowp::st,
38     StageFn ops_lowp[] = { SK_RASTER_PIPELINE_OPS_LOWP(M) };
39     StageFn just_return_lowp = (StageFn)SK_OPTS_NS::lowp::just_return;
40     void (*start_pipeline_lowp)(size_t, size_t, size_t, size_t, SkRasterPipelineStage*,
41                                 SkSpan<SkRasterPipeline_MemoryCtxPatch>,
42                                 uint8_t*) =
43             SK_OPTS_NS::lowp::start_pipeline;
44 #undef M
45 
46     // Each Init_foo() is defined in src/opts/SkOpts_foo.cpp.
47     void Init_hsw();
48     void Init_skx();
49 
init()50     static bool init() {
51     #if defined(SK_ENABLE_OPTIMIZE_SIZE)
52         // All Init_foo functions are omitted when optimizing for size
53     #elif defined(SK_CPU_X86)
54         #if SK_CPU_SSE_LEVEL < SK_CPU_SSE_LEVEL_AVX2
55             if (SkCpu::Supports(SkCpu::HSW)) { Init_hsw(); }
56         #endif
57 
58         #if (SK_CPU_SSE_LEVEL < SK_CPU_SSE_LEVEL_SKX) && defined(SK_ENABLE_AVX512_OPTS)
59             if (SkCpu::Supports(SkCpu::SKX)) { Init_skx(); }
60         #endif
61 
62     #endif
63         return true;
64     }
65 
Init()66     void Init() {
67         [[maybe_unused]] static bool gInitialized = init();
68     }
69 }  // namespace SkOpts
70