OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkBenchmark.h" | 8 #include "SkBenchmark.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
11 #include "SkRandom.h" | 11 #include "SkRandom.h" |
12 #include "SkString.h" | 12 #include "SkString.h" |
13 #include "SkShader.h" | 13 #include "SkShader.h" |
14 | 14 |
15 enum VertFlags { | 15 enum VertFlags { |
16 kColors_VertFlag, | 16 kColors_VertFlag, |
17 kTexture_VertFlag, | 17 kTexture_VertFlag, |
18 }; | 18 }; |
19 | 19 |
20 class VertBench : public SkBenchmark { | 20 class VertBench : public SkBenchmark { |
21 SkString fName; | 21 SkString fName; |
22 enum { | 22 enum { |
23 W = 640, | 23 W = 640, |
24 H = 480, | 24 H = 480, |
25 ROW = 20, | 25 ROW = 20, |
26 COL = 20, | 26 COL = 20, |
27 PTS = (ROW + 1) * (COL + 1), | 27 PTS = (ROW + 1) * (COL + 1), |
28 IDX = ROW * COL * 6, | 28 IDX = ROW * COL * 6, |
29 N = SkBENCHLOOP(10) | |
30 }; | 29 }; |
31 | 30 |
32 SkPoint fPts[PTS]; | 31 SkPoint fPts[PTS]; |
33 SkColor fColors[PTS]; | 32 SkColor fColors[PTS]; |
34 uint16_t fIdx[IDX]; | 33 uint16_t fIdx[IDX]; |
35 | 34 |
36 static void load_2_tris(uint16_t idx[], int x, int y, int rb) { | 35 static void load_2_tris(uint16_t idx[], int x, int y, int rb) { |
37 int n = y * rb + x; | 36 int n = y * rb + x; |
38 idx[0] = n; idx[1] = n + 1; idx[2] = rb + n + 1; | 37 idx[0] = n; idx[1] = n + 1; idx[2] = rb + n + 1; |
39 idx[3] = n; idx[4] = rb + n + 1; idx[5] = n + rb; | 38 idx[3] = n; idx[4] = rb + n + 1; idx[5] = n + rb; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 74 |
76 fName.set("verts"); | 75 fName.set("verts"); |
77 } | 76 } |
78 | 77 |
79 protected: | 78 protected: |
80 virtual const char* onGetName() { return fName.c_str(); } | 79 virtual const char* onGetName() { return fName.c_str(); } |
81 virtual void onDraw(SkCanvas* canvas) { | 80 virtual void onDraw(SkCanvas* canvas) { |
82 SkPaint paint; | 81 SkPaint paint; |
83 this->setupPaint(&paint); | 82 this->setupPaint(&paint); |
84 | 83 |
85 for (int i = 0; i < N; i++) { | 84 for (int i = 0; i < this->getLoops(); i++) { |
86 canvas->drawVertices(SkCanvas::kTriangles_VertexMode, PTS, | 85 canvas->drawVertices(SkCanvas::kTriangles_VertexMode, PTS, |
87 fPts, NULL, fColors, NULL, fIdx, IDX, paint); | 86 fPts, NULL, fColors, NULL, fIdx, IDX, paint); |
88 } | 87 } |
89 } | 88 } |
90 private: | 89 private: |
91 typedef SkBenchmark INHERITED; | 90 typedef SkBenchmark INHERITED; |
92 }; | 91 }; |
93 | 92 |
94 /////////////////////////////////////////////////////////////////////////////// | 93 /////////////////////////////////////////////////////////////////////////////// |
95 | 94 |
96 static SkBenchmark* Fact(void* p) { return SkNEW_ARGS(VertBench, (p)); } | 95 static SkBenchmark* Fact(void* p) { return SkNEW_ARGS(VertBench, (p)); } |
97 | 96 |
98 static BenchRegistry gReg(Fact); | 97 static BenchRegistry gReg(Fact); |
OLD | NEW |