[Mammoth/Teton] Add an OpenFile interface and use it to load a font.
This commit is contained in:
parent
4fd17a59ea
commit
86ce0a68a3
6 changed files with 84 additions and 21 deletions
|
|
@ -1,4 +1,5 @@
|
|||
add_library(mammoth STATIC
|
||||
file/file.cpp
|
||||
ipc/channel.cpp
|
||||
ipc/endpoint_client.cpp
|
||||
ipc/endpoint_server.cpp
|
||||
|
|
@ -23,7 +24,10 @@ target_include_directories(mammoth
|
|||
target_link_libraries(mammoth
|
||||
glacier
|
||||
c
|
||||
zion_stub)
|
||||
victoriafalls_yunq
|
||||
yellowstone_yunq
|
||||
zion_stub
|
||||
)
|
||||
|
||||
set_target_properties(mammoth PROPERTIES
|
||||
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}"
|
||||
|
|
|
|||
45
lib/mammoth/file/file.cpp
Normal file
45
lib/mammoth/file/file.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#include "file/file.h"
|
||||
|
||||
#include <victoriafalls/victoriafalls.yunq.client.h>
|
||||
#include <yellowstone/yellowstone.yunq.client.h>
|
||||
#include <zglobal.h>
|
||||
|
||||
#include "util/debug.h"
|
||||
|
||||
namespace mmth {
|
||||
namespace {
|
||||
|
||||
VFSClient* gVfsClient = nullptr;
|
||||
|
||||
} // namespace
|
||||
|
||||
File File::Open(glcr::StringView path) {
|
||||
if (gVfsClient == 0) {
|
||||
YellowstoneClient client(gInitEndpointCap);
|
||||
|
||||
GetEndpointRequest yreq;
|
||||
yreq.set_endpoint_name("victoriafalls");
|
||||
Endpoint yresp;
|
||||
check(client.GetEndpoint(yreq, yresp));
|
||||
|
||||
gVfsClient = new VFSClient(yresp.endpoint());
|
||||
}
|
||||
|
||||
OpenFileRequest req;
|
||||
req.set_path(path);
|
||||
OpenFileResponse resp;
|
||||
check(gVfsClient->OpenFile(req, resp));
|
||||
|
||||
return File(OwnedMemoryRegion::FromCapability(resp.memory()));
|
||||
}
|
||||
|
||||
glcr::StringView File::as_str() {
|
||||
return glcr::StringView((char*)raw_ptr(), file_data_.size());
|
||||
}
|
||||
|
||||
void* File::raw_ptr() { return reinterpret_cast<void*>(file_data_.vaddr()); }
|
||||
uint8_t* File::byte_ptr() {
|
||||
return reinterpret_cast<uint8_t*>(file_data_.vaddr());
|
||||
}
|
||||
|
||||
} // namespace mmth
|
||||
25
lib/mammoth/file/file.h
Normal file
25
lib/mammoth/file/file.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/memory/move.h>
|
||||
#include <glacier/string/string_view.h>
|
||||
|
||||
#include "mammoth/util/memory_region.h"
|
||||
|
||||
namespace mmth {
|
||||
|
||||
class File {
|
||||
public:
|
||||
static File Open(glcr::StringView path);
|
||||
|
||||
glcr::StringView as_str();
|
||||
|
||||
void* raw_ptr();
|
||||
uint8_t* byte_ptr();
|
||||
|
||||
private:
|
||||
OwnedMemoryRegion file_data_;
|
||||
|
||||
File(OwnedMemoryRegion&& file) : file_data_(glcr::Move(file)) {}
|
||||
};
|
||||
|
||||
} // namespace mmth
|
||||
Loading…
Add table
Add a link
Reference in a new issue