diff options
author | crupest <crupest@outlook.com> | 2022-01-30 20:40:59 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-01-30 20:40:59 +0800 |
commit | c1f8ea13524f398f8d1720e5f03a17dd66352ebf (patch) | |
tree | 0e27ed132cd82d1a690aa9534df38beec0c77d45 /src/osx/graphics/quartz/Convert.cpp | |
parent | a6dd823a94f0e6338545a4885e9d428e83a56593 (diff) | |
download | cru-c1f8ea13524f398f8d1720e5f03a17dd66352ebf.tar.gz cru-c1f8ea13524f398f8d1720e5f03a17dd66352ebf.tar.bz2 cru-c1f8ea13524f398f8d1720e5f03a17dd66352ebf.zip |
...
Diffstat (limited to 'src/osx/graphics/quartz/Convert.cpp')
-rw-r--r-- | src/osx/graphics/quartz/Convert.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/osx/graphics/quartz/Convert.cpp b/src/osx/graphics/quartz/Convert.cpp index af054e5a..1cd7ea1d 100644 --- a/src/osx/graphics/quartz/Convert.cpp +++ b/src/osx/graphics/quartz/Convert.cpp @@ -28,4 +28,25 @@ Rect Convert(const CGRect& rect) { static_cast<float>(rect.size.width), static_cast<float>(rect.size.height)}; } + +const CGDataProviderSequentialCallbacks kStreamToCGDataProviderCallbacks{ + 1, + [](void* stream, void* buffer, size_t size) -> size_t { + return static_cast<io::Stream*>(stream)->Read( + static_cast<std::byte*>(buffer), size); + }, + [](void* stream, off_t offset) -> off_t { + auto s = static_cast<io::Stream*>(stream); + auto current_position = s->Tell(); + s->Seek(offset, io::Stream::SeekOrigin::Current); + return s->Tell() - current_position; + }, + [](void* stream) { static_cast<io::Stream*>(stream)->Rewind(); }, + [](void* stream) {}}; + +CGDataProviderRef ConvertStreamToCGDataProvider(io::Stream* stream) { + return CGDataProviderCreateSequential(stream, + &kStreamToCGDataProviderCallbacks); +} + } // namespace cru::platform::graphics::osx::quartz |