Index: tools/vulkan/viewer/VulkanViewer.cpp |
diff --git a/tools/vulkan/viewer/VulkanViewer.cpp b/tools/vulkan/viewer/VulkanViewer.cpp |
index 27e7b1c08253a7d51cee623956dcab2276d389da..5c6e780f95c4044ff7c49ead1cb96e10485c0cf0 100644 |
--- a/tools/vulkan/viewer/VulkanViewer.cpp |
+++ b/tools/vulkan/viewer/VulkanViewer.cpp |
@@ -31,8 +31,10 @@ static void on_paint_handler(SkCanvas* canvas, void* userData) { |
return vv->onPaint(canvas); |
} |
-VulkanViewer::VulkanViewer(int argc, char** argv, void* platformData) : |
- fGMs(skiagm::GMRegistry::Head()){ |
+VulkanViewer::VulkanViewer(int argc, char** argv, void* platformData) |
+ : fGMs(skiagm::GMRegistry::Head()) |
+ , fCurrentMeasurement(0) { |
+ memset(fMeasurements, 0, sizeof(fMeasurements)); |
fWindow = Window::CreateNativeWindow(platformData); |
fWindow->attach(Window::kVulkan_BackendType, 0, nullptr); |
@@ -41,7 +43,10 @@ VulkanViewer::VulkanViewer(int argc, char** argv, void* platformData) : |
fWindow->registerKeyFunc(on_key_handler, this); |
fWindow->registerPaintFunc(on_paint_handler, this); |
- fWindow->setTitle("VulkanViewer"); |
+ SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(nullptr)); |
+ SkString title("VulkanViewer: "); |
+ title.append(gm->getName()); |
+ fWindow->setTitle(title.c_str()); |
fWindow->show(); |
} |
@@ -54,7 +59,11 @@ bool VulkanViewer::onKey(Window::Key key, Window::InputState state, uint32_t mod |
if (Window::kDown_InputState == state && (modifiers & Window::kFirstPress_ModifierKey) && |
key == Window::kRight_Key) { |
fGMs = fGMs->next(); |
- } |
+ SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(nullptr)); |
+ SkString title("VulkanViewer: "); |
+ title.append(gm->getName()); |
+ fWindow->setTitle(title.c_str()); |
+ } |
return true; |
} |
@@ -63,12 +72,59 @@ void VulkanViewer::onPaint(SkCanvas* canvas) { |
SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(nullptr)); |
canvas->save(); |
- |
gm->draw(canvas); |
+ canvas->restore(); |
+ |
+ drawStats(canvas); |
+} |
+ |
+void VulkanViewer::drawStats(SkCanvas* canvas) { |
+ static const float kPixelPerMS = 2.0f; |
+ static const int kDisplayWidth = 130; |
+ static const int kDisplayHeight = 100; |
+ static const int kDisplayPadding = 10; |
+ static const int kGraphPadding = 3; |
+ static const SkScalar kBaseMS = 1000.f / 60.f; // ms/frame to hit 60 fps |
+ |
+ SkISize canvasSize = canvas->getDeviceSize(); |
+ SkRect rect = SkRect::MakeXYWH(SkIntToScalar(canvasSize.fWidth-kDisplayWidth-kDisplayPadding), |
+ SkIntToScalar(kDisplayPadding), |
+ SkIntToScalar(kDisplayWidth), SkIntToScalar(kDisplayHeight)); |
+ SkPaint paint; |
+ canvas->save(); |
+ |
+ canvas->clipRect(rect); |
+ paint.setColor(SK_ColorBLACK); |
+ canvas->drawRect(rect, paint); |
+ // draw the 16ms line |
+ paint.setColor(SK_ColorLTGRAY); |
+ canvas->drawLine(rect.fLeft, rect.fBottom - kBaseMS*kPixelPerMS, |
+ rect.fRight, rect.fBottom - kBaseMS*kPixelPerMS, paint); |
+ paint.setColor(SK_ColorRED); |
+ paint.setStyle(SkPaint::kStroke_Style); |
+ canvas->drawRect(rect, paint); |
+ |
+ int x = SkScalarTruncToInt(rect.fLeft) + kGraphPadding; |
+ const int xStep = 2; |
+ const int startY = SkScalarTruncToInt(rect.fBottom); |
+ int i = fCurrentMeasurement; |
+ do { |
+ int endY = startY - (int)(fMeasurements[i] * kPixelPerMS + 0.5); // round to nearest value |
+ canvas->drawLine(SkIntToScalar(x), SkIntToScalar(startY), |
+ SkIntToScalar(x), SkIntToScalar(endY), paint); |
+ i++; |
+ i &= (kMeasurementCount - 1); // fast mod |
+ x += xStep; |
+ } while (i != fCurrentMeasurement); |
canvas->restore(); |
} |
-void VulkanViewer::onIdle(float dt) { |
+void VulkanViewer::onIdle(double ms) { |
+ // Record measurements |
+ fMeasurements[fCurrentMeasurement++] = ms; |
+ fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod |
+ SkASSERT(fCurrentMeasurement < kMeasurementCount); |
+ |
fWindow->onPaint(); |
} |