| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef ExpensiveCanvasHeuristicParameters_h | |
| 6 #define ExpensiveCanvasHeuristicParameters_h | |
| 7 | |
| 8 namespace blink { | |
| 9 | |
| 10 namespace ExpensiveCanvasHeuristicParameters { | |
| 11 | |
| 12 enum { | |
| 13 // Layer promotion heuristic parameters | |
| 14 //====================================== | |
| 15 | |
| 16 // FIXME (crbug.com/463239): | |
| 17 // The Layer promotion heuristics should go away after slimming paint | |
| 18 // is completely phased in and display list canvases are modified to | |
| 19 // use a lightweight layering primitive instead of the | |
| 20 // SkCanvas::saveLayer. | |
| 21 | |
| 22 // Heuristic: Canvases that are overdrawn beyond this factor in a | |
| 23 // single frame are promoted to a direct composited layer so that | |
| 24 // their contents not be re-rasterized by the compositor when the | |
| 25 // containing layer is the object of a paint invalidation. | |
| 26 kExpensiveOverdrawThreshold = 3, | |
| 27 | |
| 28 kExpensivePathPointCount = 50, | |
| 29 | |
| 30 kSVGImageSourcesAreExpensive = 1, | |
| 31 | |
| 32 kConcavePathsAreExpensive = 1, | |
| 33 | |
| 34 kComplexClipsAreExpensive = 1, | |
| 35 | |
| 36 kBlurredShadowsAreExpensive = 1, | |
| 37 | |
| 38 // Heuristic: When drawing a source image that has more pixels than | |
| 39 // the destination canvas by the following factor or more, the draw | |
| 40 // is considered expensive. | |
| 41 kExpensiveImageSizeRatio = 4, | |
| 42 | |
| 43 // Display list fallback heuristic parameters | |
| 44 //============================================ | |
| 45 | |
| 46 // Frames ending with more than this number of levels remaining | |
| 47 // on the state stack at the end of a frame are too expensive to | |
| 48 // remain in display list mode. This criterion is motivated by an | |
| 49 // O(N) cost in carying over state from one frame to the next when | |
| 50 // in display list mode. The value of this parameter should be high | |
| 51 // enough to almost never kick in other than for cases with unmatched | |
| 52 // save()/restore() calls are low enough to kick in before state | |
| 53 // management becomes measurably expensive. | |
| 54 kExpensiveRecordingStackDepth = 50, | |
| 55 | |
| 56 // GPU vs. display list heuristic parameters | |
| 57 //=========================================== | |
| 58 | |
| 59 // Pixel count beyond which we should always prefer to use display | |
| 60 // lists. Rationale: The allocation of large textures for canvas | |
| 61 // tends to starve the compositor, and increase the probability of | |
| 62 // failure of subsequent allocations required for double buffering. | |
| 63 kPreferDisplayListOverGpuSizeThreshold = 8096 * 4096, | |
| 64 | |
| 65 // Disable Acceleration heuristic parameters | |
| 66 //=========================================== | |
| 67 | |
| 68 // When drawing very large images to canvases, there is a point where | |
| 69 // GPU acceleration becomes inefficient due to texture upload overhead, | |
| 70 // especially when the image is large enough that it is likely to | |
| 71 // monopolize the texture cache, and when it is being downsized to the | |
| 72 // point that few of the upload texels are actually sampled. When both | |
| 73 // of these conditions are met, we disable acceleration. | |
| 74 kDrawImageTextureUploadSoftSizeLimit = 4096 * 4096, | |
| 75 kDrawImageTextureUploadSoftSizeLimitScaleThreshold = 4, | |
| 76 kDrawImageTextureUploadHardSizeLimit = 8192 * 8192, | |
| 77 | |
| 78 // GPU readback prevention heuristics | |
| 79 //==================================== | |
| 80 | |
| 81 kGPUReadbackForcesNoAcceleration = 1, | |
| 82 | |
| 83 // When gpu readback is successively invoked in following number of frames, | |
| 84 // we disable gpu acceleration to avoid the high cost of gpu readback. | |
| 85 kGPUReadbackMinSuccessiveFrames = 3, | |
| 86 | |
| 87 // When a canvas is used as a source image, if its destination is | |
| 88 // non-accelerated and the source canvas is accelerated, a readback | |
| 89 // from the gpu is necessary. This option causes the source canvas to | |
| 90 // switch to non-accelerated when this situation is encountered to | |
| 91 // prevent future canvas-to-canvas draws from requiring a readback. | |
| 92 kDisableAccelerationToAvoidReadbacks = 0, | |
| 93 | |
| 94 // See description of DisableAccelerationToAvoidReadbacks. This is the | |
| 95 // opposite strategy : accelerate the destination canvas. If both | |
| 96 // EnableAccelerationToAvoidReadbacks and | |
| 97 // DisableAccelerationToAvoidReadbacks are specified, we try to enable | |
| 98 // acceleration on the destination first. If that does not succeed, | |
| 99 // we disable acceleration on the source canvas. Either way, future | |
| 100 // readbacks are prevented. | |
| 101 kEnableAccelerationToAvoidReadbacks = 1, | |
| 102 | |
| 103 }; // enum | |
| 104 | |
| 105 // Constants and Coefficients for 2D Canvas Dynamic Rendering Mode Switching | |
| 106 // ========================================================================= | |
| 107 | |
| 108 // Approximate relative costs of different types of operations for the | |
| 109 // accelerated rendering pipeline and the recording rendering pipeline. | |
| 110 // These costs were estimated experimentally using the tools located in the | |
| 111 // third_party/WebKit/Source/modules/canvas2d/performance_analysis directory. | |
| 112 | |
| 113 // The RenderingModeCostIndex enum is used to access the heuristic coefficients | |
| 114 // that correspond to a given rendering mode. For example, | |
| 115 // FillRectFixedCost[RecordingModeIndex] is the estimated fixed cost for | |
| 116 // FillRect in recording mode. | |
| 117 enum RenderingModeCostIndex { | |
| 118 kRecordingModeIndex = 0, | |
| 119 kAcceleratedModeIndex = 1, | |
| 120 kNumRenderingModesCostIndexes = 2 | |
| 121 }; | |
| 122 | |
| 123 const float kFillRectFixedCost[kNumRenderingModesCostIndexes] = {6.190e-03f, | |
| 124 7.715e-03f}; | |
| 125 const float kFillConvexPathFixedCost[kNumRenderingModesCostIndexes] = { | |
| 126 1.251e-02f, 1.231e-02f}; | |
| 127 const float kFillNonConvexPathFixedCost[kNumRenderingModesCostIndexes] = { | |
| 128 1.714e-02f, 4.497e-02f}; | |
| 129 const float kFillTextFixedCost[kNumRenderingModesCostIndexes] = {1.119e-02f, | |
| 130 2.203e-02f}; | |
| 131 | |
| 132 const float kStrokeRectFixedCost[kNumRenderingModesCostIndexes] = {1.485e-02f, | |
| 133 7.287e-03f}; | |
| 134 const float kStrokePathFixedCost[kNumRenderingModesCostIndexes] = {2.390e-02f, | |
| 135 5.125e-02f}; | |
| 136 const float kStrokeTextFixedCost[kNumRenderingModesCostIndexes] = {1.149e-02f, | |
| 137 1.742e-02f}; | |
| 138 | |
| 139 const float kFillRectVariableCostPerArea[kNumRenderingModesCostIndexes] = { | |
| 140 2.933e-07f, 2.188e-09f}; | |
| 141 const float kFillConvexPathVariableCostPerArea[kNumRenderingModesCostIndexes] = | |
| 142 {7.871e-07f, 1.608e-07f}; | |
| 143 const float | |
| 144 kFillNonConvexPathVariableCostPerArea[kNumRenderingModesCostIndexes] = { | |
| 145 8.336e-07f, 1.384e-06f}; | |
| 146 const float kFillTextVariableCostPerArea[kNumRenderingModesCostIndexes] = { | |
| 147 1.411e-06f, 0.0f}; | |
| 148 | |
| 149 const float kStrokeRectVariableCostPerArea[kNumRenderingModesCostIndexes] = { | |
| 150 9.882e-07f, 0.0f}; | |
| 151 const float kStrokePathVariableCostPerArea[kNumRenderingModesCostIndexes] = { | |
| 152 1.583e-06f, 2.401e-06f}; | |
| 153 const float kStrokeTextVariableCostPerArea[kNumRenderingModesCostIndexes] = { | |
| 154 1.530e-06f, 6.699e-07f}; | |
| 155 | |
| 156 const float kPatternFillTypeFixedCost[kNumRenderingModesCostIndexes] = { | |
| 157 1.377e-02f, 1.035e-02f}; | |
| 158 const float kLinearGradientFillTypeFixedCost[kNumRenderingModesCostIndexes] = { | |
| 159 7.694e-03f, 6.900e-03f}; | |
| 160 const float kRadialGradientFillTypeFixedCost[kNumRenderingModesCostIndexes] = { | |
| 161 2.260e-02f, 7.193e-03f}; | |
| 162 | |
| 163 const float kPatternFillTypeVariableCostPerArea[kNumRenderingModesCostIndexes] = | |
| 164 {6.080e-07f, 0.0f}; | |
| 165 const float | |
| 166 kLinearGradientFillVariableCostPerArea[kNumRenderingModesCostIndexes] = { | |
| 167 9.635e-07f, 0.0f}; | |
| 168 const float | |
| 169 kRadialGradientFillVariableCostPerArea[kNumRenderingModesCostIndexes] = { | |
| 170 6.662e-06f, 0.0f}; | |
| 171 | |
| 172 const float kShadowFixedCost[kNumRenderingModesCostIndexes] = {2.502e-02f, | |
| 173 2.274e-02f}; | |
| 174 const float kShadowVariableCostPerAreaTimesShadowBlurSquared | |
| 175 [kNumRenderingModesCostIndexes] = {6.856e-09f, 0.0f}; | |
| 176 | |
| 177 const float kPutImageDataFixedCost[kNumRenderingModesCostIndexes] = { | |
| 178 1.209e-03f, 1.885e-02f}; | |
| 179 const float kPutImageDataVariableCostPerArea[kNumRenderingModesCostIndexes] = { | |
| 180 6.231e-06f, 4.116e-06f}; | |
| 181 | |
| 182 const float kDrawSVGImageFixedCost[kNumRenderingModesCostIndexes] = { | |
| 183 1.431e-01f, 2.958e-01f}; | |
| 184 const float kDrawPNGImageFixedCost[kNumRenderingModesCostIndexes] = { | |
| 185 1.278e-02f, 1.306e-02f}; | |
| 186 | |
| 187 const float kDrawSVGImageVariableCostPerArea[kNumRenderingModesCostIndexes] = { | |
| 188 1.030e-05f, 4.463e-06f}; | |
| 189 const float kDrawPNGImageVariableCostPerArea[kNumRenderingModesCostIndexes] = { | |
| 190 1.727e-06f, 0.0f}; | |
| 191 | |
| 192 // Two conditions must be met before the isAccelerationOptimalForCanvasContent | |
| 193 // heuristics recommends switching out of the accelerated mode: | |
| 194 // 1. The difference in estimated cost per frame is larger than | |
| 195 // MinCostPerFrameImprovementToSuggestDisableAcceleration. This ensures | |
| 196 // that the overhead involved in a switch of rendering mode and the risk of | |
| 197 // making a wrong decision are justified by a large expected increased | |
| 198 // performance. | |
| 199 // 2. The percent reduction in rendering cost is larger than | |
| 200 // MinPercentageImprovementToSuggestDisableAcceleration. This ensures that | |
| 201 // there is a high level of confidence that the performance would be | |
| 202 // improved in recording mode. | |
| 203 const float kMinCostPerFrameImprovementToSuggestDisableAcceleration = 15.0f; | |
| 204 const float kMinPercentageImprovementToSuggestDisableAcceleration = 30.0f; | |
| 205 | |
| 206 // Minimum number of frames that need to be rendered | |
| 207 // before the rendering pipeline may be switched. Having this set | |
| 208 // to more than 1 increases the sample size of usage data before a | |
| 209 // decision is made, improving the accuracy of heuristics. | |
| 210 const int kMinFramesBeforeSwitch = 3; | |
| 211 | |
| 212 } // namespace ExpensiveCanvasHeuristicParameters | |
| 213 | |
| 214 } // namespace blink | |
| 215 | |
| 216 #endif | |
| OLD | NEW |