@@ -119,11 +119,15 @@ private FlushScene(
119119 /// <param name="scene">The prepared composition scene.</param>
120120 /// <param name="targetBounds">The destination bounds of the flush.</param>
121121 /// <param name="allocator">The allocator used for retained row storage.</param>
122+ /// <param name="maxDegreeOfParallelism">
123+ /// The maximum degree of parallelism to use when building the scene, or -1 to use the default number of processors.
124+ /// </param>
122125 /// <returns>A flush-ready scene.</returns>
123126 public static FlushScene Create (
124127 CompositionScene scene ,
125128 in Rectangle targetBounds ,
126- MemoryAllocator allocator )
129+ MemoryAllocator allocator ,
130+ int maxDegreeOfParallelism )
127131 {
128132 int commandCount = scene . CommandCount ;
129133
@@ -145,12 +149,14 @@ public static FlushScene Create(
145149
146150 FillSceneItem ? [ ] fillItems = new FillSceneItem ? [ commandCount ] ;
147151 StrokeSceneItem ? [ ] strokeItems = new StrokeSceneItem ? [ commandCount ] ;
148- int partitionCount = Math . Min ( commandCount , Math . Min ( Environment . ProcessorCount , targetRowCount ) ) ;
152+ int availableParallelism = maxDegreeOfParallelism == - 1 ? Environment . ProcessorCount : maxDegreeOfParallelism ;
153+ int partitionCount = Math . Min ( commandCount , Math . Min ( availableParallelism , targetRowCount ) ) ;
149154 PartitionState [ ] partitions = new PartitionState [ partitionCount ] ;
150155
151156 _ = Parallel . For (
152157 0 ,
153158 partitionCount ,
159+ new ParallelOptions { MaxDegreeOfParallelism = partitionCount } ,
154160 partitionIndex =>
155161 {
156162 // Integer division splits the commands into contiguous half-open ranges,
0 commit comments