【Android图像1.1:Android中TextureView和SurfaceView的根本区别】

本文探讨了Android中TextureView和SurfaceView在图像处理上的根本区别。TextureView主要采用GPU进行composite,增加了两个Buffer,适合GPU渲染。而SurfaceView通过HardwareComposer进行硬件混合,BufferQueue通常为2个,适用于高效视频播放。实验结果显示,TextureView增加一个Buffer,SurfaceView增加一个Layer和两个Buffer。
摘要由CSDN通过智能技术生成

结论

GUI: 不同的图像进行composite(混合),效率一部分取决于 composite的工具

  1. 应用的Window对应于Layer,Surface,Layer(Surface)内有BufferQueue,BufferQueue内有不定数量的Buffer。
    • Layer (或Surface)<----包含---- 1个BufferQueue<----包含---- 多个Buffer (往往是三个 The BufferQueue for a display surface is typically configured for triple-buffering.)
    • 而 BufferQueue 又分为生产端、消费端。
  2. TextureView增加了两个Buffer,Layer不变
    • 融合采用OpenGLES的composite(混合)
    • OpenGLES 也是有hard(GPU)、soft(CPU)两种实现方式,Android手机一般都是hard实现
    • 也就是说在Android中TextureView 基本采用GPU composite
  3. SurfaceView增加Layer (Buffer自然随之增加)
    • 融合采用HardWareComposite,专用硬件来composite
    • Layer是有HWC进行混合的,是有硬件上的数量限制的
  4. BufferQueue往往2个buffer

The Hardware Composer (HWC) HAL composites layers received from SurfaceFlinger, reducing the amount of composition OpenGL ES (GLES) and the GPU perform.
The HWC abstracts objects, such as overlays and 2D blitters, to composite surfaces and communicates with specialized window composition hardware to composite windows. Use the HWC to composite windows instead of having SurfaceFlinger composite with the GPU. Most GPUs aren’t optimized for composition, and when the GPU composes layers from SurfaceFlinger, apps can’t use the GPU for their own rendering.

引用文档

Additionally, using SurfaceView objects adds two layers, which isn’t ideal because of the limitations on the number of overlays available on the hardware.

注意这个文档是说 用2个SurfaceView(对方视频播放、自己视频播放)去做视频会议,会增加2个layer。 这不是理想的解决方案,因为硬件对于layer是有数量限制的。
引用文档

实验

实验命令: adb shell dumpsys SurfaceFlinger | grep -C40 "Allocated buffers:"

TextureView

从列表Activity,调出入带有TextureView的Activity, TextureView用于视频播放(起初不播)

  1. 普通Activity
AppledeMacBook-Pro-8:~ apple$ adb shell dumpsys SurfaceFlinger  | grep -C40 "Allocated buffers:"
    0x7faa81f460: count=-1
    0x7faa81f4b0: count=-1
    0x7faa81f500: count=-1
    0x7faa81f550: count=-1
    0x7faa81f5a0: count=-1
    0x7faa81f640: count=-1
    0x7faae3a670: count=-1
h/w composer state:
  h/w composer present and enabled
Hardware Composer state (version 01050000):
  mDebugForceFakeVSync=0
  Display[0] configurations (* current):
    * 0: 1080x1920, xdpi=403.411011, ydpi=403.040985, refresh=16666666, colorMode=0
  numHwLayers=4, flags=00000000
    type   |  handle  | hint | flag | tr | blnd |   format    |     source crop (l,t,r,b)      |          frame         | name 
-----------+----------+------+------+----+------+-------------+--------------------------------+------------------------+------
       HWC | 7faa81aae0 | 0002 | 0000 | 00 | 0100 | RGBA_8888   |    0.0,    0.0, 1080.0, 1920.0 |    0,    0, 1080, 1920 | com.google.grafika/com.android.grafika.MainActivity
       HWC | 7fa6a47460 | 0002 | 0000 | 00 | 0105 | RGBA_8888   |    0.0,    0.0, 1080.0,   72.0 |    0,    0, 1080,   72 | StatusBar
       HWC | 7faa81b920 | 0002 | 0000 | 00 | 0105 | RGBA_8888   |    0.0,    0.0, 1080.0,   42.0 |    0, 1878, 1080, 1920 | UpSlideTransparentView
 FB TARGET | 7faae30f40 | 0000 | 0000 | 00 | 0105 | RGBA_8888   |    0.0,    0.0, 1080.0, 1920.0 |    0,    0, 1080, 1920 | HWC_FRAMEBUFFER_TARGET

-------- Snapdragon Display Manager --------
-----------------------
device type: 0
state: 1, vsync on: 0, max. mixer stages: 4
num configs: 1, active config index: 0
res:1080 x 1920, dpi:403.41 x 403.04, fps:60,vsync period: 16666666

ROI(L T R B) : LEFT(0 0 1080 1920)

|-----|-------------|--------|----|-------|-------------|--------------------------|---------------------|---------------------|----|------------|-----------|----|------|
| Idx |  Comp Type  |  Split | WB |  Pipe |    W x H    |          Format          |  Src Rect (L T R B) |  Dst Rect (L T R B) |  Z |    Flags   | Deci(HxV) | CS | Range|
|-----|-------------|--------|----|-------|-------------|--------------------------|---------------------|---------------------|----|------------|-----------|----|------|
|   0 |         SDE | Comp-1 |  - | 0x040 | 1088 x 1920 |           RGBA_8888_UBWC |    0    0 1080 1920 |    0    0 1080 1920 |  0 | 0x00000000 |   0 x   0 |  6 |  0 |
|-----|-------------|--------|----|-------|-------------|--------------------------|---------------------|---------------------|----|------------|-----------|----|------|
|   1 |         SDE | Comp-1 |  - | 0x010 | 1088 x   80 |           RGBA_8888_UBWC |    0    0 1080   72 |    0    0 1080   72 |  1 | 0x00000002 |   0 x   0 |  6 |  0 |
|-----|-------------|--------|----|-------|-------------|--------------------------|---------------------|---------------------|----|------------|-----------|----|------|
|   2 |         SDE | Comp-1 |  - | 0x008 | 1088 x   48 |           RGBA_8888_UBWC |    0    0 1080   42 |    0 1878 1080 1920 |  2 | 0x00000000 |   0 x   0 |  6 |  0 |
|-----|-------------|--------|----|-------|-------------|--------------------------|---------------------|---------------------|----|------------|-----------|--
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值