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

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

Issue 1990893002: Revert of Add OpenGL context to Viewer. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 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
49 Viewer::Viewer(int argc, char** argv, void* platformData) 44 Viewer::Viewer(int argc, char** argv, void* platformData)
50 : fCurrentMeasurement(0) 45 : fCurrentMeasurement(0)
51 , fDisplayStats(false) 46 , fDisplayStats(false)
52 , fBackendType(sk_app::Window::kVulkan_BackendType)
53 , fZoomCenterX(0.0f) 47 , fZoomCenterX(0.0f)
54 , fZoomCenterY(0.0f) 48 , fZoomCenterY(0.0f)
55 , fZoomLevel(0.0f) 49 , fZoomLevel(0.0f)
56 , fZoomScale(SK_Scalar1) 50 , fZoomScale(SK_Scalar1)
57 { 51 {
58 memset(fMeasurements, 0, sizeof(fMeasurements)); 52 memset(fMeasurements, 0, sizeof(fMeasurements));
59 53
60 SkDebugf("Command line arguments: "); 54 SkDebugf("Command line arguments: ");
61 for (int i = 1; i < argc; ++i) { 55 for (int i = 1; i < argc; ++i) {
62 SkDebugf("%s ", argv[i]); 56 SkDebugf("%s ", argv[i]);
63 } 57 }
64 SkDebugf("\n"); 58 SkDebugf("\n");
65 59
66 SkCommandLineFlags::Parse(argc, argv); 60 SkCommandLineFlags::Parse(argc, argv);
67 61
68 fWindow = Window::CreateNativeWindow(platformData); 62 fWindow = Window::CreateNativeWindow(platformData);
69 fWindow->attach(fBackendType, DisplayParams()); 63 fWindow->attach(Window::kVulkan_BackendType, DisplayParams());
70 64
71 // register callbacks 65 // register callbacks
72 fCommands.attach(fWindow); 66 fCommands.attach(fWindow);
73 fWindow->registerPaintFunc(on_paint_handler, this); 67 fWindow->registerPaintFunc(on_paint_handler, this);
74 68
75 // add key-bindings 69 // add key-bindings
76 fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() { 70 fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() {
77 this->fDisplayStats = !this->fDisplayStats; 71 this->fDisplayStats = !this->fDisplayStats;
78 fWindow->inval(); 72 fWindow->inval();
79 }); 73 });
(...skipping 22 matching lines...) Expand all
102 this->setupCurrentSlide(previousSlide); 96 this->setupCurrentSlide(previousSlide);
103 }); 97 });
104 fCommands.addCommand(Window::Key::kUp, "Up", "Transform", "Zoom in", [this]( ) { 98 fCommands.addCommand(Window::Key::kUp, "Up", "Transform", "Zoom in", [this]( ) {
105 this->changeZoomLevel(1.f / 32.f); 99 this->changeZoomLevel(1.f / 32.f);
106 fWindow->inval(); 100 fWindow->inval();
107 }); 101 });
108 fCommands.addCommand(Window::Key::kDown, "Down", "Transform", "Zoom out", [t his]() { 102 fCommands.addCommand(Window::Key::kDown, "Down", "Transform", "Zoom out", [t his]() {
109 this->changeZoomLevel(-1.f / 32.f); 103 this->changeZoomLevel(-1.f / 32.f);
110 fWindow->inval(); 104 fWindow->inval();
111 }); 105 });
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
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
128 106
129 // set up slides 107 // set up slides
130 this->initSlides(); 108 this->initSlides();
131 109
132 fAnimTimer.run(); 110 fAnimTimer.run();
133 111
134 // set up first frame 112 // set up first frame
135 fCurrentSlide = 0; 113 fCurrentSlide = 0;
136 setupCurrentSlide(-1); 114 setupCurrentSlide(-1);
137 updateMatrix(); 115 updateMatrix();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 fWindow->detach(); 172 fWindow->detach();
195 delete fWindow; 173 delete fWindow;
196 } 174 }
197 175
198 void Viewer::updateTitle() { 176 void Viewer::updateTitle() {
199 SkString title("Viewer: "); 177 SkString title("Viewer: ");
200 title.append(fSlides[fCurrentSlide]->getName()); 178 title.append(fSlides[fCurrentSlide]->getName());
201 if (kSRGB_SkColorProfileType == fWindow->getDisplayParams().fProfileType) { 179 if (kSRGB_SkColorProfileType == fWindow->getDisplayParams().fProfileType) {
202 title.append(" sRGB"); 180 title.append(" sRGB");
203 } 181 }
204 title.append(kBackendTypeStrings[fBackendType]);
205 fWindow->setTitle(title.c_str()); 182 fWindow->setTitle(title.c_str());
206 } 183 }
207 184
208 void Viewer::setupCurrentSlide(int previousSlide) { 185 void Viewer::setupCurrentSlide(int previousSlide) {
209 this->updateTitle(); 186 this->updateTitle();
210 fSlides[fCurrentSlide]->load(); 187 fSlides[fCurrentSlide]->load();
211 if (previousSlide >= 0) { 188 if (previousSlide >= 0) {
212 fSlides[previousSlide]->unload(); 189 fSlides[previousSlide]->unload();
213 } 190 }
214 fWindow->inval(); 191 fWindow->inval();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 226
250 // TODO: add gesture support 227 // TODO: add gesture support
251 // Apply any gesture matrix 228 // Apply any gesture matrix
252 //m.preConcat(fGesture.localM()); 229 //m.preConcat(fGesture.localM());
253 //m.preConcat(fGesture.globalM()); 230 //m.preConcat(fGesture.globalM());
254 231
255 fLocalMatrix = m; 232 fLocalMatrix = m;
256 } 233 }
257 234
258 void Viewer::onPaint(SkCanvas* canvas) { 235 void Viewer::onPaint(SkCanvas* canvas) {
236
259 int count = canvas->save(); 237 int count = canvas->save();
260 238
261 if (fWindow->supportsContentRect()) { 239 if (fWindow->supportsContentRect()) {
262 SkRect contentRect = fWindow->getContentRect(); 240 SkRect contentRect = fWindow->getContentRect();
263 canvas->clipRect(contentRect); 241 canvas->clipRect(contentRect);
264 canvas->translate(contentRect.fLeft, contentRect.fTop); 242 canvas->translate(contentRect.fLeft, contentRect.fTop);
265 } 243 }
266 244
267 canvas->clear(SK_ColorWHITE); 245 canvas->clear(SK_ColorWHITE);
268 if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) { 246 if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 // Record measurements 314 // Record measurements
337 fMeasurements[fCurrentMeasurement++] = ms; 315 fMeasurements[fCurrentMeasurement++] = ms;
338 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod 316 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod
339 SkASSERT(fCurrentMeasurement < kMeasurementCount); 317 SkASSERT(fCurrentMeasurement < kMeasurementCount);
340 318
341 fAnimTimer.updateTime(); 319 fAnimTimer.updateTime();
342 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) { 320 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) {
343 fWindow->inval(); 321 fWindow->inval();
344 } 322 }
345 } 323 }
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