Make SkIStream closer to spec, to work with more consumers.
git-svn-id: http://skia.googlecode.com/svn/trunk@2109 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/utils/win/SkIStream.cpp b/src/utils/win/SkIStream.cpp
index 4d5cd77..79164e6 100644
--- a/src/utils/win/SkIStream.cpp
+++ b/src/utils/win/SkIStream.cpp
@@ -107,7 +107,10 @@
: SkBaseIStream()
, fSkStream(stream)
, fUnrefOnRelease(unrefOnRelease)
-{ }
+ , fLocation()
+{
+ this->fSkStream->rewind();
+}
SkIStream::~SkIStream() {
if (NULL != this->fSkStream && fUnrefOnRelease) {
@@ -126,6 +129,7 @@
// ISequentialStream Interface
HRESULT STDMETHODCALLTYPE SkIStream::Read(void* pv, ULONG cb, ULONG* pcbRead) {
*pcbRead = this->fSkStream->read(pv, cb);
+ this->fLocation.QuadPart += *pcbRead;
return (*pcbRead == cb) ? S_OK : S_FALSE;
}
@@ -141,11 +145,8 @@
, DWORD dwOrigin
, ULARGE_INTEGER* lpNewFilePointer)
{
- if (lpNewFilePointer != NULL) {
- (*lpNewFilePointer).QuadPart = NULL;
- }
-
HRESULT hr = S_OK;
+
switch(dwOrigin) {
case STREAM_SEEK_SET: {
if (!this->fSkStream->rewind()) {
@@ -154,6 +155,7 @@
size_t skipped = this->fSkStream->skip(
liDistanceToMove.QuadPart
);
+ this->fLocation.QuadPart = skipped;
if (skipped != liDistanceToMove.QuadPart) {
hr = E_FAIL;
}
@@ -162,6 +164,7 @@
}
case STREAM_SEEK_CUR: {
size_t skipped = this->fSkStream->skip(liDistanceToMove.QuadPart);
+ this->fLocation.QuadPart += skipped;
if (skipped != liDistanceToMove.QuadPart) {
hr = E_FAIL;
}
@@ -171,10 +174,11 @@
if (!this->fSkStream->rewind()) {
hr = E_FAIL;
} else {
- size_t skipped = this->fSkStream->skip(
- this->fSkStream->getLength() + liDistanceToMove.QuadPart
- );
- if (skipped != liDistanceToMove.QuadPart) {
+ LONGLONG skip = this->fSkStream->getLength()
+ + liDistanceToMove.QuadPart;
+ size_t skipped = this->fSkStream->skip(skip);
+ this->fLocation.QuadPart = skipped;
+ if (skipped != skip) {
hr = E_FAIL;
}
}
@@ -185,6 +189,9 @@
break;
}
+ if (NULL != lpNewFilePointer) {
+ lpNewFilePointer->QuadPart = this->fLocation.QuadPart;
+ }
return hr;
}