| 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 #include "SkBenchmark.h" | 7 #include "SkBenchmark.h" |
| 8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkColor.h" | 9 #include "SkColor.h" |
| 10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
| 11 #include "SkPicture.h" | 11 #include "SkPicture.h" |
| 12 #include "SkPoint.h" | 12 #include "SkPoint.h" |
| 13 #include "SkRect.h" | 13 #include "SkRect.h" |
| 14 #include "SkString.h" | 14 #include "SkString.h" |
| 15 | 15 |
| 16 // This is designed to emulate about 4 screens of textual content | 16 // This is designed to emulate about 4 screens of textual content |
| 17 | 17 |
| 18 | 18 |
| 19 class PicturePlaybackBench : public SkBenchmark { | 19 class PicturePlaybackBench : public SkBenchmark { |
| 20 public: | 20 public: |
| 21 PicturePlaybackBench(void* param, const char name[]) : INHERITED(param) { | 21 PicturePlaybackBench(void* param, const char name[]) : INHERITED(param) { |
| 22 fName.printf("picture_playback_%s", name); | 22 fName.printf("picture_playback_%s", name); |
| 23 fPictureWidth = SkIntToScalar(PICTURE_WIDTH); | 23 fPictureWidth = SkIntToScalar(PICTURE_WIDTH); |
| 24 fPictureHeight = SkIntToScalar(PICTURE_HEIGHT); | 24 fPictureHeight = SkIntToScalar(PICTURE_HEIGHT); |
| 25 fTextSize = SkIntToScalar(TEXT_SIZE); | 25 fTextSize = SkIntToScalar(TEXT_SIZE); |
| 26 } | 26 } |
| 27 | 27 |
| 28 enum { | 28 enum { |
| 29 N = SkBENCHLOOP(200), // number of times to playback the picture | |
| 30 PICTURE_WIDTH = 1000, | 29 PICTURE_WIDTH = 1000, |
| 31 PICTURE_HEIGHT = 4000, | 30 PICTURE_HEIGHT = 4000, |
| 32 TEXT_SIZE = 10 | 31 TEXT_SIZE = 10 |
| 33 }; | 32 }; |
| 34 protected: | 33 protected: |
| 35 virtual const char* onGetName() { | 34 virtual const char* onGetName() { |
| 36 return fName.c_str(); | 35 return fName.c_str(); |
| 37 } | 36 } |
| 38 | 37 |
| 39 virtual void onDraw(SkCanvas* canvas) { | 38 virtual void onDraw(SkCanvas* canvas) { |
| 40 | 39 |
| 41 SkPicture picture; | 40 SkPicture picture; |
| 42 | 41 |
| 43 SkCanvas* pCanvas = picture.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT
); | 42 SkCanvas* pCanvas = picture.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT
); |
| 44 recordCanvas(pCanvas); | 43 recordCanvas(pCanvas); |
| 45 picture.endRecording(); | 44 picture.endRecording(); |
| 46 | 45 |
| 47 const SkPoint translateDelta = getTranslateDelta(); | 46 const SkPoint translateDelta = getTranslateDelta(this->getLoops()); |
| 48 | 47 |
| 49 for (int i = 0; i < N; i++) { | 48 for (int i = 0; i < this->getLoops(); i++) { |
| 50 picture.draw(canvas); | 49 picture.draw(canvas); |
| 51 canvas->translate(translateDelta.fX, translateDelta.fY); | 50 canvas->translate(translateDelta.fX, translateDelta.fY); |
| 52 } | 51 } |
| 53 } | 52 } |
| 54 | 53 |
| 55 virtual void recordCanvas(SkCanvas* canvas) = 0; | 54 virtual void recordCanvas(SkCanvas* canvas) = 0; |
| 56 virtual SkPoint getTranslateDelta() { | 55 virtual SkPoint getTranslateDelta(int N) { |
| 57 SkIPoint canvasSize = onGetSize(); | 56 SkIPoint canvasSize = onGetSize(); |
| 58 return SkPoint::Make(SkIntToScalar((PICTURE_WIDTH - canvasSize.fX)/N), | 57 return SkPoint::Make(SkIntToScalar((PICTURE_WIDTH - canvasSize.fX)/N), |
| 59 SkIntToScalar((PICTURE_HEIGHT- canvasSize.fY)/N)); | 58 SkIntToScalar((PICTURE_HEIGHT- canvasSize.fY)/N)); |
| 60 } | 59 } |
| 61 | 60 |
| 62 SkString fName; | 61 SkString fName; |
| 63 SkScalar fPictureWidth; | 62 SkScalar fPictureWidth; |
| 64 SkScalar fPictureHeight; | 63 SkScalar fPictureHeight; |
| 65 SkScalar fTextSize; | 64 SkScalar fTextSize; |
| 66 private: | 65 private: |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 136 |
| 138 /////////////////////////////////////////////////////////////////////////////// | 137 /////////////////////////////////////////////////////////////////////////////// |
| 139 | 138 |
| 140 static SkBenchmark* Fact0(void* p) { return new TextPlaybackBench(p); } | 139 static SkBenchmark* Fact0(void* p) { return new TextPlaybackBench(p); } |
| 141 static SkBenchmark* Fact1(void* p) { return new PosTextPlaybackBench(p, true); } | 140 static SkBenchmark* Fact1(void* p) { return new PosTextPlaybackBench(p, true); } |
| 142 static SkBenchmark* Fact2(void* p) { return new PosTextPlaybackBench(p, false);
} | 141 static SkBenchmark* Fact2(void* p) { return new PosTextPlaybackBench(p, false);
} |
| 143 | 142 |
| 144 static BenchRegistry gReg0(Fact0); | 143 static BenchRegistry gReg0(Fact0); |
| 145 static BenchRegistry gReg1(Fact1); | 144 static BenchRegistry gReg1(Fact1); |
| 146 static BenchRegistry gReg2(Fact2); | 145 static BenchRegistry gReg2(Fact2); |
| OLD | NEW |