1 /*
2  * Copyright 2009 The Android Open Source Project
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 "SkBitmapProcState_opts_SSE2.h"
9 #include "SkBitmapProcState_opts_SSSE3.h"
10 #include "SkBitmapScaler.h"
11 #include "SkBlitMask.h"
12 #include "SkBlitRow.h"
13 #include "SkBlitRow_opts_SSE2.h"
14 #include "SkCpu.h"
15 
16 
17 /*
18  *****************************************
19  *********This file is deprecated*********
20  *****************************************
21  * New CPU-specific work should be done in
22  * SkOpts framework. Run-time detection of
23  * available instruction set extensions is
24  * implemented in src/core/SkOpts.cpp file
25  *****************************************
26  */
27 
28 
29 /* This file must *not* be compiled with -msse or any other optional SIMD
30    extension, otherwise gcc may generate SIMD instructions even for scalar ops
31    (and thus give an invalid instruction on Pentium3 on the code below).
32    For example, only files named *_SSE2.cpp in this directory should be
33    compiled with -msse2 or higher. */
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 
platformProcs()37 void SkBitmapProcState::platformProcs() {
38     /* Every optimization in the function requires at least SSE2 */
39     if (!SkCpu::Supports(SkCpu::SSE2)) {
40         return;
41     }
42     const bool ssse3 = SkCpu::Supports(SkCpu::SSSE3);
43 
44     /* Check fSampleProc32 */
45     if (fSampleProc32 == S32_opaque_D32_filter_DX) {
46         if (ssse3) {
47             fSampleProc32 = S32_opaque_D32_filter_DX_SSSE3;
48         } else {
49             fSampleProc32 = S32_opaque_D32_filter_DX_SSE2;
50         }
51     } else if (fSampleProc32 == S32_opaque_D32_filter_DXDY) {
52         if (ssse3) {
53             fSampleProc32 = S32_opaque_D32_filter_DXDY_SSSE3;
54         }
55     } else if (fSampleProc32 == S32_alpha_D32_filter_DX) {
56         if (ssse3) {
57             fSampleProc32 = S32_alpha_D32_filter_DX_SSSE3;
58         } else {
59             fSampleProc32 = S32_alpha_D32_filter_DX_SSE2;
60         }
61     } else if (fSampleProc32 == S32_alpha_D32_filter_DXDY) {
62         if (ssse3) {
63             fSampleProc32 = S32_alpha_D32_filter_DXDY_SSSE3;
64         }
65     }
66 
67     /* Check fMatrixProc */
68     if (fMatrixProc == ClampX_ClampY_filter_scale) {
69         fMatrixProc = ClampX_ClampY_filter_scale_SSE2;
70     } else if (fMatrixProc == ClampX_ClampY_nofilter_scale) {
71         fMatrixProc = ClampX_ClampY_nofilter_scale_SSE2;
72     } else if (fMatrixProc == ClampX_ClampY_filter_affine) {
73         fMatrixProc = ClampX_ClampY_filter_affine_SSE2;
74     } else if (fMatrixProc == ClampX_ClampY_nofilter_affine) {
75         fMatrixProc = ClampX_ClampY_nofilter_affine_SSE2;
76     }
77 }
78 
79 ////////////////////////////////////////////////////////////////////////////////
80 
81 static const SkBlitRow::Proc16 platform_16_procs[] = {
82     S32_D565_Opaque_SSE2,               // S32_D565_Opaque
83     nullptr,                               // S32_D565_Blend
84     S32A_D565_Opaque_SSE2,              // S32A_D565_Opaque
85     nullptr,                               // S32A_D565_Blend
86     S32_D565_Opaque_Dither_SSE2,        // S32_D565_Opaque_Dither
87     nullptr,                               // S32_D565_Blend_Dither
88     S32A_D565_Opaque_Dither_SSE2,       // S32A_D565_Opaque_Dither
89     nullptr,                               // S32A_D565_Blend_Dither
90 };
91 
PlatformFactory565(unsigned flags)92 SkBlitRow::Proc16 SkBlitRow::PlatformFactory565(unsigned flags) {
93     if (SkCpu::Supports(SkCpu::SSE2)) {
94         return platform_16_procs[flags];
95     } else {
96         return nullptr;
97     }
98 }
99 
100 static const SkBlitRow::ColorProc16 platform_565_colorprocs_SSE2[] = {
101     Color32A_D565_SSE2,                 // Color32A_D565,
102     nullptr,                               // Color32A_D565_Dither
103 };
104 
PlatformColorFactory565(unsigned flags)105 SkBlitRow::ColorProc16 SkBlitRow::PlatformColorFactory565(unsigned flags) {
106 /* If you're thinking about writing an SSE4 version of this, do check it's
107  * actually faster on Atom. Our original SSE4 version was slower than this
108  * SSE2 version on Silvermont, and only marginally faster on a Core i7,
109  * mainly due to the MULLD timings.
110  */
111     if (SkCpu::Supports(SkCpu::SSE2)) {
112         return platform_565_colorprocs_SSE2[flags];
113     } else {
114         return nullptr;
115     }
116 }
117 
118 static const SkBlitRow::Proc32 platform_32_procs_SSE2[] = {
119     nullptr,                               // S32_Opaque,
120     S32_Blend_BlitRow32_SSE2,           // S32_Blend,
121     nullptr,                            // Ported to SkOpts
122     S32A_Blend_BlitRow32_SSE2,          // S32A_Blend,
123 };
124 
PlatformProcs32(unsigned flags)125 SkBlitRow::Proc32 SkBlitRow::PlatformProcs32(unsigned flags) {
126     if (SkCpu::Supports(SkCpu::SSE2)) {
127         return platform_32_procs_SSE2[flags];
128     } else {
129         return nullptr;
130     }
131 }
132 
133 ////////////////////////////////////////////////////////////////////////////////
134 
PlatformBlitRowProcs16(bool isOpaque)135 SkBlitMask::BlitLCD16RowProc SkBlitMask::PlatformBlitRowProcs16(bool isOpaque) {
136     if (SkCpu::Supports(SkCpu::SSE2)) {
137         if (isOpaque) {
138             return SkBlitLCD16OpaqueRow_SSE2;
139         } else {
140             return SkBlitLCD16Row_SSE2;
141         }
142     } else {
143         return nullptr;
144     }
145 
146 }
147 
PlatformRowProcs(SkColorType,SkMask::Format,RowFlags)148 SkBlitMask::RowProc SkBlitMask::PlatformRowProcs(SkColorType, SkMask::Format, RowFlags) {
149     return nullptr;
150 }
151