| 1 |
/* |
| 2 |
* Copyright 2018 Google LLC |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <inttypes.h> |
| 8 |
|
| 9 |
#include <memory> |
| 10 |
#include <vector> |
| 11 |
|
| 12 |
#include "ResourceTracker.h" |
| 13 |
#include "VulkanHandleMapping.h" |
| 14 |
#include "BumpPool.h" |
| 15 |
#include "Stream.h" |
| 16 |
#include "gfxstream/guest/IOStream.h" |
| 17 |
#include "goldfish_vk_private_defs.h" |
| 18 |
|
| 19 |
namespace gfxstream { |
| 20 |
namespace vk { |
| 21 |
|
| 22 |
class VulkanStreamGuest : public gfxstream::aemu::Stream { |
| 23 |
public: |
| 24 |
VulkanStreamGuest(gfxstream::guest::IOStream* stream); |
| 25 |
~VulkanStreamGuest(); |
| 26 |
|
| 27 |
// Returns whether the connection is valid. |
| 28 |
bool valid(); |
| 29 |
|
| 30 |
// General allocation function |
| 31 |
void alloc(void** ptrAddr, size_t bytes); |
| 32 |
|
| 33 |
// Utility functions to load strings or |
| 34 |
// string arrays in place with allocation. |
| 35 |
void loadStringInPlace(char** forOutput); |
| 36 |
void loadStringArrayInPlace(char*** forOutput); |
| 37 |
|
| 38 |
// When we load a string and are using a reserved pointer. |
| 39 |
void loadStringInPlaceWithStreamPtr(char** forOutput, uint8_t** streamPtr); |
| 40 |
void loadStringArrayInPlaceWithStreamPtr(char*** forOutput, uint8_t** streamPtr); |
| 41 |
|
| 42 |
ssize_t read(void* buffer, size_t size) override; |
| 43 |
ssize_t write(const void* buffer, size_t size) override; |
| 44 |
|
| 45 |
void writeLarge(const void* buffer, size_t size); |
| 46 |
|
| 47 |
// Frees everything that got alloc'ed. |
| 48 |
void clearPool(); |
| 49 |
|
| 50 |
void setHandleMapping(VulkanHandleMapping* mapping); |
| 51 |
void unsetHandleMapping(); |
| 52 |
VulkanHandleMapping* handleMapping() const; |
| 53 |
|
| 54 |
void flush(); |
| 55 |
|
| 56 |
uint32_t getFeatureBits() const; |
| 57 |
|
| 58 |
void incStreamRef(); |
| 59 |
bool decStreamRef(); |
| 60 |
|
| 61 |
uint8_t* reserve(size_t size); |
| 62 |
|
| 63 |
private: |
| 64 |
gfxstream::aemu::BumpPool mPool; |
| 65 |
std::vector<uint8_t> mWriteBuffer; |
| 66 |
gfxstream::guest::IOStream* mStream = nullptr; |
| 67 |
DefaultHandleMapping mDefaultHandleMapping; |
| 68 |
VulkanHandleMapping* mCurrentHandleMapping; |
| 69 |
uint32_t mFeatureBits = 0; |
| 70 |
}; |
| 71 |
|
| 72 |
class VulkanCountingStream : public VulkanStreamGuest { |
| 73 |
public: |
| 74 |
VulkanCountingStream(); |
| 75 |
~VulkanCountingStream(); |
| 76 |
|
| 77 |
ssize_t read(void* buffer, size_t size) override; |
| 78 |
ssize_t write(const void* buffer, size_t size) override; |
| 79 |
|
| 80 |
size_t bytesWritten() const { return m_written; } |
| 81 |
size_t bytesRead() const { return m_read; } |
| 82 |
|
| 83 |
void rewind(); |
| 84 |
|
| 85 |
private: |
| 86 |
size_t m_written = 0; |
| 87 |
size_t m_read = 0; |
| 88 |
}; |
| 89 |
|
| 90 |
} // namespace vk |
| 91 |
} // namespace gfxstream |