1 /* 2 * Copyright (C) 2016 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 #pragma once 17 18 #include <condition_variable> 19 #include <functional> 20 #include <mutex> 21 #include <thread> 22 #include <vector> 23 24 #include "common/libs/fs/shared_fd.h" 25 #include "guest/hals/hwcomposer/common/screen_view.h" 26 27 namespace cuttlefish { 28 29 class VsocketScreenView : public ScreenView { 30 public: 31 VsocketScreenView(); 32 virtual ~VsocketScreenView(); 33 34 void Broadcast(int buffer_id, 35 const CompositionStats* stats = nullptr) override; 36 void* GetBuffer(int fb_index) override; 37 38 int32_t x_res() const override; 39 int32_t y_res() const override; 40 int32_t dpi() const override; 41 int32_t refresh_rate() const override; 42 43 int num_buffers() const override; 44 45 private: 46 bool ConnectToScreenServer(); 47 void GetScreenParameters(); 48 void BroadcastLoop(); 49 50 std::vector<char> inner_buffer_; 51 cuttlefish::SharedFD screen_server_; 52 std::thread broadcast_thread_; 53 int current_offset_ = 0; 54 int current_seq_ = 0; 55 std::mutex mutex_; 56 std::condition_variable cond_var_; 57 bool running_ = true; 58 int32_t x_res_{720}; 59 int32_t y_res_{1280}; 60 int32_t dpi_{160}; 61 int32_t refresh_rate_{60}; 62 }; 63 64 } // namespace cuttlefish 65