Move paints to the front of draw structs.
The order of arguments in these structs is arbitrary, so we might as well arrange them to optimize something. Putting the paints at the front means the logic to find the paint is a lot more concise: it's usually just ptr+0, or *(ptr+0) when the SkPaint is optional. This considerably reduces the size of the jump table in IsDraw::operator(). BUG=skia:2378 R=fmalita@chromium.org, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/272673002 git-svn-id: http://skia.googlecode.com/svn/trunk@14634 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
8fae213590
commit
37f6e62f11
@ -187,7 +187,7 @@ struct StrengthReducer {
|
||||
Adopted<DrawPosText> adopted(draw);
|
||||
SkNEW_PLACEMENT_ARGS(record->replace<DrawPosTextH>(begin, adopted),
|
||||
DrawPosTextH,
|
||||
(draw->text, draw->byteLength, scalars, firstY, draw->paint));
|
||||
(draw->paint, draw->text, draw->byteLength, scalars, firstY));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
@ -93,34 +93,34 @@ void SkRecorder::drawPoints(PointMode mode,
|
||||
size_t count,
|
||||
const SkPoint pts[],
|
||||
const SkPaint& paint) {
|
||||
APPEND(DrawPoints, mode, count, this->copy(pts, count), delay_copy(paint));
|
||||
APPEND(DrawPoints, delay_copy(paint), mode, count, this->copy(pts, count));
|
||||
}
|
||||
|
||||
void SkRecorder::drawRect(const SkRect& rect, const SkPaint& paint) {
|
||||
APPEND(DrawRect, rect, delay_copy(paint));
|
||||
APPEND(DrawRect, delay_copy(paint), rect);
|
||||
}
|
||||
|
||||
void SkRecorder::drawOval(const SkRect& oval, const SkPaint& paint) {
|
||||
APPEND(DrawOval, oval, delay_copy(paint));
|
||||
APPEND(DrawOval, delay_copy(paint), oval);
|
||||
}
|
||||
|
||||
void SkRecorder::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
|
||||
APPEND(DrawRRect, rrect, delay_copy(paint));
|
||||
APPEND(DrawRRect, delay_copy(paint), rrect);
|
||||
}
|
||||
|
||||
void SkRecorder::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) {
|
||||
APPEND(DrawDRRect, outer, inner, delay_copy(paint));
|
||||
APPEND(DrawDRRect, delay_copy(paint), outer, inner);
|
||||
}
|
||||
|
||||
void SkRecorder::drawPath(const SkPath& path, const SkPaint& paint) {
|
||||
APPEND(DrawPath, delay_copy(path), delay_copy(paint));
|
||||
APPEND(DrawPath, delay_copy(paint), delay_copy(path));
|
||||
}
|
||||
|
||||
void SkRecorder::drawBitmap(const SkBitmap& bitmap,
|
||||
SkScalar left,
|
||||
SkScalar top,
|
||||
const SkPaint* paint) {
|
||||
APPEND(DrawBitmap, delay_copy(bitmap), left, top, this->copy(paint));
|
||||
APPEND(DrawBitmap, this->copy(paint), delay_copy(bitmap), left, top);
|
||||
}
|
||||
|
||||
void SkRecorder::drawBitmapRectToRect(const SkBitmap& bitmap,
|
||||
@ -129,53 +129,61 @@ void SkRecorder::drawBitmapRectToRect(const SkBitmap& bitmap,
|
||||
const SkPaint* paint,
|
||||
DrawBitmapRectFlags flags) {
|
||||
APPEND(DrawBitmapRectToRect,
|
||||
delay_copy(bitmap), this->copy(src), dst, this->copy(paint), flags);
|
||||
this->copy(paint), delay_copy(bitmap), this->copy(src), dst, flags);
|
||||
}
|
||||
|
||||
void SkRecorder::drawBitmapMatrix(const SkBitmap& bitmap,
|
||||
const SkMatrix& matrix,
|
||||
const SkPaint* paint) {
|
||||
APPEND(DrawBitmapMatrix, delay_copy(bitmap), matrix, this->copy(paint));
|
||||
APPEND(DrawBitmapMatrix, this->copy(paint), delay_copy(bitmap), matrix);
|
||||
}
|
||||
|
||||
void SkRecorder::drawBitmapNine(const SkBitmap& bitmap,
|
||||
const SkIRect& center,
|
||||
const SkRect& dst,
|
||||
const SkPaint* paint) {
|
||||
APPEND(DrawBitmapNine, delay_copy(bitmap), center, dst, this->copy(paint));
|
||||
APPEND(DrawBitmapNine, this->copy(paint), delay_copy(bitmap), center, dst);
|
||||
}
|
||||
|
||||
void SkRecorder::drawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint) {
|
||||
APPEND(DrawSprite, delay_copy(bitmap), left, top, this->copy(paint));
|
||||
APPEND(DrawSprite, this->copy(paint), delay_copy(bitmap), left, top);
|
||||
}
|
||||
|
||||
void SkRecorder::onDrawText(const void* text, size_t byteLength,
|
||||
SkScalar x, SkScalar y, const SkPaint& paint) {
|
||||
APPEND(DrawText,
|
||||
this->copy((const char*)text, byteLength), byteLength, x, y, delay_copy(paint));
|
||||
delay_copy(paint), this->copy((const char*)text, byteLength), byteLength, x, y);
|
||||
}
|
||||
|
||||
void SkRecorder::onDrawPosText(const void* text, size_t byteLength,
|
||||
const SkPoint pos[], const SkPaint& paint) {
|
||||
const unsigned points = paint.countText(text, byteLength);
|
||||
APPEND(DrawPosText,
|
||||
this->copy((const char*)text, byteLength), byteLength,
|
||||
this->copy(pos, points), delay_copy(paint));
|
||||
delay_copy(paint),
|
||||
this->copy((const char*)text, byteLength),
|
||||
byteLength,
|
||||
this->copy(pos, points));
|
||||
}
|
||||
|
||||
void SkRecorder::onDrawPosTextH(const void* text, size_t byteLength,
|
||||
const SkScalar xpos[], SkScalar constY, const SkPaint& paint) {
|
||||
const unsigned points = paint.countText(text, byteLength);
|
||||
APPEND(DrawPosTextH,
|
||||
this->copy((const char*)text, byteLength), byteLength,
|
||||
this->copy(xpos, points), constY, delay_copy(paint));
|
||||
delay_copy(paint),
|
||||
this->copy((const char*)text, byteLength),
|
||||
byteLength,
|
||||
this->copy(xpos, points),
|
||||
constY);
|
||||
}
|
||||
|
||||
void SkRecorder::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
|
||||
const SkMatrix* matrix, const SkPaint& paint) {
|
||||
APPEND(DrawTextOnPath,
|
||||
this->copy((const char*)text, byteLength), byteLength,
|
||||
delay_copy(path), this->copy(matrix), delay_copy(paint));
|
||||
delay_copy(paint),
|
||||
this->copy((const char*)text, byteLength),
|
||||
byteLength,
|
||||
delay_copy(path),
|
||||
this->copy(matrix));
|
||||
}
|
||||
|
||||
void SkRecorder::drawPicture(SkPicture& picture) {
|
||||
@ -187,15 +195,15 @@ void SkRecorder::drawVertices(VertexMode vmode,
|
||||
const SkPoint texs[], const SkColor colors[],
|
||||
SkXfermode* xmode,
|
||||
const uint16_t indices[], int indexCount, const SkPaint& paint) {
|
||||
APPEND(DrawVertices, vmode,
|
||||
APPEND(DrawVertices, delay_copy(paint),
|
||||
vmode,
|
||||
vertexCount,
|
||||
this->copy(vertices, vertexCount),
|
||||
texs ? this->copy(texs, vertexCount) : NULL,
|
||||
colors ? this->copy(colors, vertexCount) : NULL,
|
||||
xmode,
|
||||
this->copy(indices, indexCount),
|
||||
indexCount,
|
||||
delay_copy(paint));
|
||||
indexCount);
|
||||
}
|
||||
|
||||
void SkRecorder::willSave(SkCanvas::SaveFlags flags) {
|
||||
|
@ -19,11 +19,17 @@ namespace SkRecords {
|
||||
//
|
||||
// We leave this SK_RECORD_TYPES macro defined for use by code that wants to operate on SkRecords
|
||||
// types polymorphically. (See SkRecord::Record::{visit,mutate} for an example.)
|
||||
//
|
||||
// Order doesn't technically matter here, but the compiler can generally generate better code if
|
||||
// you keep them semantically grouped, especially the Draws. It's also nice to leave NoOp at 0.
|
||||
#define SK_RECORD_TYPES(M) \
|
||||
M(NoOp) \
|
||||
M(Restore) \
|
||||
M(Save) \
|
||||
M(SaveLayer) \
|
||||
M(PushCull) \
|
||||
M(PopCull) \
|
||||
M(PairedPushCull) /*From SkRecordAnnotateCullingPairs*/ \
|
||||
M(Concat) \
|
||||
M(SetMatrix) \
|
||||
M(ClipPath) \
|
||||
@ -48,9 +54,6 @@ namespace SkRecords {
|
||||
M(DrawText) \
|
||||
M(DrawTextOnPath) \
|
||||
M(DrawVertices) \
|
||||
M(PushCull) \
|
||||
M(PopCull) \
|
||||
M(PairedPushCull) /*From SkRecordAnnotateCullingPairs*/ \
|
||||
M(BoundedDrawPosTextH) /*From SkRecordBoundDrawPosTextH*/
|
||||
|
||||
// Defines SkRecords::Type, an enum of all record types.
|
||||
@ -195,71 +198,73 @@ RECORD3(ClipRect, SkRect, rect, SkRegion::Op, op, bool, doAA);
|
||||
RECORD2(ClipRegion, SkRegion, region, SkRegion::Op, op);
|
||||
|
||||
RECORD1(Clear, SkColor, color);
|
||||
RECORD4(DrawBitmap, ImmutableBitmap, bitmap,
|
||||
// While not strictly required, if you have an SkPaint, it's fastest to put it first.
|
||||
RECORD4(DrawBitmap, Optional<SkPaint>, paint,
|
||||
ImmutableBitmap, bitmap,
|
||||
SkScalar, left,
|
||||
SkScalar, top,
|
||||
Optional<SkPaint>, paint);
|
||||
RECORD3(DrawBitmapMatrix, ImmutableBitmap, bitmap, SkMatrix, matrix, Optional<SkPaint>, paint);
|
||||
RECORD4(DrawBitmapNine, ImmutableBitmap, bitmap,
|
||||
SkScalar, top);
|
||||
RECORD3(DrawBitmapMatrix, Optional<SkPaint>, paint, ImmutableBitmap, bitmap, SkMatrix, matrix);
|
||||
RECORD4(DrawBitmapNine, Optional<SkPaint>, paint,
|
||||
ImmutableBitmap, bitmap,
|
||||
SkIRect, center,
|
||||
SkRect, dst,
|
||||
Optional<SkPaint>, paint);
|
||||
RECORD5(DrawBitmapRectToRect, ImmutableBitmap, bitmap,
|
||||
SkRect, dst);
|
||||
RECORD5(DrawBitmapRectToRect, Optional<SkPaint>, paint,
|
||||
ImmutableBitmap, bitmap,
|
||||
Optional<SkRect>, src,
|
||||
SkRect, dst,
|
||||
Optional<SkPaint>, paint,
|
||||
SkCanvas::DrawBitmapRectFlags, flags);
|
||||
RECORD3(DrawDRRect, SkRRect, outer, SkRRect, inner, SkPaint, paint);
|
||||
RECORD2(DrawOval, SkRect, oval, SkPaint, paint);
|
||||
RECORD3(DrawDRRect, SkPaint, paint, SkRRect, outer, SkRRect, inner);
|
||||
RECORD2(DrawOval, SkPaint, paint, SkRect, oval);
|
||||
RECORD1(DrawPaint, SkPaint, paint);
|
||||
RECORD2(DrawPath, SkPath, path, SkPaint, paint);
|
||||
RECORD4(DrawPoints, SkCanvas::PointMode, mode, size_t, count, SkPoint*, pts, SkPaint, paint);
|
||||
RECORD4(DrawPosText, PODArray<char>, text,
|
||||
RECORD2(DrawPath, SkPaint, paint, SkPath, path);
|
||||
RECORD4(DrawPoints, SkPaint, paint, SkCanvas::PointMode, mode, size_t, count, SkPoint*, pts);
|
||||
RECORD4(DrawPosText, SkPaint, paint,
|
||||
PODArray<char>, text,
|
||||
size_t, byteLength,
|
||||
PODArray<SkPoint>, pos,
|
||||
SkPaint, paint);
|
||||
RECORD5(DrawPosTextH, PODArray<char>, text,
|
||||
PODArray<SkPoint>, pos);
|
||||
RECORD5(DrawPosTextH, SkPaint, paint,
|
||||
PODArray<char>, text,
|
||||
size_t, byteLength,
|
||||
PODArray<SkScalar>, xpos,
|
||||
SkScalar, y,
|
||||
SkPaint, paint);
|
||||
RECORD2(DrawRRect, SkRRect, rrect, SkPaint, paint);
|
||||
RECORD2(DrawRect, SkRect, rect, SkPaint, paint);
|
||||
RECORD4(DrawSprite, ImmutableBitmap, bitmap, int, left, int, top, Optional<SkPaint>, paint);
|
||||
RECORD5(DrawText, PODArray<char>, text,
|
||||
SkScalar, y);
|
||||
RECORD2(DrawRRect, SkPaint, paint, SkRRect, rrect);
|
||||
RECORD2(DrawRect, SkPaint, paint, SkRect, rect);
|
||||
RECORD4(DrawSprite, Optional<SkPaint>, paint, ImmutableBitmap, bitmap, int, left, int, top);
|
||||
RECORD5(DrawText, SkPaint, paint,
|
||||
PODArray<char>, text,
|
||||
size_t, byteLength,
|
||||
SkScalar, x,
|
||||
SkScalar, y,
|
||||
SkPaint, paint);
|
||||
RECORD5(DrawTextOnPath, PODArray<char>, text,
|
||||
SkScalar, y);
|
||||
RECORD5(DrawTextOnPath, SkPaint, paint,
|
||||
PODArray<char>, text,
|
||||
size_t, byteLength,
|
||||
SkPath, path,
|
||||
Optional<SkMatrix>, matrix,
|
||||
SkPaint, paint);
|
||||
Optional<SkMatrix>, matrix);
|
||||
|
||||
// This guy is so ugly we just write it manually.
|
||||
struct DrawVertices {
|
||||
static const Type kType = DrawVertices_Type;
|
||||
|
||||
DrawVertices(SkCanvas::VertexMode vmode,
|
||||
DrawVertices(const SkPaint& paint,
|
||||
SkCanvas::VertexMode vmode,
|
||||
int vertexCount,
|
||||
SkPoint* vertices,
|
||||
SkPoint* texs,
|
||||
SkColor* colors,
|
||||
SkXfermode* xmode,
|
||||
uint16_t* indices,
|
||||
int indexCount,
|
||||
const SkPaint& paint)
|
||||
: vmode(vmode)
|
||||
int indexCount)
|
||||
: paint(paint)
|
||||
, vmode(vmode)
|
||||
, vertexCount(vertexCount)
|
||||
, vertices(vertices)
|
||||
, texs(texs)
|
||||
, colors(colors)
|
||||
, xmode(SkSafeRef(xmode))
|
||||
, indices(indices)
|
||||
, indexCount(indexCount)
|
||||
, paint(paint) {}
|
||||
, indexCount(indexCount) {}
|
||||
|
||||
SkPaint paint;
|
||||
SkCanvas::VertexMode vmode;
|
||||
int vertexCount;
|
||||
PODArray<SkPoint> vertices;
|
||||
@ -268,7 +273,6 @@ struct DrawVertices {
|
||||
SkAutoTUnref<SkXfermode> xmode;
|
||||
PODArray<uint16_t> indices;
|
||||
int indexCount;
|
||||
SkPaint paint;
|
||||
};
|
||||
|
||||
// Records added by optimizations.
|
||||
|
@ -55,7 +55,7 @@ DEF_TEST(Record, r) {
|
||||
// Add a simple DrawRect command.
|
||||
SkRect rect = SkRect::MakeWH(10, 10);
|
||||
SkPaint paint;
|
||||
SkNEW_PLACEMENT_ARGS(record.append<SkRecords::DrawRect>(), SkRecords::DrawRect, (rect, paint));
|
||||
SkNEW_PLACEMENT_ARGS(record.append<SkRecords::DrawRect>(), SkRecords::DrawRect, (paint, rect));
|
||||
|
||||
// Its area should be 100.
|
||||
AreaSummer summer;
|
||||
|
Loading…
Reference in New Issue
Block a user