public void BeforeRender(RectFloat clipRect)
        {
            if ((!this.afterRenderCalled || this.beforeRenderCalled) || this.renderCalled)
            {
                throw new PaintDotNet.InternalErrorException();
            }
            this.afterRenderCalled  = false;
            this.beforeRenderCalled = true;
            bool flag = this.canvasView.RenderTarget.IsSupported(RenderTargetType.Software, null, null, null);

            if (flag || this.IsActive)
            {
                this.renderStopwatch.Restart();
                RectInt32 num2  = RectInt32.Intersect(clipRect.Int32Bound, this.owner.Document.Bounds());
                bool      flag2 = false;
                if (num2.HasPositiveArea)
                {
                    PointInt32   num7;
                    PointInt32[] array = this.nonCurrentTileOffsets.ToArrayEx <PointInt32>();
                    this.nonCurrentTileOffsets.Clear();
                    PointInt32 sourcePt  = PointDouble.Round(this.owner.Owner.MouseLocation, MidpointRounding.AwayFromZero);
                    PointInt32 comparand = this.tileMathHelper.ConvertSourcePointToTileOffset(sourcePt);
                    CompareTileOffsetsByDistance comparer = new CompareTileOffsetsByDistance(comparand);
                    ListUtil.Sort <PointInt32, ArrayStruct <PointInt32>, CompareTileOffsetsByDistance>(array.AsStruct <PointInt32>(), comparer);
                    DequeSet <PointInt32> set = new DequeSet <PointInt32>(array);
                    int count = set.Count;
                    while (set.TryDequeue(out num7))
                    {
                        if (!this.isDeviceBitmapCurrent[num7.Y][num7.X])
                        {
                            if (flag2)
                            {
                                this.nonCurrentTileOffsets.TryEnqueue(num7);
                            }
                            else
                            {
                                if (!this.TryUpdateDeviceBitmap(num7))
                                {
                                    this.nonCurrentTileOffsets.TryEnqueue(num7);
                                    flag2 = true;
                                }
                                if ((!flag2 && !flag) && (this.renderStopwatch.ElapsedMilliseconds > 0x7fffffffffffffffL))
                                {
                                    flag2 = true;
                                }
                            }
                        }
                    }
                }
            }
        }