关闭

UNDERSTANDING ANDROID GRAPHICS INTERNALS – THE GRAPHIC SURFACE SERVICE INTERFACES

223人阅读 评论(0) 收藏 举报
分类:

As pointed out in previous posts, Android does not allow UI applications to write to the frame buffer directly; SurfaceFlinger administrates the allocation of surfaces/graphic buffers to UI applications, oversees the composition of surface buffers to the back frame buffer and display overlays. In accordance to this arrangement, its design features a suite of Interfaces which form the de facto  service contracts between the implementors and corresponding clients.

In this post, we cover ISurfaceComposer and ISurfaceComposerClient.

  • ISurfaceComposer

ISurfaceComposer is an advertised service Interface (i.e. registered with ServiceManager). The SurfaceFlinger implements BnSurfaceComposer while a client UI app must establish a BpSurfaceComposer proxy object by querying ServiceManager.

The methods in ISurfaceComposer have been in change in number and method signature, and will continue to evolve. Here we quote the interface declaration below.

/*  * This class defines the Binder IPC interface for accessing various  * SurfaceFlinger features.  */ class ISurfaceComposer: public IInterface { public:     DECLARE_META_INTERFACE(SurfaceComposer);

// flags for setTransactionState()

enum {         eSynchronous = 0x01,         eAnimation   = 0x02,     };

enum {         eDisplayIdMain = 0,         eDisplayIdHdmi = 1     };

/* create connection with surface flinger, requires      * ACCESS_SURFACE_FLINGER permission      */

virtual sp<ISurfaceComposerClient> createConnection() = 0;

/* create a graphic buffer allocator      */

virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc() = 0;

/* return an IDisplayEventConnection */

virtual sp<IDisplayEventConnection> createDisplayEventConnection() = 0;

/* create a display      * requires ACCESS_SURFACE_FLINGER permission.      */

virtual sp<IBinder> createDisplay(const String8& displayName,             bool secure) = 0;

/* get the token for the existing default displays. possible values      * for id are eDisplayIdMain and eDisplayIdHdmi.      */     virtual sp<IBinder> getBuiltInDisplay(int32_t id) = 0;

/* open/close transactions. requires ACCESS_SURFACE_FLINGER permission */

virtual void setTransactionState(const Vector<ComposerState>& state,             const Vector<DisplayState>& displays, uint32_t flags) = 0;

/* signal that we’re done booting.      * Requires ACCESS_SURFACE_FLINGER permission      */

virtual void bootFinished() = 0;

/* verify that an IGraphicBufferProducer was created by SurfaceFlinger.      */

virtual bool authenticateSurfaceTexture(             const sp<IGraphicBufferProducer>& surface) const = 0;

/* triggers screen off and waits for it to complete      * requires ACCESS_SURFACE_FLINGER permission.      */

virtual void blank(const sp<IBinder>& display) = 0;

/* triggers screen on and waits for it to complete      * requires ACCESS_SURFACE_FLINGER permission.      */

virtual void unblank(const sp<IBinder>& display) = 0;

/* returns information about a display      * intended to be used to get information about built-in displays */

virtual status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) = 0;

/* Capture the specified screen. requires READ_FRAME_BUFFER permission
* This function will fail if there is a secure window on screen.
*/
virtual status_t captureScreen(const sp<IBinder>& display,
const sp<IGraphicBufferProducer>& producer,
uint32_t reqWidth, uint32_t reqHeight,
uint32_t minLayerZ, uint32_t maxLayerZ,
bool isCpuConsumer) = 0;
};

Notes on the usage.

1.  In surface operations, createConnection() is the first method to be invoked to obtain a BpSurfaceComposer object. Inside SurfaceFlinger, an instance of ISurfaceComposerClient implementator Client (declared in  native/services/surfaceflinger/Client.h) is created; SurfaceFlinger does not explicitly track outstanding connections, the Client instances is associated with Layers ( declared in native/services/surfaceflinger/Layer.h)  it created later which are tracked within SufaceFlinger.

2. createGraphicBufferAlloc () is invoked to obtain IGraphiBufferAlloc interface for the client.

3. setTransactionState() is invoked to inform SurfaceFlinger state of changes of the surface; changes are categorized in two types, layer_state_t and Display_state (both declared in native/include/private/gui/LayerState.h)  respectively. layer_state_t tracks changes in position, depth, sizes,  color scheme, alpha property and crop property, etc; Display_state tracks changes in orientation, etc.

4. createDisplayEventConnection() is used for vsync purpose.

5. captureScreen() is used for capturing a snapshot of screen display.

  •  ISurfaceComposerClient

The interface is declared in frameworks/native/include/gui/ISurfaceComposerClient.h.

class ISurfaceComposerClient : public IInterface { public:     DECLARE_META_INTERFACE(SurfaceComposerClient);

// flags for createSurface()

enum {

// (keep in sync with Surface.java)

eHidden             = 0x00000004,

eDestroyBackbuffer  = 0x00000020,

eSecure             = 0x00000080,

eNonPremultiplied   = 0x00000100,

eOpaque             = 0x00000400,

eProtectedByApp     = 0x00000800,

eProtectedByDRM     = 0x00001000,

eFXSurfaceNormal    = 0x00000000,

eFXSurfaceDim       = 0x00020000,

eFXSurfaceMask      = 0x000F0000,     };

/*      * Requires ACCESS_SURFACE_FLINGER permission      */

virtual status_t createSurface(             const String8& name, int32_t w, uint32_t h,             PixelFormat format, uint32_t flags,             sp<IBinder>* handle,             sp<IGraphicBufferProducer>* gbp) = 0;

/*      * Requires ACCESS_SURFACE_FLINGER permission      */

virtual status_t destroySurface(const sp<IBinder>& handle) = 0; };

In the createSurface() method, the initial width, height and the color scheme is specified. Other attributes such as depth on the screen, position, etc. are specified in the SurfaceFlinger::setTransactionState(). All Surface attributes are subject to change anyway.

0
0
查看评论
发表评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场

Android 4.4 Graphic系统详解(4)HWUI概述

1 概述 Android从3.0(API Level 11)开始,在绘制View的时候支持硬件加速,充分利用GPU的特性,使得绘制更加平滑。 实质上就是Android3.0以前,几乎所有的图形绘制都...
  • michaelcao1980
  • michaelcao1980
  • 2015-01-28 17:48
  • 11449

通过Graphics对象来实现动画效果

通过Graphics对象来实现动画效果
  • yaerfeng
  • yaerfeng
  • 2014-02-23 10:43
  • 1526

Android平台截图研究 FrameBuffer(/dev/graphics/fb0) 文件内容研究!(含源码工程)

啊赛
  • A1w0n
  • A1w0n
  • 2014-07-12 18:22
  • 8574

android graphic(8)—surface申请GraphicBuffer过程

http://blog.csdn.net/lewif/article/details/50703679 目录(?)[+] surface的dequeueBuffer函数 向BufferQ...
  • fu_shuwu
  • fu_shuwu
  • 2016-11-06 20:22
  • 869

android graphic(10)—activity申请surface流程

http://blog.csdn.net/lewif/article/details/50735460 目录(?)[+] create new Activity newActivit...
  • fu_shuwu
  • fu_shuwu
  • 2016-11-06 20:45
  • 510

Android N Graphics之应用侧的surface的创建

我们知道的是在ViewRootImpl的setView函数中调用了requestLayout函数,我们从这个函数中去分析一下surface的创建流程 public void requestLay...
  • u012638414
  • u012638414
  • 2017-08-10 00:30
  • 155

ATL Internals 2ed复习.chapter 8.COM Collection and Enumeration Interfaces

COM Collection接口定义类似于: [ object, dual ] template typename T> interface ICollection : IDispatch { ...
  • mcmcmc
  • mcmcmc
  • 2012-10-10 23:02
  • 701

A-Deeper-Understanding-of-Spark-Internals(Spark内核深入理解)

这篇文章是对Spark Submit 2014会议上Aaron Davidson做的报告的PPT内容的整理,报告主要讲了Spark中shuffle过程的调优。 做了下整理,加入一些自己的理解。   G...
  • sdujava2011
  • sdujava2011
  • 2016-01-28 21:52
  • 509

Understanding JVM Internals

原文地址:http://www.cubrid.org/blog/dev-platform/understanding-jvm-internals/
  • jayceyxc635
  • jayceyxc635
  • 2015-09-06 17:40
  • 65

surface在android4.2跟4.4系统中本地service里使用上的差异

surface在android4.2跟4.4系统中本地service里使用上的差异        了解android的人都知道,android的应用是java写的,运行的效率应该比C/C++要低一些,...
  • sundesheng125
  • sundesheng125
  • 2014-04-07 17:42
  • 2708
    个人资料
    • 访问:19622次
    • 积分:332
    • 等级:
    • 排名:千里之外
    • 原创:8篇
    • 转载:38篇
    • 译文:0篇
    • 评论:0条
    文章分类