summaryrefslogtreecommitdiffstats
path: root/samples
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2009-07-16 11:38:02 -0400
committerDerek Sollenberger <djsollen@google.com>2009-07-17 08:50:53 -0400
commitc0f26576955f8dd6ba7a58f9f55054fb3c0fa7d8 (patch)
treecc3d116e100722f7dd1c92b0a0ca883b04159d9b /samples
parent7b627e8935bc6a63bd8ae1d7de056af9a4d0386e (diff)
downloadandroid_development-c0f26576955f8dd6ba7a58f9f55054fb3c0fa7d8.tar.gz
android_development-c0f26576955f8dd6ba7a58f9f55054fb3c0fa7d8.tar.bz2
android_development-c0f26576955f8dd6ba7a58f9f55054fb3c0fa7d8.zip
Adding support for surface views. also removed subplugin's dependency on ANPCanvas.
Diffstat (limited to 'samples')
-rw-r--r--samples/BrowserPlugin/jni/Android.mk2
-rw-r--r--samples/BrowserPlugin/jni/PluginObject.h4
-rw-r--r--samples/BrowserPlugin/jni/animation/AnimationPlugin.cpp30
-rw-r--r--samples/BrowserPlugin/jni/animation/AnimationPlugin.h6
-rw-r--r--samples/BrowserPlugin/jni/audio/AudioPlugin.cpp30
-rw-r--r--samples/BrowserPlugin/jni/audio/AudioPlugin.h15
-rw-r--r--samples/BrowserPlugin/jni/background/BackgroundPlugin.cpp31
-rw-r--r--samples/BrowserPlugin/jni/background/BackgroundPlugin.h3
-rw-r--r--samples/BrowserPlugin/jni/form/FormPlugin.cpp30
-rw-r--r--samples/BrowserPlugin/jni/form/FormPlugin.h3
-rw-r--r--samples/BrowserPlugin/jni/main.cpp15
-rw-r--r--samples/BrowserPlugin/jni/surface/SurfacePlugin.cpp88
-rw-r--r--samples/BrowserPlugin/jni/surface/SurfacePlugin.h42
13 files changed, 220 insertions, 79 deletions
diff --git a/samples/BrowserPlugin/jni/Android.mk b/samples/BrowserPlugin/jni/Android.mk
index a5150ba0d..329a6fdd1 100644
--- a/samples/BrowserPlugin/jni/Android.mk
+++ b/samples/BrowserPlugin/jni/Android.mk
@@ -34,6 +34,7 @@ LOCAL_SRC_FILES := \
audio/AudioPlugin.cpp \
background/BackgroundPlugin.cpp \
form/FormPlugin.cpp \
+ surface/SurfacePlugin.cpp \
LOCAL_C_INCLUDES += \
$(LOCAL_PATH) \
@@ -41,6 +42,7 @@ LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/audio \
$(LOCAL_PATH)/background \
$(LOCAL_PATH)/form \
+ $(LOCAL_PATH)/surface \
external/webkit/WebCore/bridge \
external/webkit/WebCore/plugins \
external/webkit/WebCore/platform/android/JavaVM \
diff --git a/samples/BrowserPlugin/jni/PluginObject.h b/samples/BrowserPlugin/jni/PluginObject.h
index dfda6b741..248a09b03 100644
--- a/samples/BrowserPlugin/jni/PluginObject.h
+++ b/samples/BrowserPlugin/jni/PluginObject.h
@@ -40,7 +40,6 @@ class SubPlugin {
public:
SubPlugin(NPP inst) : m_inst(inst) {}
virtual ~SubPlugin() {}
- virtual void draw(ANPCanvas*) = 0;
virtual int16 handleEvent(const ANPEvent* evt) = 0;
virtual bool supportsDrawingModel(ANPDrawingModel) = 0;
@@ -56,7 +55,8 @@ enum PluginTypes {
kBackground_PluginType = 3,
kForm_PluginType = 4,
kText_PluginType = 5,
- kPaint_PluginType = 6
+ kPaint_PluginType = 6,
+ kSurface_PluginType = 7,
};
typedef uint32_t PluginType;
diff --git a/samples/BrowserPlugin/jni/animation/AnimationPlugin.cpp b/samples/BrowserPlugin/jni/animation/AnimationPlugin.cpp
index 8516d0477..9b264515e 100644
--- a/samples/BrowserPlugin/jni/animation/AnimationPlugin.cpp
+++ b/samples/BrowserPlugin/jni/animation/AnimationPlugin.cpp
@@ -63,20 +63,6 @@ static void inval(NPP instance, const ANPRectF& r, bool doAA) {
browser->invalidaterect(instance, &inval);
}
-static void drawPlugin(SubPlugin* plugin, const ANPBitmap& bitmap, const ANPRectI& clip) {
- ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap);
-
- ANPRectF clipR;
- clipR.left = clip.left;
- clipR.top = clip.top;
- clipR.right = clip.right;
- clipR.bottom = clip.bottom;
- gCanvasI.clipRect(canvas, &clipR);
-
- plugin->draw(canvas);
- gCanvasI.deleteCanvas(canvas);
-}
-
uint32_t getMSecs() {
struct timeval tv;
gettimeofday(&tv, NULL);
@@ -134,6 +120,20 @@ bool BallAnimation::supportsDrawingModel(ANPDrawingModel model) {
return (model == kBitmap_ANPDrawingModel);
}
+void BallAnimation::drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip) {
+ ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap);
+
+ ANPRectF clipR;
+ clipR.left = clip.left;
+ clipR.top = clip.top;
+ clipR.right = clip.right;
+ clipR.bottom = clip.bottom;
+ gCanvasI.clipRect(canvas, &clipR);
+
+ draw(canvas);
+ gCanvasI.deleteCanvas(canvas);
+}
+
void BallAnimation::draw(ANPCanvas* canvas) {
NPP instance = this->inst();
PluginObject *obj = (PluginObject*) instance->pdata;
@@ -233,7 +233,7 @@ int16 BallAnimation::handleEvent(const ANPEvent* evt) {
case kDraw_ANPEventType:
switch (evt->data.draw.model) {
case kBitmap_ANPDrawingModel:
- drawPlugin(this, evt->data.draw.data.bitmap, evt->data.draw.clip);
+ drawPlugin(evt->data.draw.data.bitmap, evt->data.draw.clip);
return 1;
default:
break; // unknown drawing model
diff --git a/samples/BrowserPlugin/jni/animation/AnimationPlugin.h b/samples/BrowserPlugin/jni/animation/AnimationPlugin.h
index e47bec48e..464f906bd 100644
--- a/samples/BrowserPlugin/jni/animation/AnimationPlugin.h
+++ b/samples/BrowserPlugin/jni/animation/AnimationPlugin.h
@@ -33,9 +33,12 @@ public:
BallAnimation(NPP inst);
virtual ~BallAnimation();
virtual bool supportsDrawingModel(ANPDrawingModel);
- virtual void draw(ANPCanvas*);
virtual int16 handleEvent(const ANPEvent* evt);
private:
+ void draw(ANPCanvas*);
+ void drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip);
+ void centerPluginOnScreen();
+
float m_x;
float m_y;
float m_dx;
@@ -48,7 +51,6 @@ private:
static const float SCALE = 0.1;
- void centerPluginOnScreen();
int m_scrollX;
int m_scrollY;
int m_screenH;
diff --git a/samples/BrowserPlugin/jni/audio/AudioPlugin.cpp b/samples/BrowserPlugin/jni/audio/AudioPlugin.cpp
index 621b8f835..58d340cb3 100644
--- a/samples/BrowserPlugin/jni/audio/AudioPlugin.cpp
+++ b/samples/BrowserPlugin/jni/audio/AudioPlugin.cpp
@@ -64,20 +64,6 @@ static void inval(NPP instance, const ANPRectF& r, bool doAA) {
browser->invalidaterect(instance, &inval);
}
-static void drawPlugin(SubPlugin* plugin, const ANPBitmap& bitmap, const ANPRectI& clip) {
- ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap);
-
- ANPRectF clipR;
- clipR.left = clip.left;
- clipR.top = clip.top;
- clipR.right = clip.right;
- clipR.bottom = clip.bottom;
- gCanvasI.clipRect(canvas, &clipR);
-
- plugin->draw(canvas);
- gCanvasI.deleteCanvas(canvas);
-}
-
static void audioCallback(ANPAudioEvent evt, void* user, ANPAudioBuffer* buffer) {
switch (evt) {
case kMoreData_ANPAudioEvent: {
@@ -202,6 +188,20 @@ bool AudioPlugin::supportsDrawingModel(ANPDrawingModel model) {
return (model == kBitmap_ANPDrawingModel);
}
+void AudioPlugin::drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip) {
+ ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap);
+
+ ANPRectF clipR;
+ clipR.left = clip.left;
+ clipR.top = clip.top;
+ clipR.right = clip.right;
+ clipR.bottom = clip.bottom;
+ gCanvasI.clipRect(canvas, &clipR);
+
+ draw(canvas);
+ gCanvasI.deleteCanvas(canvas);
+}
+
void AudioPlugin::draw(ANPCanvas* canvas) {
NPP instance = this->inst();
PluginObject *obj = (PluginObject*) instance->pdata;
@@ -279,7 +279,7 @@ int16 AudioPlugin::handleEvent(const ANPEvent* evt) {
case kDraw_ANPEventType:
switch (evt->data.draw.model) {
case kBitmap_ANPDrawingModel:
- drawPlugin(this, evt->data.draw.data.bitmap, evt->data.draw.clip);
+ drawPlugin(evt->data.draw.data.bitmap, evt->data.draw.clip);
return 1;
default:
break; // unknown drawing model
diff --git a/samples/BrowserPlugin/jni/audio/AudioPlugin.h b/samples/BrowserPlugin/jni/audio/AudioPlugin.h
index 2291f0f27..129d33a78 100644
--- a/samples/BrowserPlugin/jni/audio/AudioPlugin.h
+++ b/samples/BrowserPlugin/jni/audio/AudioPlugin.h
@@ -42,9 +42,15 @@ public:
AudioPlugin(NPP inst);
virtual ~AudioPlugin();
virtual bool supportsDrawingModel(ANPDrawingModel);
- virtual void draw(ANPCanvas*);
virtual int16 handleEvent(const ANPEvent* evt);
private:
+ void draw(ANPCanvas*);
+ void drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip);
+
+ void handleTouch(int x, int y);
+ void invalActiveRect();
+ ANPPaint* getPaint(ANPRectF*);
+ ANPRectF* validTouch(int x, int y);
ANPRectF m_trackRect;
ANPRectF m_playRect;
@@ -63,13 +69,6 @@ private:
bool m_activeTouch;
ANPRectF* m_activeTouchRect;
ANPRectF* m_activeRect;
-
- ANPPaint* getPaint(ANPRectF*);
- ANPRectF* validTouch(int x, int y);
- void handleTouch(int x, int y);
- void invalActiveRect();
-
-
};
#endif // audioPlugin__DEFINED
diff --git a/samples/BrowserPlugin/jni/background/BackgroundPlugin.cpp b/samples/BrowserPlugin/jni/background/BackgroundPlugin.cpp
index 6e038f3b4..09f58cf75 100644
--- a/samples/BrowserPlugin/jni/background/BackgroundPlugin.cpp
+++ b/samples/BrowserPlugin/jni/background/BackgroundPlugin.cpp
@@ -77,6 +77,20 @@ bool BackgroundPlugin::supportsDrawingModel(ANPDrawingModel model) {
return (model == kBitmap_ANPDrawingModel);
}
+void BackgroundPlugin::drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip) {
+ ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap);
+
+ ANPRectF clipR;
+ clipR.left = clip.left;
+ clipR.top = clip.top;
+ clipR.right = clip.right;
+ clipR.bottom = clip.bottom;
+ gCanvasI.clipRect(canvas, &clipR);
+
+ draw(canvas);
+ gCanvasI.deleteCanvas(canvas);
+}
+
void BackgroundPlugin::draw(ANPCanvas* canvas) {
gCanvasI.drawColor(canvas, 0xFFFFFFFF);
@@ -89,21 +103,6 @@ void BackgroundPlugin::draw(ANPCanvas* canvas) {
gCanvasI.drawText(canvas, c, sizeof(c)-1, 10, -fm.fTop, m_paint);
}
-static void drawPlugin(SubPlugin* plugin, const ANPBitmap& bitmap, const ANPRectI& clip) {
-
- ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap);
-
- ANPRectF clipR;
- clipR.left = clip.left;
- clipR.top = clip.top;
- clipR.right = clip.right;
- clipR.bottom = clip.bottom;
- gCanvasI.clipRect(canvas, &clipR);
-
- plugin->draw(canvas);
- gCanvasI.deleteCanvas(canvas);
-}
-
int16 BackgroundPlugin::handleEvent(const ANPEvent* evt) {
NPP instance = this->inst();
@@ -112,7 +111,7 @@ int16 BackgroundPlugin::handleEvent(const ANPEvent* evt) {
switch (evt->data.draw.model) {
case kBitmap_ANPDrawingModel:
test_bitmap_transparency(evt);
- drawPlugin(this, evt->data.draw.data.bitmap, evt->data.draw.clip);
+ drawPlugin(evt->data.draw.data.bitmap, evt->data.draw.clip);
return 1;
default:
break; // unknown drawing model
diff --git a/samples/BrowserPlugin/jni/background/BackgroundPlugin.h b/samples/BrowserPlugin/jni/background/BackgroundPlugin.h
index a465f412c..8893c9dc8 100644
--- a/samples/BrowserPlugin/jni/background/BackgroundPlugin.h
+++ b/samples/BrowserPlugin/jni/background/BackgroundPlugin.h
@@ -33,7 +33,6 @@ public:
BackgroundPlugin(NPP inst);
virtual ~BackgroundPlugin();
virtual bool supportsDrawingModel(ANPDrawingModel);
- virtual void draw(ANPCanvas*);
virtual int16 handleEvent(const ANPEvent* evt);
// Timer Testing Variables
@@ -49,6 +48,8 @@ public:
bool mFinishedStageThree; // check opaque
private:
+ void draw(ANPCanvas*);
+ void drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip);
ANPPaint* m_paint;
diff --git a/samples/BrowserPlugin/jni/form/FormPlugin.cpp b/samples/BrowserPlugin/jni/form/FormPlugin.cpp
index 8e1fa7df5..fbb4c6b39 100644
--- a/samples/BrowserPlugin/jni/form/FormPlugin.cpp
+++ b/samples/BrowserPlugin/jni/form/FormPlugin.cpp
@@ -63,20 +63,6 @@ static void inval(NPP instance, const ANPRectF& r, bool doAA) {
browser->invalidaterect(instance, &inval);
}
-static void drawPlugin(SubPlugin* plugin, const ANPBitmap& bitmap, const ANPRectI& clip) {
- ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap);
-
- ANPRectF clipR;
- clipR.left = clip.left;
- clipR.top = clip.top;
- clipR.right = clip.right;
- clipR.bottom = clip.bottom;
- gCanvasI.clipRect(canvas, &clipR);
-
- plugin->draw(canvas);
- gCanvasI.deleteCanvas(canvas);
-}
-
///////////////////////////////////////////////////////////////////////////////
FormPlugin::FormPlugin(NPP inst) : SubPlugin(inst) {
@@ -128,6 +114,20 @@ bool FormPlugin::supportsDrawingModel(ANPDrawingModel model) {
return (model == kBitmap_ANPDrawingModel);
}
+void FormPlugin::drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip) {
+ ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap);
+
+ ANPRectF clipR;
+ clipR.left = clip.left;
+ clipR.top = clip.top;
+ clipR.right = clip.right;
+ clipR.bottom = clip.bottom;
+ gCanvasI.clipRect(canvas, &clipR);
+
+ draw(canvas);
+ gCanvasI.deleteCanvas(canvas);
+}
+
void FormPlugin::draw(ANPCanvas* canvas) {
NPP instance = this->inst();
PluginObject *obj = (PluginObject*) instance->pdata;
@@ -206,7 +206,7 @@ int16 FormPlugin::handleEvent(const ANPEvent* evt) {
case kDraw_ANPEventType:
switch (evt->data.draw.model) {
case kBitmap_ANPDrawingModel:
- drawPlugin(this, evt->data.draw.data.bitmap, evt->data.draw.clip);
+ drawPlugin(evt->data.draw.data.bitmap, evt->data.draw.clip);
return 1;
default:
break; // unknown drawing model
diff --git a/samples/BrowserPlugin/jni/form/FormPlugin.h b/samples/BrowserPlugin/jni/form/FormPlugin.h
index 1785c32e4..041ffb870 100644
--- a/samples/BrowserPlugin/jni/form/FormPlugin.h
+++ b/samples/BrowserPlugin/jni/form/FormPlugin.h
@@ -39,9 +39,10 @@ public:
FormPlugin(NPP inst);
virtual ~FormPlugin();
virtual bool supportsDrawingModel(ANPDrawingModel);
- virtual void draw(ANPCanvas*);
virtual int16 handleEvent(const ANPEvent* evt);
private:
+ void draw(ANPCanvas*);
+ void drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip);
bool m_hasFocus;
diff --git a/samples/BrowserPlugin/jni/main.cpp b/samples/BrowserPlugin/jni/main.cpp
index 5019e420c..7e7d04258 100644
--- a/samples/BrowserPlugin/jni/main.cpp
+++ b/samples/BrowserPlugin/jni/main.cpp
@@ -32,6 +32,7 @@
#include "AudioPlugin.h"
#include "BackgroundPlugin.h"
#include "FormPlugin.h"
+#include "SurfacePlugin.h"
#include "android_npapi.h"
NPNetscapeFuncs* browser;
@@ -68,6 +69,7 @@ ANPCanvasInterfaceV0 gCanvasI;
ANPLogInterfaceV0 gLogI;
ANPPaintInterfaceV0 gPaintI;
ANPPathInterfaceV0 gPathI;
+ANPSurfaceInterfaceV0 gSurfaceI;
ANPTypefaceInterfaceV0 gTypefaceI;
ANPWindowInterfaceV0 gWindowI;
@@ -107,14 +109,15 @@ NPError NP_Initialize(NPNetscapeFuncs* browserFuncs, NPPluginFuncs* pluginFuncs,
uint32_t size;
ANPInterface* i;
} gPairs[] = {
+ { kAudioTrackInterfaceV0_ANPGetValue, sizeof(gSoundI), &gSoundI },
{ kBitmapInterfaceV0_ANPGetValue, sizeof(gBitmapI), &gBitmapI },
{ kCanvasInterfaceV0_ANPGetValue, sizeof(gCanvasI), &gCanvasI },
{ kLogInterfaceV0_ANPGetValue, sizeof(gLogI), &gLogI },
{ kPaintInterfaceV0_ANPGetValue, sizeof(gPaintI), &gPaintI },
{ kPathInterfaceV0_ANPGetValue, sizeof(gPathI), &gPathI },
+ { kSurfaceInterfaceV0_ANPGetValue, sizeof(gSurfaceI), &gSurfaceI },
{ kTypefaceInterfaceV0_ANPGetValue, sizeof(gPaintI), &gTypefaceI },
- { kAudioTrackInterfaceV0_ANPGetValue, sizeof(gSoundI), &gSoundI },
- { kWindowInterfaceV0_ANPGetValue, sizeof(gWindowI), &gWindowI },
+ { kWindowInterfaceV0_ANPGetValue, sizeof(gWindowI), &gWindowI },
};
for (size_t i = 0; i < ARRAY_COUNT(gPairs); i++) {
gPairs[i].i->inSize = gPairs[i].size;
@@ -171,6 +174,10 @@ NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
obj->pluginType = kForm_PluginType;
obj->activePlugin = new FormPlugin(instance);
}
+ else if (!strcmp(argv[i], "RGBA_Surface")) {
+ obj->pluginType = kSurface_PluginType;
+ obj->activePlugin = new SurfacePlugin(instance, kRGBA_ANPSurfaceType);
+ }
gLogI.log(instance, kDebug_ANPLogType, "------ %p PluginType is %d", instance, obj->pluginType);
break;
}
@@ -190,8 +197,8 @@ NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
if (!strcmp(argv[i], "Bitmap")) {
model = kBitmap_ANPDrawingModel;
}
- else if (!strcmp(argv[i], "RasterSurface")) {
- // model = kRasterSurface_ANPDrawingModel;
+ else if (!strcmp(argv[i], "Surface")) {
+ model = kSurface_ANPDrawingModel;
}
gLogI.log(instance, kDebug_ANPLogType, "------ %p DrawingModel is %d", instance, model);
break;
diff --git a/samples/BrowserPlugin/jni/surface/SurfacePlugin.cpp b/samples/BrowserPlugin/jni/surface/SurfacePlugin.cpp
new file mode 100644
index 000000000..b3be90a63
--- /dev/null
+++ b/samples/BrowserPlugin/jni/surface/SurfacePlugin.cpp
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+
+#include "SurfacePlugin.h"
+
+#include <stdio.h>
+#include <sys/time.h>
+#include <time.h>
+#include <math.h>
+#include <string.h>
+
+extern NPNetscapeFuncs* browser;
+extern ANPLogInterfaceV0 gLogI;
+extern ANPPaintInterfaceV0 gPaintI;
+extern ANPSurfaceInterfaceV0 gSurfaceI;
+extern ANPTypefaceInterfaceV0 gTypefaceI;
+extern ANPWindowInterfaceV0 gWindowI;
+
+///////////////////////////////////////////////////////////////////////////////
+
+SurfacePlugin::SurfacePlugin(NPP inst, ANPSurfaceType surfaceType) : SubPlugin(inst) {
+
+ m_surface = gSurfaceI.newSurface(inst, surfaceType);
+
+ if(!m_surface)
+ gLogI.log(inst, kError_ANPLogType, "----%p Unable to create surface (%d)", inst, surfaceType);
+}
+
+SurfacePlugin::~SurfacePlugin() {
+ if (m_surface)
+ gSurfaceI.deleteSurface(m_surface);
+}
+
+bool SurfacePlugin::supportsDrawingModel(ANPDrawingModel model) {
+ return (model == kSurface_ANPDrawingModel);
+}
+
+void SurfacePlugin::draw() {
+ NPP instance = this->inst();
+ PluginObject *obj = (PluginObject*) instance->pdata;
+
+ ANPBitmap bitmap;
+
+ bool value = gSurfaceI.lock(m_surface, &bitmap, NULL);
+ gLogI.log(instance, kDebug_ANPLogType, "----%p locking: %b", instance, value);
+ gSurfaceI.unlock(m_surface);
+}
+
+int16 SurfacePlugin::handleEvent(const ANPEvent* evt) {
+ NPP instance = this->inst();
+
+ switch (evt->eventType) {
+ case kDraw_ANPEventType:
+ switch (evt->data.draw.model) {
+ case kSurface_ANPDrawingModel:
+ if (m_surface)
+ draw();
+ return 1;
+ default:
+ break; // unknown drawing model
+ }
+ default:
+ break;
+ }
+ return 0; // unknown or unhandled event
+}
diff --git a/samples/BrowserPlugin/jni/surface/SurfacePlugin.h b/samples/BrowserPlugin/jni/surface/SurfacePlugin.h
new file mode 100644
index 000000000..349f8b10f
--- /dev/null
+++ b/samples/BrowserPlugin/jni/surface/SurfacePlugin.h
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+#include "PluginObject.h"
+
+#ifndef surfacePlugin__DEFINED
+#define surfacePlugin__DEFINED
+
+class SurfacePlugin : public SubPlugin {
+public:
+ SurfacePlugin(NPP inst, ANPSurfaceType surfaceType);
+ virtual ~SurfacePlugin();
+ virtual bool supportsDrawingModel(ANPDrawingModel);
+ virtual int16 handleEvent(const ANPEvent* evt);
+private:
+ void draw();
+ ANPSurface* m_surface;
+
+};
+#endif // surfacePlugin__DEFINED