dom/plugins/base/android/android_npapi.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial