SurfaceView, TextureView, SurfaceTexture等的区别
SurfaceView
从Android 1.0(API level 1)时就有 。它继承自类View,因此它本质上是一个View。但与普通View不同的是,它有自己的Surface。我们知道,一般的Activity包含的多个View会组成View hierachy的树形结构,只有最顶层的DecorView,也就是根结点视图,才是对WMS可见的。这个DecorView在WMS中有一个对应的WindowState。相应地,在SF中对应的Layer。而SurfaceView自带一个Surface,这个Surface在WMS中有自己对应的WindowState,在SF中也会有自己的Layer。如下图所示:
GLSurfaceView
- public class TriangleActivity extends Activity {
- protected void onCreate(Bundle savedInstanceState) {
- mGLView = new GLSurfaceView(this);
- mGLView.setRenderer(new RendererImpl(this));
相关类图如下。其中SurfaceView中的SurfaceHolder主要是提供了一坨操作Surface的接口。GLSurfaceView中的EglHelper和GLThread分别实现了上面提到的管理EGL环境和渲染线程的工作。GLSurfaceView的使用者需要实现Renderer接口。
SurfaceTexture
TextureView
- 109 public VideoDumpView(Context context) {
- ...
- 116 mRenderer = new VideoDumpRenderer(context);
- 117 setRenderer(mRenderer);
- 118 }
- 519 public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
- ...
- 551 // Create our texture. This has to be done each time the surface is created.
- 552 int[] textures = new int[1];
- 553 GLES20.glGenTextures(1, textures, 0);
- 554
- 555 mTextureID = textures[0];
- 556 GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureID);
- ...
- 575 mSurface = new SurfaceTexture(mTextureID);
- 576 mSurface.setOnFrameAvailableListener(this);
- 577
- 578 Surface surface = new Surface(mSurface);
- 579 mMediaPlayer.setSurface(surface);
- 230static void SurfaceTexture_init(JNIEnv* env, jobject thiz, jboolean isDetached,
- 231 jint texName, jboolean singleBufferMode, jobject weakThiz)
- 232{
- ...
- 235 BufferQueue::createBufferQueue(&producer, &consumer);
- ...
- 242 sp<GLConsumer> surfaceTexture;
- 243 if (isDetached) {
- 244 surfaceTexture = new GLConsumer(consumer, GL_TEXTURE_EXTERNAL_OES,
- 245 true, true);
- 246 } else {
- 247 surfaceTexture = new GLConsumer(consumer, texName,
- 248 GL_TEXTURE_EXTERNAL_OES, true, true);
- 249 }
- ...
- 256 SurfaceTexture_setSurfaceTexture(env, thiz, surfaceTexture);
- 257 SurfaceTexture_setProducer(env, thiz, producer);
- ...
- 266 sp<JNISurfaceTextureContext> ctx(new JNISurfaceTextureContext(env, weakThiz,
- 267 clazz));
- 268 surfaceTexture->setFrameAvailableListener(ctx);
- 269 SurfaceTexture_setFrameAvailableListener(env, thiz, ctx);
- 180void JNISurfaceTextureContext::onFrameAvailable()
- ...
- 184 env->CallStaticVoidMethod(mClazz, fields.postEvent, mWeakThiz);
- 133 public Surface(SurfaceTexture surfaceTexture) {
- ...
- 140 setNativeObjectLocked(nativeCreateFromSurfaceTexture(surfaceTexture));
- 135static jlong nativeCreateFromSurfaceTexture(JNIEnv* env, jclass clazz,
- 136 jobject surfaceTextureObj) {
- 137 sp<IGraphicBufferProducer> producer(SurfaceTexture_getProducer(env, surfaceTextureObj));
- ...
- 144 sp<Surface> surface(new Surface(producer, true));
- 372 public void onDrawFrame(GL10 glUnused) {
- ...
- 377 if (updateSurface) {
- ...
- 380 mSurface.updateTexImage();
- 381 mSurface.getTransformMatrix(mSTMatrix);
- 382 updateSurface = false;
- ...
- 394 // Activate the texture.
- 395 GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
- 396 GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureID);
- ...
- 421 // Draw a rectangle and render the <span style="padding: 0px; width: auto; height: auto; float: none;"><a target="_blank" style="padding: 0px; color: #333333;" href="http://cpro.baidu.com/cpro/ui/uijs.php?app_id=0&c=news&cf=1001&ch=0&di=128&fv=18&is_app=0&jk=ddd62cbeae8a0ad1&k=video&k0=video&kdi0=0&luki=7&n=10&p=baidu&q=65035100_cpr&rb=0&rs=1&seller_id=1&sid=d10a8aaebe2cd6dd&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1836545&u=http%3A%2F%2Fwww%2Ebubuko%2Ecom%2Finfodetail%2D656030%2Ehtml&urlid=0"><span style="padding: 0px; color: #0000ff; width: auto; height: auto;">video</span></a></span> frame as a texture on it.
- 422 GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
- ...
- 429 DumpToFile(frameNumber);
- protected void onCreate(Bundle savedInstanceState) {
- ...
- mTextureView = new TextureView(this);
- mTextureView.setSurfaceTextureListener(this);
- ...
- }
- 348 HardwareLayer getHardwareLayer() {
- ...
- 358 mLayer = mAttachInfo.mHardwareRenderer.createTextureLayer();
- 359 if (!mUpdateSurface) {
- 360 // Create a new SurfaceTexture for the layer.
- 361 mSurface = new SurfaceTexture(false);
- 362 mLayer.setSurfaceTexture(mSurface);
- 363 }
- 364 mSurface.setDefaultBufferSize(getWidth(), getHeight());
- 365 nCreateNativeWindow(mSurface);
- 366
- 367 mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler);
- 368
- 369 if (mListener != null && !mUpdateSurface) {
- 370 mListener.onSurfaceTextureAvailable(mSurface, getWidth(), getHeight());
- 371 }
- ...
- 390 applyUpdate();
- 391 applyTransformMatrix();
- 392
- 393 return mLayer;
- 394 }
- public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
- mCamera = Camera.open();
- ...
- mCamera.setPreviewTexture(surface);
- mCamera.startPreview();
- ...
- }
- 576static void android_<span style="padding: 0px; width: auto; height: auto; float: none;"><a target="_blank" style="padding: 0px; color: #333333;" href="http://cpro.baidu.com/cpro/ui/uijs.php?app_id=0&c=news&cf=1001&ch=0&di=128&fv=18&is_app=0&jk=ddd62cbeae8a0ad1&k=hardware&k0=hardware&kdi0=0&luki=3&n=10&p=baidu&q=65035100_cpr&rb=0&rs=1&seller_id=1&sid=d10a8aaebe2cd6dd&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1836545&u=http%3A%2F%2Fwww%2Ebubuko%2Ecom%2Finfodetail%2D656030%2Ehtml&urlid=0"><span style="padding: 0px; color: #0000ff; width: auto; height: auto;">hardware</span></a></span>_Camera_setPreviewTexture(JNIEnv *env,
- 577 jobject thiz, jobject jSurfaceTexture)
- ...
- 585 producer = SurfaceTexture_getProducer(env, jSurfaceTexture);
- ...
- 594 if (camera->setPreviewTarget(producer) != NO_ERROR) {
- 755 public void onFrameAvailable(SurfaceTexture surfaceTexture) {
- 756 updateLayer();
- 757 invalidate();
- 758 }
- 138 public void updateSurfaceTexture() {
- 139 nUpdateSurfaceTexture(mFinalizer.get());
- 140 mRenderer.pushLayerUpdate(this);
- 141 }
SurfaceView, TextureView, SurfaceTexture等的区别的更多相关文章
- TextureView+SurfaceTexture+OpenGL ES来播放视频(一)
引自:http://www.ithao123.cn/content-8733143.html 最近发现视频直播类应用层出不穷,比如233手游直播,蓝鲸直播,微录客等等什么的,连android界大神老罗 ...
- TextureView+SurfaceTexture+OpenGL ES来播放视频(三)
引自:http://www.jianshu.com/p/291ff6ddc164 做好的Demo截图 opengl-video 前言 讲了这么多,可能有人要问了,播放视频用个android封装的Vid ...
- TextureView+SurfaceTexture+OpenGL ES来播放视频(二)
引自:http://www.jianshu.com/p/b2d949ab1a1a 在使用OpenGL ES 绘制前,我先概括下接下来要做的工作:我先借用一个博主kiffa举的的一个栗子,我觉得说的恰到 ...
- 两年Android开发三面上岸腾讯,这些核心知识点建议收藏
概述 感觉毕业后时间过得真快啊,从 19 年 7 月本科毕业入职后,到现在快两年了,前段时间金三银四期间想着找一个新的工作,前前后后花了一个多月的时间复习以及面试,面试好几家大厂,最后选择了腾讯.也祝 ...
- Android 5.0(Lollipop)中的SurfaceTexture,TextureView, SurfaceView和GLSurfaceView
SurfaceView, GLSurfaceView, SurfaceTexture以及TextureView是Android当中名字比较绕,关系又比较密切的几个类.本文基于Android 5.0(L ...
- android: View, SurfaceView, GLSurfaceView, TextureView 区别与联系
区别与联系 View: 显示视图,内置画布,提供了图形绘制函数.触屏事件.按键事件函数等,必须在UI主线程内更新画面,速度较慢: SurfaceView: 基于view视图进行拓展的视图类,更适合2D ...
- 玩转Android Camera开发(二):使用TextureView和SurfaceTexture预览Camera 基础拍照demo
Google自Android4.0出了TextureView,为什么推出呢?就是为了弥补Surfaceview的不足,另外一方面也是为了平衡GlSurfaceView,当然这是本人揣度的.关于Text ...
- SurfaceView 和 TextureView
1.区别 The followings are two limitations of SurfaceView: You can not be animated, transformed and sca ...
- Android Camera开发:使用TextureView和SurfaceTexture预览Camera 基础拍照demo
Google自Android4.0出了TextureView,为什么推出呢?就是为了弥补Surfaceview的不足,另外一方面也是为了平衡GlSurfaceView,当然这是本人揣度的.关于Text ...
随机推荐
- IT菜鸟的第2天(输入输出,数据类型,运算符的使用)
1:输入输出 另一种读写方法: 注释:Console.Write(Line{自动换行})是输入,string xxx = Console.ReadLine();是输出. string :字符串类型 ...
- python pip install mysql-connector-python
sudo pip install mysql-connector-python 报错信息:Collecting mysql-connector-python Could not find a vers ...
- bzoj2286 消耗战
还是虚树的题目啊... 如果只有一个询问,我们这么考虑,可以设dp[x]为只删除x子树内和x到父亲的边,使得x这棵子树内的能源岛屿都与x的父亲不连通的最小花费. 这样如果x本身是能源岛屿,那么dp[x ...
- Linux下修改系统编码的操作记录
Linux系统安装后,发现中文显示乱码.因为系统编码为en_US.UTF-8,应改为支持中文的编码(即zh_CN.UTF-8)操作记录如下:1)检查linux的系统编码检查linux的系统编码,确定系 ...
- python设计模式1:导言
<设计模式>一书总结了23个模式,依据各自的目的又被分为创建型模式(creational pattern).结构型模式(structural pattern)和行为型模式(behavior ...
- 内网机(无网络安装 .NET Core win开发环境
1.安装 vs2015 update3 2.按顺序安装以下包 DotNetCore.1.0.0-SDK.Preview2-x64.exe aspnetcoremodule_x64_en_rc2_14. ...
- Linux 信号详解六(可靠信号与不可靠信号)
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h&g ...
- 利用writing-mode实现元素的垂直居中
writing-mode是CSS3的新特性之一,使用场景不是很多.这个属性主要是改变文档流的显示方式.具体的介绍参考这篇文章:http://www.zhangxinxu.com/wordpress/2 ...
- Theano3.3-练习之逻辑回归
是官网上theano的逻辑回归的练习(http://deeplearning.net/tutorial/logreg.html#logreg)的讲解. Classifying MNIST digits ...
- 2016年优秀的java网站分享
java中文网站 伯乐在线java版:http://www.importnew.com/ 码农网:http://www.codeceo.com/ infoq:http://www.infoq.com/ ...