示例#1
0
 public BackgroundEffectRenderer(Effect effect, EffectConfigToken effectToken, RenderArgs dstArgs, RenderArgs srcArgs, PdnRegion renderRegion, IRenderer <ColorAlpha8> clipMaskRenderer, int tileCount, int workerThreads)
 {
     this.effect       = effect;
     this.effectToken  = effectToken;
     this.dstArgs      = dstArgs;
     this.srcArgs      = srcArgs;
     this.renderRegion = renderRegion;
     this.renderRegion.Intersect(dstArgs.Bounds);
     this.tileCount = tileCount;
     if (effect.CheckForEffectFlags(EffectFlags.None | EffectFlags.SingleRenderCall))
     {
         this.tileCount = 1;
     }
     this.tileRegions    = this.SliceUpRegion(renderRegion, this.tileCount, dstArgs.Bounds);
     this.tilePdnRegions = new PdnRegion[this.tileRegions.Length];
     for (int i = 0; i < this.tileRegions.Length; i++)
     {
         this.tilePdnRegions[i] = PdnRegion.FromRectangles(this.tileRegions[i]);
     }
     this.workerThreads = workerThreads;
     if (effect.CheckForEffectFlags(EffectFlags.None | EffectFlags.SingleThreaded))
     {
         this.workerThreads = 1;
     }
     this.clipMaskRenderer = clipMaskRenderer;
     this.threadPool       = new EffectRendererWorkItemQueue(WorkItemDispatcher.Default, WorkItemQueuePriority.Normal, workerThreads);
 }
示例#2
0
 private void ThreadFunction()
 {
     if (this.srcArgs.Surface.Scan0.MaySetAllowWrites)
     {
         this.srcArgs.Surface.Scan0.AllowWrites = false;
     }
     try
     {
         this.threadInitialized.Set();
         this.effect.SetRenderInfo(this.effectTokenCopy, this.dstArgs, this.srcArgs);
         RendererContext context = new RendererContext(this);
         if (this.threadShouldStop)
         {
             this.effect.SignalCancelRequest();
         }
         else if (this.tileCount > 0)
         {
             context.RenderNextTile(this.effectTokenCopy);
         }
         WaitCallback rcwc = new WaitCallback(context.RenderNextTileProc);
         for (int i = 0; i < this.tileCount; i++)
         {
             if (this.threadShouldStop)
             {
                 this.effect.SignalCancelRequest();
                 break;
             }
             EffectConfigToken token = (this.effectTokenCopy == null) ? null : this.effectTokenCopy.CloneT <EffectConfigToken>();
             this.threadPool.Enqueue(() => rcwc(token));
         }
         this.threadPool.Join();
     }
     catch (Exception exception)
     {
         this.exceptions.Add(exception);
     }
     finally
     {
         EffectRendererWorkItemQueue threadPool = this.threadPool;
         if (!this.disposed && (threadPool != null))
         {
             try
             {
                 threadPool.Join();
             }
             catch (Exception)
             {
             }
         }
         this.OnFinishedRendering();
         RenderArgs srcArgs = this.srcArgs;
         if (srcArgs != null)
         {
             Surface surface = srcArgs.Surface;
             if (surface != null)
             {
                 MemoryBlock block = surface.Scan0;
                 if (((block != null) && !this.disposed) && block.MaySetAllowWrites)
                 {
                     try
                     {
                         block.AllowWrites = true;
                     }
                     catch (ObjectDisposedException)
                     {
                     }
                 }
             }
         }
     }
 }