1 /* 2 * Copyright (C) 2019 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 <cstdint> 20 #include <functional> 21 22 #include "common/libs/utils/size_utils.h" 23 #include "host/libs/config/cuttlefish_config.h" 24 25 namespace cvd { 26 27 using FrameCallback = std::function<void(std::uint32_t /*frame_number*/, 28 std::uint8_t* /*frame_pixels*/)>; 29 30 class ScreenConnector { 31 public: 32 static ScreenConnector* Get(int frames_fd); 33 34 virtual ~ScreenConnector() = default; 35 36 // Runs the given callback on the next available frame after the given 37 // frame number and returns true if successful. 38 virtual bool OnFrameAfter(std::uint32_t frame_number, 39 const FrameCallback& frame_callback) = 0; 40 BytesPerPixel()41 static inline constexpr int BytesPerPixel() { 42 return sizeof(int32_t); 43 } 44 ScreenHeight()45 static inline int ScreenHeight() { 46 return vsoc::CuttlefishConfig::Get()->y_res(); 47 } 48 ScreenWidth()49 static inline int ScreenWidth() { 50 return vsoc::CuttlefishConfig::Get()->x_res(); 51 } 52 ScreenStride()53 static inline int ScreenStride() { 54 return AlignToPowerOf2(ScreenWidth() * BytesPerPixel(), 4); 55 } 56 ScreenSizeInBytes()57 static inline int ScreenSizeInBytes() { 58 return ScreenStride() * ScreenHeight(); 59 } 60 61 protected: 62 ScreenConnector() = default; 63 }; 64 65 } // namespace cvd