android在副屏中运行一个应用_android双屏显示的一些修改与尝试

本文介绍了在Android系统中如何在副屏运行应用程序,通过修改SurfaceFlinger的代码,特别是在`surfaceflinger.cpp`中增加新的DisplayHardware实例来支持副屏。详细讲解了DisplayHardware类的初始化过程,涉及到的EGL配置以及与HAL层的交互。内容包括对EGL显示、配置选择、上下文创建和双屏设备的初始化。在实际操作中,作者遇到了EGL相关的问题,这些问题正在研究中。
摘要由CSDN通过智能技术生成

由于目前跟踪代码只跟到了surfaceflinger这一层,下面先从surfaceflinger说起:

在frameworks\base\services\surfaceflinger\surfaceflinger.cpp这个文件中有如下代码片断:

status_t SurfaceFlinger::readyToRun()

{

LOGI("SurfaceFlinger's main thread ready to run. Initializing graphics H/W...\n");//we only support one display currentlyintdpy=0;

{//initialize the main displayGraphicPlane&plane(graphicPlane(dpy));

DisplayHardware*consthw=newDisplayHardware(this, dpy);

DisplayHardware*consthw1=newDisplayHardware(this,1); //这个是我加入测试HAL层用的,下面将介绍到

plane.setDisplayHardware(hw);

}//create the shared control-blockmServerHeap=newMemoryHeapBase(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).constGraphicPlane&plane(graphicPlane(dpy));constDisplayHardware&hw=plane.displayHardware();constuint32_t w=hw.getWidth();constuint32_t h=hw.getHeight();constuint32_t f=hw.getFormat();

hw.makeCurrent();//initialize the shared control blockmServerCblk->connected|=1<

display_cblk_t*dcblk=mServerCblk->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();//Initialize OpenGL|ESglPixelStorei(GL_UNPACK_ALIGNMENT,4);

glPixelStorei(GL_PACK_ALIGNMENT,4);

glEnableClientState(GL_VERTEX_ARRAY);

glEnable(GL_SCISSOR_TEST);

glShadeModel(GL_FLAT);

glDisable(GL_DITHER);

glDisable(GL_CULL_FACE);constuint16_t g0=pack565(0x0F,0x1F,0x0F);constuint16_t g1=pack565(0x17,0x2f,0x17);constuint16_t textureData[4]={ g0, g1, g1, g0 };

glGenTextures(1,&mWormholeTexName);

glBindTexture(GL_TEXTURE_2D, mWormholeTexName);

glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);

glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

glTexImage2D(GL_TEXTURE_2D,0, GL_RGB,2,2,0,GL_RGB, GL_UNSIGNED_SHORT_5_6_5, textureData);

glViewport(0,0, w, h);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glOrthof(0, w, h,0,0,1);

LayerDim::initDimmer(this, w, h);

mReadyToRunBarrier.open();/** We're now ready to accept clients...*///start boot animationproperty_set("ctl.start","bootanim");returnNO_ERROR;

}

重点看上面用黄色标出的那两行,其中DisplayHardware* const hw1 = new DisplayHardware(this, 1);是我加入用来测试HAL层的buffer分配用的,DisplayHardware这个是在frameworks\base\services\surfaceflinger\DisplayHardware\DisplayHardware.cpp这个文件中定义的,如以下代码片断:

/** Initialize the display to the specified values.

**/DisplayHardware::DisplayHardware(constsp&flinger,uint32_t dpy)

: DisplayHardwareBase(flinger, dpy),mFlags(0)

{

init(dpy);

}

而在同文件中有如下代码片断:

voidDisplayHardware::init(uint32_t dpy)

{

mNativeWindow=newFramebufferNativeWindow(dpy);

framebuffer_device_tconst*fbDev=mNativeWindow->getDevice();

mDpiX=mNativeWindow->xdpi;

mDpiY=mNativeWindow->ydpi;

mRefreshRate=fbDev->fps;

mOverlayEngine=NULL;

hw_module_tconst*module;if(hw_get_module(OVERLAY_HARDWARE_MODULE_ID,&module)==0)

{

overlay_control_open(module,&mOverlayEngine);

}

EGLint w, h, dummy;

EGLint numConfigs=0;

EGLSurface surface;

EGLContext context;//initialize EGLEGLint attribs[]={

EGL_SURFACE_TYPE,

EGL_WINDOW_BIT,

EGL_NONE,0,

EGL_NONE

};//debug: disable h/w renderingcharproperty[PROPERTY_VALUE_MAX];if(property_get("debug.sf.hw", property, NULL)>0)

{if(atoi(property)==0)

{

LOGW("H/W composition disabled");

attribs[2]=EGL_CONFIG_CAVEAT;

attribs[3]=EGL_SLOW_CONFIG;

}

}//TODO: all the extensions below should be queried through//eglGetProcAddress().//set to EGL wrapper to load SW OpenGLES onlyif(property_get("debug.sf.enable_hgl", property,"1")>0)

{if(atoi(property)==0)

{

eglSetImplementationAndroid(EGL_TRUE);

}

}/*下面这些都是和egl相关的,目前正在研究中,由于代码量太大,一起不好发上来,这里简单介绍一下,frameworks\base\opengl\libagl目录下是agl相关的一些代码,这些代码会生成libGLES_android.so 这个动态库,这点可以从此目录下的Android.mk文件里看出:

LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/egl

LOCAL_MODULE:= libGLES_android

在frameworks\base\opengl\libs目录下是egl相关的一些代码,这些代码主要把agl这个库作了个封装,并向外提供相关接口*/EGLDisplay display=eglGetDisplay((NativeDisplayType)dpy);//(EGL_DEFAULT_DISPLAY);LOGI("******DisplayHardware.cpp display:%d******\n",(int)display);

eglInitialize(display, NULL, NULL);

eglGetConfigs(display, NULL,0,&numConfigs);

EGLConfig config;

status_t err=EGLUtils::selectConfigForNativeWindow(display, attribs, mNativeWindow.get(),&config);

LOGE_IF(err,"couldn't find an EGLConfig matching the screen format");

EGLint r,g,b,a;

eglGetConfigAttrib(display, config, EGL_RED_SIZE,&r);

eglGetConfigAttrib(display, config, EGL_GREEN_SIZE,&g);

eglGetConfigAttrib(display, config, EGL_BLUE_SIZE,&b);

eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE,&a);if(mNativeWindow->isUpdateOnDemand())

mFlags|=PARTIAL_UPDATES;if(eglGetConfigAttrib(display, config, EGL_CONFIG_CAVEAT,&dummy)==EGL_TRUE)

{if(dummy==EGL_SLOW_CONFIG)

mFlags|=SLOW_CONFIG;

}/**

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值