Cleaning up SkPicture-related classes

R=mtklein@google.com

Author: robertphillips@google.com

Review URL: https://codereview.chromium.org/459043002
This commit is contained in:
robertphillips 2014-08-11 09:50:11 -07:00 committed by Commit bot
parent addf2edf3d
commit 6162af8d4c
6 changed files with 1 additions and 898 deletions

View File

@ -44,70 +44,6 @@ template <typename T> int SafeCount(const T* obj) {
return obj ? obj->count() : 0;
}
#define DUMP_BUFFER_SIZE 65536
#ifdef SK_DEBUG
// enable SK_DEBUG_TRACE to trace DrawType elements when
// recorded and played back
// #define SK_DEBUG_TRACE
// enable SK_DEBUG_SIZE to see the size of picture components
// #define SK_DEBUG_SIZE
// enable SK_DEBUG_DUMP to see the contents of recorded elements
// #define SK_DEBUG_DUMP
// enable SK_DEBUG_VALIDATE to check internal structures for consistency
// #define SK_DEBUG_VALIDATE
#endif
#if defined SK_DEBUG_TRACE || defined SK_DEBUG_DUMP
const char* DrawTypeToString(DrawType drawType) {
switch (drawType) {
case UNUSED: SkDebugf("DrawType UNUSED\n"); SkASSERT(0); break;
case CLIP_PATH: return "CLIP_PATH";
case CLIP_REGION: return "CLIP_REGION";
case CLIP_RECT: return "CLIP_RECT";
case CLIP_RRECT: return "CLIP_RRECT";
case CONCAT: return "CONCAT";
case DRAW_BITMAP: return "DRAW_BITMAP";
case DRAW_BITMAP_MATRIX: return "DRAW_BITMAP_MATRIX";
case DRAW_BITMAP_NINE: return "DRAW_BITMAP_NINE";
case DRAW_BITMAP_RECT_TO_RECT: return "DRAW_BITMAP_RECT_TO_RECT";
case DRAW_CLEAR: return "DRAW_CLEAR";
case DRAW_DATA: return "DRAW_DATA";
case DRAW_OVAL: return "DRAW_OVAL";
case DRAW_PAINT: return "DRAW_PAINT";
case DRAW_PATH: return "DRAW_PATH";
case DRAW_PICTURE: return "DRAW_PICTURE";
case DRAW_POINTS: return "DRAW_POINTS";
case DRAW_POS_TEXT: return "DRAW_POS_TEXT";
case DRAW_POS_TEXT_TOP_BOTTOM: return "DRAW_POS_TEXT_TOP_BOTTOM";
case DRAW_POS_TEXT_H: return "DRAW_POS_TEXT_H";
case DRAW_POS_TEXT_H_TOP_BOTTOM: return "DRAW_POS_TEXT_H_TOP_BOTTOM";
case DRAW_RECT: return "DRAW_RECT";
case DRAW_RRECT: return "DRAW_RRECT";
case DRAW_SPRITE: return "DRAW_SPRITE";
case DRAW_TEXT: return "DRAW_TEXT";
case DRAW_TEXT_ON_PATH: return "DRAW_TEXT_ON_PATH";
case DRAW_TEXT_TOP_BOTTOM: return "DRAW_TEXT_TOP_BOTTOM";
case DRAW_VERTICES: return "DRAW_VERTICES";
case RESTORE: return "RESTORE";
case ROTATE: return "ROTATE";
case SAVE: return "SAVE";
case SAVE_LAYER: return "SAVE_LAYER";
case SCALE: return "SCALE";
case SET_MATRIX: return "SET_MATRIX";
case SKEW: return "SKEW";
case TRANSLATE: return "TRANSLATE";
case NOOP: return "NOOP";
default:
SkDebugf("DrawType error 0x%08x\n", drawType);
SkASSERT(0);
break;
}
SkASSERT(0);
return NULL;
}
#endif
///////////////////////////////////////////////////////////////////////////////
#ifdef SK_SUPPORT_LEGACY_DEFAULT_PICTURE_CTOR

View File

@ -40,42 +40,6 @@ SkPictureData::SkPictureData(const SkPictureRecord& record,
const SkPictInfo& info,
bool deepCopyOps)
: fInfo(info) {
#ifdef SK_DEBUG_SIZE
size_t overallBytes, bitmapBytes, matricesBytes,
paintBytes, pathBytes, pictureBytes, regionBytes;
int bitmaps = record.bitmaps(&bitmapBytes);
int matrices = record.matrices(&matricesBytes);
int paints = record.paints(&paintBytes);
int paths = record.paths(&pathBytes);
int pictures = record.pictures(&pictureBytes);
int regions = record.regions(&regionBytes);
SkDebugf("picture record mem used %zd (stream %zd) ", record.size(),
record.streamlen());
if (bitmaps != 0)
SkDebugf("bitmaps size %zd (bitmaps:%d) ", bitmapBytes, bitmaps);
if (matrices != 0)
SkDebugf("matrices size %zd (matrices:%d) ", matricesBytes, matrices);
if (paints != 0)
SkDebugf("paints size %zd (paints:%d) ", paintBytes, paints);
if (paths != 0)
SkDebugf("paths size %zd (paths:%d) ", pathBytes, paths);
if (pictures != 0)
SkDebugf("pictures size %zd (pictures:%d) ", pictureBytes, pictures);
if (regions != 0)
SkDebugf("regions size %zd (regions:%d) ", regionBytes, regions);
if (record.fPointWrites != 0)
SkDebugf("points size %zd (points:%d) ", record.fPointBytes, record.fPointWrites);
if (record.fRectWrites != 0)
SkDebugf("rects size %zd (rects:%d) ", record.fRectBytes, record.fRectWrites);
if (record.fTextWrites != 0)
SkDebugf("text size %zd (text strings:%d) ", record.fTextBytes, record.fTextWrites);
SkDebugf("\n");
#endif
#ifdef SK_DEBUG_DUMP
record.dumpMatrices();
record.dumpPaints();
#endif
this->init();
@ -112,27 +76,6 @@ SkPictureData::SkPictureData(const SkPictureRecord& record,
fPictureRefs[i]->ref();
}
}
#ifdef SK_DEBUG_SIZE
int overall = fPlayback->size(&overallBytes);
bitmaps = fPlayback->bitmaps(&bitmapBytes);
paints = fPlayback->paints(&paintBytes);
paths = fPlayback->paths(&pathBytes);
pictures = fPlayback->pictures(&pictureBytes);
regions = fPlayback->regions(&regionBytes);
SkDebugf("playback size %zd (objects:%d) ", overallBytes, overall);
if (bitmaps != 0)
SkDebugf("bitmaps size %zd (bitmaps:%d) ", bitmapBytes, bitmaps);
if (paints != 0)
SkDebugf("paints size %zd (paints:%d) ", paintBytes, paints);
if (paths != 0)
SkDebugf("paths size %zd (paths:%d) ", pathBytes, paths);
if (pictures != 0)
SkDebugf("pictures size %zd (pictures:%d) ", pictureBytes, pictures);
if (regions != 0)
SkDebugf("regions size %zd (regions:%d) ", regionBytes, regions);
SkDebugf("\n");
#endif
}
#ifdef SK_SUPPORT_LEGACY_PICTURE_CLONE
@ -218,15 +161,6 @@ SkPictureData::~SkPictureData() {
SkDELETE(fFactoryPlayback);
}
void SkPictureData::dumpSize() const {
SkDebugf("--- picture size: ops=%d bitmaps=%d [%d] paints=%d [%d]\n",
fOpData->size(),
SafeCount(fBitmaps), SafeCount(fBitmaps) * sizeof(SkBitmap),
SafeCount(fPaints), SafeCount(fPaints) * sizeof(SkPaint));
SkDebugf("--- picture size: paths=%d\n",
SafeCount(fPathHeap.get()));
}
bool SkPictureData::containsBitmaps() const {
if (fBitmaps && fBitmaps->count() > 0) {
return true;
@ -287,7 +221,6 @@ void SkPictureData::WriteFactories(SkWStream* stream, const SkFactorySet& rec) {
for (int i = 0; i < count; i++) {
const char* name = SkFlattenable::FactoryToName(array[i]);
// SkDebugf("---- write factories [%d] %p <%s>\n", i, array[i], name);
if (NULL == name || 0 == *name) {
stream->writePackedUInt(0);
} else {
@ -687,511 +620,4 @@ bool SkPictureData::suitableForGpuRasterization(GrContext* context, const char *
#endif
///////////////////////////////////////////////////////////////////////////////
#ifdef SK_DEBUG_SIZE
int SkPictureData::size(size_t* sizePtr) {
int objects = bitmaps(sizePtr);
objects += paints(sizePtr);
objects += paths(sizePtr);
objects += pictures(sizePtr);
objects += regions(sizePtr);
*sizePtr = fOpData.size();
return objects;
}
int SkPictureData::bitmaps(size_t* size) {
size_t result = 0;
for (int index = 0; index < fBitmapCount; index++) {
// const SkBitmap& bitmap = fBitmaps[index];
result += sizeof(SkBitmap); // bitmap->size();
}
*size = result;
return fBitmapCount;
}
int SkPictureData::paints(size_t* size) {
size_t result = 0;
for (int index = 0; index < fPaintCount; index++) {
// const SkPaint& paint = fPaints[index];
result += sizeof(SkPaint); // paint->size();
}
*size = result;
return fPaintCount;
}
int SkPictureData::paths(size_t* size) {
size_t result = 0;
for (int index = 0; index < fPathCount; index++) {
const SkPath& path = fPaths[index];
result += path.flatten(NULL);
}
*size = result;
return fPathCount;
}
#endif
#ifdef SK_DEBUG_DUMP
void SkPictureData::dumpBitmap(const SkBitmap& bitmap) const {
char pBuffer[DUMP_BUFFER_SIZE];
char* bufferPtr = pBuffer;
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"BitmapData bitmap%p = {", &bitmap);
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kWidth, %d}, ", bitmap.width());
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kHeight, %d}, ", bitmap.height());
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kRowBytes, %d}, ", bitmap.rowBytes());
// start here;
SkDebugf("%s{0}};\n", pBuffer);
}
void dumpMatrix(const SkMatrix& matrix) const {
SkMatrix defaultMatrix;
defaultMatrix.reset();
char pBuffer[DUMP_BUFFER_SIZE];
char* bufferPtr = pBuffer;
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"MatrixData matrix%p = {", &matrix);
SkScalar scaleX = matrix.getScaleX();
if (scaleX != defaultMatrix.getScaleX())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kScaleX, %g}, ", SkScalarToFloat(scaleX));
SkScalar scaleY = matrix.getScaleY();
if (scaleY != defaultMatrix.getScaleY())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kScaleY, %g}, ", SkScalarToFloat(scaleY));
SkScalar skewX = matrix.getSkewX();
if (skewX != defaultMatrix.getSkewX())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kSkewX, %g}, ", SkScalarToFloat(skewX));
SkScalar skewY = matrix.getSkewY();
if (skewY != defaultMatrix.getSkewY())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kSkewY, %g}, ", SkScalarToFloat(skewY));
SkScalar translateX = matrix.getTranslateX();
if (translateX != defaultMatrix.getTranslateX())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kTranslateX, %g}, ", SkScalarToFloat(translateX));
SkScalar translateY = matrix.getTranslateY();
if (translateY != defaultMatrix.getTranslateY())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kTranslateY, %g}, ", SkScalarToFloat(translateY));
SkScalar perspX = matrix.getPerspX();
if (perspX != defaultMatrix.getPerspX())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kPerspX, %g}, ", perspX);
SkScalar perspY = matrix.getPerspY();
if (perspY != defaultMatrix.getPerspY())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kPerspY, %g}, ", perspY);
SkDebugf("%s{0}};\n", pBuffer);
}
void dumpPaint(const SkPaint& paint) const {
SkPaint defaultPaint;
char pBuffer[DUMP_BUFFER_SIZE];
char* bufferPtr = pBuffer;
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"PaintPointers paintPtrs%p = {", &paint);
const SkTypeface* typeface = paint.getTypeface();
if (typeface != defaultPaint.getTypeface())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kTypeface, %p}, ", typeface);
const SkPathEffect* pathEffect = paint.getPathEffect();
if (pathEffect != defaultPaint.getPathEffect())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kPathEffect, %p}, ", pathEffect);
const SkShader* shader = paint.getShader();
if (shader != defaultPaint.getShader())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kShader, %p}, ", shader);
const SkXfermode* xfermode = paint.getXfermode();
if (xfermode != defaultPaint.getXfermode())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kXfermode, %p}, ", xfermode);
const SkMaskFilter* maskFilter = paint.getMaskFilter();
if (maskFilter != defaultPaint.getMaskFilter())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kMaskFilter, %p}, ", maskFilter);
const SkColorFilter* colorFilter = paint.getColorFilter();
if (colorFilter != defaultPaint.getColorFilter())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kColorFilter, %p}, ", colorFilter);
const SkRasterizer* rasterizer = paint.getRasterizer();
if (rasterizer != defaultPaint.getRasterizer())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kRasterizer, %p}, ", rasterizer);
const SkDrawLooper* drawLooper = paint.getLooper();
if (drawLooper != defaultPaint.getLooper())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kDrawLooper, %p}, ", drawLooper);
SkDebugf("%s{0}};\n", pBuffer);
bufferPtr = pBuffer;
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"PaintScalars paintScalars%p = {", &paint);
SkScalar textSize = paint.getTextSize();
if (textSize != defaultPaint.getTextSize())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kTextSize, %g}, ", SkScalarToFloat(textSize));
SkScalar textScaleX = paint.getTextScaleX();
if (textScaleX != defaultPaint.getTextScaleX())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kTextScaleX, %g}, ", SkScalarToFloat(textScaleX));
SkScalar textSkewX = paint.getTextSkewX();
if (textSkewX != defaultPaint.getTextSkewX())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kTextSkewX, %g}, ", SkScalarToFloat(textSkewX));
SkScalar strokeWidth = paint.getStrokeWidth();
if (strokeWidth != defaultPaint.getStrokeWidth())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kStrokeWidth, %g}, ", SkScalarToFloat(strokeWidth));
SkScalar strokeMiter = paint.getStrokeMiter();
if (strokeMiter != defaultPaint.getStrokeMiter())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kStrokeMiter, %g}, ", SkScalarToFloat(strokeMiter));
SkDebugf("%s{0}};\n", pBuffer);
bufferPtr = pBuffer;
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"PaintInts = paintInts%p = {", &paint);
unsigned color = paint.getColor();
if (color != defaultPaint.getColor())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kColor, 0x%x}, ", color);
unsigned flags = paint.getFlags();
if (flags != defaultPaint.getFlags())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kFlags, 0x%x}, ", flags);
int align = paint.getTextAlign();
if (align != defaultPaint.getTextAlign())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kAlign, 0x%x}, ", align);
int strokeCap = paint.getStrokeCap();
if (strokeCap != defaultPaint.getStrokeCap())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kStrokeCap, 0x%x}, ", strokeCap);
int strokeJoin = paint.getStrokeJoin();
if (strokeJoin != defaultPaint.getStrokeJoin())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kAlign, 0x%x}, ", strokeJoin);
int style = paint.getStyle();
if (style != defaultPaint.getStyle())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kStyle, 0x%x}, ", style);
int textEncoding = paint.getTextEncoding();
if (textEncoding != defaultPaint.getTextEncoding())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"{kTextEncoding, 0x%x}, ", textEncoding);
SkDebugf("%s{0}};\n", pBuffer);
SkDebugf("PaintData paint%p = {paintPtrs%p, paintScalars%p, paintInts%p};\n",
&paint, &paint, &paint, &paint);
}
void SkPictureData::dumpPath(const SkPath& path) const {
SkDebugf("path dump unimplemented\n");
}
void SkPictureData::dumpPicture(const SkPicture& picture) const {
SkDebugf("picture dump unimplemented\n");
}
void SkPictureData::dumpRegion(const SkRegion& region) const {
SkDebugf("region dump unimplemented\n");
}
int SkPictureData::dumpDrawType(char* bufferPtr, char* buffer, DrawType drawType) {
return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
"k%s, ", DrawTypeToString(drawType));
}
int SkPictureData::dumpInt(char* bufferPtr, char* buffer, char* name) {
return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
"%s:%d, ", name, getInt());
}
int SkPictureData::dumpRect(char* bufferPtr, char* buffer, char* name) {
const SkRect* rect = fReader.skipRect();
return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
"%s:{l:%g t:%g r:%g b:%g}, ", name, SkScalarToFloat(rect.fLeft),
SkScalarToFloat(rect.fTop),
SkScalarToFloat(rect.fRight), SkScalarToFloat(rect.fBottom));
}
int SkPictureData::dumpPoint(char* bufferPtr, char* buffer, char* name) {
SkPoint pt;
getPoint(&pt);
return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
"%s:{x:%g y:%g}, ", name, SkScalarToFloat(pt.fX),
SkScalarToFloat(pt.fY));
}
void SkPictureData::dumpPointArray(char** bufferPtrPtr, char* buffer, int count) {
char* bufferPtr = *bufferPtrPtr;
const SkPoint* pts = (const SkPoint*)fReadStream.getAtPos();
fReadStream.skip(sizeof(SkPoint) * count);
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
"count:%d {", count);
for (int index = 0; index < count; index++)
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
"{x:%g y:%g}, ", SkScalarToFloat(pts[index].fX),
SkScalarToFloat(pts[index].fY));
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
"} ");
*bufferPtrPtr = bufferPtr;
}
int SkPictureData::dumpPtr(char* bufferPtr, char* buffer, char* name, void* ptr) {
return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
"%s:%p, ", name, ptr);
}
int SkPictureData::dumpRectPtr(char* bufferPtr, char* buffer, char* name) {
char result;
fReadStream.read(&result, sizeof(result));
if (result)
return dumpRect(bufferPtr, buffer, name);
else
return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
"%s:NULL, ", name);
}
int SkPictureData::dumpScalar(char* bufferPtr, char* buffer, char* name) {
return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
"%s:%d, ", name, getScalar());
}
void SkPictureData::dumpText(char** bufferPtrPtr, char* buffer) {
char* bufferPtr = *bufferPtrPtr;
int length = getInt();
bufferPtr += dumpDrawType(bufferPtr, buffer);
fReadStream.skipToAlign4();
char* text = (char*) fReadStream.getAtPos();
fReadStream.skip(length);
bufferPtr += dumpInt(bufferPtr, buffer, "length");
int limit = DUMP_BUFFER_SIZE - (bufferPtr - buffer) - 2;
length >>= 1;
if (limit > length)
limit = length;
if (limit > 0) {
*bufferPtr++ = '"';
for (int index = 0; index < limit; index++) {
*bufferPtr++ = *(unsigned short*) text;
text += sizeof(unsigned short);
}
*bufferPtr++ = '"';
}
*bufferPtrPtr = bufferPtr;
}
#define DUMP_DRAWTYPE(drawType) \
bufferPtr += dumpDrawType(bufferPtr, buffer, drawType)
#define DUMP_INT(name) \
bufferPtr += dumpInt(bufferPtr, buffer, #name)
#define DUMP_RECT_PTR(name) \
bufferPtr += dumpRectPtr(bufferPtr, buffer, #name)
#define DUMP_POINT(name) \
bufferPtr += dumpRect(bufferPtr, buffer, #name)
#define DUMP_RECT(name) \
bufferPtr += dumpRect(bufferPtr, buffer, #name)
#define DUMP_POINT_ARRAY(count) \
dumpPointArray(&bufferPtr, buffer, count)
#define DUMP_PTR(name, ptr) \
bufferPtr += dumpPtr(bufferPtr, buffer, #name, (void*) ptr)
#define DUMP_SCALAR(name) \
bufferPtr += dumpScalar(bufferPtr, buffer, #name)
#define DUMP_TEXT() \
dumpText(&bufferPtr, buffer)
void SkPictureData::dumpStream() {
SkDebugf("RecordStream stream = {\n");
DrawType drawType;
fReadStream.rewind();
char buffer[DUMP_BUFFER_SIZE], * bufferPtr;
while (fReadStream.read(&drawType, sizeof(drawType))) {
bufferPtr = buffer;
DUMP_DRAWTYPE(drawType);
switch (drawType) {
case CLIP_PATH: {
DUMP_PTR(SkPath, &getPath());
DUMP_INT(SkRegion::Op);
DUMP_INT(offsetToRestore);
} break;
case CLIP_REGION: {
DUMP_INT(SkRegion::Op);
DUMP_INT(offsetToRestore);
} break;
case CLIP_RECT: {
DUMP_RECT(rect);
DUMP_INT(SkRegion::Op);
DUMP_INT(offsetToRestore);
} break;
case CONCAT:
break;
case DRAW_BITMAP: {
DUMP_PTR(SkPaint, getPaint());
DUMP_PTR(SkBitmap, &getBitmap());
DUMP_SCALAR(left);
DUMP_SCALAR(top);
} break;
case DRAW_PAINT:
DUMP_PTR(SkPaint, getPaint());
break;
case DRAW_PATH: {
DUMP_PTR(SkPaint, getPaint());
DUMP_PTR(SkPath, &getPath());
} break;
case DRAW_PICTURE: {
DUMP_PTR(SkPicture, &getPicture());
} break;
case DRAW_POINTS: {
DUMP_PTR(SkPaint, getPaint());
(void)getInt(); // PointMode
size_t count = getInt();
fReadStream.skipToAlign4();
DUMP_POINT_ARRAY(count);
} break;
case DRAW_POS_TEXT: {
DUMP_PTR(SkPaint, getPaint());
DUMP_TEXT();
size_t points = getInt();
fReadStream.skipToAlign4();
DUMP_POINT_ARRAY(points);
} break;
case DRAW_POS_TEXT_H: {
DUMP_PTR(SkPaint, getPaint());
DUMP_TEXT();
size_t points = getInt();
fReadStream.skipToAlign4();
DUMP_SCALAR(top);
DUMP_SCALAR(bottom);
DUMP_SCALAR(constY);
DUMP_POINT_ARRAY(points);
} break;
case DRAW_RECT: {
DUMP_PTR(SkPaint, getPaint());
DUMP_RECT(rect);
} break;
case DRAW_SPRITE: {
DUMP_PTR(SkPaint, getPaint());
DUMP_PTR(SkBitmap, &getBitmap());
DUMP_SCALAR(left);
DUMP_SCALAR(top);
} break;
case DRAW_TEXT: {
DUMP_PTR(SkPaint, getPaint());
DUMP_TEXT();
DUMP_SCALAR(x);
DUMP_SCALAR(y);
} break;
case DRAW_TEXT_ON_PATH: {
DUMP_PTR(SkPaint, getPaint());
DUMP_TEXT();
DUMP_PTR(SkPath, &getPath());
} break;
case RESTORE:
break;
case ROTATE:
DUMP_SCALAR(rotate);
break;
case SAVE:
DUMP_INT(SkCanvas::SaveFlags);
break;
case SAVE_LAYER: {
DUMP_RECT_PTR(layer);
DUMP_PTR(SkPaint, getPaint());
DUMP_INT(SkCanvas::SaveFlags);
} break;
case SCALE: {
DUMP_SCALAR(sx);
DUMP_SCALAR(sy);
} break;
case SKEW: {
DUMP_SCALAR(sx);
DUMP_SCALAR(sy);
} break;
case TRANSLATE: {
DUMP_SCALAR(dx);
DUMP_SCALAR(dy);
} break;
default:
SkASSERT(0);
}
SkDebugf("%s\n", buffer);
}
}
void SkPictureData::dump() const {
char pBuffer[DUMP_BUFFER_SIZE];
char* bufferPtr = pBuffer;
int index;
if (fBitmapCount > 0)
SkDebugf("// bitmaps (%d)\n", fBitmapCount);
for (index = 0; index < fBitmapCount; index++) {
const SkBitmap& bitmap = fBitmaps[index];
dumpBitmap(bitmap);
}
if (fBitmapCount > 0)
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"Bitmaps bitmaps = {");
for (index = 0; index < fBitmapCount; index++)
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"bitmap%p, ", &fBitmaps[index]);
if (fBitmapCount > 0)
SkDebugf("%s0};\n", pBuffer);
if (fPaintCount > 0)
SkDebugf("// paints (%d)\n", fPaintCount);
for (index = 0; index < fPaintCount; index++) {
const SkPaint& paint = fPaints[index];
dumpPaint(paint);
}
bufferPtr = pBuffer;
if (fPaintCount > 0)
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"Paints paints = {");
for (index = 0; index < fPaintCount; index++)
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"paint%p, ", &fPaints[index]);
if (fPaintCount > 0)
SkDebugf("%s0};\n", pBuffer);
for (index = 0; index < fPathCount; index++) {
const SkPath& path = fPaths[index];
dumpPath(path);
}
bufferPtr = pBuffer;
if (fPathCount > 0)
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"Paths paths = {");
for (index = 0; index < fPathCount; index++)
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"path%p, ", &fPaths[index]);
if (fPathCount > 0)
SkDebugf("%s0};\n", pBuffer);
for (index = 0; index < fPictureCount; index++) {
dumpPicture(*fPictureRefs[index]);
}
bufferPtr = pBuffer;
if (fPictureCount > 0)
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"Pictures pictures = {");
for (index = 0; index < fPictureCount; index++)
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"picture%p, ", fPictureRefs[index]);
if (fPictureCount > 0)
SkDebugf("%s0};\n", pBuffer);
const_cast<SkPictureData*>(this)->dumpStream();
}
#endif

View File

@ -87,8 +87,6 @@ public:
void serialize(SkWStream*, SkPicture::EncodeBitmap) const;
void flatten(SkWriteBuffer&) const;
void dumpSize() const;
bool containsBitmaps() const;
const SkData* opData() const { return fOpData; }
@ -138,36 +136,6 @@ public:
}
}
#ifdef SK_DEBUG_SIZE
int size(size_t* sizePtr);
int bitmaps(size_t* size);
int paints(size_t* size);
int paths(size_t* size);
#endif
#ifdef SK_DEBUG_DUMP
private:
void dumpBitmap(const SkBitmap& bitmap) const;
void dumpMatrix(const SkMatrix& matrix) const;
void dumpPaint(const SkPaint& paint) const;
void dumpPath(const SkPath& path) const;
void dumpPicture(const SkPicture& picture) const;
void dumpRegion(const SkRegion& region) const;
int dumpDrawType(char* bufferPtr, char* buffer, DrawType drawType);
int dumpInt(char* bufferPtr, char* buffer, char* name);
int dumpRect(char* bufferPtr, char* buffer, char* name);
int dumpPoint(char* bufferPtr, char* buffer, char* name);
void dumpPointArray(char** bufferPtrPtr, char* buffer, int count);
int dumpPtr(char* bufferPtr, char* buffer, char* name, void* ptr);
int dumpRectPtr(char* bufferPtr, char* buffer, char* name);
int dumpScalar(char* bufferPtr, char* buffer, char* name);
void dumpText(char** bufferPtrPtr, char* buffer);
void dumpStream();
public:
void dump() const;
#endif
#if SK_SUPPORT_GPU
/**
* sampleCount is the number of samples-per-pixel or zero if non-MSAA.

View File

@ -8,7 +8,6 @@
#ifndef SkPictureFlat_DEFINED
#define SkPictureFlat_DEFINED
//#define SK_DEBUG_SIZE
#include "SkBitmapHeap.h"
#include "SkChecksum.h"

View File

@ -44,10 +44,6 @@ SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags)
, fPaints(&fFlattenableHeap)
, fRecordFlags(flags)
, fOptsEnabled(kBeClever) {
#ifdef SK_DEBUG_SIZE
fPointBytes = fRectBytes = fTextBytes = 0;
fPointWrites = fRectWrites = fTextWrites = 0;
#endif
fBitmapHeap = SkNEW(SkBitmapHeap);
fFlattenableHeap.setBitmapStorage(fBitmapHeap);
@ -230,10 +226,6 @@ static DrawType peek_op_and_size(SkWriter32* writer, size_t offset, uint32_t* si
return (DrawType) op;
}
#ifdef TRACK_COLLAPSE_STATS
static int gCollapseCount, gCollapseCalls;
#endif
// Is the supplied paint simply a color?
static bool is_simple(const SkPaint& p) {
intptr_t orAccum = (intptr_t)p.getPathEffect() |
@ -472,10 +464,6 @@ static bool is_drawing_op(DrawType op) {
*/
static bool collapse_save_clip_restore(SkWriter32* writer, int32_t offset,
SkPaintDictionary* paintDict) {
#ifdef TRACK_COLLAPSE_STATS
gCollapseCalls += 1;
#endif
int32_t restoreOffset = (int32_t)writer->bytesWritten();
// back up to the save block
@ -508,12 +496,6 @@ static bool collapse_save_clip_restore(SkWriter32* writer, int32_t offset,
offset += opSize;
}
#ifdef TRACK_COLLAPSE_STATS
gCollapseCount += 1;
SkDebugf("Collapse [%d out of %d] %g%spn", gCollapseCount, gCollapseCalls,
(double)gCollapseCount / gCollapseCalls, "%");
#endif
writer->rewindToOffset(saveOffset);
return true;
}
@ -1134,9 +1116,6 @@ void SkPictureRecord::onDrawPosText(const void* text, size_t byteLength, const S
this->addText(text, byteLength);
this->addInt(points);
#ifdef SK_DEBUG_SIZE
size_t start = fWriter.bytesWritten();
#endif
if (canUseDrawH) {
if (fast) {
this->addFontMetricsTopBottom(paint, *flatPaintData, pos[0].fY, pos[0].fY);
@ -1151,10 +1130,6 @@ void SkPictureRecord::onDrawPosText(const void* text, size_t byteLength, const S
this->addFontMetricsTopBottom(paint, *flatPaintData, minY, maxY);
}
}
#ifdef SK_DEBUG_SIZE
fPointBytes += fWriter.bytesWritten() - start;
fPointWrites += points;
#endif
this->validate(initialOffset, size);
}
@ -1189,18 +1164,11 @@ void SkPictureRecord::drawPosTextHImpl(const void* text, size_t byteLength,
this->addText(text, byteLength);
this->addInt(points);
#ifdef SK_DEBUG_SIZE
size_t start = fWriter.bytesWritten();
#endif
if (fast) {
this->addFontMetricsTopBottom(paint, *flatPaintData, constY, constY);
}
this->addScalar(constY);
fWriter.writeMul4(xpos, points * sizeof(SkScalar));
#ifdef SK_DEBUG_SIZE
fPointBytes += fWriter.bytesWritten() - start;
fPointWrites += points;
#endif
this->validate(initialOffset, size);
}
@ -1454,22 +1422,11 @@ void SkPictureRecord::addPicture(const SkPicture* picture) {
}
void SkPictureRecord::addPoint(const SkPoint& point) {
#ifdef SK_DEBUG_SIZE
size_t start = fWriter.bytesWritten();
#endif
fWriter.writePoint(point);
#ifdef SK_DEBUG_SIZE
fPointBytes += fWriter.bytesWritten() - start;
fPointWrites++;
#endif
}
void SkPictureRecord::addPoints(const SkPoint pts[], int count) {
fWriter.writeMul4(pts, count * sizeof(SkPoint));
#ifdef SK_DEBUG_SIZE
fPointBytes += count * sizeof(SkPoint);
fPointWrites++;
#endif
}
void SkPictureRecord::addNoOp() {
@ -1478,14 +1435,7 @@ void SkPictureRecord::addNoOp() {
}
void SkPictureRecord::addRect(const SkRect& rect) {
#ifdef SK_DEBUG_SIZE
size_t start = fWriter.bytesWritten();
#endif
fWriter.writeRect(rect);
#ifdef SK_DEBUG_SIZE
fRectBytes += fWriter.bytesWritten() - start;
fRectWrites++;
#endif
}
void SkPictureRecord::addRectPtr(const SkRect* rect) {
@ -1514,147 +1464,9 @@ void SkPictureRecord::addRegion(const SkRegion& region) {
void SkPictureRecord::addText(const void* text, size_t byteLength) {
fContentInfo.onDrawText();
#ifdef SK_DEBUG_SIZE
size_t start = fWriter.bytesWritten();
#endif
addInt(SkToInt(byteLength));
fWriter.writePad(text, byteLength);
#ifdef SK_DEBUG_SIZE
fTextBytes += fWriter.bytesWritten() - start;
fTextWrites++;
#endif
}
///////////////////////////////////////////////////////////////////////////////
#ifdef SK_DEBUG_SIZE
size_t SkPictureRecord::size() const {
size_t result = 0;
size_t sizeData;
bitmaps(&sizeData);
result += sizeData;
matrices(&sizeData);
result += sizeData;
paints(&sizeData);
result += sizeData;
paths(&sizeData);
result += sizeData;
pictures(&sizeData);
result += sizeData;
regions(&sizeData);
result += sizeData;
result += streamlen();
return result;
}
int SkPictureRecord::bitmaps(size_t* size) const {
size_t result = 0;
int count = fBitmaps.count();
for (int index = 0; index < count; index++)
result += sizeof(fBitmaps[index]) + fBitmaps[index]->size();
*size = result;
return count;
}
int SkPictureRecord::matrices(size_t* size) const {
int count = fMatrices.count();
*size = sizeof(fMatrices[0]) * count;
return count;
}
int SkPictureRecord::paints(size_t* size) const {
size_t result = 0;
int count = fPaints.count();
for (int index = 0; index < count; index++)
result += sizeof(fPaints[index]) + fPaints[index]->size();
*size = result;
return count;
}
int SkPictureRecord::paths(size_t* size) const {
size_t result = 0;
int count = fPaths.count();
for (int index = 0; index < count; index++)
result += sizeof(fPaths[index]) + fPaths[index]->size();
*size = result;
return count;
}
int SkPictureRecord::regions(size_t* size) const {
size_t result = 0;
int count = fRegions.count();
for (int index = 0; index < count; index++)
result += sizeof(fRegions[index]) + fRegions[index]->size();
*size = result;
return count;
}
size_t SkPictureRecord::streamlen() const {
return fWriter.size();
}
#endif
#ifdef SK_DEBUG_VALIDATE
void SkPictureRecord::validate(uint32_t initialOffset, uint32_t size) const {
SkASSERT(fWriter.size() == initialOffset + size);
validateBitmaps();
validateMatrices();
validatePaints();
validatePaths();
validateRegions();
}
void SkPictureRecord::validateBitmaps() const {
int count = fBitmapHeap->count();
SkASSERT((unsigned) count < 0x1000);
for (int index = 0; index < count; index++) {
const SkBitmap* bitPtr = fBitmapHeap->getBitmap(index);
SkASSERT(bitPtr);
bitPtr->validate();
}
}
void SkPictureRecord::validateMatrices() const {
int count = fMatrices.count();
SkASSERT((unsigned) count < 0x1000);
for (int index = 0; index < count; index++) {
const SkFlatData* matrix = fMatrices[index];
SkASSERT(matrix);
// matrix->validate();
}
}
void SkPictureRecord::validatePaints() const {
int count = fPaints.count();
SkASSERT((unsigned) count < 0x1000);
for (int index = 0; index < count; index++) {
const SkFlatData* paint = fPaints[index];
SkASSERT(paint);
// paint->validate();
}
}
void SkPictureRecord::validatePaths() const {
if (NULL == fPathHeap) {
return;
}
int count = fPathHeap->count();
SkASSERT((unsigned) count < 0x1000);
for (int index = 0; index < count; index++) {
const SkPath& path = (*fPathHeap)[index];
path.validate();
}
}
void SkPictureRecord::validateRegions() const {
int count = fRegions.count();
SkASSERT((unsigned) count < 0x1000);
for (int index = 0; index < count; index++) {
const SkFlatData* region = fRegions[index];
SkASSERT(region);
// region->validate();
}
}
#endif

View File

@ -143,10 +143,6 @@ private:
this->predrawNotify();
fContentInfo.addOperation();
#ifdef SK_DEBUG_TRACE
SkDebugf("add %s\n", DrawTypeToString(drawType));
#endif
SkASSERT(0 != *size);
SkASSERT(((uint8_t) drawType) == drawType);
@ -189,43 +185,11 @@ private:
int find(const SkBitmap& bitmap);
#ifdef SK_DEBUG_DUMP
public:
void dumpMatrices();
void dumpPaints();
#endif
#ifdef SK_DEBUG_SIZE
public:
size_t size() const;
int bitmaps(size_t* size) const;
int matrices(size_t* size) const;
int paints(size_t* size) const;
int paths(size_t* size) const;
int regions(size_t* size) const;
size_t streamlen() const;
size_t fPointBytes, fRectBytes, fTextBytes;
int fPointWrites, fRectWrites, fTextWrites;
#endif
#ifdef SK_DEBUG_VALIDATE
public:
void validate(size_t initialOffset, uint32_t size) const;
private:
void validateBitmaps() const;
void validateMatrices() const;
void validatePaints() const;
void validatePaths() const;
void validateRegions() const;
#else
public:
protected:
void validate(size_t initialOffset, size_t size) const {
SkASSERT(fWriter.bytesWritten() == initialOffset + size);
}
#endif
protected:
virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE;
const void* onPeekPixels(SkImageInfo*, size_t*) SK_OVERRIDE {
return NULL;
@ -304,8 +268,6 @@ protected:
SkBitmapHeap* fBitmapHeap;
private:
friend class MatrixClipState; // for access to *Impl methods
SkPictureContentInfo fContentInfo;
SkAutoTUnref<SkPathHeap> fPathHeap;