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/viewer/Viewer.cpp

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