[Base] Android content URI file memory mapping

This commit is contained in:
Triang3l
2022-07-17 16:34:17 +03:00
parent 93a7918025
commit 624f2b2d9e
4 changed files with 73 additions and 39 deletions

View File

@@ -12,7 +12,9 @@
#include <filesystem>
#include <memory>
#include <string>
#include <string_view>
#include "xenia/base/platform.h"
namespace xe {
@@ -26,21 +28,25 @@ class MappedMemory {
static std::unique_ptr<MappedMemory> Open(const std::filesystem::path& path,
Mode mode, size_t offset = 0,
size_t length = 0);
#if XE_PLATFORM_ANDROID
static std::unique_ptr<MappedMemory> OpenForAndroidContentUri(
const std::string_view uri, Mode mode, size_t offset = 0,
size_t length = 0);
#endif // XE_PLATFORM_ANDROID
MappedMemory(const std::filesystem::path& path, Mode mode)
: path_(path), mode_(mode), data_(nullptr), size_(0) {}
MappedMemory(const std::filesystem::path& path, Mode mode, void* data,
size_t size)
: path_(path), mode_(mode), data_(data), size_(size) {}
MappedMemory() : data_(nullptr), size_(0) {}
MappedMemory(void* data, size_t size) : data_(data), size_(size) {}
MappedMemory(const MappedMemory& mapped_memory) = delete;
MappedMemory& operator=(const MappedMemory& mapped_memory) = delete;
MappedMemory(MappedMemory&& mapped_memory) = delete;
MappedMemory& operator=(MappedMemory&& mapped_memory) = delete;
virtual ~MappedMemory() = default;
std::unique_ptr<MappedMemory> Slice(Mode mode, size_t offset, size_t length) {
// The mapping is still backed by the object the slice was created from, a
// slice is not owning.
std::unique_ptr<MappedMemory> Slice(size_t offset, size_t length) {
return std::unique_ptr<MappedMemory>(
new MappedMemory(path_, mode, data() + offset, length));
new MappedMemory(data() + offset, length));
}
uint8_t* data() const { return reinterpret_cast<uint8_t*>(data_); }
@@ -54,8 +60,6 @@ class MappedMemory {
virtual bool Remap(size_t offset, size_t length) { return false; }
protected:
std::filesystem::path path_;
Mode mode_;
void* data_;
size_t size_;
};