Exemplo n.º 1
0
        private void Render(bool shouldRecompose, bool shouldRetry)
        {
            var interpolationMode = false ? BitmapInterpolationMode.Linear : BitmapInterpolationMode.NearestNeighbor;

            _windowRenderTarget.BeginDraw();

            if (BorderVisible)
            {
                CreateCompositeRenderTarget();

                _compositeRenderTarget.BeginDraw();
                _compositeRenderTarget.Clear(_clearColor);
                _compositeRenderTarget.DrawBitmap(_screenRenderTarget.Bitmap, new RawRectangleF(48, 40, 48 + 160, 40 + 144), 1.0f, BitmapInterpolationMode.NearestNeighbor);
                _compositeRenderTarget.DrawBitmap(_borderBitmap, 1.0f, BitmapInterpolationMode.NearestNeighbor);
                _compositeRenderTarget.EndDraw();
                _windowRenderTarget.DrawBitmap(_compositeRenderTarget.Bitmap, _drawRectangle, 1.0f, interpolationMode);
            }
            else
            {
                _windowRenderTarget.DrawBitmap(_screenRenderTarget.Bitmap, _drawRectangle, 1.0f, interpolationMode);
            }

            try { _windowRenderTarget.EndDraw(); }
            catch (COMException)
            {
                // If needed, try to recreate the target.
                ResetRendering();
                // Try to render again, but only once. (We don't want to enter an infinite recursion… AKA Stack Overflow)
                if (shouldRetry)
                {
                    Render(true, false);
                }
            }
        }
Exemplo n.º 2
0
        private void UpdateScreenAndPresent(object state)
        {
            SwapBitmaps();

            _screenBitmap1.CopyFromMemory(_screenBuffer, 160 * 4);

            _screenRenderTarget.BeginDraw();
            _screenRenderTarget.DrawBitmap(_screenBitmap2, new RawRectangleF(0, 0, 160, 144), 1.0f, BitmapInterpolationMode.NearestNeighbor);
            _screenRenderTarget.DrawBitmap(_screenBitmap1, new RawRectangleF(0, 0, 160, 144), 0.5f, BitmapInterpolationMode.NearestNeighbor);
            _screenRenderTarget.EndDraw();

            Render(true);

            HandleCompletion(state);
        }
Exemplo n.º 3
0
        public ImageBrushImpl(
            ImageBrush brush,
            SharpDX.Direct2D1.RenderTarget target,
            Size targetSize)
        {
            if (brush.Source == null)
            {
                return;
            }

            var image            = ((BitmapImpl)brush.Source.PlatformImpl).GetDirect2DBitmap(target);
            var imageSize        = new Size(brush.Source.PixelWidth, brush.Source.PixelHeight);
            var tileMode         = brush.TileMode;
            var sourceRect       = brush.SourceRect.ToPixels(imageSize);
            var destinationRect  = brush.DestinationRect.ToPixels(targetSize);
            var scale            = brush.Stretch.CalculateScaling(destinationRect.Size, sourceRect.Size);
            var translate        = CalculateTranslate(brush, sourceRect, destinationRect, scale);
            var intermediateSize = CalculateIntermediateSize(tileMode, targetSize, destinationRect.Size);
            var brtOpts          = CompatibleRenderTargetOptions.None;

            // TODO: There are times where we don't need to draw an intermediate bitmap. Identify
            // them and directly use 'image' in those cases.
            using (var intermediate = new BitmapRenderTarget(target, brtOpts, intermediateSize))
            {
                Rect drawRect;
                var  transform = CalculateIntermediateTransform(
                    tileMode,
                    sourceRect,
                    destinationRect,
                    scale,
                    translate,
                    out drawRect);

                intermediate.BeginDraw();
                intermediate.PushAxisAlignedClip(drawRect.ToDirect2D(), AntialiasMode.Aliased);
                intermediate.Transform = transform.ToDirect2D();
                intermediate.DrawBitmap(image, 1, BitmapInterpolationMode.Linear);
                intermediate.PopAxisAlignedClip();
                intermediate.EndDraw();

                this.PlatformBrush = new BitmapBrush(
                    target,
                    intermediate.Bitmap,
                    GetBitmapBrushProperties(brush),
                    GetBrushProperties(brush, destinationRect));
            }
        }