Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / bench / SKPBench.cpp
1 /*
2  * Copyright 2014 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7
8 #include "SKPBench.h"
9 #include "SkCommandLineFlags.h"
10
11 DEFINE_int32(benchTile, 256, "Tile dimension used for SKP playback.");
12
13 SKPBench::SKPBench(const char* name, const SkPicture* pic, const SkIRect& clip, SkScalar scale)
14     : fPic(SkRef(pic))
15     , fClip(clip)
16     , fScale(scale)
17     , fName(name) {
18     fUniqueName.printf("%s_%.2g", name, scale);  // Scale makes this unqiue for skiaperf.com traces.
19 }
20
21 const char* SKPBench::onGetName() {
22     return fName.c_str();
23 }
24
25 const char* SKPBench::onGetUniqueName() {
26     return fUniqueName.c_str();
27 }
28
29 bool SKPBench::isSuitableFor(Backend backend) {
30     return backend != kNonRendering_Backend;
31 }
32
33 SkIPoint SKPBench::onGetSize() {
34     return SkIPoint::Make(fClip.width(), fClip.height());
35 }
36
37 void SKPBench::onDraw(const int loops, SkCanvas* canvas) {
38     SkIRect bounds;
39     SkAssertResult(canvas->getClipDeviceBounds(&bounds));
40
41     SkAutoCanvasRestore overall(canvas, true/*save now*/);
42     canvas->scale(fScale, fScale);
43
44     for (int i = 0; i < loops; i++) {
45         for (int y = bounds.fTop; y < bounds.fBottom; y += FLAGS_benchTile) {
46             for (int x = bounds.fLeft; x < bounds.fRight; x += FLAGS_benchTile) {
47                 SkAutoCanvasRestore perTile(canvas, true/*save now*/);
48                 canvas->clipRect(SkRect::Make(
49                             SkIRect::MakeXYWH(x, y, FLAGS_benchTile, FLAGS_benchTile)));
50                 fPic->playback(canvas);
51             }
52         }
53         canvas->flush();
54     }
55 }