Android GUI update process

Source: Internet
Author: User
Android GUI update process

 

From:

Http://www.linuxgraphics.cn/android/gui_update_flow.html

Component Diagram

Related components are shown in:

  • Viewroot

In private void draw (Boolean fullredrawneeded), lockcanvas is called to obtain a canvas object, and then the draw function of the subwindow (View) is called recursively to draw itself, finally, call unlockcanvasandpost to update the surface to the screen.

    canvas = surface.lockCanvas(dirty);    mView.draw(canvas);    surface.unlockCanvasAndPost(canvas);
  • Android/View/Surface

It mainly encapsulates some native functions.

    private native Canvas lockCanvasNative(Rect dirty);    public native   void unlockCanvasAndPost(Canvas canvas);
  • Android_view_surface.cpp

This is the implementation of native functions.

Surface_lockcanvas First locks the surface to obtain information about the surface, such as the format, width, height, and Pixel Buffer. Then create a bitmap, which shares a Pixel Buffer with the view, so that the view can be directly drawn to the surface.

Status_t err = surface-> lock (& info, & dirtyregion); bitmap. setpixels (info. BITs); nativecanvas-> setbitmapdevice (Bitmap); surface_unlockcanvasandpost it disconnects the relationship between skcanvas and surface, and then calls the surface unlockandpost.
    nativeCanvas->setBitmapDevice(SkBitmap());    status_t err = surface->unlockAndPost();
  • Surfaceflinger_client/surface. cpp

Surface: Lock call dequeuebuffer to obtain an available buffer. dequeuebuffer calls sharedbufferclient: dequeue to wait until the backbuffer is available, lock the buffer and fill in relevant information.

Status_t err = dequeuebuffer (& backbuffer); err = lockbuffer (backbuffer. Get (); surface: unlockandpost first unlock buffer, then call queuebuffer to display buffer.
Status_t err = mlockedbuffer-> unlock (); err = queuebuffer (mlockedbuffer. get (); surface: queuebuffer is interesting. It sets the updated region and notifies the server (surfaceflinger ). Msharedbufferclient-> setdirtyregion (bufidx, mdirtyregion); err = msharedbufferclient-> Queue (bufidx); client-> signalserver (); send requests to the service through Binder:
    virtual void signal() const    {        Parcel data, reply;        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());        remote()->transact(BnSurfaceComposer::SIGNAL, data, &reply, IBinder::FLAG_ONEWAY);    }
  • Surfaceflinger
Bnsurfacecomposer: ontransact case signal: {check_interface (isurfacecomposer, Data, reply); signal () ;}break; this is the code for processing signal in surfaceflinger. It calls surfaceflinger: signal, call surfaceflinger: signalevent and call messagequeue: invalidate to wake up the main loop of surfaceflinger.

In the main loop, waitforevent is returned, and handlerepaint is used to synthesize a layer/surface.

Bool surfaceflinger: threadloop () {waitforevent (); handlerepaint (); postframebuffer ();} surfaceflinger: handlerepaint will call composesurfaces to merge the surfaces to be drawn, it is drawn to the backbuffer of framebuffer.
For (size_t I = 0; I <count; ++ I) {const sp <layerbase> & layer = Layers [I]; const region & visibleregion (layer-> visibleregionscreen ); if (! Visibleregion. isempty () {/* broncho Cy add */# ifdef useoverlay mtoppest [1] = mtoppest [0]; mtoppest [0] = Layer-> getidentity (); # endif/* broncho end */const region clip (dirty. intersect (visibleregion); If (! Clip. isempty () {layer-> draw (CLIP) ;}} surfaceflinger: postframebuffer finally displays the buffer of framebuffer on the screen:
hw.flip(mInvalidRegion); -->eglSwapBuffers(dpy, surface);

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.