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 <tuple> |
| 9 |
| 10 #include "Benchmark.h" |
| 11 #include "Resources.h" |
| 12 #include "SkCpu.h" |
| 13 #include "SkImage.h" |
| 14 #include "SkImage_Base.h" |
| 15 #include "SkNx.h" |
| 16 #include "SkOpts.h" |
| 17 #include "SkString.h" |
| 18 |
| 19 #define INNER_LOOPS 10 |
| 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 class SrcOverVSkOptsBruteForce { |
| 27 public: |
| 28 static SkString Name() { return SkString{"VSkOptsBruteForce"}; } |
| 29 static bool WorksOnCpu() { return true; } |
| 30 static void BlendN(uint32_t* dst, int count, const uint32_t* src) { |
| 31 sk_default::brute_force_srcover_srgb_srgb(dst, src, count, count); |
| 32 } |
| 33 }; |
| 34 |
| 35 namespace sk_default { |
| 36 extern void trivial_srcover_srgb_srgb( |
| 37 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc); |
| 38 } |
| 39 |
| 40 class SrcOverVSkOptsTrivial { |
| 41 public: |
| 42 static SkString Name() { return SkString{"VSkOptsTrivial"}; } |
| 43 static bool WorksOnCpu() { return true; } |
| 44 static void BlendN(uint32_t* dst, int count, const uint32_t* src) { |
| 45 sk_default::trivial_srcover_srgb_srgb(dst, src, count, count); |
| 46 } |
| 47 }; |
| 48 |
| 49 namespace sk_default { |
| 50 extern void best_non_simd_srcover_srgb_srgb( |
| 51 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc); |
| 52 } |
| 53 |
| 54 class SrcOverVSkOptsNonSimdCore { |
| 55 public: |
| 56 static SkString Name() { return SkString{"VSkOptsNonSimdCore"}; } |
| 57 static bool WorksOnCpu() { return true; } |
| 58 static void BlendN(uint32_t* dst, int count, const uint32_t* src) { |
| 59 sk_default::best_non_simd_srcover_srgb_srgb(dst, src, count, count); |
| 60 } |
| 61 }; |
| 62 |
| 63 namespace sk_default { |
| 64 extern void srcover_srgb_srgb( |
| 65 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc); |
| 66 } |
| 67 |
| 68 class SrcOverVSkOptsDefault { |
| 69 public: |
| 70 static SkString Name() { return SkString{"VSkOptsDefault"}; } |
| 71 static bool WorksOnCpu() { return true; } |
| 72 static void BlendN(uint32_t* dst, int count, const uint32_t* src) { |
| 73 sk_default::srcover_srgb_srgb(dst, src, count, count); |
| 74 } |
| 75 }; |
| 76 |
| 77 namespace sk_sse41 { |
| 78 extern void srcover_srgb_srgb( |
| 79 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc); |
| 80 } |
| 81 |
| 82 class SrcOverVSkOptsSSE41 { |
| 83 public: |
| 84 static SkString Name() { return SkString{"VSkOptsSSE41"}; } |
| 85 static bool WorksOnCpu() { return SkCpu::Supports(SkCpu::SSE41); } |
| 86 static void BlendN(uint32_t* dst, int count, const uint32_t* src) { |
| 87 sk_sse41::srcover_srgb_srgb(dst, src, count, count); |
| 88 } |
| 89 }; |
| 90 |
| 91 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 92 |
| 93 template <typename Blender> |
| 94 class LinearSrcOverBench : public Benchmark { |
| 95 public: |
| 96 LinearSrcOverBench(const char* fileName) { |
| 97 fName = "LinearSrcOver"; |
| 98 fName.append(fileName); |
| 99 fName.append(Blender::Name()); |
| 100 |
| 101 sk_sp<SkImage> image = GetResourceAsImage(fileName); |
| 102 SkBitmap bm; |
| 103 if (!as_IB(image)->getROPixels(&bm)) { |
| 104 SkFAIL("Could not read resource"); |
| 105 } |
| 106 bm.peekPixels(&fPixmap); |
| 107 fCount = fPixmap.rowBytesAsPixels(); |
| 108 fDst.reset(fCount); |
| 109 memset(fDst.get(), 0, fPixmap.rowBytes()); |
| 110 } |
| 111 |
| 112 protected: |
| 113 bool isSuitableFor(Backend backend) override { |
| 114 return backend == kNonRendering_Backend && Blender::WorksOnCpu(); |
| 115 } |
| 116 const char* onGetName() override { return fName.c_str(); } |
| 117 void onDraw(int loops, SkCanvas*) override { |
| 118 SkASSERT(fPixmap.colorType() == kN32_SkColorType); |
| 119 |
| 120 const int width = fPixmap.rowBytesAsPixels(); |
| 121 |
| 122 for (int i = 0; i < loops * INNER_LOOPS; ++i) { |
| 123 const uint32_t* src = fPixmap.addr32(); |
| 124 for (int y = 0; y < fPixmap.height(); y++) { |
| 125 Blender::BlendN(fDst.get(), width, src); |
| 126 src += width; |
| 127 } |
| 128 } |
| 129 } |
| 130 |
| 131 void onPostDraw(SkCanvas*) override { |
| 132 // Make sure the compiler does not optimize away the operation. |
| 133 volatile uint32_t v = 0; |
| 134 for (int i = 0; i < fCount; i++) { |
| 135 v ^= fDst[i]; |
| 136 } |
| 137 } |
| 138 |
| 139 private: |
| 140 int fCount; |
| 141 SkAutoTArray<uint32_t> fDst; |
| 142 SkString fName; |
| 143 SkPixmap fPixmap; |
| 144 |
| 145 typedef Benchmark INHERITED; |
| 146 }; |
| 147 |
| 148 #if defined(SK_CPU_X86) && !defined(SK_BUILD_FOR_IOS) |
| 149 #define BENCHES(fileName)
\ |
| 150 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsBruteForce>(fileName); )
\ |
| 151 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsTrivial>(fileName); )
\ |
| 152 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsNonSimdCore>(fileName); )
\ |
| 153 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsDefault>(fileName); )
\ |
| 154 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsSSE41>(fileName); ) |
| 155 #else |
| 156 #define BENCHES(fileName)
\ |
| 157 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsBruteForce>(fileName); )
\ |
| 158 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsTrivial>(fileName); )
\ |
| 159 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsNonSimdCore>(fileName); )
\ |
| 160 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsDefault>(fileName); ) |
| 161 #endif |
| 162 |
| 163 BENCHES("yellow_rose.png") |
| 164 BENCHES("baby_tux.png") |
| 165 BENCHES("plane.png") |
| 166 BENCHES("mandrill_512.png") |
| 167 BENCHES("iconstrip.png") |
OLD | NEW |