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 | 7 |
8 #include "SKPBench.h" | 8 #include "SKPBench.h" |
9 #include "SkCommandLineFlags.h" | 9 #include "SkCommandLineFlags.h" |
10 #include "SkMultiPictureDraw.h" | 10 #include "SkMultiPictureDraw.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 const char* SKPBench::onGetName() { | 34 const char* SKPBench::onGetName() { |
35 return fName.c_str(); | 35 return fName.c_str(); |
36 } | 36 } |
37 | 37 |
38 const char* SKPBench::onGetUniqueName() { | 38 const char* SKPBench::onGetUniqueName() { |
39 return fUniqueName.c_str(); | 39 return fUniqueName.c_str(); |
40 } | 40 } |
41 | 41 |
42 void SKPBench::onPerCanvasPreDraw(SkCanvas* canvas) { | 42 void SKPBench::onPerCanvasPreDraw(SkCanvas* canvas) { |
43 if (!fUseMultiPictureDraw) { | |
44 return; | |
45 } | |
46 | |
47 SkIRect bounds; | 43 SkIRect bounds; |
48 SkAssertResult(canvas->getClipDeviceBounds(&bounds)); | 44 SkAssertResult(canvas->getClipDeviceBounds(&bounds)); |
49 | 45 |
50 int xTiles = SkScalarCeilToInt(bounds.width() / SkIntToScalar(FLAGS_benchTi
le)); | 46 int xTiles = SkScalarCeilToInt(bounds.width() / SkIntToScalar(FLAGS_benchTi
le)); |
51 int yTiles = SkScalarCeilToInt(bounds.height() / SkIntToScalar(FLAGS_benchTi
le)); | 47 int yTiles = SkScalarCeilToInt(bounds.height() / SkIntToScalar(FLAGS_benchTi
le)); |
52 | 48 |
53 fSurfaces.setReserve(xTiles * yTiles); | 49 fSurfaces.setReserve(xTiles * yTiles); |
54 fTileRects.setReserve(xTiles * yTiles); | 50 fTileRects.setReserve(xTiles * yTiles); |
55 | 51 |
56 SkImageInfo ii = canvas->imageInfo().makeWH(FLAGS_benchTile, FLAGS_benchTile
); | 52 SkImageInfo ii = canvas->imageInfo().makeWH(FLAGS_benchTile, FLAGS_benchTile
); |
(...skipping 10 matching lines...) Expand all Loading... |
67 clip.offset(-SkIntToScalar(tileRect.fLeft), -SkIntToScalar(tileRect.
fTop)); | 63 clip.offset(-SkIntToScalar(tileRect.fLeft), -SkIntToScalar(tileRect.
fTop)); |
68 fSurfaces.top()->getCanvas()->clipRect(clip); | 64 fSurfaces.top()->getCanvas()->clipRect(clip); |
69 | 65 |
70 fSurfaces.top()->getCanvas()->setMatrix(canvas->getTotalMatrix()); | 66 fSurfaces.top()->getCanvas()->setMatrix(canvas->getTotalMatrix()); |
71 fSurfaces.top()->getCanvas()->scale(fScale, fScale); | 67 fSurfaces.top()->getCanvas()->scale(fScale, fScale); |
72 } | 68 } |
73 } | 69 } |
74 } | 70 } |
75 | 71 |
76 void SKPBench::onPerCanvasPostDraw(SkCanvas* canvas) { | 72 void SKPBench::onPerCanvasPostDraw(SkCanvas* canvas) { |
77 if (!fUseMultiPictureDraw) { | |
78 return; | |
79 } | |
80 | |
81 // Draw the last set of tiles into the master canvas in case we're | 73 // Draw the last set of tiles into the master canvas in case we're |
82 // saving the images | 74 // saving the images |
83 for (int i = 0; i < fTileRects.count(); ++i) { | 75 for (int i = 0; i < fTileRects.count(); ++i) { |
84 SkAutoTUnref<SkImage> image(fSurfaces[i]->newImageSnapshot()); | 76 SkAutoTUnref<SkImage> image(fSurfaces[i]->newImageSnapshot()); |
85 canvas->drawImage(image, | 77 canvas->drawImage(image, |
86 SkIntToScalar(fTileRects[i].fLeft), SkIntToScalar(fTil
eRects[i].fTop)); | 78 SkIntToScalar(fTileRects[i].fLeft), SkIntToScalar(fTil
eRects[i].fTop)); |
87 SkSafeSetNull(fSurfaces[i]); | 79 SkSafeSetNull(fSurfaces[i]); |
88 } | 80 } |
89 | 81 |
90 fSurfaces.rewind(); | 82 fSurfaces.rewind(); |
91 fTileRects.rewind(); | 83 fTileRects.rewind(); |
92 } | 84 } |
93 | 85 |
94 bool SKPBench::isSuitableFor(Backend backend) { | 86 bool SKPBench::isSuitableFor(Backend backend) { |
95 return backend != kNonRendering_Backend; | 87 return backend != kNonRendering_Backend; |
96 } | 88 } |
97 | 89 |
98 SkIPoint SKPBench::onGetSize() { | 90 SkIPoint SKPBench::onGetSize() { |
99 return SkIPoint::Make(fClip.width(), fClip.height()); | 91 return SkIPoint::Make(fClip.width(), fClip.height()); |
100 } | 92 } |
101 | 93 |
102 void SKPBench::onDraw(const int loops, SkCanvas* canvas) { | 94 void SKPBench::onDraw(const int loops, SkCanvas* canvas) { |
103 if (fUseMultiPictureDraw) { | 95 if (fUseMultiPictureDraw) { |
104 for (int i = 0; i < loops; i++) { | 96 for (int i = 0; i < loops; i++) { |
105 SkMultiPictureDraw mpd; | 97 SkMultiPictureDraw mpd; |
106 | 98 |
107 for (int i = 0; i < fTileRects.count(); ++i) { | 99 for (int j = 0; j < fTileRects.count(); ++j) { |
108 SkMatrix trans; | 100 SkMatrix trans; |
109 trans.setTranslate(-fTileRects[i].fLeft/fScale, | 101 trans.setTranslate(-fTileRects[j].fLeft/fScale, |
110 -fTileRects[i].fTop/fScale); | 102 -fTileRects[j].fTop/fScale); |
111 mpd.add(fSurfaces[i]->getCanvas(), fPic, &trans); | 103 mpd.add(fSurfaces[j]->getCanvas(), fPic, &trans); |
112 } | 104 } |
113 | 105 |
114 mpd.draw(); | 106 mpd.draw(); |
115 | 107 |
116 for (int i = 0; i < fTileRects.count(); ++i) { | 108 for (int j = 0; j < fTileRects.count(); ++j) { |
117 fSurfaces[i]->getCanvas()->flush(); | 109 fSurfaces[j]->getCanvas()->flush(); |
118 } | 110 } |
119 } | 111 } |
120 } else { | 112 } else { |
121 SkIRect bounds; | |
122 SkAssertResult(canvas->getClipDeviceBounds(&bounds)); | |
123 | |
124 SkAutoCanvasRestore overall(canvas, true/*save now*/); | |
125 canvas->scale(fScale, fScale); | |
126 | |
127 for (int i = 0; i < loops; i++) { | 113 for (int i = 0; i < loops; i++) { |
128 for (int y = bounds.fTop; y < bounds.fBottom; y += FLAGS_benchTile)
{ | 114 for (int j = 0; j < fTileRects.count(); ++j) { |
129 for (int x = bounds.fLeft; x < bounds.fRight; x += FLAGS_benchTi
le) { | 115 SkMatrix trans; |
130 SkAutoCanvasRestore perTile(canvas, true/*save now*/); | 116 trans.setTranslate(-fTileRects[j].fLeft / fScale, |
131 canvas->clipRect(SkRect::MakeXYWH(x/fScale, y/fScale, | 117 -fTileRects[j].fTop / fScale); |
132 FLAGS_benchTile/fScale, | 118 fSurfaces[j]->getCanvas()->drawPicture(fPic, &trans, NULL); |
133 FLAGS_benchTile/fScale)); | |
134 fPic->playback(canvas); | |
135 } | |
136 } | 119 } |
137 | 120 |
138 canvas->flush(); | 121 for (int j = 0; j < fTileRects.count(); ++j) { |
| 122 fSurfaces[j]->getCanvas()->flush(); |
| 123 } |
139 } | 124 } |
140 } | 125 } |
141 } | 126 } |
OLD | NEW |