Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Unified Diff: include/core/SkWriter32.h

Issue 167113003: Add capture snapshot as data to SkWriter32, use it to optimise record->playback. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Clarified the snapshotAsData api comment. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/core/SkPicturePlayback.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkWriter32.h
diff --git a/include/core/SkWriter32.h b/include/core/SkWriter32.h
index 2e7c9563d9f748017a6b4e04adc1ccff1cbab63b..cadcaa7853d8d663c7d6ab6310aa46c7e80ed2f9 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;
@@ -70,7 +72,7 @@ public:
/**
* Read a T record at offset, which must be a multiple of 4. Only legal if the record
- * was writtern atomically using the write methods below.
+ * was written atomically using the write methods below.
*/
template<typename T>
const T& readTAt(size_t offset) const {
@@ -81,12 +83,13 @@ public:
/**
* Overwrite a T record at offset, which must be a multiple of 4. Only legal if the record
- * was writtern atomically using the write methods below.
+ * was written atomically using the write methods below.
*/
template<typename T>
void overwriteTAt(size_t offset, const T& value) {
SkASSERT(SkAlign4(offset) == offset);
SkASSERT(offset < fUsed);
+ SkASSERT(fSnapshot.get() == NULL);
*(T*)(fData + offset) = value;
}
@@ -230,6 +233,18 @@ 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 SkData,
+ * but this is not guaranteed.
+ * Future appends will not affect the returned buffer.
+ * It is illegal to call overwriteTAt after this without an intervening
+ * append. It may cause the snapshot buffer to be corrupted.
+ * Callers must unref the returned SkData.
+ * This is not thread safe, it should only be called on the writing thread,
+ * the result however can be shared across threads.
+ */
+ SkData* snapshotAsData() const;
private:
void growToAtLeast(size_t size);
@@ -238,6 +253,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.
};
/**
« no previous file with comments | « no previous file | src/core/SkPicturePlayback.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698