TextureView中的Texture到底是什么,源码追踪

本文探讨了Android的TextureView如何在OpenGL中创建纹理对象和离屏缓冲区,并结合SurfaceTexture工作原理,解释了TextureView的Layer实际是OpenGL的texture。内容涉及FrameBuffer的属性、纹理类型GL_TEXTURE_2D和GL_TEXTURE_EXTERNAL_OES的关系及其在多渲染缓冲区技术中的应用。
摘要由CSDN通过智能技术生成

先来结论是 OpenGL中的纹理 FBO(FrameBuffer的形式)

TextureView

TextureView

 @Override
    public final void draw(Canvas canvas) {
        // NOTE: Maintain this carefully (see View#draw)
        mPrivateFlags = (mPrivateFlags & ~PFLAG_DIRTY_MASK) | PFLAG_DRAWN;

        /* Simplify drawing to guarantee the layer is the only thing drawn - so e.g. no background,
        scrolling, or fading edges. This guarantees all drawing is in the layer, so drawing
        properties (alpha, layer paint) affect all of the content of a TextureView. */

        if (canvas.isHardwareAccelerated()) {
            DisplayListCanvas displayListCanvas = (DisplayListCanvas) canvas;

            HardwareLayer layer = getHardwareLayer();
            if (layer != null) {
                applyUpdate();
                applyTransformMatrix();

                mLayer.setLayerPaint(mLayerPaint); // ensure layer paint is up to date
                displayListCanvas.drawHardwareLayer(layer);
            }
        }
    }

DisplayListCanvas

    void drawHardwareLayer(HardwareLayer layer) {
        nDrawLayer(mNativeCanvasWrapper, layer.getLayerHandle());
    }
    
    private static native void nDrawLayer(long renderer, long layer);

TextureView的 SurfaceTexture,Layer
            mLayer = mAttachInfo.mThreadedRenderer.createTextureLayer();
            boolean createNewSurface = (mSurface == null);
            if (createNewSurface) {
                // Create a new SurfaceTexture for the layer.
                mSurface = new SurfaceTexture(false);
                nCreateNativeWindow(mSurface);
            }
            mLayer.setSurfaceTexture(mSurface);
  • SurfaceTexture实例化后,作为参数 创建nativeWindows。
  • mLayer从mAttachInfo.mThreadedRenderer.createTextureLayer();
  • mAttachInfo
public class TextureView extends View 

View{
//包级,隐藏API
        AttachInfo mAttachInfo;
        
    /** View的静态内部类,和Window关联
     * A set of information given to a view when it is attached to its parent
     * window.
     */
    final static class AttachInfo {
        ThreadedRenderer mThreadedRenderer;
        List<RenderNode> mPendingAnimatingRenderNodes;
    
        final IWindowSession mSession;
        final IWindow mWindow;
        final IBinder mWindowToken;

        
                static class InvalidateInfo {//invalidate的view、dirty region
                    View target;
                }
     
    }
}

ThreadedRenderer

Threaded renderer that proxies the rendering to

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值