private void Render(bool forceUpdateWindow = false) { if (_view_height == 0 || _view_width == 0) { return; } var templateBmp = _parentWindowIsFocused ? _decorator.ActiveBitmapTemplate : _decorator.InactiveBitmapTemplate; var matrix = GetShadowMetrics(templateBmp, _view_width, _view_height); CreateDeviceResource(); var tplBitmap = _parentWindowIsFocused ? _cachedActiveBmp : _cachedInactiveBmp; _renderTarget.BeginDraw(); _renderTarget.Clear(Color.Transparent); if (_side == ShadowDockPositon.Bottom || _side == ShadowDockPositon.Top) { _renderTarget.DrawBitmap(tplBitmap, new RawRectF(matrix.destNearCornerRect.X, matrix.destNearCornerRect.Y, matrix.destNearCornerRect.Right, matrix.destNearCornerRect.Bottom), 1.0f, BitmapInterpolationMode.Linear, new RawRectF(matrix.srcNearCornerRect.X, matrix.srcNearCornerRect.Y, matrix.srcNearCornerRect.Right, matrix.srcNearCornerRect.Bottom)); _renderTarget.DrawBitmap(tplBitmap, new RawRectF(matrix.destFarCornerRect.X, matrix.destFarCornerRect.Y, matrix.destFarCornerRect.Right, matrix.destFarCornerRect.Bottom), 1.0f, BitmapInterpolationMode.Linear, new RawRectF(matrix.srcFarCornerRect.X, matrix.srcFarCornerRect.Y, matrix.srcFarCornerRect.Right, matrix.srcFarCornerRect.Bottom)); _renderTarget.DrawBitmap(tplBitmap, new RawRectF(matrix.destRect.X, matrix.destRect.Y, matrix.destRect.Right, matrix.destRect.Bottom), 1.0f, BitmapInterpolationMode.Linear, new RawRectF(matrix.srcRect.X, matrix.srcRect.Y, matrix.srcRect.Right, matrix.srcRect.Bottom)); } else { _renderTarget.DrawBitmap(tplBitmap, new RawRectF(matrix.destNearCornerRect.X, matrix.destNearCornerRect.Y, matrix.destNearCornerRect.Right, matrix.destNearCornerRect.Bottom), 1.0f, BitmapInterpolationMode.Linear, new RawRectF(matrix.srcNearCornerRect.X, matrix.srcNearCornerRect.Y, matrix.srcNearCornerRect.Right, matrix.srcNearCornerRect.Bottom)); _renderTarget.DrawBitmap(tplBitmap, new RawRectF(matrix.destFarCornerRect.X, matrix.destFarCornerRect.Y, matrix.destFarCornerRect.Right, matrix.destFarCornerRect.Bottom), 1.0f, BitmapInterpolationMode.Linear, new RawRectF(matrix.srcFarCornerRect.X, matrix.srcFarCornerRect.Y, matrix.srcFarCornerRect.Right, matrix.srcFarCornerRect.Bottom)); _renderTarget.DrawBitmap(tplBitmap, new RawRectF(matrix.destRect.X, matrix.destRect.Y, matrix.destRect.Right, matrix.destRect.Bottom), 1.0f, BitmapInterpolationMode.Linear, new RawRectF(matrix.srcRect.X, matrix.srcRect.Y, matrix.srcRect.Right, matrix.srcRect.Bottom)); } if (_renderTarget.EndDraw().Failure) { DiscardDeviceResource(); } GC.Collect(); if (forceUpdateWindow) { UpdateLayeredWindow(); } }
protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height) { if (width <= 0 || height <= 0) { return; } var handle = _owner.HostWindowHandle; 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(); } 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)); } if (_renderTarget.EndDraw().Failure) { DiscardDeviceResources(); } unsafe { var rect = new RECT(); User32.GetWindowRect(handle, ref rect); var newLocation = new POINT(rect.left, rect.top); var newSize = new SIZE(rect.Width, rect.Height); var zeroPoint = new POINT(0, 0); if (rect.Width == 0 || rect.Height == 0) { return; } var blend = new BLENDFUNCTION { BlendOp = AcSrcOver, BlendFlags = 0, SourceConstantAlpha = 255, AlphaFormat = AcSrcAlpha }; var ulwi = new UPDATELAYEREDWINDOWINFO { cbSize = Marshal.SizeOf(typeof(UPDATELAYEREDWINDOWINFO)), hdcDst = _screenDC, pptDst = &newLocation, psize = &newSize, hdcSrc = _memDC, pptSrc = &zeroPoint, //crKey = new COLORREF(0), pblend = &blend, dwFlags = BlendFlags.ULW_ALPHA, prcDirty = null }; User32.UpdateLayeredWindowIndirect(_owner.HostWindowHandle, ref ulwi); } GC.Collect(); }