OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <tuple> | 9 #include <tuple> |
10 #include <vector> | 10 #include <vector> |
11 #include "Resources.h" | 11 #include "Resources.h" |
12 #include "SkCpu.h" | 12 #include "SkCpu.h" |
13 #include "SkImage.h" | 13 #include "SkImage.h" |
14 #include "SkImage_Base.h" | 14 #include "SkImage_Base.h" |
15 #include "SkOpts.h" | 15 #include "SkOpts.h" |
| 16 #include "SkPM4fPriv.h" |
16 #include "SkNx.h" | 17 #include "SkNx.h" |
17 #include "Test.h" | 18 #include "Test.h" |
18 #include "../include/core/SkImageInfo.h" | |
19 | 19 |
20 typedef void (*Blender)(uint32_t* dst, const uint32_t* const srcStart, int ndst,
const int nsrc); | 20 typedef void (*Blender)(uint32_t* dst, const uint32_t* const srcStart, int ndst,
const int nsrc); |
21 | 21 |
22 namespace sk_default { | 22 static void brute_force_srcover_srgb_srgb( |
23 extern void brute_force_srcover_srgb_srgb( | 23 uint32_t* dst, const uint32_t* const src, int ndst, const int nsrc) { |
24 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc); | 24 while (ndst > 0) { |
| 25 int n = SkTMin(ndst, nsrc); |
| 26 |
| 27 for (int i = 0; i < n; i++) { |
| 28 srcover_blend_srgb8888_srgb_1(dst++, srgb_to_linear(to_4f(src[i]))); |
| 29 } |
| 30 ndst -= n; |
| 31 } |
25 } | 32 } |
26 | 33 |
27 namespace sk_default { | 34 namespace sk_default { |
28 extern void trivial_srcover_srgb_srgb( | |
29 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc); | |
30 | |
31 extern void best_non_simd_srcover_srgb_srgb( | |
32 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc); | |
33 | |
34 extern void srcover_srgb_srgb( | 35 extern void srcover_srgb_srgb( |
35 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc); | 36 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc); |
36 } | 37 } |
37 | 38 |
38 #if defined(SK_CPU_X86) && !defined(SK_BUILD_NO_OPTS) | 39 #if defined(SK_CPU_X86) && !defined(SK_BUILD_NO_OPTS) |
39 namespace sk_sse41 { | 40 namespace sk_sse41 { |
40 extern void srcover_srgb_srgb( | 41 extern void srcover_srgb_srgb( |
41 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc); | 42 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc); |
42 } | 43 } |
43 #endif | 44 #endif |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 SkASSERTF(pixmap.colorType() == kN32_SkColorType, "colorType: %d", pixmap.co
lorType()); | 78 SkASSERTF(pixmap.colorType() == kN32_SkColorType, "colorType: %d", pixmap.co
lorType()); |
78 SkASSERT(pixmap.alphaType() != kUnpremul_SkAlphaType); | 79 SkASSERT(pixmap.alphaType() != kUnpremul_SkAlphaType); |
79 const uint32_t* src = pixmap.addr32(); | 80 const uint32_t* src = pixmap.addr32(); |
80 const int width = pixmap.rowBytesAsPixels(); | 81 const int width = pixmap.rowBytesAsPixels(); |
81 SkASSERT(width > 0); | 82 SkASSERT(width > 0); |
82 SkASSERT(width < 4000); | 83 SkASSERT(width < 4000); |
83 SkAutoTArray<uint32_t> correctDst(width); | 84 SkAutoTArray<uint32_t> correctDst(width); |
84 SkAutoTArray<uint32_t> testDst(width); | 85 SkAutoTArray<uint32_t> testDst(width); |
85 | 86 |
86 for (int y = 0; y < pixmap.height(); y++) { | 87 for (int y = 0; y < pixmap.height(); y++) { |
87 memset(correctDst.get(), 0, width * sizeof(uint32_t)); | 88 sk_bzero(correctDst.get(), width * sizeof(uint32_t)); |
88 memset(testDst.get(), 0, width * sizeof(uint32_t)); | 89 sk_bzero(testDst.get(), width * sizeof(uint32_t)); |
89 sk_default::brute_force_srcover_srgb_srgb(correctDst.get(), src, width,
width); | 90 brute_force_srcover_srgb_srgb(correctDst.get(), src, width, width); |
90 blender(testDst.get(), src, width, width); | 91 blender(testDst.get(), src, width, width); |
91 for (int x = 0; x < width; x++) { | 92 for (int x = 0; x < width; x++) { |
92 REPORTER_ASSERT_MESSAGE( | 93 REPORTER_ASSERT_MESSAGE( |
93 reporter, correctDst[x] == testDst[x], | 94 reporter, correctDst[x] == testDst[x], |
94 missmatch_message(resourceName, name, x, y, src[x], correctDst[x
], testDst[x])); | 95 missmatch_message(resourceName, name, x, y, src[x], correctDst[x
], testDst[x])); |
95 if (correctDst[x] != testDst[x]) break; | 96 if (correctDst[x] != testDst[x]) break; |
96 } | 97 } |
97 src += width; | 98 src += width; |
98 } | 99 } |
99 } | 100 } |
100 | 101 |
101 DEF_TEST(SkBlend_optsCheck, reporter) { | 102 DEF_TEST(SkBlend_optsCheck, reporter) { |
102 std::vector<Spec> specs = { | 103 std::vector<Spec> specs = { |
103 Spec{sk_default::trivial_srcover_srgb_srgb, "trivial"}, | |
104 Spec{sk_default::best_non_simd_srcover_srgb_srgb, "best_non_simd"}, | |
105 Spec{sk_default::srcover_srgb_srgb, "default"}, | 104 Spec{sk_default::srcover_srgb_srgb, "default"}, |
106 }; | 105 }; |
107 #if defined(SK_CPU_X86) && !defined(SK_BUILD_NO_OPTS) | 106 #if defined(SK_CPU_X86) && !defined(SK_BUILD_NO_OPTS) |
108 if (SkCpu::Supports(SkCpu::SSE41)) { | 107 if (SkCpu::Supports(SkCpu::SSE41)) { |
109 specs.push_back(Spec{sk_sse41::srcover_srgb_srgb, "sse41", }); | 108 specs.push_back(Spec{sk_sse41::srcover_srgb_srgb, "sse41", }); |
110 } | 109 } |
111 #endif | 110 #endif |
112 | 111 |
113 std::vector<std::string> testResources = { | 112 std::vector<std::string> testResources = { |
114 "yellow_rose", "baby_tux", "plane", "mandrill_512", "iconstrip" | 113 "yellow_rose", "baby_tux", "plane", "mandrill_512", "iconstrip" |
115 }; | 114 }; |
116 | 115 |
117 for (auto& spec : specs) { | 116 for (auto& spec : specs) { |
118 for (auto& resourceName : testResources) { | 117 for (auto& resourceName : testResources) { |
119 test_blender(spec, resourceName, reporter); | 118 test_blender(spec, resourceName, reporter); |
120 } | 119 } |
121 } | 120 } |
122 } | 121 } |
123 | 122 |
124 | |
125 | |
126 DEF_TEST(SkBlend_optsSqrtCheck, reporter) { | 123 DEF_TEST(SkBlend_optsSqrtCheck, reporter) { |
127 for (int c = 0; c < 256; c++) { | 124 for (int c = 0; c < 256; c++) { |
128 Sk4f i{(float)c}; | 125 Sk4f i{(float)c}; |
129 Sk4f ii = i * i; | 126 Sk4f ii = i * i; |
130 Sk4f s = ii.sqrt() + 0.5f; | 127 Sk4f s = ii.sqrt() + 0.5f; |
131 Sk4f sf = s.floor(); | 128 Sk4f sf = s.floor(); |
132 REPORTER_ASSERT_MESSAGE( | 129 REPORTER_ASSERT_MESSAGE( |
133 reporter, i[0] == sf[0], SkStringPrintf("i: %f, s: %f", i[0], sf[0])
); | 130 reporter, i[0] == sf[0], SkStringPrintf("i: %f, s: %f", i[0], sf[0])
); |
134 } | 131 } |
135 } | 132 } |
OLD | NEW |