@@ -26,27 +26,45 @@ DisplayListMetalComplexityCalculator::GetInstance() {
2626}
2727
2828unsigned int
29- DisplayListMetalComplexityCalculator::MetalHelper::SaveLayerComplexity () {
29+ DisplayListMetalComplexityCalculator::MetalHelper::BatchedComplexity () {
3030 // Calculate the impact of saveLayer.
3131 unsigned int save_layer_complexity;
32- if (SaveLayerCount () == 0 ) {
32+ if (save_layer_count_ == 0 ) {
3333 save_layer_complexity = 0 ;
3434 } else {
3535 // saveLayer seems to have two trends; if the count is < 200,
3636 // then the individual cost of a saveLayer is higher than if
3737 // the count is > 200.
38- if (SaveLayerCount () > 200 ) {
38+ if (save_layer_count_ > 200 ) {
3939 // m = 1/5
4040 // c = 1
41- save_layer_complexity = (SaveLayerCount () + 5 ) * 40000 ;
41+ save_layer_complexity = (save_layer_count_ + 5 ) * 40000 ;
4242 } else {
4343 // m = 1/2
4444 // c = 1
45- save_layer_complexity = (SaveLayerCount () + 2 ) * 100000 ;
45+ save_layer_complexity = (save_layer_count_ + 2 ) * 100000 ;
4646 }
4747 }
4848
49- return save_layer_complexity;
49+ unsigned int draw_text_blob_complexity;
50+ if (draw_text_blob_count_ == 0 ) {
51+ draw_text_blob_complexity = 0 ;
52+ } else {
53+ // m = 1/240
54+ // c = 0.75
55+ draw_text_blob_complexity = (draw_text_blob_count_ + 180 ) * 2500 / 3 ;
56+ }
57+
58+ return save_layer_complexity + draw_text_blob_complexity;
59+ }
60+
61+ void DisplayListMetalComplexityCalculator::MetalHelper::saveLayer (
62+ const SkRect* bounds,
63+ const SaveLayerOptions options) {
64+ if (IsComplex ()) {
65+ return ;
66+ }
67+ save_layer_count_++;
5068}
5169
5270void DisplayListMetalComplexityCalculator::MetalHelper::drawLine (
@@ -552,36 +570,13 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawTextBlob(
552570 if (IsComplex ()) {
553571 return ;
554572 }
555- // There are two classes here, hairline vs non-hairline.
556- //
557- // Hairline scales loglinearly with the number of glyphs.
558- // Non-hairline scales linearly.
559573
560- // Unfortunately there is currently no way for us to figure out the glyph
561- // count from an SkTextBlob. We will need to figure out a better solution
562- // here, but for now just use a placeholder value of 100 glyphs.
563- unsigned int glyph_count = 100 ;
574+ // DrawTextBlob has a high fixed cost, but if we call it multiple times
575+ // per frame, that fixed cost is greatly reduced per subsequent call. This
576+ // is likely because there is batching being done in SkCanvas.
564577
565- // These values were worked out by creating a straight line graph (y=mx+c)
566- // approximately matching the measured data, normalising the data so that
567- // 0.0005ms resulted in a score of 100 then simplifying down the formula.
568- unsigned int complexity;
569- if (IsHairline () && Style () == SkPaint::Style::kStroke_Style ) {
570- // If hairlines are on, we hit a degenerative case within Skia that causes
571- // our time to skyrocket.
572- //
573- // m = 1/3000
574- // c = 1.75
575- // x = glyph_count * log2(glyph_count)
576- unsigned int x = glyph_count * log (glyph_count);
577- complexity = (x + 5250 ) * 200 / 3 ;
578- } else {
579- // m = 1/5000
580- // c = 0.75
581- complexity = 40 * (glyph_count + 3750 );
582- }
583-
584- AccumulateComplexity (complexity);
578+ // Increment draw_text_blob_count_ and calculate the cost at the end.
579+ draw_text_blob_count_++;
585580}
586581
587582void DisplayListMetalComplexityCalculator::MetalHelper::drawShadow (
0 commit comments