Debian Codegraph @

tools/viewer/CaptureSlide.cpp

raw
1 /*
2 * Copyright 2025 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "include/core/SkCanvas.h"
9 #include "include/core/SkClipOp.h"
10 #include "include/core/SkData.h"
11 #include "include/core/SkPicture.h"
12 #include "include/core/SkRect.h"
13 #include "include/core/SkRefCnt.h"
14 #include "include/private/base/SkDebug.h"
15 #include "src/capture/SkCapture.h"
16 #include "tools/viewer/CaptureSlide.h"
17
18 CaptureSlide::CaptureSlide(const SkString& name, const SkString& path) {
19 auto data = SkData::MakeFromFileName(path.c_str());
20 fCapture = SkCapture::MakeFromData(data);
21 if (fCapture) {
22 fMetadata = fCapture->getMetadata();
23 } else {
24 SkDebugf("Couldn't load capture %s", path.c_str());
25 }
26 }
27
28 CaptureSlide::~CaptureSlide() {}
29
30 void CaptureSlide::draw(SkCanvas* canvas) {
31 if (fCapture) {
32 auto focusPicture = fCapture->getPicture(fCurrentPictureIndex);
33 auto bounds = focusPicture->cullRect().roundOut();
34 canvas->clipIRect(bounds, SkClipOp::kIntersect);
35 canvas->drawPicture(fCapture->getPicture(fCurrentPictureIndex));
36 }
37 }
38
39 bool CaptureSlide::animate(double) {
40 if (fInvalidate) {
41 fInvalidate = false;
42 return true;
43 }
44 return fInvalidate;
45 }
46
47 void CaptureSlide::load(SkScalar, SkScalar) {
48 }
49
50 void CaptureSlide::unload() {
51 fCapture.reset(nullptr);
52 }
53
54 SkISize CaptureSlide::getDimensions() const {
55 return {0, 0};
56 }
57
58 bool CaptureSlide::onChar(SkUnichar c) {
59 switch (c) {
60 case 'N':
61 fCurrentPictureIndex = (fCurrentPictureIndex + 1) % fMetadata.numPictures;
62 fInvalidate = true;
63 return true;
64 case 'P':
65 fCurrentPictureIndex = (fCurrentPictureIndex + fMetadata.numPictures - 1) % fMetadata.numPictures;
66 fInvalidate = true;
67 return true;
68 }
69
70 return Slide::onChar(c);
71 }