Exemple #1
0
        void _drawPathDrawMeshCallback(uiPaint p, uiMeshMesh fillMesh, uiMeshMesh strokeMesh, bool convex, float alpha,
                                       float strokeMult, Texture tex,
                                       uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji)
        {
            if (!this._applyClip(fillMesh.bounds))
            {
                ObjectPool <uiMeshMesh> .release(fillMesh);

                ObjectPool <uiMeshMesh> .release(strokeMesh);

                return;
            }

            var layer = this._currentLayer;

            if (convex)
            {
                layer.draws.Add(CanvasShader.convexFill(layer, p, fillMesh));
            }
            else
            {
                layer.draws.Add(CanvasShader.fill0(layer, fillMesh));
                layer.draws.Add(CanvasShader.fill1(layer, p, fillMesh.boundsMesh));
            }

            if (strokeMesh != null)
            {
                layer.draws.Add(CanvasShader.strokeAlpha(layer, p, alpha, strokeMult, strokeMesh));
                layer.draws.Add(CanvasShader.stroke1(layer, strokeMesh.duplicate()));
            }
        }
Exemple #2
0
        void _drawTextDrawMeshCallback(uiPaint p, uiMeshMesh fillMesh, uiMeshMesh strokeMesh, bool convex, float alpha,
                                       float strokeMult, Texture tex,
                                       uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji)
        {
            if (!this._applyClip(textBlobBounds))
            {
                ObjectPool <TextBlobMesh> .release(textMesh);

                return;
            }

            var layer = this._currentLayer;

            if (notEmoji)
            {
                layer.draws.Add(CanvasShader.texAlpha(layer, p, textMesh, tex));
            }
            else
            {
                uiPaint paintWithWhite = new uiPaint(p);
                paintWithWhite.color = uiColor.white;
                if (EmojiUtils.image == null)
                {
                    ObjectPool <TextBlobMesh> .release(textMesh);

                    return;
                }

                var raw_mesh = textMesh.resolveMesh();
                var meshmesh = raw_mesh.duplicate();
                ObjectPool <TextBlobMesh> .release(textMesh);

                layer.draws.Add(CanvasShader.tex(layer, paintWithWhite, meshmesh, EmojiUtils.image));
            }
        }
Exemple #3
0
        void _drawWithMaskFilter(uiRect meshBounds, uiPaint paint, uiMaskFilter maskFilter,
                                 uiMeshMesh fillMesh, uiMeshMesh strokeMesh, bool convex, float alpha, float strokeMult, Texture tex,
                                 uiRect texBound, TextBlobMesh textMesh, bool notEmoji,
                                 _drawPathDrawMeshCallbackDelegate drawCallback)
        {
            var layer      = this._currentLayer;
            var clipBounds = layer.layerBounds;

            uiRect?stackBounds;
            bool   iior;

            layer.clipStack.getBounds(out stackBounds, out iior);

            if (stackBounds != null)
            {
                clipBounds = uiRectHelper.intersect(clipBounds, stackBounds.Value);
            }

            if (clipBounds.isEmpty)
            {
                this._drawPathDrawMeshQuit(fillMesh, strokeMesh, textMesh);
                return;
            }

            var   state = layer.currentState;
            float sigma = state.scale * maskFilter.sigma;

            if (sigma <= 0)
            {
                this._drawPathDrawMeshQuit(fillMesh, strokeMesh, textMesh);
                return;
            }

            float sigma3     = 3 * sigma;
            var   maskBounds = uiRectHelper.inflate(meshBounds, sigma3);

            maskBounds = uiRectHelper.intersect(maskBounds, uiRectHelper.inflate(clipBounds, sigma3));
            if (maskBounds.isEmpty)
            {
                this._drawPathDrawMeshQuit(fillMesh, strokeMesh, textMesh);
                return;
            }

            var maskLayer = this._createMaskLayer(layer, maskBounds, drawCallback, paint, convex, alpha, strokeMult,
                                                  tex, texBound,
                                                  textMesh, fillMesh, strokeMesh, notEmoji);

            var blurLayer = this._createBlurLayer(maskLayer, sigma, sigma, layer);

            var blurMesh = ImageMeshGenerator.imageMesh(null, uiRectHelper.one, maskBounds);

            if (!this._applyClip(blurMesh.bounds))
            {
                ObjectPool <uiMeshMesh> .release(blurMesh);

                return;
            }

            layer.draws.Add(CanvasShader.texRT(layer, paint, blurMesh, blurLayer));
        }
Exemple #4
0
        void _drawPathDrawMeshQuit(uiMeshMesh fillMesh, uiMeshMesh strokeMesh, TextBlobMesh textMesh)
        {
            ObjectPool <uiMeshMesh> .release(fillMesh);

            ObjectPool <uiMeshMesh> .release(strokeMesh);

            ObjectPool <TextBlobMesh> .release(textMesh);
        }
        public static TextBlobMesh create(TextBlob textBlob, float scale, uiMatrix3 matrix)
        {
            TextBlobMesh newMesh = ObjectPool <TextBlobMesh> .alloc();

            newMesh.textBlob = textBlob;
            newMesh.scale    = scale;
            newMesh.matrix   = matrix;
            return(newMesh);
        }
Exemple #6
0
        void _drawPathDrawMeshCallback2(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex,
                                        uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji)
        {
            if (!this._applyClip(mesh.bounds))
            {
                ObjectPool <uiMeshMesh> .release(mesh);

                return;
            }

            var layer = this._currentLayer;

            layer.draws.Add(CanvasShader.stroke0(layer, p, alpha, mesh));
            layer.draws.Add(CanvasShader.stroke1(layer, mesh.duplicate()));
        }
Exemple #7
0
        RenderLayer _createMaskLayer(RenderLayer parentLayer, uiRect maskBounds,
                                     _drawPathDrawMeshCallbackDelegate drawCallback,
                                     uiPaint paint, bool convex, float alpha, float strokeMult, Texture tex, uiRect texBound,
                                     TextBlobMesh textMesh,
                                     uiMeshMesh fillMesh, uiMeshMesh strokeMesh, bool notEmoji)
        {
            var textureWidth = Mathf.CeilToInt(maskBounds.width * this._devicePixelRatio);

            if (textureWidth < 1)
            {
                textureWidth = 1;
            }

            var textureHeight = Mathf.CeilToInt(maskBounds.height * this._devicePixelRatio);

            if (textureHeight < 1)
            {
                textureHeight = 1;
            }

            var maskLayer = RenderLayer.create(
                rtID: Shader.PropertyToID(this._getNewRenderTextureKey()),
                width: textureWidth,
                height: textureHeight,
                layerBounds: maskBounds,
                filterMode: FilterMode.Bilinear,
                noMSAA: true
                );

            parentLayer.addLayer(maskLayer);
            this._layers.Add(maskLayer);
            this._currentLayer = maskLayer;

            var parentState = parentLayer.states[parentLayer.states.Count - 1];
            var maskState   = maskLayer.states[maskLayer.states.Count - 1];

            maskState.matrix = parentState.matrix;

            drawCallback.Invoke(uiPaint.shapeOnly(paint), fillMesh, strokeMesh, convex, alpha, strokeMult, tex,
                                texBound, textMesh, notEmoji);

            var removed = this._layers.removeLast();

            D.assert(removed == maskLayer);
            this._currentLayer = this._layers[this._layers.Count - 1];

            return(maskLayer);
        }
Exemple #8
0
        public static PictureFlusher.RenderDraw texAlpha(PictureFlusher.RenderLayer layer, Paint paint,
                                                         MeshMesh mesh, TextBlobMesh textMesh, Texture tex)
        {
            var mat = _texMat.getMaterial(paint.blendMode, layer.ignoreClip);

            _getShaderPassAndProps(layer, paint, mesh, 1.0f, out var pass, out var props);
            tex.filterMode = paint.filterMode;
            props.SetTexture("_tex", tex);
            props.SetInt("_texMode", 2); // alpha only

            return(new PictureFlusher.RenderDraw {
                mesh = mesh,
                textMesh = textMesh,
                pass = pass,
                material = mat,
                properties = props,
            });
        }
Exemple #9
0
        public static PictureFlusher.CmdDraw texAlpha(PictureFlusher.RenderLayer layer, uiPaint paint,
                                                      uiMeshMesh mesh, TextBlobMesh textMesh, Texture tex)
        {
            var mat        = _texMat.getMaterial(paint.blendMode, layer.ignoreClip);
            var meshMatrix = mesh != null ? mesh.matrix : textMesh.matrix;

            _getShaderPassAndProps(layer, paint, meshMatrix, 1.0f, 0.0f, out var pass, out var props);
            tex.filterMode = paint.filterMode;
            props.SetTexture(_texId, tex);
            props.SetInt(_texModeId, 2); // alpha only

            return(PictureFlusher.CmdDraw.create(
                       mesh: mesh,
                       textMesh: textMesh,
                       pass: pass,
                       material: mat,
                       properties: props
                       ));
        }
Exemple #10
0
            public static CmdDraw create(uiMeshMesh mesh = null, TextBlobMesh textMesh = null, int pass = 0,
                                         MaterialPropertyBlockWrapper properties = null, int?layerId = null, Material material = null,
                                         Image image         = null, Mesh meshObj = null,
                                         bool meshObjCreated = false)
            {
                CmdDraw newCmd = ObjectPool <CmdDraw> .alloc();

                newCmd.mesh           = mesh;
                newCmd.textMesh       = textMesh;
                newCmd.pass           = pass;
                newCmd.properties     = properties;
                newCmd.layerId        = layerId;
                newCmd.material       = material;
                newCmd.image          = image;
                newCmd.meshObj        = meshObj;
                newCmd.meshObjCreated = meshObjCreated;

                return(newCmd);
            }
Exemple #11
0
        void _drawTextBlob(TextBlob textBlob, Offset offset, Paint paint)
        {
            D.assert(textBlob != null);
            D.assert(offset != null);
            D.assert(paint != null);

            var state = this._currentLayer.currentState;
            var scale = state.scale * this._devicePixelRatio;

            var matrix = new Matrix3(state.matrix);

            matrix.preTranslate(offset.dx, offset.dy);
            var mesh = new TextBlobMesh(textBlob, scale, matrix);

            // request font texture so text mesh could be generated correctly
            var font           = FontManager.instance.getOrCreate(textBlob.style.fontFamily).font;
            var style          = textBlob.style;
            var fontSizeToLoad = Mathf.CeilToInt(style.UnityFontSize * scale);
            var subText        = textBlob.text.Substring(textBlob.textOffset, textBlob.textSize);

            font.RequestCharactersInTexture(subText, fontSizeToLoad, style.UnityFontStyle);

            var tex = font.material.mainTexture;

            Action <Paint> drawMesh = (Paint p) => {
                if (!this._applyClip(textBlob.bounds))
                {
                    return;
                }

                var layer = this._currentLayer;
                layer.draws.Add(CanvasShader.texAlpha(layer, p, mesh, tex));
            };

            if (paint.maskFilter != null && paint.maskFilter.sigma != 0)
            {
                this._drawWithMaskFilter(textBlob.bounds, drawMesh, paint, paint.maskFilter);
                return;
            }

            drawMesh(paint);
        }
Exemple #12
0
        void _drawPathDrawMeshCallback(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex,
                                       uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji)
        {
            if (!this._applyClip(mesh.bounds))
            {
                ObjectPool <uiMeshMesh> .release(mesh);

                return;
            }

            var layer = this._currentLayer;

            if (convex)
            {
                layer.draws.Add(CanvasShader.convexFill(layer, p, mesh));
            }
            else
            {
                layer.draws.Add(CanvasShader.fill0(layer, mesh));
                layer.draws.Add(CanvasShader.fill1(layer, p, mesh.boundsMesh));
            }
        }
Exemple #13
0
        void _drawTextBlob(TextBlob?textBlob, uiOffset offset, uiPaint paint)
        {
            D.assert(textBlob != null);

            var state = this._currentLayer.currentState;
            var scale = state.scale * this._devicePixelRatio;

            var matrix = new uiMatrix3(state.matrix.Value);

            matrix.preTranslate(offset.dx, offset.dy);

            var mesh           = TextBlobMesh.create(textBlob.Value, scale, matrix);
            var textBlobBounds = matrix.mapRect(uiRectHelper.fromRect(textBlob.Value.boundsInText));

            // request font texture so text mesh could be generated correctly
            var     style          = textBlob.Value.style;
            var     font           = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle).font;
            var     fontSizeToLoad = Mathf.CeilToInt(style.UnityFontSize * scale);
            var     subText        = textBlob.Value.text.Substring(textBlob.Value.textOffset, textBlob.Value.textSize);
            Texture tex            = null;
            bool    notEmoji       = !char.IsHighSurrogate(subText[0]) && !EmojiUtils.isSingleCharEmoji(subText[0]);

            if (notEmoji)
            {
                font.RequestCharactersInTextureSafe(subText, fontSizeToLoad, style.UnityFontStyle);
                tex = font.material.mainTexture;
            }

            if (paint.maskFilter != null && paint.maskFilter.Value.sigma != 0)
            {
                this._drawWithMaskFilter(textBlobBounds, paint, paint.maskFilter.Value, null, null, false, 0, 0, tex,
                                         textBlobBounds, mesh, notEmoji, this.___drawTextDrawMeshCallback);
                return;
            }

            this._drawTextDrawMeshCallback(paint, null, null, false, 0, 0, tex, textBlobBounds, mesh, notEmoji);
        }
Exemple #14
0
 public static PictureFlusher.RenderDraw texAlpha(PictureFlusher.RenderLayer layer, Paint paint,
                                                  TextBlobMesh textMesh, Texture tex)
 {
     return(texAlpha(layer, paint, null, textMesh, tex));
 }
Exemple #15
0
        void _drawPathDrawMeshQuit(uiMeshMesh mesh, TextBlobMesh textMesh)
        {
            ObjectPool <uiMeshMesh> .release(mesh);

            ObjectPool <TextBlobMesh> .release(textMesh);
        }