Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: bench/PicturePlaybackBench.cpp

Issue 214953003: split SkPictureRecorder out of SkPicture (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: update to ToT (again) Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | bench/PictureRecordBench.cpp » ('j') | samplecode/SampleTiling.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 19 matching lines...) Expand all
30 PICTURE_HEIGHT = 4000, 30 PICTURE_HEIGHT = 4000,
31 TEXT_SIZE = 10 31 TEXT_SIZE = 10
32 }; 32 };
33 protected: 33 protected:
34 virtual const char* onGetName() { 34 virtual const char* onGetName() {
35 return fName.c_str(); 35 return fName.c_str();
36 } 36 }
37 37
38 virtual void onDraw(const int loops, SkCanvas* canvas) { 38 virtual void onDraw(const int loops, SkCanvas* canvas) {
39 39
40 SkPicture picture; 40 SkPictureRecorder recorder;
41 41 SkCanvas* pCanvas = recorder.beginRecording(PICTURE_WIDTH, PICTURE_HEIGH T);
42 SkCanvas* pCanvas = picture.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT ); 42 this->recordCanvas(pCanvas);
43 recordCanvas(pCanvas); 43 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
44 picture.endRecording();
45 44
46 const SkPoint translateDelta = getTranslateDelta(loops); 45 const SkPoint translateDelta = getTranslateDelta(loops);
47 46
48 for (int i = 0; i < loops; i++) { 47 for (int i = 0; i < loops; i++) {
49 picture.draw(canvas); 48 picture->draw(canvas);
50 canvas->translate(translateDelta.fX, translateDelta.fY); 49 canvas->translate(translateDelta.fX, translateDelta.fY);
51 } 50 }
52 } 51 }
53 52
54 virtual void recordCanvas(SkCanvas* canvas) = 0; 53 virtual void recordCanvas(SkCanvas* canvas) = 0;
55 virtual SkPoint getTranslateDelta(int N) { 54 virtual SkPoint getTranslateDelta(int N) {
56 SkIPoint canvasSize = onGetSize(); 55 SkIPoint canvasSize = onGetSize();
57 return SkPoint::Make(SkIntToScalar((PICTURE_WIDTH - canvasSize.fX)/N), 56 return SkPoint::Make(SkIntToScalar((PICTURE_WIDTH - canvasSize.fX)/N),
58 SkIntToScalar((PICTURE_HEIGHT- canvasSize.fY)/N)); 57 SkIntToScalar((PICTURE_HEIGHT- canvasSize.fY)/N));
59 } 58 }
60 59
61 SkString fName; 60 SkString fName;
62 SkScalar fPictureWidth; 61 SkScalar fPictureWidth;
63 SkScalar fPictureHeight; 62 SkScalar fPictureHeight;
64 SkScalar fTextSize; 63 SkScalar fTextSize;
65 private: 64 private:
66 typedef SkBenchmark INHERITED; 65 typedef SkBenchmark INHERITED;
67 }; 66 };
68 67
69 68
70 class TextPlaybackBench : public PicturePlaybackBench { 69 class TextPlaybackBench : public PicturePlaybackBench {
71 public: 70 public:
72 TextPlaybackBench() : INHERITED("drawText") { } 71 TextPlaybackBench() : INHERITED("drawText") { }
73 protected: 72 protected:
74 virtual void recordCanvas(SkCanvas* canvas) { 73 virtual void recordCanvas(SkCanvas* canvas) SK_OVERRIDE {
75 SkPaint paint; 74 SkPaint paint;
76 paint.setTextSize(fTextSize); 75 paint.setTextSize(fTextSize);
77 paint.setColor(SK_ColorBLACK); 76 paint.setColor(SK_ColorBLACK);
78 77
79 const char* text = "Hamburgefons"; 78 const char* text = "Hamburgefons";
80 size_t len = strlen(text); 79 size_t len = strlen(text);
81 const SkScalar textWidth = paint.measureText(text, len); 80 const SkScalar textWidth = paint.measureText(text, len);
82 81
83 for (SkScalar x = 0; x < fPictureWidth; x += textWidth) { 82 for (SkScalar x = 0; x < fPictureWidth; x += textWidth) {
84 for (SkScalar y = 0; y < fPictureHeight; y += fTextSize) { 83 for (SkScalar y = 0; y < fPictureHeight; y += fTextSize) {
85 canvas->drawText(text, len, x, y, paint); 84 canvas->drawText(text, len, x, y, paint);
86 } 85 }
87 } 86 }
88 } 87 }
89 private: 88 private:
90 typedef PicturePlaybackBench INHERITED; 89 typedef PicturePlaybackBench INHERITED;
91 }; 90 };
92 91
93 class PosTextPlaybackBench : public PicturePlaybackBench { 92 class PosTextPlaybackBench : public PicturePlaybackBench {
94 public: 93 public:
95 PosTextPlaybackBench(bool drawPosH) 94 PosTextPlaybackBench(bool drawPosH)
96 : INHERITED(drawPosH ? "drawPosTextH" : "drawPosText") 95 : INHERITED(drawPosH ? "drawPosTextH" : "drawPosText")
97 , fDrawPosH(drawPosH) { } 96 , fDrawPosH(drawPosH) { }
98 protected: 97 protected:
99 virtual void recordCanvas(SkCanvas* canvas) { 98 virtual void recordCanvas(SkCanvas* canvas) SK_OVERRIDE {
100 SkPaint paint; 99 SkPaint paint;
101 paint.setTextSize(fTextSize); 100 paint.setTextSize(fTextSize);
102 paint.setColor(SK_ColorBLACK); 101 paint.setColor(SK_ColorBLACK);
103 102
104 const char* text = "Hamburgefons"; 103 const char* text = "Hamburgefons";
105 size_t len = strlen(text); 104 size_t len = strlen(text);
106 const SkScalar textWidth = paint.measureText(text, len); 105 const SkScalar textWidth = paint.measureText(text, len);
107 106
108 SkScalar* adv = new SkScalar[len]; 107 SkScalar* adv = new SkScalar[len];
109 paint.getTextWidths(text, len, adv); 108 paint.getTextWidths(text, len, adv);
(...skipping 22 matching lines...) Expand all
132 bool fDrawPosH; 131 bool fDrawPosH;
133 typedef PicturePlaybackBench INHERITED; 132 typedef PicturePlaybackBench INHERITED;
134 }; 133 };
135 134
136 135
137 /////////////////////////////////////////////////////////////////////////////// 136 ///////////////////////////////////////////////////////////////////////////////
138 137
139 DEF_BENCH( return new TextPlaybackBench(); ) 138 DEF_BENCH( return new TextPlaybackBench(); )
140 DEF_BENCH( return new PosTextPlaybackBench(true); ) 139 DEF_BENCH( return new PosTextPlaybackBench(true); )
141 DEF_BENCH( return new PosTextPlaybackBench(false); ) 140 DEF_BENCH( return new PosTextPlaybackBench(false); )
OLDNEW
« no previous file with comments | « no previous file | bench/PictureRecordBench.cpp » ('j') | samplecode/SampleTiling.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698