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

Side by Side Diff: tools/VisualBench/VisualInteractiveModule.cpp

Issue 2018603003: Remove VisualBench and its Android implementation. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 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
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 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 "VisualInteractiveModule.h"
9
10 #include "SkCanvas.h"
11 #include "SkCommandLineFlags.h"
12
13 VisualInteractiveModule::VisualInteractiveModule(VisualBench* owner)
14 : INHERITED(owner)
15 , fCurrentMeasurement(0)
16 , fAdvance(false) {
17 memset(fMeasurements, 0, sizeof(fMeasurements));
18 }
19
20 void VisualInteractiveModule::renderFrame(SkCanvas* canvas, Benchmark* benchmark , int loops) {
21 benchmark->draw(loops, canvas);
22 this->drawStats(canvas);
23 canvas->flush();
24 }
25
26 void VisualInteractiveModule::drawStats(SkCanvas* canvas) {
27 static const float kPixelPerMS = 2.0f;
28 static const int kDisplayWidth = 130;
29 static const int kDisplayHeight = 100;
30 static const int kDisplayPadding = 10;
31 static const int kGraphPadding = 3;
32 static const float kBaseMS = 1000.f / 60.f; // ms/frame to hit 60 fps
33
34 SkISize canvasSize = canvas->getDeviceSize();
35 SkRect rect = SkRect::MakeXYWH(SkIntToScalar(canvasSize.fWidth-kDisplayWidth -kDisplayPadding),
36 SkIntToScalar(kDisplayPadding),
37 SkIntToScalar(kDisplayWidth), SkIntToScalar(k DisplayHeight));
38 SkPaint paint;
39 canvas->clipRect(rect);
40 paint.setColor(SK_ColorBLACK);
41 canvas->drawRect(rect, paint);
42 // draw the 16ms line
43 paint.setColor(SK_ColorLTGRAY);
44 canvas->drawLine(rect.fLeft, rect.fBottom - kBaseMS*kPixelPerMS,
45 rect.fRight, rect.fBottom - kBaseMS*kPixelPerMS, paint);
46 paint.setColor(SK_ColorRED);
47 paint.setStyle(SkPaint::kStroke_Style);
48 canvas->drawRect(rect, paint);
49
50 int x = SkScalarTruncToInt(rect.fLeft) + kGraphPadding;
51 const int xStep = 2;
52 const int startY = SkScalarTruncToInt(rect.fBottom);
53 int i = fCurrentMeasurement;
54 do {
55 int endY = startY - (int)(fMeasurements[i] * kPixelPerMS + 0.5); // rou nd to nearest value
56 canvas->drawLine(SkIntToScalar(x), SkIntToScalar(startY),
57 SkIntToScalar(x), SkIntToScalar(endY), paint);
58 i++;
59 i &= (kMeasurementCount - 1); // fast mod
60 x += xStep;
61 } while (i != fCurrentMeasurement);
62
63 }
64
65 bool VisualInteractiveModule::timingFinished(Benchmark* benchmark, int loops, do uble measurement) {
66 // Record measurements
67 fMeasurements[fCurrentMeasurement++] = measurement;
68 fCurrentMeasurement &= (kMeasurementCount-1); // fast mod
69 SkASSERT(fCurrentMeasurement < kMeasurementCount);
70 if (fAdvance) {
71 fAdvance = false;
72 return true;
73 }
74 return false;
75 }
76
77 bool VisualInteractiveModule::onHandleChar(SkUnichar c) {
78 if (' ' == c) {
79 fAdvance = true;
80 }
81
82 return true;
83 }
OLDNEW
« no previous file with comments | « tools/VisualBench/VisualInteractiveModule.h ('k') | tools/VisualBench/VisualLightweightBenchModule.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698