| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "Benchmark.h" | 9 #include "Benchmark.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 #include "SkPaint.h" | 11 #include "SkPaint.h" |
| 12 #include "SkRandom.h" | 12 #include "SkRandom.h" |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * Draws full screen opaque rectangles. It is designed to test any optimizations
in the GPU backend | 15 * Draws full screen opaque rectangles. It is designed to test any optimizations
in the GPU backend |
| 16 * to turn such draws into clears. | 16 * to turn such draws into clears. |
| 17 */ | 17 */ |
| 18 class FSRectBench : public Benchmark { | 18 class FSRectBench : public Benchmark { |
| 19 public: | 19 public: |
| 20 FSRectBench() : fInit(false) { } | 20 FSRectBench() : fInit(false) { } |
| 21 | 21 |
| 22 protected: | 22 protected: |
| 23 virtual const char* onGetName() SK_OVERRIDE { return "fullscreen_rects"; } | 23 const char* onGetName() SK_OVERRIDE { return "fullscreen_rects"; } |
| 24 | 24 |
| 25 virtual void onPreDraw() SK_OVERRIDE { | 25 void onPreDraw() SK_OVERRIDE { |
| 26 if (!fInit) { | 26 if (!fInit) { |
| 27 SkRandom rand; | 27 SkRandom rand; |
| 28 static const SkScalar kMinOffset = 0; | 28 static const SkScalar kMinOffset = 0; |
| 29 static const SkScalar kMaxOffset = 100 * SK_Scalar1; | 29 static const SkScalar kMaxOffset = 100 * SK_Scalar1; |
| 30 static const SkScalar kOffsetRange = kMaxOffset - kMinOffset; | 30 static const SkScalar kOffsetRange = kMaxOffset - kMinOffset; |
| 31 for (int i = 0; i < N; ++i) { | 31 for (int i = 0; i < N; ++i) { |
| 32 fRects[i].fLeft = -kMinOffset - SkScalarMul(rand.nextUScalar1(),
kOffsetRange); | 32 fRects[i].fLeft = -kMinOffset - SkScalarMul(rand.nextUScalar1(),
kOffsetRange); |
| 33 fRects[i].fTop = -kMinOffset - SkScalarMul(rand.nextUScalar1(),
kOffsetRange); | 33 fRects[i].fTop = -kMinOffset - SkScalarMul(rand.nextUScalar1(),
kOffsetRange); |
| 34 fRects[i].fRight = W + kMinOffset + SkScalarMul(rand.nextUScalar
1(), kOffsetRange); | 34 fRects[i].fRight = W + kMinOffset + SkScalarMul(rand.nextUScalar
1(), kOffsetRange); |
| 35 fRects[i].fBottom = H + kMinOffset + SkScalarMul(rand.nextUScala
r1(), kOffsetRange); | 35 fRects[i].fBottom = H + kMinOffset + SkScalarMul(rand.nextUScala
r1(), kOffsetRange); |
| 36 fColors[i] = rand.nextU() | 0xFF000000; | 36 fColors[i] = rand.nextU() | 0xFF000000; |
| 37 } | 37 } |
| 38 fInit = true; | 38 fInit = true; |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 42 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 43 SkPaint paint; | 43 SkPaint paint; |
| 44 for (int i = 0; i < loops; ++i) { | 44 for (int i = 0; i < loops; ++i) { |
| 45 paint.setColor(fColors[i % N]); | 45 paint.setColor(fColors[i % N]); |
| 46 canvas->drawRect(fRects[i % N], paint); | 46 canvas->drawRect(fRects[i % N], paint); |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 enum { | 51 enum { |
| 52 W = 640, | 52 W = 640, |
| 53 H = 480, | 53 H = 480, |
| 54 N = 300, | 54 N = 300, |
| 55 }; | 55 }; |
| 56 SkRect fRects[N]; | 56 SkRect fRects[N]; |
| 57 SkColor fColors[N]; | 57 SkColor fColors[N]; |
| 58 bool fInit; | 58 bool fInit; |
| 59 | 59 |
| 60 typedef Benchmark INHERITED; | 60 typedef Benchmark INHERITED; |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 DEF_BENCH( return SkNEW_ARGS(FSRectBench, ()); ) | 63 DEF_BENCH( return SkNEW_ARGS(FSRectBench, ()); ) |
| OLD | NEW |