OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "VisualInteractiveModule.h" | 8 #include "VisualInteractiveModule.h" |
9 | 9 |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 SkISize canvasSize = canvas->getDeviceSize(); | 34 SkISize canvasSize = canvas->getDeviceSize(); |
35 SkRect rect = SkRect::MakeXYWH(SkIntToScalar(canvasSize.fWidth-kDisplayWidth
-kDisplayPadding), | 35 SkRect rect = SkRect::MakeXYWH(SkIntToScalar(canvasSize.fWidth-kDisplayWidth
-kDisplayPadding), |
36 SkIntToScalar(kDisplayPadding), | 36 SkIntToScalar(kDisplayPadding), |
37 SkIntToScalar(kDisplayWidth), SkIntToScalar(k
DisplayHeight)); | 37 SkIntToScalar(kDisplayWidth), SkIntToScalar(k
DisplayHeight)); |
38 SkPaint paint; | 38 SkPaint paint; |
39 canvas->clipRect(rect); | 39 canvas->clipRect(rect); |
40 paint.setColor(SK_ColorBLACK); | 40 paint.setColor(SK_ColorBLACK); |
41 canvas->drawRect(rect, paint); | 41 canvas->drawRect(rect, paint); |
42 // draw the 16ms line | 42 // draw the 16ms line |
43 paint.setColor(SK_ColorLTGRAY); | 43 paint.setColor(SK_ColorLTGRAY); |
44 canvas->drawLine(rect.fLeft, rect.fBottom - kBaseMS*kPixelPerMS, | 44 canvas->drawLine(rect.fLeft, rect.fBottom - kBaseMS*kPixelPerMS, |
45 rect.fRight, rect.fBottom - kBaseMS*kPixelPerMS, paint); | 45 rect.fRight, rect.fBottom - kBaseMS*kPixelPerMS, paint); |
46 paint.setColor(SK_ColorRED); | 46 paint.setColor(SK_ColorRED); |
47 paint.setStyle(SkPaint::kStroke_Style); | 47 paint.setStyle(SkPaint::kStroke_Style); |
48 canvas->drawRect(rect, paint); | 48 canvas->drawRect(rect, paint); |
49 | 49 |
50 int x = SkScalarTruncToInt(rect.fLeft) + kGraphPadding; | 50 int x = SkScalarTruncToInt(rect.fLeft) + kGraphPadding; |
51 const int xStep = 2; | 51 const int xStep = 2; |
52 const int startY = SkScalarTruncToInt(rect.fBottom); | 52 const int startY = SkScalarTruncToInt(rect.fBottom); |
53 int i = fCurrentMeasurement; | 53 int i = fCurrentMeasurement; |
54 do { | 54 do { |
55 int endY = startY - (int)(fMeasurements[i] * kPixelPerMS + 0.5); // rou
nd to nearest value | 55 int endY = startY - (int)(fMeasurements[i] * kPixelPerMS + 0.5); // rou
nd to nearest value |
56 canvas->drawLine(SkIntToScalar(x), SkIntToScalar(startY), | 56 canvas->drawLine(SkIntToScalar(x), SkIntToScalar(startY), |
57 SkIntToScalar(x), SkIntToScalar(endY), paint); | 57 SkIntToScalar(x), SkIntToScalar(endY), paint); |
58 i++; | 58 i++; |
59 i &= (kMeasurementCount - 1); // fast mod | 59 i &= (kMeasurementCount - 1); // fast mod |
60 x += xStep; | 60 x += xStep; |
61 } while (i != fCurrentMeasurement); | 61 } while (i != fCurrentMeasurement); |
62 | 62 |
63 } | 63 } |
64 | 64 |
65 bool VisualInteractiveModule::timingFinished(Benchmark* benchmark, int loops, do
uble measurement) { | 65 bool VisualInteractiveModule::timingFinished(Benchmark* benchmark, int loops, do
uble measurement) { |
66 // Record measurements | 66 // Record measurements |
67 fMeasurements[fCurrentMeasurement++] = measurement; | 67 fMeasurements[fCurrentMeasurement++] = measurement; |
68 fCurrentMeasurement &= (kMeasurementCount-1); // fast mod | 68 fCurrentMeasurement &= (kMeasurementCount-1); // fast mod |
69 SkASSERT(fCurrentMeasurement < kMeasurementCount); | 69 SkASSERT(fCurrentMeasurement < kMeasurementCount); |
70 if (fAdvance) { | 70 if (fAdvance) { |
71 fAdvance = false; | 71 fAdvance = false; |
72 return true; | 72 return true; |
73 } | 73 } |
74 return false; | 74 return false; |
75 } | 75 } |
76 | 76 |
77 bool VisualInteractiveModule::onHandleChar(SkUnichar c) { | 77 bool VisualInteractiveModule::onHandleChar(SkUnichar c) { |
78 if (' ' == c) { | 78 if (' ' == c) { |
79 fAdvance = true; | 79 fAdvance = true; |
80 } | 80 } |
81 | 81 |
82 return true; | 82 return true; |
83 } | 83 } |
OLD | NEW |