summaryrefslogtreecommitdiff
path: root/platform/winrt/mupdfwinrt
diff options
context:
space:
mode:
authorMichael Vrhel <michael.vrhel@artifex.com>2014-03-20 16:50:13 -0700
committerRobin Watts <robin.watts@artifex.com>2014-03-25 16:44:49 +0000
commit3e6f3f15dd288be573b86d9013ba9f49e3bd7fdf (patch)
tree59b563d9b3327b18623aefedc193e54573adf020 /platform/winrt/mupdfwinrt
parent56585e87d5154b667e37e1b7e262122ea633c73b (diff)
downloadmupdf-3e6f3f15dd288be573b86d9013ba9f49e3bd7fdf.tar.xz
Update the winrt solution with the changes made in the win32 solution.
Also update the code for the changes made in the stream API
Diffstat (limited to 'platform/winrt/mupdfwinrt')
-rw-r--r--platform/winrt/mupdfwinrt/muctx.cpp38
-rw-r--r--platform/winrt/mupdfwinrt/muctx.h1
2 files changed, 28 insertions, 11 deletions
diff --git a/platform/winrt/mupdfwinrt/muctx.cpp b/platform/winrt/mupdfwinrt/muctx.cpp
index cc3feff3..59f41204 100644
--- a/platform/winrt/mupdfwinrt/muctx.cpp
+++ b/platform/winrt/mupdfwinrt/muctx.cpp
@@ -7,28 +7,40 @@
* (other than the file streaming stuff) */
#ifdef _WINRT_DLL
+// Attempt to use t.wait()
+//#include <ppltasks.h>
+//using namespace concurrency;
/* File streaming set up for WinRT */
-static int win_read_file(fz_stream *stm, unsigned char *buf, int len)
+static int win_next_file(fz_stream *stm, int len)
{
void *temp = stm->state;
- win_stream_struct *stream = reinterpret_cast <win_stream_struct*> (temp);
- IRandomAccessStream^ Stream = stream->stream;
+ win_stream_struct *state = reinterpret_cast <win_stream_struct*> (temp);
+ IRandomAccessStream^ Stream = state->stream;
+ unsigned char *buf = state->public_buffer;
unsigned long long curr_pos = Stream->Position;
unsigned long long length = Stream->Size;
DataReader^ local_reader = ref new DataReader(Stream);
if (local_reader == nullptr)
return 0;
- DataReaderLoadOperation^ result = local_reader->LoadAsync(len);
-
- /* Block on the Async call. This is not on the UI thread. */
- while(result->Status != AsyncStatus::Completed) {
+ // This does not work here. mupdf is not set up to wait for win_next_file
+ // to complete in an ansyn manner
+ //auto t = create_task(local_reader->LoadAsync(len));
+ //t.wait();
+ DataReaderLoadOperation^ result = local_reader->LoadAsync(len);
+ while (result->Status != AsyncStatus::Completed) {
}
result->GetResults();
+
+ /* First see what is available */
int curr_len2 = local_reader->UnconsumedBufferLength;
if (curr_len2 < len)
len = curr_len2;
+ /* And make sure that we have enough room */
+ if (len > sizeof(state->public_buffer))
+ len = sizeof(state->public_buffer);
+
Platform::Array<unsigned char>^ arrByte = ref new Platform::Array<unsigned char>(len);
if (arrByte == nullptr)
return 0;
@@ -37,7 +49,12 @@ static int win_read_file(fz_stream *stm, unsigned char *buf, int len)
memcpy(buf, arrByte->Data, len);
local_reader->DetachStream();
- return len;
+ stm->rp = buf;
+ stm->wp = buf + len;
+ stm->pos += len;
+ if (len == 0)
+ return EOF;
+ return *stm->rp++;
}
static void win_seek_file(fz_stream *stm, int offset, int whence)
@@ -64,8 +81,7 @@ static void win_seek_file(fz_stream *stm, int offset, int whence)
Stream->Seek(n);
curr_pos = Stream->Position;
stm->pos = n;
- stm->rp = stm->bp;
- stm->wp = stm->bp;
+ stm->wp = stm->rp;
}
static void win_close_file(fz_context *ctx, void *state)
@@ -78,7 +94,7 @@ static void win_close_file(fz_context *ctx, void *state)
status_t muctx::InitializeStream(IRandomAccessStream^ readStream, char *ext)
{
win_stream.stream = readStream;
- fz_stream *mu_stream = fz_new_stream(mu_ctx, 0, win_read_file, win_close_file, NULL);
+ fz_stream *mu_stream = fz_new_stream(mu_ctx, 0, win_next_file, win_close_file, NULL);
mu_stream->seek = win_seek_file;
mu_stream->state = reinterpret_cast <void*> (&win_stream);
diff --git a/platform/winrt/mupdfwinrt/muctx.h b/platform/winrt/mupdfwinrt/muctx.h
index 0a27af52..90ef90e2 100644
--- a/platform/winrt/mupdfwinrt/muctx.h
+++ b/platform/winrt/mupdfwinrt/muctx.h
@@ -58,6 +58,7 @@ using namespace Windows::Foundation;
typedef struct win_stream_struct_s
{
IRandomAccessStream^ stream;
+ unsigned char public_buffer[4096];
} win_stream_struct;
#endif