// Returns fTopBot array, so it can be passed to a routine to compute them.
// For efficiency, we assert that fTopBot have not been recorded yet.
- SkScalar* writableTopBot() {
+ SkScalar* writableTopBot() const {
SkASSERT(!this->isTopBotWritten());
return fTopBot;
}
int fIndex;
// Cache of paint's FontMetrics fTop,fBottom
- // initialied to [0,0] as a sentinel that they have not been recorded yet
+ // initialied to [NaN,NaN] as a sentinel that they have not been recorded yet
//
// This is *not* part of the key for search/sort
- SkScalar fTopBot[2];
+ mutable SkScalar fTopBot[2];
// marks fTopBot[] as unrecorded
void setTopBotUnwritten() {
return array;
}
-protected:
- void (*fFlattenProc)(SkOrderedWriteBuffer&, const void*);
- void (*fUnflattenProc)(SkOrderedReadBuffer&, void*);
-
-private:
- void unflattenIntoArray(T* array) const {
- const int count = fData.count();
- const SkFlatData** iter = fData.begin();
- for (int i = 0; i < count; ++i) {
- const SkFlatData* element = iter[i];
- int index = element->index() - 1;
- SkASSERT((unsigned)index < (unsigned)count);
- element->unflatten(&array[index], fUnflattenProc,
- fController->getBitmapHeap(),
- fController->getTypefacePlayback());
- }
- }
-
-
- SkFlatController * const fController;
- int fNextIndex;
- SkTDArray<const SkFlatData*> fData;
-
const SkFlatData* findAndReturnFlat(const T& element) {
SkFlatData* flat = SkFlatData::Create(fController, &element, fNextIndex, fFlattenProc);
return flat;
}
+protected:
+ void (*fFlattenProc)(SkOrderedWriteBuffer&, const void*);
+ void (*fUnflattenProc)(SkOrderedReadBuffer&, void*);
+
+private:
+ void unflattenIntoArray(T* array) const {
+ const int count = fData.count();
+ const SkFlatData** iter = fData.begin();
+ for (int i = 0; i < count; ++i) {
+ const SkFlatData* element = iter[i];
+ int index = element->index() - 1;
+ SkASSERT((unsigned)index < (unsigned)count);
+ element->unflatten(&array[index], fUnflattenProc,
+ fController->getBitmapHeap(),
+ fController->getTypefacePlayback());
+ }
+ }
+
+ SkFlatController * const fController;
+ int fNextIndex;
+ SkTDArray<const SkFlatData*> fData;
enum {
// Determined by trying diff values on picture-recording benchmarks
fFlattenProc = &SkFlattenObjectProc<SkPaint>;
fUnflattenProc = &SkUnflattenObjectProc<SkPaint>;
}
-
- SkFlatData* writableFlatData(int index) {
- return const_cast<SkFlatData*>((*this)[index]);
- }
};
class SkRegionDictionary : public SkFlatDictionary<SkRegion> {
topbot[1] = bounds.fBottom;
}
-void SkPictureRecord::addFontMetricsTopBottom(const SkPaint& paint, int index,
+void SkPictureRecord::addFontMetricsTopBottom(const SkPaint& paint, const SkFlatData& flat,
SkScalar minY, SkScalar maxY) {
- SkFlatData* flat = fPaints.writableFlatData(index);
if (!flat->isTopBotWritten()) {
computeFontMetricsTopBottom(paint, flat->writableTopBot());
SkASSERT(flat->isTopBotWritten());
bool fast = !paint.isVerticalText() && paint.canComputeFastBounds();
addDraw(fast ? DRAW_TEXT_TOP_BOTTOM : DRAW_TEXT);
- int paintIndex = addPaint(paint);
+ const SkFlatData* flatPaintData = addPaint(paint);
+ SkASSERT(flatPaintData);
addText(text, byteLength);
addScalar(x);
addScalar(y);
if (fast) {
- addFontMetricsTopBottom(paint, paintIndex - 1, y, y);
+ addFontMetricsTopBottom(paint, *flatPaintData, y, y);
}
validate();
}
} else {
addDraw(DRAW_POS_TEXT);
}
- int paintIndex = addPaint(paint);
+ const SkFlatData* flatPaintData = addPaint(paint);
+ SkASSERT(flatPaintData);
addText(text, byteLength);
addInt(points);
#endif
if (canUseDrawH) {
if (fast) {
- addFontMetricsTopBottom(paint, paintIndex - 1, pos[0].fY, pos[0].fY);
+ addFontMetricsTopBottom(paint, *flatPaintData, pos[0].fY, pos[0].fY);
}
addScalar(pos[0].fY);
SkScalar* xptr = (SkScalar*)fWriter.reserve(points * sizeof(SkScalar));
else {
fWriter.writeMul4(pos, points * sizeof(SkPoint));
if (fastBounds) {
- addFontMetricsTopBottom(paint, paintIndex - 1, minY, maxY);
+ addFontMetricsTopBottom(paint, *flatPaintData, minY, maxY);
}
}
#ifdef SK_DEBUG_SIZE
bool fast = !paint.isVerticalText() && paint.canComputeFastBounds();
addDraw(fast ? DRAW_POS_TEXT_H_TOP_BOTTOM : DRAW_POS_TEXT_H);
- int paintIndex = this->addPaint(paint);
+ const SkFlatData* flatPaintData = addPaint(paint);
+ SkASSERT(flatPaintData);
addText(text, byteLength);
addInt(points);
size_t start = fWriter.size();
#endif
if (fast) {
- addFontMetricsTopBottom(paint, paintIndex - 1, constY, constY);
+ addFontMetricsTopBottom(paint, *flatPaintData, constY, constY);
}
addScalar(constY);
fWriter.writeMul4(xpos, points * sizeof(SkScalar));
this->addInt(matrix ? fMatrices.find(*matrix) : 0);
}
-int SkPictureRecord::addPaintPtr(const SkPaint* paint) {
- int index = paint ? fPaints.find(*paint) : 0;
+const SkFlatData* SkPictureRecord::addPaintPtr(const SkPaint* paint) {
+ const SkFlatData* data = paint ? fPaints.findAndReturnFlat(*paint) : NULL;
+ int index = data ? data->index() : 0;
this->addInt(index);
- return index;
+ return data;
}
void SkPictureRecord::addPath(const SkPath& path) {
}
}
#endif
-
virtual void drawData(const void*, size_t) SK_OVERRIDE;
virtual bool isDrawingToLayer() const SK_OVERRIDE;
- void addFontMetricsTopBottom(const SkPaint& paint, int paintIndex,
+ void addFontMetricsTopBottom(const SkPaint& paint, const SkFlatData*,
SkScalar minY, SkScalar maxY);
const SkTDArray<SkPicture* >& getPictureRefs() const {
void addBitmap(const SkBitmap& bitmap);
void addMatrix(const SkMatrix& matrix);
void addMatrixPtr(const SkMatrix* matrix);
- int addPaint(const SkPaint& paint) { return this->addPaintPtr(&paint); }
- int addPaintPtr(const SkPaint* paint);
+ const SkFlatData* addPaint(const SkPaint& paint) { return this->addPaintPtr(&paint); }
+ const SkFlatData* addPaintPtr(const SkPaint* paint);
void addPath(const SkPath& path);
void addPicture(SkPicture& picture);
void addPoint(const SkPoint& point);