android_npapi.h revision d3fd788536f3fe65035a8fbba4ede47701716c43
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
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
120/*  queries for which drawing model is desired (for the draw event)
121
122    Should be called inside NPP_New(...)
123
124    NPN_GetValue(inst, ANPSupportedDrawingModel_EnumValue, uint32_t* bits)
125 */
126#define kSupportedDrawingModel_ANPGetValue  ((NPNVariable)2000)
127
128///////////////////////////////////////////////////////////////////////////////
129// NPN_SetValue
130
131/** Request to set the drawing model.
132
133    NPN_SetValue(inst, ANPRequestDrawingModel_EnumValue, (void*)foo_DrawingModel)
134 */
135#define kRequestDrawingModel_ANPSetValue    ((NPPVariable)1000)
136
137/*  These are used as bitfields in ANPSupportedDrawingModels_EnumValue,
138    and as-is in ANPRequestDrawingModel_EnumValue. The drawing model determines
139    how to interpret the ANPDrawingContext provided in the Draw event and how
140    to interpret the NPWindow->window field.
141 */
142enum ANPDrawingModels {
143    /** Draw into a bitmap from the browser thread in response to a Draw event.
144        NPWindow->window is reserved (ignore)
145     */
146    kBitmap_ANPDrawingModel = 0,
147};
148typedef int32_t ANPDrawingModel;
149
150/** Request to receive/disable events. If the pointer is NULL then all input will
151    be disabled. Otherwise, the input type will be enabled iff its corresponding
152    bit in the EventFlags bit field is set.
153
154    NPN_SetValue(inst, ANPAcceptEvents, (void*)EventFlags)
155 */
156#define kAcceptEvents_ANPSetValue           ((NPPVariable)1001)
157
158/*  The EventFlags are a set of bits used to determine which types of input the
159    plugin wishes to receive. For example, if the value is 0x03 then both key
160    and touch events will be provided to the plugin.
161 */
162enum ANPEventFlag {
163    kKey_ANPEventFlag           = 0x01,
164    kTouch_ANPEventFlag         = 0x02,
165    kVisibleRect_ANPEventFlag   = 0x04,
166};
167typedef uint32_t ANPEventFlags;
168
169/*  Interfaces provide additional functionality to the plugin via function ptrs.
170    Once an interface is retrived, it is valid for the lifetime of the plugin
171    (just like browserfuncs).
172
173    All ANPInterfaces begin with an inSize field, which must be set by the
174    caller (plugin) with the number of bytes allocated for the interface.
175    e.g. SomeInterface si; si.inSize = sizeof(si); browser->getvalue(..., &si);
176 */
177struct ANPInterface {
178    uint32_t    inSize;     // size (in bytes) of this struct
179};
180
181enum ANPLogTypes {
182    kError_ANPLogType   = 0,    // error
183    kWarning_ANPLogType = 1,    // warning
184    kDebug_ANPLogType   = 2     // debug only (informational)
185};
186typedef int32_t ANPLogType;
187
188struct ANPLogInterfaceV0 : ANPInterface {
189    // dumps printf messages to the log file
190    // e.g. interface->log(instance, kWarning_ANPLogType, "value is %d", value);
191    void (*log)(NPP instance, ANPLogType, const char format[], ...);
192};
193
194struct ANPBitmapInterfaceV0 : ANPInterface {
195    /** Returns true if the specified bitmap format is supported, and if packing
196        is non-null, sets it to the packing info for that format.
197     */
198    bool (*getPixelPacking)(ANPBitmapFormat, ANPPixelPacking* packing);
199};
200
201struct ANPMatrixInterfaceV0 : ANPInterface {
202    /*  Return a new identity matrix
203     */
204    ANPMatrix*  (*newMatrix)();
205    /*  Delete a matrix previously allocated by newMatrix()
206     */
207    void        (*deleteMatrix)(ANPMatrix*);
208
209    ANPMatrixFlag (*getFlags)(const ANPMatrix*);
210
211    void        (*copy)(ANPMatrix* dst, const ANPMatrix* src);
212
213    /*  Return the matrix values in a float array (allcoated by the caller),
214        where the values are treated as follows:
215        w  = x * [6] + y * [7] + [8];
216        x' = (x * [0] + y * [1] + [2]) / w;
217        y' = (x * [3] + y * [4] + [5]) / w;
218     */
219    void        (*get3x3)(const ANPMatrix*, float[9]);
220    /*  Initialize the matrix from values in a float array,
221        where the values are treated as follows:
222         w  = x * [6] + y * [7] + [8];
223         x' = (x * [0] + y * [1] + [2]) / w;
224         y' = (x * [3] + y * [4] + [5]) / w;
225     */
226    void        (*set3x3)(ANPMatrix*, const float[9]);
227
228    void        (*setIdentity)(ANPMatrix*);
229    void        (*preTranslate)(ANPMatrix*, float tx, float ty);
230    void        (*postTranslate)(ANPMatrix*, float tx, float ty);
231    void        (*preScale)(ANPMatrix*, float sx, float sy);
232    void        (*postScale)(ANPMatrix*, float sx, float sy);
233    void        (*preSkew)(ANPMatrix*, float kx, float ky);
234    void        (*postSkew)(ANPMatrix*, float kx, float ky);
235    void        (*preRotate)(ANPMatrix*, float degrees);
236    void        (*postRotate)(ANPMatrix*, float degrees);
237    void        (*preConcat)(ANPMatrix*, const ANPMatrix*);
238    void        (*postConcat)(ANPMatrix*, const ANPMatrix*);
239
240    /*  Return true if src is invertible, and if so, return its inverse in dst.
241        If src is not invertible, return false and ignore dst.
242     */
243    bool        (*invert)(ANPMatrix* dst, const ANPMatrix* src);
244
245    /*  Transform the x,y pairs in src[] by this matrix, and store the results
246        in dst[]. The count parameter is treated as the number of pairs in the
247        array. It is legal for src and dst to point to the same memory, but
248        illegal for the two arrays to partially overlap.
249     */
250    void        (*mapPoints)(ANPMatrix*, float dst[], const float src[],
251                             int32_t count);
252};
253
254struct ANPPathInterfaceV0 : ANPInterface {
255    /* Return a new path */
256    ANPPath* (*newPath)();
257
258    /* Delete a path previously allocated by ANPPath() */
259    void (*deletePath)(ANPPath*);
260
261    /* Make a deep copy of the src path, into the dst path (already allocated
262       by the caller).
263     */
264    void (*copy)(ANPPath* dst, const ANPPath* src);
265
266    /* Returns true if the two paths are the same (i.e. have the same points)
267     */
268    bool (*equal)(const ANPPath* path0, const ANPPath* path1);
269
270    /* Remove any previous points, initializing the path back to empty. */
271    void (*reset)(ANPPath*);
272
273    /* Return true if the path is empty (has no lines, quads or cubics). */
274    bool (*isEmpty)(const ANPPath*);
275
276    /* Return the path's bounds in bounds. */
277    void (*getBounds)(const ANPPath*, ANPRectF* bounds);
278
279    void (*moveTo)(ANPPath*, float x, float y);
280    void (*lineTo)(ANPPath*, float x, float y);
281    void (*quadTo)(ANPPath*, float x0, float y0, float x1, float y1);
282    void (*cubicTo)(ANPPath*, float x0, float y0, float x1, float y1,
283                    float x2, float y2);
284    void (*close)(ANPPath*);
285
286    /*  Offset the src path by [dx, dy]. If dst is null, apply the
287        change directly to the src path. If dst is not null, write the
288        changed path into dst, and leave the src path unchanged. In that case
289        dst must have been previously allocated by the caller.
290     */
291    void (*offset)(ANPPath* src, float dx, float dy, ANPPath* dst);
292
293    /*  Transform the path by the matrix. If dst is null, apply the
294        change directly to the src path. If dst is not null, write the
295        changed path into dst, and leave the src path unchanged. In that case
296        dst must have been previously allocated by the caller.
297     */
298    void (*transform)(ANPPath* src, const ANPMatrix*, ANPPath* dst);
299};
300
301/** ANPColor is always defined to have the same packing on all platforms, and
302    it is always unpremultiplied.
303
304    This is in contrast to 32bit format(s) in bitmaps, which are premultiplied,
305    and their packing may vary depending on the platform, hence the need for
306    ANPBitmapInterface::getPixelPacking()
307 */
308typedef uint32_t ANPColor;
309#define ANPColor_ASHIFT     24
310#define ANPColor_RSHIFT     16
311#define ANPColor_GSHIFT     8
312#define ANPColor_BSHIFT     0
313#define ANP_MAKE_COLOR(a, r, g, b)  \
314                   (((a) << ANPColor_ASHIFT) |  \
315                    ((r) << ANPColor_RSHIFT) |  \
316                    ((g) << ANPColor_GSHIFT) |  \
317                    ((b) << ANPColor_BSHIFT))
318
319enum ANPPaintFlag {
320    kAntiAlias_ANPPaintFlag         = 1 << 0,
321    kFilterBitmap_ANPPaintFlag      = 1 << 1,
322    kDither_ANPPaintFlag            = 1 << 2,
323    kUnderlineText_ANPPaintFlag     = 1 << 3,
324    kStrikeThruText_ANPPaintFlag    = 1 << 4,
325    kFakeBoldText_ANPPaintFlag      = 1 << 5,
326};
327typedef uint32_t ANPPaintFlags;
328
329enum ANPPaintStyles {
330    kFill_ANPPaintStyle             = 0,
331    kStroke_ANPPaintStyle           = 1,
332    kFillAndStroke_ANPPaintStyle    = 2
333};
334typedef int32_t ANPPaintStyle;
335
336enum ANPPaintCaps {
337    kButt_ANPPaintCap   = 0,
338    kRound_ANPPaintCap  = 1,
339    kSquare_ANPPaintCap = 2
340};
341typedef int32_t ANPPaintCap;
342
343enum ANPPaintJoins {
344    kMiter_ANPPaintJoin = 0,
345    kRound_ANPPaintJoin = 1,
346    kBevel_ANPPaintJoin = 2
347};
348typedef int32_t ANPPaintJoin;
349
350enum ANPPaintAligns {
351    kLeft_ANPPaintAlign     = 0,
352    kCenter_ANPPaintAlign   = 1,
353    kRight_ANPPaintAlign    = 2
354};
355typedef int32_t ANPPaintAlign;
356
357enum ANPTextEncodings {
358    kUTF8_ANPTextEncoding   = 0,
359    kUTF16_ANPTextEncoding  = 1,
360};
361typedef int32_t ANPTextEncoding;
362
363enum ANPTypefaceStyles {
364    kBold_ANPTypefaceStyle      = 1 << 0,
365    kItalic_ANPTypefaceStyle    = 1 << 1
366};
367typedef uint32_t ANPTypefaceStyle;
368
369typedef uint32_t ANPFontTableTag;
370
371struct ANPFontMetrics {
372    //! The greatest distance above the baseline for any glyph (will be <= 0)
373    float   fTop;
374    //! The recommended distance above the baseline (will be <= 0)
375    float   fAscent;
376    //! The recommended distance below the baseline (will be >= 0)
377    float   fDescent;
378    //! The greatest distance below the baseline for any glyph (will be >= 0)
379    float   fBottom;
380    //! The recommended distance to add between lines of text (will be >= 0)
381    float   fLeading;
382};
383
384struct ANPTypefaceInterfaceV0 : ANPInterface {
385    /** Return a new reference to the typeface that most closely matches the
386        requested name and style. Pass null as the name to return
387        the default font for the requested style. Will never return null
388
389        @param name     May be NULL. The name of the font family.
390        @param style    The style (normal, bold, italic) of the typeface.
391        @return reference to the closest-matching typeface. Caller must call
392                unref() when they are done with the typeface.
393     */
394    ANPTypeface* (*createFromName)(const char name[], ANPTypefaceStyle);
395
396    /** Return a new reference to the typeface that most closely matches the
397        requested typeface and specified Style. Use this call if you want to
398        pick a new style from the same family of the existing typeface.
399        If family is NULL, this selects from the default font's family.
400
401        @param family  May be NULL. The name of the existing type face.
402        @param s       The style (normal, bold, italic) of the type face.
403        @return reference to the closest-matching typeface. Call must call
404                unref() when they are done.
405     */
406    ANPTypeface* (*createFromTypeface)(const ANPTypeface* family,
407                                       ANPTypefaceStyle);
408
409    /** Return the owner count of the typeface. A newly created typeface has an
410        owner count of 1. When the owner count is reaches 0, the typeface is
411        deleted.
412     */
413    int32_t (*getRefCount)(const ANPTypeface*);
414
415    /** Increment the owner count on the typeface
416     */
417    void (*ref)(ANPTypeface*);
418
419    /** Decrement the owner count on the typeface. When the count goes to 0,
420        the typeface is deleted.
421     */
422    void (*unref)(ANPTypeface*);
423
424    /** Return the style bits for the specified typeface
425     */
426    ANPTypefaceStyle (*getStyle)(const ANPTypeface*);
427
428    /** Return the number of tables in the font
429     */
430    uint32_t (*countTables)(const ANPTypeface*);
431
432    /** Copy into tags[] (allocated by the caller) the list of table tags in
433        the font, and return the number. This will be the same as CountTables()
434        or 0 if an error occured.
435     */
436    uint32_t (*getTableTags)(const ANPTypeface*, ANPFontTableTag tags[]);
437
438    /** Given a table tag, return the size of its contents, or 0 if not present
439     */
440    uint32_t (*getTableSize)(const ANPTypeface*, ANPFontTableTag);
441
442    /** Copy the contents of a table into data (allocated by the caller). Note
443        that the contents of the table will be in their native endian order
444        (which for most truetype tables is big endian). If the table tag is
445        not found, or there is an error copying the data, then 0 is returned.
446        If this happens, it is possible that some or all of the memory pointed
447        to by data may have been written to, even though an error has occured.
448
449        @param fontID the font to copy the table from
450        @param tag  The table tag whose contents are to be copied
451        @param offset The offset in bytes into the table's contents where the
452                copy should start from.
453        @param length The number of bytes, starting at offset, of table data
454                to copy.
455        @param data storage address where the table contents are copied to
456        @return the number of bytes actually copied into data. If offset+length
457                exceeds the table's size, then only the bytes up to the table's
458                size are actually copied, and this is the value returned. If
459                offset > the table's size, or tag is not a valid table,
460                then 0 is returned.
461     */
462    uint32_t (*getTableData)(const ANPTypeface*, ANPFontTableTag,
463                             uint32_t offset, uint32_t length, void* data);
464};
465
466struct ANPPaintInterfaceV0 : ANPInterface {
467    /*  Return a new paint object, which holds all of the color and style
468        attributes that affect how things (geometry, text, bitmaps) are drawn
469        in a ANPCanvas.
470
471        The paint that is returned is not tied to any particular plugin
472        instance, but it must only be accessed from one thread at a time.
473     */
474    ANPPaint*   (*newPaint)();
475    void        (*deletePaint)(ANPPaint*);
476
477    ANPPaintFlags (*getFlags)(const ANPPaint*);
478    void        (*setFlags)(ANPPaint*, ANPPaintFlags);
479
480    ANPColor    (*getColor)(const ANPPaint*);
481    void        (*setColor)(ANPPaint*, ANPColor);
482
483    ANPPaintStyle (*getStyle)(const ANPPaint*);
484    void        (*setStyle)(ANPPaint*, ANPPaintStyle);
485
486    float       (*getStrokeWidth)(const ANPPaint*);
487    float       (*getStrokeMiter)(const ANPPaint*);
488    ANPPaintCap (*getStrokeCap)(const ANPPaint*);
489    ANPPaintJoin (*getStrokeJoin)(const ANPPaint*);
490    void        (*setStrokeWidth)(ANPPaint*, float);
491    void        (*setStrokeMiter)(ANPPaint*, float);
492    void        (*setStrokeCap)(ANPPaint*, ANPPaintCap);
493    void        (*setStrokeJoin)(ANPPaint*, ANPPaintJoin);
494
495    ANPTextEncoding (*getTextEncoding)(const ANPPaint*);
496    ANPPaintAlign (*getTextAlign)(const ANPPaint*);
497    float       (*getTextSize)(const ANPPaint*);
498    float       (*getTextScaleX)(const ANPPaint*);
499    float       (*getTextSkewX)(const ANPPaint*);
500    void        (*setTextEncoding)(ANPPaint*, ANPTextEncoding);
501    void        (*setTextAlign)(ANPPaint*, ANPPaintAlign);
502    void        (*setTextSize)(ANPPaint*, float);
503    void        (*setTextScaleX)(ANPPaint*, float);
504    void        (*setTextSkewX)(ANPPaint*, float);
505
506    /** Return the typeface ine paint, or null if there is none. This does not
507        modify the owner count of the returned typeface.
508     */
509    ANPTypeface* (*getTypeface)(const ANPPaint*);
510
511    /** Set the paint's typeface. If the paint already had a non-null typeface,
512        its owner count is decremented. If the new typeface is non-null, its
513        owner count is incremented.
514     */
515    void (*setTypeface)(ANPPaint*, ANPTypeface*);
516
517    /** Return the width of the text. If bounds is not null, return the bounds
518        of the text in that rectangle.
519     */
520    float (*measureText)(ANPPaint*, const void* text, uint32_t byteLength,
521                         ANPRectF* bounds);
522
523    /** Return the number of unichars specifed by the text.
524        If widths is not null, returns the array of advance widths for each
525            unichar.
526        If bounds is not null, returns the array of bounds for each unichar.
527     */
528    int (*getTextWidths)(ANPPaint*, const void* text, uint32_t byteLength,
529                         float widths[], ANPRectF bounds[]);
530
531    /** Return in metrics the spacing values for text, respecting the paint's
532        typeface and pointsize, and return the spacing between lines
533        (descent - ascent + leading). If metrics is NULL, it will be ignored.
534     */
535    float (*getFontMetrics)(ANPPaint*, ANPFontMetrics* metrics);
536};
537
538struct ANPCanvasInterfaceV0 : ANPInterface {
539    /*  Return a canvas that will draw into the specified bitmap. Note: the
540        canvas copies the fields of the bitmap, so it need not persist after
541        this call, but the canvas DOES point to the same pixel memory that the
542        bitmap did, so the canvas should not be used after that pixel memory
543        goes out of scope. In the case of creating a canvas to draw into the
544        pixels provided by kDraw_ANPEventType, those pixels are only while
545        handling that event.
546
547        The canvas that is returned is not tied to any particular plugin
548        instance, but it must only be accessed from one thread at a time.
549     */
550    ANPCanvas*  (*newCanvas)(const ANPBitmap*);
551    void        (*deleteCanvas)(ANPCanvas*);
552
553    void        (*save)(ANPCanvas*);
554    void        (*restore)(ANPCanvas*);
555    void        (*translate)(ANPCanvas*, float tx, float ty);
556    void        (*scale)(ANPCanvas*, float sx, float sy);
557    void        (*rotate)(ANPCanvas*, float degrees);
558    void        (*skew)(ANPCanvas*, float kx, float ky);
559    void        (*concat)(ANPCanvas*, const ANPMatrix*);
560    void        (*clipRect)(ANPCanvas*, const ANPRectF*);
561    void        (*clipPath)(ANPCanvas*, const ANPPath*);
562
563    /*  Return the current matrix on the canvas
564     */
565    void        (*getTotalMatrix)(ANPCanvas*, ANPMatrix*);
566    /*  Return the current clip bounds in local coordinates, expanding it to
567        account for antialiasing edge effects if aa is true. If the
568        current clip is empty, return false and ignore the bounds argument.
569     */
570    bool        (*getLocalClipBounds)(ANPCanvas*, ANPRectF* bounds, bool aa);
571    /*  Return the current clip bounds in device coordinates in bounds. If the
572        current clip is empty, return false and ignore the bounds argument.
573     */
574    bool        (*getDeviceClipBounds)(ANPCanvas*, ANPRectI* bounds);
575
576    void        (*drawColor)(ANPCanvas*, ANPColor);
577    void        (*drawPaint)(ANPCanvas*, const ANPPaint*);
578    void        (*drawLine)(ANPCanvas*, float x0, float y0, float x1, float y1,
579                            const ANPPaint*);
580    void        (*drawRect)(ANPCanvas*, const ANPRectF*, const ANPPaint*);
581    void        (*drawOval)(ANPCanvas*, const ANPRectF*, const ANPPaint*);
582    void        (*drawPath)(ANPCanvas*, const ANPPath*, const ANPPaint*);
583    void        (*drawText)(ANPCanvas*, const void* text, uint32_t byteLength,
584                            float x, float y, const ANPPaint*);
585    void       (*drawPosText)(ANPCanvas*, const void* text, uint32_t byteLength,
586                               const float xy[], const ANPPaint*);
587    void        (*drawBitmap)(ANPCanvas*, const ANPBitmap*, float x, float y,
588                              const ANPPaint*);
589    void        (*drawBitmapRect)(ANPCanvas*, const ANPBitmap*,
590                                  const ANPRectI* src, const ANPRectF* dst,
591                                  const ANPPaint*);
592};
593
594struct ANPWindowInterfaceV0 : ANPInterface {
595    /** Given the window field from the NPWindow struct, and an optional rect
596        describing the subset of the window that will be drawn to (may be null)
597        return true if the bitmap for that window can be accessed, and if so,
598        fill out the specified ANPBitmap to point to the window's pixels.
599
600        When drawing is complete, call unlock(window)
601     */
602    bool    (*lockRect)(void* window, const ANPRectI* inval, ANPBitmap*);
603    /** The same as lockRect, but takes a region instead of a rect to specify
604        the area that will be changed/drawn.
605     */
606    bool    (*lockRegion)(void* window, const ANPRegion* inval, ANPBitmap*);
607    /** Given a successful call to lock(window, inval, &bitmap), call unlock
608        to release access to the pixels, and allow the browser to display the
609        results. If lock returned false, unlock should not be called.
610     */
611    void    (*unlock)(void* window);
612    /** Given (x,y) coordinates in the document space the currently visible
613        window will be shifted so that window's upper left corner will be as
614        closely aligned to the coordinates as possible.
615     */
616    void    (*scrollTo)(NPP instance, int32_t x, int32_t y);
617};
618
619///////////////////////////////////////////////////////////////////////////////
620
621enum ANPSampleFormats {
622    kUnknown_ANPSamleFormat     = 0,
623    kPCM16Bit_ANPSampleFormat   = 1,
624    kPCM8Bit_ANPSampleFormat    = 2
625};
626typedef int32_t ANPSampleFormat;
627
628/** The audio buffer is passed to the callback proc to request more samples.
629    It is owned by the system, and the callback may read it, but should not
630    maintain a pointer to it outside of the scope of the callback proc.
631 */
632struct ANPAudioBuffer {
633    // RO - repeat what was specified in newTrack()
634    int32_t     channelCount;
635    // RO - repeat what was specified in newTrack()
636    ANPSampleFormat  format;
637    /** This buffer is owned by the caller. Inside the callback proc, up to
638        "size" bytes of sample data should be written into this buffer. The
639        address is only valid for the scope of a single invocation of the
640        callback proc.
641     */
642    void*       bufferData;
643    /** On input, specifies the maximum number of bytes that can be written
644        to "bufferData". On output, specifies the actual number of bytes that
645        the callback proc wrote into "bufferData".
646     */
647    uint32_t    size;
648};
649
650enum ANPAudioEvents {
651    /** This event is passed to the callback proc when the audio-track needs
652        more sample data written to the provided buffer parameter.
653     */
654    kMoreData_ANPAudioEvent = 0,
655    /** This event is passed to the callback proc if the audio system runs out
656        of sample data. In this event, no buffer parameter will be specified
657        (i.e. NULL will be passed to the 3rd parameter).
658     */
659    kUnderRun_ANPAudioEvent = 1
660};
661typedef int32_t ANPAudioEvent;
662
663/** Called to feed sample data to the track. This will be called in a separate
664    thread. However, you may call trackStop() from the callback (but you
665    cannot delete the track).
666
667    For example, when you have written the last chunk of sample data, you can
668    immediately call trackStop(). This will take effect after the current
669    buffer has been played.
670
671    The "user" parameter is the same value that was passed to newTrack()
672 */
673typedef void (*ANPAudioCallbackProc)(ANPAudioEvent event, void* user,
674                                     ANPAudioBuffer* buffer);
675
676struct ANPAudioTrack;   // abstract type for audio tracks
677
678struct ANPAudioTrackInterfaceV0 : ANPInterface {
679    /*  Create a new audio track, or NULL on failure.
680     */
681    ANPAudioTrack*  (*newTrack)(uint32_t sampleRate,    // sampling rate in Hz
682                                ANPSampleFormat,
683                                int channelCount,       // MONO=1, STEREO=2
684                                ANPAudioCallbackProc,
685                                void* user);
686    void (*deleteTrack)(ANPAudioTrack*);
687
688    void (*start)(ANPAudioTrack*);
689    void (*pause)(ANPAudioTrack*);
690    void (*stop)(ANPAudioTrack*);
691    /** Returns true if the track is not playing (e.g. pause or stop was called,
692        or start was never called.
693     */
694    bool (*isStopped)(ANPAudioTrack*);
695};
696
697///////////////////////////////////////////////////////////////////////////////
698// HandleEvent
699
700enum ANPEventTypes {
701    kNull_ANPEventType          = 0,
702    kKey_ANPEventType           = 1,
703    kMouse_ANPEventType         = 2,
704    kTouch_ANPEventType         = 3,
705    kDraw_ANPEventType          = 4,
706    kLifecycle_ANPEventType     = 5,
707    kVisibleRect_ANPEventType   = 6,
708};
709typedef int32_t ANPEventType;
710
711enum ANPKeyActions {
712    kDown_ANPKeyAction  = 0,
713    kUp_ANPKeyAction    = 1,
714};
715typedef int32_t ANPKeyAction;
716
717#include "ANPKeyCodes.h"
718typedef int32_t ANPKeyCode;
719
720enum ANPKeyModifiers {
721    kAlt_ANPKeyModifier     = 1 << 0,
722    kShift_ANPKeyModifier   = 1 << 1,
723};
724// bit-field containing some number of ANPKeyModifier bits
725typedef uint32_t ANPKeyModifier;
726
727enum ANPMouseActions {
728    kDown_ANPMouseAction  = 0,
729    kUp_ANPMouseAction    = 1,
730};
731typedef int32_t ANPMouseAction;
732
733enum ANPTouchActions {
734    kDown_ANPTouchAction   = 0,
735    kUp_ANPTouchAction     = 1,
736    kMove_ANPTouchAction   = 2,
737    kCancel_ANPTouchAction = 3,
738};
739typedef int32_t ANPTouchAction;
740
741enum ANPLifecycleActions {
742    kPause_ANPLifecycleAction      = 0,
743    kResume_ANPLifecycleAction     = 1,
744    kGainFocus_ANPLifecycleAction  = 2,
745    kLooseFocus_ANPLifecycleAction = 3,
746    kFreeMemory_ANPLifecycleAction = 4,
747};
748typedef uint32_t ANPLifecycleAction;
749
750/* This is what is passed to NPP_HandleEvent() */
751struct ANPEvent {
752    uint32_t        inSize;  // size of this struct in bytes
753    ANPEventType    eventType;
754    // use based on the value in eventType
755    union {
756        struct {
757            ANPKeyAction    action;
758            ANPKeyCode      nativeCode;
759            int32_t         virtualCode;    // windows virtual key code
760            ANPKeyModifier  modifiers;
761            int32_t         repeatCount;    // 0 for initial down (or up)
762            int32_t         unichar;        // 0 if there is no value
763        } key;
764        struct {
765            ANPMouseAction  action;
766            int32_t         x;  // relative to your "window" (0...width)
767            int32_t         y;  // relative to your "window" (0...height)
768        } mouse;
769        struct {
770            ANPTouchAction  action;
771            ANPKeyModifier  modifiers;
772            int32_t         x;  // relative to your "window" (0...width)
773            int32_t         y;  // relative to your "window" (0...height)
774        } touch;
775        struct {
776            ANPLifecycleAction  action;
777        } lifecycle;
778        struct {
779            ANPDrawingModel model;
780            // relative to (0,0) in top-left of your plugin
781            ANPRectI        clip;
782            // use based on the value in model
783            union {
784                ANPBitmap   bitmap;
785            } data;
786        } draw;
787        struct {
788            ANPRectI    rect;       // in global document coordinates
789            float       zoomScale;  // 1.0 means no zoom scale
790        } visibleRect;
791        int32_t         other[8];
792    } data;
793};
794
795#endif
796
797