| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #include "Benchmark.h" | 7 #include "Benchmark.h" |
| 8 #include "SkBitmap.h" | |
| 9 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 10 #include "SkColorPriv.h" | |
| 11 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
| 12 #include "SkPaint.h" | 10 #include "SkPaint.h" |
| 13 #include "SkPatchUtils.h" | 11 #include "SkPatchUtils.h" |
| 14 #include "SkRandom.h" | |
| 15 #include "SkShader.h" | |
| 16 #include "SkString.h" | 12 #include "SkString.h" |
| 17 #include "SkTArray.h" | |
| 18 | 13 |
| 19 class PatchBench : public Benchmark { | 14 class PatchBench : public Benchmark { |
| 20 | 15 |
| 21 public: | 16 public: |
| 22 | 17 |
| 23 enum VertexMode { | 18 enum VertexMode { |
| 24 kNone_VertexMode, | 19 kNone_VertexMode, |
| 25 kColors_VertexMode, | 20 kColors_VertexMode, |
| 26 kTexCoords_VertexMode, | 21 kTexCoords_VertexMode, |
| 27 kBoth_VertexMode | 22 kBoth_VertexMode |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 case kNone_VertexMode: | 80 case kNone_VertexMode: |
| 86 vertexMode.set("meshlines"); | 81 vertexMode.set("meshlines"); |
| 87 break; | 82 break; |
| 88 case kColors_VertexMode: | 83 case kColors_VertexMode: |
| 89 vertexMode.set("colors"); | 84 vertexMode.set("colors"); |
| 90 break; | 85 break; |
| 91 case kTexCoords_VertexMode: | 86 case kTexCoords_VertexMode: |
| 92 vertexMode.set("texs"); | 87 vertexMode.set("texs"); |
| 93 break; | 88 break; |
| 94 case kBoth_VertexMode: | 89 case kBoth_VertexMode: |
| 95 vertexMode.set("colors&texs"); | 90 vertexMode.set("colors_texs"); |
| 96 break; | 91 break; |
| 97 default: | 92 default: |
| 98 break; | 93 break; |
| 99 } | 94 } |
| 100 SkString type; | 95 SkString type; |
| 101 this->appendName(&type); | 96 this->appendName(&type); |
| 102 fName.printf("patch_%s_%s_[%f,%f]", type.c_str(), vertexMode.c_str(), | 97 fName.printf("patch_%s_%s_[%f,%f]", type.c_str(), vertexMode.c_str(), |
| 103 fScale.x(), fScale.y()); | 98 fScale.x(), fScale.y()); |
| 104 return fName.c_str(); | 99 return fName.c_str(); |
| 105 } | 100 } |
| 106 | 101 |
| 107 virtual void preDraw() { | 102 virtual void onPreDraw() { |
| 108 | |
| 109 } | |
| 110 | |
| 111 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | |
| 112 | |
| 113 this->setCubics(); | 103 this->setCubics(); |
| 114 this->setColors(); | 104 this->setColors(); |
| 115 this->setTexCoords(); | 105 this->setTexCoords(); |
| 116 this->setupPaint(&fPaint); | 106 this->setupPaint(&fPaint); |
| 117 switch (fVertexMode) { | 107 switch (fVertexMode) { |
| 118 case kTexCoords_VertexMode: | 108 case kTexCoords_VertexMode: |
| 119 case kBoth_VertexMode: | 109 case kBoth_VertexMode: |
| 120 fPaint.setShader(this->createShader())->unref(); | 110 fPaint.setShader(this->createShader())->unref(); |
| 121 break; | 111 break; |
| 122 default: | 112 default: |
| 123 fPaint.setShader(NULL); | 113 fPaint.setShader(NULL); |
| 124 break; | 114 break; |
| 125 } | 115 } |
| 116 } |
| 126 | 117 |
| 118 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 127 canvas->scale(fScale.x(), fScale.y()); | 119 canvas->scale(fScale.x(), fScale.y()); |
| 128 for (int i = 0; i < loops; i++) { | 120 for (int i = 0; i < loops; i++) { |
| 129 switch (fVertexMode) { | 121 switch (fVertexMode) { |
| 130 case kNone_VertexMode: | 122 case kNone_VertexMode: |
| 131 canvas->drawPatch(fCubics, NULL, NULL, NULL, fPaint); | 123 canvas->drawPatch(fCubics, NULL, NULL, NULL, fPaint); |
| 132 break; | 124 break; |
| 133 case kColors_VertexMode: | 125 case kColors_VertexMode: |
| 134 canvas->drawPatch(fCubics, fColors, NULL, NULL, fPaint); | 126 canvas->drawPatch(fCubics, fColors, NULL, NULL, fPaint); |
| 135 break; | 127 break; |
| 136 case kTexCoords_VertexMode: | 128 case kTexCoords_VertexMode: |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 DEF_BENCH( return new LoopPatchBench(SkVector::Make(1.0f, 1.0f), | 308 DEF_BENCH( return new LoopPatchBench(SkVector::Make(1.0f, 1.0f), |
| 317 PatchBench::kBoth_VertexMode); ) | 309 PatchBench::kBoth_VertexMode); ) |
| 318 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f), | 310 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f), |
| 319 PatchBench::kNone_VertexMode); ) | 311 PatchBench::kNone_VertexMode); ) |
| 320 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f), | 312 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f), |
| 321 PatchBench::kColors_VertexMode); ) | 313 PatchBench::kColors_VertexMode); ) |
| 322 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f), | 314 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f), |
| 323 PatchBench::kTexCoords_VertexMode); ) | 315 PatchBench::kTexCoords_VertexMode); ) |
| 324 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f), | 316 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f), |
| 325 PatchBench::kBoth_VertexMode); ) | 317 PatchBench::kBoth_VertexMode); ) |
| OLD | NEW |