コード例 #1
0
        protected override void OnPopupShow(CefBrowser browser, bool show)
        {
            _isPopupShown = show;

            if (show == false)
            {
                _popupRect = null;
                if (_cachedPopupImage != null)
                {
                    _cachedPopupImage.Dispose();
                    _cachedPopupImage = null;
                    GC.Collect();
                }
            }

            base.OnPopupShow(browser, show);
        }
コード例 #2
0
        protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
        {
            if (width <= 0 || height <= 0)
            {
                return;
            }

            CreateDeviceResource();

            _renderTarget.BeginDraw();

            if (type == CefPaintElementType.View)
            {
                var bmp = _renderTarget.CreateBitmap(new Vortice.Mathematics.Size(width, height), buffer, width * 4, new BitmapProperties(new PixelFormat(Vortice.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)));

                if (!_isPopupShown)
                {
                    _renderTarget.Clear(Color.Transparent);
                }

                _renderTarget.DrawBitmap(bmp);


                bmp.Dispose();
            }
            else if (type == CefPaintElementType.Popup)
            {
                var bmp = _renderTarget.CreateBitmap(new Vortice.Mathematics.Size(width, height), buffer, width * 4, new BitmapProperties(new PixelFormat(Vortice.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)));

                if (_cachedPopupImage != null)
                {
                    _cachedPopupImage.Dispose();
                    _cachedPopupImage = null;
                    GC.Collect();
                }

                _cachedPopupImage = _renderTarget.CreateSharedBitmap(bmp, new BitmapProperties
                {
                    PixelFormat = new PixelFormat(Vortice.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)
                });

                bmp.Dispose();
            }

            //var layer = _renderTarget.CreateLayer();
            //var layerParameter = new LayerParameters
            //{
            //    ContentBounds = new Vortice.RawRectF(0, 0, width, height),
            //    Opacity = 1
            //};
            //_renderTarget.PushLayer(ref layerParameter, layer);

            if (_cachedPopupImage != null && _isPopupShown && _popupRect.HasValue)
            {
                var scaleFactor = DpiHelper.GetScaleFactorForCurrentWindow(_owner.HostWindowHandle);
                var x           = _popupRect.Value.X * scaleFactor;
                var y           = _popupRect.Value.Y * scaleFactor;

                var popupWidth  = _popupRect.Value.Width * scaleFactor;
                var popupHeight = _popupRect.Value.Height * scaleFactor;

                var right  = x + popupWidth;
                var bottom = y + popupHeight;

                _renderTarget.DrawBitmap(_cachedPopupImage, new Vortice.RawRectF(x, y, right, bottom), 1f, BitmapInterpolationMode.Linear, new Vortice.RawRectF(0, 0, popupWidth, popupHeight));
            }

            //_renderTarget.PopLayer();

            //layer.Dispose();

            if (_renderTarget.EndDraw().Failure)
            {
                DiscardDeviceResources();
            }
        }