Esempio n. 1
0
        public void Clear()
        {
            using (LockWrite())
            {
                _write?.Dispose();
                _write = null;
            }
            using (LockRead())
            {
                _read?.Dispose();
                _read = null;
            }

            NotifyUpdated();
        }
Esempio n. 2
0
        /// <inheritdoc />
        public virtual IFramebufferReference GrabFramebufferReference(Size size, IImmutableSet <Screen> layout)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(RfbRenderTarget));
            }

            PixelSize requiredPixelSize = Conversions.GetPixelSize(size);

            // Creation of a new buffer necessary?
            // No synchronization necessary, because the only conflicting write operation is
            // in this same method and the field is marked volatile to avoid caching issues.
            // ReSharper disable once InconsistentlySynchronizedField
            bool sizeChanged = _bitmap == null || _bitmap.PixelSize != requiredPixelSize;

            WriteableBitmap bitmap;

            if (sizeChanged)
            {
                // Create new bitmap with required size and the format that is preferred by the current platform (therefore 'null').
                // TODO: Detect DPI dynamically
                bitmap = new WriteableBitmap(requiredPixelSize, new Vector(96.0f, 96.0f), null);

                // Wait for the rendering being finished before replacing the bitmap
                lock (_bitmapReplacementLock)
                {
                    _bitmap?.Dispose();
                    _bitmap = bitmap;
                }
            }
            else
            {
                // ReSharper disable once InconsistentlySynchronizedField
                bitmap = _bitmap !;
            }

            // Lock framebuffer and return as converted reference
            // ReSharper disable once InconsistentlySynchronizedField
            ILockedFramebuffer lockedFramebuffer = bitmap.Lock();

            return(new AvaloniaFramebufferReference(lockedFramebuffer, () => Dispatcher.UIThread.Post(() => {
                if (sizeChanged)
                {
                    InvalidateMeasure();
                }
                InvalidateVisual();
            })));
        }
Esempio n. 3
0
 public void Dispose()
 {
     _isDisposed = true;
     AvaloniaLocator.Current.GetService <IRenderTimer>().Tick -= RenderTick;
     this._bgWorker?.SendCommand(BgWorkerCommand.Dispose);
     _targetBitmap?.Dispose();
 }
        public override void Render(DrawingContext context)
        {
            if (_lastFrame != null && _lastFrame.Width != 0 && _lastFrame.Height != 0)
            {
                var fmt = (PixelFormat)_lastFrame.Format;
                if (_bitmap == null || _bitmap.PixelSize.Width != _lastFrame.Width ||
                    _bitmap.PixelSize.Height != _lastFrame.Height)
                {
                    _bitmap?.Dispose();
#pragma warning disable CS0618 // Type or member is obsolete
                    _bitmap = new WriteableBitmap(new PixelSize(_lastFrame.Width, _lastFrame.Height),
                                                  new Vector(96, 96), fmt);
#pragma warning restore CS0618 // Type or member is obsolete
                }
                using (var l = _bitmap.Lock())
                {
                    var lineLen = (fmt == PixelFormat.Rgb565 ? 2 : 4) * _lastFrame.Width;
                    for (var y = 0; y < _lastFrame.Height; y++)
                    {
                        Marshal.Copy(_lastFrame.Data, y * _lastFrame.Stride,
                                     new IntPtr(l.Address.ToInt64() + l.RowBytes * y), lineLen);
                    }
                }
                context.DrawImage(_bitmap, new Rect(0, 0, _bitmap.PixelSize.Width, _bitmap.PixelSize.Height),
                                  new Rect(Bounds.Size));
            }
            base.Render(context);
        }
Esempio n. 5
0
            private void UpdateBitmapSize(bool borderBlocks)
            {
                WriteableBitmap bmp       = borderBlocks ? BorderBlocksBitmap : BlocksBitmap;
                int             bmpWidth  = (borderBlocks ? BorderWidth : Width) * Overworld.Block_NumPixelsX;
                int             bmpHeight = (borderBlocks ? BorderHeight : Height) * Overworld.Block_NumPixelsY;
                bool            createNew;

                if (bmp == null)
                {
                    createNew = true;
                }
                else
                {
                    PixelSize ps = bmp.PixelSize;
                    createNew = ps.Width != bmpWidth || ps.Height != bmpHeight;
                }
                if (createNew)
                {
                    bmp?.Dispose();
                    bmp = new WriteableBitmap(new PixelSize(bmpWidth, bmpHeight), new Vector(96, 96), PixelFormat.Bgra8888);
                    if (borderBlocks)
                    {
                        BorderBlocksBitmap = bmp;
                    }
                    else
                    {
                        BlocksBitmap = bmp;
                    }
                    DrawAll(borderBlocks, true);
                }
            }
Esempio n. 6
0
 // TODO: This isn't called
 public void Dispose()
 {
     if (!_isDisposed)
     {
         _isDisposed = true;
         _screen.Dispose();
     }
 }
Esempio n. 7
0
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         GC.SuppressFinalize(this);
     }
     Bitmap.Dispose();
 }
        protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
        {
            base.OnDetachedFromLogicalTree(e);

            _unpremulBitmap?.Dispose();
            _unpremulBitmap = null;

            _premulBitmap?.Dispose();
            _unpremulBitmap = null;
        }
Esempio n. 9
0
        private bool UpdateBitmapSize()
        {
            int bmpHeight = GetBitmapHeight();

            if (Bitmap == null || Bitmap.PixelSize.Height != bmpHeight)
            {
                Bitmap?.Dispose();
                Bitmap = new WriteableBitmap(new PixelSize(BitmapNumBlocksX * Overworld.Block_NumPixelsX, bmpHeight), new Vector(96, 96), PixelFormat.Bgra8888);
                return(true);
            }
            return(false);
        }
Esempio n. 10
0
        private WriteableBitmap GetSurface(PixelBuffer pixelBuffer)
        {
            if (!Monitor.IsEntered(_syncRoot))
            {
                throw new InvalidOperationException();
            }

            WriteableBitmap surface = pixelBuffer.Surface;

            if (surface is null || surface.PixelSize != new PixelSize(pixelBuffer.Width, pixelBuffer.Height))
            {
                surface?.Dispose();
                surface             = new WriteableBitmap(new PixelSize(pixelBuffer.Width, pixelBuffer.Height), OffscreenGraphics.DpiScale.Dpi, PixelFormat.Bgra8888, AlphaFormat.Premul);
                pixelBuffer.Surface = surface;
            }

            using (ILockedFramebuffer frameBuffer = surface.Lock())
            {
                Marshal.Copy(pixelBuffer.DIB, 0, frameBuffer.Address, pixelBuffer.Size);
                pixelBuffer.ClearDirtyRectangle();
            }
            return(surface);
        }
Esempio n. 11
0
 public void Dispose()
 {
     Closed?.Invoke();
     _lastRenderedFrame?.Dispose();
     _lastRenderedFrame = null;
 }
Esempio n. 12
0
 public void Dispose()
 {
     _bitmap.Dispose();
     _selection.Changed -= OnSelectionChanged;
     ClipboardChanged    = null;
 }
Esempio n. 13
0
 public void Dispose()
 {
     _isDisposed = true;
     _bgWorker?.SendCommand(BgWorkerCommand.Dispose);
     _targetBitmap?.Dispose();
 }
Esempio n. 14
0
 public void Dispose()
 {
     _stream?.Dispose();
     _gifDecoder?.Dispose();
     _targetBitmap?.Dispose();
 }
Esempio n. 15
0
 protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
 {
     bmp?.Dispose();
     bmp = null;
     base.OnDetachedFromLogicalTree(e);
 }