|
From:
Http://www.linuxgraphics.cn/android/gui_update_flow.html
Component Diagram
Related components are shown in:
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);
It mainly encapsulates some native functions.
private native Canvas lockCanvasNative(Rect dirty); public native void unlockCanvasAndPost(Canvas canvas);
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); }
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); |