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

Side by Side Diff: tools/vulkan/viewer/VulkanViewer.cpp

Issue 1873543003: Add slides to VulkanViewer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Reverse GM array; add name to Slide Created 4 years, 8 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/vulkan/viewer/VulkanViewer.h ('k') | no next file » | 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 "VulkanViewer.h" 8 #include "VulkanViewer.h"
9 9
10 #include "GMSlide.h"
11 #include "SKPSlide.h"
12
10 #include "SkCanvas.h" 13 #include "SkCanvas.h"
14 #include "SkCommonFlags.h"
15 #include "SkOSFile.h"
11 #include "SkRandom.h" 16 #include "SkRandom.h"
12 #include "SkCommonFlags.h" 17 #include "SkStream.h"
13
14 DEFINE_string(key, "",
15 "Space-separated key/value pairs to add to JSON identifying this b uilder.");
16 18
17 Application* Application::Create(int argc, char** argv, void* platformData) { 19 Application* Application::Create(int argc, char** argv, void* platformData) {
18 return new VulkanViewer(argc, argv, platformData); 20 return new VulkanViewer(argc, argv, platformData);
19 } 21 }
20 22
21 static bool on_key_handler(Window::Key key, Window::InputState state, uint32_t m odifiers, 23 static bool on_key_handler(Window::Key key, Window::InputState state, uint32_t m odifiers,
22 void* userData) { 24 void* userData) {
23 VulkanViewer* vv = reinterpret_cast<VulkanViewer*>(userData); 25 VulkanViewer* vv = reinterpret_cast<VulkanViewer*>(userData);
24 26
25 return vv->onKey(key, state, modifiers); 27 return vv->onKey(key, state, modifiers);
26 } 28 }
27 29
28 static void on_paint_handler(SkCanvas* canvas, void* userData) { 30 static void on_paint_handler(SkCanvas* canvas, void* userData) {
29 VulkanViewer* vv = reinterpret_cast<VulkanViewer*>(userData); 31 VulkanViewer* vv = reinterpret_cast<VulkanViewer*>(userData);
30 32
31 return vv->onPaint(canvas); 33 return vv->onPaint(canvas);
32 } 34 }
33 35
34 VulkanViewer::VulkanViewer(int argc, char** argv, void* platformData) 36 DEFINE_bool2(fullscreen, f, true, "Run fullscreen.");
35 : fGMs(skiagm::GMRegistry::Head()) 37 DEFINE_string(key, "", "Space-separated key/value pairs to add to JSON identifyi ng this builder.");
36 , fCurrentMeasurement(0) { 38 DEFINE_string2(match, m, nullptr,
39 "[~][^]substring[$] [...] of bench name to run.\n"
40 "Multiple matches may be separated by spaces.\n"
41 "~ causes a matching bench to always be skipped\n"
42 "^ requires the start of the bench to match\n"
43 "$ requires the end of the bench to match\n"
44 "^ and $ requires an exact match\n"
45 "If a bench does not match any list entry,\n"
46 "it is skipped unless some list entry starts with ~");
47 DEFINE_string(skps, "skps", "Directory to read skps from.");
48
49
50
51
52
53
54 VulkanViewer::VulkanViewer(int argc, char** argv, void* platformData) : fCurrent Measurement(0) {
37 memset(fMeasurements, 0, sizeof(fMeasurements)); 55 memset(fMeasurements, 0, sizeof(fMeasurements));
38 56
57 SkDebugf("Command line arguments: ");
58 for (int i = 1; i < argc; ++i) {
59 SkDebugf("%s ", argv[i]);
60 }
61 SkDebugf("\n");
62
63 SkCommandLineFlags::Parse(argc, argv);
64
39 fWindow = Window::CreateNativeWindow(platformData); 65 fWindow = Window::CreateNativeWindow(platformData);
40 fWindow->attach(Window::kVulkan_BackendType, 0, nullptr); 66 fWindow->attach(Window::kVulkan_BackendType, 0, nullptr);
41 67
42 // register callbacks 68 // register callbacks
43 fWindow->registerKeyFunc(on_key_handler, this); 69 fWindow->registerKeyFunc(on_key_handler, this);
44 fWindow->registerPaintFunc(on_paint_handler, this); 70 fWindow->registerPaintFunc(on_paint_handler, this);
45 71
46 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(nullptr)); 72 // set up slides
73 this->initSlides();
74
75 // set up first frame
47 SkString title("VulkanViewer: "); 76 SkString title("VulkanViewer: ");
48 title.append(gm->getName()); 77 title.append(fSlides[0]->getName());
78 fCurrentSlide = 0;
49 fWindow->setTitle(title.c_str()); 79 fWindow->setTitle(title.c_str());
50 fWindow->show(); 80 fWindow->show();
51 } 81 }
52 82
83 static sk_sp<SkPicture> read_picture(const char path[]) {
84 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) {
85 return nullptr;
86 }
87
88 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
89 if (stream.get() == nullptr) {
90 SkDebugf("Could not read %s.\n", path);
91 return nullptr;
92 }
93
94 auto pic = SkPicture::MakeFromStream(stream.get());
95 if (!pic) {
96 SkDebugf("Could not read %s as an SkPicture.\n", path);
97 }
98 return pic;
99 }
100
101
102 static sk_sp<SKPSlide> loadSKP(const SkString& path) {
103 sk_sp<SkPicture> pic = read_picture(path.c_str());
104 if (!pic) {
105 return nullptr;
106 }
107
108 SkString name = SkOSPath::Basename(path.c_str());
109 return sk_sp<SKPSlide>(new SKPSlide(name.c_str(), pic));
110 }
111
112 void VulkanViewer::initSlides() {
113 const skiagm::GMRegistry* gms(skiagm::GMRegistry::Head());
114 while (gms) {
115 SkAutoTDelete<skiagm::GM> gm(gms->factory()(nullptr));
116
117 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, gm->getName())) {
118 sk_sp<Slide> slide(new GMSlide(gm.release()));
119 fSlides.push_back(slide);
120 }
121
122 gms = gms->next();
123 }
124
125 // reverse array
126 for (int i = 0; i < fSlides.count()/2; ++i) {
127 sk_sp<Slide> temp = fSlides[i];
128 fSlides[i] = fSlides[fSlides.count() - i - 1];
129 fSlides[fSlides.count() - i - 1] = temp;
130 }
131
132 // SKPs
133 for (int i = 0; i < FLAGS_skps.count(); i++) {
134 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
135 SkString path(FLAGS_skps[i]);
136 sk_sp<SKPSlide> slide = loadSKP(path);
137 if (slide) {
138 fSlides.push_back(slide);
139 }
140 } else {
141 SkOSFile::Iter it(FLAGS_skps[i], ".skp");
142 SkString path;
143 while (it.next(&path)) {
144 SkString skpName = SkOSPath::Join(FLAGS_skps[i], path.c_str());
145 sk_sp<SKPSlide> slide = loadSKP(skpName);
146 if (slide) {
147 fSlides.push_back(slide);
148 }
149 }
150 }
151 }
152 }
153
154
53 VulkanViewer::~VulkanViewer() { 155 VulkanViewer::~VulkanViewer() {
54 fWindow->detach(); 156 fWindow->detach();
55 delete fWindow; 157 delete fWindow;
56 } 158 }
57 159
58 bool VulkanViewer::onKey(Window::Key key, Window::InputState state, uint32_t mod ifiers) { 160 bool VulkanViewer::onKey(Window::Key key, Window::InputState state, uint32_t mod ifiers) {
59 if (Window::kDown_InputState == state && (modifiers & Window::kFirstPress_Mo difierKey) && 161 if (Window::kDown_InputState == state && (modifiers & Window::kFirstPress_Mo difierKey)) {
60 key == Window::kRight_Key) { 162 if (key == Window::kRight_Key) {
61 fGMs = fGMs->next(); 163 fCurrentSlide++;
62 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(nullptr)); 164 if (fCurrentSlide >= fSlides.count()) {
63 SkString title("VulkanViewer: "); 165 fCurrentSlide = 0;
64 title.append(gm->getName()); 166 }
65 fWindow->setTitle(title.c_str()); 167 SkString title("VulkanViewer: ");
168 title.append(fSlides[fCurrentSlide]->getName());
169 fWindow->setTitle(title.c_str());
170 } else if (key == Window::kLeft_Key) {
171 fCurrentSlide--;
172 if (fCurrentSlide < 0) {
173 fCurrentSlide = fSlides.count()-1;
174 }
175 SkString title("VulkanViewer: ");
176 title.append(fSlides[fCurrentSlide]->getName());
177 fWindow->setTitle(title.c_str());
178 }
66 } 179 }
67 180
68 return true; 181 return true;
69 } 182 }
70 183
71 void VulkanViewer::onPaint(SkCanvas* canvas) { 184 void VulkanViewer::onPaint(SkCanvas* canvas) {
72 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(nullptr)); 185
186 canvas->clear(SK_ColorWHITE);
73 187
74 canvas->save(); 188 canvas->save();
75 gm->draw(canvas); 189 fSlides[fCurrentSlide]->draw(canvas);
76 canvas->restore(); 190 canvas->restore();
77 191
78 drawStats(canvas); 192 drawStats(canvas);
79 } 193 }
80 194
81 void VulkanViewer::drawStats(SkCanvas* canvas) { 195 void VulkanViewer::drawStats(SkCanvas* canvas) {
82 static const float kPixelPerMS = 2.0f; 196 static const float kPixelPerMS = 2.0f;
83 static const int kDisplayWidth = 130; 197 static const int kDisplayWidth = 130;
84 static const int kDisplayHeight = 100; 198 static const int kDisplayHeight = 100;
85 static const int kDisplayPadding = 10; 199 static const int kDisplayPadding = 10;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 235 }
122 236
123 void VulkanViewer::onIdle(double ms) { 237 void VulkanViewer::onIdle(double ms) {
124 // Record measurements 238 // Record measurements
125 fMeasurements[fCurrentMeasurement++] = ms; 239 fMeasurements[fCurrentMeasurement++] = ms;
126 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod 240 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod
127 SkASSERT(fCurrentMeasurement < kMeasurementCount); 241 SkASSERT(fCurrentMeasurement < kMeasurementCount);
128 242
129 fWindow->onPaint(); 243 fWindow->onPaint();
130 } 244 }
OLDNEW
« no previous file with comments | « tools/vulkan/viewer/VulkanViewer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698