Let's talk about ANPInterface today.
Probably to make up for the shortcomings of NPAPI on Android, Google implemented ANPInterface on the Android browser. To put it bluntly, this is a series of Operation interfaces (functions) that provide something not available in the NPAPI. The plug-in can obtain these anpxxxinterfaces during initialization and use them during running.
For the use of these interfaces, you can take a look at how BrowserPlugin,
In main. cpp, some ANPInterface global variables are declared:
Using gSoundI; <br/> using gBitmapI; <br/> using gCanvasI; <br/> ANPEventInterfaceV0 gEventI; <br/> ANPLogInterfaceV0 gLogI; <br/> using gPaintI; <br/> Upgrade gPathI; <br/> ANPSurfaceInterfaceV0 gSurfaceI; <br/> ANPSystemInterfaceV0 g1_emi; <br/> Upgrade gTypefaceI; <br/> anp;winterfacev0 g1_wi;
Below is a section in NP_Initialize:
Static const struct {<br/> npnvariable V; <br/> uint32_t size; <br/> anpinterface * I; <br/>} gpairs [] ={< br/> {signature, sizeof (gsoundi), & gsoundi },< br/> {kbitmapinterfacev0_anpgetvalue, sizeof (gbitmapi ), & gbitmapi },< br/> {signature, sizeof (gcanvasi), & gcanvasi },< br/> {keventinterfacev0_anpgetvalue, sizeof (geventi), & geventi }, <br/> {signature, sizeof (Glogi), & Glogi}, <br/> {signature, sizeof (gpainti), & gpainti}, <br/> {kpathinterfacev0_anpgetvalue, sizeof (gpathi), & gpathi}, <br/> {signature, sizeof (gsurfacei), & gsurfacei}, <br/> {ksysteminterfacev0_anpgetvalue, sizeof (gsystemi ), & gsystemi },< br/> {ktypefaceinterfacev0_anpgetvalue, sizeof (gtypefacei), & gtypefacei },< br/> {signature, sizeof (gsf-wi), & gsf-wi }, <br/>}; <br/> for (size_t I = 0; I <array_count (gpairs); I ++) {<br/> gpairs [I]. i-> insize = gpairs [I]. size; <br/> nperror err = browser-> getvalue (null, gpairs [I]. v, gpairs [I]. i); <br/> If (ERR) {<br/> return err; <br/>}< br/>}
The purpose of this section is to obtain a series of anpinterfaces through getvalue in the browser. Because it is defined as a global variable, these interfaces can be used anytime, anywhere, like this:
GLogI. log (kDebug_ANPLogType, "------ % p DrawingModel is % d", instance, model );
The following describes the operations provided by these interfaces as I know.
ANPAudioTrackInterface this is a set of audio interfaces that provide the function of playing audio tracks
ANPBitmapInterface has only one function getPixelPacking. The parameter value of PixelPacking is set according to the given format.
ANPCanvasInterface provides a series of ANPCanvas plotting operations. In fact, the Skcanvas interface of skia is packaged.
Anpeventinterface provides a postevent function, which can be used to send custom messages (anpevent) to itself ).
Anploginterface provides logcat output
The anppaintinterface encapsulates the skpaint interface of skia. If you want to use anpcanvas to draw a picture, you may need to use these interfaces to set the anppaint parameter.
Anpmatrixinterface provides some operation interfaces of anpmatrix (skmatrix), which may be used for Drawing Images Using anpcanvas.
Anppathinterface provides some operation interfaces of anppath (skpath), which may be used for Drawing Images Using anpcanvas.
Anpsurfaceinterface provides the interface lock for retrieving the canvas anpbitmap from surfaceview and the interface unlock for submitting the drawing result.
ANPSystemInterface getApplicationDataDirectory can be used to obtain an address called PluginSharedDataDirectory, which I have not tried. In 2.2, loadJavaClass is added to obtain Java Class instances, this is mainly used to instantiate the View during the loading process.
I am not very clear about ANPTypefaceInterface. It seems to be the encapsulation of some functions in skia, probably related to fonts.
Anp?winterface window operation interfaces, including displaying a soft keyboard and full screen control
For specific definitions, see related files under external/webkit/WebKit/android/plugins.
For more information, see the example of development/samples/BrowserPlugin.
It can be seen that most of the interfaces provided by ANPInterface come from underlying libraries other than webkit. Some may ask, what is the difference between this and direct connection to these databases? In fact, from the result, both methods are similar, but ANPInterface is more reflected as a packaging, even if the underlying library has changed, as long as the ANPInterface remains unchanged, the code of the plug-in does not need to be modified. For example, from Android 2.1 to 2.2, surfaceflinger has made great changes, but ANPSurfaceInterface has not changed. Therefore, the plug-in does not need to modify this part. However, in actual use, you should choose to use ANPInterface or directly connect to the external database as needed. After all, the interfaces provided by ANPInterface are still very limited.