diff options
author | Mike Reed <reed@google.com> | 2009-05-04 15:34:23 -0400 |
---|---|---|
committer | Mike Reed <reed@google.com> | 2009-05-04 15:34:23 -0400 |
commit | 4603aa50552a853aa7aedcd809460a83586daa53 (patch) | |
tree | 774c026cfb6b28d842cd54cfb43de124ed1f0b46 | |
parent | 80c54961fb9fac04a32a62b92d078d3013997477 (diff) | |
download | external_webkit-4603aa50552a853aa7aedcd809460a83586daa53.zip external_webkit-4603aa50552a853aa7aedcd809460a83586daa53.tar.gz external_webkit-4603aa50552a853aa7aedcd809460a83586daa53.tar.bz2 |
add path apis for plugins. also add drawLine to canvas
-rw-r--r-- | WebKit/Android.mk | 1 | ||||
-rw-r--r-- | WebKit/android/plugins/ANPCanvasInterface.cpp | 6 | ||||
-rw-r--r-- | WebKit/android/plugins/ANPPathInterface.cpp | 113 | ||||
-rw-r--r-- | WebKit/android/plugins/android_npapi.h | 51 |
4 files changed, 170 insertions, 1 deletions
diff --git a/WebKit/Android.mk b/WebKit/Android.mk index b3de259..319671b 100644 --- a/WebKit/Android.mk +++ b/WebKit/Android.mk @@ -56,6 +56,7 @@ LOCAL_SRC_FILES := \ android/plugins/ANPLogInterface.cpp \ android/plugins/ANPMatrixInterface.cpp \ android/plugins/ANPPaintInterface.cpp \ + android/plugins/ANPPathInterface.cpp \ android/plugins/ANPSoundInterface.cpp \ android/plugins/ANPTypefaceInterface.cpp \ android/plugins/ANPWindowInterface.cpp \ diff --git a/WebKit/android/plugins/ANPCanvasInterface.cpp b/WebKit/android/plugins/ANPCanvasInterface.cpp index ba79691..e1b512f 100644 --- a/WebKit/android/plugins/ANPCanvasInterface.cpp +++ b/WebKit/android/plugins/ANPCanvasInterface.cpp @@ -102,6 +102,12 @@ static void anp_drawPaint(ANPCanvas* canvas, const ANPPaint* paint) { canvas->skcanvas->drawPaint(*paint); } +static void anp_drawLine(ANPCanvas* canvas, float x0, float y0, + float x1, float y1, const ANPPaint* paint) { + canvas->skcanvas->drawLine(SkFloatToScalar(x0), SkFloatToScalar(y0), + SkFloatToScalar(x1), SkFloatToScalar(y1), *paint); +} + static void anp_drawRect(ANPCanvas* canvas, const ANPRectF* rect, const ANPPaint* paint) { SkRect r; diff --git a/WebKit/android/plugins/ANPPathInterface.cpp b/WebKit/android/plugins/ANPPathInterface.cpp new file mode 100644 index 0000000..468d866 --- /dev/null +++ b/WebKit/android/plugins/ANPPathInterface.cpp @@ -0,0 +1,113 @@ +/* + * 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" + +static ANPPath* anp_newPath() { + return new ANPPath; +} + +static void anp_deletePath(ANPPath* path) { + delete path; +} + +static void anp_copy(ANPPath* dst, const ANPPath* src) { + *dst = *src; +} + +static bool anp_equal(const ANPPath* p0, const ANPPath* p1) { + return *p0 == *p1; +} + +static void anp_reset(ANPPath* path) { + path->reset(); +} + +static bool anp_isEmpty(const ANPPath* path) { + return path->isEmpty(); +} + +static void anp_getBounds(const ANPPath* path, ANPRectF* bounds) { + SkANP::SetRect(bounds, path->getBounds()); +} + +static void anp_moveTo(ANPPath* path, float x, float y) { + path->moveTo(SkFloatToScalar(x), SkFloatToScalar(y)); +} + +static void anp_lineTo(ANPPath* path, float x, float y) { + path->lineTo(SkFloatToScalar(x), SkFloatToScalar(y)); +} + +static void anp_quadTo(ANPPath* path, float x0, float y0, float x1, float y1) { + path->quadTo(SkFloatToScalar(x0), SkFloatToScalar(y0), + SkFloatToScalar(x1), SkFloatToScalar(y1)); +} + +static void anp_cubicTo(ANPPath* path, float x0, float y0, + float x1, float y1, float x2, float y2) { + path->cubicTo(SkFloatToScalar(x0), SkFloatToScalar(y0), + SkFloatToScalar(x1), SkFloatToScalar(y1), + SkFloatToScalar(x2), SkFloatToScalar(y2)); +} + +static void anp_close(ANPPath* path) { + path->close(); +} + +static void anp_offset(ANPPath* path, float dx, float dy, ANPPath* dst) { + path->offset(SkFloatToScalar(dx), SkFloatToScalar(dy), dst); +} + +static void anp_transform(ANPPath* src, const ANPMatrix* matrix, + ANPPath* dst) { + src->transform(*matrix, dst); +} + +/////////////////////////////////////////////////////////////////////////////// + +#define ASSIGN(obj, name) (obj)->name = anp_##name + +void ANPPathInterfaceV0_Init(ANPInterface* value) { + ANPPathInterfaceV0* i = reinterpret_cast<ANPPathInterfaceV0*>(value); + + ASSIGN(i, newPath); + ASSIGN(i, deletePath); + ASSIGN(i, copy); + ASSIGN(i, equal); + ASSIGN(i, reset); + ASSIGN(i, isEmpty); + ASSIGN(i, getBounds); + ASSIGN(i, moveTo); + ASSIGN(i, lineTo); + ASSIGN(i, quadTo); + ASSIGN(i, cubicTo); + ASSIGN(i, close); + ASSIGN(i, offset); + ASSIGN(i, transform); +} + diff --git a/WebKit/android/plugins/android_npapi.h b/WebKit/android/plugins/android_npapi.h index f64c8ce..85a8c99 100644 --- a/WebKit/android/plugins/android_npapi.h +++ b/WebKit/android/plugins/android_npapi.h @@ -212,6 +212,53 @@ struct ANPMatrixInterfaceV0 : ANPInterface { int32_t count); }; +struct ANPPathInterfaceV0 : ANPInterface { + /* Return a new path */ + ANPPath* (*newPath)(); + + /* Delete a path previously allocated by ANPPath() */ + void (*deletePath)(ANPPath*); + + /* Make a deep copy of the src path, into the dst path (already allocated + by the caller). + */ + void (*copy)(ANPPath* dst, const ANPPath* src); + + /* Returns true if the two paths are the same (i.e. have the same points) + */ + bool (*equal)(const ANPPath* path0, const ANPPath* path1); + + /* Remove any previous points, initializing the path back to empty. */ + void (*reset)(ANPPath*); + + /* Return true if the path is empty (has no lines, quads or cubics). */ + bool (*isEmpty)(const ANPPath*); + + /* Return the path's bounds in bounds. */ + void (*getBounds)(const ANPPath*, ANPRectF* bounds); + + void (*moveTo)(ANPPath*, float x, float y); + void (*lineTo)(ANPPath*, float x, float y); + void (*quadTo)(ANPPath*, float x0, float y0, float x1, float y1); + void (*cubicTo)(ANPPath*, float x0, float y0, float x1, float y1, + float x2, float y2); + void (*close)(ANPPath*); + + /* Offset the src path by [dx, dy]. If dst is null, apply the + change directly to the src path. If dst is not null, write the + changed path into dst, and leave the src path unchanged. In that case + dst must have been previously allocated by the caller. + */ + void (*offset)(ANPPath* src, float dx, float dy, ANPPath* dst); + + /* Transform the path by the matrix. If dst is null, apply the + change directly to the src path. If dst is not null, write the + changed path into dst, and leave the src path unchanged. In that case + dst must have been previously allocated by the caller. + */ + void (*transform)(ANPPath* src, const ANPMatrix*, ANPPath* dst); +}; + typedef uint32_t ANPColor; #define ANP_MAKE_COLOR(a, r, g, b) \ (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)) @@ -433,9 +480,11 @@ struct ANPCanvasInterfaceV0 : ANPInterface { 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*); + void (*drawLine)(ANPCanvas*, float x0, float y0, float x1, float y1, + const ANPPaint*); void (*drawRect)(ANPCanvas*, const ANPRectF*, const ANPPaint*); void (*drawOval)(ANPCanvas*, const ANPRectF*, const ANPPaint*); void (*drawPath)(ANPCanvas*, const ANPPath*, const ANPPaint*); |