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

Side by Side Diff: tests/SkBlend_optsTest.cpp

Issue 1939513002: Add specialized sRGB blitter for SkOpts (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix bad assert. Created 4 years, 7 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_sse41.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
(Empty)
1 /*
2 * Copyright 2016 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 #include <string>
9 #include <tuple>
10 #include <vector>
11 #include "Resources.h"
12 #include "SkCpu.h"
13 #include "SkImage.h"
14 #include "SkImage_Base.h"
15 #include "SkOpts.h"
16 #include "SkNx.h"
17 #include "Test.h"
18 #include "../include/core/SkImageInfo.h"
19
20 typedef void (*Blender)(uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc);
21
22 namespace sk_default {
23 extern void brute_force_srcover_srgb_srgb(
24 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc);
25 }
26
27 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 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc);
36 }
37
38 #if defined(SK_CPU_X86) && !defined(SK_BUILD_FOR_IOS)
39 namespace sk_sse41 {
40 extern void srcover_srgb_srgb(
41 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc);
42 }
43 #endif
44
45 static SkString missmatch_message(std::string resourceName, std::string name, in t x, int y,
46 uint32_t src, uint32_t good, uint32_t bad) {
47 return SkStringPrintf(
48 "%s - %s missmatch at %d, %d src: %08x good: %08x bad: %08x",
49 resourceName.c_str(), name.c_str(), x, y, src, good, bad);
50 }
51
52 using Spec = std::tuple<Blender, std::string>;
53
54 static void test_blender(
55 Spec spec,
56 std::string resourceName,
57 skiatest::Reporter* reporter)
58 {
59 Blender blender;
60 std::string name;
61 std::tie(blender, name) = spec;
62
63 std::string fileName = resourceName + ".png";
64 sk_sp<SkImage> image = GetResourceAsImage(fileName.c_str());
65 SkASSERT(image != nullptr);
66 if (image == nullptr) {
67 SkFAIL("image is NULL");
68 }
69 SkBitmap bm;
70 if (!as_IB(image)->getROPixels(&bm)) {
71 SkFAIL("Could not read resource");
72 }
73
74 SkPixmap pixmap;
75 bm.peekPixels(&pixmap);
76 SkASSERTF(pixmap.colorType() == kN32_SkColorType, "colorType: %d", pixmap.co lorType());
77 SkASSERT(pixmap.alphaType() != kUnpremul_SkAlphaType);
78 const uint32_t* src = pixmap.addr32();
79 const int width = pixmap.rowBytesAsPixels();
80 SkASSERT(width > 0);
81 SkASSERT(width < 4000);
82 SkAutoTArray<uint32_t> correctDst(width);
83 SkAutoTArray<uint32_t> testDst(width);
84
85 for (int y = 0; y < pixmap.height(); y++) {
86 memset(correctDst.get(), 0, width * sizeof(uint32_t));
87 memset(testDst.get(), 0, width * sizeof(uint32_t));
88 sk_default::brute_force_srcover_srgb_srgb(correctDst.get(), src, width, width);
89 blender(testDst.get(), src, width, width);
90 for (int x = 0; x < width; x++) {
91 REPORTER_ASSERT_MESSAGE(
92 reporter, correctDst[x] == testDst[x],
93 missmatch_message(resourceName, name, x, y, src[x], correctDst[x ], testDst[x]));
94 if (correctDst[x] != testDst[x]) break;
95 }
96 src += width;
97 }
98 }
99
100 DEF_TEST(SkBlend_optsCheck, reporter) {
101 std::vector<Spec> specs = {
102 Spec{sk_default::trivial_srcover_srgb_srgb, "trivial"},
103 Spec{sk_default::best_non_simd_srcover_srgb_srgb, "best_non_simd"},
104 Spec{sk_default::srcover_srgb_srgb, "default"},
105 };
106 #if defined(SK_CPU_X86) && !defined(SK_BUILD_FOR_IOS)
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 = {
113 "yellow_rose", "baby_tux", "plane", "mandrill_512", "iconstrip"
114 };
115
116 for (auto& spec : specs) {
117 for (auto& resourceName : testResources) {
118 test_blender(spec, resourceName, reporter);
119 }
120 }
121 }
122
123
124
125 DEF_TEST(SkBlend_optsSqrtCheck, reporter) {
126 for (int c = 0; c < 256; c++) {
127 Sk4f i{(float)c};
128 Sk4f ii = i * i;
129 Sk4f s = ii.sqrt() + 0.5f;
130 Sk4f sf = s.floor();
131 REPORTER_ASSERT_MESSAGE(
132 reporter, i[0] == sf[0], SkStringPrintf("i: %f, s: %f", i[0], sf[0]) );
133 }
134 }
OLDNEW
« no previous file with comments | « src/opts/SkOpts_sse41.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698