| OLD | NEW |
| (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 "Test.h" | |
| 17 #include "../include/core/SkImageInfo.h" | |
| 18 | |
| 19 typedef void (*Blender)(uint32_t* dst, const uint32_t* const srcStart, int ndst,
const int nsrc); | |
| 20 | |
| 21 namespace sk_default { | |
| 22 extern void brute_force_srcover_srgb_srgb( | |
| 23 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc); | |
| 24 } | |
| 25 | |
| 26 namespace sk_default { | |
| 27 extern void trivial_srcover_srgb_srgb( | |
| 28 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc); | |
| 29 | |
| 30 extern void best_non_simd_srcover_srgb_srgb( | |
| 31 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc); | |
| 32 | |
| 33 extern void srcover_srgb_srgb( | |
| 34 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc); | |
| 35 } | |
| 36 | |
| 37 #if defined(SK_CPU_X86) && !defined(SK_BUILD_FOR_IOS) | |
| 38 namespace sk_sse41 { | |
| 39 extern void srcover_srgb_srgb( | |
| 40 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc); | |
| 41 } | |
| 42 #endif | |
| 43 | |
| 44 static SkString missmatch_message(std::string resourceName, std::string name, in
t x, int y, | |
| 45 uint32_t src, uint32_t good, uint32_t bad) { | |
| 46 return SkStringPrintf( | |
| 47 "%s - %s missmatch at %d, %d src: %08x good: %08x bad: %08x", | |
| 48 resourceName.c_str(), name.c_str(), x, y, src, good, bad); | |
| 49 } | |
| 50 | |
| 51 using Spec = std::tuple<Blender, std::string>; | |
| 52 | |
| 53 static void test_blender( | |
| 54 Spec spec, | |
| 55 std::string resourceName, | |
| 56 skiatest::Reporter* reporter) | |
| 57 { | |
| 58 Blender blender; | |
| 59 std::string name; | |
| 60 std::tie(blender, name) = spec; | |
| 61 | |
| 62 std::string fileName = resourceName + ".png"; | |
| 63 sk_sp<SkImage> image = GetResourceAsImage(fileName.c_str()); | |
| 64 SkASSERT(image != nullptr); | |
| 65 if (image == nullptr) { | |
| 66 SkFAIL("image is NULL"); | |
| 67 } | |
| 68 SkBitmap bm; | |
| 69 if (!as_IB(image)->getROPixels(&bm)) { | |
| 70 SkFAIL("Could not read resource"); | |
| 71 } | |
| 72 | |
| 73 SkPixmap pixmap; | |
| 74 bm.peekPixels(&pixmap); | |
| 75 SkASSERTF(pixmap.colorType() == kN32_SkColorType, "colorType: %d", pixmap.co
lorType()); | |
| 76 SkASSERT(pixmap.alphaType() != kUnpremul_SkAlphaType); | |
| 77 const uint32_t* src = pixmap.addr32(); | |
| 78 const int width = pixmap.rowBytesAsPixels(); | |
| 79 SkASSERT(width > 0); | |
| 80 SkASSERT(width < 4000); | |
| 81 SkAutoTArray<uint32_t> correctDst(width); | |
| 82 SkAutoTArray<uint32_t> testDst(width); | |
| 83 | |
| 84 for (int y = 0; y < pixmap.height(); y++) { | |
| 85 memset(correctDst.get(), 0, width * sizeof(uint32_t)); | |
| 86 memset(testDst.get(), 0, width * sizeof(uint32_t)); | |
| 87 sk_default::brute_force_srcover_srgb_srgb(correctDst.get(), src, width,
width); | |
| 88 blender(testDst.get(), src, width, width); | |
| 89 for (int x = 0; x < width; x++) { | |
| 90 REPORTER_ASSERT_MESSAGE( | |
| 91 reporter, correctDst[x] == testDst[x], | |
| 92 missmatch_message(resourceName, name, x, y, src[x], correctDst[x
], testDst[x])); | |
| 93 if (correctDst[x] != testDst[x]) break; | |
| 94 } | |
| 95 src += width; | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 DEF_TEST(SkBlend_optsCheck, reporter) { | |
| 100 std::vector<Spec> specs = { | |
| 101 Spec{sk_default::trivial_srcover_srgb_srgb, "trivial"}, | |
| 102 Spec{sk_default::best_non_simd_srcover_srgb_srgb, "best_non_simd"}, | |
| 103 Spec{sk_default::srcover_srgb_srgb, "default"}, | |
| 104 }; | |
| 105 #if defined(SK_CPU_X86) && !defined(SK_BUILD_FOR_IOS) | |
| 106 if (SkCpu::Supports(SkCpu::SSE41)) { | |
| 107 specs.push_back(Spec{sk_sse41::srcover_srgb_srgb, "sse41", }); | |
| 108 } | |
| 109 #endif | |
| 110 | |
| 111 std::vector<std::string> testResources = { | |
| 112 "yellow_rose", "baby_tux", "plane", "mandrill_512", "iconstrip" | |
| 113 }; | |
| 114 | |
| 115 for (auto& spec : specs) { | |
| 116 for (auto& resourceName : testResources) { | |
| 117 test_blender(spec, resourceName, reporter); | |
| 118 } | |
| 119 } | |
| 120 } | |
| OLD | NEW |