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