| 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 <tuple> | 8 #include <tuple> |
| 9 | 9 |
| 10 #include "Benchmark.h" | 10 #include "Benchmark.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 static void BlendN(uint32_t* dst, int count, const uint32_t* src) { | 86 static void BlendN(uint32_t* dst, int count, const uint32_t* src) { |
| 87 sk_sse41::srcover_srgb_srgb(dst, src, count, count); | 87 sk_sse41::srcover_srgb_srgb(dst, src, count, count); |
| 88 } | 88 } |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 91 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 92 | 92 |
| 93 template <typename Blender> | 93 template <typename Blender> |
| 94 class LinearSrcOverBench : public Benchmark { | 94 class LinearSrcOverBench : public Benchmark { |
| 95 public: | 95 public: |
| 96 LinearSrcOverBench(const char* fileName) { | 96 LinearSrcOverBench(const char* fileName) : fFileName(fileName) { |
| 97 fName = "LinearSrcOver"; | 97 fName = "LinearSrcOver"; |
| 98 fName.append(fileName); | 98 fName.append(fileName); |
| 99 fName.append(Blender::Name()); | 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 } | 100 } |
| 111 | 101 |
| 112 protected: | 102 protected: |
| 113 bool isSuitableFor(Backend backend) override { | 103 bool isSuitableFor(Backend backend) override { |
| 114 return backend == kNonRendering_Backend && Blender::WorksOnCpu(); | 104 return backend == kNonRendering_Backend && Blender::WorksOnCpu(); |
| 115 } | 105 } |
| 116 const char* onGetName() override { return fName.c_str(); } | 106 const char* onGetName() override { return fName.c_str(); } |
| 107 |
| 108 void onPreDraw(SkCanvas*) override { |
| 109 if (!fPixmap.addr()) { |
| 110 sk_sp<SkImage> image = GetResourceAsImage(fFileName.c_str()); |
| 111 SkBitmap bm; |
| 112 if (!as_IB(image)->getROPixels(&bm)) { |
| 113 SkFAIL("Could not read resource"); |
| 114 } |
| 115 bm.peekPixels(&fPixmap); |
| 116 fCount = fPixmap.rowBytesAsPixels(); |
| 117 fDst.reset(fCount); |
| 118 memset(fDst.get(), 0, fPixmap.rowBytes()); |
| 119 } |
| 120 } |
| 121 |
| 117 void onDraw(int loops, SkCanvas*) override { | 122 void onDraw(int loops, SkCanvas*) override { |
| 118 SkASSERT(fPixmap.colorType() == kN32_SkColorType); | 123 SkASSERT(fPixmap.colorType() == kN32_SkColorType); |
| 119 | 124 |
| 120 const int width = fPixmap.rowBytesAsPixels(); | 125 const int width = fPixmap.rowBytesAsPixels(); |
| 121 | 126 |
| 122 for (int i = 0; i < loops * INNER_LOOPS; ++i) { | 127 for (int i = 0; i < loops * INNER_LOOPS; ++i) { |
| 123 const uint32_t* src = fPixmap.addr32(); | 128 const uint32_t* src = fPixmap.addr32(); |
| 124 for (int y = 0; y < fPixmap.height(); y++) { | 129 for (int y = 0; y < fPixmap.height(); y++) { |
| 125 Blender::BlendN(fDst.get(), width, src); | 130 Blender::BlendN(fDst.get(), width, src); |
| 126 src += width; | 131 src += width; |
| 127 } | 132 } |
| 128 } | 133 } |
| 129 } | 134 } |
| 130 | 135 |
| 131 void onPostDraw(SkCanvas*) override { | 136 void onPostDraw(SkCanvas*) override { |
| 132 // Make sure the compiler does not optimize away the operation. | 137 // Make sure the compiler does not optimize away the operation. |
| 133 volatile uint32_t v = 0; | 138 volatile uint32_t v = 0; |
| 134 for (int i = 0; i < fCount; i++) { | 139 for (int i = 0; i < fCount; i++) { |
| 135 v ^= fDst[i]; | 140 v ^= fDst[i]; |
| 136 } | 141 } |
| 137 } | 142 } |
| 138 | 143 |
| 139 private: | 144 private: |
| 140 int fCount; | 145 int fCount; |
| 141 SkAutoTArray<uint32_t> fDst; | 146 SkAutoTArray<uint32_t> fDst; |
| 147 SkString fFileName; |
| 142 SkString fName; | 148 SkString fName; |
| 143 SkPixmap fPixmap; | 149 SkPixmap fPixmap; |
| 144 | 150 |
| 145 typedef Benchmark INHERITED; | 151 typedef Benchmark INHERITED; |
| 146 }; | 152 }; |
| 147 | 153 |
| 148 #if defined(SK_CPU_X86) && !defined(SK_BUILD_FOR_IOS) | 154 #if defined(SK_CPU_X86) && !defined(SK_BUILD_FOR_IOS) |
| 149 #define BENCHES(fileName)
\ | 155 #define BENCHES(fileName)
\ |
| 150 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsBruteForce>(fileName); )
\ | 156 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsBruteForce>(fileName); )
\ |
| 151 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsTrivial>(fileName); )
\ | 157 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsTrivial>(fileName); )
\ |
| 152 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsNonSimdCore>(fileName); )
\ | 158 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsNonSimdCore>(fileName); )
\ |
| 153 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsDefault>(fileName); )
\ | 159 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsDefault>(fileName); )
\ |
| 154 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsSSE41>(fileName); ) | 160 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsSSE41>(fileName); ) |
| 155 #else | 161 #else |
| 156 #define BENCHES(fileName)
\ | 162 #define BENCHES(fileName)
\ |
| 157 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsBruteForce>(fileName); )
\ | 163 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsBruteForce>(fileName); )
\ |
| 158 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsTrivial>(fileName); )
\ | 164 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsTrivial>(fileName); )
\ |
| 159 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsNonSimdCore>(fileName); )
\ | 165 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsNonSimdCore>(fileName); )
\ |
| 160 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsDefault>(fileName); ) | 166 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsDefault>(fileName); ) |
| 161 #endif | 167 #endif |
| 162 | 168 |
| 163 BENCHES("yellow_rose.png") | 169 BENCHES("yellow_rose.png") |
| 164 BENCHES("baby_tux.png") | 170 BENCHES("baby_tux.png") |
| 165 BENCHES("plane.png") | 171 BENCHES("plane.png") |
| 166 BENCHES("mandrill_512.png") | 172 BENCHES("mandrill_512.png") |
| 167 BENCHES("iconstrip.png") | 173 BENCHES("iconstrip.png") |
| OLD | NEW |