• 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 
8 #ifndef SkOpts_DEFINED
9 #define SkOpts_DEFINED
10 
11 #include "include/core/SkTypes.h"
12 #include "include/private/SkOpts_spi.h"
13 #include "src/core/SkRasterPipeline.h"
14 #include "src/core/SkXfermodePriv.h"
15 
16 struct SkBitmapProcState;
17 namespace skvm {
18 struct InterpreterInstruction;
19 class TraceHook;
20 }
21 
22 namespace SkOpts {
23     // Call to replace pointers to portable functions with pointers to CPU-specific functions.
24     // Thread-safe and idempotent.
25     // Called by SkGraphics::Init().
26     void Init();
27 
28     // Declare function pointers here...
29 
30     // May return nullptr if we haven't specialized the given Mode.
31     extern SkXfermode* (*create_xfermode)(SkBlendMode);
32 
33     extern void (*blit_mask_d32_a8)(SkPMColor*, size_t, const SkAlpha*, size_t, SkColor, int, int);
34     extern void (*blit_row_color32)(SkPMColor*, const SkPMColor*, int, SkPMColor);
35     extern void (*blit_row_s32a_opaque)(SkPMColor*, const SkPMColor*, int, U8CPU);
36 
37     // Swizzle input into some sort of 8888 pixel, {premul,unpremul} x {rgba,bgra}.
38     typedef void (*Swizzle_8888_u32)(uint32_t*, const uint32_t*, int);
39     extern Swizzle_8888_u32 RGBA_to_BGRA,          // i.e. just swap RB
40                             RGBA_to_rgbA,          // i.e. just premultiply
41                             RGBA_to_bgrA,          // i.e. swap RB and premultiply
42                             inverted_CMYK_to_RGB1, // i.e. convert color space
43                             inverted_CMYK_to_BGR1; // i.e. convert color space
44 
45     typedef void (*Swizzle_8888_u8)(uint32_t*, const uint8_t*, int);
46     extern Swizzle_8888_u8 RGB_to_RGB1,     // i.e. insert an opaque alpha
47                            RGB_to_BGR1,     // i.e. swap RB and insert an opaque alpha
48                            gray_to_RGB1,    // i.e. expand to color channels + an opaque alpha
49                            grayA_to_RGBA,   // i.e. expand to color channels
50                            grayA_to_rgbA;   // i.e. expand to color channels and premultiply
51 
52     extern void (*memset16)(uint16_t[], uint16_t, int);
53     extern void SK_SPI(*memset32)(uint32_t[], uint32_t, int);
54     extern void (*memset64)(uint64_t[], uint64_t, int);
55 
56     extern void (*rect_memset16)(uint16_t[], uint16_t, int, size_t, int);
57     extern void (*rect_memset32)(uint32_t[], uint32_t, int, size_t, int);
58     extern void (*rect_memset64)(uint64_t[], uint64_t, int, size_t, int);
59 
60     extern float (*cubic_solver)(float, float, float, float);
61 
62     static inline uint32_t hash(const void* data, size_t bytes, uint32_t seed=0) {
63         return hash_fn(data, bytes, seed);
64     }
65 
66     // SkBitmapProcState optimized Shader, Sample, or Matrix procs.
67     extern void (*S32_alpha_D32_filter_DX)(const SkBitmapProcState&,
68                                            const uint32_t* xy, int count, SkPMColor*);
69     extern void (*S32_alpha_D32_filter_DXDY)(const SkBitmapProcState&,
70                                              const uint32_t* xy, int count, SkPMColor*);
71 
72 #define M(st) +1
73     // We can't necessarily express the type of SkJumper stage functions here,
74     // so we just use this void(*)(void) as a stand-in.
75     using StageFn = void(*)(void);
76     extern StageFn stages_highp[SK_RASTER_PIPELINE_STAGES(M)], just_return_highp;
77     extern StageFn stages_lowp [SK_RASTER_PIPELINE_STAGES(M)], just_return_lowp;
78 
79     extern void (*start_pipeline_highp)(size_t,size_t,size_t,size_t, void**);
80     extern void (*start_pipeline_lowp )(size_t,size_t,size_t,size_t, void**);
81 #undef M
82 
83     extern void (*interpret_skvm)(const skvm::InterpreterInstruction insts[], int ninsts,
84                                   int nregs, int loop, const int strides[],
85                                   skvm::TraceHook* traceHooks[], int nTraceHooks,
86                                   int nargs, int n, void* args[]);
87 }  // namespace SkOpts
88 
89 /** Similar to memset(), but it assigns a 16, 32, or 64-bit value into the buffer.
90     @param buffer   The memory to have value copied into it
91     @param value    The value to be copied into buffer
92     @param count    The number of times value should be copied into the buffer.
93 */
sk_memset16(uint16_t buffer[],uint16_t value,int count)94 static inline void sk_memset16(uint16_t buffer[], uint16_t value, int count) {
95     SkOpts::memset16(buffer, value, count);
96 }
sk_memset32(uint32_t buffer[],uint32_t value,int count)97 static inline void sk_memset32(uint32_t buffer[], uint32_t value, int count) {
98     SkOpts::memset32(buffer, value, count);
99 }
sk_memset64(uint64_t buffer[],uint64_t value,int count)100 static inline void sk_memset64(uint64_t buffer[], uint64_t value, int count) {
101     SkOpts::memset64(buffer, value, count);
102 }
103 
104 #endif//SkOpts_DEFINED
105