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

Side by Side Diff: tools/viewer/Viewer.cpp

Issue 2004633002: Add drawer with state information (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Merge Created 4 years, 6 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
« no previous file with comments | « tools/viewer/Viewer.h ('k') | tools/viewer/sk_app/Window.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 DEFINE_bool2(fullscreen, f, false, "Run fullscreen."); 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.");
39 DEFINE_string(key, "", "Space-separated key/value pairs to add to JSON identifyi ng this builder."); 45 DEFINE_string(key, "", "Space-separated key/value pairs to add to JSON identifyi ng this builder.");
40 DEFINE_string2(match, m, nullptr, 46 DEFINE_string2(match, m, nullptr,
41 "[~][^]substring[$] [...] of bench name to run.\n" 47 "[~][^]substring[$] [...] of bench name to run.\n"
42 "Multiple matches may be separated by spaces.\n" 48 "Multiple matches may be separated by spaces.\n"
43 "~ causes a matching bench to always be skipped\n" 49 "~ causes a matching bench to always be skipped\n"
44 "^ requires the start of the bench to match\n" 50 "^ requires the start of the bench to match\n"
45 "$ requires the end of the bench to match\n" 51 "$ requires the end of the bench to match\n"
46 "^ and $ requires an exact match\n" 52 "^ and $ requires an exact match\n"
47 "If a bench does not match any list entry,\n" 53 "If a bench does not match any list entry,\n"
48 "it is skipped unless some list entry starts with ~"); 54 "it is skipped unless some list entry starts with ~");
49 DEFINE_string(skps, "skps", "Directory to read skps from."); 55 DEFINE_string(skps, "skps", "Directory to read skps from.");
50 DEFINE_bool(vulkan, true, "Run with Vulkan."); 56 DEFINE_bool(vulkan, true, "Run with Vulkan.");
51 57
52 const char *kBackendTypeStrings[sk_app::Window::kBackendTypeCount] = { 58 const char *kBackendTypeStrings[sk_app::Window::kBackendTypeCount] = {
53 " [OpenGL]", 59 " [OpenGL]",
54 " [Vulkan]" 60 " [Vulkan]"
55 }; 61 };
56 62
63 const char* kName = "name";
64 const char* kValue = "value";
65 const char* kOptions = "options";
66 const char* kSlideStateName = "Slide";
67 const char* kBackendStateName = "Backend";
68
57 Viewer::Viewer(int argc, char** argv, void* platformData) 69 Viewer::Viewer(int argc, char** argv, void* platformData)
58 : fCurrentMeasurement(0) 70 : fCurrentMeasurement(0)
59 , fDisplayStats(false) 71 , fDisplayStats(false)
60 , fBackendType(sk_app::Window::kVulkan_BackendType) 72 , fBackendType(sk_app::Window::kVulkan_BackendType)
61 , fZoomCenterX(0.0f) 73 , fZoomCenterX(0.0f)
62 , fZoomCenterY(0.0f) 74 , fZoomCenterY(0.0f)
63 , fZoomLevel(0.0f) 75 , fZoomLevel(0.0f)
64 , fZoomScale(SK_Scalar1) 76 , fZoomScale(SK_Scalar1)
65 { 77 {
66 memset(fMeasurements, 0, sizeof(fMeasurements)); 78 memset(fMeasurements, 0, sizeof(fMeasurements));
67 79
68 SkDebugf("Command line arguments: "); 80 SkDebugf("Command line arguments: ");
69 for (int i = 1; i < argc; ++i) { 81 for (int i = 1; i < argc; ++i) {
70 SkDebugf("%s ", argv[i]); 82 SkDebugf("%s ", argv[i]);
71 } 83 }
72 SkDebugf("\n"); 84 SkDebugf("\n");
73 85
74 SkCommandLineFlags::Parse(argc, argv); 86 SkCommandLineFlags::Parse(argc, argv);
75 87
76 fBackendType = FLAGS_vulkan ? sk_app::Window::kVulkan_BackendType 88 fBackendType = FLAGS_vulkan ? sk_app::Window::kVulkan_BackendType
77 : sk_app::Window::kNativeGL_BackendType; 89 : sk_app::Window::kNativeGL_BackendType;
78 90
79 fWindow = Window::CreateNativeWindow(platformData); 91 fWindow = Window::CreateNativeWindow(platformData);
80 fWindow->attach(fBackendType, DisplayParams()); 92 fWindow->attach(fBackendType, DisplayParams());
81 93
82 // register callbacks 94 // register callbacks
83 fCommands.attach(fWindow); 95 fCommands.attach(fWindow);
84 fWindow->registerPaintFunc(on_paint_handler, this); 96 fWindow->registerPaintFunc(on_paint_handler, this);
85 fWindow->registerTouchFunc(on_touch_handler, this); 97 fWindow->registerTouchFunc(on_touch_handler, this);
98 fWindow->registerUIStateChangedFunc(on_ui_state_changed_handler, this);
86 99
87 // add key-bindings 100 // add key-bindings
88 fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() { 101 fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() {
89 this->fDisplayStats = !this->fDisplayStats; 102 this->fDisplayStats = !this->fDisplayStats;
90 fWindow->inval(); 103 fWindow->inval();
91 }); 104 });
92 fCommands.addCommand('c', "Modes", "Toggle sRGB color mode", [this]() { 105 fCommands.addCommand('c', "Modes", "Toggle sRGB color mode", [this]() {
93 DisplayParams params = fWindow->getDisplayParams(); 106 DisplayParams params = fWindow->getDisplayParams();
94 params.fProfileType = (kLinear_SkColorProfileType == params.fProfileType ) 107 params.fProfileType = (kLinear_SkColorProfileType == params.fProfileType )
95 ? kSRGB_SkColorProfileType : kLinear_SkColorProfileType; 108 ? kSRGB_SkColorProfileType : kLinear_SkColorProfileType;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 SkString title("Viewer: "); 226 SkString title("Viewer: ");
214 title.append(fSlides[fCurrentSlide]->getName()); 227 title.append(fSlides[fCurrentSlide]->getName());
215 if (kSRGB_SkColorProfileType == fWindow->getDisplayParams().fProfileType) { 228 if (kSRGB_SkColorProfileType == fWindow->getDisplayParams().fProfileType) {
216 title.append(" sRGB"); 229 title.append(" sRGB");
217 } 230 }
218 title.append(kBackendTypeStrings[fBackendType]); 231 title.append(kBackendTypeStrings[fBackendType]);
219 fWindow->setTitle(title.c_str()); 232 fWindow->setTitle(title.c_str());
220 } 233 }
221 234
222 void Viewer::setupCurrentSlide(int previousSlide) { 235 void Viewer::setupCurrentSlide(int previousSlide) {
236 if (fCurrentSlide == previousSlide) {
237 return; // no change; do nothing
238 }
239
223 fGesture.reset(); 240 fGesture.reset();
224 fDefaultMatrix.reset(); 241 fDefaultMatrix.reset();
225 fDefaultMatrixInv.reset(); 242 fDefaultMatrixInv.reset();
226 243
227 if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) { 244 if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) {
228 const SkRect contentRect = fWindow->getContentRect(); 245 const SkRect contentRect = fWindow->getContentRect();
229 const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions(); 246 const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions();
230 const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize. height()); 247 const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize. height());
231 if (contentRect.width() > 0 && contentRect.height() > 0) { 248 if (contentRect.width() > 0 && contentRect.height() > 0) {
232 fDefaultMatrix.setRectToRect(slideBounds, contentRect, SkMatrix::kSt art_ScaleToFit); 249 fDefaultMatrix.setRectToRect(slideBounds, contentRect, SkMatrix::kSt art_ScaleToFit);
233 SkAssertResult(fDefaultMatrix.invert(&fDefaultMatrixInv)); 250 SkAssertResult(fDefaultMatrix.invert(&fDefaultMatrixInv));
234 } 251 }
235 } 252 }
236 253
237 if (fWindow->supportsContentRect()) { 254 if (fWindow->supportsContentRect()) {
238 const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions(); 255 const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions();
239 SkRect windowRect = fWindow->getContentRect(); 256 SkRect windowRect = fWindow->getContentRect();
240 fDefaultMatrixInv.mapRect(&windowRect); 257 fDefaultMatrixInv.mapRect(&windowRect);
241 fGesture.setTransLimit(SkRect::MakeWH(slideSize.width(), slideSize.heigh t()), windowRect); 258 fGesture.setTransLimit(SkRect::MakeWH(slideSize.width(), slideSize.heigh t()), windowRect);
242 } 259 }
243 260
244 this->updateTitle(); 261 this->updateTitle();
262 this->updateUIState();
245 fSlides[fCurrentSlide]->load(); 263 fSlides[fCurrentSlide]->load();
246 if (previousSlide >= 0) { 264 if (previousSlide >= 0) {
247 fSlides[previousSlide]->unload(); 265 fSlides[previousSlide]->unload();
248 } 266 }
249 fWindow->inval(); 267 fWindow->inval();
250 } 268 }
251 269
252 #define MAX_ZOOM_LEVEL 8 270 #define MAX_ZOOM_LEVEL 8
253 #define MIN_ZOOM_LEVEL -8 271 #define MIN_ZOOM_LEVEL -8
254 272
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 // Record measurements 400 // Record measurements
383 fMeasurements[fCurrentMeasurement++] = ms; 401 fMeasurements[fCurrentMeasurement++] = ms;
384 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod 402 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod
385 SkASSERT(fCurrentMeasurement < kMeasurementCount); 403 SkASSERT(fCurrentMeasurement < kMeasurementCount);
386 404
387 fAnimTimer.updateTime(); 405 fAnimTimer.updateTime();
388 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) { 406 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) {
389 fWindow->inval(); 407 fWindow->inval();
390 } 408 }
391 } 409 }
410
411 void Viewer::updateUIState() {
412 Json::Value slideState(Json::objectValue);
413 slideState[kName] = kSlideStateName;
414 slideState[kValue] = fSlides[fCurrentSlide]->getName().c_str();
415 Json::Value allSlideNames(Json::arrayValue);
416 for(auto slide : fSlides) {
417 allSlideNames.append(Json::Value(slide->getName().c_str()));
418 }
419 slideState[kOptions] = allSlideNames;
420
421 // This state is currently a demo for the one without options.
422 // We will be able to change the backend too.
423 Json::Value backendState(Json::objectValue);
424 backendState[kName] = kBackendStateName;
425 backendState[kValue] = fBackendType == sk_app::Window::kVulkan_BackendType ?
426 "Vulkan" : "Other than Vulkan";
427 backendState[kOptions] = Json::Value(Json::arrayValue);
428
429 Json::Value state(Json::arrayValue);
430 state.append(slideState);
431 state.append(backendState);
432
433 fWindow->setUIState(state);
434 }
435
436 void Viewer::onUIStateChanged(const SkString& stateName, const SkString& stateVa lue) {
437 // Currently, we only recognize the Slide state
438 if (stateName.equals(kSlideStateName)) {
439 int previousSlide = fCurrentSlide;
440 fCurrentSlide = 0;
441 for(auto slide : fSlides) {
442 if (slide->getName().equals(stateValue)) {
443 setupCurrentSlide(previousSlide);
444 break;
445 }
446 fCurrentSlide++;
447 }
448 if (fCurrentSlide >= fSlides.count()) {
449 fCurrentSlide = previousSlide;
450 SkDebugf("Slide not found: %s", stateValue.c_str());
451 }
452 } else {
453 SkDebugf("Unknown stateName: %s", stateName.c_str());
454 }
455 }
OLDNEW
« no previous file with comments | « tools/viewer/Viewer.h ('k') | tools/viewer/sk_app/Window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698