Merge change 7521

* changes:
  Adding support for surface views. also removed subplugin's dependency on ANPCanvas.
This commit is contained in:
Android (Google) Code Review
2009-07-17 06:29:23 -07:00
13 changed files with 220 additions and 79 deletions

View File

@@ -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 \

View File

@@ -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;

View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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
}

View File

@@ -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