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

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

Issue 2069653002: Use Offscreen Surface for Split Screen (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: More fixes Created 4 years, 6 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 | « no previous file | tools/viewer/sk_app/Window.h » ('j') | tools/viewer/sk_app/WindowContext.h » ('J')
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"
11 #include "ImageSlide.h" 11 #include "ImageSlide.h"
12 #include "SKPSlide.h" 12 #include "SKPSlide.h"
13 13
14 #include "GrRenderTarget.h"
14 #include "SkCanvas.h" 15 #include "SkCanvas.h"
15 #include "SkCommonFlags.h" 16 #include "SkCommonFlags.h"
17 #include "SkDashPathEffect.h"
16 #include "SkMetaData.h" 18 #include "SkMetaData.h"
17 #include "SkOSFile.h" 19 #include "SkOSFile.h"
18 #include "SkRandom.h" 20 #include "SkRandom.h"
19 #include "SkStream.h" 21 #include "SkStream.h"
22 #include "SkSurface.h"
20 23
21 using namespace sk_app; 24 using namespace sk_app;
22 25
23 Application* Application::Create(int argc, char** argv, void* platformData) { 26 Application* Application::Create(int argc, char** argv, void* platformData) {
24 return new Viewer(argc, argv, platformData); 27 return new Viewer(argc, argv, platformData);
25 } 28 }
26 29
27 static void on_paint_handler(SkCanvas* canvas, void* userData) { 30 static void on_paint_handler(SkCanvas* canvas, void* userData) {
28 Viewer* vv = reinterpret_cast<Viewer*>(userData); 31 Viewer* vv = reinterpret_cast<Viewer*>(userData);
29 32
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 contentRect.fLeft += 356 contentRect.fLeft +=
354 inSplitScreen ? (contentRect.fRight - contentRect.fLeft) * 0.5f : 0.0f; 357 inSplitScreen ? (contentRect.fRight - contentRect.fLeft) * 0.5f : 0.0f;
355 canvas->clipRect(contentRect); 358 canvas->clipRect(contentRect);
356 canvas->translate(contentRect.fLeft, contentRect.fTop); 359 canvas->translate(contentRect.fLeft, contentRect.fTop);
357 } 360 }
358 361
359 canvas->clear(SK_ColorWHITE); 362 canvas->clear(SK_ColorWHITE);
360 canvas->concat(fDefaultMatrix); 363 canvas->concat(fDefaultMatrix);
361 canvas->concat(computeMatrix()); 364 canvas->concat(computeMatrix());
362 365
363 canvas->getMetaData().setBool(kImageColorXformMetaData, inSplitScreen); 366 if (inSplitScreen) {
364 fSlides[fCurrentSlide]->draw(canvas); 367 sk_sp<SkSurface> offscreenSurface = fWindow->getOffscreenSurface(true);
368 fSlides[fCurrentSlide]->draw(offscreenSurface->getCanvas());
369 sk_sp<SkImage> snapshot = offscreenSurface->makeImageSnapshot();
370 canvas->drawImage(snapshot, 0, 0);
371 } else {
372 fSlides[fCurrentSlide]->draw(canvas);
373 }
374
365 canvas->restoreToCount(count); 375 canvas->restoreToCount(count);
376
377 if (inSplitScreen) {
378 // Draw split line
379 SkPaint paint;
380 SkScalar intervals[] = {10.0f, 5.0f};
381 paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0.0f));
382 SkRect contentRect = fWindow->getContentRect();
383 SkScalar middleX = (contentRect.fLeft + contentRect.fRight) * 0.5f;
384 canvas->drawLine(middleX, contentRect.fTop, middleX, contentRect.fBottom , paint);
385 }
366 } 386 }
367 387
368 void Viewer::onPaint(SkCanvas* canvas) { 388 void Viewer::onPaint(SkCanvas* canvas) {
369 drawSlide(canvas, false); 389 drawSlide(canvas, false);
370 if (fSplitScreen && fWindow->supportsContentRect()) { 390 if (fSplitScreen && fWindow->supportsContentRect()) {
371 drawSlide(canvas, true); 391 drawSlide(canvas, true);
372 } 392 }
373 393
374 if (fDisplayStats) { 394 if (fDisplayStats) {
375 drawStats(canvas); 395 drawStats(canvas);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 bool newSplitScreen = stateValue.equals(kON); 579 bool newSplitScreen = stateValue.equals(kON);
560 if (newSplitScreen != fSplitScreen) { 580 if (newSplitScreen != fSplitScreen) {
561 fSplitScreen = newSplitScreen; 581 fSplitScreen = newSplitScreen;
562 fWindow->inval(); 582 fWindow->inval();
563 updateUIState(); 583 updateUIState();
564 } 584 }
565 } else { 585 } else {
566 SkDebugf("Unknown stateName: %s", stateName.c_str()); 586 SkDebugf("Unknown stateName: %s", stateName.c_str());
567 } 587 }
568 } 588 }
OLDNEW
« no previous file with comments | « no previous file | tools/viewer/sk_app/Window.h » ('j') | tools/viewer/sk_app/WindowContext.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698