先来结论是 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