Ejemplo n.º 1
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         DisposableUtil.Free <ThreadDispatcher>(ref this.backgroundThread);
         DisposableUtil.Free <ISystemFonts>(ref this.systemFonts);
         DisposableUtil.Free <System.Windows.Forms.Timer>(ref this.clearCacheTimer);
         DisposableUtil.Free <SelectionHighlightRenderer>(ref this.selectionHighlightRenderer);
         if (this.fontPreviewRenderCache != null)
         {
             Dictionary <TupleStruct <string, float, PaintDotNet.UI.Media.Brush>, PlacedBitmap> fontPreviewRenderCache = this.fontPreviewRenderCache;
             lock (fontPreviewRenderCache)
             {
                 this.fontPreviewRenderCache.Values.ForEach <PlacedBitmap>(pb => pb.Dispose());
                 this.fontPreviewRenderCache = null;
             }
         }
         if (this.fontMap != null)
         {
             this.fontMap.CollectionChanged -= new EventHandler(this.OnFontFamilyNameCollectionChanged);
             this.fontMap.Dispose();
             this.fontMap = null;
         }
         DisposableUtil.Free <ISystemFonts>(ref this.systemFonts);
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 2
0
 protected override void OnDeactivate()
 {
     DisposableUtil.Free <Cursor>(ref this.cursorMouseDown);
     DisposableUtil.Free <Cursor>(ref this.cursorMouseUp);
     DisposableUtil.Free <Cursor>(ref this.cursorMouseInvalid);
     base.OnDeactivate();
 }
Ejemplo n.º 3
0
 protected override void OnDeactivated()
 {
     this.mouseInputDrawingAgent = null;
     this.txHandler.RelayDeactivated();
     DisposableUtil.Free <TimerResolutionScope>(ref this.timerResolutionScope);
     base.OnDeactivated();
 }
Ejemplo n.º 4
0
 private void OnClearCacheTimerTick(object sender, EventArgs e)
 {
     try
     {
         if (!base.IsDisposed && (this.fontPreviewRenderCache != null))
         {
             using (Profiling.UseEnter("Clearing the font preview cache"))
             {
                 Dictionary <TupleStruct <string, float, PaintDotNet.UI.Media.Brush>, PlacedBitmap> fontPreviewRenderCache = this.fontPreviewRenderCache;
                 lock (fontPreviewRenderCache)
                 {
                     this.fontPreviewRenderCache.Clear();
                 }
             }
         }
     }
     catch (Exception)
     {
     }
     finally
     {
         try
         {
             DisposableUtil.Free <System.Windows.Forms.Timer>(ref this.clearCacheTimer);
         }
         catch (Exception)
         {
         }
     }
 }
Ejemplo n.º 5
0
        private IDeviceBitmap GetOrCreateDeviceBitmap(IDeviceResourceFactory factory, SizeInt32 desiredPixelSize)
        {
            base.VerifyAccess();
            IDeviceBitmap result = null;
            int           num    = Int32Util.Pow2RoundUp(desiredPixelSize.Width);
            int           num2   = Int32Util.Pow2RoundUp(desiredPixelSize.Height);
            int           width  = Math.Max(Math.Max(num, num2), 0x100);
            SizeInt32     num5   = new SizeInt32(width, width);

            while (this.deviceBitmapPool.TryDequeue(out result))
            {
                SizeInt32 pixelSize = result.PixelSize;
                if (((pixelSize.Width >= num5.Width) && (pixelSize.Width <= (num5.Width * 2))) && ((pixelSize.Height >= num5.Height) && (pixelSize.Height <= (num5.Height * 2))))
                {
                    break;
                }
                DisposableUtil.Free <IDeviceBitmap>(ref result);
            }
            if (result == null)
            {
                result = factory.CreateDeviceBitmap(desiredPixelSize, maskBitmapProperties);
                AttachedData.SetValue(result, isPooledBitmapAttachedKey, BooleanUtil.GetBoxed(true));
            }
            return(result);
        }
Ejemplo n.º 6
0
 private void DisposeCore(bool disposing)
 {
     if (Interlocked.Exchange(ref this.isDisposed, 1) == 0)
     {
         try
         {
             this.Dispose(disposing);
         }
         finally
         {
             IObjectRef innerRef = this.innerRef;
             this.InnerRef = null;
             if ((this.proxyOptions & ObjectRefProxyOptions.DoNotCreateRef) != ObjectRefProxyOptions.DoNotCreateRef)
             {
                 IRefTrackedObject obj2 = innerRef as IRefTrackedObject;
                 if (obj2 != null)
                 {
                     obj2.ReleaseRef(this, disposing);
                 }
             }
         }
         if (disposing)
         {
             RefTrackedObject cleanupContainer;
             ObjectRefProxy proxy = this;
             lock (proxy)
             {
                 cleanupContainer = this.cleanupContainer;
                 this.cleanupContainer = null;
             }
             DisposableUtil.Free<RefTrackedObject>(ref cleanupContainer, disposing);
         }
     }
 }
Ejemplo n.º 7
0
 private void EndRedraw(RectDouble canvasBounds, RectFloat maskSourceRect, IBitmap <ColorAlpha8> interiorMask, IBitmap <ColorAlpha8>[] dashedOutlineMasks)
 {
     base.VerifyAccess();
     if (base.IsDisposed)
     {
         DisposableUtil.Free <IBitmap <ColorAlpha8> >(ref interiorMask);
         DisposableUtil.FreeContents <IBitmap <ColorAlpha8> >(dashedOutlineMasks);
     }
     else
     {
         this.isRedrawing = false;
         base.CanvasView.Invalidate(this.renderedCanvasBounds);
         this.ReturnOrFreeDeviceBitmap(ref this.renderedInteriorDeviceBitmap);
         this.ReturnOrFreeDeviceBitmaps(this.renderedDashedOutlineDeviceBitmaps);
         this.renderedDashedOutlineDeviceBitmaps = null;
         DisposableUtil.Free <IBitmap <ColorAlpha8> >(ref this.renderedInteriorMask);
         this.renderedInteriorMask = interiorMask;
         DisposableUtil.FreeContents <IBitmap <ColorAlpha8> >(this.renderedDashedOutlineMasks);
         this.renderedDashedOutlineMasks = dashedOutlineMasks;
         this.renderedCanvasBounds       = canvasBounds;
         this.renderedMaskSourceRect     = maskSourceRect;
         this.renderedRenderParams       = this.redrawRenderParams;
         this.redrawRenderParams         = null;
         base.CanvasView.Invalidate(this.renderedCanvasBounds);
         if (this.isRedrawNeeded)
         {
             this.isRedrawNeeded = false;
             this.QueueBeginRedraw();
         }
     }
 }
 protected override void Dispose(bool disposing)
 {
     DisposableUtil.Free(ref this.writer, disposing);
     this.textWriter = null;
     this.stream     = null;
     base.Dispose(disposing);
 }
Ejemplo n.º 9
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (this.components != null)
         {
             this.components.Dispose();
             this.components = null;
         }
         try
         {
             SystemEvents.SessionSwitch          -= new SessionSwitchEventHandler(this.OnSystemEventsSessionSwitch);
             SystemEvents.DisplaySettingsChanged -= new EventHandler(this.OnSystemEventsDisplaySettingsChanged);
         }
         catch (Exception)
         {
         }
         if (this.hookedControls != null)
         {
             this.UnhookControl(this);
             this.hookedControls = null;
         }
         DisposableUtil.Free <AnimatedDouble>(ref this.opacityVariable);
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 10
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         DisposableUtil.Free <IContainer>(ref this.components, disposing);
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 11
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         DisposableUtil.Free <Document>(ref this.oldDocument);
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 12
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         DisposableUtil.Free <Timer>(ref this.toolSettingsDebounceTimer);
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 13
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         DisposableUtil.Free <DropShadowRenderer>(ref this.dropShadowRenderer);
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 14
0
        private void CreateAllLayersRenderSurface(int sampleSize)
        {
            DisposableUtil.Free <Surface>(ref this.allLayersRenderSurface);
            int width  = (base.Document.Bounds.Width < sampleSize) ? base.Document.Bounds.Width : sampleSize;
            int height = (base.Document.Bounds.Height < sampleSize) ? base.Document.Bounds.Height : sampleSize;

            this.allLayersRenderSurface = new Surface(width, height);
        }
Ejemplo n.º 15
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         DisposableUtil.Free <Surface>(ref this.allLayersRenderSurface);
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 16
0
        private void UpdateTileWhileLocked(TileData tileData, ICancellationToken cancelToken)
        {
            RectInt32  tileSourceRect = this.tileMathHelper.GetTileSourceRect(tileData.Offset);
            RectDouble num2           = tileSourceRect;

            cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
            object newCurrencyToken = this.renderData.CreateCurrencyToken();

            cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
            IList <int?> list  = this.renderData.GetStrokeSampleIndicesInRect(tileSourceRect, tileData.CurrencyToken, newCurrencyToken);
            int          count = list.Count;

            if (count > 0)
            {
                SizeDouble      size = this.stamp.Size;
                RectDouble      num5 = new RectDouble(PointDouble.Zero, size);
                IDrawingContext dc   = null;
                try
                {
                    for (int i = 0; i < count; i++)
                    {
                        int?nullable = list[i];
                        if (nullable.HasValue)
                        {
                            if (tileData.Mask == null)
                            {
                                cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
                                tileData.Mask = new SurfaceAlpha8(tileSourceRect.Size);
                            }
                            if (tileData.MaskRenderTarget == null)
                            {
                                cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
                                tileData.MaskRenderTarget = RenderTarget.FromSurface(tileData.Mask, FactorySource.PerThread);
                            }
                            if (dc == null)
                            {
                                cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
                                dc = DrawingContext.FromRenderTarget(tileData.MaskRenderTarget);
                                dc.UseTranslateTransform((float)-tileSourceRect.X, (float)-tileSourceRect.Y, MatrixMultiplyOrder.Prepend);
                                dc.AntialiasMode = AntialiasMode.Aliased;
                            }
                            int        valueOrDefault = nullable.GetValueOrDefault();
                            RectDouble bounds         = this.renderData.StrokeSamples[valueOrDefault].GetBounds(size);
                            RectDouble num9           = this.stamp.Antialiased ? bounds : RectDouble.Round(bounds, MidpointRounding.AwayFromZero);
                            cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
                            RectDouble?srcRect = null;
                            dc.FillOpacityMask(this.lazyStampMaskDevBitmap.CancelableValue <DeviceBitmap>(), whiteBrush, OpacityMaskContent.Graphics, new RectDouble?(num9), srcRect);
                        }
                    }
                }
                finally
                {
                    DisposableUtil.Free <IDrawingContext>(ref dc);
                }
            }
            tileData.CurrencyToken = newCurrencyToken;
        }
        protected override void Dispose(bool disposing)
        {
            if (!this.leaveOpen)
            {
                DisposableUtil.Free(ref this.textWriter, disposing);
            }

            base.Dispose(disposing);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                DisposableUtil.Free(ref this.image);
            }

            base.Dispose(disposing);
        }
Ejemplo n.º 19
0
 protected override void Dispose(bool disposing)
 {
     if (disposing && (this.document != null))
     {
         this.Document = null;
     }
     DisposableUtil.Free <ThumbnailManager>(ref this.thumbnailManager, disposing);
     base.Dispose(disposing);
 }
        private bool TryUpdateDeviceBitmap(int tileColumn, int tileRow)
        {
            IRenderTarget renderTarget = this.canvasView.RenderTarget;

            if (renderTarget == null)
            {
                return(false);
            }
            bool flag = renderTarget.IsSupported(RenderTargetType.Software, null, null, null);

            if (!flag && (!this.IsVisible || !this.IsActive))
            {
                throw new PaintDotNet.InternalErrorException();
            }
            if (!this.isDeviceBitmapCurrent[tileRow][tileColumn])
            {
                using (IBitmap <ColorPbgra32> bitmap = this.tileCache.TryGetTileBufferRef(tileColumn, tileRow))
                {
                    if (bitmap != null)
                    {
                        if (bitmap.IsDisposed)
                        {
                            throw new ObjectDisposedException("tileBufferRef");
                        }
                        if (flag)
                        {
                            DisposableUtil.Free <IDeviceBitmap>(ref this.deviceBitmaps[tileRow][tileColumn]);
                            DisposableUtil.Free <IBitmap <ColorPbgra32> >(ref this.tileBuffers[tileRow][tileColumn]);
                            IBitmapLock   bitmapLock = bitmap.Lock <ColorPbgra32>(BitmapLockOptions.Read);
                            IDeviceBitmap bitmap2    = renderTarget.CreateSharedBitmap(bitmapLock, null);
                            this.deviceBitmaps[tileRow][tileColumn] = bitmap2;
                            this.tileBuffers[tileRow][tileColumn]   = bitmap.CreateRef <ColorPbgra32>();
                        }
                        else
                        {
                            ObjectPoolTicket <IDeviceBitmap> ticket = this.deviceBitmapTickets[tileRow][tileColumn];
                            if (ticket == null)
                            {
                                try
                                {
                                    ticket = this.owner.DeviceBitmapPool.Get(bitmap.Size);
                                }
                                catch (RecreateTargetException)
                                {
                                    return(false);
                                }
                                this.deviceBitmapTickets[tileRow][tileColumn] = ticket;
                                this.deviceBitmaps[tileRow][tileColumn]       = ticket.Value;
                            }
                            ticket.Value.CopyFromBitmap(null, bitmap, null);
                        }
                        this.isDeviceBitmapCurrent[tileRow][tileColumn] = true;
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 21
0
 private void DestroyBitmapResources()
 {
     if (this.wheelBackgroundDeviceBitmap != null)
     {
         this.wheelBackgroundDeviceBitmap.BitmapSource = null;
         this.wheelBackgroundDeviceBitmap = null;
     }
     DisposableUtil.Free <ISurface <ColorBgra> >(ref this.wheelBackgroundSurface);
 }
Ejemplo n.º 22
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                DisposableUtil.Free(ref this.heifReaderHandle);
            }

            base.Dispose(disposing);
        }
Ejemplo n.º 23
0
 protected override void OnDeactivate()
 {
     base.ToolSettings.PixelSampleMode.ValueChangedT -= new ValueChangedEventHandler <PixelSampleMode>(this.OnPixelSampleModeValueChangedT);
     DisposableUtil.Free <Surface>(ref this.allLayersRenderSurface);
     base.DocumentCanvas.CanvasLayers.Remove(this.previewRenderer);
     DisposableUtil.Free <PickerPreviewCanvasLayer>(ref this.previewRenderer);
     DisposableUtil.Free <Cursor>(ref this.colorPickerToolCursor);
     base.OnDeactivate();
 }
Ejemplo n.º 24
0
 private void PopTimerScope()
 {
     ((BrushToolBase <TDerived, TChanges, TUI>) this).VerifyAccess <BrushToolBase <TDerived, TChanges, TUI> >();
     if (this.timerResolutionScope == null)
     {
         throw new InvalidOperationException("mismatched push/pop");
     }
     DisposableUtil.Free <TimerResolutionScope>(ref this.timerResolutionScope);
 }
Ejemplo n.º 25
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         DisposableUtil.Free <SelectionHighlightRenderer>(ref this.selectionHighlightRenderer);
         DisposableUtil.Free <ISurface <ColorBgra> >(ref this.renderBuffer);
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 26
0
        public void Rollback()
        {
            object sync = this.sync;

            lock (sync)
            {
                try
                {
                    switch (this.state)
                    {
                    case SaveTransactionState.Initializing:
                    case SaveTransactionState.FailedInitialization:
                    case SaveTransactionState.Committing:
                    case SaveTransactionState.Committed:
                    case SaveTransactionState.RollingBack:
                    case SaveTransactionState.FailedRollback:
                    case SaveTransactionState.RolledBack:
                        throw new InvalidOperationException($"This transaction is not in a state that allows it to be committed ({this.state})");

                    case SaveTransactionState.Initialized:
                    case SaveTransactionState.FailedCommit:
                        break;

                    case SaveTransactionState.Disposed:
                        throw new ObjectDisposedException("SaveTransaction");

                    default:
                        throw new InternalErrorException(new InvalidEnumArgumentException("this.state", (int)this.state, typeof(SaveTransactionState)));
                    }
                    this.state = SaveTransactionState.RollingBack;
                    try
                    {
                        DisposableUtil.Free <GuardedStream>(ref this.guardedStream);
                    }
                    catch (IOException)
                    {
                    }
                    if (this.kernelTx != null)
                    {
                        this.kernelTx.Rollback();
                        this.kernelTx = null;
                    }
                    else if (this.tempPath != null)
                    {
                        File.Delete(this.tempPath);
                    }
                    this.tempPath = null;
                    this.state    = SaveTransactionState.RolledBack;
                }
                catch (Exception)
                {
                    this.state = SaveTransactionState.FailedRollback;
                    throw;
                }
            }
        }
Ejemplo n.º 27
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                DisposableUtil.Free(ref this.heifWriterHandle);
                DisposableUtil.Free(ref this.writerErrors);
            }

            base.Dispose(disposing);
        }
Ejemplo n.º 28
0
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         DisposableUtil.Free <EditableDataWorkItemQueue <PointInt32> >(ref this.workItemQueue);
         Work.QueueDisposeStream((IEnumerable <IDisposable>) this.tileBuffers.SelectMany <IBitmap <ColorPbgra32> >());
         this.tileBuffers = null;
         this.source      = null;
     }
 }
Ejemplo n.º 29
0
            protected override void Dispose(bool disposing)
            {
                if (disposing)
                {
                    DisposableUtil.Free(ref this.successMessage);
                    DisposableUtil.Free(ref this.writeErrorMessage);
                }

                base.Dispose(disposing);
            }
Ejemplo n.º 30
0
 protected override void OnDeactivate()
 {
     DisposableUtil.Free <Cursor>(ref this.cursorZoom);
     DisposableUtil.Free <Cursor>(ref this.cursorZoomIn);
     DisposableUtil.Free <Cursor>(ref this.cursorZoomOut);
     DisposableUtil.Free <Cursor>(ref this.cursorZoomPan);
     base.DocumentCanvas.CanvasLayers.Remove(this.outlineRenderer);
     DisposableUtil.Free <SelectionCanvasLayer>(ref this.outlineRenderer);
     base.OnDeactivate();
 }