源码位置

/frameworks/native/libs/gui/include/gui/BufferSlot.h

源码

struct BufferSlot {

    BufferSlot()
: mGraphicBuffer(nullptr),
mEglDisplay(EGL_NO_DISPLAY),
mBufferState(),
mRequestBufferCalled(false),
mFrameNumber(0),
mEglFence(EGL_NO_SYNC_KHR),
mFence(Fence::NO_FENCE),
mAcquireCalled(false),
mNeedsReallocation(false) {
} // mGraphicBuffer points to the buffer allocated for this slot or is NULL
// if no buffer has been allocated.
sp<GraphicBuffer> mGraphicBuffer; // mEglDisplay is the EGLDisplay used to create EGLSyncKHR objects.
EGLDisplay mEglDisplay; // mBufferState is the current state of this buffer slot.
BufferState mBufferState; // mRequestBufferCalled is used for validating that the producer did
// call requestBuffer() when told to do so. Technically this is not
// needed but useful for debugging and catching producer bugs.
bool mRequestBufferCalled; // mFrameNumber is the number of the queued frame for this slot. This
// is used to dequeue buffers in LRU order (useful because buffers
// may be released before their release fence is signaled).
uint64_t mFrameNumber; // mEglFence is the EGL sync object that must signal before the buffer
// associated with this buffer slot may be dequeued. It is initialized
// to EGL_NO_SYNC_KHR when the buffer is created and may be set to a
// new sync object in releaseBuffer. (This is deprecated in favor of
// mFence, below.)
EGLSyncKHR mEglFence; // mFence is a fence which will signal when work initiated by the
// previous owner of the buffer is finished. When the buffer is FREE,
// the fence indicates when the consumer has finished reading
// from the buffer, or when the producer has finished writing if it
// called cancelBuffer after queueing some writes. When the buffer is
// QUEUED, it indicates when the producer has finished filling the
// buffer. When the buffer is DEQUEUED or ACQUIRED, the fence has been
// passed to the consumer or producer along with ownership of the
// buffer, and mFence is set to NO_FENCE.
sp<Fence> mFence; // Indicates whether this buffer has been seen by a consumer yet
bool mAcquireCalled; // Indicates whether the buffer was re-allocated without notifying the
// producer. If so, it needs to set the BUFFER_NEEDS_REALLOCATION flag when
// dequeued to prevent the producer from using a stale cached buffer.
bool mNeedsReallocation;
};

成员注解

  • sp<GraphicBuffer> mGraphicBuffer;   // mGraphicBuffer指向这个槽位分配的缓冲区,如果没有分配缓冲区则为NULL
  • EGLDisplay mEglDisplay;  // 用于创建EGLSyncKHR对象的EGLDisplay
  • BufferState mBufferState; // 缓冲槽的当前状态
  • bool mRequestBufferCalled; // mRequestBufferCalled用于验证生产者是否在被告知时调用了requestBuffer()。从技术上讲,这不是必需的,但对于调试和捕获生产者bug非常有用。
  • uint64_t mFrameNumber; // mFrameNumber是此插槽的排队帧编号。这用于按LRU顺序将缓冲区出列(很有用,因为缓冲区可能在释放围栏发出信号之前被释放)。
  • EGLSyncKHR mEglFence; // mEglFence是EGL sync对象,必须在与此缓冲槽关联的缓冲区退出队列之前发出信号。当创建缓冲区时,它被初始化为EGL_NO_SYNC_KHR,并且可以设置为releaseBuffer中的新同步对象(支持mFence时mEglFence被弃用)
  • sp<Fence> mFence;  // mFence是一个围栏,当缓冲区的前所有者启动的工作完成时,它将发出信号。
  1. 当Buffer处在FREE时,Fence指示消费者何时已完成从缓冲区的读取,或者生产者何时已完成写入
  2. 当Buffer处在QUEUED时,它指示生产者何时完成缓冲区填充。
  3. 当Buffer处在DEQUEUED or ACQUIRED时,Fence连同缓冲区的所有权一起传递给消费者或生产者,并且mFence设置为NO_FENCE。
  • bool mAcquireCalled; // 指示消费者consumer是否已看到此缓冲区
  • bool mNeedsReallocation; //指示是否在未通知生产者的情况下重新分配了缓冲区。如果是这样,它需要在退出队列时设置BUFFER_NEEDS_REALLOCATION标志,以防止生产者使用过时的缓存缓冲区。

buffer的状态

    // A buffer can be in one of five states, represented as below:
//
// | mShared | mDequeueCount | mQueueCount | mAcquireCount |
// --------|---------|---------------|-------------|---------------|
// FREE | false | 0 | 0 | 0 |
// DEQUEUED| false | 1 | 0 | 0 |
// QUEUED | false | 0 | 1 | 0 |
// ACQUIRED| false | 0 | 0 | 1 |
// SHARED | true | any | any | any |
//
// FREE indicates that the buffer is available to be dequeued by the
// producer. The slot is "owned" by BufferQueue. It transitions to DEQUEUED
// when dequeueBuffer is called.
//
// DEQUEUED indicates that the buffer has been dequeued by the producer, but
// has not yet been queued or canceled. The producer may modify the
// buffer's contents as soon as the associated release fence is signaled.
// The slot is "owned" by the producer. It can transition to QUEUED (via
// queueBuffer or attachBuffer) or back to FREE (via cancelBuffer or
// detachBuffer).
//
// QUEUED indicates that the buffer has been filled by the producer and
// queued for use by the consumer. The buffer contents may continue to be
// modified for a finite time, so the contents must not be accessed until
// the associated fence is signaled. The slot is "owned" by BufferQueue. It
// can transition to ACQUIRED (via acquireBuffer) or to FREE (if another
// buffer is queued in asynchronous mode).
//
// ACQUIRED indicates that the buffer has been acquired by the consumer. As
// with QUEUED, the contents must not be accessed by the consumer until the
// acquire fence is signaled. The slot is "owned" by the consumer. It
// transitions to FREE when releaseBuffer (or detachBuffer) is called. A
// detached buffer can also enter the ACQUIRED state via attachBuffer.
//
// SHARED indicates that this buffer is being used in shared buffer
// mode. It can be in any combination of the other states at the same time,
// except for FREE (since that excludes being in any other state). It can
// also be dequeued, queued, or acquired multiple times.
  • FREE状态,buffer及slot属于BufferQueue,producer可以通过调用dequeueBuffer获取该buffer,其状态转为DEQUEUED
  • DEQUEUED状态,表示该buffer已经被producer出队列,但时还被queued或canceled。一旦与该buffer相关联的fence发出信号,producer就可以修改buffer的内容。这种状态下slot属于producer所有,当调用queueBuffer or attachBuffer后转为QUEUED,或调用cancelBuffer or detachBuffer转为FREE
  • QUEUED状态,表示该buffer已经被producer填充数据,入队列让consumer使用。buffer内容可能会在有限的时间内继续修改,因此在相关fence发出信号之前,不得访问内容。此时slot归BufferQueue所有,buffer状态可以转为ACQUIRED(via acquireBuffer) 或FREE(另一个buffer异步模式下入队列)
  • ACQUIRED状态,表示该buffer被consumer取得。fence信号发出后,消费者就可以访问其内容了。slot被consumer所拥有。 当调用releaseBuffer (or detachBuffer)可以转为FREE
  • SHARED状态,表示此缓冲区正在共享缓冲区模式下使用

Android 9.0 BufferSlot注解的更多相关文章

  1. Android 6.0 运行时权限处理完全解析

    一.概述 随着Android 6.0发布以及普及,我们开发者所要应对的主要就是新版本SDK带来的一些变化,首先关注的就是权限机制的变化.对于6.0的几个主要的变化,查看查看官网的这篇文章http:// ...

  2. Android 5.0以上Material Design 沉浸式状态栏

    偶然在知乎上看到这个问题,Android 5.0 如何实现将布局的内容延伸到状态栏,之前也见过多个应用的这个功能,但是知乎上的答案却没有一个真正实现此功能的一类是把标题栏设置App主题颜色,一类是提取 ...

  3. android 6.0 动态权限

    Android 6.0 动态权限: 除了要在AndroidManifest.xml中申请外,还需使用时,请求用户允许授权. 以下是需要单独申请的权限,共分为9组,每组只要有一个权限申请成功了,就默认整 ...

  4. Android 7.0 行为变更

    Android 7.0 除了提供诸多新特性和功能外,还对系统和 API 行为做出了各种变更.本文重点介绍您应该了解并在开发应用时加以考虑的一些主要变更. 如果您之前发布过 Android 应用,请注意 ...

  5. Android 6.0 运行时权限处理完全解析 (摘抄)

    转载请标明出处: http://blog.csdn.net/lmj623565791/article/details/50709663: 本文出自:[张鸿洋的博客] 一.概述 随着Android 6. ...

  6. Android 6.0 执行时权限处理全然解析

    转载请标明出处: http://blog.csdn.net/lmj623565791/article/details/50709663: 本文出自:[张鸿洋的博客] 一.概述 随着Android 6. ...

  7. Android Studio2.0 Beta 2版本号更新说明及注意事项

    我们刚刚向canary channel推送了Android Studio2.0 Beta 2版本号 老毕译注: ---------- canary channel: 金丝雀版本号,平均1到2周就会更新 ...

  8. Android 7.0新特性

    还望支持个人博客站:http://www.enjoytoday.cn 由于google目前不是无法直接在国内访问,故此,对于android 开发平台的7.0新特性做个保存.也可供大家查阅.原文转自an ...

  9. Android xUtils3.0使用手册(二) - 数据库操作

    步骤:  (1). 创建数据表: (2). DaoConfig 获取数据库的配置信息: (3).  获取数据库实例:  x.getDb(daoConfig); (4). 数据库的增删改查. 1. 创建 ...

随机推荐

  1. 升级IDEA后Lombok不能用了,如何解决?

    今天到工作室比较晚,在电脑前吃着早饭,看到提示IDEA提示升级,寻思已经有好久没有升过级了.一样等着,就升级下吧. 升级完毕重启之后,突然发现好多错误,原来的应用也没法启动了.仔细一看报错信息,是由于 ...

  2. 使用过redis做异步队列么,你是怎么用的?有什么缺点?

    Redis设计主要是用来做缓存的,但是由于它自身的某种特性使得它可以用来做消息队列. 它有几个阻塞式的API可以使用,正是这些阻塞式的API让其有能力做消息队列: 另外,做消息队列的其他特性例如FIF ...

  3. 深度解析HashMap底层实现架构

    摘要:分析Map接口的详细使用以及HashMap的底层是如何实现的? 本文分享自华为云社区<[图文并茂]深度解析HashMap高频面试及底层实现结构![奔跑吧!JAVA]>,原文作者:灰小 ...

  4. MySQL | Xtrabackup 的简介

    Xtrabackup 简介 Xtrabackup是由Percona开发的一个开源软件,可实现对InnoDB的数据备份,支持在线热备份(备份时不影响数据读写). Xtrabackup有2款主要工具,xt ...

  5. tr 字符转换命令

    tr:可以用来删除一段信息当中的文字,或者是进行文字信息的替换 语法:tr [parameter] set1 ...参数: -d:删除信息当中的set1这个字符 -s:替换掉重复的字符 举例: 将la ...

  6. 「BZOJ3545」「ONTAK2010」Peaks

    「BZOJ3545」「ONTAK2010」Peaks 题目传送门 题目大意: 给定一个 \(n\) 个点,\(m\) 条边的带点权边权无向图,有 \(q\) 次询问,每次询问从 \(v\) 点出发,经 ...

  7. 『动善时』JMeter基础 — 55、使用非GUI模式运行JMeter(命令行模式)

    目录 1.JMeter的非GUI模式说明 2.为什么使用非GUI模式运行JMeter 3.使用非GUI模式运行JMeter (1)非GUI模式运行JMeter步骤 (2)其它参数说明 4.CLI模式运 ...

  8. 阿里云PTS分享-用性能测试工具JMeter实现基于供应链业务上对于WebSocket 协议的压测

    性能测试PTS(Performance Testing Service)是面向所有技术相关背景人员的云化性能测试工具,孵化自阿里内部平台.有别于传统工具的繁复,PTS以互联网化的交互,面向分布式和云化 ...

  9. 鸟哥的Linux私房菜基础学习篇--进程(process)一 归纳总结

    权限!权限!权限! 没有权限,一些资源你是没办法使用的.在Linux中cat filename,结果屏幕显示了filename的内容,为什么你能看见,而我不能?权限.与UID/GID有关,与文件的属性 ...

  10. python 动态指定header获取网页源代码的函数

    import random import requests def get_htmla(url): aui=0 while aui==0: try: header={'User-Agent':'Moz ...