Ana Krulec | 70d15b1b | 2020-12-01 10:05:15 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <SkDocument.h> |
| 20 | #include <SkNWayCanvas.h> |
| 21 | #include <SkSurface.h> |
| 22 | #include <chrono> |
| 23 | #include "CaptureTimer.h" |
| 24 | #include "tools/SkSharingProc.h" |
| 25 | |
| 26 | namespace android { |
| 27 | namespace renderengine { |
| 28 | namespace skia { |
| 29 | |
| 30 | using namespace std::chrono_literals; |
| 31 | |
| 32 | /** |
| 33 | * Class that captures frames that are sent to Skia in Render Engine. It sets up |
| 34 | * a multi frame capture and writes it into a file on the device. The capture is |
| 35 | * done based on a timer. |
| 36 | */ |
| 37 | class SkiaCapture { |
| 38 | using Interval = std::chrono::milliseconds; |
| 39 | |
| 40 | public: |
| 41 | SkiaCapture() {} |
| 42 | virtual ~SkiaCapture(); |
| 43 | // Called every frame. Normally returns early with screen canvas. |
| 44 | // But when capture is enabled, returns an nwaycanvas where commands are also recorded. |
| 45 | SkCanvas* tryCapture(SkSurface* surface); |
| 46 | // Called at the end of every frame. |
| 47 | void endCapture(); |
Ana Krulec | 6eab17a | 2020-12-09 15:52:36 -0800 | [diff] [blame] | 48 | // Returns whether the capture is running. |
| 49 | bool isCaptureRunning() { return mCaptureRunning; } |
Ana Krulec | 70d15b1b | 2020-12-01 10:05:15 -0800 | [diff] [blame] | 50 | |
| 51 | private: |
| 52 | // Performs the first-frame work of a multi frame SKP capture. Returns true if successful. |
| 53 | bool setupMultiFrameCapture(); |
| 54 | |
| 55 | // Closes the recording and serializes sequence to a file. |
| 56 | void writeToFile(); |
| 57 | |
| 58 | // Multi frame serialization stream and writer used when serializing more than one frame. |
| 59 | std::unique_ptr<SkFILEWStream> mOpenMultiPicStream; |
| 60 | sk_sp<SkDocument> mMultiPic; |
| 61 | std::unique_ptr<SkSharingSerialContext> mSerialContext; |
| 62 | std::unique_ptr<SkNWayCanvas> mNwayCanvas; |
| 63 | |
| 64 | // Capturing and interval control. |
| 65 | bool mCaptureRunning = false; |
| 66 | CaptureTimer mTimer; |
| 67 | Interval mTimerInterval = 0ms; |
| 68 | }; |
| 69 | |
| 70 | } // namespace skia |
| 71 | } // namespace renderengine |
| 72 | } // namespace android |