예제 #1
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);
        }
        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);
        }
예제 #3
0
        private void ReturnOrFreeDeviceBitmap(ref IDeviceBitmap deviceBitmap)
        {
            object obj2;

            if (((deviceBitmap != null) && AttachedData.TryGetValue(deviceBitmap, isPooledBitmapAttachedKey, out obj2)) && ((bool)obj2))
            {
                this.deviceBitmapPool.Enqueue(deviceBitmap);
                deviceBitmap = null;
            }
            DisposableUtil.Free <IDeviceBitmap>(ref deviceBitmap);
        }
예제 #4
0
 private void GetInitializedRenderBitmaps(IDeviceResourceFactory factory, out IDeviceBitmap interiorDeviceBitmap, out IDeviceBitmap blackDashedOutlineDeviceBitmap, out IDeviceBitmap whiteDashedOutlineDeviceBitmap)
 {
     interiorDeviceBitmap           = this.InitializeDeviceBitmap(factory, this.renderedInteriorMask, ref this.renderedInteriorDeviceBitmap);
     blackDashedOutlineDeviceBitmap = null;
     whiteDashedOutlineDeviceBitmap = null;
     if (this.renderedDashedOutlineMasks != null)
     {
         int num   = this.renderedRenderParams.IsOutlineAnimated ? base.Owner.GetOutlineDashOffset(base.CanvasView) : 0;
         int index = num % SelectionCanvasLayer.DashLength;
         int num3  = (num + (SelectionCanvasLayer.DashLength / 2)) % SelectionCanvasLayer.DashLength;
         if (this.renderedDashedOutlineDeviceBitmaps == null)
         {
             this.renderedDashedOutlineDeviceBitmaps = new IDeviceBitmap[this.renderedDashedOutlineMasks.Length];
         }
         blackDashedOutlineDeviceBitmap = this.InitializeDeviceBitmap(factory, this.renderedDashedOutlineMasks[index], ref this.renderedDashedOutlineDeviceBitmaps[index]);
         whiteDashedOutlineDeviceBitmap = this.InitializeDeviceBitmap(factory, this.renderedDashedOutlineMasks[num3], ref this.renderedDashedOutlineDeviceBitmaps[num3]);
     }
 }
        public void Render(IDrawingContext dc, RectFloat clipRect, float opacity, BitmapInterpolationMode interpolationMode)
        {
            if (!this.beforeRenderCalled || this.afterRenderCalled)
            {
                throw new PaintDotNet.InternalErrorException();
            }
            this.renderCalled = true;
            if (this.isRendering)
            {
                throw new InvalidOperationException("Render() is not reentrant");
            }
            RectInt32 sourceRect = RectInt32.Intersect(clipRect.Int32Bound, this.owner.Document.Bounds());

            if (sourceRect.HasPositiveArea)
            {
                this.isRendering = true;
                try
                {
                    bool flag = dc.IsSupported(RenderTargetType.Software, null, null, null);
                    foreach (PointInt32 num3 in this.tileMathHelper.EnumerateTileOffsets(sourceRect))
                    {
                        if (flag)
                        {
                            IBitmap <ColorPbgra32> bitmap2 = this.tileBuffers[num3.Y][num3.X];
                            if ((bitmap2 != null) && bitmap2.IsDisposed)
                            {
                                continue;
                            }
                        }
                        IDeviceBitmap bitmap = this.deviceBitmaps[num3.Y][num3.X];
                        if (bitmap != null)
                        {
                            RectInt32 tileSourceRect = this.tileMathHelper.GetTileSourceRect(num3.X, num3.Y);
                            RectFloat?srcRect        = null;
                            dc.DrawBitmap(bitmap, new RectFloat?(tileSourceRect), opacity, interpolationMode, srcRect);
                        }
                    }
                }
                finally
                {
                    this.isRendering = false;
                }
            }
        }
예제 #6
0
 public void DrawBitmap(IDeviceBitmap bitmap, RectFloat?dstRect, float opacity, BitmapInterpolationMode interpolationMode, RectFloat?srcRect)
 {
     base.innerRefT.DrawBitmap(bitmap, dstRect, opacity, interpolationMode, srcRect);
 }
예제 #7
0
 public IDeviceBitmap CreateSharedBitmap(IDeviceBitmap bitmap, BitmapProperties?bitmapProperties) =>
 base.innerRefT.CreateSharedBitmap(bitmap, bitmapProperties);
예제 #8
0
 public IBitmapBrush CreateBitmapBrush(IDeviceBitmap bitmap, BitmapBrushProperties?bitmapBrushProperties, BrushProperties?brushProperties) =>
 base.innerRefT.CreateBitmapBrush(bitmap, bitmapBrushProperties, brushProperties);
예제 #9
0
 public void FillOpacityMask(IDeviceBitmap opacityMask, IBrush brush, OpacityMaskContent content, RectFloat?dstRect, RectFloat?srcRect)
 {
     base.innerRefT.FillOpacityMask(opacityMask, brush, content, dstRect, srcRect);
 }
 private void DisposeDeviceBitmap(SizeInt32 size, IDeviceBitmap deviceBitmap)
 {
     deviceBitmap.Dispose();
 }
 public static IDeviceBitmap CreateRef(this IDeviceBitmap objectRef) =>
 ((IDeviceBitmap)objectRef.CreateRef(typeof(IDeviceBitmap)));
예제 #12
0
 private IDeviceBitmap InitializeDeviceBitmap(IDeviceResourceFactory factory, IBitmap bitmap, ref IDeviceBitmap deviceBitmap)
 {
     if (bitmap == null)
     {
         this.ReturnOrFreeDeviceBitmap(ref deviceBitmap);
         return(deviceBitmap);
     }
     if ((bitmap != null) && (deviceBitmap == null))
     {
         if (factory.IsSupported(RenderTargetType.Software, null, null, null))
         {
             SizeInt32   num        = bitmap.Size;
             IBitmapLock bitmapLock = bitmap.Lock(BitmapLockOptions.Read);
             deviceBitmap = factory.CreateSharedBitmap(bitmapLock, new BitmapProperties?(maskBitmapProperties));
             return(deviceBitmap);
         }
         SizeInt32 size = bitmap.Size;
         deviceBitmap = this.GetOrCreateDeviceBitmap(factory, size);
         deviceBitmap.CopyFromBitmap(new PointInt32?(PointInt32.Zero), bitmap, new RectInt32(PointInt32.Zero, size));
     }
     return(deviceBitmap);
 }