Merge change 7697
* changes:
Pretend to be root by intercepting getuid() in the simulator, so we don't have to litter the framework with if(Process.supportsProcesses()).
diff --git a/samples/BrowserPlugin/jni/Android.mk b/samples/BrowserPlugin/jni/Android.mk
index a5150ba..329a6fd 100644
--- a/samples/BrowserPlugin/jni/Android.mk
+++ b/samples/BrowserPlugin/jni/Android.mk
@@ -34,6 +34,7 @@
audio/AudioPlugin.cpp \
background/BackgroundPlugin.cpp \
form/FormPlugin.cpp \
+ surface/SurfacePlugin.cpp \
LOCAL_C_INCLUDES += \
$(LOCAL_PATH) \
@@ -41,6 +42,7 @@
$(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 dfda6b7..248a09b 100644
--- a/samples/BrowserPlugin/jni/PluginObject.h
+++ b/samples/BrowserPlugin/jni/PluginObject.h
@@ -40,7 +40,6 @@
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 @@
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 8516d04..9b26451 100644
--- a/samples/BrowserPlugin/jni/animation/AnimationPlugin.cpp
+++ b/samples/BrowserPlugin/jni/animation/AnimationPlugin.cpp
@@ -63,20 +63,6 @@
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 @@
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 @@
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 e47bec4..464f906 100644
--- a/samples/BrowserPlugin/jni/animation/AnimationPlugin.h
+++ b/samples/BrowserPlugin/jni/animation/AnimationPlugin.h
@@ -33,9 +33,12 @@
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 @@
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 621b8f8..58d340c 100644
--- a/samples/BrowserPlugin/jni/audio/AudioPlugin.cpp
+++ b/samples/BrowserPlugin/jni/audio/AudioPlugin.cpp
@@ -64,20 +64,6 @@
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 @@
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 @@
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 2291f0f..129d33a 100644
--- a/samples/BrowserPlugin/jni/audio/AudioPlugin.h
+++ b/samples/BrowserPlugin/jni/audio/AudioPlugin.h
@@ -42,9 +42,15 @@
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 @@
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 6e038f3..09f58cf 100644
--- a/samples/BrowserPlugin/jni/background/BackgroundPlugin.cpp
+++ b/samples/BrowserPlugin/jni/background/BackgroundPlugin.cpp
@@ -77,6 +77,20 @@
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 @@
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 @@
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 a465f41..8893c9d 100644
--- a/samples/BrowserPlugin/jni/background/BackgroundPlugin.h
+++ b/samples/BrowserPlugin/jni/background/BackgroundPlugin.h
@@ -33,7 +33,6 @@
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 @@
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 8e1fa7d..fbb4c6b 100644
--- a/samples/BrowserPlugin/jni/form/FormPlugin.cpp
+++ b/samples/BrowserPlugin/jni/form/FormPlugin.cpp
@@ -63,20 +63,6 @@
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 @@
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 @@
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 1785c32..041ffb8 100644
--- a/samples/BrowserPlugin/jni/form/FormPlugin.h
+++ b/samples/BrowserPlugin/jni/form/FormPlugin.h
@@ -39,9 +39,10 @@
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 5019e42..7e7d042 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 @@
ANPLogInterfaceV0 gLogI;
ANPPaintInterfaceV0 gPaintI;
ANPPathInterfaceV0 gPathI;
+ANPSurfaceInterfaceV0 gSurfaceI;
ANPTypefaceInterfaceV0 gTypefaceI;
ANPWindowInterfaceV0 gWindowI;
@@ -107,14 +109,15 @@
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 @@
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 @@
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 0000000..b3be90a
--- /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 0000000..349f8b1
--- /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
diff --git a/testrunner/android_manifest.py b/testrunner/android_manifest.py
new file mode 100644
index 0000000..7ede96c
--- /dev/null
+++ b/testrunner/android_manifest.py
@@ -0,0 +1,60 @@
+#!/usr/bin/python2.4
+#
+#
+# Copyright 2009, The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""In memory representation of AndroidManifest.xml file.
+
+Specification of AndroidManifest.xml can be found at
+http://developer.android.com/guide/topics/manifest/manifest-intro.html
+"""
+
+# python imports
+import xml.dom.minidom
+import xml.parsers
+
+
+class AndroidManifest(object):
+ """In memory representation of AndroidManifest.xml file."""
+
+ FILENAME = "AndroidManifest.xml"
+
+ def __init__(self, app_path=None):
+ if app_path:
+ self.ParseManifest(app_path)
+
+ def GetPackageName(self):
+ """Retrieve package name defined at <manifest package="...">.
+
+ Returns:
+ Package name if defined, otherwise None
+ """
+ manifests = self._dom.getElementsByTagName("manifest")
+ if not manifests or not manifests[0].getAttribute("package"):
+ return None
+ return manifests[0].getAttribute("package")
+
+ def ParseManifest(self, app_path):
+ """Parse AndroidManifest.xml at the specified path.
+
+ Args:
+ app_path: path to folder containing AndroidManifest.xml
+ Raises:
+ IOError: AndroidManifest.xml cannot be found at given path, or cannot be
+ opened for reading
+ """
+ self.app_path = app_path.rstrip("/")
+ self.manifest_path = "%s/%s" % (self.app_path, self.FILENAME)
+ self._dom = xml.dom.minidom.parse(self.manifest_path)
diff --git a/testrunner/android_mk.py b/testrunner/android_mk.py
new file mode 100644
index 0000000..663aa5c
--- /dev/null
+++ b/testrunner/android_mk.py
@@ -0,0 +1,96 @@
+#!/usr/bin/python2.4
+#
+#
+# Copyright 2009, The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""In memory representation of Android.mk file.
+
+Specifications for Android.mk can be found at
+development/ndk/docs/ANDROID-MK.txt
+"""
+
+import re
+from sets import Set
+
+
+class AndroidMK(object):
+ """In memory representation of Android.mk file."""
+
+ _RE_INCLUDE = re.compile(r'include\s+\$\((.+)\)')
+ _VAR_DELIMITER = ":="
+ FILENAME = "Android.mk"
+ CERTIFICATE = "LOCAL_CERTIFICATE"
+ PACKAGE_NAME = "LOCAL_PACKAGE_NAME"
+
+ def __init__(self, app_path=None):
+ self._includes = Set() # variables included in makefile
+ self._variables = {} # variables defined in makefile
+
+ if app_path:
+ self.ParseMK(app_path)
+
+ def _ProcessMKLine(self, line):
+ """Add a variable definition or include.
+
+ Ignores unrecognized lines.
+
+ Args:
+ line: line of text from makefile
+ """
+ m = self._RE_INCLUDE.match(line)
+ if m:
+ self._includes.add(m.group(1))
+ else:
+ parts = line.split(self._VAR_DELIMITER)
+ if len(parts) > 1:
+ self._variables[parts[0].strip()] = parts[1].strip()
+
+ def GetVariable(self, identifier):
+ """Retrieve makefile variable.
+
+ Args:
+ identifier: name of variable to retrieve
+ Returns:
+ value of specified identifier, None if identifier not found in makefile
+ """
+ # use dict.get(x) rather than dict[x] to avoid KeyError exception,
+ # so None is returned if identifier not found
+ return self._variables.get(identifier, None)
+
+ def HasInclude(self, identifier):
+ """Check variable is included in makefile.
+
+ Args:
+ identifer: name of variable to check
+ Returns:
+ True if identifer is included in makefile, otherwise False
+ """
+ return identifier in self._includes
+
+ def ParseMK(self, app_path):
+ """Parse Android.mk at the specified path.
+
+ Args:
+ app_path: path to folder containing Android.mk
+ Raises:
+ IOError: Android.mk cannot be found at given path, or cannot be opened
+ for reading
+ """
+ self.app_path = app_path.rstrip("/")
+ self.mk_path = "%s/%s" % (self.app_path, self.FILENAME)
+ mk = open(self.mk_path)
+ for line in mk:
+ self._ProcessMKLine(line)
+ mk.close()
diff --git a/testrunner/create_test.py b/testrunner/create_test.py
new file mode 100755
index 0000000..2fc3a3c
--- /dev/null
+++ b/testrunner/create_test.py
@@ -0,0 +1,245 @@
+#!/usr/bin/python2.4
+#
+#
+# Copyright 2009, The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Utility to create Android project files for tests."""
+
+# python imports
+import datetime
+import optparse
+import os
+import string
+import sys
+
+# local imports
+import android_mk
+import android_manifest
+
+
+class TestsConsts(object):
+ """Constants for test Android.mk and AndroidManifest.xml creation."""
+
+ MK_BUILD_INCLUDE = "call all-makefiles-under,$(LOCAL_PATH)"
+ MK_BUILD_STRING = "\ninclude $(%s)\n" % MK_BUILD_INCLUDE
+ TEST_MANIFEST_TEMPLATE = """<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) $YEAR The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="$PACKAGE_NAME.tests">
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="$PACKAGE_NAME"
+ android:label="Tests for $MODULE_NAME">
+ </instrumentation>
+</manifest>
+"""
+ TEST_MK_TEMPLATE = """LOCAL_PATH := $$(call my-dir)
+include $$(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
+LOCAL_SRC_FILES := $$(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := ${MODULE_NAME}Tests${CERTIFICATE}
+
+LOCAL_INSTRUMENTATION_FOR := ${MODULE_NAME}
+
+LOCAL_SDK_VERSION := current
+
+include $$(BUILD_PACKAGE)
+"""
+ TESTS_FOLDER = "tests"
+
+
+def _GenerateTestManifest(manifest, module_name, mapping=None):
+ """Create and populate tests/AndroidManifest.xml with variable values from
+ Android.mk and AndroidManifest.xml.
+
+ Does nothing if tests/AndroidManifest.xml already exists.
+
+ Args:
+ manifest: AndroidManifest object for application manifest
+ module_name: module name used for labelling
+ mapping: optional user defined mapping of variable values, replaces values
+ extracted from AndroidManifest.xml
+ Raises:
+ IOError: tests/AndroidManifest.xml cannot be opened for writing
+ """
+ # skip if file already exists
+ tests_path = "%s/%s" % (manifest.app_path, TestsConsts.TESTS_FOLDER)
+ tests_manifest_path = "%s/%s" % (tests_path, manifest.FILENAME)
+ if os.path.exists(tests_manifest_path):
+ _PrintMessage("%s already exists, not overwritten" % tests_manifest_path)
+ return
+
+ if not mapping:
+ package_name = manifest.GetPackageName()
+ mapping = {"PACKAGE_NAME":package_name, "MODULE_NAME":module_name,
+ "YEAR":datetime.date.today().year}
+ output = string.Template(TestsConsts.TEST_MANIFEST_TEMPLATE).substitute(mapping)
+
+ # create tests folder if not existent
+ if not os.path.exists(tests_path):
+ os.mkdir(tests_path)
+
+ # write tests/AndroidManifest.xml
+ tests_manifest = open(tests_manifest_path, mode="w")
+ tests_manifest.write(output)
+ tests_manifest.close()
+ _PrintMessage("Created %s" % tests_manifest_path)
+
+
+def _GenerateTestMK(mk, mapping=None):
+ """Create and populate tests/Android.mk with variable values from Android.mk.
+
+ Does nothing if tests/Android.mk already exists.
+
+ Args:
+ mk: AndroidMK object for application makefile
+ mapping: optional user defined mapping of variable values, replaces
+ values stored in mk
+ Raises:
+ IOError: tests/Android.mk cannot be opened for writing
+ """
+ # skip if file already exists
+ tests_path = "%s/%s" % (mk.app_path, TestsConsts.TESTS_FOLDER)
+ tests_mk_path = "%s/%s" % (tests_path, mk.FILENAME)
+ if os.path.exists(tests_mk_path):
+ _PrintMessage("%s already exists, not overwritten" % tests_mk_path)
+ return
+
+ # append test build if not existent in makefile
+ if not mk.HasInclude(TestsConsts.MK_BUILD_INCLUDE):
+ mk_path = "%s/%s" % (mk.app_path, mk.FILENAME)
+ mk_file = open(mk_path, mode="a")
+ mk_file.write(TestsConsts.MK_BUILD_STRING)
+ mk_file.close()
+
+ # construct tests/Android.mk
+ # include certificate definition if existent in makefile
+ certificate = mk.GetVariable(mk.CERTIFICATE)
+ if certificate:
+ cert_definition = ("\n%s := %s" % (mk.CERTIFICATE, certificate))
+ else:
+ cert_definition = ""
+ if not mapping:
+ module_name = mk.GetVariable(mk.PACKAGE_NAME)
+ mapping = {"MODULE_NAME":module_name, "CERTIFICATE":cert_definition}
+ output = string.Template(TestsConsts.TEST_MK_TEMPLATE).substitute(mapping)
+
+ # create tests folder if not existent
+ if not os.path.exists(tests_path):
+ os.mkdir(tests_path)
+
+ # write tests/Android.mk to disk
+ tests_mk = open(tests_mk_path, mode="w")
+ tests_mk.write(output)
+ tests_mk.close()
+ _PrintMessage("Created %s" % tests_mk_path)
+
+
+def _ParseArgs(argv):
+ """Parse the command line arguments.
+
+ Args:
+ argv: the list of command line arguments
+ Returns:
+ a tuple of options and individual command line arguments.
+ """
+ parser = optparse.OptionParser(usage="%s <app_path>" % sys.argv[0])
+ options, args = parser.parse_args(argv)
+ if len(args) < 1:
+ _PrintError("Error: Incorrect syntax")
+ parser.print_usage()
+ sys.exit()
+ return (options, args)
+
+
+def _PrintMessage(msg):
+ print >> sys.stdout, msg
+
+
+def _PrintError(msg):
+ print >> sys.stderr, msg
+
+
+def _ValidateInputFiles(mk, manifest):
+ """Verify that required variables are defined in input files.
+
+ Args:
+ mk: AndroidMK object for application makefile
+ manifest: AndroidManifest object for application manifest
+ Raises:
+ RuntimeError: mk does not define LOCAL_PACKAGE_NAME or
+ manifest does not define package variable
+ """
+ module_name = mk.GetVariable(mk.PACKAGE_NAME)
+ if not module_name:
+ raise RuntimeError("Variable %s missing from %s" %
+ (mk.PACKAGE_NAME, mk.FILENAME))
+
+ package_name = manifest.GetPackageName()
+ if not package_name:
+ raise RuntimeError("Variable package missing from %s" % manifest.FILENAME)
+
+
+def main(argv):
+ options, args = _ParseArgs(argv)
+ app_path = args[0];
+
+ if not os.path.exists(app_path):
+ _PrintError("Error: Application path %s not found" % app_path)
+ sys.exit()
+
+ try:
+ mk = android_mk.AndroidMK(app_path=app_path)
+ manifest = android_manifest.AndroidManifest(app_path=app_path)
+ _ValidateInputFiles(mk, manifest)
+
+ module_name = mk.GetVariable(mk.PACKAGE_NAME)
+ _GenerateTestMK(mk)
+ _GenerateTestManifest(manifest, module_name)
+ except Exception, e:
+ _PrintError("Error: %s" % e)
+ _PrintError("Error encountered, script aborted")
+ sys.exit()
+
+ src_path = app_path + "/tests/src"
+ if not os.path.exists(src_path):
+ os.mkdir(src_path)
+
+
+if __name__ == "__main__":
+ main(sys.argv[1:])