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