Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
| 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> | 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
| 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> | 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> |
| 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
| 8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. | 8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. |
| 9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
| 10 * | 10 * |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 #include "core/frame/Settings.h" | 46 #include "core/frame/Settings.h" |
| 47 #include "core/html/TextMetrics.h" | 47 #include "core/html/TextMetrics.h" |
| 48 #include "core/html/canvas/CanvasFontCache.h" | 48 #include "core/html/canvas/CanvasFontCache.h" |
| 49 #include "core/layout/LayoutBox.h" | 49 #include "core/layout/LayoutBox.h" |
| 50 #include "core/layout/LayoutTheme.h" | 50 #include "core/layout/LayoutTheme.h" |
| 51 #include "modules/canvas2d/CanvasStyle.h" | 51 #include "modules/canvas2d/CanvasStyle.h" |
| 52 #include "modules/canvas2d/HitRegion.h" | 52 #include "modules/canvas2d/HitRegion.h" |
| 53 #include "modules/canvas2d/Path2D.h" | 53 #include "modules/canvas2d/Path2D.h" |
| 54 #include "platform/fonts/FontCache.h" | 54 #include "platform/fonts/FontCache.h" |
| 55 #include "platform/graphics/DrawLooperBuilder.h" | 55 #include "platform/graphics/DrawLooperBuilder.h" |
| 56 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" | |
| 57 #include "platform/graphics/ImageBuffer.h" | 56 #include "platform/graphics/ImageBuffer.h" |
| 58 #include "platform/graphics/StrokeData.h" | 57 #include "platform/graphics/StrokeData.h" |
| 59 #include "platform/graphics/skia/SkiaUtils.h" | 58 #include "platform/graphics/skia/SkiaUtils.h" |
| 60 #include "platform/text/BidiTextRun.h" | 59 #include "platform/text/BidiTextRun.h" |
| 61 #include "public/platform/Platform.h" | 60 #include "public/platform/Platform.h" |
| 62 #include "third_party/skia/include/core/SkCanvas.h" | 61 #include "third_party/skia/include/core/SkCanvas.h" |
| 63 #include "third_party/skia/include/core/SkImageFilter.h" | 62 #include "third_party/skia/include/core/SkImageFilter.h" |
| 64 #include "wtf/MathExtras.h" | 63 #include "wtf/MathExtras.h" |
| 65 #include "wtf/text/StringBuilder.h" | 64 #include "wtf/text/StringBuilder.h" |
| 66 #include "wtf/typed_arrays/ArrayBufferContents.h" | 65 #include "wtf/typed_arrays/ArrayBufferContents.h" |
| (...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1061 } | 1060 } |
| 1062 | 1061 |
| 1063 unsigned CanvasRenderingContext2D::hitRegionsCount() const | 1062 unsigned CanvasRenderingContext2D::hitRegionsCount() const |
| 1064 { | 1063 { |
| 1065 if (m_hitRegionManager) | 1064 if (m_hitRegionManager) |
| 1066 return m_hitRegionManager->getHitRegionsCount(); | 1065 return m_hitRegionManager->getHitRegionsCount(); |
| 1067 | 1066 |
| 1068 return 0; | 1067 return 0; |
| 1069 } | 1068 } |
| 1070 | 1069 |
| 1070 | |
| 1071 double CanvasRenderingContext2D::estimateRenderingCostForUsage(BaseRenderingCont ext2D::UsageCounters usage, ExpensiveCanvasHeuristicParameters::RenderingModeCos tIndex index) const | |
|
Justin Novosad
2016/08/04 15:53:17
double -> float here and below
sebastienlc
2016/08/04 16:36:27
Done.
| |
| 1072 { | |
| 1073 double basicCostOfDrawCalls = | |
| 1074 ExpensiveCanvasHeuristicParameters::FillRectFixedCost[index] * usage.num DrawCalls[BaseRenderingContext2D::FillRect] + | |
| 1075 ExpensiveCanvasHeuristicParameters::FillConvexPathFixedCost[index] * (us age.numDrawCalls[BaseRenderingContext2D::FillPath] - usage.numNonConvexFillPathC alls) + | |
| 1076 ExpensiveCanvasHeuristicParameters::FillNonConvexPathFixedCost[index] * usage.numNonConvexFillPathCalls + | |
| 1077 ExpensiveCanvasHeuristicParameters::FillTextFixedCost[index] * usage.num DrawCalls[BaseRenderingContext2D::FillText] + | |
| 1078 | |
| 1079 ExpensiveCanvasHeuristicParameters::StrokeRectFixedCost[index] * usage.n umDrawCalls[BaseRenderingContext2D::StrokeRect] + | |
| 1080 ExpensiveCanvasHeuristicParameters::StrokePathFixedCost[index] * usage.n umDrawCalls[BaseRenderingContext2D::StrokePath] + | |
| 1081 ExpensiveCanvasHeuristicParameters::StrokeTextFixedCost[index] * usage.n umDrawCalls[BaseRenderingContext2D::StrokeText] + | |
| 1082 | |
| 1083 ExpensiveCanvasHeuristicParameters::FillRectVariableCostPerArea[index] * usage.boundingBoxAreaDrawCalls[BaseRenderingContext2D::FillRect] + | |
| 1084 ExpensiveCanvasHeuristicParameters::FillConvexPathVariableCostPerArea[in dex] * (usage.boundingBoxAreaDrawCalls[BaseRenderingContext2D::FillPath] - usage .nonConvexFillPathArea) + | |
| 1085 ExpensiveCanvasHeuristicParameters::FillNonConvexPathVariableCostPerArea [index] * usage.nonConvexFillPathArea + | |
| 1086 ExpensiveCanvasHeuristicParameters::FillTextVariableCostPerArea[index] * usage.boundingBoxAreaDrawCalls[BaseRenderingContext2D::FillText] + | |
| 1087 | |
| 1088 ExpensiveCanvasHeuristicParameters::StrokeRectVariableCostPerArea[index] * usage.boundingBoxAreaDrawCalls[BaseRenderingContext2D::StrokeRect] + | |
| 1089 ExpensiveCanvasHeuristicParameters::StrokePathVariableCostPerArea[index] * usage.boundingBoxAreaDrawCalls[BaseRenderingContext2D::StrokePath] + | |
| 1090 ExpensiveCanvasHeuristicParameters::StrokeTextVariableCostPerArea[index] * usage.boundingBoxAreaDrawCalls[BaseRenderingContext2D::StrokeText] + | |
| 1091 | |
| 1092 ExpensiveCanvasHeuristicParameters::PutImageDataFixedCost[index] * usage .numPutImageDataCalls + | |
| 1093 ExpensiveCanvasHeuristicParameters::PutImageDataVariableCostPerArea[inde x] * usage.areaPutImageDataCalls + | |
| 1094 | |
| 1095 ExpensiveCanvasHeuristicParameters::DrawSVGImageFixedCost[index] * usage .numDrawCalls[BaseRenderingContext2D::DrawSVGImage] + | |
| 1096 ExpensiveCanvasHeuristicParameters::DrawPNGImageFixedCost[index] * usage .numDrawCalls[BaseRenderingContext2D::DrawPNGImage] + | |
| 1097 | |
| 1098 ExpensiveCanvasHeuristicParameters::DrawSVGImageVariableCostPerArea[inde x] * usage.boundingBoxAreaDrawCalls[BaseRenderingContext2D::DrawSVGImage] + | |
| 1099 ExpensiveCanvasHeuristicParameters::DrawPNGImageVariableCostPerArea[inde x] * usage.boundingBoxAreaDrawCalls[BaseRenderingContext2D::DrawPNGImage]; | |
| 1100 | |
| 1101 double fillTypeAdjustment = | |
| 1102 ExpensiveCanvasHeuristicParameters::PatternFillTypeFixedCost[index] * us age.numPatterns + | |
| 1103 ExpensiveCanvasHeuristicParameters::LinearGradientFillTypeFixedCost[inde x] * usage.numLinearGradients + | |
| 1104 ExpensiveCanvasHeuristicParameters::RadialGradientFillTypeFixedCost[inde x] * usage.numRadialGradients + | |
| 1105 | |
| 1106 ExpensiveCanvasHeuristicParameters::PatternFillTypeVariableCostPerArea[i ndex] * usage.boundingBoxAreaFillType[BaseRenderingContext2D::PatternFillType] + | |
| 1107 ExpensiveCanvasHeuristicParameters::LinearGradientFillVariableCostPerAre a[index] * usage.boundingBoxAreaFillType[BaseRenderingContext2D::LinearGradientF illType] + | |
| 1108 ExpensiveCanvasHeuristicParameters::RadialGradientFillVariableCostPerAre a[index] * usage.boundingBoxAreaFillType[BaseRenderingContext2D::RadialGradientF illType]; | |
| 1109 | |
| 1110 double shadowAdjustment = | |
| 1111 ExpensiveCanvasHeuristicParameters::ShadowFixedCost[index] * usage.numBl urredShadows + | |
| 1112 ExpensiveCanvasHeuristicParameters::ShadowVariableCostPerAreaTimesShadow BlurSquared[index] * usage.boundingBoxAreaTimesShadowBlurSquared; | |
| 1113 | |
| 1114 return basicCostOfDrawCalls + fillTypeAdjustment + shadowAdjustment; | |
| 1115 } | |
| 1116 | |
| 1071 bool CanvasRenderingContext2D::isAccelerationOptimalForCanvasContent() const | 1117 bool CanvasRenderingContext2D::isAccelerationOptimalForCanvasContent() const |
| 1072 { | 1118 { |
| 1073 // Simple heuristic to determine if the GPU accelerated pipeline should be | 1119 // Heuristic to determine if the GPU accelerated rendering pipeline is optim al |
| 1074 // used to maximize performance of 2D canvas based on past usage. | 1120 // for performance based on past usage. It has a bias towards suggesting tha t the |
| 1121 // accelerated pipeline is optimal. | |
| 1075 | 1122 |
| 1076 int numDrawPathCalls = | 1123 double acceleratedCost = estimateRenderingCostForUsage(m_usageCounters, Expe nsiveCanvasHeuristicParameters::AcceleratedModeIndex); |
|
Justin Novosad
2016/08/04 15:53:17
double -> float here and below
sebastienlc
2016/08/04 16:36:27
Done.
| |
| 1077 m_usageCounters.numDrawCalls[StrokePath] + | |
| 1078 m_usageCounters.numDrawCalls[FillPath] + | |
| 1079 m_usageCounters.numDrawCalls[FillText] + | |
| 1080 m_usageCounters.numDrawCalls[StrokeText] + | |
| 1081 m_usageCounters.numDrawCalls[FillRect] + | |
| 1082 m_usageCounters.numDrawCalls[StrokeRect]; | |
| 1083 | 1124 |
| 1084 double acceleratedCost = | 1125 double recordingCost = estimateRenderingCostForUsage(m_usageCounters, Expens iveCanvasHeuristicParameters::RecordingModeIndex); |
| 1085 numDrawPathCalls * ExpensiveCanvasHeuristicParameters::AcceleratedDrawPa thApproximateCost + | |
| 1086 m_usageCounters.numGetImageDataCalls * ExpensiveCanvasHeuristicParameter s::AcceleratedGetImageDataApproximateCost+ | |
| 1087 m_usageCounters.numDrawCalls[DrawImage] * ExpensiveCanvasHeuristicParame ters::AcceleratedDrawImageApproximateCost; | |
| 1088 | 1126 |
| 1089 double recordingCost = | 1127 double costDifference = acceleratedCost - recordingCost; |
| 1090 numDrawPathCalls * ExpensiveCanvasHeuristicParameters::RecordingDrawPath ApproximateCost + | 1128 double percentCostReduction = costDifference / acceleratedCost * 100.0; |
| 1091 m_usageCounters.numGetImageDataCalls * ExpensiveCanvasHeuristicParameter s::UnacceleratedGetImageDataApproximateCost + | 1129 double costDifferencePerFrame = costDifference / m_usageCounters.numFramesSi nceReset; |
| 1092 m_usageCounters.numDrawCalls[DrawImage] * ExpensiveCanvasHeuristicParame ters::RecordingDrawImageApproximateCost; | |
| 1093 | 1130 |
| 1094 if (recordingCost * ExpensiveCanvasHeuristicParameters::AcceleratedHeuristic Bias < acceleratedCost) { | 1131 if (percentCostReduction >= ExpensiveCanvasHeuristicParameters::MinPercentag eImprovementToSuggestDisableAcceleration |
| 1132 && costDifferencePerFrame >= ExpensiveCanvasHeuristicParameters::MinCost PerFrameImprovementToSuggestDisableAcceleration) { | |
| 1095 return false; | 1133 return false; |
| 1096 } | 1134 } |
| 1097 return true; | 1135 return true; |
| 1098 } | 1136 } |
| 1099 | 1137 |
| 1100 void CanvasRenderingContext2D::resetUsageTracking() | 1138 void CanvasRenderingContext2D::resetUsageTracking() |
| 1101 { | 1139 { |
| 1102 UsageCounters newCounters; | 1140 UsageCounters newCounters; |
| 1103 m_usageCounters = newCounters; | 1141 m_usageCounters = newCounters; |
| 1104 } | 1142 } |
| 1105 | 1143 |
| 1106 } // namespace blink | 1144 } // namespace blink |
| OLD | NEW |