private void CalculateLayout(int width, int height)
        {
            rectView.Reset();
            rectView.AddRect(0f, 0f, 1f * Width, 1f * Height, Path.Direction.Cw);

            if (clipManager != null)
            {
                if (width > 0 && height > 0)
                {
                    clipManager.SetupClipLayout(width, height);
                    clipPath.Reset();
                    clipPath.Set(clipManager.CreateMask(width, height));

                    if (RequiresBitmap())
                    {
                        if (clipBitmap != null)
                        {
                            clipBitmap.Recycle();
                        }
                        clipBitmap = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);
                        Canvas canvas = new Canvas(clipBitmap);

                        if (drawable != null)
                        {
                            drawable.SetBounds(0, 0, width, height);
                            drawable.Draw(canvas);
                        }
                        else
                        {
                            canvas.DrawPath(clipPath, clipManager.GetPaint());
                        }
                    }

                    //invert the path for android P
                    if (Build.VERSION.SdkInt > BuildVersionCodes.OMr1)
                    {
                        bool success = rectView.InvokeOp(clipPath, Path.Op.Difference);
                    }

                    //this needs to be fixed for 25.4.0
                    if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop && ViewCompat.GetElevation(this) > 0f)
                    {
                        try
                        {
                            OutlineProvider = new CustomOutlineProvider(clipManager);
                        }
                        catch
                        {
                            //
                        }
                    }
                }
            }

            PostInvalidate();
        }
        public void Draw(AView view, Canvas canvas, Action dispatchDraw)
        {
            if (PathProvider == null)
            {
                return;
            }

            InitializeClipPath(canvas.Width, canvas.Height);

            var saveCount = canvas.SaveLayer(0, 0, canvas.Width, canvas.Height, null);

            dispatchDraw();
            canvas.DrawPath(_maskPath, _maskPaint);
            canvas.RestoreToCount(saveCount);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop && ViewCompat.GetElevation(view) > 0)
            {
                view.OutlineProvider = _clipPath.IsConvex ? new PathOutlineProvider(PathProvider) : null;
            }
        }