Exemple #1
0
        public void flush(uiPicture picture)
        {
            this._reset();
            this._resetRenderTextureId();

            this._drawUIPicture(picture, false);

            D.assert(this._layers.Count == 1);
            D.assert(this._layers[0].states.Count == 1);

            var layer = this._currentLayer;

            using (var cmdBuf = new CommandBuffer()) {
                cmdBuf.name = "CommandBufferCanvas";

                this._lastRtID = -1;
                this._drawLayer(layer, cmdBuf);

                // this is necessary for webgl2. not sure why... just to be safe to disable the scissor.
                cmdBuf.DisableScissorRect();

                Graphics.ExecuteCommandBuffer(cmdBuf);
            }

            D.assert(this._layers.Count == 0 || (this._layers.Count == 1 && this._layers[0] == this._currentLayer));
            if (this._currentLayer != null)
            {
                this._clearLayer(this._currentLayer);
                ObjectPool <RenderLayer> .release(this._currentLayer);

                this._currentLayer = null;
                this._lastScissor  = null;
                this._layers.Clear();
            }
        }
Exemple #2
0
        void _drawUIPicture(uiPicture picture, bool needsSave = true)
        {
            if (needsSave)
            {
                this._save();
            }

            int saveCount = 0;

            var drawCmds = picture.drawCmds;

            foreach (var drawCmd in drawCmds)
            {
                switch (drawCmd)
                {
                case uiDrawSave _:
                    saveCount++;
                    this._save();
                    break;

                case uiDrawSaveLayer cmd: {
                    saveCount++;
                    this._saveLayer(cmd.rect.Value, cmd.paint);
                    break;
                }

                case uiDrawRestore _: {
                    saveCount--;
                    if (saveCount < 0)
                    {
                        throw new Exception("unmatched save/restore in picture");
                    }

                    this._restore();
                    break;
                }

                case uiDrawTranslate cmd: {
                    this._translate(cmd.dx, cmd.dy);
                    break;
                }

                case uiDrawScale cmd: {
                    this._scale(cmd.sx, cmd.sy);
                    break;
                }

                case uiDrawRotate cmd: {
                    this._rotate(cmd.radians, cmd.offset);
                    break;
                }

                case uiDrawSkew cmd: {
                    this._skew(cmd.sx, cmd.sy);
                    break;
                }

                case uiDrawConcat cmd: {
                    this._concat(cmd.matrix.Value);
                    break;
                }

                case uiDrawResetMatrix _:
                    this._resetMatrix();
                    break;

                case uiDrawSetMatrix cmd: {
                    this._setMatrix(cmd.matrix.Value);
                    break;
                }

                case uiDrawClipRect cmd: {
                    this._clipUIRect(cmd.rect.Value);
                    break;
                }

                case uiDrawClipRRect cmd: {
                    this._clipRRect(cmd.rrect);
                    break;
                }

                case uiDrawClipPath cmd: {
                    this._clipPath(cmd.path);
                    break;
                }

                case uiDrawPath cmd: {
                    this._drawPath(cmd.path, cmd.paint);
                    break;
                }

                case uiDrawImage cmd: {
                    this._drawImage(cmd.image, cmd.offset.Value, cmd.paint);
                    break;
                }

                case uiDrawImageRect cmd: {
                    this._drawImageRect(cmd.image, cmd.src, cmd.dst.Value, cmd.paint);
                    break;
                }

                case uiDrawImageNine cmd: {
                    this._drawImageNine(cmd.image, cmd.src, cmd.center.Value, cmd.dst.Value, cmd.paint);
                    break;
                }

                case uiDrawPicture cmd: {
                    this._drawPicture(cmd.picture);
                    break;
                }

                case uiDrawTextBlob cmd: {
                    this._drawTextBlob(cmd.textBlob, cmd.offset.Value, cmd.paint);
                    break;
                }

                default:
                    throw new Exception("unknown drawCmd: " + drawCmd);
                }
            }

            if (saveCount != 0)
            {
                throw new Exception("unmatched save/restore in picture");
            }

            if (needsSave)
            {
                this._restore();
            }
        }