internal void NotifyTileCacheFinishedRendering <TEnumerable>(TEnumerable finishedTileOffsets) where TEnumerable : IEnumerable <PointInt32>
 {
     base.VerifyAccess();
     if (this.IsActive)
     {
         RectInt32 num      = this.canvasView.GetVisibleCanvasBounds().Int32Bound;
         RectInt32?nullable = null;
         foreach (PointInt32 num3 in finishedTileOffsets)
         {
             this.isDeviceBitmapCurrent[num3.Y][num3.X] = false;
             RectInt32 tileSourceRect = this.tileMathHelper.GetTileSourceRect(num3);
             if (num.IntersectsWith(tileSourceRect))
             {
                 nullable = new RectInt32?(RectInt32Util.Union(nullable, tileSourceRect));
             }
             else
             {
                 this.ReleaseDeviceBitmap(num3);
             }
             this.nonCurrentTileOffsets.TryEnqueue(num3, QueueSide.Back);
         }
         if (nullable.HasValue)
         {
             this.canvasView.Invalidate(nullable.Value);
         }
     }
     else
     {
         foreach (PointInt32 num5 in finishedTileOffsets)
         {
             this.ReleaseDeviceBitmap(num5);
         }
     }
 }
Example #2
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if (historyWorkspace.Selection.IsEmpty)
            {
                return(null);
            }
            SelectionHistoryMemento             memento      = new SelectionHistoryMemento(StaticName, StaticImage, historyWorkspace);
            GeometryList                        selectedPath = historyWorkspace.Selection.GetCachedGeometryList();
            SelectionRenderingQuality           selectionRenderingQuality = historyWorkspace.ToolSettings.Selection.RenderingQuality.Value;
            Result <IReadOnlyList <RectInt32> > selectedPathScansLazy     = historyWorkspace.Selection.GetCachedLazyClippingMaskScans();
            RectInt32           documentBounds = historyWorkspace.Document.Bounds();
            Func <GeometryList> invertedPathFn = delegate {
                if ((selectionRenderingQuality == SelectionRenderingQuality.Aliased) || selectedPath.IsPixelated)
                {
                    GeometryList list2 = GeometryList.FromNonOverlappingSortedScans(selectedPathScansLazy.Value);
                    list2.AddRect(documentBounds);
                    SegmentedList <RectInt32> scans = new SegmentedList <RectInt32>();
                    foreach (RectInt32 num in list2.EnumerateInteriorScans())
                    {
                        if (documentBounds.Contains(num))
                        {
                            scans.Add(num);
                        }
                        else if (documentBounds.IntersectsWith(num))
                        {
                            scans.Add(RectInt32.Intersect(documentBounds, num));
                        }
                    }
                    return(GeometryList.FromNonOverlappingScans(scans));
                }
                GeometryList lhs = documentBounds.Contains(selectedPath.Bounds) ? selectedPath : GeometryList.ClipToRect(selectedPath, documentBounds);
                return(GeometryList.Combine(lhs, GeometryCombineMode.Xor, documentBounds));
            };
            ThreadTask <GeometryList> task = historyWorkspace.TaskManager.StartNewThreadTask <GeometryList>(task => invertedPathFn(), ApartmentState.MTA);
            ManualResetEvent          taskFinishedEvent = new ManualResetEvent(false);

            task.ResultAsync <GeometryList>().Receive(delegate(Result <GeometryList> r) {
                taskFinishedEvent.Set();
            }).Observe();
            if (!taskFinishedEvent.WaitOne(0x3e8))
            {
                using (TaskProgressDialog dialog = new TaskProgressDialog())
                {
                    dialog.Task       = task;
                    dialog.Text       = StaticName;
                    dialog.Icon       = StaticImage.Reference.ToIcon();
                    dialog.HeaderText = PdnResources.GetString("SaveConfigDialog.Finishing.Text");
                    dialog.ShowDialog(historyWorkspace.Window);
                }
            }
            Result <GeometryList> taskResult = task.TaskResult;

            if (taskResult.IsError)
            {
                if (taskResult.Error is OutOfMemoryException)
                {
                    throw new OutOfMemoryException(null, taskResult.Error);
                }
                throw new AggregateException(null, taskResult.Error);
            }
            GeometryList geometry = task.TaskResult.Value;

            base.EnterCriticalRegion();
            using (historyWorkspace.Selection.UseChangeScope())
            {
                historyWorkspace.Selection.Reset();
                geometry.Freeze();
                historyWorkspace.Selection.SetContinuation(geometry, SelectionCombineMode.Replace);
                historyWorkspace.Selection.CommitContinuation();
            }
            return(memento);
        }