SurfaceView
Since Android 1.0(API Level 1). It inherits from the class View, so it’s essentially a View. But unlike regular View, it has its own Surface. As we know, a typical Activity contains multiple views that form a tree of hierachy views, and only the top-level DecorView, the root View, is visible to THE WMS. This DecorView has a corresponding Windows State in THE WMS. Accordingly, the corresponding Layer in SF. The SurfaceView comes with a Surface, which has its own WindowState in WMS and its own Layer in SF. As shown below:
While on the Client side (App) it is still in the View hierachy, on the Server side (WMS and SF) it is separate from the host window.The advantage of this is that rendering of the Surface can be done in a separate thread with its own GL context. This is useful for performance-related applications such as games, videos, etc., because it does not affect the main thread’s response to events. However, it also has disadvantages, because the Surface is not in the hierachy of the View, and its display is not controlled by the attributes of the View, so it cannot be translated, zooming and other transformations, nor can it be placed in other viewgroups, and some features in the View cannot be used.
GLSurfaceView
The relevant class diagram is shown below. The SurfaceHolder in the SurfaceView mainly provides a bunch of interfaces to operate the Surface. The EglHelper and GLThread in GLSurfaceView do the aforementioned work of managing the EGL environment and rendering threads, respectively. GLSurfaceView users need to implement the Renderer interface.
SurfaceTexture
The processing of image stream is not directly displayed, but converted to GL external texture, so it can be used for secondary processing of image stream data (such as Camera filter, desktop effects, etc.).Camera preview data, for example, can be presented to GLSurfaceView as a texture, or to TextureView as a hardware acceleration layer in View Heirachy via SurfaceTexture. First, the SurfaceTexture retrieves frame data from the image stream (from Camera preview, video decoding, GL rendering scene, etc.). When updateTexImage() is called, the GL texture object corresponding to the SurfaceTexture is updated based on the most recent image in the content stream. Next, You can manipulate it just like a normal GL texture. As you can see from the class diagram below, its core manages both the Consumer and Producer ends of a BufferQueue. The Producer side uses the source output data for the content stream, and the Consumer side uses the GraphicBuffer to generate textures. SurfaceTexture. OnFrameAvailableListener for SurfaceTexture so users know that there are new data arrives. JNISurfaceTextureContext is the JNI springboard for OnFrameAvailableListener from Native to Java. The SurfaceTexture attachToGLContext() and detachToGLContext() allow multiple GL Contexts to share the same content source.
TextureView
It does not create a separate window in THE WMS, but as a normal View in the View hierachy, so you can move, rotate, zoom, animate, and so on, just like any normal View. It’s worth noting
TextureView must be in the hardware Accelerated window.It displays content stream data that can come from the App process or a remote process. As you can see from the class diagram, TextureView inherits from the View, which is managed and drawn in hierachy like other views. TextureView overloads the Draw () method, which updates the image data received from the SurfaceTexture to the corresponding HardwareLayer as a texture. SurfaceTexture. OnFrameAvailableListener for inform TextureView content flow has a new image. The SurfaceTextureListener interface is used to let TextureView consumers know that SurfaceTexture is ready so that they can hand it to the appropriate content source. The Surface class implements the Producer interface for the BufferQueue, allowing producers to provide graphic buffers to the BufferQueue inside the SurfaceTexture via their software or hardware rendering interfaces.
Android 5.0 introduced rendering threadsIt is a larger topic beyond the scope of this article, and only the relevant parts are covered here. For background, only the relevant classes are drawn below. As you can see, ThreadedRenderer is the new hardwar renderreplacing the Gl20Renderer in Android 4.4. The key is the RenderProxy class, which sends tasks to the renderer thread when it needs to do something. The threadLoop() function is the main loop. It polls and waits on the thread’s Looper most of the time. When a synchronization request (or VSync signal) comes in, it wakes up. The tasks in the TaskQueue are then processed. A TaskQueue is a queue of RenderTasks that represent tasks in a rendering thread. For example, DrawFrameTask is one of RenderTask’s inherited classes, which is used to render the current frame. The DeferredLayerUpdater collection in DrawFrameTask holds previous requests to update the hardware acceleration layer.
memoryThe cost is also slightly higher.
From: www.bubuko.com/infodetail-…