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 ...
随机推荐
- 什么是 A 轮融资?有 B轮 C轮么?
融资的顺序是A轮 B轮 C轮这之前还有天使轮,种子轮,首轮在这之后还有vc/pe,ipo等等,只是一些不同时段的融资 Chen Shu 知乎用户.千叶光.angle LI 等人赞同 就是公司的初卖.再 ...
- 使用gulp将移动端px转为rem
使用gulp的插件可以很方便的将xp转为rem,在布局的时候使用@1x .@2x布局,即10rem=device-width:@1x即设计图为320px,1rem对应的10px像素,相对的@2x即为布 ...
- C语言:void指针
使用前必须进行强制类型转换 #include <stdio.h> void test(const void *p); int main(){ ; int *p = &i; puts ...
- C#.NET 大型通用信息化系统集成快速开发平台 4.0 版本 - 用户权限树的实现 -- 权限递归树
业务系统里经常会需要计算类似的树形权限树的业务需求 1:往往会有一些需求,a 对 b 有权限, b对c 有权限, 等等. 2:还需要很直观的看到,整个权限的树形关系,一目了然的那种. 3:程序调用简单 ...
- Nodejs生态圈的TypeScript+React
基于Nodejs生态圈的TypeScript+React开发入门教程 基于Nodejs生态圈的TypeScript+React开发入门教程 概述 本教程旨在为基于Nodejs npm生态圈的前端程 ...
- 将packages/apps/下的app导入eclipse
当刚接触android自带的一个模块时,如何去熟悉它?相信不少人第一步都会尝试着去了解其内容的调用流程,而此时若能够单步调试则显得非常重要了,于是有了文章标题所说的尝试. 作者这里要导入的是Setti ...
- QT QT练习一
界面中通过三个 QLineEdit控件,一个QPushButton实现+ - * /四则运算,点击pushbutton后将运算结果显示在QLabel控件上. #ifndef WIDGET_H #def ...
- C# 如何定义让PropertyGrid控件显示[...]按钮,并且点击后以下拉框形式显示自定义控件编辑属性值
关于PropertyGrid控件的详细用法请参考文献: 1.C# PropertyGrid控件应用心得 2.C#自定义PropertyGrid属性 首先定义一个要在下拉框显示的控件: using Sy ...
- 使用mysqldump进行mysql数据库备份还原
mysqldump是mysql自带的备份还原工具,默认在安装目录的bin下 可通过cmd命令行启动,然后运行: 还原一个数据库: mysql -h 主机 -u 用户名 -p密码 数据库名 < 指 ...
- SQLServer(MSSQL)、MySQL、SQLite、Access相互迁移转换工具 DB2DB v1.3
最近公司有一个项目,需要把原来的系统从 MSSQL 升迁到阿里云RDS(MySQL)上面.为便于测试,所以需要把原来系统的所有数据表以及测试数据转换到 MySQL 上面.在百度上找了很多方法,有通过微 ...