public override void SwitchBackToDefaultBuffer(DrawboardBuffer backbuffer)
        {
#if DEBUG
            if (dbugSwitchCount == 0)
            {
            }
            dbugSwitchCount--;
#endif

            SaveContext saveContext = _saveContexts.Pop();
            _canvasOriginX   = saveContext.prevCanvasOrgX;
            _canvasOriginY   = saveContext.prevCanvasOrgY;
            _currentClipRect = saveContext.prevClipRect;

            _gpuPainter.PainterContext.AttachToRenderSurface(saveContext.prevGLRenderSurface);
            _gpuPainter.PainterContext.OriginKind = RenderSurfaceOrientation.LeftTop;
            _gpuPainter.UpdatePainterContext();

            _left   = 0;
            _top    = 0;
            _width  = _gpuPainter.Width;
            _height = _gpuPainter.Height;


            _gpuPainter.SetOrigin(_canvasOriginX, _canvasOriginY);
            SetClipRect(_currentClipRect);
        }
        public override void AttachToBackBuffer(DrawboardBuffer backbuffer)
        {
#if DEBUG
            if (dbugSwitchCount > 0)
            {
            }
            dbugSwitchCount++;
#endif

            //save prev context
            SaveContext prevContext = new SaveContext();
            prevContext.prevClipRect        = _currentClipRect;
            prevContext.prevCanvasOrgX      = _canvasOriginX;
            prevContext.prevCanvasOrgY      = _canvasOriginY;
            prevContext.prevGLRenderSurface = _gpuPainter.PainterContext.CurrentRenderSurface;
            _saveContexts.Push(prevContext);

            //_prevClipRect = _currentClipRect;
            _currentClipRect = new Rectangle(0, 0, backbuffer.Width, backbuffer.Height);
            MyGLBackbuffer glBackBuffer = (MyGLBackbuffer)backbuffer;

            _gpuPainter.PainterContext.AttachToRenderSurface(glBackBuffer.RenderSurface);
            _gpuPainter.PainterContext.OriginKind = RenderSurfaceOrientation.LeftTop;
            _gpuPainter.UpdatePainterContext();

            _left   = 0;
            _top    = 0;
            _width  = _gpuPainter.Width;
            _height = _gpuPainter.Height;


            //_prevCanvasOrgX = _canvasOriginX;
            //_prevCanvasOrgY = _canvasOriginY;

            _canvasOriginX = 0;
            _canvasOriginY = 0;
            _gpuPainter.SetOrigin(0, 0);
            SetClipRect(_currentClipRect);
        }
Exemplo n.º 3
0
        protected override void RenderClientContent(DrawBoard d, UpdateArea updateArea)
        {
            //TODO: review here,
            if (_myHtmlVisualRoot == null)
            {
                return;
            }

            bool useBackbuffer = d.IsGpuDrawBoard;

            //useBackbuffer = false;

            //... TODO: review here, check doc update here?
            _myHtmlVisualRoot.CheckDocUpdate();

            if (useBackbuffer)
            {
                PaintVisitor painter = PaintVisitorStock.GetSharedPaintVisitor(_myHtmlVisualRoot, d);

                if (_builtInBackBuffer == null)
                {
                    _builtInBackBuffer = painter.CreateOffscreenDrawBoard(this.Width, this.Height);
                }

#if DEBUG
                painter.dbugDrawDiagonalBox(Color.Blue, this.X, this.Y, this.Width, this.Height);
#endif
                if (!_builtInBackBuffer.IsValid)
                {
                    //painter.FillRectangle(Color.Red, 0, 0, 100, 100);//debug
                    //painter.DrawText(i.ToString().ToCharArray(), 0, 1, new PointF(0, 0), new SizeF(100, 100)); //debug


                    float backupViewportW = painter.ViewportWidth;       //backup
                    float backupViewportH = painter.ViewportHeight;      //backup

                    painter.EnterNewDrawboardBuffer(_builtInBackBuffer); //*** switch to builtInBackbuffer
                    painter.SetViewportSize(this.Width, this.Height);

                    if (!_hasAccumRect)
                    {
                        _invalidateRect = new Rectangle(0, 0, Width, Height);
                    }

#if DEBUG
                    //System.Diagnostics.Debug.WriteLine("inv_rect:" + _invalidateRect + "," + painter.ToString());
#endif
                    if (painter.PushLocalClipArea(
                            _invalidateRect.Left, _invalidateRect.Top,
                            _invalidateRect.Width, _invalidateRect.Height))
                    {
#if DEBUG
                        //for debug , test clear with random color
                        //another useful technique to see latest clear area frame-by-frame => use random color
                        //painter.Clear(ColorEx.dbugGetRandomColor());

                        painter.Clear(Color.White);
#else
                        painter.Clear(Color.White);
#endif
                        _myHtmlVisualRoot.PerformPaint(painter);

                        painter.PopLocalClipArea();
                    }


                    //
                    _builtInBackBuffer.IsValid = true;
                    _hasAccumRect = false;

                    painter.ExitCurrentDrawboardBuffer();                      //*** switch back
                    painter.SetViewportSize(backupViewportW, backupViewportH); //restore viewport size
                }

                painter.DrawImage(_builtInBackBuffer.GetImage(), 0, 0, this.Width, this.Height);

                PaintVisitorStock.ReleaseSharedPaintVisitor(painter);
            }
#if DEBUG
            else if (dbugPreferSoftwareRenderer && d.IsGpuDrawBoard)
            {
                //TODO: review this again ***
                //test built-in 'shared' software rendering surface
                DrawBoard cpuDrawBoard = null;
                if ((cpuDrawBoard = d.GetCpuBlitDrawBoard()) != null)
                {
                    cpuDrawBoard.Clear(Color.White);
                    PaintVisitor painter = PaintVisitorStock.GetSharedPaintVisitor(_myHtmlVisualRoot, cpuDrawBoard);

                    painter.SetViewportSize(this.Width, this.Height);

#if DEBUG
                    painter.dbugDrawDiagonalBox(Color.Blue, this.X, this.Y, this.Width, this.Height);
#endif


                    _myHtmlVisualRoot.PerformPaint(painter);
                    PaintVisitorStock.ReleaseSharedPaintVisitor(painter);

                    //then copy from cpu to gpu
                    d.BlitFrom(cpuDrawBoard, X, Y, this.Width, this.Height, 0, 0);
                }
            }
#endif
            else
            {
                PaintVisitor painter = PaintVisitorStock.GetSharedPaintVisitor(_myHtmlVisualRoot, d);
                painter.SetViewportSize(this.Width, this.Height);
#if DEBUG
                //System.Diagnostics.Debug.WriteLine(">> 500x500");
                painter.dbugDrawDiagonalBox(Color.Blue, this.X, this.Y, this.Width, this.Height);

                //for debug , test clear with random color
                //another useful technique to see latest clear area frame-by-frame => use random color
                //painter.Clear(Color.FromArgb(255, dbugRandom.Next(0, 255), dbugRandom.Next(0, 255), dbugRandom.Next(0, 255)));
#endif

#if DEBUG
                //System.Diagnostics.Debug.WriteLine("inv_rect:" + _invalidateRect + "," + painter.ToString());
#endif
                //painter.SetClipRect(new Rectangle(0, 0, 200, 200));
                _myHtmlVisualRoot.PerformPaint(painter);
#if DEBUG
                //System.Diagnostics.Debug.WriteLine("<< 500x500");
                //painter.dbugDrawDiagonalBox(Color.Blue, this.X, this.Y, this.Width, this.Height);
#endif
                PaintVisitorStock.ReleaseSharedPaintVisitor(painter);
            }
        }
Exemplo n.º 4
0
 public abstract void SwitchBackToDefaultBuffer(DrawboardBuffer backbuffer);
Exemplo n.º 5
0
 public abstract void AttachToBackBuffer(DrawboardBuffer backbuffer);
Exemplo n.º 6
0
 public void EnterNewDrawboardBuffer(DrawboardBuffer attachToBackbuffer)
 {
     //save
     _drawBoard.EnterNewDrawboardBuffer(attachToBackbuffer);
 }
Exemplo n.º 7
0
 public abstract void EnterNewDrawboardBuffer(DrawboardBuffer backbuffer);
Exemplo n.º 8
0
        protected override void RenderClientContent(DrawBoard d, UpdateArea updateArea)
        {
            if (ContentBox == null)
            {
                return;
            }
            //
            if (EnableDoubleBuffer)
            {
                var painter = new PixelFarm.Drawing.Internal.MicroPainter(d);
                if (_builtInBackBuffer == null)
                {
                    _builtInBackBuffer = painter.CreateOffscreenDrawBoard(this.Width, this.Height);
                }

                if (!_builtInBackBuffer.IsValid)
                {
#if DEBUG
                    System.Diagnostics.Debug.WriteLine("double_buffer_update:" + this.dbug_obj_id + "," + _invalidateRect.ToString());
#endif
                    float backupViewportW = painter.ViewportWidth;  //backup
                    float backupViewportH = painter.ViewportHeight; //backup
                    painter.AttachTo(_builtInBackBuffer);           //*** switch to builtInBackbuffer
                    painter.SetViewportSize(this.Width, this.Height);
                    if (!_hasAccumRect)
                    {
                        _invalidateRect = new Rectangle(0, 0, Width, Height);
                    }

#if DEBUG
                    if (_invalidateRect.Width == 15)
                    {
                    }
#endif

                    //                    if (painter.PushLocalClipArea(
                    //                        _invalidateRect.Left, _invalidateRect.Top,
                    //                        _invalidateRect.Width, _invalidateRect.Height))
                    //                    {
                    //#if DEBUG
                    //                        //for debug , test clear with random color
                    //                        //another useful technique to see latest clear area frame-by-frame => use random color
                    //                        //painter.Clear(Color.FromArgb(255, dbugRandom.Next(0, 255), dbugRandom.Next(0, 255), dbugRandom.Next(0, 255)));

                    //                        canvas.Clear(Color.White);
                    //#else
                    //                        canvas.Clear(Color.White);
                    //#endif

                    //                        base.RenderBoxContent(canvas, updateArea);
                    //                    }

                    //if (painter.PushLocalClipArea(
                    //    _invalidateRect.Left, _invalidateRect.Top,
                    //    _invalidateRect.Width, _invalidateRect.Height))
                    //{
#if DEBUG
                    //for debug , test clear with random color
                    //another useful technique to see latest clear area frame-by-frame => use random color
                    //painter.Clear(Color.FromArgb(255, dbugRandom.Next(0, 255), dbugRandom.Next(0, 255), dbugRandom.Next(0, 255)));

                    d.Clear(Color.White);
#else
                    d.Clear(Color.White);
#endif


                    //Rectangle updateArea2 = new Rectangle(0, 0, _builtInBackBuffer.Width, _builtInBackBuffer.Height);

                    Rectangle backup2 = updateArea.CurrentRect;
                    updateArea.CurrentRect = new Rectangle(0, 0, _builtInBackBuffer.Width, _builtInBackBuffer.Height);
                    RenderElement.Render(ContentBox, d, updateArea);
                    updateArea.CurrentRect = backup2;


                    //}
                    //painter.PopLocalClipArea();
                    //
                    _builtInBackBuffer.IsValid = true;
                    _hasAccumRect = false;

                    painter.AttachToNormalBuffer();                            //*** switch back
                    painter.SetViewportSize(backupViewportW, backupViewportH); //restore viewport size
                }

#if DEBUG
                else
                {
                    System.Diagnostics.Debug.WriteLine("double_buffer_update:" + dbug_obj_id + " use cache");
                }
#endif
                painter.DrawImage(_builtInBackBuffer.GetImage(), 0, 0, this.Width, this.Height);
            }
            else
            {
                RenderElement.Render(ContentBox, d, updateArea);
            }
        }
 public override void AttachToBackBuffer(DrawboardBuffer backbuffer)
 {
     //MyGdiBackbuffer gdiBackbuffer = (MyGdiBackbuffer)backbuffer;
 }
 public override void SwitchBackToDefaultBuffer(DrawboardBuffer backbuffer)
 {
     //throw new NotImplementedException();
 }