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

Unified Diff: src/core/SkPaint.cpp

Issue 134163010: Refactor read and write buffers. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: whoops, read buffers have .size() Created 6 years, 11 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 | « src/core/SkOrderedWriteBuffer.cpp ('k') | src/core/SkPaintOptionsAndroid.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPaint.cpp
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index cc6d7ba1b3d792acc0f00b2f5d04dd224e086b0d..c3f217cefc60e5501e08a88755b5f537dbcb956c 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -18,8 +18,8 @@
#include "SkImageFilter.h"
#include "SkMaskFilter.h"
#include "SkMaskGamma.h"
-#include "SkOrderedReadBuffer.h"
-#include "SkOrderedWriteBuffer.h"
+#include "SkReadBuffer.h"
+#include "SkWriteBuffer.h"
#include "SkPaintDefaults.h"
#include "SkPaintOptionsAndroid.h"
#include "SkPathEffect.h"
@@ -1474,8 +1474,8 @@ void SkPaint::getPosTextPath(const void* textData, size_t length,
}
static void add_flattenable(SkDescriptor* desc, uint32_t tag,
- SkOrderedWriteBuffer* buffer) {
- buffer->writeToMemory(desc->addEntry(tag, buffer->size(), NULL));
+ SkWriteBuffer* buffer) {
+ buffer->writeToMemory(desc->addEntry(tag, buffer->bytesWritten(), NULL));
}
// SkFontHost can override this choice in FilterRec()
@@ -1815,18 +1815,18 @@ void SkPaint::descriptorProc(const SkDeviceProperties* deviceProperties,
SkMaskFilter* mf = this->getMaskFilter();
SkRasterizer* ra = this->getRasterizer();
- SkOrderedWriteBuffer peBuffer, mfBuffer, raBuffer;
+ SkWriteBuffer peBuffer, mfBuffer, raBuffer;
if (pe) {
peBuffer.writeFlattenable(pe);
- descSize += peBuffer.size();
+ descSize += peBuffer.bytesWritten();
entryCount += 1;
rec.fMaskFormat = SkMask::kA8_Format; // force antialiasing when we do the scan conversion
// seems like we could support kLCD as well at this point...
}
if (mf) {
mfBuffer.writeFlattenable(mf);
- descSize += mfBuffer.size();
+ descSize += mfBuffer.bytesWritten();
entryCount += 1;
rec.fMaskFormat = SkMask::kA8_Format; // force antialiasing with maskfilters
/* Pre-blend is not currently applied to filtered text.
@@ -1837,15 +1837,15 @@ void SkPaint::descriptorProc(const SkDeviceProperties* deviceProperties,
}
if (ra) {
raBuffer.writeFlattenable(ra);
- descSize += raBuffer.size();
+ descSize += raBuffer.bytesWritten();
entryCount += 1;
rec.fMaskFormat = SkMask::kA8_Format; // force antialiasing when we do the scan conversion
}
#ifdef SK_BUILD_FOR_ANDROID
- SkOrderedWriteBuffer androidBuffer;
+ SkWriteBuffer androidBuffer;
fPaintOptionsAndroid.flatten(androidBuffer);
- descSize += androidBuffer.size();
+ descSize += androidBuffer.bytesWritten();
entryCount += 1;
#endif
@@ -1999,7 +1999,7 @@ static const uint32_t kPODPaintSize = 5 * sizeof(SkScalar) +
/* To save space/time, we analyze the paint, and write a truncated version of
it if there are not tricky elements like shaders, etc.
*/
-void SkPaint::flatten(SkFlattenableWriteBuffer& buffer) const {
+void SkPaint::flatten(SkWriteBuffer& buffer) const {
uint8_t flatFlags = 0;
if (this->getTypeface()) {
flatFlags |= kHasTypeface_FlatFlag;
@@ -2021,42 +2021,24 @@ void SkPaint::flatten(SkFlattenableWriteBuffer& buffer) const {
}
#endif
- if (buffer.isOrderedBinaryBuffer()) {
- SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize);
- uint32_t* ptr = buffer.getOrderedBinaryBuffer()->reserve(kPODPaintSize);
-
- ptr = write_scalar(ptr, this->getTextSize());
- ptr = write_scalar(ptr, this->getTextScaleX());
- ptr = write_scalar(ptr, this->getTextSkewX());
- ptr = write_scalar(ptr, this->getStrokeWidth());
- ptr = write_scalar(ptr, this->getStrokeMiter());
- *ptr++ = this->getColor();
- // previously flags:16, textAlign:8, flatFlags:8
- // now flags:16, hinting:4, textAlign:4, flatFlags:8
- *ptr++ = (this->getFlags() << 16) |
- // hinting added later. 0 in this nibble means use the default.
- ((this->getHinting()+1) << 12) |
- (this->getTextAlign() << 8) |
- flatFlags;
- *ptr++ = pack_4(this->getStrokeCap(), this->getStrokeJoin(),
- this->getStyle(), this->getTextEncoding());
- } else {
- buffer.writeScalar(fTextSize);
- buffer.writeScalar(fTextScaleX);
- buffer.writeScalar(fTextSkewX);
- buffer.writeScalar(fWidth);
- buffer.writeScalar(fMiterLimit);
- buffer.writeColor(fColor);
- buffer.writeUInt(fFlags);
- buffer.writeUInt(fHinting);
- buffer.writeUInt(fTextAlign);
- buffer.writeUInt(flatFlags);
-
- buffer.writeUInt(fCapType);
- buffer.writeUInt(fJoinType);
- buffer.writeUInt(fStyle);
- buffer.writeUInt(fTextEncoding);
- }
+ SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize);
+ uint32_t* ptr = buffer.reserve(kPODPaintSize);
+
+ ptr = write_scalar(ptr, this->getTextSize());
+ ptr = write_scalar(ptr, this->getTextScaleX());
+ ptr = write_scalar(ptr, this->getTextSkewX());
+ ptr = write_scalar(ptr, this->getStrokeWidth());
+ ptr = write_scalar(ptr, this->getStrokeMiter());
+ *ptr++ = this->getColor();
+ // previously flags:16, textAlign:8, flatFlags:8
+ // now flags:16, hinting:4, textAlign:4, flatFlags:8
+ *ptr++ = (this->getFlags() << 16) |
+ // hinting added later. 0 in this nibble means use the default.
+ ((this->getHinting()+1) << 12) |
+ (this->getTextAlign() << 8) |
+ flatFlags;
+ *ptr++ = pack_4(this->getStrokeCap(), this->getStrokeJoin(),
+ this->getStyle(), this->getTextEncoding());
// now we're done with ptr and the (pre)reserved space. If we need to write
// additional fields, use the buffer directly
@@ -2087,58 +2069,38 @@ void SkPaint::flatten(SkFlattenableWriteBuffer& buffer) const {
#endif
}
-void SkPaint::unflatten(SkFlattenableReadBuffer& buffer) {
+void SkPaint::unflatten(SkReadBuffer& buffer) {
uint8_t flatFlags = 0;
- if (buffer.isOrderedBinaryBuffer()) {
- SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize);
- const void* podData = buffer.getOrderedBinaryBuffer()->skip(kPODPaintSize);
- const uint32_t* pod = reinterpret_cast<const uint32_t*>(podData);
-
- // the order we read must match the order we wrote in flatten()
- this->setTextSize(read_scalar(pod));
- this->setTextScaleX(read_scalar(pod));
- this->setTextSkewX(read_scalar(pod));
- this->setStrokeWidth(read_scalar(pod));
- this->setStrokeMiter(read_scalar(pod));
- this->setColor(*pod++);
-
- // previously flags:16, textAlign:8, flatFlags:8
- // now flags:16, hinting:4, textAlign:4, flatFlags:8
- uint32_t tmp = *pod++;
- this->setFlags(tmp >> 16);
-
- // hinting added later. 0 in this nibble means use the default.
- uint32_t hinting = (tmp >> 12) & 0xF;
- this->setHinting(0 == hinting ? kNormal_Hinting : static_cast<Hinting>(hinting-1));
-
- this->setTextAlign(static_cast<Align>((tmp >> 8) & 0xF));
-
- flatFlags = tmp & 0xFF;
-
- tmp = *pod++;
- this->setStrokeCap(static_cast<Cap>((tmp >> 24) & 0xFF));
- this->setStrokeJoin(static_cast<Join>((tmp >> 16) & 0xFF));
- this->setStyle(static_cast<Style>((tmp >> 8) & 0xFF));
- this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF));
- } else {
- this->setTextSize(buffer.readScalar());
- this->setTextScaleX(buffer.readScalar());
- this->setTextSkewX(buffer.readScalar());
- // Skip the hinting scalar factor, which is not supported.
- buffer.readScalar();
- this->setStrokeWidth(buffer.readScalar());
- this->setStrokeMiter(buffer.readScalar());
- this->setColor(buffer.readColor());
- this->setFlags(buffer.readUInt());
- this->setHinting(static_cast<SkPaint::Hinting>(buffer.readUInt()));
- this->setTextAlign(static_cast<SkPaint::Align>(buffer.readUInt()));
- flatFlags = buffer.readUInt();
-
- this->setStrokeCap(static_cast<SkPaint::Cap>(buffer.readUInt()));
- this->setStrokeJoin(static_cast<SkPaint::Join>(buffer.readUInt()));
- this->setStyle(static_cast<SkPaint::Style>(buffer.readUInt()));
- this->setTextEncoding(static_cast<SkPaint::TextEncoding>(buffer.readUInt()));
- }
+ SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize);
+ const void* podData = buffer.skip(kPODPaintSize);
+ const uint32_t* pod = reinterpret_cast<const uint32_t*>(podData);
+
+ // the order we read must match the order we wrote in flatten()
+ this->setTextSize(read_scalar(pod));
+ this->setTextScaleX(read_scalar(pod));
+ this->setTextSkewX(read_scalar(pod));
+ this->setStrokeWidth(read_scalar(pod));
+ this->setStrokeMiter(read_scalar(pod));
+ this->setColor(*pod++);
+
+ // previously flags:16, textAlign:8, flatFlags:8
+ // now flags:16, hinting:4, textAlign:4, flatFlags:8
+ uint32_t tmp = *pod++;
+ this->setFlags(tmp >> 16);
+
+ // hinting added later. 0 in this nibble means use the default.
+ uint32_t hinting = (tmp >> 12) & 0xF;
+ this->setHinting(0 == hinting ? kNormal_Hinting : static_cast<Hinting>(hinting-1));
+
+ this->setTextAlign(static_cast<Align>((tmp >> 8) & 0xF));
+
+ flatFlags = tmp & 0xFF;
+
+ tmp = *pod++;
+ this->setStrokeCap(static_cast<Cap>((tmp >> 24) & 0xFF));
+ this->setStrokeJoin(static_cast<Join>((tmp >> 16) & 0xFF));
+ this->setStyle(static_cast<Style>((tmp >> 8) & 0xFF));
+ this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF));
if (flatFlags & kHasTypeface_FlatFlag) {
this->setTypeface(buffer.readTypeface());
« no previous file with comments | « src/core/SkOrderedWriteBuffer.cpp ('k') | src/core/SkPaintOptionsAndroid.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698