Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/containers/hash_tables.h" | |
| 6 #include "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/strings/stringprintf.h" | |
| 7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "skia/ext/benchmarking_canvas.h" | 8 #include "skia/ext/benchmarking_canvas.h" |
| 9 #include "third_party/skia/include/core/SkSurface.h" | 9 #include "third_party/skia/include/core/SkPicture.h" |
| 10 #include "third_party/skia/include/utils/SkNWayCanvas.h" | 10 #include "third_party/skia/include/core/SkRegion.h" |
| 11 #include "third_party/skia/include/core/SkTextBlob.h" | |
| 12 #include "third_party/skia/include/core/SkXfermode.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 class FlagsBuilder { | |
| 17 public: | |
| 18 FlagsBuilder(char separator) | |
| 19 : separator_(separator) {} | |
| 20 | |
| 21 void addFlag(bool flag_val, const char flag_name[]) { | |
| 22 if (!flag_val) | |
| 23 return; | |
| 24 if (!oss_.str().empty()) | |
| 25 oss_ << separator_; | |
| 26 | |
| 27 oss_ << flag_name; | |
| 28 } | |
| 29 | |
| 30 std::string str() const { | |
| 31 return oss_.str(); | |
| 32 } | |
| 33 | |
| 34 private: | |
| 35 char separator_; | |
| 36 std::ostringstream oss_; | |
| 37 }; | |
| 38 | |
| 39 WARN_UNUSED_RESULT | |
| 40 scoped_ptr<base::Value> AsValue(bool b) { | |
| 41 scoped_ptr<base::FundamentalValue> val(new base::FundamentalValue(b)); | |
| 42 | |
| 43 return val.Pass(); | |
| 44 } | |
| 45 | |
| 46 WARN_UNUSED_RESULT | |
| 47 scoped_ptr<base::Value> AsValue(SkScalar scalar) { | |
| 48 scoped_ptr<base::FundamentalValue> val(new base::FundamentalValue(scalar)); | |
| 49 | |
| 50 return val.Pass(); | |
| 51 } | |
| 52 | |
| 53 WARN_UNUSED_RESULT | |
| 54 scoped_ptr<base::Value> AsValue(const SkSize& size) { | |
| 55 scoped_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | |
| 56 val->Set("width", AsValue(size.width())); | |
| 57 val->Set("height", AsValue(size.height())); | |
| 58 | |
| 59 return val.Pass(); | |
| 60 } | |
| 61 | |
| 62 WARN_UNUSED_RESULT | |
| 63 scoped_ptr<base::Value> AsValue(const SkPoint& point) { | |
| 64 scoped_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | |
| 65 val->Set("x", AsValue(point.x())); | |
| 66 val->Set("y", AsValue(point.y())); | |
| 67 | |
| 68 return val.Pass(); | |
| 69 } | |
| 70 | |
| 71 WARN_UNUSED_RESULT | |
| 72 scoped_ptr<base::Value> AsValue(const SkRect& rect) { | |
| 73 scoped_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | |
| 74 val->Set("left", AsValue(rect.fLeft)); | |
| 75 val->Set("top", AsValue(rect.fTop)); | |
| 76 val->Set("right", AsValue(rect.fRight)); | |
| 77 val->Set("bottom", AsValue(rect.fBottom)); | |
| 78 | |
| 79 return val.Pass(); | |
| 80 } | |
| 81 | |
| 82 WARN_UNUSED_RESULT | |
| 83 scoped_ptr<base::Value> AsValue(const SkRRect& rrect) { | |
| 84 scoped_ptr<base::DictionaryValue> radii_val(new base::DictionaryValue()); | |
| 85 radii_val->Set("upper-left", AsValue(rrect.radii(SkRRect::kUpperLeft_Corner))) ; | |
| 86 radii_val->Set("upper-right", AsValue(rrect.radii(SkRRect::kUpperRight_Corner) )); | |
| 87 radii_val->Set("lower-right", AsValue(rrect.radii(SkRRect::kLowerRight_Corner) )); | |
| 88 radii_val->Set("lower-left", AsValue(rrect.radii(SkRRect::kLowerLeft_Corner))) ; | |
| 89 | |
| 90 scoped_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | |
| 91 val->Set("rect", AsValue(rrect.rect())); | |
| 92 val->Set("radii", radii_val.Pass()); | |
| 93 | |
| 94 return val.Pass(); | |
| 95 } | |
| 96 | |
| 97 WARN_UNUSED_RESULT | |
| 98 scoped_ptr<base::Value> AsValue(const SkMatrix& matrix) { | |
| 99 scoped_ptr<base::ListValue> val(new base::ListValue()); | |
| 100 for (int i = 0; i < 9; ++i) | |
| 101 val->Append(AsValue(matrix[i]).release()); // no scoped_ptr-aware Append() v ariant | |
| 102 | |
| 103 return val.Pass(); | |
| 104 } | |
| 105 | |
| 106 WARN_UNUSED_RESULT | |
| 107 scoped_ptr<base::Value> AsValue(SkColor color) { | |
| 108 scoped_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | |
| 109 val->SetInteger("a", SkColorGetA(color)); | |
| 110 val->SetInteger("r", SkColorGetR(color)); | |
| 111 val->SetInteger("g", SkColorGetG(color)); | |
| 112 val->SetInteger("b", SkColorGetB(color)); | |
| 113 | |
| 114 return val.Pass(); | |
| 115 } | |
| 116 | |
| 117 WARN_UNUSED_RESULT | |
| 118 scoped_ptr<base::Value> AsValue(const SkXfermode& xfermode) { | |
| 119 SkXfermode::Mode mode; | |
| 120 scoped_ptr<base::StringValue> val(new base::StringValue( | |
| 121 xfermode.asMode(&mode) ? SkXfermode::ModeName(mode) : "unknown")); | |
| 122 | |
| 123 return val.Pass(); | |
| 124 } | |
| 125 | |
| 126 WARN_UNUSED_RESULT | |
| 127 scoped_ptr<base::Value> AsValue(const SkPaint& paint) { | |
| 128 scoped_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | |
| 129 SkPaint default_paint; | |
| 130 | |
| 131 if (paint.getColor() != default_paint.getColor()) | |
| 132 val->Set("Color", AsValue(paint.getColor())); | |
| 133 | |
| 134 if (paint.getStyle() != default_paint.getStyle()) { | |
| 135 static const char* gStyleStrings[] = { "Fill", "Stroke", "StrokeFill" }; | |
| 136 DCHECK_LT(static_cast<size_t>(paint.getStyle()), | |
| 137 SK_ARRAY_COUNT(gStyleStrings)); | |
| 138 val->SetString("Style", gStyleStrings[paint.getStyle()]); | |
| 139 } | |
| 140 | |
| 141 if (paint.getXfermode() != default_paint.getXfermode()) { | |
| 142 DCHECK(paint.getXfermode()); | |
| 143 val->Set("Xfermode", AsValue(*paint.getXfermode())); | |
| 144 } | |
| 145 | |
| 146 if (paint.getFlags()) { | |
| 147 FlagsBuilder builder('|'); | |
| 148 builder.addFlag(paint.isAntiAlias(), "AntiAlias"); | |
| 149 builder.addFlag(paint.isDither(), "Dither"); | |
| 150 builder.addFlag(paint.isUnderlineText(), "UnderlineText"); | |
| 151 builder.addFlag(paint.isStrikeThruText(), "StrikeThruText"); | |
| 152 builder.addFlag(paint.isFakeBoldText(), "FakeBoldText"); | |
| 153 builder.addFlag(paint.isLinearText(), "LinearText"); | |
| 154 builder.addFlag(paint.isSubpixelText(), "SubpixelText"); | |
| 155 builder.addFlag(paint.isDevKernText(), "DevKernText"); | |
| 156 builder.addFlag(paint.isLCDRenderText(), "LCDRenderText"); | |
| 157 builder.addFlag(paint.isEmbeddedBitmapText(), "EmbeddedBitmapText"); | |
| 158 builder.addFlag(paint.isAutohinted(), "Autohinted"); | |
| 159 builder.addFlag(paint.isVerticalText(), "VerticalText"); | |
| 160 builder.addFlag(paint.getFlags() & SkPaint::kGenA8FromLCD_Flag, "GenA8FromLC D"); | |
| 161 | |
| 162 val->SetString("Flags", builder.str()); | |
| 163 } | |
| 164 | |
| 165 if (paint.getFilterLevel() != default_paint.getFilterLevel()) { | |
| 166 static const char* gFilterLevelStrings[] = { "None", "Low", "Medium", "High" }; | |
| 167 DCHECK_LT(static_cast<size_t>(paint.getFilterLevel()), | |
| 168 SK_ARRAY_COUNT(gFilterLevelStrings)); | |
| 169 val->SetString("FilterLevel", gFilterLevelStrings[paint.getFilterLevel()]); | |
| 170 } | |
| 171 | |
| 172 if (paint.getTextSize() != default_paint.getTextSize()) | |
| 173 val->SetDouble("TextSize", paint.getTextSize()); | |
| 174 | |
| 175 if (paint.getTextScaleX() != default_paint.getTextScaleX()) | |
| 176 val->SetDouble("TextScaleX", paint.getTextScaleX()); | |
| 177 | |
| 178 if (paint.getTextSkewX() != default_paint.getTextSkewX()) | |
| 179 val->SetDouble("TextSkewX", paint.getTextSkewX()); | |
| 180 | |
|
robertphillips
2015/02/23 20:30:21
ImageFilters?
ColorFilters?
f(malita)
2015/02/24 17:45:00
Done.
(for ImageFilters there's not much info to
| |
| 181 | |
| 182 return val.Pass(); | |
| 183 } | |
| 184 | |
| 185 WARN_UNUSED_RESULT | |
| 186 scoped_ptr<base::Value> AsValue(SkCanvas::SaveFlags flags) { | |
| 187 FlagsBuilder builder('|'); | |
| 188 builder.addFlag(flags & SkCanvas::kHasAlphaLayer_SaveFlag, "kHasAlphaLayer"); | |
| 189 builder.addFlag(flags & SkCanvas::kFullColorLayer_SaveFlag, "kFullColorLayer") ; | |
| 190 builder.addFlag(flags & SkCanvas::kClipToLayer_SaveFlag, "kClipToLayer"); | |
| 191 | |
| 192 scoped_ptr<base::StringValue> val(new base::StringValue(builder.str())); | |
| 193 | |
| 194 return val.Pass(); | |
| 195 } | |
| 196 | |
| 197 WARN_UNUSED_RESULT | |
| 198 scoped_ptr<base::Value> AsValue(SkRegion::Op op) { | |
| 199 static const char* gOpStrings[] = { "Difference", | |
| 200 "Intersect", | |
| 201 "Union", | |
| 202 "XOR", | |
| 203 "ReverseDifference", | |
| 204 "Replace" | |
| 205 }; | |
| 206 DCHECK_LT(static_cast<size_t>(op), SK_ARRAY_COUNT(gOpStrings)); | |
| 207 scoped_ptr<base::StringValue> val(new base::StringValue(gOpStrings[op])); | |
| 208 return val.Pass(); | |
| 209 } | |
| 210 | |
| 211 WARN_UNUSED_RESULT | |
| 212 scoped_ptr<base::Value> AsValue(const SkRegion& region) { | |
| 213 scoped_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | |
| 214 val->Set("bounds", AsValue(SkRect::Make(region.getBounds()))); | |
| 215 | |
| 216 return val.Pass(); | |
| 217 } | |
| 218 | |
| 219 WARN_UNUSED_RESULT | |
| 220 scoped_ptr<base::Value> AsValue(const SkPicture& picture) { | |
| 221 scoped_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | |
| 222 val->Set("cull-rect", AsValue(picture.cullRect())); | |
| 223 | |
| 224 return val.Pass(); | |
| 225 } | |
| 226 | |
| 227 WARN_UNUSED_RESULT | |
| 228 scoped_ptr<base::Value> AsValue(const SkBitmap& bitmap) { | |
| 229 scoped_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | |
| 230 val->Set("size", AsValue(SkSize::Make(bitmap.width(), bitmap.height()))); | |
| 231 | |
| 232 return val.Pass(); | |
| 233 } | |
| 234 | |
| 235 WARN_UNUSED_RESULT | |
| 236 scoped_ptr<base::Value> AsValue(const SkImage& image) { | |
| 237 scoped_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | |
| 238 val->Set("size", AsValue(SkSize::Make(image.width(), image.height()))); | |
| 239 | |
| 240 return val.Pass(); | |
| 241 } | |
| 242 | |
| 243 WARN_UNUSED_RESULT | |
| 244 scoped_ptr<base::Value> AsValue(const SkTextBlob& blob) { | |
| 245 scoped_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | |
| 246 val->Set("bounds", AsValue(blob.bounds())); | |
| 247 | |
| 248 return val.Pass(); | |
| 249 } | |
| 250 | |
| 251 WARN_UNUSED_RESULT | |
| 252 scoped_ptr<base::Value> AsValue(const SkPath& path) { | |
| 253 scoped_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | |
| 254 val->Set("bounds", AsValue(path.getBounds())); | |
|
robertphillips
2015/02/23 20:30:21
Dump out convexity, verbs & points?
f(malita)
2015/02/24 17:45:00
Done.
| |
| 255 | |
| 256 return val.Pass(); | |
| 257 } | |
| 258 | |
| 259 template<typename T> | |
| 260 WARN_UNUSED_RESULT | |
| 261 scoped_ptr<base::Value> AsListValue(const T array[], size_t count) { | |
| 262 scoped_ptr<base::ListValue> val(new base::ListValue()); | |
| 263 | |
| 264 for (size_t i = 0; i < count; ++i) | |
| 265 val->Append(AsValue(array[i]).release()); | |
| 266 | |
| 267 return val.Pass(); | |
| 268 } | |
| 269 | |
| 270 } // namespace | |
| 11 | 271 |
| 12 namespace skia { | 272 namespace skia { |
| 13 | 273 |
| 14 class AutoStamper { | 274 class BenchmarkingCanvas::AutoOp { |
| 15 public: | 275 public: |
| 16 AutoStamper(TimingCanvas* timing_canvas); | 276 AutoOp(BenchmarkingCanvas* canvas, const char op_name[], |
| 17 ~AutoStamper(); | 277 const SkPaint* paint = nullptr) |
| 278 : canvas_(canvas) | |
| 279 , op_record_(new base::DictionaryValue()) | |
| 280 , op_params_(new base::ListValue()) { | |
| 281 | |
| 282 DCHECK(canvas); | |
| 283 DCHECK(op_name); | |
| 284 | |
| 285 op_record_->SetString("cmd_string", op_name); | |
| 286 op_record_->Set("info", op_params_); | |
| 287 | |
| 288 if (paint) | |
| 289 this->addParam("paint", AsValue(*paint)); | |
| 290 | |
| 291 start_ticks_ = base::TimeTicks::Now(); | |
| 292 } | |
| 293 | |
| 294 ~AutoOp() { | |
| 295 base::TimeDelta ticks = base::TimeTicks::Now() - start_ticks_; | |
| 296 op_record_->SetDouble("cmd_time", ticks.InMillisecondsF()); | |
| 297 | |
| 298 canvas_->op_records_.Append(op_record_); | |
| 299 } | |
| 300 | |
| 301 void addParam(const char name[], scoped_ptr<base::Value> value) { | |
| 302 scoped_ptr<base::DictionaryValue> param(new base::DictionaryValue()); | |
| 303 param->Set(name, value.Pass()); | |
| 304 | |
| 305 op_params_->Append(param.release()); // no scoped_ptr-aware Append() variant . | |
| 306 } | |
| 18 | 307 |
| 19 private: | 308 private: |
| 20 TimingCanvas* timing_canvas_; | 309 BenchmarkingCanvas* canvas_; |
| 310 base::DictionaryValue* op_record_; | |
| 311 base::ListValue* op_params_; | |
| 21 base::TimeTicks start_ticks_; | 312 base::TimeTicks start_ticks_; |
| 22 }; | 313 }; |
| 23 | 314 |
| 24 class TimingCanvas : public SkNWayCanvas { | 315 BenchmarkingCanvas::BenchmarkingCanvas(SkCanvas* canvas) |
| 25 public: | 316 : INHERITED(canvas->imageInfo().width(), |
| 26 TimingCanvas(int width, int height, const BenchmarkingCanvas* track_canvas) | 317 canvas->imageInfo().height()) { |
| 27 : SkNWayCanvas(width, height) | 318 addCanvas(canvas); |
| 28 , tracking_canvas_(track_canvas) { | |
| 29 surface_ = skia::AdoptRef(SkSurface::NewRasterN32Premul(width, height)); | |
| 30 | |
| 31 addCanvas(surface_->getCanvas()); | |
| 32 } | |
| 33 | |
| 34 ~TimingCanvas() override {} | |
| 35 | |
| 36 double GetTime(size_t index) { | |
| 37 TimingsMap::const_iterator timing_info = timings_map_.find(index); | |
| 38 return timing_info != timings_map_.end() | |
| 39 ? timing_info->second.InMillisecondsF() | |
| 40 : 0.0; | |
| 41 } | |
| 42 | |
| 43 // SkCanvas overrides. | |
| 44 void willSave() override { | |
| 45 AutoStamper stamper(this); | |
| 46 SkNWayCanvas::willSave(); | |
| 47 } | |
| 48 | |
| 49 SaveLayerStrategy willSaveLayer(const SkRect* bounds, | |
| 50 const SkPaint* paint, | |
| 51 SaveFlags flags) override { | |
| 52 AutoStamper stamper(this); | |
| 53 return SkNWayCanvas::willSaveLayer(bounds, paint, flags); | |
| 54 } | |
| 55 | |
| 56 void willRestore() override { | |
| 57 AutoStamper stamper(this); | |
| 58 SkNWayCanvas::willRestore(); | |
| 59 } | |
| 60 | |
| 61 void onDrawPaint(const SkPaint& paint) override { | |
| 62 AutoStamper stamper(this); | |
| 63 SkNWayCanvas::onDrawPaint(paint); | |
| 64 } | |
| 65 | |
| 66 void onDrawPoints(PointMode mode, | |
| 67 size_t count, | |
| 68 const SkPoint pts[], | |
| 69 const SkPaint& paint) override { | |
| 70 AutoStamper stamper(this); | |
| 71 SkNWayCanvas::onDrawPoints(mode, count, pts, paint); | |
| 72 } | |
| 73 | |
| 74 void onDrawOval(const SkRect& rect, const SkPaint& paint) override { | |
| 75 AutoStamper stamper(this); | |
| 76 SkNWayCanvas::onDrawOval(rect, paint); | |
| 77 } | |
| 78 | |
| 79 void onDrawRect(const SkRect& rect, const SkPaint& paint) override { | |
| 80 AutoStamper stamper(this); | |
| 81 SkNWayCanvas::onDrawRect(rect, paint); | |
| 82 } | |
| 83 | |
| 84 void onDrawRRect(const SkRRect& rrect, const SkPaint& paint) override { | |
| 85 AutoStamper stamper(this); | |
| 86 SkNWayCanvas::onDrawRRect(rrect, paint); | |
| 87 } | |
| 88 | |
| 89 void onDrawPath(const SkPath& path, const SkPaint& paint) override { | |
| 90 AutoStamper stamper(this); | |
| 91 SkNWayCanvas::onDrawPath(path, paint); | |
| 92 } | |
| 93 | |
| 94 void onDrawBitmap(const SkBitmap& bitmap, | |
| 95 SkScalar left, | |
| 96 SkScalar top, | |
| 97 const SkPaint* paint) override { | |
| 98 AutoStamper stamper(this); | |
| 99 SkNWayCanvas::onDrawBitmap(bitmap, left, top, paint); | |
| 100 } | |
| 101 | |
| 102 void onDrawBitmapRect(const SkBitmap& bitmap, | |
| 103 const SkRect* src, | |
| 104 const SkRect& dst, | |
| 105 const SkPaint* paint, | |
| 106 DrawBitmapRectFlags flags) override { | |
| 107 AutoStamper stamper(this); | |
| 108 SkNWayCanvas::onDrawBitmapRect(bitmap, src, dst, paint, flags); | |
| 109 } | |
| 110 | |
| 111 void onDrawSprite(const SkBitmap& bitmap, | |
| 112 int left, | |
| 113 int top, | |
| 114 const SkPaint* paint) override { | |
| 115 AutoStamper stamper(this); | |
| 116 SkNWayCanvas::onDrawSprite(bitmap, left, top, paint); | |
| 117 } | |
| 118 | |
| 119 void onDrawVertices(VertexMode vmode, | |
| 120 int vertexCount, | |
| 121 const SkPoint vertices[], | |
| 122 const SkPoint texs[], | |
| 123 const SkColor colors[], | |
| 124 SkXfermode* xmode, | |
| 125 const uint16_t indices[], | |
| 126 int indexCount, | |
| 127 const SkPaint& paint) override { | |
| 128 AutoStamper stamper(this); | |
| 129 SkNWayCanvas::onDrawVertices(vmode, vertexCount, vertices, texs, colors, | |
| 130 xmode, indices, indexCount, paint); | |
| 131 } | |
| 132 | |
| 133 protected: | |
| 134 void onDrawText(const void* text, | |
| 135 size_t byteLength, | |
| 136 SkScalar x, | |
| 137 SkScalar y, | |
| 138 const SkPaint& paint) override { | |
| 139 AutoStamper stamper(this); | |
| 140 SkNWayCanvas::onDrawText(text, byteLength, x, y, paint); | |
| 141 } | |
| 142 | |
| 143 void onDrawPosText(const void* text, | |
| 144 size_t byteLength, | |
| 145 const SkPoint pos[], | |
| 146 const SkPaint& paint) override { | |
| 147 AutoStamper stamper(this); | |
| 148 SkNWayCanvas::onDrawPosText(text, byteLength, pos, paint); | |
| 149 } | |
| 150 | |
| 151 void onDrawPosTextH(const void* text, | |
| 152 size_t byteLength, | |
| 153 const SkScalar xpos[], | |
| 154 SkScalar constY, | |
| 155 const SkPaint& paint) override { | |
| 156 AutoStamper stamper(this); | |
| 157 SkNWayCanvas::onDrawPosTextH(text, byteLength, xpos, constY, paint); | |
| 158 } | |
| 159 | |
| 160 void onDrawTextOnPath(const void* text, | |
| 161 size_t byteLength, | |
| 162 const SkPath& path, | |
| 163 const SkMatrix* matrix, | |
| 164 const SkPaint& paint) override { | |
| 165 AutoStamper stamper(this); | |
| 166 SkNWayCanvas::onDrawTextOnPath(text, byteLength, path, matrix, paint); | |
| 167 } | |
| 168 | |
| 169 void onClipRect(const SkRect& rect, | |
| 170 SkRegion::Op op, | |
| 171 ClipEdgeStyle edge_style) override { | |
| 172 AutoStamper stamper(this); | |
| 173 SkNWayCanvas::onClipRect(rect, op, edge_style); | |
| 174 } | |
| 175 | |
| 176 void onClipRRect(const SkRRect& rrect, | |
| 177 SkRegion::Op op, | |
| 178 ClipEdgeStyle edge_style) override { | |
| 179 AutoStamper stamper(this); | |
| 180 SkNWayCanvas::onClipRRect(rrect, op, edge_style); | |
| 181 } | |
| 182 | |
| 183 void onClipPath(const SkPath& path, | |
| 184 SkRegion::Op op, | |
| 185 ClipEdgeStyle edge_style) override { | |
| 186 AutoStamper stamper(this); | |
| 187 SkNWayCanvas::onClipPath(path, op, edge_style); | |
| 188 } | |
| 189 | |
| 190 void onClipRegion(const SkRegion& region, SkRegion::Op op) override { | |
| 191 AutoStamper stamper(this); | |
| 192 SkNWayCanvas::onClipRegion(region, op); | |
| 193 } | |
| 194 | |
| 195 void onDrawPicture(const SkPicture* picture, | |
| 196 const SkMatrix* matrix, | |
| 197 const SkPaint* paint) override { | |
| 198 AutoStamper stamper(this); | |
| 199 SkNWayCanvas::onDrawPicture(picture, matrix, paint); | |
| 200 } | |
| 201 | |
| 202 private: | |
| 203 typedef base::hash_map<size_t, base::TimeDelta> TimingsMap; | |
| 204 TimingsMap timings_map_; | |
| 205 | |
| 206 skia::RefPtr<SkSurface> surface_; | |
| 207 | |
| 208 friend class AutoStamper; | |
| 209 const BenchmarkingCanvas* tracking_canvas_; | |
| 210 }; | |
| 211 | |
| 212 AutoStamper::AutoStamper(TimingCanvas *timing_canvas) | |
| 213 : timing_canvas_(timing_canvas) { | |
| 214 start_ticks_ = base::TimeTicks::Now(); | |
| 215 } | |
| 216 | |
| 217 AutoStamper::~AutoStamper() { | |
| 218 base::TimeDelta delta = base::TimeTicks::Now() - start_ticks_; | |
| 219 int command_index = timing_canvas_->tracking_canvas_->CommandCount() - 1; | |
| 220 DCHECK_GE(command_index, 0); | |
| 221 timing_canvas_->timings_map_[command_index] = delta; | |
| 222 } | |
| 223 | |
| 224 BenchmarkingCanvas::BenchmarkingCanvas(int width, int height) | |
| 225 : SkNWayCanvas(width, height) { | |
| 226 debug_canvas_ = skia::AdoptRef(SkNEW_ARGS(SkDebugCanvas, (width, height))); | |
| 227 timing_canvas_ = skia::AdoptRef(SkNEW_ARGS(TimingCanvas, (width, height, this) )); | |
| 228 | |
| 229 addCanvas(debug_canvas_.get()); | |
| 230 addCanvas(timing_canvas_.get()); | |
| 231 } | 319 } |
| 232 | 320 |
| 233 BenchmarkingCanvas::~BenchmarkingCanvas() { | 321 BenchmarkingCanvas::~BenchmarkingCanvas() { |
| 234 removeAll(); | |
| 235 } | 322 } |
| 236 | 323 |
| 237 size_t BenchmarkingCanvas::CommandCount() const { | 324 size_t BenchmarkingCanvas::CommandCount() const { |
| 238 return debug_canvas_->getSize(); | 325 return op_records_.GetSize(); |
| 239 } | 326 } |
| 240 | 327 |
| 241 SkDrawCommand* BenchmarkingCanvas::GetCommand(size_t index) { | 328 const base::ListValue& BenchmarkingCanvas::Commands() const { |
| 242 DCHECK_LT(index, static_cast<size_t>(debug_canvas_->getSize())); | 329 return op_records_; |
| 243 return debug_canvas_->getDrawCommandAt(index); | |
| 244 } | 330 } |
| 245 | 331 |
| 246 double BenchmarkingCanvas::GetTime(size_t index) { | 332 double BenchmarkingCanvas::GetTime(size_t index) { |
| 247 DCHECK_LT(index, static_cast<size_t>(debug_canvas_->getSize())); | 333 const base::DictionaryValue* op; |
| 248 return timing_canvas_->GetTime(index); | 334 if (!op_records_.GetDictionary(index, &op)) |
| 335 return 0; | |
| 336 | |
| 337 double t; | |
| 338 if (!op->GetDouble("cmd_time", &t)) | |
| 339 return 0; | |
| 340 | |
| 341 return t; | |
| 342 } | |
| 343 | |
| 344 void BenchmarkingCanvas::willSave() { | |
| 345 AutoOp op(this, "Save"); | |
| 346 | |
| 347 INHERITED::willSave(); | |
| 348 } | |
| 349 | |
| 350 SkCanvas::SaveLayerStrategy BenchmarkingCanvas::willSaveLayer(const SkRect* rect , | |
| 351 const SkPaint* pai nt, | |
| 352 SaveFlags flags) { | |
| 353 AutoOp op(this, "SaveLayer", paint); | |
| 354 if (rect) | |
| 355 op.addParam("bounds", AsValue(*rect)); | |
| 356 if (paint) | |
| 357 op.addParam("paint", AsValue(*paint)); | |
| 358 if (flags) | |
| 359 op.addParam("flags", AsValue(flags)); | |
| 360 | |
| 361 return INHERITED::willSaveLayer(rect, paint, flags); | |
| 362 } | |
| 363 | |
| 364 void BenchmarkingCanvas::willRestore() { | |
| 365 AutoOp op(this, "Restore"); | |
| 366 | |
| 367 INHERITED::willRestore(); | |
| 368 } | |
| 369 | |
| 370 void BenchmarkingCanvas::didConcat(const SkMatrix& m) { | |
| 371 AutoOp op(this, "Concat"); | |
| 372 op.addParam("matrix", AsValue(m)); | |
| 373 | |
| 374 INHERITED::didConcat(m); | |
| 375 } | |
| 376 | |
| 377 void BenchmarkingCanvas::didSetMatrix(const SkMatrix& m) { | |
| 378 AutoOp op(this, "SetMatrix"); | |
| 379 op.addParam("matrix", AsValue(m)); | |
| 380 | |
| 381 INHERITED::didSetMatrix(m); | |
| 382 } | |
| 383 | |
| 384 void BenchmarkingCanvas::onClipRect(const SkRect& rect, | |
| 385 SkRegion::Op region_op, | |
| 386 SkCanvas::ClipEdgeStyle style) { | |
| 387 AutoOp op(this, "ClipRect"); | |
| 388 op.addParam("rect", AsValue(rect)); | |
| 389 op.addParam("op", AsValue(region_op)); | |
| 390 op.addParam("anti-alias", AsValue(style == kSoft_ClipEdgeStyle)); | |
| 391 | |
| 392 INHERITED::onClipRect(rect, region_op, style); | |
| 393 } | |
| 394 | |
| 395 void BenchmarkingCanvas::onClipRRect(const SkRRect& rrect, | |
| 396 SkRegion::Op region_op, | |
| 397 SkCanvas::ClipEdgeStyle style) { | |
| 398 AutoOp op(this, "ClipRRect"); | |
| 399 op.addParam("rrect", AsValue(rrect)); | |
| 400 op.addParam("op", AsValue(region_op)); | |
| 401 op.addParam("anti-alias", AsValue(style == kSoft_ClipEdgeStyle)); | |
| 402 | |
| 403 INHERITED::onClipRRect(rrect, region_op, style); | |
| 404 } | |
| 405 | |
| 406 void BenchmarkingCanvas::onClipPath(const SkPath& path, | |
| 407 SkRegion::Op region_op, | |
| 408 SkCanvas::ClipEdgeStyle style) { | |
| 409 AutoOp op(this, "ClipPath"); | |
| 410 op.addParam("path", AsValue(path)); | |
| 411 op.addParam("op", AsValue(region_op)); | |
| 412 op.addParam("anti-alias", AsValue(style == kSoft_ClipEdgeStyle)); | |
| 413 | |
| 414 INHERITED::onClipPath(path, region_op, style); | |
| 415 } | |
| 416 | |
| 417 void BenchmarkingCanvas::onClipRegion(const SkRegion& region, | |
| 418 SkRegion::Op region_op) { | |
| 419 AutoOp op(this, "ClipRegion"); | |
| 420 op.addParam("region", AsValue(region)); | |
| 421 op.addParam("op", AsValue(region_op)); | |
| 422 | |
| 423 INHERITED::onClipRegion(region, region_op); | |
| 424 } | |
| 425 | |
| 426 void BenchmarkingCanvas::onDrawPaint(const SkPaint& paint) { | |
| 427 AutoOp op(this, "DrawPaint", &paint); | |
| 428 | |
| 429 INHERITED::onDrawPaint(paint); | |
| 430 } | |
| 431 | |
| 432 void BenchmarkingCanvas::onDrawPoints(PointMode mode, size_t count, | |
| 433 const SkPoint pts[], const SkPaint& paint) { | |
| 434 AutoOp op(this, "DrawPoints", &paint); | |
| 435 // FIXME: moar params | |
|
pdr.
2015/02/20 18:17:53
Oops, a fixme slipped in.
f(malita)
2015/02/24 17:45:00
Done.
| |
| 436 | |
| 437 INHERITED::onDrawPoints(mode, count, pts, paint); | |
| 438 } | |
| 439 | |
| 440 void BenchmarkingCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) { | |
| 441 AutoOp op(this, "DrawRect", &paint); | |
| 442 op.addParam("rect", AsValue(rect)); | |
| 443 | |
| 444 INHERITED::onDrawRect(rect, paint); | |
| 445 } | |
| 446 | |
| 447 void BenchmarkingCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) { | |
| 448 AutoOp op(this, "DrawOval", &paint); | |
| 449 op.addParam("rect", AsValue(rect)); | |
| 450 | |
| 451 INHERITED::onDrawOval(rect, paint); | |
| 452 } | |
| 453 | |
| 454 void BenchmarkingCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { | |
| 455 AutoOp op(this, "DrawRRect", &paint); | |
| 456 op.addParam("rrect", AsValue(rrect)); | |
| 457 | |
| 458 INHERITED::onDrawRRect(rrect, paint); | |
| 459 } | |
| 460 | |
| 461 void BenchmarkingCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner , | |
| 462 const SkPaint& paint) { | |
| 463 AutoOp op(this, "DrawDRRect", &paint); | |
| 464 op.addParam("outer", AsValue(outer)); | |
| 465 op.addParam("inner", AsValue(inner)); | |
| 466 | |
| 467 INHERITED::onDrawDRRect(outer, inner, paint); | |
| 468 } | |
| 469 | |
| 470 void BenchmarkingCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { | |
| 471 AutoOp op(this, "DrawPath", &paint); | |
| 472 op.addParam("path", AsValue(path)); | |
| 473 | |
| 474 INHERITED::onDrawPath(path, paint); | |
| 475 } | |
| 476 | |
| 477 void BenchmarkingCanvas::onDrawPicture(const SkPicture* picture, | |
| 478 const SkMatrix* matrix, | |
| 479 const SkPaint* paint) { | |
| 480 DCHECK(picture); | |
| 481 AutoOp op(this, "DrawPicture", paint); | |
| 482 op.addParam("picture", AsValue(picture)); | |
| 483 if (matrix) | |
| 484 op.addParam("matrix", AsValue(*matrix)); | |
| 485 | |
| 486 INHERITED::drawPicture(picture, matrix, paint); | |
| 487 } | |
| 488 | |
| 489 void BenchmarkingCanvas::onDrawBitmap(const SkBitmap& bitmap, | |
| 490 SkScalar left, | |
| 491 SkScalar top, | |
| 492 const SkPaint* paint) { | |
| 493 AutoOp op(this, "DrawBitmap", paint); | |
| 494 op.addParam("bitmap", AsValue(bitmap)); | |
| 495 op.addParam("left", AsValue(left)); | |
| 496 op.addParam("top", AsValue(top)); | |
| 497 | |
| 498 INHERITED::onDrawBitmap(bitmap, left, top, paint); | |
| 499 } | |
| 500 | |
| 501 void BenchmarkingCanvas::onDrawBitmapRect(const SkBitmap& bitmap, | |
| 502 const SkRect* src, | |
| 503 const SkRect& dst, | |
| 504 const SkPaint* paint, | |
| 505 DrawBitmapRectFlags flags) { | |
| 506 AutoOp op(this, "DrawBitmapRect", paint); | |
| 507 op.addParam("bitmap", AsValue(bitmap)); | |
| 508 if (src) | |
| 509 op.addParam("src", AsValue(*src)); | |
| 510 op.addParam("dst", AsValue(dst)); | |
| 511 | |
| 512 INHERITED::onDrawBitmapRect(bitmap, src, dst, paint, flags); | |
| 513 } | |
| 514 | |
| 515 void BenchmarkingCanvas::onDrawImage(const SkImage* image, | |
| 516 SkScalar left, | |
| 517 SkScalar top, | |
| 518 const SkPaint* paint) { | |
| 519 DCHECK(image); | |
| 520 AutoOp op(this, "DrawImage", paint); | |
| 521 op.addParam("image", AsValue(*image)); | |
| 522 op.addParam("left", AsValue(left)); | |
| 523 op.addParam("top", AsValue(top)); | |
| 524 | |
| 525 INHERITED::onDrawImage(image, left, top, paint); | |
| 526 } | |
| 527 | |
| 528 void BenchmarkingCanvas::onDrawImageRect(const SkImage* image, const SkRect* src , | |
| 529 const SkRect& dst, const SkPaint* paint ) { | |
| 530 DCHECK(image); | |
| 531 AutoOp op(this, "DrawImageRect", paint); | |
| 532 op.addParam("image", AsValue(*image)); | |
| 533 if (src) | |
| 534 op.addParam("src", AsValue(*src)); | |
| 535 op.addParam("dst", AsValue(dst)); | |
| 536 | |
| 537 INHERITED::onDrawImageRect(image, src, dst, paint); | |
| 538 } | |
| 539 | |
| 540 void BenchmarkingCanvas::onDrawBitmapNine(const SkBitmap& bitmap, | |
| 541 const SkIRect& center, | |
| 542 const SkRect& dst, | |
| 543 const SkPaint* paint) { | |
| 544 AutoOp op(this, "DrawBitmapNine", paint); | |
| 545 op.addParam("bitmap", AsValue(bitmap)); | |
| 546 op.addParam("center", AsValue(SkRect::Make(center))); | |
| 547 op.addParam("dst", AsValue(dst)); | |
| 548 | |
| 549 INHERITED::onDrawBitmapNine(bitmap, center, dst, paint); | |
| 550 } | |
| 551 | |
| 552 void BenchmarkingCanvas::onDrawSprite(const SkBitmap& bitmap, int left, int top, | |
| 553 const SkPaint* paint) { | |
| 554 AutoOp op(this, "DrawSprite", paint); | |
| 555 op.addParam("bitmap", AsValue(bitmap)); | |
| 556 op.addParam("left", AsValue(SkIntToScalar(left))); | |
| 557 op.addParam("top", AsValue(SkIntToScalar(top))); | |
| 558 | |
| 559 INHERITED::onDrawSprite(bitmap, left, top, paint); | |
| 560 } | |
| 561 | |
| 562 void BenchmarkingCanvas::onDrawText(const void* text, size_t byteLength, | |
| 563 SkScalar x, SkScalar y, | |
| 564 const SkPaint& paint) { | |
| 565 AutoOp op(this, "DrawText", &paint); | |
| 566 op.addParam("count", AsValue(SkIntToScalar(paint.countText(text, byteLength))) ); | |
| 567 op.addParam("x", AsValue(x)); | |
| 568 op.addParam("y", AsValue(y)); | |
| 569 | |
| 570 INHERITED::onDrawText(text, byteLength, x, y, paint); | |
| 571 } | |
| 572 | |
| 573 void BenchmarkingCanvas::onDrawPosText(const void* text, size_t byteLength, | |
| 574 const SkPoint pos[], const SkPaint& paint ) { | |
| 575 AutoOp op(this, "DrawPosText", &paint); | |
| 576 | |
| 577 int count = paint.countText(text, byteLength); | |
| 578 op.addParam("count", AsValue(SkIntToScalar(count))); | |
| 579 op.addParam("pos", AsListValue(pos, count)); | |
| 580 | |
| 581 INHERITED::onDrawPosText(text, byteLength, pos, paint); | |
| 582 } | |
| 583 | |
| 584 void BenchmarkingCanvas::onDrawPosTextH(const void* text, size_t byteLength, | |
| 585 const SkScalar xpos[], SkScalar constY, | |
| 586 const SkPaint& paint) { | |
| 587 AutoOp op(this, "DrawPosTextH", &paint); | |
| 588 op.addParam("constY", AsValue(constY)); | |
| 589 | |
| 590 int count = paint.countText(text, byteLength); | |
| 591 op.addParam("count", AsValue(SkIntToScalar(count))); | |
| 592 op.addParam("pos", AsListValue(xpos, count)); | |
| 593 | |
| 594 INHERITED::onDrawPosTextH(text, byteLength, xpos, constY, paint); | |
| 595 } | |
| 596 | |
| 597 void BenchmarkingCanvas::onDrawTextOnPath(const void* text, size_t byteLength, | |
| 598 const SkPath& path, const SkMatrix* ma trix, | |
| 599 const SkPaint& paint) { | |
| 600 AutoOp op(this, "DrawTextOnPath", &paint); | |
| 601 op.addParam("count", AsValue(SkIntToScalar(paint.countText(text, byteLength))) ); | |
| 602 op.addParam("path", AsValue(path)); | |
| 603 if (matrix) | |
| 604 op.addParam("matrix", AsValue(*matrix)); | |
| 605 | |
| 606 INHERITED::onDrawTextOnPath(text, byteLength, path, matrix, paint); | |
| 607 } | |
| 608 | |
| 609 void BenchmarkingCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkSc alar y, | |
| 610 const SkPaint& paint) { | |
| 611 DCHECK(blob); | |
| 612 AutoOp op(this, "DrawTextBlob", &paint); | |
| 613 op.addParam("blob", AsValue(*blob)); | |
| 614 op.addParam("x", AsValue(x)); | |
| 615 op.addParam("y", AsValue(y)); | |
| 616 | |
| 617 INHERITED::onDrawTextBlob(blob, x, y, paint); | |
| 249 } | 618 } |
| 250 | 619 |
| 251 } // namespace skia | 620 } // namespace skia |
| OLD | NEW |