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 ...
随机推荐
- 虚拟机软件VMware Workstation Pro的安装与使用
聚焦行业最佳实践,BDTC 2016完整议程公布 Java 编程入门(系列) 程序员11月书讯,评论得书啦 免费的知识库,你的知识库 虚拟机软件VMware Workst ...
- 使用uboot的tftp下载bootloader、内核、文件系统
开发板 jz2440 下载uboot.bin tftp 0x30000000 u-boot.bin nand erase bootloader nand write bootloader 下载内核 t ...
- C++ ODB 框架(未实践使用)
http://www.codesynthesis.com/products/odb/doc/manual.xhtml#17.1
- Cornerstone 哪些错误
1.Unable to connect to a repository at URl.............,The operation could not be completed 说明无法连接的 ...
- Location 对象
Location 对象 Location 对象包含有关当前 URL 的信息. Location 对象是 window 对象的一部分,可通过 window.Location 属性对其进行访问. 注意: ...
- AIO 简介
from:http://blog.chinaunix.net/uid-11572501-id-2868654.html Linux的I/O机制经历了一下几个阶段的演进: 1. 同步阻塞I/O: 用 ...
- html中label宽度设置、非替换元素和替换元素
<label ></label> 单独对label设置一个width:100px的属性石不起作用的,和float:left或者display:inline-block配合的话 ...
- C#.NET 大型通用信息化系统集成快速开发平台 4.0 版本 - 拆分表、联系方式的拆分?
当用户数据有接近10万时,而且多表的关联也比较频繁时,能把大表拆为小表,也会提高系统的性能,I/O.运算性能.当然以后用户数据会更大可能会到30-40万以上,所有有能力时适当拆表,分分合合,合合分分也 ...
- LINQ基础概述
介绍LINQ基础之前,首说一下LINQ 的历史和LINQ是什么,然后说一下学习 LINQ要了解的东西和 LINQ基础语法 LINQ 的历史 从语言方面的进化 –委托 –匿名方法 –Lambda表达 ...
- 网页中三角切边还半透明,现在的设计师越来越牛,css也要跟上啊
需求 今天在群里看到一个需求,啊这种三角形缺角怎么做啊,还带半透明阴影的. 分析 要实现这个,可以用css做三角,网上找一下代码,像这样. 由于以前没有试过border能不能带透明,所以需要试验一下. ...