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); }
public static IBitmap <TPixel> CreateRef <TPixel>(this IBitmap <TPixel> objectRef) where TPixel : struct, INaturalPixelInfo => ((IBitmap <TPixel>)objectRef.CreateRef(typeof(IBitmap <TPixel>)));
public static IBitmap CreateRef(this IBitmap objectRef) => ((IBitmap)objectRef.CreateRef(typeof(IBitmap)));
public PlacedBitmap(IBitmap bitmap, RectDouble layoutRect, bool assumeOwnership) { this.bitmap = assumeOwnership ? bitmap : bitmap.CreateRef(); this.layoutRect = layoutRect; }