77范文网 - 专业文章范例文档资料分享平台

Android的Graphic系统分析之skia(3)

来源:网络收集 时间:2020-04-16 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

status_t SurfaceFlinger::readyToRun() {

LOGI( “SurfaceFlinger’s main thread ready to run. ” “Initializing graphics H/W…”);

// we only support one display currently int dpy = 0;

{

// initialize the main display

GraphicPlane& plane(graphicPlane(dpy));

DisplayHardware* const hw = new DisplayHardware(this, dpy); plane.setDisplayHardware(hw); }

// create the shared control-block

//创建共享控制块,因未指定在何处分配内存,默认的是ashmem上 mServerHeap = new MemoryHeapBase(4096,

MemoryHeapBase::READ_ONLY, “SurfaceFlinger read-only heap”);

LOGE_IF(mServerHeap==0, “can’t create shared memory dealer”);

mServerCblk = static_cast (mServerHeap->getBase());//获取基址

LOGE_IF(mServerCblk==0, “can’t get to shared control block’s address”);

new(mServerCblk) surface_flinger_cblk_t;

// initialize primary screen

// (other display should be initialized in the same manner, but

// asynchronously, as they could come and go. None of this is supported yet).

const GraphicPlane& plane(graphicPlane(dpy)); const DisplayHardware& hw = plane.displayHardware(); const uint32_t w = hw.getWidth(); const uint32_t h = hw.getHeight(); const uint32_t f = hw.getFormat(); hw.makeCurrent();

// initialize the shared control block

mServerCblk->connected |= 1<displays + dpy; memset(dcblk, 0, sizeof(display_cblk_t)); dcblk->w = plane.getWidth(); dcblk->h = plane.getHeight(); dcblk->format = f;

dcblk->orientation = ISurfaceComposer::eOrientationDefault; dcblk->xdpi = hw.getDpiX(); dcblk->ydpi = hw.getDpiY(); dcblk->fps = hw.getRefreshRate(); dcblk->density = hw.getDensity();

……//省略部分代码

}

它为该控制块在ashmem上分配内存并对其初始化赋值。

SharedClient控制块

在SurfaceControl的getSurface() 时,会创建一个Surface,接着调用SurfaceClient的构造函数,由于SurfaceClient是singleton,即系统中只有一个实例,因此,在其第一次创建时调用了构造函数,而在其构造函数中调用了createClientConnection,这个就是建立连接的过程,就是分配内存控制块的过程。在client侧,其代码如下:

SurfaceClient(): Singleton(), mStatus(NO_INIT) {

sp //获取Composer service sf(ComposerService::getComposerService()); mComposerService = sf;

mClient = sf->createClientConnection();//创建client连接 if (mClient != NULL) {//创建成功的话

mControlMemory = mClient->getControlBlock();//获取内存块 if (mControlMemory != NULL) {

mControl = static_cast(

mControlMemory->getBase());//得到基地址,并转换为SharedClient指针,然后赋值给mControl if (mControl) {

mStatus = NO_ERROR; } } } }

在server侧,它调用UserClient的构造函数:

UserClient::UserClient(const sp& flinger) : ctrlblk(0), mBitmap(0), mFlinger(flinger) {

const int pgsize = getpagesize();//获取内存页大小

const int cblksize = //控制块大小,即进行页对齐后的SharedClient大小 ((sizeof(SharedClient)+(pgsize-1))&~(pgsize-1));

mCblkHeap = new MemoryHeapBase(cblksize, 0,//在ashmem上分配内存 “SurfaceFlinger Client control-block”);

ctrlblk = static_cast(mCblkHeap->getBase());//指针类型转换 if (ctrlblk) { // construct the shared structure in-place. new(ctrlblk) SharedClient;//调用构造函数初始化内存块对象 } }

也就是说,建立一个clientConnection的过程,也就是在server侧:在堆上分配一块页对齐的内存块,它被用来存储SharedClient对象;之后,client侧同样也拥有该块内存,同样也被解释为SharedClient对象指针。TODO:它们是跨进程的,所以通过IMemoryHeap这个binder接口来操作。

那么SharedClient是何方神圣呢?在头文件SharedBufferStack.h中有代码注释:“

These classes manage a stack of buffers in shared memory.

SharedClient: represents a client with several stacks

SharedBufferStack: represents a stack of buffers

SharedBufferClient: manipulates the SharedBufferStack from the client side

SharedBufferServer: manipulates the SharedBufferStack from the server side

Buffers can be dequeued until there are none available, they can be locked

unless they are in use by the server, which is only the case for the last

dequeue-able buffer. When these various conditions are not met, the caller

waits until the condition is met.

我们先来看一下比较重要的一个类SharedBufferStack

class SharedBufferStack {

……//省略部分代码

struct SmallRect {//定义了一个矩形:左上角和右下角的坐标 uint16_t l, t, r, b; };

//定义了一个平面区域,包含了若干(不超过5个)矩形 struct FlatRegion { // 52 bytes = 4 * (1 + 2*N) static const unsigned int NUM_RECT_MAX = 5; uint32_t count;

SmallRect rects[NUM_RECT_MAX]; };

struct BufferData {//64Bytes FlatRegion dirtyRegion;//5个矩形区域 SmallRect crop;//1个剪切矩形区

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库Android的Graphic系统分析之skia(3)在线全文阅读。

Android的Graphic系统分析之skia(3).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/974550.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: