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

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

Issue 1978573003: Add OpenGL context to Viewer. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase to ToT Created 4 years, 7 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/DisplayParams.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 30 matching lines...) Expand all
41 "[~][^]substring[$] [...] of bench name to run.\n" 41 "[~][^]substring[$] [...] of bench name to run.\n"
42 "Multiple matches may be separated by spaces.\n" 42 "Multiple matches may be separated by spaces.\n"
43 "~ causes a matching bench to always be skipped\n" 43 "~ causes a matching bench to always be skipped\n"
44 "^ requires the start of the bench to match\n" 44 "^ requires the start of the bench to match\n"
45 "$ requires the end of the bench to match\n" 45 "$ requires the end of the bench to match\n"
46 "^ and $ requires an exact match\n" 46 "^ and $ requires an exact match\n"
47 "If a bench does not match any list entry,\n" 47 "If a bench does not match any list entry,\n"
48 "it is skipped unless some list entry starts with ~"); 48 "it is skipped unless some list entry starts with ~");
49 DEFINE_string(skps, "skps", "Directory to read skps from."); 49 DEFINE_string(skps, "skps", "Directory to read skps from.");
50 50
51 const char *kBackendTypeStrings[sk_app::Window::kBackendTypeCount] = {
52 " [OpenGL]",
53 " [Vulkan]"
54 };
55
51 Viewer::Viewer(int argc, char** argv, void* platformData) 56 Viewer::Viewer(int argc, char** argv, void* platformData)
52 : fCurrentMeasurement(0) 57 : fCurrentMeasurement(0)
53 , fDisplayStats(false) 58 , fDisplayStats(false)
59 , fBackendType(sk_app::Window::kVulkan_BackendType)
54 , fZoomCenterX(0.0f) 60 , fZoomCenterX(0.0f)
55 , fZoomCenterY(0.0f) 61 , fZoomCenterY(0.0f)
56 , fZoomLevel(0.0f) 62 , fZoomLevel(0.0f)
57 , fZoomScale(SK_Scalar1) 63 , fZoomScale(SK_Scalar1)
58 { 64 {
59 memset(fMeasurements, 0, sizeof(fMeasurements)); 65 memset(fMeasurements, 0, sizeof(fMeasurements));
60 66
61 SkDebugf("Command line arguments: "); 67 SkDebugf("Command line arguments: ");
62 for (int i = 1; i < argc; ++i) { 68 for (int i = 1; i < argc; ++i) {
63 SkDebugf("%s ", argv[i]); 69 SkDebugf("%s ", argv[i]);
64 } 70 }
65 SkDebugf("\n"); 71 SkDebugf("\n");
66 72
67 SkCommandLineFlags::Parse(argc, argv); 73 SkCommandLineFlags::Parse(argc, argv);
68 74
69 fWindow = Window::CreateNativeWindow(platformData); 75 fWindow = Window::CreateNativeWindow(platformData);
70 fWindow->attach(Window::kVulkan_BackendType, DisplayParams()); 76 fWindow->attach(fBackendType, DisplayParams());
71 77
72 // register callbacks 78 // register callbacks
73 fCommands.attach(fWindow); 79 fCommands.attach(fWindow);
74 fWindow->registerPaintFunc(on_paint_handler, this); 80 fWindow->registerPaintFunc(on_paint_handler, this);
75 fWindow->registerTouchFunc(on_touch_handler, this); 81 fWindow->registerTouchFunc(on_touch_handler, this);
76 82
77 // add key-bindings 83 // add key-bindings
78 fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() { 84 fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() {
79 this->fDisplayStats = !this->fDisplayStats; 85 this->fDisplayStats = !this->fDisplayStats;
80 fWindow->inval(); 86 fWindow->inval();
(...skipping 23 matching lines...) Expand all
104 this->setupCurrentSlide(previousSlide); 110 this->setupCurrentSlide(previousSlide);
105 }); 111 });
106 fCommands.addCommand(Window::Key::kUp, "Up", "Transform", "Zoom in", [this]( ) { 112 fCommands.addCommand(Window::Key::kUp, "Up", "Transform", "Zoom in", [this]( ) {
107 this->changeZoomLevel(1.f / 32.f); 113 this->changeZoomLevel(1.f / 32.f);
108 fWindow->inval(); 114 fWindow->inval();
109 }); 115 });
110 fCommands.addCommand(Window::Key::kDown, "Down", "Transform", "Zoom out", [t his]() { 116 fCommands.addCommand(Window::Key::kDown, "Down", "Transform", "Zoom out", [t his]() {
111 this->changeZoomLevel(-1.f / 32.f); 117 this->changeZoomLevel(-1.f / 32.f);
112 fWindow->inval(); 118 fWindow->inval();
113 }); 119 });
120 #ifndef SK_BUILD_FOR_ANDROID
121 fCommands.addCommand('d', "Modes", "Change rendering backend", [this]() {
122 fWindow->detach();
123
124 if (sk_app::Window::kVulkan_BackendType == fBackendType) {
125 fBackendType = sk_app::Window::kNativeGL_BackendType;
126 }
127 // TODO: get Vulkan -> OpenGL working without swapchain creation failure
128 //else if (sk_app::Window::kNativeGL_BackendType == fBackendType) {
129 // fBackendType = sk_app::Window::kVulkan_BackendType;
130 //}
131
132 fWindow->attach(fBackendType, DisplayParams());
133 this->updateTitle();
134 });
135 #endif
114 136
115 // set up slides 137 // set up slides
116 this->initSlides(); 138 this->initSlides();
117 139
118 fAnimTimer.run(); 140 fAnimTimer.run();
119 141
120 // set up first frame 142 // set up first frame
121 fCurrentSlide = 0; 143 fCurrentSlide = 0;
122 setupCurrentSlide(-1); 144 setupCurrentSlide(-1);
123 145
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 fWindow->detach(); 201 fWindow->detach();
180 delete fWindow; 202 delete fWindow;
181 } 203 }
182 204
183 void Viewer::updateTitle() { 205 void Viewer::updateTitle() {
184 SkString title("Viewer: "); 206 SkString title("Viewer: ");
185 title.append(fSlides[fCurrentSlide]->getName()); 207 title.append(fSlides[fCurrentSlide]->getName());
186 if (kSRGB_SkColorProfileType == fWindow->getDisplayParams().fProfileType) { 208 if (kSRGB_SkColorProfileType == fWindow->getDisplayParams().fProfileType) {
187 title.append(" sRGB"); 209 title.append(" sRGB");
188 } 210 }
211 title.append(kBackendTypeStrings[fBackendType]);
189 fWindow->setTitle(title.c_str()); 212 fWindow->setTitle(title.c_str());
190 } 213 }
191 214
192 void Viewer::setupCurrentSlide(int previousSlide) { 215 void Viewer::setupCurrentSlide(int previousSlide) {
193 this->updateTitle(); 216 this->updateTitle();
194 fSlides[fCurrentSlide]->load(); 217 fSlides[fCurrentSlide]->load();
195 if (previousSlide >= 0) { 218 if (previousSlide >= 0) {
196 fSlides[previousSlide]->unload(); 219 fSlides[previousSlide]->unload();
197 } 220 }
198 fWindow->inval(); 221 fWindow->inval();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 m.postTranslate(cx, cy); 253 m.postTranslate(cx, cy);
231 } 254 }
232 255
233 m.preConcat(fGesture.localM()); 256 m.preConcat(fGesture.localM());
234 m.preConcat(fGesture.globalM()); 257 m.preConcat(fGesture.globalM());
235 258
236 return m; 259 return m;
237 } 260 }
238 261
239 void Viewer::onPaint(SkCanvas* canvas) { 262 void Viewer::onPaint(SkCanvas* canvas) {
240
241 int count = canvas->save(); 263 int count = canvas->save();
242 264
243 if (fWindow->supportsContentRect()) { 265 if (fWindow->supportsContentRect()) {
244 SkRect contentRect = fWindow->getContentRect(); 266 SkRect contentRect = fWindow->getContentRect();
245 canvas->clipRect(contentRect); 267 canvas->clipRect(contentRect);
246 canvas->translate(contentRect.fLeft, contentRect.fTop); 268 canvas->translate(contentRect.fLeft, contentRect.fTop);
247 } 269 }
248 270
249 canvas->clear(SK_ColorWHITE); 271 canvas->clear(SK_ColorWHITE);
250 if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) { 272 if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 // Record measurements 360 // Record measurements
339 fMeasurements[fCurrentMeasurement++] = ms; 361 fMeasurements[fCurrentMeasurement++] = ms;
340 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod 362 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod
341 SkASSERT(fCurrentMeasurement < kMeasurementCount); 363 SkASSERT(fCurrentMeasurement < kMeasurementCount);
342 364
343 fAnimTimer.updateTime(); 365 fAnimTimer.updateTime();
344 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) { 366 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) {
345 fWindow->inval(); 367 fWindow->inval();
346 } 368 }
347 } 369 }
OLDNEW
« no previous file with comments | « tools/viewer/Viewer.h ('k') | tools/viewer/sk_app/DisplayParams.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698