aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pipe
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-06-21 19:24:00 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-06-21 19:24:00 +0000
commit6bac947cd5bc460dd9166ada6310d678fd2e39f8 (patch)
tree4f0adb7306dc1738f7e935ad84aac16ea1cc5d4d /src/pipe
parent25fb21f5df904c6f111bbf8f07e6a6c339416d09 (diff)
Add option in flattening to write factory names inline, as we are recording.
SkGPipe needs this, since it cannot (unlike SkPicture) see all of the factories before it hands its data to the reader. In this mode, the writer embedds the factory name the first time it sees it, and then after that writes an index (referencing the fFactorySet). The reader installs an empty array, and as it encounters names, appends them to that array so that subsequent indices can be used to retrieve the previously named factory. Some of the existing patheffects did not register their factory names, so those changes are also part of this CL. Annoyingly, to register your factory using the current scheme, it has to be in the public section of the class definition. git-svn-id: http://skia.googlecode.com/svn/trunk@1663 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/pipe')
-rw-r--r--src/pipe/SkGPipePriv.h2
-rw-r--r--src/pipe/SkGPipeRead.cpp27
-rw-r--r--src/pipe/SkGPipeWrite.cpp24
3 files changed, 5 insertions, 48 deletions
diff --git a/src/pipe/SkGPipePriv.h b/src/pipe/SkGPipePriv.h
index fb1553693d..06ba7b6aaa 100644
--- a/src/pipe/SkGPipePriv.h
+++ b/src/pipe/SkGPipePriv.h
@@ -75,8 +75,6 @@ enum DrawOps {
kDef_Typeface_DrawOp,
kDef_Flattenable_DrawOp,
- kName_Flattenable_DrawOp, // index <--> name
-
// these are signals to playback, not drawing verbs
kDone_DrawOp,
};
diff --git a/src/pipe/SkGPipeRead.cpp b/src/pipe/SkGPipeRead.cpp
index 6665abb3ff..fb0fbc497e 100644
--- a/src/pipe/SkGPipeRead.cpp
+++ b/src/pipe/SkGPipeRead.cpp
@@ -72,7 +72,7 @@ public:
void setReader(SkFlattenableReadBuffer* reader) {
fReader = reader;
- fReader->setFactoryPlayback(fFactoryArray.begin(), fFactoryArray.count());
+ fReader->setFactoryArray(&fFactoryArray);
}
const SkPaint& paint() const { return fPaint; }
@@ -91,16 +91,6 @@ public:
*fFlatArray.append() = obj;
}
- void nameFlattenable(PaintFlats pf, unsigned index) {
- SkASSERT(index == fFactoryArray.count() + 1);
- const char* name = fReader->readString();
- SkFlattenable::Factory fact = SkFlattenable::NameToFactory(name);
- *fFactoryArray.append() = fact;
-
- // update this each time we grow the array
- fReader->setFactoryPlayback(fFactoryArray.begin(), fFactoryArray.count());
- }
-
void addTypeface() {
size_t size = fReader->readU32();
const void* data = fReader->skip(SkAlign4(size));
@@ -444,13 +434,6 @@ static void def_PaintFlat_rp(SkCanvas*, SkReader32*, uint32_t op32,
state->defFlattenable(pf, index);
}
-static void name_PaintFlat_rp(SkCanvas*, SkReader32*, uint32_t op32,
- SkGPipeState* state) {
- PaintFlats pf = (PaintFlats)DrawOp_unpackFlags(op32);
- unsigned index = DrawOp_unpackData(op32);
- state->nameFlattenable(pf, index);
-}
-
///////////////////////////////////////////////////////////////////////////////
static void skip_rp(SkCanvas*, SkReader32* reader, uint32_t op32, SkGPipeState*) {
@@ -497,7 +480,6 @@ static const ReadProc gReadTable[] = {
paintOp_rp,
def_Typeface_rp,
def_PaintFlat_rp,
- name_PaintFlat_rp,
done_rp
};
@@ -507,8 +489,8 @@ static const ReadProc gReadTable[] = {
SkGPipeState::SkGPipeState() {}
SkGPipeState::~SkGPipeState() {
- fTypefaces.unrefAll();
- fFlatArray.unrefAll();
+ fTypefaces.safeUnrefAll();
+ fFlatArray.safeUnrefAll();
}
///////////////////////////////////////////////////////////////////////////////
@@ -562,8 +544,7 @@ SkGPipeReader::Status SkGPipeReader::playback(const void* data, size_t length,
if (readAtom &&
(table[op] != paintOp_rp &&
table[op] != def_Typeface_rp &&
- table[op] != def_PaintFlat_rp &&
- table[op] != name_PaintFlat_rp
+ table[op] != def_PaintFlat_rp
)) {
status = kReadAtom_Status;
break;
diff --git a/src/pipe/SkGPipeWrite.cpp b/src/pipe/SkGPipeWrite.cpp
index 5f928d7de3..18c3e60c9f 100644
--- a/src/pipe/SkGPipeWrite.cpp
+++ b/src/pipe/SkGPipeWrite.cpp
@@ -197,31 +197,9 @@ int SkGPipeCanvas::flattenToIndex(SkFlattenable* obj, PaintFlats paintflat) {
if (NULL == obj) {
return 0;
}
-
- SkFlattenable::Factory fact = obj->getFactory();
- if (NULL == fact) {
- return 0;
- }
- if (fFactorySet) {
- uint32_t id = fFactorySet->find((void*)fact);
- if (0 == id) {
- const char* name = SkFlattenable::FactoryToName(fact);
- if (NULL == name) {
- return 0;
- }
- size_t len = strlen(name);
- size_t size = SkWriter32::WriteStringSize(name, len);
- if (!this->needOpBytes(size)) {
- return 0;
- }
- unsigned id = fFactorySet->add(fact);
- this->writeOp(kName_Flattenable_DrawOp, paintflat, id);
- fWriter.writeString(name, len);
- }
- }
-
SkFlattenableWriteBuffer tmpWriter(1024);
+ tmpWriter.setFlags(SkFlattenableWriteBuffer::kInlineFactoryNames_Flag);
tmpWriter.setFactoryRecorder(fFactorySet);
tmpWriter.writeFlattenable(obj);