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 ...
随机推荐
- [No000060]冷读热读:读书九问
兵无常势,水无常形,读书亦无法.彼之砒霜,我之佳肴.然读书无法却有道.你我都是使用同一颗大脑在读书.这颗大脑受制于那千千万万年以来,星辰起落,狩猎采集,演化大道. Q1:读物如何分级? 坏书.可用的书 ...
- iOS Block详细介绍(block实现)
Block的实现 数据结构定义 block的数据结构定义如下图 对应的结构体定义如下: struct Block_descriptor { unsigned long int reserved; un ...
- 阿里云日志api创建logStore
, shardCount = }); string date = FormatRfc822Date(time); string con ...
- Delphi连接Oracle控件ODAC的安装及使用(轉載)
Delphi连接Oracle控件ODAC的安装及使用 2010-08-13 01:13:37 标签:Oracle Delphi 控件 休闲 ODAC 原创作品,允许转载,转载时请务必以超链接形式标明 ...
- Windows Server 2008 R2中的ASP.NET环境架设
.NET Framework的部分功能在Windows Server 2008 R2得到支持,包括:.NET 2/3/3.5的子集和ASP.NET.另外,PowerShell也在Server Core ...
- POJ 3259 Wormholes (判负环)
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 46123 Accepted: 17033 Descripti ...
- Android智能指针sp wp详解
研究Android的时候,经常会遇到sp.wp的东西,网上一搜,原来是android封装了c++中对象回收机制.说明:1. 如果一个类想使用智能指针,那么必须满足下面两个条件: a. 该类是虚基 ...
- 数据库 SQL语法二
聚合函数 -SUM([DISTINCT] FIELDNAME) 求指定列之和,[DISTINCT]选项表示剔除重复记录 例如:SELECT SUM(age) FROM TABLE1; SELECT S ...
- HAXM VT-X (与Hype-V冲突)
之前一直使用vs emulator. 感觉性能各方面都比较好, 但在我更新完电脑后不知道什么原因各种起不来... 无奈之下想回到Google自带的模拟器. 然后发现intel haxm一直安装失败. ...
- DTCMS插件的制作实例电子资源管理(一)插件目录结构
总目录 插件目录结构(一) Admin后台页面编写(二) 前台模板页编写(三) URL重写(四) 本实例旨在以一个实际的项目中的例子来介绍如何在dtcms中制作插件,本系列文章非入门教程,部分 ...