diff options
-rw-r--r-- | include/core/SkStream.h | 11 | ||||
-rw-r--r-- | include/core/SkTypes.h | 2 | ||||
-rw-r--r-- | src/core/SkDebug.cpp | 5 | ||||
-rw-r--r-- | src/core/SkStream.cpp | 2 | ||||
-rw-r--r-- | src/utils/SkMD5.h | 2 | ||||
-rw-r--r-- | src/utils/SkSHA1.h | 2 |
6 files changed, 21 insertions, 3 deletions
diff --git a/include/core/SkStream.h b/include/core/SkStream.h index 29aac1356c..516b036a55 100644 --- a/include/core/SkStream.h +++ b/include/core/SkStream.h @@ -189,6 +189,8 @@ public: virtual void newline(); virtual void flush(); + virtual size_t bytesWritten() const = 0; + // helpers bool write8(U8CPU); @@ -369,9 +371,9 @@ public: */ bool isValid() const { return fFILE != NULL; } - size_t bytesWritten() const; virtual bool write(const void* buffer, size_t size) SK_OVERRIDE; virtual void flush() SK_OVERRIDE; + virtual size_t bytesWritten() const SK_OVERRIDE; private: SkFILE* fFILE; @@ -385,7 +387,7 @@ public: SkMemoryWStream(void* buffer, size_t size); virtual bool write(const void* buffer, size_t size) SK_OVERRIDE; - size_t bytesWritten() const { return fBytesWritten; } + virtual size_t bytesWritten() const SK_OVERRIDE { return fBytesWritten; } private: char* fBuffer; @@ -403,12 +405,12 @@ public: virtual ~SkDynamicMemoryWStream(); virtual bool write(const void* buffer, size_t size) SK_OVERRIDE; + virtual size_t bytesWritten() const SK_OVERRIDE { return fBytesWritten; } // random access write // modifies stream and returns true if offset + size is less than or equal to getOffset() bool write(const void* buffer, size_t offset, size_t size); bool read(void* buffer, size_t offset, size_t size); size_t getOffset() const { return fBytesWritten; } - size_t bytesWritten() const { return fBytesWritten; } // copy what has been written to the stream into dst void copyTo(void* dst) const; @@ -444,13 +446,16 @@ private: class SK_API SkDebugWStream : public SkWStream { public: + SkDebugWStream() : fBytesWritten(0) {} SK_DECLARE_INST_COUNT(SkDebugWStream) // overrides virtual bool write(const void* buffer, size_t size) SK_OVERRIDE; virtual void newline() SK_OVERRIDE; + virtual size_t bytesWritten() const SK_OVERRIDE { return fBytesWritten; } private: + size_t fBytesWritten; typedef SkWStream INHERITED; }; diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h index 969aac77b6..ab43767c6d 100644 --- a/include/core/SkTypes.h +++ b/include/core/SkTypes.h @@ -219,6 +219,7 @@ typedef uint8_t SkBool8; SK_API uint32_t SkToU32(uintmax_t); SK_API int SkToInt(intmax_t); SK_API unsigned SkToUInt(uintmax_t); + SK_API size_t SkToSizeT(uintmax_t); #else #define SkToS8(x) ((int8_t)(x)) #define SkToU8(x) ((uint8_t)(x)) @@ -228,6 +229,7 @@ typedef uint8_t SkBool8; #define SkToU32(x) ((uint32_t)(x)) #define SkToInt(x) ((int)(x)) #define SkToUInt(x) ((unsigned)(x)) + #define SkToSizeT(x) ((size_t)(x)) #endif /** Returns 0 or 1 based on the condition diff --git a/src/core/SkDebug.cpp b/src/core/SkDebug.cpp index d484f5eaff..b705a650ea 100644 --- a/src/core/SkDebug.cpp +++ b/src/core/SkDebug.cpp @@ -51,4 +51,9 @@ unsigned SkToUInt(uintmax_t x) { return (unsigned)x; } +size_t SkToSizeT(uintmax_t x) { + SkASSERT((size_t)x == x); + return (size_t)x; +} + #endif diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp index 70f97d2f7c..e766a1b35e 100644 --- a/src/core/SkStream.cpp +++ b/src/core/SkStream.cpp @@ -806,6 +806,7 @@ void SkDebugWStream::newline() { #if defined(SK_DEBUG) || defined(SK_DEVELOPER) SkDebugf("\n"); + fBytesWritten++; #endif } @@ -817,6 +818,7 @@ bool SkDebugWStream::write(const void* buffer, size_t size) s[size] = 0; SkDebugf("%s", s); delete[] s; + fBytesWritten += size+1; #endif return true; } diff --git a/src/utils/SkMD5.h b/src/utils/SkMD5.h index 0148641edc..4f504782b6 100644 --- a/src/utils/SkMD5.h +++ b/src/utils/SkMD5.h @@ -29,6 +29,8 @@ public: return true; } + virtual size_t bytesWritten() const SK_OVERRIDE { return SkToSizeT(this->byteCount); } + /** Processes input, adding it to the digest. Calling this after finish is undefined. */ void update(const uint8_t* input, size_t length); diff --git a/src/utils/SkSHA1.h b/src/utils/SkSHA1.h index cf2cb8c679..df8b9bf1b6 100644 --- a/src/utils/SkSHA1.h +++ b/src/utils/SkSHA1.h @@ -29,6 +29,8 @@ public: return true; } + virtual size_t bytesWritten() const SK_OVERRIDE { return SkToSizeT(this->byteCount); } + /** Processes input, adding it to the digest. Calling this after finish is undefined. */ void update(const uint8_t* input, size_t length); |