OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "Viewer.h" | 8 #include "Viewer.h" |
9 | 9 |
10 #include "GMSlide.h" | 10 #include "GMSlide.h" |
11 #include "ImageSlide.h" | 11 #include "ImageSlide.h" |
12 #include "SampleSlide.h" | 12 #include "SampleSlide.h" |
13 #include "SKPSlide.h" | 13 #include "SKPSlide.h" |
14 | 14 |
15 #include "SkCanvas.h" | 15 #include "SkCanvas.h" |
16 #include "SkCommonFlags.h" | 16 #include "SkCommonFlags.h" |
17 #include "SkDashPathEffect.h" | 17 #include "SkDashPathEffect.h" |
18 #include "SkMetaData.h" | 18 #include "SkMetaData.h" |
19 #include "SkOSFile.h" | 19 #include "SkOSFile.h" |
20 #include "SkRandom.h" | 20 #include "SkRandom.h" |
21 #include "SkStream.h" | 21 #include "SkStream.h" |
22 #include "SkSurface.h" | 22 #include "SkSurface.h" |
| 23 #include "SkTime.h" |
23 | 24 |
24 using namespace sk_app; | 25 using namespace sk_app; |
25 | 26 |
26 Application* Application::Create(int argc, char** argv, void* platformData) { | 27 Application* Application::Create(int argc, char** argv, void* platformData) { |
27 return new Viewer(argc, argv, platformData); | 28 return new Viewer(argc, argv, platformData); |
28 } | 29 } |
29 | 30 |
30 static void on_paint_handler(SkCanvas* canvas, void* userData) { | 31 static void on_paint_handler(SkCanvas* canvas, void* userData) { |
31 Viewer* vv = reinterpret_cast<Viewer*>(userData); | 32 Viewer* vv = reinterpret_cast<Viewer*>(userData); |
32 | 33 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 const char* kValue = "value"; | 80 const char* kValue = "value"; |
80 const char* kOptions = "options"; | 81 const char* kOptions = "options"; |
81 const char* kSlideStateName = "Slide"; | 82 const char* kSlideStateName = "Slide"; |
82 const char* kBackendStateName = "Backend"; | 83 const char* kBackendStateName = "Backend"; |
83 const char* kSoftkeyStateName = "Softkey"; | 84 const char* kSoftkeyStateName = "Softkey"; |
84 const char* kSoftkeyHint = "Please select a softkey"; | 85 const char* kSoftkeyHint = "Please select a softkey"; |
85 const char* kFpsStateName = "FPS"; | 86 const char* kFpsStateName = "FPS"; |
86 const char* kSplitScreenStateName = "Split screen"; | 87 const char* kSplitScreenStateName = "Split screen"; |
87 const char* kON = "ON"; | 88 const char* kON = "ON"; |
88 const char* kOFF = "OFF"; | 89 const char* kOFF = "OFF"; |
| 90 const char* kRefreshStateName = "Refresh"; |
89 | 91 |
90 Viewer::Viewer(int argc, char** argv, void* platformData) | 92 Viewer::Viewer(int argc, char** argv, void* platformData) |
91 : fCurrentMeasurement(0) | 93 : fCurrentMeasurement(0) |
92 , fDisplayStats(false) | 94 , fDisplayStats(false) |
| 95 , fRefresh(false) |
93 , fSplitScreen(false) | 96 , fSplitScreen(false) |
94 , fBackendType(sk_app::Window::kNativeGL_BackendType) | 97 , fBackendType(sk_app::Window::kNativeGL_BackendType) |
95 , fZoomCenterX(0.0f) | 98 , fZoomCenterX(0.0f) |
96 , fZoomCenterY(0.0f) | 99 , fZoomCenterY(0.0f) |
97 , fZoomLevel(0.0f) | 100 , fZoomLevel(0.0f) |
98 , fZoomScale(SK_Scalar1) | 101 , fZoomScale(SK_Scalar1) |
99 { | 102 { |
100 memset(fMeasurements, 0, sizeof(fMeasurements)); | 103 memset(fMeasurements, 0, sizeof(fMeasurements)); |
101 | 104 |
102 SkDebugf("Command line arguments: "); | 105 SkDebugf("Command line arguments: "); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 SkPaint paint; | 396 SkPaint paint; |
394 SkScalar intervals[] = {10.0f, 5.0f}; | 397 SkScalar intervals[] = {10.0f, 5.0f}; |
395 paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0.0f)); | 398 paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0.0f)); |
396 SkRect contentRect = fWindow->getContentRect(); | 399 SkRect contentRect = fWindow->getContentRect(); |
397 SkScalar middleX = (contentRect.fLeft + contentRect.fRight) * 0.5f; | 400 SkScalar middleX = (contentRect.fLeft + contentRect.fRight) * 0.5f; |
398 canvas->drawLine(middleX, contentRect.fTop, middleX, contentRect.fBottom
, paint); | 401 canvas->drawLine(middleX, contentRect.fTop, middleX, contentRect.fBottom
, paint); |
399 } | 402 } |
400 } | 403 } |
401 | 404 |
402 void Viewer::onPaint(SkCanvas* canvas) { | 405 void Viewer::onPaint(SkCanvas* canvas) { |
| 406 // Record measurements |
| 407 double startTime = SkTime::GetMSecs(); |
| 408 |
403 drawSlide(canvas, false); | 409 drawSlide(canvas, false); |
404 if (fSplitScreen && fWindow->supportsContentRect()) { | 410 if (fSplitScreen && fWindow->supportsContentRect()) { |
405 drawSlide(canvas, true); | 411 drawSlide(canvas, true); |
406 } | 412 } |
407 | 413 |
408 if (fDisplayStats) { | 414 if (fDisplayStats) { |
409 drawStats(canvas); | 415 drawStats(canvas); |
410 } | 416 } |
411 fCommands.drawHelp(canvas); | 417 fCommands.drawHelp(canvas); |
| 418 |
| 419 fMeasurements[fCurrentMeasurement++] = SkTime::GetMSecs() - startTime; |
| 420 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod |
| 421 SkASSERT(fCurrentMeasurement < kMeasurementCount); |
| 422 updateUIState(); // Update the FPS |
412 } | 423 } |
413 | 424 |
414 bool Viewer::onTouch(intptr_t owner, Window::InputState state, float x, float y)
{ | 425 bool Viewer::onTouch(intptr_t owner, Window::InputState state, float x, float y)
{ |
415 void* castedOwner = reinterpret_cast<void*>(owner); | 426 void* castedOwner = reinterpret_cast<void*>(owner); |
416 SkPoint touchPoint = fDefaultMatrixInv.mapXY(x, y); | 427 SkPoint touchPoint = fDefaultMatrixInv.mapXY(x, y); |
417 switch (state) { | 428 switch (state) { |
418 case Window::kUp_InputState: { | 429 case Window::kUp_InputState: { |
419 fGesture.touchEnd(castedOwner); | 430 fGesture.touchEnd(castedOwner); |
420 break; | 431 break; |
421 } | 432 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 canvas->drawLine(SkIntToScalar(x), SkIntToScalar(startY), | 484 canvas->drawLine(SkIntToScalar(x), SkIntToScalar(startY), |
474 SkIntToScalar(x), SkIntToScalar(endY), paint); | 485 SkIntToScalar(x), SkIntToScalar(endY), paint); |
475 i++; | 486 i++; |
476 i &= (kMeasurementCount - 1); // fast mod | 487 i &= (kMeasurementCount - 1); // fast mod |
477 x += xStep; | 488 x += xStep; |
478 } while (i != fCurrentMeasurement); | 489 } while (i != fCurrentMeasurement); |
479 | 490 |
480 canvas->restore(); | 491 canvas->restore(); |
481 } | 492 } |
482 | 493 |
483 void Viewer::onIdle(double ms) { | 494 void Viewer::onIdle() { |
484 // Record measurements | |
485 fMeasurements[fCurrentMeasurement++] = ms; | |
486 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod | |
487 SkASSERT(fCurrentMeasurement < kMeasurementCount); | |
488 | |
489 fAnimTimer.updateTime(); | 495 fAnimTimer.updateTime(); |
490 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) { | 496 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats || fRefresh
) { |
491 fWindow->inval(); | 497 fWindow->inval(); |
492 updateUIState(); // Update the FPS | |
493 } | 498 } |
494 } | 499 } |
495 | 500 |
496 void Viewer::updateUIState() { | 501 void Viewer::updateUIState() { |
497 // Slide state | 502 // Slide state |
498 Json::Value slideState(Json::objectValue); | 503 Json::Value slideState(Json::objectValue); |
499 slideState[kName] = kSlideStateName; | 504 slideState[kName] = kSlideStateName; |
500 slideState[kValue] = fSlides[fCurrentSlide]->getName().c_str(); | 505 slideState[kValue] = fSlides[fCurrentSlide]->getName().c_str(); |
501 if (fAllSlideNames.size() == 0) { | 506 if (fAllSlideNames.size() == 0) { |
502 for(auto slide : fSlides) { | 507 for(auto slide : fSlides) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 fCommands.onSoftkey(stateValue); | 594 fCommands.onSoftkey(stateValue); |
590 updateUIState(); // This is still needed to reset the value to kSoft
keyHint | 595 updateUIState(); // This is still needed to reset the value to kSoft
keyHint |
591 } | 596 } |
592 } else if (stateName.equals(kSplitScreenStateName)) { | 597 } else if (stateName.equals(kSplitScreenStateName)) { |
593 bool newSplitScreen = stateValue.equals(kON); | 598 bool newSplitScreen = stateValue.equals(kON); |
594 if (newSplitScreen != fSplitScreen) { | 599 if (newSplitScreen != fSplitScreen) { |
595 fSplitScreen = newSplitScreen; | 600 fSplitScreen = newSplitScreen; |
596 fWindow->inval(); | 601 fWindow->inval(); |
597 updateUIState(); | 602 updateUIState(); |
598 } | 603 } |
| 604 } else if (stateName.equals(kRefreshStateName)) { |
| 605 // This state is actually NOT in the UI state. |
| 606 // We use this to allow Android to quickly set bool fRefresh. |
| 607 fRefresh = stateValue.equals(kON); |
599 } else { | 608 } else { |
600 SkDebugf("Unknown stateName: %s", stateName.c_str()); | 609 SkDebugf("Unknown stateName: %s", stateName.c_str()); |
601 } | 610 } |
602 } | 611 } |
OLD | NEW |