Debian Codegraph @

src/capture/SkCaptureManager.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 "src/capture/SkCaptureManager.h"
9
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkSurface.h"
12 #include "src/capture/SkCapture.h"
13 #include "src/capture/SkCaptureCanvas.h"
14
15 #include <memory>
16
17 SkCaptureManager::SkCaptureManager() {}
18
19 SkCanvas* SkCaptureManager::makeCaptureCanvas(SkCanvas* canvas) {
20 auto newCanvas = std::make_unique<SkCaptureCanvas>(canvas, this);
21 auto rawCanvasPtr = newCanvas.get();
22 fTrackedCanvases.emplace_back(std::move(newCanvas));
23 return rawCanvasPtr;
24 }
25
26 void SkCaptureManager::snapPictures() {
27 for (auto& canvas : fTrackedCanvases) {
28 if (canvas) {
29 auto picture = canvas->snapPicture();
30 if (picture) {
31 fPictures.emplace_back(picture);
32 }
33 }
34 }
35 }
36
37 // TODO: make thread saffe by using exchange() and a mutex.
38 void SkCaptureManager::toggleCapture(bool capturing) {
39 if (capturing != fIsCurrentlyCapturing && !capturing) {
40 // on capture stop, save the capture and reset
41 this->snapPictures();
42 fLastCapture = SkCapture::MakeFromPictures(fPictures);
43 fPictures.clear();
44 }
45 fIsCurrentlyCapturing = capturing;
46 }
47
48 void SkCaptureManager::snapPicture(SkSurface* surface) {
49 for (auto& canvas : fTrackedCanvases) {
50 if (canvas) {
51 if (canvas->getSurface() == surface) {
52 auto picture = canvas->snapPicture();
53 if (picture) {
54 // TODO(412351769): for every storing of a picture, we should track a content id
55 // and the surface it was drawn to.
56 fPictures.emplace_back(picture);
57 }
58 return;
59 }
60 }
61 }
62 }
63
64 sk_sp<SkCapture> SkCaptureManager::getLastCapture() const {
65 return fLastCapture;
66 }