Home | History | Annotate | Download | only in plugins
      1 /*
      2  * Copyright 2009, The Android Open Source Project
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  *  * Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  *  * Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 /*  Defines the android-specific types and functions as part of npapi
     27 
     28     In particular, defines the window and event types that are passed to
     29     NPN_GetValue, NPP_SetWindow and NPP_HandleEvent.
     30 
     31     To minimize what native libraries the plugin links against, some
     32     functionality is provided via function-ptrs (e.g. time, sound)
     33  */
     34 
     35 #ifndef android_npapi_H
     36 #define android_npapi_H
     37 
     38 #include <stdint.h>
     39 
     40 #include "npapi.h"
     41 
     42 ///////////////////////////////////////////////////////////////////////////////
     43 // General types
     44 
     45 enum ANPBitmapFormats {
     46     kUnknown_ANPBitmapFormat    = 0,
     47     kRGBA_8888_ANPBitmapFormat  = 1,
     48     kRGB_565_ANPBitmapFormat    = 2
     49 };
     50 typedef int32_t ANPBitmapFormat;
     51 
     52 struct ANPPixelPacking {
     53     uint8_t AShift;
     54     uint8_t ABits;
     55     uint8_t RShift;
     56     uint8_t RBits;
     57     uint8_t GShift;
     58     uint8_t GBits;
     59     uint8_t BShift;
     60     uint8_t BBits;
     61 };
     62 
     63 struct ANPBitmap {
     64     void*           baseAddr;
     65     ANPBitmapFormat format;
     66     int32_t         width;
     67     int32_t         height;
     68     int32_t         rowBytes;
     69 };
     70 
     71 struct ANPRectF {
     72     float   left;
     73     float   top;
     74     float   right;
     75     float   bottom;
     76 };
     77 
     78 struct ANPRectI {
     79     int32_t left;
     80     int32_t top;
     81     int32_t right;
     82     int32_t bottom;
     83 };
     84 
     85 struct ANPCanvas;
     86 struct ANPMatrix;
     87 struct ANPPaint;
     88 struct ANPPath;
     89 struct ANPRegion;
     90 struct ANPTypeface;
     91 
     92 enum ANPMatrixFlags {
     93     kIdentity_ANPMatrixFlag     = 0,
     94     kTranslate_ANPMatrixFlag    = 0x01,
     95     kScale_ANPMatrixFlag        = 0x02,
     96     kAffine_ANPMatrixFlag       = 0x04,
     97     kPerspective_ANPMatrixFlag  = 0x08,
     98 };
     99 typedef uint32_t ANPMatrixFlag;
    100 
    101 ///////////////////////////////////////////////////////////////////////////////
    102 // NPN_GetValue
    103 
    104 /** queries for a specific ANPInterface.
    105 
    106     Maybe called with NULL for the NPP instance
    107 
    108     NPN_GetValue(inst, interface_enum, ANPInterface*)
    109  */
    110 #define kLogInterfaceV0_ANPGetValue         ((NPNVariable)1000)
    111 #define kAudioTrackInterfaceV0_ANPGetValue  ((NPNVariable)1001)
    112 #define kCanvasInterfaceV0_ANPGetValue      ((NPNVariable)1002)
    113 #define kMatrixInterfaceV0_ANPGetValue      ((NPNVariable)1003)
    114 #define kPaintInterfaceV0_ANPGetValue       ((NPNVariable)1004)
    115 #define kPathInterfaceV0_ANPGetValue        ((NPNVariable)1005)
    116 #define kTypefaceInterfaceV0_ANPGetValue    ((NPNVariable)1006)
    117 #define kWindowInterfaceV0_ANPGetValue      ((NPNVariable)1007)
    118 #define kBitmapInterfaceV0_ANPGetValue      ((NPNVariable)1008)
    119 #define kSurfaceInterfaceV0_ANPGetValue     ((NPNVariable)1009)
    120 #define kSystemInterfaceV0_ANPGetValue      ((NPNVariable)1010)
    121 #define kEventInterfaceV0_ANPGetValue       ((NPNVariable)1011)
    122 
    123 /** queries for the drawing models supported on this device.
    124 
    125     NPN_GetValue(inst, kSupportedDrawingModel_ANPGetValue, uint32_t* bits)
    126  */
    127 #define kSupportedDrawingModel_ANPGetValue  ((NPNVariable)2000)
    128 
    129 /** queries for the context (android.content.Context) of the plugin. If no
    130     instance is specified the application's context is returned. If the instance
    131     is given then the context returned is identical to the context used to
    132     create the webview in which that instance resides.
    133 
    134     NOTE: Holding onto a non-application context after your instance has been
    135     destroyed will cause a memory leak.  Refer to the android documentation to
    136     determine what context is best suited for your particular scenario.
    137 
    138     NPN_GetValue(inst, kJavaContext_ANPGetValue, jobject context)
    139  */
    140 #define kJavaContext_ANPGetValue            ((NPNVariable)2001)
    141 
    142 ///////////////////////////////////////////////////////////////////////////////
    143 // NPN_SetValue
    144 
    145 /** Request to set the drawing model. SetValue will return false if the drawing
    146     model is not supported or has insufficient information for configuration.
    147 
    148     NPN_SetValue(inst, kRequestDrawingModel_ANPSetValue, (void*)foo_ANPDrawingModel)
    149  */
    150 #define kRequestDrawingModel_ANPSetValue    ((NPPVariable)1000)
    151 
    152 /** These are used as bitfields in ANPSupportedDrawingModels_EnumValue,
    153     and as-is in ANPRequestDrawingModel_EnumValue. The drawing model determines
    154     how to interpret the ANPDrawingContext provided in the Draw event and how
    155     to interpret the NPWindow->window field.
    156  */
    157 enum ANPDrawingModels {
    158     /** Draw into a bitmap from the browser thread in response to a Draw event.
    159         NPWindow->window is reserved (ignore)
    160      */
    161     kBitmap_ANPDrawingModel  = 1 << 0,
    162     /** Draw into a surface (e.g. raster, openGL, etc.) using the Java surface
    163         interface. When this model is used the browser will invoke the Java
    164         class specified in the plugin's apk manifest. From that class the browser
    165         will invoke the appropriate method to return an an instance of a android
    166         Java View. The instance is then embedded in the html. The plugin can then
    167         manipulate the view as it would any normal Java View in android.
    168 
    169         Unlike the bitmap model, a surface model is opaque so no html content
    170         behind the plugin will be  visible. Unless the plugin needs to be
    171         transparent the surface model should be chosen over the bitmap model as
    172         it will have better performance.
    173 
    174         Further, a plugin can manipulate some surfaces in native code using the
    175         ANPSurfaceInterface.  This interface can be used to manipulate Java
    176         objects that extend Surface.class by allowing them to access the
    177         surface's underlying bitmap in native code.  For instance, if a raster
    178         surface is used the plugin can lock, draw directly into the bitmap, and
    179         unlock the surface in native code without making JNI calls to the Java
    180         surface object.
    181      */
    182     kSurface_ANPDrawingModel = 1 << 1,
    183 };
    184 typedef int32_t ANPDrawingModel;
    185 
    186 /** Request to receive/disable events. If the pointer is NULL then all flags will
    187     be disabled. Otherwise, the event type will be enabled iff its corresponding
    188     bit in the EventFlags bit field is set.
    189 
    190     NPN_SetValue(inst, ANPAcceptEvents, (void*)EventFlags)
    191  */
    192 #define kAcceptEvents_ANPSetValue           ((NPPVariable)1001)
    193 
    194 /** The EventFlags are a set of bits used to determine which types of events the
    195     plugin wishes to receive. For example, if the value is 0x03 then both key
    196     and touch events will be provided to the plugin.
    197  */
    198 enum ANPEventFlag {
    199     kKey_ANPEventFlag               = 0x01,
    200     kTouch_ANPEventFlag             = 0x02,
    201 };
    202 typedef uint32_t ANPEventFlags;
    203 
    204 ///////////////////////////////////////////////////////////////////////////////
    205 // NPP_GetValue
    206 
    207 /** Requests that the plugin return a java surface to be displayed. This will
    208     only be used if the plugin has choosen the kSurface_ANPDrawingModel.
    209 
    210     NPP_GetValue(inst, kJavaSurface_ANPGetValue, jobject surface)
    211  */
    212 #define kJavaSurface_ANPGetValue            ((NPPVariable)2000)
    213 
    214 
    215 ///////////////////////////////////////////////////////////////////////////////
    216 // ANDROID INTERFACE DEFINITIONS
    217 
    218 /** Interfaces provide additional functionality to the plugin via function ptrs.
    219     Once an interface is retrieved, it is valid for the lifetime of the plugin
    220     (just like browserfuncs).
    221 
    222     All ANPInterfaces begin with an inSize field, which must be set by the
    223     caller (plugin) with the number of bytes allocated for the interface.
    224     e.g. SomeInterface si; si.inSize = sizeof(si); browser->getvalue(..., &si);
    225  */
    226 struct ANPInterface {
    227     uint32_t    inSize;     // size (in bytes) of this struct
    228 };
    229 
    230 enum ANPLogTypes {
    231     kError_ANPLogType   = 0,    // error
    232     kWarning_ANPLogType = 1,    // warning
    233     kDebug_ANPLogType   = 2     // debug only (informational)
    234 };
    235 typedef int32_t ANPLogType;
    236 
    237 struct ANPLogInterfaceV0 : ANPInterface {
    238     /** dumps printf messages to the log file
    239         e.g. interface->log(instance, kWarning_ANPLogType, "value is %d", value);
    240      */
    241     void (*log)(ANPLogType, const char format[], ...);
    242 };
    243 
    244 struct ANPBitmapInterfaceV0 : ANPInterface {
    245     /** Returns true if the specified bitmap format is supported, and if packing
    246         is non-null, sets it to the packing info for that format.
    247      */
    248     bool (*getPixelPacking)(ANPBitmapFormat, ANPPixelPacking* packing);
    249 };
    250 
    251 struct ANPMatrixInterfaceV0 : ANPInterface {
    252     /** Return a new identity matrix
    253      */
    254     ANPMatrix*  (*newMatrix)();
    255     /** Delete a matrix previously allocated by newMatrix()
    256      */
    257     void        (*deleteMatrix)(ANPMatrix*);
    258 
    259     ANPMatrixFlag (*getFlags)(const ANPMatrix*);
    260 
    261     void        (*copy)(ANPMatrix* dst, const ANPMatrix* src);
    262 
    263     /** Return the matrix values in a float array (allcoated by the caller),
    264         where the values are treated as follows:
    265         w  = x * [6] + y * [7] + [8];
    266         x' = (x * [0] + y * [1] + [2]) / w;
    267         y' = (x * [3] + y * [4] + [5]) / w;
    268      */
    269     void        (*get3x3)(const ANPMatrix*, float[9]);
    270     /** Initialize the matrix from values in a float array,
    271         where the values are treated as follows:
    272          w  = x * [6] + y * [7] + [8];
    273          x' = (x * [0] + y * [1] + [2]) / w;
    274          y' = (x * [3] + y * [4] + [5]) / w;
    275      */
    276     void        (*set3x3)(ANPMatrix*, const float[9]);
    277 
    278     void        (*setIdentity)(ANPMatrix*);
    279     void        (*preTranslate)(ANPMatrix*, float tx, float ty);
    280     void        (*postTranslate)(ANPMatrix*, float tx, float ty);
    281     void        (*preScale)(ANPMatrix*, float sx, float sy);
    282     void        (*postScale)(ANPMatrix*, float sx, float sy);
    283     void        (*preSkew)(ANPMatrix*, float kx, float ky);
    284     void        (*postSkew)(ANPMatrix*, float kx, float ky);
    285     void        (*preRotate)(ANPMatrix*, float degrees);
    286     void        (*postRotate)(ANPMatrix*, float degrees);
    287     void        (*preConcat)(ANPMatrix*, const ANPMatrix*);
    288     void        (*postConcat)(ANPMatrix*, const ANPMatrix*);
    289 
    290     /** Return true if src is invertible, and if so, return its inverse in dst.
    291         If src is not invertible, return false and ignore dst.
    292      */
    293     bool        (*invert)(ANPMatrix* dst, const ANPMatrix* src);
    294 
    295     /** Transform the x,y pairs in src[] by this matrix, and store the results
    296         in dst[]. The count parameter is treated as the number of pairs in the
    297         array. It is legal for src and dst to point to the same memory, but
    298         illegal for the two arrays to partially overlap.
    299      */
    300     void        (*mapPoints)(ANPMatrix*, float dst[], const float src[],
    301                              int32_t count);
    302 };
    303 
    304 struct ANPPathInterfaceV0 : ANPInterface {
    305     /** Return a new path */
    306     ANPPath* (*newPath)();
    307 
    308     /** Delete a path previously allocated by ANPPath() */
    309     void (*deletePath)(ANPPath*);
    310 
    311     /** Make a deep copy of the src path, into the dst path (already allocated
    312         by the caller).
    313      */
    314     void (*copy)(ANPPath* dst, const ANPPath* src);
    315 
    316     /** Returns true if the two paths are the same (i.e. have the same points)
    317      */
    318     bool (*equal)(const ANPPath* path0, const ANPPath* path1);
    319 
    320     /** Remove any previous points, initializing the path back to empty. */
    321     void (*reset)(ANPPath*);
    322 
    323     /** Return true if the path is empty (has no lines, quads or cubics). */
    324     bool (*isEmpty)(const ANPPath*);
    325 
    326     /** Return the path's bounds in bounds. */
    327     void (*getBounds)(const ANPPath*, ANPRectF* bounds);
    328 
    329     void (*moveTo)(ANPPath*, float x, float y);
    330     void (*lineTo)(ANPPath*, float x, float y);
    331     void (*quadTo)(ANPPath*, float x0, float y0, float x1, float y1);
    332     void (*cubicTo)(ANPPath*, float x0, float y0, float x1, float y1,
    333                     float x2, float y2);
    334     void (*close)(ANPPath*);
    335 
    336     /** Offset the src path by [dx, dy]. If dst is null, apply the
    337         change directly to the src path. If dst is not null, write the
    338         changed path into dst, and leave the src path unchanged. In that case
    339         dst must have been previously allocated by the caller.
    340      */
    341     void (*offset)(ANPPath* src, float dx, float dy, ANPPath* dst);
    342 
    343     /** Transform the path by the matrix. If dst is null, apply the
    344         change directly to the src path. If dst is not null, write the
    345         changed path into dst, and leave the src path unchanged. In that case
    346         dst must have been previously allocated by the caller.
    347      */
    348     void (*transform)(ANPPath* src, const ANPMatrix*, ANPPath* dst);
    349 };
    350 
    351 /** ANPColor is always defined to have the same packing on all platforms, and
    352     it is always unpremultiplied.
    353 
    354     This is in contrast to 32bit format(s) in bitmaps, which are premultiplied,
    355     and their packing may vary depending on the platform, hence the need for
    356     ANPBitmapInterface::getPixelPacking()
    357  */
    358 typedef uint32_t ANPColor;
    359 #define ANPColor_ASHIFT     24
    360 #define ANPColor_RSHIFT     16
    361 #define ANPColor_GSHIFT     8
    362 #define ANPColor_BSHIFT     0
    363 #define ANP_MAKE_COLOR(a, r, g, b)  \
    364                    (((a) << ANPColor_ASHIFT) |  \
    365                     ((r) << ANPColor_RSHIFT) |  \
    366                     ((g) << ANPColor_GSHIFT) |  \
    367                     ((b) << ANPColor_BSHIFT))
    368 
    369 enum ANPPaintFlag {
    370     kAntiAlias_ANPPaintFlag         = 1 << 0,
    371     kFilterBitmap_ANPPaintFlag      = 1 << 1,
    372     kDither_ANPPaintFlag            = 1 << 2,
    373     kUnderlineText_ANPPaintFlag     = 1 << 3,
    374     kStrikeThruText_ANPPaintFlag    = 1 << 4,
    375     kFakeBoldText_ANPPaintFlag      = 1 << 5,
    376 };
    377 typedef uint32_t ANPPaintFlags;
    378 
    379 enum ANPPaintStyles {
    380     kFill_ANPPaintStyle             = 0,
    381     kStroke_ANPPaintStyle           = 1,
    382     kFillAndStroke_ANPPaintStyle    = 2
    383 };
    384 typedef int32_t ANPPaintStyle;
    385 
    386 enum ANPPaintCaps {
    387     kButt_ANPPaintCap   = 0,
    388     kRound_ANPPaintCap  = 1,
    389     kSquare_ANPPaintCap = 2
    390 };
    391 typedef int32_t ANPPaintCap;
    392 
    393 enum ANPPaintJoins {
    394     kMiter_ANPPaintJoin = 0,
    395     kRound_ANPPaintJoin = 1,
    396     kBevel_ANPPaintJoin = 2
    397 };
    398 typedef int32_t ANPPaintJoin;
    399 
    400 enum ANPPaintAligns {
    401     kLeft_ANPPaintAlign     = 0,
    402     kCenter_ANPPaintAlign   = 1,
    403     kRight_ANPPaintAlign    = 2
    404 };
    405 typedef int32_t ANPPaintAlign;
    406 
    407 enum ANPTextEncodings {
    408     kUTF8_ANPTextEncoding   = 0,
    409     kUTF16_ANPTextEncoding  = 1,
    410 };
    411 typedef int32_t ANPTextEncoding;
    412 
    413 enum ANPTypefaceStyles {
    414     kBold_ANPTypefaceStyle      = 1 << 0,
    415     kItalic_ANPTypefaceStyle    = 1 << 1
    416 };
    417 typedef uint32_t ANPTypefaceStyle;
    418 
    419 typedef uint32_t ANPFontTableTag;
    420 
    421 struct ANPFontMetrics {
    422     /** The greatest distance above the baseline for any glyph (will be <= 0) */
    423     float   fTop;
    424     /** The recommended distance above the baseline (will be <= 0) */
    425     float   fAscent;
    426     /** The recommended distance below the baseline (will be >= 0) */
    427     float   fDescent;
    428     /** The greatest distance below the baseline for any glyph (will be >= 0) */
    429     float   fBottom;
    430     /** The recommended distance to add between lines of text (will be >= 0) */
    431     float   fLeading;
    432 };
    433 
    434 struct ANPTypefaceInterfaceV0 : ANPInterface {
    435     /** Return a new reference to the typeface that most closely matches the
    436         requested name and style. Pass null as the name to return
    437         the default font for the requested style. Will never return null
    438 
    439         The 5 generic font names "serif", "sans-serif", "monospace", "cursive",
    440         "fantasy" are recognized, and will be mapped to their logical font
    441         automatically by this call.
    442 
    443         @param name     May be NULL. The name of the font family.
    444         @param style    The style (normal, bold, italic) of the typeface.
    445         @return reference to the closest-matching typeface. Caller must call
    446                 unref() when they are done with the typeface.
    447      */
    448     ANPTypeface* (*createFromName)(const char name[], ANPTypefaceStyle);
    449 
    450     /** Return a new reference to the typeface that most closely matches the
    451         requested typeface and specified Style. Use this call if you want to
    452         pick a new style from the same family of the existing typeface.
    453         If family is NULL, this selects from the default font's family.
    454 
    455         @param family  May be NULL. The name of the existing type face.
    456         @param s       The style (normal, bold, italic) of the type face.
    457         @return reference to the closest-matching typeface. Call must call
    458                 unref() when they are done.
    459      */
    460     ANPTypeface* (*createFromTypeface)(const ANPTypeface* family,
    461                                        ANPTypefaceStyle);
    462 
    463     /** Return the owner count of the typeface. A newly created typeface has an
    464         owner count of 1. When the owner count is reaches 0, the typeface is
    465         deleted.
    466      */
    467     int32_t (*getRefCount)(const ANPTypeface*);
    468 
    469     /** Increment the owner count on the typeface
    470      */
    471     void (*ref)(ANPTypeface*);
    472 
    473     /** Decrement the owner count on the typeface. When the count goes to 0,
    474         the typeface is deleted.
    475      */
    476     void (*unref)(ANPTypeface*);
    477 
    478     /** Return the style bits for the specified typeface
    479      */
    480     ANPTypefaceStyle (*getStyle)(const ANPTypeface*);
    481 
    482     /** Some fonts are stored in files. If that is true for the fontID, then
    483         this returns the byte length of the full file path. If path is not null,
    484         then the full path is copied into path (allocated by the caller), up to
    485         length bytes. If index is not null, then it is set to the truetype
    486         collection index for this font, or 0 if the font is not in a collection.
    487 
    488         Note: getFontPath does not assume that path is a null-terminated string,
    489         so when it succeeds, it only copies the bytes of the file name and
    490         nothing else (i.e. it copies exactly the number of bytes returned by the
    491         function. If the caller wants to treat path[] as a C string, it must be
    492         sure that it is allocated at least 1 byte larger than the returned size,
    493         and it must copy in the terminating 0.
    494 
    495         If the fontID does not correspond to a file, then the function returns
    496         0, and the path and index parameters are ignored.
    497 
    498         @param fontID  The font whose file name is being queried
    499         @param path    Either NULL, or storage for receiving up to length bytes
    500                        of the font's file name. Allocated by the caller.
    501         @param length  The maximum space allocated in path (by the caller).
    502                        Ignored if path is NULL.
    503         @param index   Either NULL, or receives the TTC index for this font.
    504                        If the font is not a TTC, then will be set to 0.
    505         @return The byte length of th font's file name, or 0 if the font is not
    506                 baked by a file.
    507      */
    508     int32_t (*getFontPath)(const ANPTypeface*, char path[], int32_t length,
    509                            int32_t* index);
    510 
    511     /** Return a UTF8 encoded path name for the font directory, or NULL if not
    512         supported. If returned, this string address will be valid for the life
    513         of the plugin instance. It will always end with a '/' character.
    514      */
    515     const char* (*getFontDirectoryPath)();
    516 };
    517 
    518 struct ANPPaintInterfaceV0 : ANPInterface {
    519     /** Return a new paint object, which holds all of the color and style
    520         attributes that affect how things (geometry, text, bitmaps) are drawn
    521         in a ANPCanvas.
    522 
    523         The paint that is returned is not tied to any particular plugin
    524         instance, but it must only be accessed from one thread at a time.
    525      */
    526     ANPPaint*   (*newPaint)();
    527     void        (*deletePaint)(ANPPaint*);
    528 
    529     ANPPaintFlags (*getFlags)(const ANPPaint*);
    530     void        (*setFlags)(ANPPaint*, ANPPaintFlags);
    531 
    532     ANPColor    (*getColor)(const ANPPaint*);
    533     void        (*setColor)(ANPPaint*, ANPColor);
    534 
    535     ANPPaintStyle (*getStyle)(const ANPPaint*);
    536     void        (*setStyle)(ANPPaint*, ANPPaintStyle);
    537 
    538     float       (*getStrokeWidth)(const ANPPaint*);
    539     float       (*getStrokeMiter)(const ANPPaint*);
    540     ANPPaintCap (*getStrokeCap)(const ANPPaint*);
    541     ANPPaintJoin (*getStrokeJoin)(const ANPPaint*);
    542     void        (*setStrokeWidth)(ANPPaint*, float);
    543     void        (*setStrokeMiter)(ANPPaint*, float);
    544     void        (*setStrokeCap)(ANPPaint*, ANPPaintCap);
    545     void        (*setStrokeJoin)(ANPPaint*, ANPPaintJoin);
    546 
    547     ANPTextEncoding (*getTextEncoding)(const ANPPaint*);
    548     ANPPaintAlign (*getTextAlign)(const ANPPaint*);
    549     float       (*getTextSize)(const ANPPaint*);
    550     float       (*getTextScaleX)(const ANPPaint*);
    551     float       (*getTextSkewX)(const ANPPaint*);
    552     void        (*setTextEncoding)(ANPPaint*, ANPTextEncoding);
    553     void        (*setTextAlign)(ANPPaint*, ANPPaintAlign);
    554     void        (*setTextSize)(ANPPaint*, float);
    555     void        (*setTextScaleX)(ANPPaint*, float);
    556     void        (*setTextSkewX)(ANPPaint*, float);
    557 
    558     /** Return the typeface ine paint, or null if there is none. This does not
    559         modify the owner count of the returned typeface.
    560      */
    561     ANPTypeface* (*getTypeface)(const ANPPaint*);
    562 
    563     /** Set the paint's typeface. If the paint already had a non-null typeface,
    564         its owner count is decremented. If the new typeface is non-null, its
    565         owner count is incremented.
    566      */
    567     void (*setTypeface)(ANPPaint*, ANPTypeface*);
    568 
    569     /** Return the width of the text. If bounds is not null, return the bounds
    570         of the text in that rectangle.
    571      */
    572     float (*measureText)(ANPPaint*, const void* text, uint32_t byteLength,
    573                          ANPRectF* bounds);
    574 
    575     /** Return the number of unichars specifed by the text.
    576         If widths is not null, returns the array of advance widths for each
    577             unichar.
    578         If bounds is not null, returns the array of bounds for each unichar.
    579      */
    580     int (*getTextWidths)(ANPPaint*, const void* text, uint32_t byteLength,
    581                          float widths[], ANPRectF bounds[]);
    582 
    583     /** Return in metrics the spacing values for text, respecting the paint's
    584         typeface and pointsize, and return the spacing between lines
    585         (descent - ascent + leading). If metrics is NULL, it will be ignored.
    586      */
    587     float (*getFontMetrics)(ANPPaint*, ANPFontMetrics* metrics);
    588 };
    589 
    590 struct ANPCanvasInterfaceV0 : ANPInterface {
    591     /** Return a canvas that will draw into the specified bitmap. Note: the
    592         canvas copies the fields of the bitmap, so it need not persist after
    593         this call, but the canvas DOES point to the same pixel memory that the
    594         bitmap did, so the canvas should not be used after that pixel memory
    595         goes out of scope. In the case of creating a canvas to draw into the
    596         pixels provided by kDraw_ANPEventType, those pixels are only while
    597         handling that event.
    598 
    599         The canvas that is returned is not tied to any particular plugin
    600         instance, but it must only be accessed from one thread at a time.
    601      */
    602     ANPCanvas*  (*newCanvas)(const ANPBitmap*);
    603     void        (*deleteCanvas)(ANPCanvas*);
    604 
    605     void        (*save)(ANPCanvas*);
    606     void        (*restore)(ANPCanvas*);
    607     void        (*translate)(ANPCanvas*, float tx, float ty);
    608     void        (*scale)(ANPCanvas*, float sx, float sy);
    609     void        (*rotate)(ANPCanvas*, float degrees);
    610     void        (*skew)(ANPCanvas*, float kx, float ky);
    611     void        (*concat)(ANPCanvas*, const ANPMatrix*);
    612     void        (*clipRect)(ANPCanvas*, const ANPRectF*);
    613     void        (*clipPath)(ANPCanvas*, const ANPPath*);
    614 
    615     /** Return the current matrix on the canvas
    616      */
    617     void        (*getTotalMatrix)(ANPCanvas*, ANPMatrix*);
    618     /** Return the current clip bounds in local coordinates, expanding it to
    619         account for antialiasing edge effects if aa is true. If the
    620         current clip is empty, return false and ignore the bounds argument.
    621      */
    622     bool        (*getLocalClipBounds)(ANPCanvas*, ANPRectF* bounds, bool aa);
    623     /** Return the current clip bounds in device coordinates in bounds. If the
    624         current clip is empty, return false and ignore the bounds argument.
    625      */
    626     bool        (*getDeviceClipBounds)(ANPCanvas*, ANPRectI* bounds);
    627 
    628     void        (*drawColor)(ANPCanvas*, ANPColor);
    629     void        (*drawPaint)(ANPCanvas*, const ANPPaint*);
    630     void        (*drawLine)(ANPCanvas*, float x0, float y0, float x1, float y1,
    631                             const ANPPaint*);
    632     void        (*drawRect)(ANPCanvas*, const ANPRectF*, const ANPPaint*);
    633     void        (*drawOval)(ANPCanvas*, const ANPRectF*, const ANPPaint*);
    634     void        (*drawPath)(ANPCanvas*, const ANPPath*, const ANPPaint*);
    635     void        (*drawText)(ANPCanvas*, const void* text, uint32_t byteLength,
    636                             float x, float y, const ANPPaint*);
    637     void       (*drawPosText)(ANPCanvas*, const void* text, uint32_t byteLength,
    638                                const float xy[], const ANPPaint*);
    639     void        (*drawBitmap)(ANPCanvas*, const ANPBitmap*, float x, float y,
    640                               const ANPPaint*);
    641     void        (*drawBitmapRect)(ANPCanvas*, const ANPBitmap*,
    642                                   const ANPRectI* src, const ANPRectF* dst,
    643                                   const ANPPaint*);
    644 };
    645 
    646 struct ANPWindowInterfaceV0 : ANPInterface {
    647     /** Registers a set of rectangles that the plugin would like to keep on
    648         screen. The rectangles are listed in order of priority with the highest
    649         priority rectangle in location rects[0].  The browser will attempt to keep
    650         as many of the rectangles on screen as possible and will scroll them into
    651         view in response to the invocation of this method and other various events.
    652         The count specifies how many rectangles are in the array. If the count is
    653         zero it signals the browser that any existing rectangles should be cleared
    654         and no rectangles will be tracked.
    655      */
    656     void (*setVisibleRects)(NPP instance, const ANPRectI rects[], int32_t count);
    657     /** Clears any rectangles that are being tracked as a result of a call to
    658         setVisibleRects. This call is equivalent to setVisibleRect(inst, NULL, 0).
    659      */
    660     void    (*clearVisibleRects)(NPP instance);
    661     /** Given a boolean value of true the device will be requested to provide
    662         a keyboard. A value of false will result in a request to hide the
    663         keyboard. Further, the on-screen keyboard will not be displayed if a
    664         physical keyboard is active.
    665      */
    666     void    (*showKeyboard)(NPP instance, bool value);
    667     /** Called when a plugin wishes to enter into full screen mode. The plugin's
    668         Java class (defined in the plugin's apk manifest) will be called
    669         asynchronously to provide a View object to be displayed full screen.
    670      */
    671     void    (*requestFullScreen)(NPP instance);
    672     /** Called when a plugin wishes to exit from full screen mode. As a result,
    673         the plugin's full screen view will be discarded by the view system.
    674      */
    675     void    (*exitFullScreen)(NPP instance);
    676     /** Called when a plugin wishes to be zoomed and centered in the current view.
    677      */
    678     void    (*requestCenterFitZoom)(NPP instance);
    679 };
    680 
    681 ///////////////////////////////////////////////////////////////////////////////
    682 
    683 enum ANPSampleFormats {
    684     kUnknown_ANPSamleFormat     = 0,
    685     kPCM16Bit_ANPSampleFormat   = 1,
    686     kPCM8Bit_ANPSampleFormat    = 2
    687 };
    688 typedef int32_t ANPSampleFormat;
    689 
    690 /** The audio buffer is passed to the callback proc to request more samples.
    691     It is owned by the system, and the callback may read it, but should not
    692     maintain a pointer to it outside of the scope of the callback proc.
    693  */
    694 struct ANPAudioBuffer {
    695     // RO - repeat what was specified in newTrack()
    696     int32_t     channelCount;
    697     // RO - repeat what was specified in newTrack()
    698     ANPSampleFormat  format;
    699     /** This buffer is owned by the caller. Inside the callback proc, up to
    700         "size" bytes of sample data should be written into this buffer. The
    701         address is only valid for the scope of a single invocation of the
    702         callback proc.
    703      */
    704     void*       bufferData;
    705     /** On input, specifies the maximum number of bytes that can be written
    706         to "bufferData". On output, specifies the actual number of bytes that
    707         the callback proc wrote into "bufferData".
    708      */
    709     uint32_t    size;
    710 };
    711 
    712 enum ANPAudioEvents {
    713     /** This event is passed to the callback proc when the audio-track needs
    714         more sample data written to the provided buffer parameter.
    715      */
    716     kMoreData_ANPAudioEvent = 0,
    717     /** This event is passed to the callback proc if the audio system runs out
    718         of sample data. In this event, no buffer parameter will be specified
    719         (i.e. NULL will be passed to the 3rd parameter).
    720      */
    721     kUnderRun_ANPAudioEvent = 1
    722 };
    723 typedef int32_t ANPAudioEvent;
    724 
    725 /** Called to feed sample data to the track. This will be called in a separate
    726     thread. However, you may call trackStop() from the callback (but you
    727     cannot delete the track).
    728 
    729     For example, when you have written the last chunk of sample data, you can
    730     immediately call trackStop(). This will take effect after the current
    731     buffer has been played.
    732 
    733     The "user" parameter is the same value that was passed to newTrack()
    734  */
    735 typedef void (*ANPAudioCallbackProc)(ANPAudioEvent event, void* user,
    736                                      ANPAudioBuffer* buffer);
    737 
    738 struct ANPAudioTrack;   // abstract type for audio tracks
    739 
    740 struct ANPAudioTrackInterfaceV0 : ANPInterface {
    741     /** Create a new audio track, or NULL on failure. The track is initially in
    742         the stopped state and therefore ANPAudioCallbackProc will not be called
    743         until the track is started.
    744      */
    745     ANPAudioTrack*  (*newTrack)(uint32_t sampleRate,    // sampling rate in Hz
    746                                 ANPSampleFormat,
    747                                 int channelCount,       // MONO=1, STEREO=2
    748                                 ANPAudioCallbackProc,
    749                                 void* user);
    750     /** Deletes a track that was created using newTrack.  The track can be
    751         deleted in any state and it waits for the ANPAudioCallbackProc thread
    752         to exit before returning.
    753      */
    754     void (*deleteTrack)(ANPAudioTrack*);
    755 
    756     void (*start)(ANPAudioTrack*);
    757     void (*pause)(ANPAudioTrack*);
    758     void (*stop)(ANPAudioTrack*);
    759     /** Returns true if the track is not playing (e.g. pause or stop was called,
    760         or start was never called.
    761      */
    762     bool (*isStopped)(ANPAudioTrack*);
    763 };
    764 
    765 ///////////////////////////////////////////////////////////////////////////////
    766 // DEFINITION OF VALUES PASSED THROUGH NPP_HandleEvent
    767 
    768 enum ANPEventTypes {
    769     kNull_ANPEventType          = 0,
    770     kKey_ANPEventType           = 1,
    771     /** Mouse events are triggered by either clicking with the navigational pad
    772         or by tapping the touchscreen (if the kDown_ANPTouchAction is handled by
    773         the plugin then no mouse event is generated).  The kKey_ANPEventFlag has
    774         to be set to true in order to receive these events.
    775      */
    776     kMouse_ANPEventType         = 2,
    777     /** Touch events are generated when the user touches on the screen. The
    778         kTouch_ANPEventFlag has to be set to true in order to receive these
    779         events.
    780      */
    781     kTouch_ANPEventType         = 3,
    782     /** Only triggered by a plugin using the kBitmap_ANPDrawingModel. This event
    783         signals that the plugin needs to redraw itself into the provided bitmap.
    784      */
    785     kDraw_ANPEventType          = 4,
    786     kLifecycle_ANPEventType     = 5,
    787 
    788     /** This event type is completely defined by the plugin.
    789         When creating an event, the caller must always set the first
    790         two fields, the remaining data is optional.
    791             ANPEvent evt;
    792             evt.inSize = sizeof(ANPEvent);
    793             evt.eventType = kCustom_ANPEventType
    794             // other data slots are optional
    795             evt.other[] = ...;
    796         To post a copy of the event, call
    797             eventInterface->postEvent(myNPPInstance, &evt);
    798         That call makes a copy of the event struct, and post that on the event
    799         queue for the plugin.
    800      */
    801     kCustom_ANPEventType   = 6,
    802 };
    803 typedef int32_t ANPEventType;
    804 
    805 enum ANPKeyActions {
    806     kDown_ANPKeyAction  = 0,
    807     kUp_ANPKeyAction    = 1,
    808 };
    809 typedef int32_t ANPKeyAction;
    810 
    811 #include "ANPKeyCodes.h"
    812 typedef int32_t ANPKeyCode;
    813 
    814 enum ANPKeyModifiers {
    815     kAlt_ANPKeyModifier     = 1 << 0,
    816     kShift_ANPKeyModifier   = 1 << 1,
    817 };
    818 // bit-field containing some number of ANPKeyModifier bits
    819 typedef uint32_t ANPKeyModifier;
    820 
    821 enum ANPMouseActions {
    822     kDown_ANPMouseAction  = 0,
    823     kUp_ANPMouseAction    = 1,
    824 };
    825 typedef int32_t ANPMouseAction;
    826 
    827 enum ANPTouchActions {
    828     /** This occurs when the user first touches on the screen. As such, this
    829         action will always occur prior to any of the other touch actions. If
    830         the plugin chooses to not handle this action then no other events
    831         related to that particular touch gesture will be generated.
    832      */
    833     kDown_ANPTouchAction        = 0,
    834     kUp_ANPTouchAction          = 1,
    835     kMove_ANPTouchAction        = 2,
    836     kCancel_ANPTouchAction      = 3,
    837     // The web view will ignore the return value from the following actions
    838     kLongPress_ANPTouchAction   = 4,
    839     kDoubleTap_ANPTouchAction   = 5,
    840 };
    841 typedef int32_t ANPTouchAction;
    842 
    843 enum ANPLifecycleActions {
    844     /** The web view containing this plugin has been paused.  See documentation
    845         on the android activity lifecycle for more information.
    846      */
    847     kPause_ANPLifecycleAction           = 0,
    848     /** The web view containing this plugin has been resumed. See documentation
    849         on the android activity lifecycle for more information.
    850      */
    851     kResume_ANPLifecycleAction          = 1,
    852     /** The plugin has focus and is now the recipient of input events (e.g. key,
    853         touch, etc.)
    854      */
    855     kGainFocus_ANPLifecycleAction       = 2,
    856     /** The plugin has lost focus and will not receive any input events until it
    857         regains focus. This event is always preceded by a GainFocus action.
    858      */
    859     kLoseFocus_ANPLifecycleAction       = 3,
    860     /** The browser is running low on available memory and is requesting that
    861         the plugin free any unused/inactive resources to prevent a performance
    862         degradation.
    863      */
    864     kFreeMemory_ANPLifecycleAction      = 4,
    865     /** The page has finished loading. This happens when the page's top level
    866         frame reports that it has completed loading.
    867      */
    868     kOnLoad_ANPLifecycleAction          = 5,
    869     /** The browser is honoring the plugin's request to go full screen. Upon
    870         returning from this event the browser will resize the plugin's java
    871         surface to full-screen coordinates.
    872      */
    873     kEnterFullScreen_ANPLifecycleAction = 6,
    874     /** The browser has exited from full screen mode. Immediately prior to
    875         sending this event the browser has resized the plugin's java surface to
    876         its original coordinates.
    877      */
    878     kExitFullScreen_ANPLifecycleAction  = 7,
    879     /** The plugin is visible to the user on the screen. This event will always
    880         occur after a kOffScreen_ANPLifecycleAction event.
    881      */
    882     kOnScreen_ANPLifecycleAction        = 8,
    883     /** The plugin is no longer visible to the user on the screen. This event
    884         will always occur prior to an kOnScreen_ANPLifecycleAction event.
    885      */
    886     kOffScreen_ANPLifecycleAction       = 9,
    887 };
    888 typedef uint32_t ANPLifecycleAction;
    889 
    890 /* This is what is passed to NPP_HandleEvent() */
    891 struct ANPEvent {
    892     uint32_t        inSize;  // size of this struct in bytes
    893     ANPEventType    eventType;
    894     // use based on the value in eventType
    895     union {
    896         struct {
    897             ANPKeyAction    action;
    898             ANPKeyCode      nativeCode;
    899             int32_t         virtualCode;    // windows virtual key code
    900             ANPKeyModifier  modifiers;
    901             int32_t         repeatCount;    // 0 for initial down (or up)
    902             int32_t         unichar;        // 0 if there is no value
    903         } key;
    904         struct {
    905             ANPMouseAction  action;
    906             int32_t         x;  // relative to your "window" (0...width)
    907             int32_t         y;  // relative to your "window" (0...height)
    908         } mouse;
    909         struct {
    910             ANPTouchAction  action;
    911             ANPKeyModifier  modifiers;
    912             int32_t         x;  // relative to your "window" (0...width)
    913             int32_t         y;  // relative to your "window" (0...height)
    914         } touch;
    915         struct {
    916             ANPLifecycleAction  action;
    917         } lifecycle;
    918         struct {
    919             ANPDrawingModel model;
    920             // relative to (0,0) in top-left of your plugin
    921             ANPRectI        clip;
    922             // use based on the value in model
    923             union {
    924                 ANPBitmap   bitmap;
    925             } data;
    926         } draw;
    927         int32_t     other[8];
    928     } data;
    929 };
    930 
    931 struct ANPEventInterfaceV0 : ANPInterface {
    932     /** Post a copy of the specified event to the plugin. The event will be
    933         delivered to the plugin in its main thread (the thread that receives
    934         other ANPEvents). If, after posting before delivery, the NPP instance
    935         is torn down, the event will be discarded.
    936      */
    937     void (*postEvent)(NPP inst, const ANPEvent* event);
    938 };
    939 
    940 
    941 #endif
    942