/* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include "HostConnection.h" #include "VirtGpu.h" #include "gfxstream/guest/IOStream.h" #include /* This file implements an IOStream that uses VIRTGPU TRANSFER* ioctls on a * virtio-gpu DRM rendernode device to communicate with a goldfish-pipe * service on the host side. */ class VirtioGpuPipeStream : public gfxstream::guest::IOStream { public: explicit VirtioGpuPipeStream(size_t bufsize = 10000); explicit VirtioGpuPipeStream(size_t bufsize, int stream_handle); ~VirtioGpuPipeStream(); int connect(const char* serviceName = 0); uint64_t initProcessPipe(); virtual void *allocBuffer(size_t minSize); virtual int commitBuffer(size_t size); virtual const unsigned char *readFully( void *buf, size_t len); virtual const unsigned char *commitBufferAndReadFully( size_t size, void *buf, size_t len); virtual const unsigned char *read( void *buf, size_t *inout_len); bool valid(); int getRendernodeFd(); int recv(void *buf, size_t len); virtual int writeFully(const void *buf, size_t len); private: // sync. Also resets the write position. void wait(); // transfer to/from host ops ssize_t transferToHost(const void* buffer, size_t len); ssize_t transferFromHost(void* buffer, size_t len); int m_fd = -1; std::unique_ptr m_device; VirtGpuBlobPtr m_resource; VirtGpuBlobMappingPtr m_resourceMapping; unsigned char* m_virtio_mapped; // user mapping of bo // intermediate buffer size_t m_bufsize; unsigned char *m_buf; size_t m_writtenPos; };