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 <future>
20#include <mutex>
21
22#include <fmt/format.h>
23
26
27namespace cuttlefish {
28
30 public:
31 ScreenshotHandler() = default;
32 ~ScreenshotHandler() = default;
33
34 using SharedFrame = std::shared_ptr<VideoFrameBuffer>;
35 using SharedFrameFuture = std::shared_future<SharedFrame>;
36 using SharedFramePromise = std::promise<SharedFrame>;
37
38 Result<void> Screenshot(std::uint32_t display_number,
39 const std::string& screenshot_path);
40
41 void OnFrame(std::uint32_t display_number, SharedFrame& frame);
42
43 private:
45 // Promises used to share a frame for a given display from the display handler
46 // thread to the snapshot thread for processing.
47 std::unordered_map<std::uint32_t, SharedFramePromise>
49};
50
51} // namespace cuttlefish
Definition: expected.h:86
Definition: screenshot_handler.h:29
std::unordered_map< std::uint32_t, SharedFramePromise > pending_screenshot_displays_
Definition: screenshot_handler.h:48
std::shared_ptr< VideoFrameBuffer > SharedFrame
Definition: screenshot_handler.h:34
std::shared_future< SharedFrame > SharedFrameFuture
Definition: screenshot_handler.h:35
Result< void > Screenshot(std::uint32_t display_number, const std::string &screenshot_path)
Definition: screenshot_handler.cpp:162
void OnFrame(std::uint32_t display_number, SharedFrame &frame)
Definition: screenshot_handler.cpp:197
std::promise< SharedFrame > SharedFramePromise
Definition: screenshot_handler.h:36
std::mutex pending_screenshot_displays_mutex_
Definition: screenshot_handler.h:44
Definition: alloc_utils.cpp:23