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

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: Address comments 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
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 23 matching lines...) Expand all
34 "[~][^]substring[$] [...] of bench name to run.\n" 34 "[~][^]substring[$] [...] of bench name to run.\n"
35 "Multiple matches may be separated by spaces.\n" 35 "Multiple matches may be separated by spaces.\n"
36 "~ causes a matching bench to always be skipped\n" 36 "~ causes a matching bench to always be skipped\n"
37 "^ requires the start of the bench to match\n" 37 "^ requires the start of the bench to match\n"
38 "$ requires the end of the bench to match\n" 38 "$ requires the end of the bench to match\n"
39 "^ and $ requires an exact match\n" 39 "^ and $ requires an exact match\n"
40 "If a bench does not match any list entry,\n" 40 "If a bench does not match any list entry,\n"
41 "it is skipped unless some list entry starts with ~"); 41 "it is skipped unless some list entry starts with ~");
42 DEFINE_string(skps, "skps", "Directory to read skps from."); 42 DEFINE_string(skps, "skps", "Directory to read skps from.");
43 43
44 const char *kBackendTypeStrings[sk_app::Window::kBackendTypeCount] = {
45 " [OpenGL]",
46 " [Vulkan]"
47 };
48
44 Viewer::Viewer(int argc, char** argv, void* platformData) 49 Viewer::Viewer(int argc, char** argv, void* platformData)
45 : fCurrentMeasurement(0) 50 : fCurrentMeasurement(0)
46 , fDisplayStats(false) 51 , fDisplayStats(false)
52 , fBackendType(sk_app::Window::kVulkan_BackendType)
47 , fZoomCenterX(0.0f) 53 , fZoomCenterX(0.0f)
48 , fZoomCenterY(0.0f) 54 , fZoomCenterY(0.0f)
49 , fZoomLevel(0.0f) 55 , fZoomLevel(0.0f)
50 , fZoomScale(SK_Scalar1) 56 , fZoomScale(SK_Scalar1)
51 { 57 {
52 memset(fMeasurements, 0, sizeof(fMeasurements)); 58 memset(fMeasurements, 0, sizeof(fMeasurements));
53 59
54 SkDebugf("Command line arguments: "); 60 SkDebugf("Command line arguments: ");
55 for (int i = 1; i < argc; ++i) { 61 for (int i = 1; i < argc; ++i) {
56 SkDebugf("%s ", argv[i]); 62 SkDebugf("%s ", argv[i]);
57 } 63 }
58 SkDebugf("\n"); 64 SkDebugf("\n");
59 65
60 SkCommandLineFlags::Parse(argc, argv); 66 SkCommandLineFlags::Parse(argc, argv);
61 67
62 fWindow = Window::CreateNativeWindow(platformData); 68 fWindow = Window::CreateNativeWindow(platformData);
63 fWindow->attach(Window::kVulkan_BackendType, DisplayParams()); 69 fWindow->attach(fBackendType, DisplayParams());
64 70
65 // register callbacks 71 // register callbacks
66 fCommands.attach(fWindow); 72 fCommands.attach(fWindow);
67 fWindow->registerPaintFunc(on_paint_handler, this); 73 fWindow->registerPaintFunc(on_paint_handler, this);
68 74
69 // add key-bindings 75 // add key-bindings
70 fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() { 76 fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() {
71 this->fDisplayStats = !this->fDisplayStats; 77 this->fDisplayStats = !this->fDisplayStats;
72 fWindow->inval(); 78 fWindow->inval();
73 }); 79 });
(...skipping 22 matching lines...) Expand all
96 this->setupCurrentSlide(previousSlide); 102 this->setupCurrentSlide(previousSlide);
97 }); 103 });
98 fCommands.addCommand(Window::Key::kUp, "Up", "Transform", "Zoom in", [this]( ) { 104 fCommands.addCommand(Window::Key::kUp, "Up", "Transform", "Zoom in", [this]( ) {
99 this->changeZoomLevel(1.f / 32.f); 105 this->changeZoomLevel(1.f / 32.f);
100 fWindow->inval(); 106 fWindow->inval();
101 }); 107 });
102 fCommands.addCommand(Window::Key::kDown, "Down", "Transform", "Zoom out", [t his]() { 108 fCommands.addCommand(Window::Key::kDown, "Down", "Transform", "Zoom out", [t his]() {
103 this->changeZoomLevel(-1.f / 32.f); 109 this->changeZoomLevel(-1.f / 32.f);
104 fWindow->inval(); 110 fWindow->inval();
105 }); 111 });
112 #ifndef SK_BUILD_FOR_ANDROID
113 fCommands.addCommand('d', "Modes", "Change rendering backend", [this]() {
114 fWindow->detach();
115
116 if (sk_app::Window::kVulkan_BackendType == fBackendType) {
117 fBackendType = sk_app::Window::kNativeGL_BackendType;
118 }
119 // TODO: get Vulkan -> OpenGL working without swapchain creation failure
Brian Osman 2016/05/17 17:32:11 This is unfortunate. Is it likely that we can fix
jvanverth1 2016/05/17 17:59:50 I don't know. I put a message out to vulkan-devs a
120 //else if (sk_app::Window::kNativeGL_BackendType == fBackendType) {
121 // fBackendType = sk_app::Window::kVulkan_BackendType;
122 //}
123
124 fWindow->attach(fBackendType, DisplayParams());
125 this->updateTitle();
126 });
127 #endif
106 128
107 // set up slides 129 // set up slides
108 this->initSlides(); 130 this->initSlides();
109 131
110 fAnimTimer.run(); 132 fAnimTimer.run();
111 133
112 // set up first frame 134 // set up first frame
113 fCurrentSlide = 0; 135 fCurrentSlide = 0;
114 setupCurrentSlide(-1); 136 setupCurrentSlide(-1);
115 updateMatrix(); 137 updateMatrix();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 fWindow->detach(); 194 fWindow->detach();
173 delete fWindow; 195 delete fWindow;
174 } 196 }
175 197
176 void Viewer::updateTitle() { 198 void Viewer::updateTitle() {
177 SkString title("Viewer: "); 199 SkString title("Viewer: ");
178 title.append(fSlides[fCurrentSlide]->getName()); 200 title.append(fSlides[fCurrentSlide]->getName());
179 if (kSRGB_SkColorProfileType == fWindow->getDisplayParams().fProfileType) { 201 if (kSRGB_SkColorProfileType == fWindow->getDisplayParams().fProfileType) {
180 title.append(" sRGB"); 202 title.append(" sRGB");
181 } 203 }
204 title.append(kBackendTypeStrings[fBackendType]);
182 fWindow->setTitle(title.c_str()); 205 fWindow->setTitle(title.c_str());
183 } 206 }
184 207
185 void Viewer::setupCurrentSlide(int previousSlide) { 208 void Viewer::setupCurrentSlide(int previousSlide) {
186 this->updateTitle(); 209 this->updateTitle();
187 fSlides[fCurrentSlide]->load(); 210 fSlides[fCurrentSlide]->load();
188 if (previousSlide >= 0) { 211 if (previousSlide >= 0) {
189 fSlides[previousSlide]->unload(); 212 fSlides[previousSlide]->unload();
190 } 213 }
191 fWindow->inval(); 214 fWindow->inval();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 249
227 // TODO: add gesture support 250 // TODO: add gesture support
228 // Apply any gesture matrix 251 // Apply any gesture matrix
229 //m.preConcat(fGesture.localM()); 252 //m.preConcat(fGesture.localM());
230 //m.preConcat(fGesture.globalM()); 253 //m.preConcat(fGesture.globalM());
231 254
232 fLocalMatrix = m; 255 fLocalMatrix = m;
233 } 256 }
234 257
235 void Viewer::onPaint(SkCanvas* canvas) { 258 void Viewer::onPaint(SkCanvas* canvas) {
236
237 int count = canvas->save(); 259 int count = canvas->save();
238 260
239 if (fWindow->supportsContentRect()) { 261 if (fWindow->supportsContentRect()) {
240 SkRect contentRect = fWindow->getContentRect(); 262 SkRect contentRect = fWindow->getContentRect();
241 canvas->clipRect(contentRect); 263 canvas->clipRect(contentRect);
242 canvas->translate(contentRect.fLeft, contentRect.fTop); 264 canvas->translate(contentRect.fLeft, contentRect.fTop);
243 } 265 }
244 266
245 canvas->clear(SK_ColorWHITE); 267 canvas->clear(SK_ColorWHITE);
246 if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) { 268 if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 // Record measurements 336 // Record measurements
315 fMeasurements[fCurrentMeasurement++] = ms; 337 fMeasurements[fCurrentMeasurement++] = ms;
316 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod 338 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod
317 SkASSERT(fCurrentMeasurement < kMeasurementCount); 339 SkASSERT(fCurrentMeasurement < kMeasurementCount);
318 340
319 fAnimTimer.updateTime(); 341 fAnimTimer.updateTime();
320 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) { 342 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) {
321 fWindow->inval(); 343 fWindow->inval();
322 } 344 }
323 } 345 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698