summaryrefslogtreecommitdiffstats
path: root/tests/BrowserTestPlugin/jni
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2009-09-08 18:31:40 -0400
committerDerek Sollenberger <djsollen@google.com>2009-09-15 19:33:54 -0400
commit0b3a5d65247be1fb79d66af534fa78a94743864f (patch)
tree4528b972912c47ee3c8f3161a9b9ba32134b3a74 /tests/BrowserTestPlugin/jni
parentd1d6778247d4b3798f9b9fafca4312a348826a0b (diff)
downloadframeworks_base-0b3a5d65247be1fb79d66af534fa78a94743864f.zip
frameworks_base-0b3a5d65247be1fb79d66af534fa78a94743864f.tar.gz
frameworks_base-0b3a5d65247be1fb79d66af534fa78a94743864f.tar.bz2
First pass at replacing native plugin views with java.
Change-Id: I6d1f45f31210c2353fa348cc37be8d91bcd5e887
Diffstat (limited to 'tests/BrowserTestPlugin/jni')
-rw-r--r--tests/BrowserTestPlugin/jni/event/EventPlugin.cpp66
-rw-r--r--tests/BrowserTestPlugin/jni/event/EventPlugin.h5
-rw-r--r--tests/BrowserTestPlugin/jni/main.cpp9
3 files changed, 27 insertions, 53 deletions
diff --git a/tests/BrowserTestPlugin/jni/event/EventPlugin.cpp b/tests/BrowserTestPlugin/jni/event/EventPlugin.cpp
index 1263204..706c27e 100644
--- a/tests/BrowserTestPlugin/jni/event/EventPlugin.cpp
+++ b/tests/BrowserTestPlugin/jni/event/EventPlugin.cpp
@@ -36,27 +36,18 @@ extern NPNetscapeFuncs* browser;
extern ANPCanvasInterfaceV0 gCanvasI;
extern ANPLogInterfaceV0 gLogI;
extern ANPPaintInterfaceV0 gPaintI;
-extern ANPSurfaceInterfaceV0 gSurfaceI;
extern ANPTypefaceInterfaceV0 gTypefaceI;
///////////////////////////////////////////////////////////////////////////////
-EventPlugin::EventPlugin(NPP inst) : SubPlugin(inst) {
+EventPlugin::EventPlugin(NPP inst) : SubPlugin(inst) { }
- // initialize the drawing surface
- m_surfaceReady = false;
- m_surface = gSurfaceI.newRasterSurface(inst, kRGB_565_ANPBitmapFormat, false);
- if(!m_surface)
- gLogI.log(inst, kError_ANPLogType, "----%p Unable to create Raster surface", inst);
-}
-
-EventPlugin::~EventPlugin() {
- gSurfaceI.deleteSurface(m_surface);
-}
+EventPlugin::~EventPlugin() { }
-void EventPlugin::drawPlugin(int surfaceWidth, int surfaceHeight) {
+void EventPlugin::drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip) {
- gLogI.log(inst(), kDebug_ANPLogType, " ------ %p drawing the plugin (%d,%d)", inst(), surfaceWidth, surfaceHeight);
+ gLogI.log(inst(), kDebug_ANPLogType, " ------ %p drawing the plugin (%d,%d)",
+ inst(), bitmap.width, bitmap.height);
// get the plugin's dimensions according to the DOM
PluginObject *obj = (PluginObject*) inst()->pdata;
@@ -64,8 +55,8 @@ void EventPlugin::drawPlugin(int surfaceWidth, int surfaceHeight) {
const int H = obj->window->height;
// compute the current zoom level
- const float zoomFactorW = static_cast<float>(surfaceWidth) / W;
- const float zoomFactorH = static_cast<float>(surfaceHeight) / H;
+ const float zoomFactorW = static_cast<float>(bitmap.width) / W;
+ const float zoomFactorH = static_cast<float>(bitmap.height) / H;
// check to make sure the zoom level is uniform
if (zoomFactorW + .01 < zoomFactorH && zoomFactorW - .01 > zoomFactorH)
@@ -76,15 +67,16 @@ void EventPlugin::drawPlugin(int surfaceWidth, int surfaceHeight) {
const int fontSize = (int)(zoomFactorW * 16);
const int leftMargin = (int)(zoomFactorW * 10);
- // lock the surface
- ANPBitmap bitmap;
- if (!m_surfaceReady || !gSurfaceI.lock(m_surface, &bitmap, NULL)) {
- gLogI.log(inst(), kError_ANPLogType, " ------ %p unable to lock the plugin", inst());
- return;
- }
-
- // create a canvas
+ // create and clip a canvas
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);
+
gCanvasI.drawColor(canvas, 0xFFFFFFFF);
// configure the paint
@@ -106,10 +98,9 @@ void EventPlugin::drawPlugin(int surfaceWidth, int surfaceHeight) {
const char c[] = "Browser Test Plugin";
gCanvasI.drawText(canvas, c, sizeof(c)-1, leftMargin, -fm.fTop, paint);
- // clean up variables and unlock the surface
+ // clean up variables
gPaintI.deletePaint(paint);
gCanvasI.deleteCanvas(canvas);
- gSurfaceI.unlock(m_surface);
}
void EventPlugin::printToDiv(const char* text, int length) {
@@ -149,23 +140,16 @@ void EventPlugin::printToDiv(const char* text, int length) {
int16 EventPlugin::handleEvent(const ANPEvent* evt) {
switch (evt->eventType) {
- case kDraw_ANPEventType:
- gLogI.log(inst(), kError_ANPLogType, " ------ %p the plugin did not request draw events", inst());
- break;
- case kSurface_ANPEventType:
- switch (evt->data.surface.action) {
- case kCreated_ANPSurfaceAction:
- m_surfaceReady = true;
- return 1;
- case kDestroyed_ANPSurfaceAction:
- m_surfaceReady = false;
- return 1;
- case kChanged_ANPSurfaceAction:
- drawPlugin(evt->data.surface.data.changed.width,
- evt->data.surface.data.changed.height);
+
+ case kDraw_ANPEventType: {
+ switch (evt->data.draw.model) {
+ case kBitmap_ANPDrawingModel:
+ drawPlugin(evt->data.draw.data.bitmap, evt->data.draw.clip);
return 1;
+ default:
+ break; // unknown drawing model
}
- break;
+ }
case kLifecycle_ANPEventType:
switch (evt->data.lifecycle.action) {
case kOnLoad_ANPLifecycleAction: {
diff --git a/tests/BrowserTestPlugin/jni/event/EventPlugin.h b/tests/BrowserTestPlugin/jni/event/EventPlugin.h
index 73dd6ea..88b7c9d 100644
--- a/tests/BrowserTestPlugin/jni/event/EventPlugin.h
+++ b/tests/BrowserTestPlugin/jni/event/EventPlugin.h
@@ -35,11 +35,8 @@ public:
virtual int16 handleEvent(const ANPEvent* evt);
private:
- void drawPlugin(int surfaceWidth, int surfaceHeight);
+ void drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip);
void printToDiv(const char* text, int length);
-
- bool m_surfaceReady;
- ANPSurface* m_surface;
};
#endif // eventPlugin__DEFINED
diff --git a/tests/BrowserTestPlugin/jni/main.cpp b/tests/BrowserTestPlugin/jni/main.cpp
index 056ec4d..e3ad4a7 100644
--- a/tests/BrowserTestPlugin/jni/main.cpp
+++ b/tests/BrowserTestPlugin/jni/main.cpp
@@ -65,7 +65,6 @@ ANPCanvasInterfaceV0 gCanvasI;
ANPLogInterfaceV0 gLogI;
ANPPaintInterfaceV0 gPaintI;
ANPPathInterfaceV0 gPathI;
-ANPSurfaceInterfaceV0 gSurfaceI;
ANPSystemInterfaceV0 gSystemI;
ANPTypefaceInterfaceV0 gTypefaceI;
ANPWindowInterfaceV0 gWindowI;
@@ -105,16 +104,10 @@ 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 },
- { kSystemInterfaceV0_ANPGetValue, sizeof(gSystemI), &gSystemI },
{ kTypefaceInterfaceV0_ANPGetValue, sizeof(gTypefaceI), &gTypefaceI },
- { kWindowInterfaceV0_ANPGetValue, sizeof(gWindowI), &gWindowI },
};
for (size_t i = 0; i < ARRAY_COUNT(gPairs); i++) {
gPairs[i].i->inSize = gPairs[i].size;
@@ -156,7 +149,7 @@ NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
}
// select the drawing model
- ANPDrawingModel model = kSurface_ANPDrawingModel;
+ ANPDrawingModel model = kBitmap_ANPDrawingModel;
// notify the plugin API of the drawing model we wish to use. This must be
// done prior to creating certain subPlugin objects (e.g. surfaceViews)