dom/plugins/base/android/android_npapi.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:29b6b5426722
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 #include <jni.h>
40 #include "npapi.h"
41 #include "GLDefs.h"
42
43 ///////////////////////////////////////////////////////////////////////////////
44 // General types
45
46 enum ANPBitmapFormats {
47 kUnknown_ANPBitmapFormat = 0,
48 kRGBA_8888_ANPBitmapFormat = 1,
49 kRGB_565_ANPBitmapFormat = 2
50 };
51 typedef int32_t ANPBitmapFormat;
52
53 struct ANPPixelPacking {
54 uint8_t AShift;
55 uint8_t ABits;
56 uint8_t RShift;
57 uint8_t RBits;
58 uint8_t GShift;
59 uint8_t GBits;
60 uint8_t BShift;
61 uint8_t BBits;
62 };
63
64 struct ANPBitmap {
65 void* baseAddr;
66 ANPBitmapFormat format;
67 int32_t width;
68 int32_t height;
69 int32_t rowBytes;
70 };
71
72 struct ANPRectF {
73 float left;
74 float top;
75 float right;
76 float bottom;
77 };
78
79 struct ANPRectI {
80 int32_t left;
81 int32_t top;
82 int32_t right;
83 int32_t bottom;
84 };
85
86 struct ANPCanvas;
87 struct ANPMatrix;
88 struct ANPPaint;
89 struct ANPPath;
90 struct ANPRegion;
91 struct ANPTypeface;
92
93 enum ANPMatrixFlags {
94 kIdentity_ANPMatrixFlag = 0,
95 kTranslate_ANPMatrixFlag = 0x01,
96 kScale_ANPMatrixFlag = 0x02,
97 kAffine_ANPMatrixFlag = 0x04,
98 kPerspective_ANPMatrixFlag = 0x08,
99 };
100 typedef uint32_t ANPMatrixFlag;
101
102 ///////////////////////////////////////////////////////////////////////////////
103 // NPN_GetValue
104
105 /** queries for a specific ANPInterface.
106
107 Maybe called with NULL for the NPP instance
108
109 NPN_GetValue(inst, interface_enum, ANPInterface*)
110 */
111 #define kLogInterfaceV0_ANPGetValue ((NPNVariable)1000)
112 #define kAudioTrackInterfaceV0_ANPGetValue ((NPNVariable)1001)
113 #define kCanvasInterfaceV0_ANPGetValue ((NPNVariable)1002)
114 #define kMatrixInterfaceV0_ANPGetValue ((NPNVariable)1003)
115 #define kPaintInterfaceV0_ANPGetValue ((NPNVariable)1004)
116 #define kPathInterfaceV0_ANPGetValue ((NPNVariable)1005)
117 #define kTypefaceInterfaceV0_ANPGetValue ((NPNVariable)1006)
118 #define kWindowInterfaceV0_ANPGetValue ((NPNVariable)1007)
119 #define kBitmapInterfaceV0_ANPGetValue ((NPNVariable)1008)
120 #define kSurfaceInterfaceV0_ANPGetValue ((NPNVariable)1009)
121 #define kSystemInterfaceV0_ANPGetValue ((NPNVariable)1010)
122 #define kEventInterfaceV0_ANPGetValue ((NPNVariable)1011)
123
124 #define kAudioTrackInterfaceV1_ANPGetValue ((NPNVariable)1012)
125 #define kOpenGLInterfaceV0_ANPGetValue ((NPNVariable)1013)
126 #define kWindowInterfaceV1_ANPGetValue ((NPNVariable)1014)
127 #define kVideoInterfaceV0_ANPGetValue ((NPNVariable)1015)
128 #define kSystemInterfaceV1_ANPGetValue ((NPNVariable)1016)
129 #define kSystemInterfaceV2_ANPGetValue ((NPNVariable)1017)
130 #define kWindowInterfaceV2_ANPGetValue ((NPNVariable)1018)
131 #define kNativeWindowInterfaceV0_ANPGetValue ((NPNVariable)1019)
132 #define kVideoInterfaceV1_ANPGetValue ((NPNVariable)1020)
133
134 /** queries for the drawing models supported on this device.
135
136 NPN_GetValue(inst, kSupportedDrawingModel_ANPGetValue, uint32_t* bits)
137 */
138 #define kSupportedDrawingModel_ANPGetValue ((NPNVariable)2000)
139
140 /** queries for the context (android.content.Context) of the plugin. If no
141 instance is specified the application's context is returned. If the instance
142 is given then the context returned is identical to the context used to
143 create the webview in which that instance resides.
144
145 NOTE: Holding onto a non-application context after your instance has been
146 destroyed will cause a memory leak. Refer to the android documentation to
147 determine what context is best suited for your particular scenario.
148
149 NPN_GetValue(inst, kJavaContext_ANPGetValue, jobject context)
150 */
151 #define kJavaContext_ANPGetValue ((NPNVariable)2001)
152
153 ///////////////////////////////////////////////////////////////////////////////
154 // NPN_SetValue
155
156 /** Request to set the drawing model. SetValue will return false if the drawing
157 model is not supported or has insufficient information for configuration.
158
159 NPN_SetValue(inst, kRequestDrawingModel_ANPSetValue, (void*)foo_ANPDrawingModel)
160 */
161 #define kRequestDrawingModel_ANPSetValue ((NPPVariable)1000)
162
163 /** These are used as bitfields in ANPSupportedDrawingModels_EnumValue,
164 and as-is in ANPRequestDrawingModel_EnumValue. The drawing model determines
165 how to interpret the ANPDrawingContext provided in the Draw event and how
166 to interpret the NPWindow->window field.
167 */
168 enum ANPDrawingModels {
169 /** Draw into a bitmap from the browser thread in response to a Draw event.
170 NPWindow->window is reserved (ignore)
171 */
172 kBitmap_ANPDrawingModel = 1 << 0,
173 /** Draw into a surface (e.g. raster, openGL, etc.) using the Java surface
174 interface. When this model is used the browser will invoke the Java
175 class specified in the plugin's apk manifest. From that class the browser
176 will invoke the appropriate method to return an an instance of a android
177 Java View. The instance is then embedded in the html. The plugin can then
178 manipulate the view as it would any normal Java View in android.
179
180 Unlike the bitmap model, a surface model is opaque so no html content
181 behind the plugin will be visible. Unless the plugin needs to be
182 transparent the surface model should be chosen over the bitmap model as
183 it will have better performance.
184
185 Further, a plugin can manipulate some surfaces in native code using the
186 ANPSurfaceInterface. This interface can be used to manipulate Java
187 objects that extend Surface.class by allowing them to access the
188 surface's underlying bitmap in native code. For instance, if a raster
189 surface is used the plugin can lock, draw directly into the bitmap, and
190 unlock the surface in native code without making JNI calls to the Java
191 surface object.
192 */
193 kSurface_ANPDrawingModel = 1 << 1,
194 kOpenGL_ANPDrawingModel = 1 << 2,
195 };
196 typedef int32_t ANPDrawingModel;
197
198 /** Request to receive/disable events. If the pointer is NULL then all flags will
199 be disabled. Otherwise, the event type will be enabled iff its corresponding
200 bit in the EventFlags bit field is set.
201
202 NPN_SetValue(inst, ANPAcceptEvents, (void*)EventFlags)
203 */
204 #define kAcceptEvents_ANPSetValue ((NPPVariable)1001)
205
206 /** The EventFlags are a set of bits used to determine which types of events the
207 plugin wishes to receive. For example, if the value is 0x03 then both key
208 and touch events will be provided to the plugin.
209 */
210 enum ANPEventFlag {
211 kKey_ANPEventFlag = 0x01,
212 kTouch_ANPEventFlag = 0x02,
213 };
214 typedef uint32_t ANPEventFlags;
215
216 ///////////////////////////////////////////////////////////////////////////////
217 // NPP_GetValue
218
219 /** Requests that the plugin return a java surface to be displayed. This will
220 only be used if the plugin has choosen the kSurface_ANPDrawingModel.
221
222 NPP_GetValue(inst, kJavaSurface_ANPGetValue, jobject surface)
223 */
224 #define kJavaSurface_ANPGetValue ((NPPVariable)2000)
225
226
227 ///////////////////////////////////////////////////////////////////////////////
228 // ANDROID INTERFACE DEFINITIONS
229
230 /** Interfaces provide additional functionality to the plugin via function ptrs.
231 Once an interface is retrieved, it is valid for the lifetime of the plugin
232 (just like browserfuncs).
233
234 All ANPInterfaces begin with an inSize field, which must be set by the
235 caller (plugin) with the number of bytes allocated for the interface.
236 e.g. SomeInterface si; si.inSize = sizeof(si); browser->getvalue(..., &si);
237 */
238 struct ANPInterface {
239 uint32_t inSize; // size (in bytes) of this struct
240 };
241
242 enum ANPLogTypes {
243 kError_ANPLogType = 0, // error
244 kWarning_ANPLogType = 1, // warning
245 kDebug_ANPLogType = 2 // debug only (informational)
246 };
247 typedef int32_t ANPLogType;
248
249 struct ANPLogInterfaceV0 : ANPInterface {
250 /** dumps printf messages to the log file
251 e.g. interface->log(instance, kWarning_ANPLogType, "value is %d", value);
252 */
253 void (*log)(ANPLogType, const char format[], ...);
254 };
255
256 struct ANPBitmapInterfaceV0 : ANPInterface {
257 /** Returns true if the specified bitmap format is supported, and if packing
258 is non-null, sets it to the packing info for that format.
259 */
260 bool (*getPixelPacking)(ANPBitmapFormat, ANPPixelPacking* packing);
261 };
262
263 struct ANPMatrixInterfaceV0 : ANPInterface {
264 /** Return a new identity matrix
265 */
266 ANPMatrix* (*newMatrix)();
267 /** Delete a matrix previously allocated by newMatrix()
268 */
269 void (*deleteMatrix)(ANPMatrix*);
270
271 ANPMatrixFlag (*getFlags)(const ANPMatrix*);
272
273 void (*copy)(ANPMatrix* dst, const ANPMatrix* src);
274
275 /** Return the matrix values in a float array (allcoated by the caller),
276 where the values are treated as follows:
277 w = x * [6] + y * [7] + [8];
278 x' = (x * [0] + y * [1] + [2]) / w;
279 y' = (x * [3] + y * [4] + [5]) / w;
280 */
281 void (*get3x3)(const ANPMatrix*, float[9]);
282 /** Initialize the matrix from values in a float array,
283 where the values are treated as follows:
284 w = x * [6] + y * [7] + [8];
285 x' = (x * [0] + y * [1] + [2]) / w;
286 y' = (x * [3] + y * [4] + [5]) / w;
287 */
288 void (*set3x3)(ANPMatrix*, const float[9]);
289
290 void (*setIdentity)(ANPMatrix*);
291 void (*preTranslate)(ANPMatrix*, float tx, float ty);
292 void (*postTranslate)(ANPMatrix*, float tx, float ty);
293 void (*preScale)(ANPMatrix*, float sx, float sy);
294 void (*postScale)(ANPMatrix*, float sx, float sy);
295 void (*preSkew)(ANPMatrix*, float kx, float ky);
296 void (*postSkew)(ANPMatrix*, float kx, float ky);
297 void (*preRotate)(ANPMatrix*, float degrees);
298 void (*postRotate)(ANPMatrix*, float degrees);
299 void (*preConcat)(ANPMatrix*, const ANPMatrix*);
300 void (*postConcat)(ANPMatrix*, const ANPMatrix*);
301
302 /** Return true if src is invertible, and if so, return its inverse in dst.
303 If src is not invertible, return false and ignore dst.
304 */
305 bool (*invert)(ANPMatrix* dst, const ANPMatrix* src);
306
307 /** Transform the x,y pairs in src[] by this matrix, and store the results
308 in dst[]. The count parameter is treated as the number of pairs in the
309 array. It is legal for src and dst to point to the same memory, but
310 illegal for the two arrays to partially overlap.
311 */
312 void (*mapPoints)(ANPMatrix*, float dst[], const float src[],
313 int32_t count);
314 };
315
316 struct ANPPathInterfaceV0 : ANPInterface {
317 /** Return a new path */
318 ANPPath* (*newPath)();
319
320 /** Delete a path previously allocated by ANPPath() */
321 void (*deletePath)(ANPPath*);
322
323 /** Make a deep copy of the src path, into the dst path (already allocated
324 by the caller).
325 */
326 void (*copy)(ANPPath* dst, const ANPPath* src);
327
328 /** Returns true if the two paths are the same (i.e. have the same points)
329 */
330 bool (*equal)(const ANPPath* path0, const ANPPath* path1);
331
332 /** Remove any previous points, initializing the path back to empty. */
333 void (*reset)(ANPPath*);
334
335 /** Return true if the path is empty (has no lines, quads or cubics). */
336 bool (*isEmpty)(const ANPPath*);
337
338 /** Return the path's bounds in bounds. */
339 void (*getBounds)(const ANPPath*, ANPRectF* bounds);
340
341 void (*moveTo)(ANPPath*, float x, float y);
342 void (*lineTo)(ANPPath*, float x, float y);
343 void (*quadTo)(ANPPath*, float x0, float y0, float x1, float y1);
344 void (*cubicTo)(ANPPath*, float x0, float y0, float x1, float y1,
345 float x2, float y2);
346 void (*close)(ANPPath*);
347
348 /** Offset the src path by [dx, dy]. If dst is null, apply the
349 change directly to the src path. If dst is not null, write the
350 changed path into dst, and leave the src path unchanged. In that case
351 dst must have been previously allocated by the caller.
352 */
353 void (*offset)(ANPPath* src, float dx, float dy, ANPPath* dst);
354
355 /** Transform the path by the matrix. If dst is null, apply the
356 change directly to the src path. If dst is not null, write the
357 changed path into dst, and leave the src path unchanged. In that case
358 dst must have been previously allocated by the caller.
359 */
360 void (*transform)(ANPPath* src, const ANPMatrix*, ANPPath* dst);
361 };
362
363 /** ANPColor is always defined to have the same packing on all platforms, and
364 it is always unpremultiplied.
365
366 This is in contrast to 32bit format(s) in bitmaps, which are premultiplied,
367 and their packing may vary depending on the platform, hence the need for
368 ANPBitmapInterface::getPixelPacking()
369 */
370 typedef uint32_t ANPColor;
371 #define ANPColor_ASHIFT 24
372 #define ANPColor_RSHIFT 16
373 #define ANPColor_GSHIFT 8
374 #define ANPColor_BSHIFT 0
375 #define ANP_MAKE_COLOR(a, r, g, b) \
376 (((a) << ANPColor_ASHIFT) | \
377 ((r) << ANPColor_RSHIFT) | \
378 ((g) << ANPColor_GSHIFT) | \
379 ((b) << ANPColor_BSHIFT))
380
381 enum ANPPaintFlag {
382 kAntiAlias_ANPPaintFlag = 1 << 0,
383 kFilterBitmap_ANPPaintFlag = 1 << 1,
384 kDither_ANPPaintFlag = 1 << 2,
385 kUnderlineText_ANPPaintFlag = 1 << 3,
386 kStrikeThruText_ANPPaintFlag = 1 << 4,
387 kFakeBoldText_ANPPaintFlag = 1 << 5,
388 };
389 typedef uint32_t ANPPaintFlags;
390
391 enum ANPPaintStyles {
392 kFill_ANPPaintStyle = 0,
393 kStroke_ANPPaintStyle = 1,
394 kFillAndStroke_ANPPaintStyle = 2
395 };
396 typedef int32_t ANPPaintStyle;
397
398 enum ANPPaintCaps {
399 kButt_ANPPaintCap = 0,
400 kRound_ANPPaintCap = 1,
401 kSquare_ANPPaintCap = 2
402 };
403 typedef int32_t ANPPaintCap;
404
405 enum ANPPaintJoins {
406 kMiter_ANPPaintJoin = 0,
407 kRound_ANPPaintJoin = 1,
408 kBevel_ANPPaintJoin = 2
409 };
410 typedef int32_t ANPPaintJoin;
411
412 enum ANPPaintAligns {
413 kLeft_ANPPaintAlign = 0,
414 kCenter_ANPPaintAlign = 1,
415 kRight_ANPPaintAlign = 2
416 };
417 typedef int32_t ANPPaintAlign;
418
419 enum ANPTextEncodings {
420 kUTF8_ANPTextEncoding = 0,
421 kUTF16_ANPTextEncoding = 1,
422 };
423 typedef int32_t ANPTextEncoding;
424
425 enum ANPTypefaceStyles {
426 kBold_ANPTypefaceStyle = 1 << 0,
427 kItalic_ANPTypefaceStyle = 1 << 1
428 };
429 typedef uint32_t ANPTypefaceStyle;
430
431 typedef uint32_t ANPFontTableTag;
432
433 struct ANPFontMetrics {
434 /** The greatest distance above the baseline for any glyph (will be <= 0) */
435 float fTop;
436 /** The recommended distance above the baseline (will be <= 0) */
437 float fAscent;
438 /** The recommended distance below the baseline (will be >= 0) */
439 float fDescent;
440 /** The greatest distance below the baseline for any glyph (will be >= 0) */
441 float fBottom;
442 /** The recommended distance to add between lines of text (will be >= 0) */
443 float fLeading;
444 };
445
446 struct ANPTypefaceInterfaceV0 : ANPInterface {
447 /** Return a new reference to the typeface that most closely matches the
448 requested name and style. Pass null as the name to return
449 the default font for the requested style. Will never return null
450
451 The 5 generic font names "serif", "sans-serif", "monospace", "cursive",
452 "fantasy" are recognized, and will be mapped to their logical font
453 automatically by this call.
454
455 @param name May be NULL. The name of the font family.
456 @param style The style (normal, bold, italic) of the typeface.
457 @return reference to the closest-matching typeface. Caller must call
458 unref() when they are done with the typeface.
459 */
460 ANPTypeface* (*createFromName)(const char name[], ANPTypefaceStyle);
461
462 /** Return a new reference to the typeface that most closely matches the
463 requested typeface and specified Style. Use this call if you want to
464 pick a new style from the same family of the existing typeface.
465 If family is NULL, this selects from the default font's family.
466
467 @param family May be NULL. The name of the existing type face.
468 @param s The style (normal, bold, italic) of the type face.
469 @return reference to the closest-matching typeface. Call must call
470 unref() when they are done.
471 */
472 ANPTypeface* (*createFromTypeface)(const ANPTypeface* family,
473 ANPTypefaceStyle);
474
475 /** Return the owner count of the typeface. A newly created typeface has an
476 owner count of 1. When the owner count is reaches 0, the typeface is
477 deleted.
478 */
479 int32_t (*getRefCount)(const ANPTypeface*);
480
481 /** Increment the owner count on the typeface
482 */
483 void (*ref)(ANPTypeface*);
484
485 /** Decrement the owner count on the typeface. When the count goes to 0,
486 the typeface is deleted.
487 */
488 void (*unref)(ANPTypeface*);
489
490 /** Return the style bits for the specified typeface
491 */
492 ANPTypefaceStyle (*getStyle)(const ANPTypeface*);
493
494 /** Some fonts are stored in files. If that is true for the fontID, then
495 this returns the byte length of the full file path. If path is not null,
496 then the full path is copied into path (allocated by the caller), up to
497 length bytes. If index is not null, then it is set to the truetype
498 collection index for this font, or 0 if the font is not in a collection.
499
500 Note: getFontPath does not assume that path is a null-terminated string,
501 so when it succeeds, it only copies the bytes of the file name and
502 nothing else (i.e. it copies exactly the number of bytes returned by the
503 function. If the caller wants to treat path[] as a C string, it must be
504 sure that it is allocated at least 1 byte larger than the returned size,
505 and it must copy in the terminating 0.
506
507 If the fontID does not correspond to a file, then the function returns
508 0, and the path and index parameters are ignored.
509
510 @param fontID The font whose file name is being queried
511 @param path Either NULL, or storage for receiving up to length bytes
512 of the font's file name. Allocated by the caller.
513 @param length The maximum space allocated in path (by the caller).
514 Ignored if path is NULL.
515 @param index Either NULL, or receives the TTC index for this font.
516 If the font is not a TTC, then will be set to 0.
517 @return The byte length of th font's file name, or 0 if the font is not
518 baked by a file.
519 */
520 int32_t (*getFontPath)(const ANPTypeface*, char path[], int32_t length,
521 int32_t* index);
522
523 /** Return a UTF8 encoded path name for the font directory, or NULL if not
524 supported. If returned, this string address will be valid for the life
525 of the plugin instance. It will always end with a '/' character.
526 */
527 const char* (*getFontDirectoryPath)();
528 };
529
530 struct ANPPaintInterfaceV0 : ANPInterface {
531 /** Return a new paint object, which holds all of the color and style
532 attributes that affect how things (geometry, text, bitmaps) are drawn
533 in a ANPCanvas.
534
535 The paint that is returned is not tied to any particular plugin
536 instance, but it must only be accessed from one thread at a time.
537 */
538 ANPPaint* (*newPaint)();
539 void (*deletePaint)(ANPPaint*);
540
541 ANPPaintFlags (*getFlags)(const ANPPaint*);
542 void (*setFlags)(ANPPaint*, ANPPaintFlags);
543
544 ANPColor (*getColor)(const ANPPaint*);
545 void (*setColor)(ANPPaint*, ANPColor);
546
547 ANPPaintStyle (*getStyle)(const ANPPaint*);
548 void (*setStyle)(ANPPaint*, ANPPaintStyle);
549
550 float (*getStrokeWidth)(const ANPPaint*);
551 float (*getStrokeMiter)(const ANPPaint*);
552 ANPPaintCap (*getStrokeCap)(const ANPPaint*);
553 ANPPaintJoin (*getStrokeJoin)(const ANPPaint*);
554 void (*setStrokeWidth)(ANPPaint*, float);
555 void (*setStrokeMiter)(ANPPaint*, float);
556 void (*setStrokeCap)(ANPPaint*, ANPPaintCap);
557 void (*setStrokeJoin)(ANPPaint*, ANPPaintJoin);
558
559 ANPTextEncoding (*getTextEncoding)(const ANPPaint*);
560 ANPPaintAlign (*getTextAlign)(const ANPPaint*);
561 float (*getTextSize)(const ANPPaint*);
562 float (*getTextScaleX)(const ANPPaint*);
563 float (*getTextSkewX)(const ANPPaint*);
564 void (*setTextEncoding)(ANPPaint*, ANPTextEncoding);
565 void (*setTextAlign)(ANPPaint*, ANPPaintAlign);
566 void (*setTextSize)(ANPPaint*, float);
567 void (*setTextScaleX)(ANPPaint*, float);
568 void (*setTextSkewX)(ANPPaint*, float);
569
570 /** Return the typeface ine paint, or null if there is none. This does not
571 modify the owner count of the returned typeface.
572 */
573 ANPTypeface* (*getTypeface)(const ANPPaint*);
574
575 /** Set the paint's typeface. If the paint already had a non-null typeface,
576 its owner count is decremented. If the new typeface is non-null, its
577 owner count is incremented.
578 */
579 void (*setTypeface)(ANPPaint*, ANPTypeface*);
580
581 /** Return the width of the text. If bounds is not null, return the bounds
582 of the text in that rectangle.
583 */
584 float (*measureText)(ANPPaint*, const void* text, uint32_t byteLength,
585 ANPRectF* bounds);
586
587 /** Return the number of unichars specifed by the text.
588 If widths is not null, returns the array of advance widths for each
589 unichar.
590 If bounds is not null, returns the array of bounds for each unichar.
591 */
592 int (*getTextWidths)(ANPPaint*, const void* text, uint32_t byteLength,
593 float widths[], ANPRectF bounds[]);
594
595 /** Return in metrics the spacing values for text, respecting the paint's
596 typeface and pointsize, and return the spacing between lines
597 (descent - ascent + leading). If metrics is NULL, it will be ignored.
598 */
599 float (*getFontMetrics)(ANPPaint*, ANPFontMetrics* metrics);
600 };
601
602 struct ANPCanvasInterfaceV0 : ANPInterface {
603 /** Return a canvas that will draw into the specified bitmap. Note: the
604 canvas copies the fields of the bitmap, so it need not persist after
605 this call, but the canvas DOES point to the same pixel memory that the
606 bitmap did, so the canvas should not be used after that pixel memory
607 goes out of scope. In the case of creating a canvas to draw into the
608 pixels provided by kDraw_ANPEventType, those pixels are only while
609 handling that event.
610
611 The canvas that is returned is not tied to any particular plugin
612 instance, but it must only be accessed from one thread at a time.
613 */
614 ANPCanvas* (*newCanvas)(const ANPBitmap*);
615 void (*deleteCanvas)(ANPCanvas*);
616
617 void (*save)(ANPCanvas*);
618 void (*restore)(ANPCanvas*);
619 void (*translate)(ANPCanvas*, float tx, float ty);
620 void (*scale)(ANPCanvas*, float sx, float sy);
621 void (*rotate)(ANPCanvas*, float degrees);
622 void (*skew)(ANPCanvas*, float kx, float ky);
623 void (*concat)(ANPCanvas*, const ANPMatrix*);
624 void (*clipRect)(ANPCanvas*, const ANPRectF*);
625 void (*clipPath)(ANPCanvas*, const ANPPath*);
626
627 /** Return the current matrix on the canvas
628 */
629 void (*getTotalMatrix)(ANPCanvas*, ANPMatrix*);
630 /** Return the current clip bounds in local coordinates, expanding it to
631 account for antialiasing edge effects if aa is true. If the
632 current clip is empty, return false and ignore the bounds argument.
633 */
634 bool (*getLocalClipBounds)(ANPCanvas*, ANPRectF* bounds, bool aa);
635 /** Return the current clip bounds in device coordinates in bounds. If the
636 current clip is empty, return false and ignore the bounds argument.
637 */
638 bool (*getDeviceClipBounds)(ANPCanvas*, ANPRectI* bounds);
639
640 void (*drawColor)(ANPCanvas*, ANPColor);
641 void (*drawPaint)(ANPCanvas*, const ANPPaint*);
642 void (*drawLine)(ANPCanvas*, float x0, float y0, float x1, float y1,
643 const ANPPaint*);
644 void (*drawRect)(ANPCanvas*, const ANPRectF*, const ANPPaint*);
645 void (*drawOval)(ANPCanvas*, const ANPRectF*, const ANPPaint*);
646 void (*drawPath)(ANPCanvas*, const ANPPath*, const ANPPaint*);
647 void (*drawText)(ANPCanvas*, const void* text, uint32_t byteLength,
648 float x, float y, const ANPPaint*);
649 void (*drawPosText)(ANPCanvas*, const void* text, uint32_t byteLength,
650 const float xy[], const ANPPaint*);
651 void (*drawBitmap)(ANPCanvas*, const ANPBitmap*, float x, float y,
652 const ANPPaint*);
653 void (*drawBitmapRect)(ANPCanvas*, const ANPBitmap*,
654 const ANPRectI* src, const ANPRectF* dst,
655 const ANPPaint*);
656 };
657
658 struct ANPWindowInterfaceV0 : ANPInterface {
659 /** Registers a set of rectangles that the plugin would like to keep on
660 screen. The rectangles are listed in order of priority with the highest
661 priority rectangle in location rects[0]. The browser will attempt to keep
662 as many of the rectangles on screen as possible and will scroll them into
663 view in response to the invocation of this method and other various events.
664 The count specifies how many rectangles are in the array. If the count is
665 zero it signals the browser that any existing rectangles should be cleared
666 and no rectangles will be tracked.
667 */
668 void (*setVisibleRects)(NPP instance, const ANPRectI rects[], int32_t count);
669 /** Clears any rectangles that are being tracked as a result of a call to
670 setVisibleRects. This call is equivalent to setVisibleRect(inst, NULL, 0).
671 */
672 void (*clearVisibleRects)(NPP instance);
673 /** Given a boolean value of true the device will be requested to provide
674 a keyboard. A value of false will result in a request to hide the
675 keyboard. Further, the on-screen keyboard will not be displayed if a
676 physical keyboard is active.
677 */
678 void (*showKeyboard)(NPP instance, bool value);
679 /** Called when a plugin wishes to enter into full screen mode. The plugin's
680 Java class (defined in the plugin's apk manifest) will be called
681 asynchronously to provide a View object to be displayed full screen.
682 */
683 void (*requestFullScreen)(NPP instance);
684 /** Called when a plugin wishes to exit from full screen mode. As a result,
685 the plugin's full screen view will be discarded by the view system.
686 */
687 void (*exitFullScreen)(NPP instance);
688 /** Called when a plugin wishes to be zoomed and centered in the current view.
689 */
690 void (*requestCenterFitZoom)(NPP instance);
691 };
692
693 struct ANPWindowInterfaceV1 : ANPWindowInterfaceV0 {
694 /** Returns a rectangle representing the visible area of the plugin on
695 screen. The coordinates are relative to the size of the plugin in the
696 document and therefore will never be negative or exceed the plugin's size.
697 */
698 ANPRectI (*visibleRect)(NPP instance);
699 };
700
701 enum ANPScreenOrientations {
702 /** No preference specified: let the system decide the best orientation.
703 */
704 kDefault_ANPScreenOrientation = 0,
705 /** Would like to have the screen in a landscape orientation, but it will
706 not allow for 180 degree rotations.
707 */
708 kFixedLandscape_ANPScreenOrientation = 1,
709 /** Would like to have the screen in a portrait orientation, but it will
710 not allow for 180 degree rotations.
711 */
712 kFixedPortrait_ANPScreenOrientation = 2,
713 /** Would like to have the screen in landscape orientation, but can use the
714 sensor to change which direction the screen is facing.
715 */
716 kLandscape_ANPScreenOrientation = 3,
717 /** Would like to have the screen in portrait orientation, but can use the
718 sensor to change which direction the screen is facing.
719 */
720 kPortrait_ANPScreenOrientation = 4
721 };
722
723 typedef int32_t ANPScreenOrientation;
724
725 struct ANPWindowInterfaceV2 : ANPWindowInterfaceV1 {
726 /** Called when the plugin wants to specify a particular screen orientation
727 when entering into full screen mode. The orientation must be set prior
728 to entering into full screen. After entering full screen any subsequent
729 changes will be updated the next time the plugin goes full screen.
730 */
731 void (*requestFullScreenOrientation)(NPP instance, ANPScreenOrientation orientation);
732 };
733
734 ///////////////////////////////////////////////////////////////////////////////
735
736 enum ANPSampleFormats {
737 kUnknown_ANPSamleFormat = 0,
738 kPCM16Bit_ANPSampleFormat = 1,
739 kPCM8Bit_ANPSampleFormat = 2
740 };
741 typedef int32_t ANPSampleFormat;
742
743 /** The audio buffer is passed to the callback proc to request more samples.
744 It is owned by the system, and the callback may read it, but should not
745 maintain a pointer to it outside of the scope of the callback proc.
746 */
747 struct ANPAudioBuffer {
748 // RO - repeat what was specified in newTrack()
749 int32_t channelCount;
750 // RO - repeat what was specified in newTrack()
751 ANPSampleFormat format;
752 /** This buffer is owned by the caller. Inside the callback proc, up to
753 "size" bytes of sample data should be written into this buffer. The
754 address is only valid for the scope of a single invocation of the
755 callback proc.
756 */
757 void* bufferData;
758 /** On input, specifies the maximum number of bytes that can be written
759 to "bufferData". On output, specifies the actual number of bytes that
760 the callback proc wrote into "bufferData".
761 */
762 uint32_t size;
763 };
764
765 enum ANPAudioEvents {
766 /** This event is passed to the callback proc when the audio-track needs
767 more sample data written to the provided buffer parameter.
768 */
769 kMoreData_ANPAudioEvent = 0,
770 /** This event is passed to the callback proc if the audio system runs out
771 of sample data. In this event, no buffer parameter will be specified
772 (i.e. NULL will be passed to the 3rd parameter).
773 */
774 kUnderRun_ANPAudioEvent = 1
775 };
776 typedef int32_t ANPAudioEvent;
777
778 /** Called to feed sample data to the track. This will be called in a separate
779 thread. However, you may call trackStop() from the callback (but you
780 cannot delete the track).
781
782 For example, when you have written the last chunk of sample data, you can
783 immediately call trackStop(). This will take effect after the current
784 buffer has been played.
785
786 The "user" parameter is the same value that was passed to newTrack()
787 */
788 typedef void (*ANPAudioCallbackProc)(ANPAudioEvent event, void* user,
789 ANPAudioBuffer* buffer);
790
791 struct ANPAudioTrack; // abstract type for audio tracks
792
793 struct ANPAudioTrackInterfaceV0 : ANPInterface {
794 /** Create a new audio track, or NULL on failure. The track is initially in
795 the stopped state and therefore ANPAudioCallbackProc will not be called
796 until the track is started.
797 */
798 ANPAudioTrack* (*newTrack)(uint32_t sampleRate, // sampling rate in Hz
799 ANPSampleFormat,
800 int channelCount, // MONO=1, STEREO=2
801 ANPAudioCallbackProc,
802 void* user);
803 /** Deletes a track that was created using newTrack. The track can be
804 deleted in any state and it waits for the ANPAudioCallbackProc thread
805 to exit before returning.
806 */
807 void (*deleteTrack)(ANPAudioTrack*);
808
809 void (*start)(ANPAudioTrack*);
810 void (*pause)(ANPAudioTrack*);
811 void (*stop)(ANPAudioTrack*);
812 /** Returns true if the track is not playing (e.g. pause or stop was called,
813 or start was never called.
814 */
815 bool (*isStopped)(ANPAudioTrack*);
816 };
817
818 struct ANPAudioTrackInterfaceV1 : ANPAudioTrackInterfaceV0 {
819 /** Returns the track's latency in milliseconds. */
820 uint32_t (*trackLatency)(ANPAudioTrack*);
821 };
822
823
824 ///////////////////////////////////////////////////////////////////////////////
825 // DEFINITION OF VALUES PASSED THROUGH NPP_HandleEvent
826
827 enum ANPEventTypes {
828 kNull_ANPEventType = 0,
829 kKey_ANPEventType = 1,
830 /** Mouse events are triggered by either clicking with the navigational pad
831 or by tapping the touchscreen (if the kDown_ANPTouchAction is handled by
832 the plugin then no mouse event is generated). The kKey_ANPEventFlag has
833 to be set to true in order to receive these events.
834 */
835 kMouse_ANPEventType = 2,
836 /** Touch events are generated when the user touches on the screen. The
837 kTouch_ANPEventFlag has to be set to true in order to receive these
838 events.
839 */
840 kTouch_ANPEventType = 3,
841 /** Only triggered by a plugin using the kBitmap_ANPDrawingModel. This event
842 signals that the plugin needs to redraw itself into the provided bitmap.
843 */
844 kDraw_ANPEventType = 4,
845 kLifecycle_ANPEventType = 5,
846
847 /** This event type is completely defined by the plugin.
848 When creating an event, the caller must always set the first
849 two fields, the remaining data is optional.
850 ANPEvent evt;
851 evt.inSize = sizeof(ANPEvent);
852 evt.eventType = kCustom_ANPEventType
853 // other data slots are optional
854 evt.other[] = ...;
855 To post a copy of the event, call
856 eventInterface->postEvent(myNPPInstance, &evt);
857 That call makes a copy of the event struct, and post that on the event
858 queue for the plugin.
859 */
860 kCustom_ANPEventType = 6,
861 };
862 typedef int32_t ANPEventType;
863
864 enum ANPKeyActions {
865 kDown_ANPKeyAction = 0,
866 kUp_ANPKeyAction = 1,
867 };
868 typedef int32_t ANPKeyAction;
869
870 #include "ANPKeyCodes.h"
871 typedef int32_t ANPKeyCode;
872
873 enum ANPKeyModifiers {
874 kAlt_ANPKeyModifier = 1 << 0,
875 kShift_ANPKeyModifier = 1 << 1,
876 };
877 // bit-field containing some number of ANPKeyModifier bits
878 typedef uint32_t ANPKeyModifier;
879
880 enum ANPMouseActions {
881 kDown_ANPMouseAction = 0,
882 kUp_ANPMouseAction = 1,
883 };
884 typedef int32_t ANPMouseAction;
885
886 enum ANPTouchActions {
887 /** This occurs when the user first touches on the screen. As such, this
888 action will always occur prior to any of the other touch actions. If
889 the plugin chooses to not handle this action then no other events
890 related to that particular touch gesture will be generated.
891 */
892 kDown_ANPTouchAction = 0,
893 kUp_ANPTouchAction = 1,
894 kMove_ANPTouchAction = 2,
895 kCancel_ANPTouchAction = 3,
896 // The web view will ignore the return value from the following actions
897 kLongPress_ANPTouchAction = 4,
898 kDoubleTap_ANPTouchAction = 5,
899 };
900 typedef int32_t ANPTouchAction;
901
902 enum ANPLifecycleActions {
903 /** The web view containing this plugin has been paused. See documentation
904 on the android activity lifecycle for more information.
905 */
906 kPause_ANPLifecycleAction = 0,
907 /** The web view containing this plugin has been resumed. See documentation
908 on the android activity lifecycle for more information.
909 */
910 kResume_ANPLifecycleAction = 1,
911 /** The plugin has focus and is now the recipient of input events (e.g. key,
912 touch, etc.)
913 */
914 kGainFocus_ANPLifecycleAction = 2,
915 /** The plugin has lost focus and will not receive any input events until it
916 regains focus. This event is always preceded by a GainFocus action.
917 */
918 kLoseFocus_ANPLifecycleAction = 3,
919 /** The browser is running low on available memory and is requesting that
920 the plugin free any unused/inactive resources to prevent a performance
921 degradation.
922 */
923 kFreeMemory_ANPLifecycleAction = 4,
924 /** The page has finished loading. This happens when the page's top level
925 frame reports that it has completed loading.
926 */
927 kOnLoad_ANPLifecycleAction = 5,
928 /** The browser is honoring the plugin's request to go full screen. Upon
929 returning from this event the browser will resize the plugin's java
930 surface to full-screen coordinates.
931 */
932 kEnterFullScreen_ANPLifecycleAction = 6,
933 /** The browser has exited from full screen mode. Immediately prior to
934 sending this event the browser has resized the plugin's java surface to
935 its original coordinates.
936 */
937 kExitFullScreen_ANPLifecycleAction = 7,
938 /** The plugin is visible to the user on the screen. This event will always
939 occur after a kOffScreen_ANPLifecycleAction event.
940 */
941 kOnScreen_ANPLifecycleAction = 8,
942 /** The plugin is no longer visible to the user on the screen. This event
943 will always occur prior to an kOnScreen_ANPLifecycleAction event.
944 */
945 kOffScreen_ANPLifecycleAction = 9,
946 };
947 typedef uint32_t ANPLifecycleAction;
948
949 /* This is what is passed to NPP_HandleEvent() */
950 struct ANPEvent {
951 uint32_t inSize; // size of this struct in bytes
952 ANPEventType eventType;
953 // use based on the value in eventType
954 union {
955 struct {
956 ANPKeyAction action;
957 ANPKeyCode nativeCode;
958 int32_t virtualCode; // windows virtual key code
959 ANPKeyModifier modifiers;
960 int32_t repeatCount; // 0 for initial down (or up)
961 int32_t unichar; // 0 if there is no value
962 } key;
963 struct {
964 ANPMouseAction action;
965 int32_t x; // relative to your "window" (0...width)
966 int32_t y; // relative to your "window" (0...height)
967 } mouse;
968 struct {
969 ANPTouchAction action;
970 ANPKeyModifier modifiers;
971 int32_t x; // relative to your "window" (0...width)
972 int32_t y; // relative to your "window" (0...height)
973 } touch;
974 struct {
975 ANPLifecycleAction action;
976 } lifecycle;
977 struct {
978 ANPDrawingModel model;
979 // relative to (0,0) in top-left of your plugin
980 ANPRectI clip;
981 // use based on the value in model
982 union {
983 ANPBitmap bitmap;
984 struct {
985 int32_t width;
986 int32_t height;
987 } surfaceSize;
988 } data;
989 } draw;
990 } data;
991 };
992
993
994 struct ANPEventInterfaceV0 : ANPInterface {
995 /** Post a copy of the specified event to the plugin. The event will be
996 delivered to the plugin in its main thread (the thread that receives
997 other ANPEvents). If, after posting before delivery, the NPP instance
998 is torn down, the event will be discarded.
999 */
1000 void (*postEvent)(NPP inst, const ANPEvent* event);
1001 };
1002
1003 struct ANPSystemInterfaceV0 : ANPInterface {
1004 /** Return the path name for the current Application's plugin data directory,
1005 or NULL if not supported
1006 */
1007 const char* (*getApplicationDataDirectory)();
1008
1009 /** A helper function to load java classes from the plugin's apk. The
1010 function looks for a class given the fully qualified and null terminated
1011 string representing the className. For example,
1012
1013 const char* className = "com.android.mypackage.MyClass";
1014
1015 If the class cannot be found or there is a problem loading the class
1016 NULL will be returned.
1017 */
1018 jclass (*loadJavaClass)(NPP instance, const char* className);
1019 };
1020
1021 struct ANPSurfaceInterfaceV0 : ANPInterface {
1022 /** Locks the surface from manipulation by other threads and provides a bitmap
1023 to be written to. The dirtyRect param specifies which portion of the
1024 bitmap will be written to. If the dirtyRect is NULL then the entire
1025 surface will be considered dirty. If the lock was successful the function
1026 will return true and the bitmap will be set to point to a valid bitmap.
1027 If not the function will return false and the bitmap will be set to NULL.
1028 */
1029 bool (*lock)(JNIEnv* env, jobject surface, ANPBitmap* bitmap, ANPRectI* dirtyRect);
1030 /** Given a locked surface handle (i.e. result of a successful call to lock)
1031 the surface is unlocked and the contents of the bitmap, specifically
1032 those inside the dirtyRect are written to the screen.
1033 */
1034 void (*unlock)(JNIEnv* env, jobject surface);
1035 };
1036
1037 /**
1038 * TODO should we not use EGL and GL data types for ABI safety?
1039 */
1040 struct ANPTextureInfo {
1041 GLuint textureId;
1042 uint32_t width;
1043 uint32_t height;
1044 GLenum internalFormat;
1045 };
1046
1047 typedef void* ANPEGLContext;
1048
1049 struct ANPOpenGLInterfaceV0 : ANPInterface {
1050 ANPEGLContext (*acquireContext)(NPP instance);
1051
1052 ANPTextureInfo (*lockTexture)(NPP instance);
1053
1054 void (*releaseTexture)(NPP instance, const ANPTextureInfo*);
1055
1056 /**
1057 * Invert the contents of the plugin on the y-axis.
1058 * default is to not be inverted (i.e. use OpenGL coordinates)
1059 */
1060 void (*invertPluginContent)(NPP instance, bool isContentInverted);
1061 };
1062
1063 enum ANPPowerStates {
1064 kDefault_ANPPowerState = 0,
1065 kScreenOn_ANPPowerState = 1
1066 };
1067 typedef int32_t ANPPowerState;
1068
1069 struct ANPSystemInterfaceV1 : ANPSystemInterfaceV0 {
1070 void (*setPowerState)(NPP instance, ANPPowerState powerState);
1071 };
1072
1073 struct ANPSystemInterfaceV2 : ANPInterface {
1074 /** Return the path name for the current Application's plugin data directory,
1075 or NULL if not supported. This directory will change depending on whether
1076 or not the plugin is found within an incognito tab.
1077 */
1078 const char* (*getApplicationDataDirectory)(NPP instance);
1079
1080 // redeclaration of existing features
1081 jclass (*loadJavaClass)(NPP instance, const char* className);
1082 void (*setPowerState)(NPP instance, ANPPowerState powerState);
1083 };
1084
1085 typedef void* ANPNativeWindow;
1086
1087 struct ANPVideoInterfaceV0 : ANPInterface {
1088
1089 /**
1090 * Constructs a new native window to be used for rendering video content.
1091 *
1092 * Subsequent calls will produce new windows, but may also return NULL after
1093 * n attempts if the browser has reached it's limit. Further, if the browser
1094 * is unable to acquire the window quickly it may also return NULL in order
1095 * to not prevent the plugin from executing. A subsequent call will then
1096 * return the window if it is avaiable.
1097 *
1098 * NOTE: The hardware may fail if you try to decode more than the allowable
1099 * number of videos supported on that device.
1100 */
1101 ANPNativeWindow (*acquireNativeWindow)(NPP instance);
1102
1103 /**
1104 * Sets the rectangle that specifies where the video content is to be drawn.
1105 * The dimensions are in document space. Further, if the rect is NULL the
1106 * browser will not attempt to draw the window, therefore do not set the
1107 * dimensions until you queue the first buffer in the window.
1108 */
1109 void (*setWindowDimensions)(NPP instance, const ANPNativeWindow window, const ANPRectF* dimensions);
1110
1111 /**
1112 */
1113 void (*releaseNativeWindow)(NPP instance, ANPNativeWindow window);
1114 };
1115
1116 /** Called to notify the plugin that a video frame has been composited by the
1117 * browser for display. This will be called in a separate thread and as such
1118 * you cannot call releaseNativeWindow from the callback.
1119 *
1120 * The timestamp is in nanoseconds, and is monotonically increasing.
1121 */
1122 typedef void (*ANPVideoFrameCallbackProc)(ANPNativeWindow* window, int64_t timestamp);
1123
1124 struct ANPVideoInterfaceV1 : ANPVideoInterfaceV0 {
1125 /** Set a callback to be notified when an ANPNativeWindow is composited by
1126 * the browser.
1127 */
1128 void (*setFramerateCallback)(NPP instance, const ANPNativeWindow window, ANPVideoFrameCallbackProc);
1129 };
1130
1131 struct ANPNativeWindowInterfaceV0 : ANPInterface {
1132 /**
1133 * Constructs a new native window to be used for rendering plugin content.
1134 *
1135 * Subsequent calls will return the original constructed window. Further, if
1136 * the browser is unable to acquire the window quickly it may return NULL in
1137 * order to not block the plugin indefinitely. A subsequent call will then
1138 * return the window if it is available.
1139 */
1140 ANPNativeWindow (*acquireNativeWindow)(NPP instance);
1141
1142 /**
1143 * Invert the contents of the plugin on the y-axis.
1144 * default is to not be inverted (e.g. use OpenGL coordinates)
1145 */
1146 void (*invertPluginContent)(NPP instance, bool isContentInverted);
1147 };
1148
1149
1150 #endif

mercurial