Android-cuttlefish cvd tool
screenshot_handler.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024 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 <stdint.h>
20
21#include <future>
22#include <memory>
23#include <mutex>
24#include <string>
25#include <unordered_map>
26
29
30namespace cuttlefish {
31
33 public:
34 ScreenshotHandler() = default;
35 ~ScreenshotHandler() = default;
36
37 using SharedFrame = std::shared_ptr<VideoFrameBuffer>;
38 using SharedFrameFuture = std::shared_future<SharedFrame>;
39 using SharedFramePromise = std::promise<SharedFrame>;
40
41 Result<void> Screenshot(uint32_t display_number,
42 const std::string& screenshot_path);
43
44 void OnFrame(uint32_t display_number, SharedFrame& frame);
45
46 private:
48 // Promises used to share a frame for a given display from the display handler
49 // thread to the snapshot thread for processing.
50 std::unordered_map<uint32_t, SharedFramePromise> pending_screenshot_displays_;
51};
52
53} // namespace cuttlefish
Definition: screenshot_handler.h:32
std::shared_ptr< VideoFrameBuffer > SharedFrame
Definition: screenshot_handler.h:37
std::unordered_map< uint32_t, SharedFramePromise > pending_screenshot_displays_
Definition: screenshot_handler.h:50
std::shared_future< SharedFrame > SharedFrameFuture
Definition: screenshot_handler.h:38
Result< void > Screenshot(uint32_t display_number, const std::string &screenshot_path)
Definition: screenshot_handler.cpp:169
void OnFrame(uint32_t display_number, SharedFrame &frame)
Definition: screenshot_handler.cpp:206
std::promise< SharedFrame > SharedFramePromise
Definition: screenshot_handler.h:39
std::mutex pending_screenshot_displays_mutex_
Definition: screenshot_handler.h:47
Definition: alloc_driver.h:20
tl::expected< T, StackTraceError > Result
Definition: result_type.h:30