Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: tests/SkBlend_optsTest.cpp

Issue 2145833002: Update SkOpts namespaces. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: static, just in case Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/opts/SkOpts_ssse3.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
(...skipping 13 matching lines...) Expand all
24 while (ndst > 0) { 24 while (ndst > 0) {
25 int n = SkTMin(ndst, nsrc); 25 int n = SkTMin(ndst, nsrc);
26 26
27 for (int i = 0; i < n; i++) { 27 for (int i = 0; i < n; i++) {
28 srcover_blend_srgb8888_srgb_1(dst++, srgb_to_linear(to_4f(src[i]))); 28 srcover_blend_srgb8888_srgb_1(dst++, srgb_to_linear(to_4f(src[i])));
29 } 29 }
30 ndst -= n; 30 ndst -= n;
31 } 31 }
32 } 32 }
33 33
34 namespace sk_default { 34 static SkString mismatch_message(std::string resourceName, int x, int y,
35 extern void srcover_srgb_srgb( 35 uint32_t src, uint32_t good, uint32_t bad) {
36 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc); 36 return SkStringPrintf(
37 "%s - missmatch at %d, %d src: %08x good: %08x bad: %08x",
38 resourceName.c_str(), x, y, src, good, bad);
37 } 39 }
38 40
39 #if defined(SK_CPU_X86) && !defined(SK_BUILD_NO_OPTS) 41 static void test_blender(std::string resourceName, skiatest::Reporter* reporter) {
40 namespace sk_sse41 {
41 extern void srcover_srgb_srgb(
42 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc);
43 }
44 #endif
45
46 static SkString missmatch_message(std::string resourceName, std::string name, in t x, int y,
47 uint32_t src, uint32_t good, uint32_t bad) {
48 return SkStringPrintf(
49 "%s - %s missmatch at %d, %d src: %08x good: %08x bad: %08x",
50 resourceName.c_str(), name.c_str(), x, y, src, good, bad);
51 }
52
53 using Spec = std::tuple<Blender, std::string>;
54
55 static void test_blender(
56 Spec spec,
57 std::string resourceName,
58 skiatest::Reporter* reporter)
59 {
60 Blender blender;
61 std::string name;
62 std::tie(blender, name) = spec;
63
64 std::string fileName = resourceName + ".png"; 42 std::string fileName = resourceName + ".png";
65 sk_sp<SkImage> image = GetResourceAsImage(fileName.c_str()); 43 sk_sp<SkImage> image = GetResourceAsImage(fileName.c_str());
66 if (image == nullptr) { 44 if (image == nullptr) {
67 ERRORF(reporter, "image is NULL"); 45 ERRORF(reporter, "image is NULL");
68 return; 46 return;
69 } 47 }
70 SkBitmap bm; 48 SkBitmap bm;
71 if (!as_IB(image)->getROPixels(&bm)) { 49 if (!as_IB(image)->getROPixels(&bm)) {
72 ERRORF(reporter, "Could not read resource"); 50 ERRORF(reporter, "Could not read resource");
73 return; 51 return;
74 } 52 }
75 53
76 SkPixmap pixmap; 54 SkPixmap pixmap;
77 bm.peekPixels(&pixmap); 55 bm.peekPixels(&pixmap);
78 SkASSERTF(pixmap.colorType() == kN32_SkColorType, "colorType: %d", pixmap.co lorType()); 56 SkASSERTF(pixmap.colorType() == kN32_SkColorType, "colorType: %d", pixmap.co lorType());
79 SkASSERT(pixmap.alphaType() != kUnpremul_SkAlphaType); 57 SkASSERT(pixmap.alphaType() != kUnpremul_SkAlphaType);
80 const uint32_t* src = pixmap.addr32(); 58 const uint32_t* src = pixmap.addr32();
81 const int width = pixmap.rowBytesAsPixels(); 59 const int width = pixmap.rowBytesAsPixels();
82 SkASSERT(width > 0); 60 SkASSERT(width > 0);
83 SkASSERT(width < 4000); 61 SkASSERT(width < 4000);
84 SkAutoTArray<uint32_t> correctDst(width); 62 SkAutoTArray<uint32_t> correctDst(width);
85 SkAutoTArray<uint32_t> testDst(width); 63 SkAutoTArray<uint32_t> testDst(width);
86 64
87 for (int y = 0; y < pixmap.height(); y++) { 65 for (int y = 0; y < pixmap.height(); y++) {
88 sk_bzero(correctDst.get(), width * sizeof(uint32_t)); 66 sk_bzero(correctDst.get(), width * sizeof(uint32_t));
89 sk_bzero(testDst.get(), width * sizeof(uint32_t)); 67 sk_bzero(testDst.get(), width * sizeof(uint32_t));
90 brute_force_srcover_srgb_srgb(correctDst.get(), src, width, width); 68 brute_force_srcover_srgb_srgb(correctDst.get(), src, width, width);
91 blender(testDst.get(), src, width, width); 69 SkOpts:: srcover_srgb_srgb( testDst.get(), src, width, width);
92 for (int x = 0; x < width; x++) { 70 for (int x = 0; x < width; x++) {
93 REPORTER_ASSERT_MESSAGE( 71 REPORTER_ASSERT_MESSAGE(
94 reporter, correctDst[x] == testDst[x], 72 reporter, correctDst[x] == testDst[x],
95 missmatch_message(resourceName, name, x, y, src[x], correctDst[x ], testDst[x])); 73 mismatch_message(resourceName, x, y, src[x], correctDst[x], test Dst[x]));
96 if (correctDst[x] != testDst[x]) break; 74 if (correctDst[x] != testDst[x]) break;
97 } 75 }
98 src += width; 76 src += width;
99 } 77 }
100 } 78 }
101 79
102 DEF_TEST(SkBlend_optsCheck, reporter) { 80 DEF_TEST(SkBlend_optsCheck, reporter) {
103 std::vector<Spec> specs = {
104 Spec{sk_default::srcover_srgb_srgb, "default"},
105 };
106 #if defined(SK_CPU_X86) && !defined(SK_BUILD_NO_OPTS)
107 if (SkCpu::Supports(SkCpu::SSE41)) {
108 specs.push_back(Spec{sk_sse41::srcover_srgb_srgb, "sse41", });
109 }
110 #endif
111
112 std::vector<std::string> testResources = { 81 std::vector<std::string> testResources = {
113 "yellow_rose", "baby_tux", "plane", "mandrill_512", "iconstrip" 82 "yellow_rose", "baby_tux", "plane", "mandrill_512", "iconstrip"
114 }; 83 };
115 84
116 for (auto& spec : specs) { 85 for (auto& resourceName : testResources) {
117 for (auto& resourceName : testResources) { 86 test_blender(resourceName, reporter);
118 test_blender(spec, resourceName, reporter);
119 }
120 } 87 }
121 } 88 }
122 89
123 DEF_TEST(SkBlend_optsSqrtCheck, reporter) { 90 DEF_TEST(SkBlend_optsSqrtCheck, reporter) {
124 for (int c = 0; c < 256; c++) { 91 for (int c = 0; c < 256; c++) {
125 Sk4f i{(float)c}; 92 Sk4f i{(float)c};
126 Sk4f ii = i * i; 93 Sk4f ii = i * i;
127 Sk4f s = ii.sqrt() + 0.5f; 94 Sk4f s = ii.sqrt() + 0.5f;
128 Sk4f sf = s.floor(); 95 Sk4f sf = s.floor();
129 REPORTER_ASSERT_MESSAGE( 96 REPORTER_ASSERT_MESSAGE(
130 reporter, i[0] == sf[0], SkStringPrintf("i: %f, s: %f", i[0], sf[0]) ); 97 reporter, i[0] == sf[0], SkStringPrintf("i: %f, s: %f", i[0], sf[0]) );
131 } 98 }
132 } 99 }
OLDNEW
« no previous file with comments | « src/opts/SkOpts_ssse3.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698