| OLD | NEW |
| 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 "SampleSlide.h" | 12 #include "SampleSlide.h" |
| 13 #include "SKPSlide.h" | 13 #include "SKPSlide.h" |
| 14 | 14 |
| 15 #include "SkCanvas.h" | 15 #include "SkCanvas.h" |
| 16 #include "SkCommonFlags.h" | 16 #include "SkCommonFlags.h" |
| 17 #include "SkDashPathEffect.h" |
| 17 #include "SkMetaData.h" | 18 #include "SkMetaData.h" |
| 18 #include "SkOSFile.h" | 19 #include "SkOSFile.h" |
| 19 #include "SkRandom.h" | 20 #include "SkRandom.h" |
| 20 #include "SkStream.h" | 21 #include "SkStream.h" |
| 22 #include "SkSurface.h" |
| 21 | 23 |
| 22 using namespace sk_app; | 24 using namespace sk_app; |
| 23 | 25 |
| 24 Application* Application::Create(int argc, char** argv, void* platformData) { | 26 Application* Application::Create(int argc, char** argv, void* platformData) { |
| 25 return new Viewer(argc, argv, platformData); | 27 return new Viewer(argc, argv, platformData); |
| 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 Viewer* vv = reinterpret_cast<Viewer*>(userData); | 31 Viewer* vv = reinterpret_cast<Viewer*>(userData); |
| 30 | 32 |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 contentRect.fLeft += | 366 contentRect.fLeft += |
| 365 inSplitScreen ? (contentRect.fRight - contentRect.fLeft) * 0.5f
: 0.0f; | 367 inSplitScreen ? (contentRect.fRight - contentRect.fLeft) * 0.5f
: 0.0f; |
| 366 canvas->clipRect(contentRect); | 368 canvas->clipRect(contentRect); |
| 367 canvas->translate(contentRect.fLeft, contentRect.fTop); | 369 canvas->translate(contentRect.fLeft, contentRect.fTop); |
| 368 } | 370 } |
| 369 | 371 |
| 370 canvas->clear(SK_ColorWHITE); | 372 canvas->clear(SK_ColorWHITE); |
| 371 canvas->concat(fDefaultMatrix); | 373 canvas->concat(fDefaultMatrix); |
| 372 canvas->concat(computeMatrix()); | 374 canvas->concat(computeMatrix()); |
| 373 | 375 |
| 374 canvas->getMetaData().setBool(kImageColorXformMetaData, inSplitScreen); | 376 if (inSplitScreen) { |
| 375 fSlides[fCurrentSlide]->draw(canvas); | 377 sk_sp<SkSurface> offscreenSurface = fWindow->getOffscreenSurface(true); |
| 378 fSlides[fCurrentSlide]->draw(offscreenSurface->getCanvas()); |
| 379 sk_sp<SkImage> snapshot = offscreenSurface->makeImageSnapshot(); |
| 380 canvas->drawImage(snapshot, 0, 0); |
| 381 } else { |
| 382 fSlides[fCurrentSlide]->draw(canvas); |
| 383 } |
| 384 |
| 376 canvas->restoreToCount(count); | 385 canvas->restoreToCount(count); |
| 386 |
| 387 if (inSplitScreen) { |
| 388 // Draw split line |
| 389 SkPaint paint; |
| 390 SkScalar intervals[] = {10.0f, 5.0f}; |
| 391 paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0.0f)); |
| 392 SkRect contentRect = fWindow->getContentRect(); |
| 393 SkScalar middleX = (contentRect.fLeft + contentRect.fRight) * 0.5f; |
| 394 canvas->drawLine(middleX, contentRect.fTop, middleX, contentRect.fBottom
, paint); |
| 395 } |
| 377 } | 396 } |
| 378 | 397 |
| 379 void Viewer::onPaint(SkCanvas* canvas) { | 398 void Viewer::onPaint(SkCanvas* canvas) { |
| 380 drawSlide(canvas, false); | 399 drawSlide(canvas, false); |
| 381 if (fSplitScreen && fWindow->supportsContentRect()) { | 400 if (fSplitScreen && fWindow->supportsContentRect()) { |
| 382 drawSlide(canvas, true); | 401 drawSlide(canvas, true); |
| 383 } | 402 } |
| 384 | 403 |
| 385 if (fDisplayStats) { | 404 if (fDisplayStats) { |
| 386 drawStats(canvas); | 405 drawStats(canvas); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 bool newSplitScreen = stateValue.equals(kON); | 589 bool newSplitScreen = stateValue.equals(kON); |
| 571 if (newSplitScreen != fSplitScreen) { | 590 if (newSplitScreen != fSplitScreen) { |
| 572 fSplitScreen = newSplitScreen; | 591 fSplitScreen = newSplitScreen; |
| 573 fWindow->inval(); | 592 fWindow->inval(); |
| 574 updateUIState(); | 593 updateUIState(); |
| 575 } | 594 } |
| 576 } else { | 595 } else { |
| 577 SkDebugf("Unknown stateName: %s", stateName.c_str()); | 596 SkDebugf("Unknown stateName: %s", stateName.c_str()); |
| 578 } | 597 } |
| 579 } | 598 } |
| OLD | NEW |