summaryrefslogtreecommitdiffstats
path: root/WebKit/android/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/android/plugins')
-rw-r--r--WebKit/android/plugins/ANPCanvasInterface.cpp28
-rw-r--r--WebKit/android/plugins/ANPMatrixInterface.cpp168
-rw-r--r--WebKit/android/plugins/ANPPaintInterface.cpp14
-rw-r--r--WebKit/android/plugins/SkANP.cpp8
-rw-r--r--WebKit/android/plugins/SkANP.h5
-rw-r--r--WebKit/android/plugins/android_npapi.h103
-rw-r--r--WebKit/android/plugins/sample/pluginGraphics.cpp5
7 files changed, 327 insertions, 4 deletions
diff --git a/WebKit/android/plugins/ANPCanvasInterface.cpp b/WebKit/android/plugins/ANPCanvasInterface.cpp
index 96498ef..ba79691 100644
--- a/WebKit/android/plugins/ANPCanvasInterface.cpp
+++ b/WebKit/android/plugins/ANPCanvasInterface.cpp
@@ -69,6 +69,31 @@ static void anp_clipPath(ANPCanvas* canvas, const ANPPath* path) {
canvas->skcanvas->clipPath(*path);
}
+static void anp_getTotalMatrix(ANPCanvas* canvas, ANPMatrix* matrix) {
+ const SkMatrix& src = canvas->skcanvas->getTotalMatrix();
+ *matrix = *reinterpret_cast<const ANPMatrix*>(&src);
+}
+
+static bool anp_getLocalClipBounds(ANPCanvas* canvas, ANPRectF* r,
+ bool antialias) {
+ SkRect bounds;
+ if (canvas->skcanvas->getClipBounds(&bounds,
+ antialias ? SkCanvas::kAA_EdgeType : SkCanvas::kBW_EdgeType)) {
+ SkANP::SetRect(r, bounds);
+ return true;
+ }
+ return false;
+}
+
+static bool anp_getDeviceClipBounds(ANPCanvas* canvas, ANPRectI* r) {
+ const SkRegion& clip = canvas->skcanvas->getTotalClip();
+ if (!clip.isEmpty()) {
+ SkANP::SetRect(r, clip.getBounds());
+ return true;
+ }
+ return false;
+}
+
static void anp_drawColor(ANPCanvas* canvas, ANPColor color) {
canvas->skcanvas->drawColor(color);
}
@@ -146,6 +171,9 @@ void ANPCanvasInterfaceV0_Init(ANPInterface* value) {
ASSIGN(i, skew);
ASSIGN(i, clipRect);
ASSIGN(i, clipPath);
+ ASSIGN(i, getTotalMatrix);
+ ASSIGN(i, getLocalClipBounds);
+ ASSIGN(i, getDeviceClipBounds);
ASSIGN(i, drawColor);
ASSIGN(i, drawPaint);
ASSIGN(i, drawRect);
diff --git a/WebKit/android/plugins/ANPMatrixInterface.cpp b/WebKit/android/plugins/ANPMatrixInterface.cpp
new file mode 100644
index 0000000..815b954
--- /dev/null
+++ b/WebKit/android/plugins/ANPMatrixInterface.cpp
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2009, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// must include config.h first for webkit to fiddle with new/delete
+#include "config.h"
+#include "SkANP.h"
+
+#ifdef SK_SCALAR_IS_FIXED
+static void fromFloat(SkScalar dst[], const float src[], int n) {
+ for (int i = 0; i < n; i++) {
+ dst[i] = SkFloatToScalar(src[i]);
+ }
+}
+
+static void toFloat(float dst[], const SkScalar src[], int n) {
+ for (int i = 0; i < n; i++) {
+ dst[i] = SkScalarToFloat(src[i]);
+ }
+}
+#endif
+
+static ANPMatrix* anp_newMatrix() {
+ return new ANPMatrix;
+}
+
+static void anp_deleteMatrix(ANPMatrix* matrix) {
+ delete matrix;
+}
+
+static ANPMatrixFlag anp_getFlags(const ANPMatrix* matrix) {
+ return matrix->getType();
+}
+
+static void anp_copy(ANPMatrix* dst, const ANPMatrix* src) {
+ *dst = *src;
+}
+
+static void anp_get3x3(const ANPMatrix* matrix, float dst[9]) {
+ for (int i = 0; i < 9; i++) {
+ dst[i] = SkScalarToFloat(matrix->get(i));
+ }
+}
+
+static void anp_set3x3(ANPMatrix* matrix, const float src[9]) {
+ for (int i = 0; i < 9; i++) {
+ matrix->set(i, SkFloatToScalar(src[i]));
+ }
+}
+
+static void anp_setIdentity(ANPMatrix* matrix) {
+ matrix->reset();
+}
+
+static void anp_preTranslate(ANPMatrix* matrix, float tx, float ty) {
+ matrix->preTranslate(SkFloatToScalar(tx), SkFloatToScalar(ty));
+}
+
+static void anp_postTranslate(ANPMatrix* matrix, float tx, float ty) {
+ matrix->postTranslate(SkFloatToScalar(tx), SkFloatToScalar(ty));
+}
+
+static void anp_preScale(ANPMatrix* matrix, float sx, float sy) {
+ matrix->preScale(SkFloatToScalar(sx), SkFloatToScalar(sy));
+}
+
+static void anp_postScale(ANPMatrix* matrix, float sx, float sy) {
+ matrix->postScale(SkFloatToScalar(sx), SkFloatToScalar(sy));
+}
+
+static void anp_preSkew(ANPMatrix* matrix, float kx, float ky) {
+ matrix->preSkew(SkFloatToScalar(kx), SkFloatToScalar(ky));
+}
+
+static void anp_postSkew(ANPMatrix* matrix, float kx, float ky) {
+ matrix->postSkew(SkFloatToScalar(kx), SkFloatToScalar(ky));
+}
+
+static void anp_preRotate(ANPMatrix* matrix, float degrees) {
+ matrix->preRotate(SkFloatToScalar(degrees));
+}
+
+static void anp_postRotate(ANPMatrix* matrix, float degrees) {
+ matrix->postRotate(SkFloatToScalar(degrees));
+}
+
+static void anp_preConcat(ANPMatrix* matrix, const ANPMatrix* other) {
+ matrix->preConcat(*other);
+}
+
+static void anp_postConcat(ANPMatrix* matrix, const ANPMatrix* other) {
+ matrix->postConcat(*other);
+}
+
+static bool anp_invert(ANPMatrix* dst, const ANPMatrix* src) {
+ return src->invert(dst);
+}
+
+static void anp_mapPoints(ANPMatrix* matrix, float dst[], const float src[],
+ int32_t count) {
+#ifdef SK_SCALAR_IS_FLOAT
+ matrix->mapPoints(reinterpret_cast<SkPoint*>(dst),
+ reinterpret_cast<const SkPoint*>(src), count);
+#else
+ const int N = 64;
+ SkPoint tmp[N];
+ do {
+ int n = count;
+ if (n > N) {
+ n = N;
+ }
+ fromFloat(&tmp[0].fX, src, n*2);
+ matrix->mapPoints(tmp, n);
+ toFloat(dst, &tmp[0].fX, n*2);
+ count -= n;
+ } while (count > 0);
+#endif
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+#define ASSIGN(obj, name) (obj)->name = anp_##name
+
+void ANPMatrixInterfaceV0_Init(ANPInterface* value) {
+ ANPMatrixInterfaceV0* i = reinterpret_cast<ANPMatrixInterfaceV0*>(value);
+
+ ASSIGN(i, newMatrix);
+ ASSIGN(i, deleteMatrix);
+ ASSIGN(i, getFlags);
+ ASSIGN(i, copy);
+ ASSIGN(i, get3x3);
+ ASSIGN(i, set3x3);
+ ASSIGN(i, setIdentity);
+ ASSIGN(i, preTranslate);
+ ASSIGN(i, postTranslate);
+ ASSIGN(i, preScale);
+ ASSIGN(i, postScale);
+ ASSIGN(i, preSkew);
+ ASSIGN(i, postSkew);
+ ASSIGN(i, preRotate);
+ ASSIGN(i, postRotate);
+ ASSIGN(i, preConcat);
+ ASSIGN(i, postConcat);
+ ASSIGN(i, invert);
+ ASSIGN(i, mapPoints);
+}
+
diff --git a/WebKit/android/plugins/ANPPaintInterface.cpp b/WebKit/android/plugins/ANPPaintInterface.cpp
index 2a74b7f..4b561f0 100644
--- a/WebKit/android/plugins/ANPPaintInterface.cpp
+++ b/WebKit/android/plugins/ANPPaintInterface.cpp
@@ -158,6 +158,19 @@ static int anp_getTextWidths(ANPPaint* paint, const void* text,
reinterpret_cast<SkRect*>(bounds));
}
+static float anp_getFontMetrics(ANPPaint* paint, ANPFontMetrics* metrics) {
+ SkPaint::FontMetrics fm;
+ SkScalar spacing = paint->getFontMetrics(&fm);
+ if (metrics) {
+ metrics->fTop = SkScalarToFloat(fm.fTop);
+ metrics->fAscent = SkScalarToFloat(fm.fAscent);
+ metrics->fDescent = SkScalarToFloat(fm.fDescent);
+ metrics->fBottom = SkScalarToFloat(fm.fBottom);
+ metrics->fLeading = SkScalarToFloat(fm.fLeading);
+ }
+ return SkScalarToFloat(spacing);
+}
+
///////////////////////////////////////////////////////////////////////////////
#define ASSIGN(obj, name) (obj)->name = anp_##name
@@ -195,5 +208,6 @@ void ANPPaintInterfaceV0_Init(ANPInterface* value) {
ASSIGN(i, setTypeface);
ASSIGN(i, measureText);
ASSIGN(i, getTextWidths);
+ ASSIGN(i, getFontMetrics);
}
diff --git a/WebKit/android/plugins/SkANP.cpp b/WebKit/android/plugins/SkANP.cpp
index 276dd8d..3912f99 100644
--- a/WebKit/android/plugins/SkANP.cpp
+++ b/WebKit/android/plugins/SkANP.cpp
@@ -48,6 +48,14 @@ ANPRectI* SkANP::SetRect(ANPRectI* dst, const SkIRect& src) {
return dst;
}
+ANPRectF* SkANP::SetRect(ANPRectF* dst, const SkRect& src) {
+ dst->left = SkScalarToFloat(src.fLeft);
+ dst->top = SkScalarToFloat(src.fTop);
+ dst->right = SkScalarToFloat(src.fRight);
+ dst->bottom = SkScalarToFloat(src.fBottom);
+ return dst;
+}
+
SkBitmap* SkANP::SetBitmap(SkBitmap* dst, const ANPBitmap& src) {
SkBitmap::Config config = SkBitmap::kNo_Config;
diff --git a/WebKit/android/plugins/SkANP.h b/WebKit/android/plugins/SkANP.h
index 2389f0d..f319c9b 100644
--- a/WebKit/android/plugins/SkANP.h
+++ b/WebKit/android/plugins/SkANP.h
@@ -28,10 +28,14 @@
#include "android_npapi.h"
#include "SkCanvas.h"
+#include "SkMatrix.h"
#include "SkPaint.h"
#include "SkPath.h"
#include "SkTypeface.h"
+struct ANPMatrix : SkMatrix {
+};
+
struct ANPPath : SkPath {
};
@@ -65,6 +69,7 @@ public:
static SkRect* SetRect(SkRect* dst, const ANPRectF& src);
static SkIRect* SetRect(SkIRect* dst, const ANPRectI& src);
static ANPRectI* SetRect(ANPRectI* dst, const SkIRect& src);
+ static ANPRectF* SetRect(ANPRectF* dst, const SkRect& src);
static SkBitmap* SetBitmap(SkBitmap* dst, const ANPBitmap& src);
static bool SetBitmap(ANPBitmap* dst, const SkBitmap& src);
diff --git a/WebKit/android/plugins/android_npapi.h b/WebKit/android/plugins/android_npapi.h
index 8b05d0a..f64c8ce 100644
--- a/WebKit/android/plugins/android_npapi.h
+++ b/WebKit/android/plugins/android_npapi.h
@@ -72,11 +72,21 @@ struct ANPRectI {
};
struct ANPCanvas;
+struct ANPMatrix;
struct ANPPaint;
struct ANPPath;
struct ANPRegion;
struct ANPTypeface;
+enum ANPMatrixFlags {
+ kIdentity_ANPMatrixFlag = 0,
+ kTranslate_ANPMatrixFlag = 0x01,
+ kScale_ANPMatrixFlag = 0x02,
+ kAffine_ANPMatrixFlag = 0x04,
+ kPerspective_ANPMatrixFlag = 0x08,
+};
+typedef uint32_t ANPMatrixFlag;
+
///////////////////////////////////////////////////////////////////////////////
// NPN_GetValue
@@ -89,9 +99,10 @@ struct ANPTypeface;
#define kLogInterfaceV0_ANPGetValue ((NPNVariable)1000)
#define kAudioTrackInterfaceV0_ANPGetValue ((NPNVariable)1001)
#define kCanvasInterfaceV0_ANPGetValue ((NPNVariable)1002)
-#define kPaintInterfaceV0_ANPGetValue ((NPNVariable)1003)
-#define kTypefaceInterfaceV0_ANPGetValue ((NPNVariable)1004)
-#define kWindowInterfaceV0_ANPGetValue ((NPNVariable)1005)
+#define kMatrixInterfaceV0_ANPGetValue ((NPNVariable)1003)
+#define kPaintInterfaceV0_ANPGetValue ((NPNVariable)1004)
+#define kTypefaceInterfaceV0_ANPGetValue ((NPNVariable)1005)
+#define kWindowInterfaceV0_ANPGetValue ((NPNVariable)1006)
/* queries for which drawing model is desired (for the draw event)
@@ -148,6 +159,59 @@ struct ANPLogInterfaceV0 : ANPInterface {
void (*log)(NPP instance, ANPLogType, const char format[], ...);
};
+struct ANPMatrixInterfaceV0 : ANPInterface {
+ /* Return a new identity matrix
+ */
+ ANPMatrix* (*newMatrix)();
+ /* Delete a matrix previously allocated by newMatrix()
+ */
+ void (*deleteMatrix)(ANPMatrix*);
+
+ ANPMatrixFlag (*getFlags)(const ANPMatrix*);
+
+ void (*copy)(ANPMatrix* dst, const ANPMatrix* src);
+
+ /* Return the matrix values in a float array (allcoated by the caller),
+ where the values are treated as follows:
+ w = x * [6] + y * [7] + [8];
+ x' = (x * [0] + y * [1] + [2]) / w;
+ y' = (x * [3] + y * [4] + [5]) / w;
+ */
+ void (*get3x3)(const ANPMatrix*, float[9]);
+ /* Initialize the matrix from values in a float array,
+ where the values are treated as follows:
+ w = x * [6] + y * [7] + [8];
+ x' = (x * [0] + y * [1] + [2]) / w;
+ y' = (x * [3] + y * [4] + [5]) / w;
+ */
+ void (*set3x3)(ANPMatrix*, const float[9]);
+
+ void (*setIdentity)(ANPMatrix*);
+ void (*preTranslate)(ANPMatrix*, float tx, float ty);
+ void (*postTranslate)(ANPMatrix*, float tx, float ty);
+ void (*preScale)(ANPMatrix*, float sx, float sy);
+ void (*postScale)(ANPMatrix*, float sx, float sy);
+ void (*preSkew)(ANPMatrix*, float kx, float ky);
+ void (*postSkew)(ANPMatrix*, float kx, float ky);
+ void (*preRotate)(ANPMatrix*, float degrees);
+ void (*postRotate)(ANPMatrix*, float degrees);
+ void (*preConcat)(ANPMatrix*, const ANPMatrix*);
+ void (*postConcat)(ANPMatrix*, const ANPMatrix*);
+
+ /* Return true if src is invertible, and if so, return its inverse in dst.
+ If src is not invertible, return false and ignore dst.
+ */
+ bool (*invert)(ANPMatrix* dst, const ANPMatrix* src);
+
+ /* Transform the x,y pairs in src[] by this matrix, and store the results
+ in dst[]. The count parameter is treated as the number of pairs in the
+ array. It is legal for src and dst to point to the same memory, but
+ illegal for the two arrays to partially overlap.
+ */
+ void (*mapPoints)(ANPMatrix*, float dst[], const float src[],
+ int32_t count);
+};
+
typedef uint32_t ANPColor;
#define ANP_MAKE_COLOR(a, r, g, b) \
(((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
@@ -202,6 +266,19 @@ enum ANPTypefaceStyles {
};
typedef uint32_t ANPTypefaceStyle;
+struct ANPFontMetrics {
+ //! The greatest distance above the baseline for any glyph (will be <= 0)
+ float fTop;
+ //! The recommended distance above the baseline (will be <= 0)
+ float fAscent;
+ //! The recommended distance below the baseline (will be >= 0)
+ float fDescent;
+ //! The greatest distance below the baseline for any glyph (will be >= 0)
+ float fBottom;
+ //! The recommended distance to add between lines of text (will be >= 0)
+ float fLeading;
+};
+
struct ANPTypefaceInterfaceV0 : ANPInterface {
/** Return a new reference to the typeface that most closely matches the
requested name and style. Pass null as the name to return
@@ -311,6 +388,12 @@ struct ANPPaintInterfaceV0 : ANPInterface {
*/
int (*getTextWidths)(ANPPaint*, const void* text, uint32_t byteLength,
float widths[], ANPRectF bounds[]);
+
+ /** Return in metrics the spacing values for text, respecting the paint's
+ typeface and pointsize, and return the spacing between lines
+ (descent - ascent + leading). If metrics is NULL, it will be ignored.
+ */
+ float (*getFontMetrics)(ANPPaint*, ANPFontMetrics* metrics);
};
struct ANPCanvasInterfaceV0 : ANPInterface {
@@ -334,8 +417,22 @@ struct ANPCanvasInterfaceV0 : ANPInterface {
void (*scale)(ANPCanvas*, float sx, float sy);
void (*rotate)(ANPCanvas*, float degrees);
void (*skew)(ANPCanvas*, float kx, float ky);
+ void (*concat)(ANPCanvas*, const ANPMatrix*);
void (*clipRect)(ANPCanvas*, const ANPRectF*);
void (*clipPath)(ANPCanvas*, const ANPPath*);
+
+ /* Return the current matrix on the canvas
+ */
+ void (*getTotalMatrix)(ANPCanvas*, ANPMatrix*);
+ /* Return the current clip bounds in local coordinates, expanding it to
+ account for antialiasing edge effects if aa is true. If the
+ current clip is empty, return false and ignore the bounds argument.
+ */
+ bool (*getLocalClipBounds)(ANPCanvas*, ANPRectF* bounds, bool aa);
+ /* Return the current clip bounds in device coordinates in bounds. If the
+ current clip is empty, return false and ignore the bounds argument.
+ */
+ bool (*getDeviceClipBounds)(ANPCanvas*, ANPRectI* bounds);
void (*drawColor)(ANPCanvas*, ANPColor);
void (*drawPaint)(ANPCanvas*, const ANPPaint*);
diff --git a/WebKit/android/plugins/sample/pluginGraphics.cpp b/WebKit/android/plugins/sample/pluginGraphics.cpp
index 4c0e6f8..ffa43e5 100644
--- a/WebKit/android/plugins/sample/pluginGraphics.cpp
+++ b/WebKit/android/plugins/sample/pluginGraphics.cpp
@@ -145,9 +145,12 @@ void BallAnimation::draw(ANPCanvas* canvas) {
bounce(&m_y, &m_dy, obj->window->height - OH);
if (obj->mUnichar) {
+ ANPFontMetrics fm;
+ gPaintI.getFontMetrics(m_paint, &fm);
+
gPaintI.setColor(m_paint, 0xFF0000FF);
char c = static_cast<char>(obj->mUnichar);
- gCanvasI.drawText(canvas, &c, 1, 10, 30, m_paint);
+ gCanvasI.drawText(canvas, &c, 1, 10, -fm.fTop, m_paint);
}
}