File: ExpensiveCanvasHeuristicParameters.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (211 lines) | stat: -rw-r--r-- 9,577 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ExpensiveCanvasHeuristicParameters_h
#define ExpensiveCanvasHeuristicParameters_h

namespace blink {

namespace ExpensiveCanvasHeuristicParameters {

enum {
  // Layer promotion heuristic parameters
  //======================================

  // FIXME (crbug.com/463239):
  // The Layer promotion heuristics should go away after slimming paint
  // is completely phased in and display list canvases are modified to
  // use a lightweight layering primitive instead of the
  // SkCanvas::saveLayer.

  // Heuristic: Canvases that are overdrawn beyond this factor in a
  // single frame are promoted to a direct composited layer so that
  // their contents not be re-rasterized by the compositor when the
  // containing layer is the object of a paint invalidation.
  ExpensiveOverdrawThreshold = 3,

  ExpensivePathPointCount = 50,

  SVGImageSourcesAreExpensive = 1,

  ConcavePathsAreExpensive = 1,

  ComplexClipsAreExpensive = 1,

  BlurredShadowsAreExpensive = 1,

  // Heuristic: When drawing a source image that has more pixels than
  // the destination canvas by the following factor or more, the draw
  // is considered expensive.
  ExpensiveImageSizeRatio = 4,

  // Display list fallback heuristic parameters
  //============================================

  // Frames ending with more than this number of levels remaining
  // on the state stack at the end of a frame are too expensive to
  // remain in display list mode. This criterion is motivated by an
  // O(N) cost in carying over state from one frame to the next when
  // in display list mode. The value of this parameter should be high
  // enough to almost never kick in other than for cases with unmatched
  // save()/restore() calls are low enough to kick in before state
  // management becomes measurably expensive.
  ExpensiveRecordingStackDepth = 50,

  // GPU vs. display list heuristic parameters
  //===========================================

  // Pixel count beyond which we should always prefer to use display
  // lists. Rationale: The allocation of large textures for canvas
  // tends to starve the compositor, and increase the probability of
  // failure of subsequent allocations required for double buffering.
  PreferDisplayListOverGpuSizeThreshold = 8096 * 4096,

  // Disable Acceleration heuristic parameters
  //===========================================

  // When drawing very large images to canvases, there is a point where
  // GPU acceleration becomes inefficient due to texture upload overhead,
  // especially when the image is large enough that it is likely to
  // monopolize the texture cache, and when it is being downsized to the
  // point that few of the upload texels are actually sampled. When both
  // of these conditions are met, we disable acceleration.
  DrawImageTextureUploadSoftSizeLimit = 4096 * 4096,
  DrawImageTextureUploadSoftSizeLimitScaleThreshold = 4,
  DrawImageTextureUploadHardSizeLimit = 8192 * 8192,

  // GPU readback prevention heuristics
  //====================================

  GetImageDataForcesNoAcceleration = 1,

  // When a canvas is used as a source image, if its destination is
  // non-accelerated and the source canvas is accelerated, a readback
  // from the gpu is necessary. This option causes the source canvas to
  // switch to non-accelerated when this situation is encountered to
  // prevent future canvas-to-canvas draws from requiring a readback.
  DisableAccelerationToAvoidReadbacks = 0,

  // See description of DisableAccelerationToAvoidReadbacks. This is the
  // opposite strategy : accelerate the destination canvas. If both
  // EnableAccelerationToAvoidReadbacks and
  // DisableAccelerationToAvoidReadbacks are specified, we try to enable
  // acceleration on the destination first. If that does not succeed,
  // we disable acceleration on the source canvas. Either way, future
  // readbacks are prevented.
  EnableAccelerationToAvoidReadbacks = 1,

};  // enum

// Constants and Coefficients for 2D Canvas Dynamic Rendering Mode Switching
// =========================================================================

// Approximate relative costs of different types of operations for the
// accelerated rendering pipeline and the recording rendering pipeline.
// These costs were estimated experimentally using the tools located in the
// third_party/WebKit/Source/modules/canvas2d/performance_analysis directory.

// The RenderingModeCostIndex enum is used to access the heuristic coefficients
// that correspond to a given rendering mode. For example,
// FillRectFixedCost[RecordingModeIndex] is the estimated fixed cost for
// FillRect in recording mode.
enum RenderingModeCostIndex {
  RecordingModeIndex = 0,
  AcceleratedModeIndex = 1,
  NumRenderingModesCostIndexes = 2
};

const float FillRectFixedCost[NumRenderingModesCostIndexes] = {6.190e-03f,
                                                               7.715e-03f};
const float FillConvexPathFixedCost[NumRenderingModesCostIndexes] = {
    1.251e-02f, 1.231e-02f};
const float FillNonConvexPathFixedCost[NumRenderingModesCostIndexes] = {
    1.714e-02f, 4.497e-02f};
const float FillTextFixedCost[NumRenderingModesCostIndexes] = {1.119e-02f,
                                                               2.203e-02f};

const float StrokeRectFixedCost[NumRenderingModesCostIndexes] = {1.485e-02f,
                                                                 7.287e-03f};
const float StrokePathFixedCost[NumRenderingModesCostIndexes] = {2.390e-02f,
                                                                 5.125e-02f};
const float StrokeTextFixedCost[NumRenderingModesCostIndexes] = {1.149e-02f,
                                                                 1.742e-02f};

const float FillRectVariableCostPerArea[NumRenderingModesCostIndexes] = {
    2.933e-07f, 2.188e-09f};
const float FillConvexPathVariableCostPerArea[NumRenderingModesCostIndexes] = {
    7.871e-07f, 1.608e-07f};
const float FillNonConvexPathVariableCostPerArea[NumRenderingModesCostIndexes] =
    {8.336e-07f, 1.384e-06f};
const float FillTextVariableCostPerArea[NumRenderingModesCostIndexes] = {
    1.411e-06f, 0.0f};

const float StrokeRectVariableCostPerArea[NumRenderingModesCostIndexes] = {
    9.882e-07f, 0.0f};
const float StrokePathVariableCostPerArea[NumRenderingModesCostIndexes] = {
    1.583e-06f, 2.401e-06f};
const float StrokeTextVariableCostPerArea[NumRenderingModesCostIndexes] = {
    1.530e-06f, 6.699e-07f};

const float PatternFillTypeFixedCost[NumRenderingModesCostIndexes] = {
    1.377e-02f, 1.035e-02f};
const float LinearGradientFillTypeFixedCost[NumRenderingModesCostIndexes] = {
    7.694e-03f, 6.900e-03f};
const float RadialGradientFillTypeFixedCost[NumRenderingModesCostIndexes] = {
    2.260e-02f, 7.193e-03f};

const float PatternFillTypeVariableCostPerArea[NumRenderingModesCostIndexes] = {
    6.080e-07f, 0.0f};
const float
    LinearGradientFillVariableCostPerArea[NumRenderingModesCostIndexes] = {
        9.635e-07f, 0.0f};
const float
    RadialGradientFillVariableCostPerArea[NumRenderingModesCostIndexes] = {
        6.662e-06f, 0.0f};

const float ShadowFixedCost[NumRenderingModesCostIndexes] = {2.502e-02f,
                                                             2.274e-02f};
const float ShadowVariableCostPerAreaTimesShadowBlurSquared
    [NumRenderingModesCostIndexes] = {6.856e-09f, 0.0f};

const float PutImageDataFixedCost[NumRenderingModesCostIndexes] = {1.209e-03f,
                                                                   1.885e-02f};
const float PutImageDataVariableCostPerArea[NumRenderingModesCostIndexes] = {
    6.231e-06f, 4.116e-06f};

const float DrawSVGImageFixedCost[NumRenderingModesCostIndexes] = {1.431e-01f,
                                                                   2.958e-01f};
const float DrawPNGImageFixedCost[NumRenderingModesCostIndexes] = {1.278e-02f,
                                                                   1.306e-02f};

const float DrawSVGImageVariableCostPerArea[NumRenderingModesCostIndexes] = {
    1.030e-05f, 4.463e-06f};
const float DrawPNGImageVariableCostPerArea[NumRenderingModesCostIndexes] = {
    1.727e-06f, 0.0f};

// Two conditions must be met before the isAccelerationOptimalForCanvasContent
// heuristics recommends switching out of the accelerated mode:
//   1. The difference in estimated cost per frame is larger than
//      MinCostPerFrameImprovementToSuggestDisableAcceleration. This ensures
//      that the overhead involved in a switch of rendering mode and the risk of
//      making a wrong decision are justified by a large expected increased
//      performance.
//   2. The percent reduction in rendering cost is larger than
//      MinPercentageImprovementToSuggestDisableAcceleration. This ensures that
//      there is a high level of confidence that the performance would be
//      improved in recording mode.
const float MinCostPerFrameImprovementToSuggestDisableAcceleration = 15.0f;
const float MinPercentageImprovementToSuggestDisableAcceleration = 30.0f;

// Minimum number of frames that need to be rendered
// before the rendering pipeline may be switched. Having this set
// to more than 1 increases the sample size of usage data before a
// decision is made, improving the accuracy of heuristics.
const int MinFramesBeforeSwitch = 3;

}  // namespace ExpensiveCanvasHeuristicParameters

}  // namespace blink

#endif