Chromium Code Reviews| Index: include/core/SkWriter32.h |
| diff --git a/include/core/SkWriter32.h b/include/core/SkWriter32.h |
| index 2e7c9563d9f748017a6b4e04adc1ccff1cbab63b..28d74a7dfd34e4be71b3579e7264e6390af8d0fa 100644 |
| --- a/include/core/SkWriter32.h |
| +++ b/include/core/SkWriter32.h |
| @@ -10,6 +10,7 @@ |
| #ifndef SkWriter32_DEFINED |
| #define SkWriter32_DEFINED |
| +#include "SkData.h" |
| #include "SkMatrix.h" |
| #include "SkPath.h" |
| #include "SkPoint.h" |
| @@ -44,6 +45,7 @@ public: |
| SkASSERT(SkIsAlign4((uintptr_t)external)); |
| SkASSERT(SkIsAlign4(externalBytes)); |
| + fSnapshot.reset(NULL); |
| fData = (uint8_t*)external; |
| fCapacity = externalBytes; |
| fUsed = 0; |
| @@ -230,6 +232,16 @@ public: |
| return stream->read(this->reservePad(length), length); |
| } |
| + /** |
| + * Captures a snapshot of the data as it is right now, and return it. |
| + * Multiple calls without intervening writes may return the same buffer, |
|
reed1
2014/02/14 17:31:08
I like noting this possible optimization, but perh
iancottrell
2014/02/14 18:28:36
Sure, I deliberately used the word may, but I agre
|
| + * and future appends will not affect the returned buffer. |
| + * Callers must unref the returned SkData. |
| + */ |
| + SkData* snapshotAsData(); |
| + SkData* snapshotAsData() const { |
|
mtklein
2014/02/14 17:42:18
Why have both const and non-const versions? Why n
iancottrell
2014/02/14 18:28:36
Would we rather make it threadsafe?
|
| + return const_cast<SkWriter32*>(this)->snapshotAsData(); |
|
reed1
2014/02/14 17:31:08
Do we want a mutex guard around this, since we are
iancottrell
2014/02/14 18:28:36
Maybe? This is an area where I just don't have eno
iancottrell
2014/02/27 20:16:19
Added a mutex guard in the implementation.
|
| + } |
| private: |
| void growToAtLeast(size_t size); |
| @@ -238,6 +250,7 @@ private: |
| size_t fUsed; // Number of bytes written. |
| void* fExternal; // Unmanaged memory block. |
| SkAutoTMalloc<uint8_t> fInternal; // Managed memory block. |
| + SkAutoTUnref<SkData> fSnapshot; // Holds the result of last asData. |
| }; |
| /** |