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 ...
随机推荐
- JS客户端判断
<script language="javascript" type="text/javascript"> function browserDete ...
- 解决为什么每次打开Eclipse新的workspace需要更新nexus-maven-repository-index问题
解决为什么每次打开Eclipse新的workspace需要更新nexus-maven-repository-index问题 新建一个Eclipse的workspace. 打开Window—>Pr ...
- tyvj[1089]smrtfun
描述 现有N个物品,第i个物品有两个属性A_i和B_i.在其中选取若干个物品,使得sum{A_i + B_i}最大,同时sum{A_i},sum{B_i}均非负(sum{}表示求和). 输入格式 ...
- offsetLeft与offsetTop详解
offsetLeft与offsetTop使用方法一样,只是一个是找距离定位父级(position:relative)左边的距离,一个是找距离定位父级上边的距离 没有定位则找body,我们还是看看ie7 ...
- 在Java代码中使用pdfBox将PDF转换为图片
生成图片 // 生成图片 PDDocument pd = PDDocument.load(new File(filePath)); PDFRenderer pdfRenderer = new PDFR ...
- IE 和Firefox的js兼容性总结
IE 和Firefox的js兼容性总结 12 August 2010 11:39 Thursday by 小屋 标签: 浏览器 方法 属性 IT 写法 一.函数和方法差异 1 . getYear()方 ...
- 2016.11.14测试 长乐一中2014NOIP复赛模拟题 第一题。
1.正确答案 [题目描述] 小H与小Y刚刚参加完UOIP外卡组的初赛,就迫不及待的跑出考场对答案. "吔,我的答案和你都不一样!",小Y说道,"我们去找神犇们问答案吧&q ...
- BZOJ 1096 【ZJOI2007】 仓库建设
Description L公司有N个工厂,由高到底分布在一座山上.如图所示,工厂1在山顶,工厂N在山脚.由于这座山处于高原内陆地区(干燥少雨),L公司一般把产品直接堆放在露天,以节省费用.突然有一天, ...
- Android — Camera聚焦流程
原文 http://www.cnphp6.com/archives/65098 主题 Android Camera.java autoFocus()聚焦回调函数 @Override public v ...
- ubuntu mysql 更改IP导致mysql无法启动
bind-address = 127.0.0.1 => bind-address= 136.129.20.168 IP要这么改 这么改远程连不上,那么需要把这行整行注释掉,重启MYSQL,tel ...