diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-23 16:20:16 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-23 16:20:16 +0000 |
commit | add8582104c3bb4849c9855553a194f4c506a720 (patch) | |
tree | 8a4ab583b88d49c2573f6d48efbd626d681d52b9 /webkit/tools/pepper_test_plugin | |
parent | 558833a430fd4b8cb2ab88d1bc4bdc580cbc11aa (diff) | |
download | chromium_src-add8582104c3bb4849c9855553a194f4c506a720.zip chromium_src-add8582104c3bb4849c9855553a194f4c506a720.tar.gz chromium_src-add8582104c3bb4849c9855553a194f4c506a720.tar.bz2 |
Make the test plugin draw an antialiased green circle with a gradient so we
can see it's working.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/293053
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29898 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/tools/pepper_test_plugin')
-rw-r--r-- | webkit/tools/pepper_test_plugin/main.cc | 31 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/plugin_object.cc | 67 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/plugin_object.h | 5 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/test_page.html | 4 |
4 files changed, 79 insertions, 28 deletions
diff --git a/webkit/tools/pepper_test_plugin/main.cc b/webkit/tools/pepper_test_plugin/main.cc index 3b3819f..2bb514d 100644 --- a/webkit/tools/pepper_test_plugin/main.cc +++ b/webkit/tools/pepper_test_plugin/main.cc @@ -93,12 +93,6 @@ void Log(NPP instance, const char* format, ...) { browser->releaseobject(window_object); } -NPInitializeRenderContextPtr initialize_render_context = NULL; -NPFlushRenderContextPtr flush_render_context = NULL; - -void FlushCallback(NPRenderContext* context, void* user_data) { -} - } // namespace // Plugin entry points @@ -171,34 +165,12 @@ NPError NPP_New(NPMIMEType pluginType, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved) { - if (!initialize_render_context) { - browser->getvalue(instance, NPNVInitializeRenderContextFunc, - reinterpret_cast<void*>(&initialize_render_context)); - CHECK(initialize_render_context); - } - if (!flush_render_context) { - browser->getvalue(instance, NPNVFlushRenderContextFunc, - reinterpret_cast<void*>(&flush_render_context)); - CHECK(flush_render_context); - } - if (browser->version >= 14) { PluginObject* obj = reinterpret_cast<PluginObject*>( browser->createobject(instance, PluginObject::GetPluginClass())); instance->pdata = obj; } - // On Windows and Unix, plugins only get events if they are windowless. - browser->setvalue(instance, NPPVpluginWindowBool, NULL); - - /* TODO(brettw) fill this out. It needs to be moved somewhere else until after the plugin has been initialized. - NPRenderContext context; - initialize_render_context(instance, NPRenderGraphicsRGBA, &context); - memset(context.u.graphicsRgba.region, 0x80, 1000); - - NPFlushRenderContextCallbackPtr asdf = (NPFlushRenderContextCallbackPtr)&FlushCallback; - flush_render_context(instance, &context, asdf, NULL); - */ return NPERR_NO_ERROR; } @@ -212,6 +184,9 @@ NPError NPP_Destroy(NPP instance, NPSavedData** save) { } NPError NPP_SetWindow(NPP instance, NPWindow* window) { + PluginObject* obj = static_cast<PluginObject*>(instance->pdata); + if (obj) + obj->SetWindow(*window); return NPERR_NO_ERROR; } diff --git a/webkit/tools/pepper_test_plugin/plugin_object.cc b/webkit/tools/pepper_test_plugin/plugin_object.cc index 8b52378..90908d0 100644 --- a/webkit/tools/pepper_test_plugin/plugin_object.cc +++ b/webkit/tools/pepper_test_plugin/plugin_object.cc @@ -28,6 +28,9 @@ #include <string> #include "base/logging.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "third_party/skia/include/core/SkCanvas.h" +#include "third_party/skia/include/effects/SkGradientShader.h" #include "webkit/tools/pepper_test_plugin/test_object.h" NPNetscapeFuncs* browser; @@ -194,13 +197,56 @@ NPClass plugin_class = { PluginSetProperty, }; +// Bitmap painting ------------------------------------------------------------- + +void DrawSampleBitmap(SkCanvas& canvas, int width, int height) { + SkRect rect; + rect.set(SkIntToScalar(0), SkIntToScalar(0), + SkIntToScalar(width), SkIntToScalar(height)); + SkPath path; + path.addOval(rect); + + // Create a gradient shader going from opaque green to transparent. + SkPaint paint; + paint.setAntiAlias(true); + + SkColor grad_colors[2]; + grad_colors[0] = SkColorSetARGB(0xFF, 0x00, 0xFF, 0x00); + grad_colors[1] = SkColorSetARGB(0x00, 0x00, 0xFF, 0x00); + SkPoint grad_points[2]; + grad_points[0].set(SkIntToScalar(0), SkIntToScalar(0)); + grad_points[1].set(SkIntToScalar(0), SkIntToScalar(height)); + paint.setShader(SkGradientShader::CreateLinear( + grad_points, grad_colors, NULL, 2, SkShader::kRepeat_TileMode)) + ->safeUnref(); + + canvas.drawPath(path, paint); +} + +NPInitializeRenderContextPtr initialize_render_context = NULL; +NPFlushRenderContextPtr flush_render_context = NULL; + +void FlushCallback(NPRenderContext* context, void* user_data) { +} + } // namespace + // PluginObject ---------------------------------------------------------------- PluginObject::PluginObject(NPP npp) : npp_(npp), test_object_(browser->createobject(npp, GetTestClass())) { + if (!initialize_render_context) { + browser->getvalue(npp_, NPNVInitializeRenderContextFunc, + reinterpret_cast<void*>(&initialize_render_context)); + CHECK(initialize_render_context); + } + if (!flush_render_context) { + browser->getvalue(npp_, NPNVFlushRenderContextFunc, + reinterpret_cast<void*>(&flush_render_context)); + CHECK(flush_render_context); + } } PluginObject::~PluginObject() { @@ -211,3 +257,24 @@ PluginObject::~PluginObject() { NPClass* PluginObject::GetPluginClass() { return &plugin_class; } + +void PluginObject::SetWindow(const NPWindow& window) { + size_.set_width(window.width); + size_.set_height(window.height); + + NPRenderContext context; + initialize_render_context(npp_, NPRenderGraphicsRGBA, &context); + + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, window.width, window.height); + bitmap.setPixels(context.u.graphicsRgba.region); + + SkCanvas canvas(bitmap); + DrawSampleBitmap(canvas, window.width, window.height); + + // TODO(brettw) figure out why this cast is necessary, the functions seem to + // match. Could be a calling convention mismatch? + NPFlushRenderContextCallbackPtr callback = + reinterpret_cast<NPFlushRenderContextCallbackPtr>(&FlushCallback); + flush_render_context(npp_, &context, callback, NULL); +} diff --git a/webkit/tools/pepper_test_plugin/plugin_object.h b/webkit/tools/pepper_test_plugin/plugin_object.h index 525870f..a45bdc4 100644 --- a/webkit/tools/pepper_test_plugin/plugin_object.h +++ b/webkit/tools/pepper_test_plugin/plugin_object.h @@ -27,6 +27,7 @@ #define WEBKIT_TOOLS_PEPPER_TEST_PLUGIN_PLUGIN_OBJECT_H_ #include "base/basictypes.h" +#include "base/gfx/size.h" #include "webkit/glue/plugins/nphostapi.h" extern NPNetscapeFuncs* browser; @@ -41,11 +42,15 @@ class PluginObject { NPObject* header() { return &header_; } NPP npp() const { return npp_; } + void SetWindow(const NPWindow& window); + private: NPObject header_; NPP npp_; NPObject* test_object_; + gfx::Size size_; + DISALLOW_COPY_AND_ASSIGN(PluginObject); }; diff --git a/webkit/tools/pepper_test_plugin/test_page.html b/webkit/tools/pepper_test_plugin/test_page.html index 734bd16..f76b09d 100644 --- a/webkit/tools/pepper_test_plugin/test_page.html +++ b/webkit/tools/pepper_test_plugin/test_page.html @@ -1,3 +1,7 @@ +<body style="background-image:url(http://www.google.com/intl/en_ALL/images/logo.gif); background-repeat:repeat;"> + This page embeds a file declared as the pepper test plugins MIME type so that it will get loaded for testing. <p> <embed type="pepper-application/x-pepper-test-plugin" width="400" height="400"/> + +</body> |