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