private void UpdateShadeInfo(Shade shade) { if (!_weakSource.TryGetTarget(out var source)) { return; } InternalLogger.Debug(LogTag, () => $"UpdateShadeInfo( shade: {shade} )"); _shadeInfos[shade] = ShadeInfo.FromShade(Context, shade, _cornerRadius, source); }
private void InsertBitmap(Shade shade) { if (!_weakSource.TryGetTarget(out var source) || !HasMinimumSize(source)) { return; } #if DEBUG var stopWatch = new Stopwatch(); stopWatch.Start(); #endif InternalLogger.Debug(LogTag, () => $"InsertBitmap( shade: {shade}, sourceWidth: {source.MeasuredWidth}, sourceHeight: {source.MeasuredHeight})"); var shadeInfo = ShadeInfo.FromShade(Context, shade, _cornerRadius, source); _shadeInfos.Add(shade, shadeInfo); _cache.Add(shadeInfo.Hash, () => CreateBitmap(shadeInfo)); #if DEBUG LogPerf(LogTag, stopWatch); #endif }
private Bitmap CreateBitmap(ShadeInfo shadeInfo) { #if DEBUG var stopWatch = new Stopwatch(); stopWatch.Start(); #endif var shadow = Bitmap.CreateBitmap( shadeInfo.Width, shadeInfo.Height, Bitmap.Config.Argb8888); InternalLogger.Debug(LogTag, () => $"CreateBitmap( shadeInfo: {shadeInfo} )"); RectF rect = new RectF( ShadeInfo.Padding, ShadeInfo.Padding, shadeInfo.Width - ShadeInfo.Padding, shadeInfo.Height - ShadeInfo.Padding); using var bitmapCanvas = new Canvas(shadow); using var paint = new Paint { Color = shadeInfo.Color }; bitmapCanvas.DrawRoundRect( rect, _cornerRadius, _cornerRadius, paint); if (shadeInfo.BlurRadius < 1) { return(shadow); } const int MaxBlur = 25; float blurAmount = shadeInfo.BlurRadius > MaxRadius ? MaxRadius : shadeInfo.BlurRadius; while (blurAmount > 0) { Allocation input = Allocation.CreateFromBitmap( _renderScript, shadow, Allocation.MipmapControl.MipmapNone, AllocationUsage.Script); Allocation output = Allocation.CreateTyped(_renderScript, input.Type); ScriptIntrinsicBlur script = ScriptIntrinsicBlur.Create(_renderScript, Element.U8_4(_renderScript)); float blurRadius; if (blurAmount > MaxBlur) { blurRadius = MaxBlur; blurAmount -= MaxBlur; } else { blurRadius = blurAmount; blurAmount = 0; } script.SetRadius(blurRadius); script.SetInput(input); script.ForEach(output); output.CopyTo(shadow); } #if DEBUG LogPerf(LogTag, stopWatch); #endif return(shadow); }