Android overlay Learning

Source: Internet
Author: User

The previous article only learned about the overlay Hal architecture. Next we will continue to look at how the system layer calls the overlay module.

1. Test code

Frameworks/base/libs/surfaceflinger/tests/overlays. CPP provides a simple overlay call process. Unfortunately, this test program has errors,

In sp <surface> surface = client-> createsurface (getpid (), 0,320,
240, pixel_format_unknown, isurfacecomposer: epushbuffers );
This sentence cannot be compiled. The application for errors on the surface is irrelevant to overlay.

Let's take a look at this Code:

Int main (INT argc, char ** argv)
{
// Set up the thread-pool to create a thread pool
Sp <processstate> proc (processstate: Self ());
Processstate: Self ()-> startthreadpool ();

// Create a client to surfaceflinger create a surfaceflinger Client
Sp <surfacecomposerclient> client = new surfacecomposerclient ();

// Create pushbuffer surface to create a surface. Which of the following parameters is the type?
Sp <surface> surface = client-> createsurface (getpid (), 0,320,240,
Pixel_format_unknown, isurfacecomposer: epushbuffers );

// Get To The isurface Interface
Sp <isurface> isurface = test: getisurface (surface );
Printf ("isurface = % P/N", isurface. Get ());

// Now request an overlay to create an overlay
Sp <overlayref> ref = isurface-> createoverlay (320,240, pixel_format_rgb_565 );
Sp <overlay> overlay = new overlay (REF );

/*
* Here we can use the overlay API after creating the overlay API, you can use the overlay API, which corresponds to the specific implementation of overlay Hal.
*/

Overlay_buffer_t buffer;
Overlay-> dequeuebuffer (& buffer );
Printf ("buffer = % P/N", buffer );

Void * address = overlay-> getbufferaddress (buffer );
Printf ("address = % P/N", address );

Overlay-> queuebuffer (buffer); // The most important operation is to queue the buffer through queuebuffer.

Return 0;
}

2. Create an overlay in the Android system (call createoverlay)

1) camera related cameraservice. cpp (frameworks/base/camera/libcameraservice)
Setpreviewdisplay (), startpreviewmode ()
|
Setoverlay ()
|
Creatoverlay ()

2) Interface related isurface. cpp (frameworks/base/libs/UI)
Layerbaseclient: Surface: ontransact () <-- this function is located in layerbase. cpp. It seems to be a function used for ibind Process Communication.
|
Bnsurface: ontransact () // there are 5 methods. Case create_overlay is called only when overlay hardware is supported.
|
......
Switch (CODE ){
Case request_buffer :{
Check_interface (isurface, Data, reply );
Int bufferidx = data. readint32 ();
Int usage = data. readint32 ();
Sp <graphicbuffer> buffer (requestbuffer (bufferidx, usage ));
Return graphicbuffer: writetoparcel (reply, buffer. Get ());
}
Case register_buffers :{
Check_interface (isurface, Data, reply );
Bufferheap buffer;
Buffer. W = data. readint32 ();
Buffer. H = data. readint32 ();
Buffer. hor_stride = data. readint32 ();
Buffer. ver_stride = data. readint32 ();
Buffer. format = data. readint32 ();
Buffer. Transform = data. readint32 ();
Buffer. Flags = data. readint32 ();
Buffer. Heap = interface_cast <imemoryheap> (data. readstrongbinder ());
Status_t err = registerbuffers (buffer );
Reply-> writeint32 (ERR );
Return no_error;
} Break;
Case unregister_buffers :{
Check_interface (isurface, Data, reply );
Unregisterbuffers ();
Return no_error;
} Break;
Case post_buffer :{
Check_interface (isurface, Data, reply );
Ssize_t offset = data. readint32 ();
Postbuffer (offset );
Return no_error;
} Break;
Case create_overlay :{
Check_interface (isurface, Data, reply );
Int W = data. readint32 ();
Int H = data. readint32 ();
Int F = data. readint32 ();
Sp <overlayref> O = createoverlay (W, H, F );
Return overlayref: writetoparcel (reply, O );
} Break;
Default:
Return bbinder: ontransact (Code, Data, reply, flags );
......

3) layerbuffer. cpp (frameworks/base/libs/surfaceflinger) is actually the implementation of createoverlay.
Sp <overlayref> layerbuffer: surfacelayerbuffer: createoverlay (uint32_t W, uint32_t H, int32_t format)
|
Sp <overlayref> layerbuffer: createoverlay (uint32_t W, uint32_t H, int32_t F)
|
Sp <overlaysource> source = new overlaysource (* This, & result, W, H, f); // use overlaysource to create overlay

Layerbuffer: overlaysource () // This function calls the overlay Hal API createoverlay.
{
Overlay_control_device_t * overlay_dev = mlayer. mflinger-> getoverlayengine (); // get Hal
Overlay_t * overlay = overlay_dev-> createoverlay (overlay_dev, W, H, format); // Hal API

// Enable dithering...
Overlay_dev-> setparameter (overlay_dev, overlay, overlay_dither, overlay_enable );
// Set parameters and initialize the overlayref class. The overlayref constructor is in Overlay. cpp.
Moverlay = overlay;
Mwidth = overlay-> W;
Mheight = overlay-> h;
Mformat = overlay-> Format;
Mwidthstride = overlay-> w_stride;
Mheightstride = overlay-> h_stride;
Minitialized = false;
......
* Overlayref = new overlayref (moverlayhandle, channel, mwidth, mheight, mformat, mwidthstride, mheightstride );
}

3. Overlay Hal module Management

Overlay. cpp (frameworks/base/libs/UI) manages overlay Hal and encapsulates Hal APIs.

1) Open the overlay Hal module.
Overlay: overlay (const sp <overlayref> & overlayref)
: Moverlayref (overlayref), moverlaydata (0), mstatus (no_init)
{
Moverlaydata = NULL;
Hw_module_t const * module;
If (overlayref! = 0 ){
If (hw_get_module (overlay_hardware_module_id, & module) = 0 ){
If (overlay_data_open (module, & moverlaydata) = no_error ){
Mstatus = moverlaydata-> initialize (moverlaydata,
Overlayref-> moverlayhandle );
}
}
}
}

2) Overlay Hal Initialization
Refer to the previous section, overlayref = new overlayref (moverlayhandle, channel, mwidth, mheight, mformat, mwidthstride, mheightstride );

The constructor is located in Overlay. cpp.
Overlayref: overlayref (overlay_handle_t handle, const sp <ioverlay> & channel,
Uint32_t W, uint32_t H, int32_t F, uint32_t WS, uint32_t HS)
: Moverlayhandle (handle), moverlaychannel (channel ),
Mwidth (W), mheight (H), mformat (F), mwidthstride (WS), mheightstride (HS ),
Mownhandle (false)
{
}

3) A lot of APIs are encapsulated, but no call is found. It seems that a major change to the framework is required to truly utilize overlay.
For example, the opencore function written by TI is useful for video output.
Android_surface_output_omap34xx.cpp (Hardware/Ti/omap3/libopencorehw)

 

4. Summary

There are two types of overlay output objects: Video (mainly YUV format, calling system v4l2) and image data of isurface (in RGB format, Directly Writing framebuffer)
From the perspective of code implementation, the android system does not use the overlay function by default. Although the overlay Hal of skeleton is provided and encapsulated, the upper layer almost does not call the encapsulated API.
If you want to use overlay Hal well, you need to modify the upper-layer frame a lot. This may be important for video playback. For details, refer to TI's android_surface_output_omap34xx.cpp.
In addition, the overlay and copybit functions implemented by surface are partially repeated. Ti code mainly implements the overlay function of v4l2.

 

Http://hi.baidu.com/aokikyon/blog/item/6e4e622c4fdaaae18a1399d4.html


Related Article

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.