| 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" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 return vv->onPaint(canvas); | 28 return vv->onPaint(canvas); |
| 29 } | 29 } |
| 30 | 30 |
| 31 static bool on_touch_handler(int owner, Window::InputState state, float x, float
y, void* userData) | 31 static bool on_touch_handler(int owner, Window::InputState state, float x, float
y, void* userData) |
| 32 { | 32 { |
| 33 Viewer* viewer = reinterpret_cast<Viewer*>(userData); | 33 Viewer* viewer = reinterpret_cast<Viewer*>(userData); |
| 34 | 34 |
| 35 return viewer->onTouch(owner, state, x, y); | 35 return viewer->onTouch(owner, state, x, y); |
| 36 } | 36 } |
| 37 | 37 |
| 38 static void on_ui_state_changed_handler(const SkString& stateName, const SkStrin
g& stateValue, void* userData) { | |
| 39 Viewer* viewer = reinterpret_cast<Viewer*>(userData); | |
| 40 | |
| 41 return viewer->onUIStateChanged(stateName, stateValue); | |
| 42 } | |
| 43 | |
| 44 DEFINE_bool2(fullscreen, f, true, "Run fullscreen."); | 38 DEFINE_bool2(fullscreen, f, true, "Run fullscreen."); |
| 45 DEFINE_string(key, "", "Space-separated key/value pairs to add to JSON identifyi
ng this builder."); | 39 DEFINE_string(key, "", "Space-separated key/value pairs to add to JSON identifyi
ng this builder."); |
| 46 DEFINE_string2(match, m, nullptr, | 40 DEFINE_string2(match, m, nullptr, |
| 47 "[~][^]substring[$] [...] of bench name to run.\n" | 41 "[~][^]substring[$] [...] of bench name to run.\n" |
| 48 "Multiple matches may be separated by spaces.\n" | 42 "Multiple matches may be separated by spaces.\n" |
| 49 "~ causes a matching bench to always be skipped\n" | 43 "~ causes a matching bench to always be skipped\n" |
| 50 "^ requires the start of the bench to match\n" | 44 "^ requires the start of the bench to match\n" |
| 51 "$ requires the end of the bench to match\n" | 45 "$ requires the end of the bench to match\n" |
| 52 "^ and $ requires an exact match\n" | 46 "^ and $ requires an exact match\n" |
| 53 "If a bench does not match any list entry,\n" | 47 "If a bench does not match any list entry,\n" |
| 54 "it is skipped unless some list entry starts with ~"); | 48 "it is skipped unless some list entry starts with ~"); |
| 55 DEFINE_string(skps, "skps", "Directory to read skps from."); | 49 DEFINE_string(skps, "skps", "Directory to read skps from."); |
| 56 | 50 |
| 57 const char *kBackendTypeStrings[sk_app::Window::kBackendTypeCount] = { | 51 const char *kBackendTypeStrings[sk_app::Window::kBackendTypeCount] = { |
| 58 " [OpenGL]", | 52 " [OpenGL]", |
| 59 " [Vulkan]" | 53 " [Vulkan]" |
| 60 }; | 54 }; |
| 61 | 55 |
| 62 const char* kName = "name"; | |
| 63 const char* kValue = "value"; | |
| 64 const char* kOptions = "options"; | |
| 65 const char* kSlideStateName = "Slide"; | |
| 66 const char* kBackendStateName = "Backend"; | |
| 67 | |
| 68 Viewer::Viewer(int argc, char** argv, void* platformData) | 56 Viewer::Viewer(int argc, char** argv, void* platformData) |
| 69 : fCurrentMeasurement(0) | 57 : fCurrentMeasurement(0) |
| 70 , fDisplayStats(false) | 58 , fDisplayStats(false) |
| 71 , fBackendType(sk_app::Window::kVulkan_BackendType) | 59 , fBackendType(sk_app::Window::kVulkan_BackendType) |
| 72 , fZoomCenterX(0.0f) | 60 , fZoomCenterX(0.0f) |
| 73 , fZoomCenterY(0.0f) | 61 , fZoomCenterY(0.0f) |
| 74 , fZoomLevel(0.0f) | 62 , fZoomLevel(0.0f) |
| 75 , fZoomScale(SK_Scalar1) | 63 , fZoomScale(SK_Scalar1) |
| 76 { | 64 { |
| 77 memset(fMeasurements, 0, sizeof(fMeasurements)); | 65 memset(fMeasurements, 0, sizeof(fMeasurements)); |
| 78 | 66 |
| 79 SkDebugf("Command line arguments: "); | 67 SkDebugf("Command line arguments: "); |
| 80 for (int i = 1; i < argc; ++i) { | 68 for (int i = 1; i < argc; ++i) { |
| 81 SkDebugf("%s ", argv[i]); | 69 SkDebugf("%s ", argv[i]); |
| 82 } | 70 } |
| 83 SkDebugf("\n"); | 71 SkDebugf("\n"); |
| 84 | 72 |
| 85 SkCommandLineFlags::Parse(argc, argv); | 73 SkCommandLineFlags::Parse(argc, argv); |
| 86 | 74 |
| 87 fWindow = Window::CreateNativeWindow(platformData); | 75 fWindow = Window::CreateNativeWindow(platformData); |
| 88 fWindow->attach(fBackendType, DisplayParams()); | 76 fWindow->attach(fBackendType, DisplayParams()); |
| 89 | 77 |
| 90 // register callbacks | 78 // register callbacks |
| 91 fCommands.attach(fWindow); | 79 fCommands.attach(fWindow); |
| 92 fWindow->registerPaintFunc(on_paint_handler, this); | 80 fWindow->registerPaintFunc(on_paint_handler, this); |
| 93 fWindow->registerTouchFunc(on_touch_handler, this); | 81 fWindow->registerTouchFunc(on_touch_handler, this); |
| 94 fWindow->registerUIStateChangedFunc(on_ui_state_changed_handler, this); | |
| 95 | 82 |
| 96 // add key-bindings | 83 // add key-bindings |
| 97 fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() { | 84 fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() { |
| 98 this->fDisplayStats = !this->fDisplayStats; | 85 this->fDisplayStats = !this->fDisplayStats; |
| 99 fWindow->inval(); | 86 fWindow->inval(); |
| 100 }); | 87 }); |
| 101 fCommands.addCommand('c', "Modes", "Toggle sRGB color mode", [this]() { | 88 fCommands.addCommand('c', "Modes", "Toggle sRGB color mode", [this]() { |
| 102 DisplayParams params = fWindow->getDisplayParams(); | 89 DisplayParams params = fWindow->getDisplayParams(); |
| 103 params.fProfileType = (kLinear_SkColorProfileType == params.fProfileType
) | 90 params.fProfileType = (kLinear_SkColorProfileType == params.fProfileType
) |
| 104 ? kSRGB_SkColorProfileType : kLinear_SkColorProfileType; | 91 ? kSRGB_SkColorProfileType : kLinear_SkColorProfileType; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 SkString title("Viewer: "); | 206 SkString title("Viewer: "); |
| 220 title.append(fSlides[fCurrentSlide]->getName()); | 207 title.append(fSlides[fCurrentSlide]->getName()); |
| 221 if (kSRGB_SkColorProfileType == fWindow->getDisplayParams().fProfileType) { | 208 if (kSRGB_SkColorProfileType == fWindow->getDisplayParams().fProfileType) { |
| 222 title.append(" sRGB"); | 209 title.append(" sRGB"); |
| 223 } | 210 } |
| 224 title.append(kBackendTypeStrings[fBackendType]); | 211 title.append(kBackendTypeStrings[fBackendType]); |
| 225 fWindow->setTitle(title.c_str()); | 212 fWindow->setTitle(title.c_str()); |
| 226 } | 213 } |
| 227 | 214 |
| 228 void Viewer::setupCurrentSlide(int previousSlide) { | 215 void Viewer::setupCurrentSlide(int previousSlide) { |
| 229 if (fCurrentSlide == previousSlide) { | |
| 230 return; // no change; do nothing | |
| 231 } | |
| 232 | |
| 233 fGesture.reset(); | 216 fGesture.reset(); |
| 234 fDefaultMatrix.reset(); | 217 fDefaultMatrix.reset(); |
| 235 fDefaultMatrixInv.reset(); | 218 fDefaultMatrixInv.reset(); |
| 236 | 219 |
| 237 if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) { | 220 if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) { |
| 238 const SkRect contentRect = fWindow->getContentRect(); | 221 const SkRect contentRect = fWindow->getContentRect(); |
| 239 const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions(); | 222 const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions(); |
| 240 const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize.
height()); | 223 const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize.
height()); |
| 241 if (contentRect.width() > 0 && contentRect.height() > 0) { | 224 if (contentRect.width() > 0 && contentRect.height() > 0) { |
| 242 fDefaultMatrix.setRectToRect(slideBounds, contentRect, SkMatrix::kSt
art_ScaleToFit); | 225 fDefaultMatrix.setRectToRect(slideBounds, contentRect, SkMatrix::kSt
art_ScaleToFit); |
| 243 SkAssertResult(fDefaultMatrix.invert(&fDefaultMatrixInv)); | 226 SkAssertResult(fDefaultMatrix.invert(&fDefaultMatrixInv)); |
| 244 } | 227 } |
| 245 } | 228 } |
| 246 | 229 |
| 247 if (fWindow->supportsContentRect()) { | 230 if (fWindow->supportsContentRect()) { |
| 248 const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions(); | 231 const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions(); |
| 249 SkRect windowRect = fWindow->getContentRect(); | 232 SkRect windowRect = fWindow->getContentRect(); |
| 250 fDefaultMatrixInv.mapRect(&windowRect); | 233 fDefaultMatrixInv.mapRect(&windowRect); |
| 251 fGesture.setTransLimit(SkRect::MakeWH(slideSize.width(), slideSize.heigh
t()), windowRect); | 234 fGesture.setTransLimit(SkRect::MakeWH(slideSize.width(), slideSize.heigh
t()), windowRect); |
| 252 } | 235 } |
| 253 | 236 |
| 254 this->updateTitle(); | 237 this->updateTitle(); |
| 255 this->updateUIState(); | |
| 256 fSlides[fCurrentSlide]->load(); | 238 fSlides[fCurrentSlide]->load(); |
| 257 if (previousSlide >= 0) { | 239 if (previousSlide >= 0) { |
| 258 fSlides[previousSlide]->unload(); | 240 fSlides[previousSlide]->unload(); |
| 259 } | 241 } |
| 260 fWindow->inval(); | 242 fWindow->inval(); |
| 261 } | 243 } |
| 262 | 244 |
| 263 #define MAX_ZOOM_LEVEL 8 | 245 #define MAX_ZOOM_LEVEL 8 |
| 264 #define MIN_ZOOM_LEVEL -8 | 246 #define MIN_ZOOM_LEVEL -8 |
| 265 | 247 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 // Record measurements | 375 // Record measurements |
| 394 fMeasurements[fCurrentMeasurement++] = ms; | 376 fMeasurements[fCurrentMeasurement++] = ms; |
| 395 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod | 377 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod |
| 396 SkASSERT(fCurrentMeasurement < kMeasurementCount); | 378 SkASSERT(fCurrentMeasurement < kMeasurementCount); |
| 397 | 379 |
| 398 fAnimTimer.updateTime(); | 380 fAnimTimer.updateTime(); |
| 399 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) { | 381 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) { |
| 400 fWindow->inval(); | 382 fWindow->inval(); |
| 401 } | 383 } |
| 402 } | 384 } |
| 403 | |
| 404 void Viewer::updateUIState() { | |
| 405 Json::Value slideState(Json::objectValue); | |
| 406 slideState[kName] = kSlideStateName; | |
| 407 slideState[kValue] = fSlides[fCurrentSlide]->getName().c_str(); | |
| 408 Json::Value allSlideNames(Json::arrayValue); | |
| 409 for(auto slide : fSlides) { | |
| 410 allSlideNames.append(Json::Value(slide->getName().c_str())); | |
| 411 } | |
| 412 slideState[kOptions] = allSlideNames; | |
| 413 | |
| 414 // This state is currently a demo for the one without options. | |
| 415 // We will be able to change the backend too. | |
| 416 Json::Value backendState(Json::objectValue); | |
| 417 backendState[kName] = kBackendStateName; | |
| 418 backendState[kValue] = fBackendType == sk_app::Window::kVulkan_BackendType ? | |
| 419 "Vulkan" : "Other than Vulkan"; | |
| 420 backendState[kOptions] = Json::Value(Json::arrayValue); | |
| 421 | |
| 422 Json::Value state(Json::arrayValue); | |
| 423 state.append(slideState); | |
| 424 state.append(backendState); | |
| 425 | |
| 426 fWindow->setUIState(state); | |
| 427 } | |
| 428 | |
| 429 void Viewer::onUIStateChanged(const SkString& stateName, const SkString& stateVa
lue) { | |
| 430 // Currently, we only recognize the Slide state | |
| 431 if (stateName.equals(kSlideStateName)) { | |
| 432 int previousSlide = fCurrentSlide; | |
| 433 fCurrentSlide = 0; | |
| 434 for(auto slide : fSlides) { | |
| 435 if (slide->getName().equals(stateValue)) { | |
| 436 setupCurrentSlide(previousSlide); | |
| 437 break; | |
| 438 } | |
| 439 fCurrentSlide++; | |
| 440 } | |
| 441 if (fCurrentSlide >= fSlides.count()) { | |
| 442 fCurrentSlide = previousSlide; | |
| 443 SkDebugf("Slide not found: %s", stateValue.c_str()); | |
| 444 } | |
| 445 } else { | |
| 446 SkDebugf("Unknown stateName: %s", stateName.c_str()); | |
| 447 } | |
| 448 } | |
| OLD | NEW |