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

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

Issue 1950983007: Add sRGB mode toggle to Viewer. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Bundle window surface parameters in struct, use SkColorType/SkColorProfileType 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 SkDebugf("Command line arguments: "); 67 SkDebugf("Command line arguments: ");
68 for (int i = 1; i < argc; ++i) { 68 for (int i = 1; i < argc; ++i) {
69 SkDebugf("%s ", argv[i]); 69 SkDebugf("%s ", argv[i]);
70 } 70 }
71 SkDebugf("\n"); 71 SkDebugf("\n");
72 72
73 SkCommandLineFlags::Parse(argc, argv); 73 SkCommandLineFlags::Parse(argc, argv);
74 74
75 fWindow = Window::CreateNativeWindow(platformData); 75 fWindow = Window::CreateNativeWindow(platformData);
76 fWindow->attach(Window::kVulkan_BackendType, 0); 76 fWindow->attach(Window::kVulkan_BackendType, DisplayParams());
77 77
78 // register callbacks 78 // register callbacks
79 fWindow->registerKeyFunc(on_key_handler, this); 79 fWindow->registerKeyFunc(on_key_handler, this);
80 fWindow->registerCharFunc(on_char_handler, this); 80 fWindow->registerCharFunc(on_char_handler, this);
81 fWindow->registerPaintFunc(on_paint_handler, this); 81 fWindow->registerPaintFunc(on_paint_handler, this);
82 82
83 // set up slides 83 // set up slides
84 this->initSlides(); 84 this->initSlides();
85 85
86 fAnimTimer.run(); 86 fAnimTimer.run();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 142 }
143 } 143 }
144 } 144 }
145 145
146 146
147 Viewer::~Viewer() { 147 Viewer::~Viewer() {
148 fWindow->detach(); 148 fWindow->detach();
149 delete fWindow; 149 delete fWindow;
150 } 150 }
151 151
152 void Viewer::setupCurrentSlide(int previousSlide) { 152 void Viewer::updateTitle() {
153 SkString title("Viewer: "); 153 SkString title("Viewer: ");
154 title.append(fSlides[fCurrentSlide]->getName()); 154 title.append(fSlides[fCurrentSlide]->getName());
155 if (kSRGB_SkColorProfileType == fWindow->getDisplayParams().fProfileType) {
156 title.append(" sRGB");
157 }
158 fWindow->setTitle(title.c_str());
159 }
160
161 void Viewer::setupCurrentSlide(int previousSlide) {
162 this->updateTitle();
155 fSlides[fCurrentSlide]->load(); 163 fSlides[fCurrentSlide]->load();
156 if (previousSlide >= 0) { 164 if (previousSlide >= 0) {
157 fSlides[previousSlide]->unload(); 165 fSlides[previousSlide]->unload();
158 } 166 }
159 fWindow->setTitle(title.c_str());
160 fWindow->inval(); 167 fWindow->inval();
161 } 168 }
162 169
163 #define MAX_ZOOM_LEVEL 8 170 #define MAX_ZOOM_LEVEL 8
164 #define MIN_ZOOM_LEVEL -8 171 #define MIN_ZOOM_LEVEL -8
165 172
166 void Viewer::changeZoomLevel(float delta) { 173 void Viewer::changeZoomLevel(float delta) {
167 fZoomLevel += delta; 174 fZoomLevel += delta;
168 if (fZoomLevel > 0) { 175 if (fZoomLevel > 0) {
169 fZoomLevel = SkMinScalar(fZoomLevel, MAX_ZOOM_LEVEL); 176 fZoomLevel = SkMinScalar(fZoomLevel, MAX_ZOOM_LEVEL);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 setupCurrentSlide(previousSlide); 220 setupCurrentSlide(previousSlide);
214 return true; 221 return true;
215 } 222 }
216 223
217 case Window::kLeft_Key: { 224 case Window::kLeft_Key: {
218 int previousSlide = fCurrentSlide; 225 int previousSlide = fCurrentSlide;
219 fCurrentSlide--; 226 fCurrentSlide--;
220 if (fCurrentSlide < 0) { 227 if (fCurrentSlide < 0) {
221 fCurrentSlide = fSlides.count() - 1; 228 fCurrentSlide = fSlides.count() - 1;
222 } 229 }
223 SkString title("Viewer: ");
224 title.append(fSlides[fCurrentSlide]->getName());
225 fWindow->setTitle(title.c_str());
226 setupCurrentSlide(previousSlide); 230 setupCurrentSlide(previousSlide);
227 return true; 231 return true;
228 } 232 }
229 233
230 case Window::kUp_Key: { 234 case Window::kUp_Key: {
231 this->changeZoomLevel(1.f / 32.f); 235 this->changeZoomLevel(1.f / 32.f);
232 fWindow->inval(); 236 fWindow->inval();
233 return true; 237 return true;
234 } 238 }
235 239
236 case Window::kDown_Key: { 240 case Window::kDown_Key: {
237 this->changeZoomLevel(-1.f / 32.f); 241 this->changeZoomLevel(-1.f / 32.f);
238 fWindow->inval(); 242 fWindow->inval();
239 return true; 243 return true;
240 } 244 }
241 245
242 default: 246 default:
243 break; 247 break;
244 } 248 }
245 } 249 }
246 250
247 return false; 251 return false;
248 } 252 }
249 253
250 bool Viewer::onChar(SkUnichar c, uint32_t modifiers) { 254 bool Viewer::onChar(SkUnichar c, uint32_t modifiers) {
251 if ('s' == c) { 255 switch (c) {
252 fDisplayStats = !fDisplayStats; 256 case 's':
253 return true; 257 fDisplayStats = !fDisplayStats;
258 return true;
259 case 'c':
260 DisplayParams params = fWindow->getDisplayParams();
261 params.fProfileType = (kLinear_SkColorProfileType == params.fProfile Type)
262 ? kSRGB_SkColorProfileType : kLinear_SkColorProfileType;
263 fWindow->setDisplayParams(params);
264 this->updateTitle();
265 fWindow->inval();
266 return true;
254 } 267 }
255 268
256 return false; 269 return false;
257 } 270 }
258 271
259 void Viewer::onPaint(SkCanvas* canvas) { 272 void Viewer::onPaint(SkCanvas* canvas) {
260 273
261 int count = canvas->save(); 274 int count = canvas->save();
262 275
263 if (fWindow->supportsContentRect()) { 276 if (fWindow->supportsContentRect()) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 // Record measurements 350 // Record measurements
338 fMeasurements[fCurrentMeasurement++] = ms; 351 fMeasurements[fCurrentMeasurement++] = ms;
339 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod 352 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod
340 SkASSERT(fCurrentMeasurement < kMeasurementCount); 353 SkASSERT(fCurrentMeasurement < kMeasurementCount);
341 354
342 fAnimTimer.updateTime(); 355 fAnimTimer.updateTime();
343 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) { 356 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) {
344 fWindow->inval(); 357 fWindow->inval();
345 } 358 }
346 } 359 }
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