Turn disable or delete optimizations that don't have any effect.

Recording gets a ~5% speedup.

BUG=skia:
R=robertphillips@google.com, mtklein@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/577673003
This commit is contained in:
mtklein 2014-09-16 11:11:20 -07:00 коммит произвёл Commit bot
Родитель e3b051cf8b
Коммит 1e78fc4ed2
3 изменённых файлов: 6 добавлений и 73 удалений

Просмотреть файл

@ -14,9 +14,13 @@
using namespace SkRecords;
void SkRecordOptimize(SkRecord* record) {
// This might be useful as a first pass in the future if we want to weed
// out junk for other optimization passes. Right now, nothing needs it,
// and the bounding box hierarchy will do the work of skipping no-op
// Save-NoDraw-Restore sequences better than we can here.
//SkRecordNoopSaveRestores(record);
SkRecordNoopSaveLayerDrawRestores(record);
SkRecordNoopSaveRestores(record);
SkRecordReduceDrawPosTextStrength(record);
}
// Most of the optimizations in this file are pattern-based. These are all defined as structs with:
@ -147,47 +151,3 @@ void SkRecordNoopSaveLayerDrawRestores(SkRecord* record) {
apply(&pass, record);
}
// Replaces DrawPosText with DrawPosTextH when all Y coordinates are equal.
struct StrengthReducer {
typedef Pattern1<Is<DrawPosText> > Pattern;
bool onMatch(SkRecord* record, Pattern* pattern, unsigned begin, unsigned end) {
SkASSERT(end == begin + 1);
DrawPosText* draw = pattern->first<DrawPosText>();
const unsigned points = draw->paint.countText(draw->text, draw->byteLength);
if (points == 0) {
return false; // No point (ha!).
}
const SkScalar firstY = draw->pos[0].fY;
for (unsigned i = 1; i < points; i++) {
if (draw->pos[i].fY != firstY) {
return false; // Needs full power of DrawPosText.
}
}
// All ys are the same. We can replace DrawPosText with DrawPosTextH.
// draw->pos is points SkPoints, [(x,y),(x,y),(x,y),(x,y), ... ].
// We're going to squint and look at that as 2*points SkScalars, [x,y,x,y,x,y,x,y, ...].
// Then we'll rearrange things so all the xs are in order up front, clobbering the ys.
SK_COMPILE_ASSERT(sizeof(SkPoint) == 2 * sizeof(SkScalar), SquintingIsNotSafe);
SkScalar* scalars = &draw->pos[0].fX;
for (unsigned i = 0; i < 2*points; i += 2) {
scalars[i/2] = scalars[i];
}
// Extend lifetime of draw to the end of the loop so we can copy its paint.
Adopted<DrawPosText> adopted(draw);
SkNEW_PLACEMENT_ARGS(record->replace<DrawPosTextH>(begin, adopted),
DrawPosTextH,
(draw->paint, draw->text, draw->byteLength, scalars, firstY));
return true;
}
};
void SkRecordReduceDrawPosTextStrength(SkRecord* record) {
StrengthReducer pass;
apply(&pass, record);
}

Просмотреть файл

@ -20,7 +20,4 @@ void SkRecordNoopSaveRestores(SkRecord*);
// draw, and no-op the SaveLayer and Restore.
void SkRecordNoopSaveLayerDrawRestores(SkRecord*);
// Convert DrawPosText to DrawPosTextH when all the Y coordinates are equal.
void SkRecordReduceDrawPosTextStrength(SkRecord*);
#endif//SkRecordOpts_DEFINED

Просмотреть файл

@ -16,30 +16,6 @@
static const int W = 1920, H = 1080;
static void draw_pos_text(SkCanvas* canvas, const char* text, bool constantY) {
const size_t len = strlen(text);
SkAutoTMalloc<SkPoint> pos(len);
for (size_t i = 0; i < len; i++) {
pos[i].fX = (SkScalar)i;
pos[i].fY = constantY ? SK_Scalar1 : (SkScalar)i;
}
canvas->drawPosText(text, len, pos, SkPaint());
}
DEF_TEST(RecordOpts_StrengthReduction, r) {
SkRecord record;
SkRecorder recorder(&record, W, H);
// We can convert a drawPosText into a drawPosTextH when all the Ys are the same.
draw_pos_text(&recorder, "This will be reduced to drawPosTextH.", true);
draw_pos_text(&recorder, "This cannot be reduced to drawPosTextH.", false);
SkRecordReduceDrawPosTextStrength(&record);
assert_type<SkRecords::DrawPosTextH>(r, record, 0);
assert_type<SkRecords::DrawPosText>(r, record, 1);
}
DEF_TEST(RecordOpts_NoopDrawSaveRestore, r) {
SkRecord record;
SkRecorder recorder(&record, W, H);