| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "webkit/tools/pepper_test_plugin/plugin_object.h" | 26 #include "webkit/tools/pepper_test_plugin/plugin_object.h" |
| 27 | 27 |
| 28 #include <stdio.h> | 28 #include <stdio.h> |
| 29 #include <string> | 29 #include <string> |
| 30 | 30 |
| 31 #include "base/logging.h" | 31 #include "base/logging.h" |
| 32 #include "gpu/command_buffer/client/gles2_lib.h" |
| 33 #include "gpu/command_buffer/client/gles2_demo_cc.h" |
| 32 #include "third_party/skia/include/core/SkBitmap.h" | 34 #include "third_party/skia/include/core/SkBitmap.h" |
| 33 #include "third_party/skia/include/core/SkCanvas.h" | 35 #include "third_party/skia/include/core/SkCanvas.h" |
| 34 #include "third_party/skia/include/effects/SkGradientShader.h" | 36 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 35 #include "webkit/tools/pepper_test_plugin/event_handler.h" | 37 #include "webkit/tools/pepper_test_plugin/event_handler.h" |
| 36 #include "webkit/tools/pepper_test_plugin/test_object.h" | 38 #include "webkit/tools/pepper_test_plugin/test_object.h" |
| 37 | 39 |
| 38 NPNetscapeFuncs* browser; | 40 NPNetscapeFuncs* browser; |
| 39 | 41 |
| 40 namespace { | 42 namespace { |
| 41 | 43 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 242 |
| 241 } // namespace | 243 } // namespace |
| 242 | 244 |
| 243 | 245 |
| 244 // PluginObject ---------------------------------------------------------------- | 246 // PluginObject ---------------------------------------------------------------- |
| 245 | 247 |
| 246 PluginObject::PluginObject(NPP npp) | 248 PluginObject::PluginObject(NPP npp) |
| 247 : npp_(npp), | 249 : npp_(npp), |
| 248 test_object_(browser->createobject(npp, GetTestClass())), | 250 test_object_(browser->createobject(npp, GetTestClass())), |
| 249 device2d_(NULL) { | 251 device2d_(NULL) { |
| 250 if (!extensions) { | |
| 251 browser->getvalue(npp_, NPNVPepperExtensions, | |
| 252 reinterpret_cast<void*>(&extensions)); | |
| 253 CHECK(extensions); | |
| 254 } | |
| 255 device2d_ = extensions->acquireDevice(npp, NPPepper2DDevice); | |
| 256 CHECK(device2d_); | |
| 257 } | 252 } |
| 258 | 253 |
| 259 PluginObject::~PluginObject() { | 254 PluginObject::~PluginObject() { |
| 260 // FIXME(brettw) destroy the context. | 255 // FIXME(brettw) destroy the context. |
| 261 browser->releaseobject(test_object_); | 256 browser->releaseobject(test_object_); |
| 262 } | 257 } |
| 263 | 258 |
| 264 // static | 259 // static |
| 265 NPClass* PluginObject::GetPluginClass() { | 260 NPClass* PluginObject::GetPluginClass() { |
| 266 return &plugin_class; | 261 return &plugin_class; |
| 267 } | 262 } |
| 268 | 263 |
| 264 namespace { |
| 265 void Draw3DCallback(void* data) { |
| 266 static_cast<PluginObject*>(data)->Draw3D(); |
| 267 } |
| 268 } |
| 269 |
| 270 void PluginObject::New(NPMIMEType pluginType, |
| 271 int16 argc, |
| 272 char* argn[], |
| 273 char* argv[]) { |
| 274 // Default to 2D rendering. |
| 275 dimensions_ = 2; |
| 276 |
| 277 for (int i = 0; i < argc; ++i) { |
| 278 if (strcmp(argn[i], "dimensions") == 0) |
| 279 dimensions_ = atoi(argv[i]); |
| 280 } |
| 281 |
| 282 if (!extensions) { |
| 283 browser->getvalue(npp_, NPNVPepperExtensions, |
| 284 reinterpret_cast<void*>(&extensions)); |
| 285 CHECK(extensions); |
| 286 } |
| 287 device2d_ = extensions->acquireDevice(npp_, NPPepper2DDevice); |
| 288 CHECK(device2d_); |
| 289 } |
| 290 |
| 269 void PluginObject::SetWindow(const NPWindow& window) { | 291 void PluginObject::SetWindow(const NPWindow& window) { |
| 270 size_.set_width(window.width); | 292 if (dimensions_ == 2) { |
| 271 size_.set_height(window.height); | 293 size_.set_width(window.width); |
| 294 size_.set_height(window.height); |
| 272 | 295 |
| 273 NPDeviceContext2DConfig config; | 296 NPDeviceContext2DConfig config; |
| 274 NPDeviceContext2D context; | 297 NPDeviceContext2D context; |
| 275 device2d_->initializeContext(npp_, &config, &context); | 298 device2d_->initializeContext(npp_, &config, &context); |
| 276 | 299 |
| 277 SkBitmap bitmap; | 300 SkBitmap bitmap; |
| 278 bitmap.setConfig(SkBitmap::kARGB_8888_Config, window.width, window.height); | 301 bitmap.setConfig(SkBitmap::kARGB_8888_Config, window.width, window.height); |
| 279 bitmap.setPixels(context.region); | 302 bitmap.setPixels(context.region); |
| 280 | 303 |
| 281 SkCanvas canvas(bitmap); | 304 SkCanvas canvas(bitmap); |
| 282 DrawSampleBitmap(canvas, window.width, window.height); | 305 DrawSampleBitmap(canvas, window.width, window.height); |
| 283 | 306 |
| 284 // TODO(brettw) figure out why this cast is necessary, the functions seem to | 307 // TODO(brettw) figure out why this cast is necessary, the functions seem to |
| 285 // match. Could be a calling convention mismatch? | 308 // match. Could be a calling convention mismatch? |
| 286 NPDeviceFlushContextCallbackPtr callback = | 309 NPDeviceFlushContextCallbackPtr callback = |
| 287 reinterpret_cast<NPDeviceFlushContextCallbackPtr>(&FlushCallback); | 310 reinterpret_cast<NPDeviceFlushContextCallbackPtr>(&FlushCallback); |
| 288 device2d_->flushContext(npp_, &context, callback, NULL); | 311 device2d_->flushContext(npp_, &context, callback, NULL); |
| 312 } else { |
| 313 if (!command_buffer_.get()) { |
| 314 if (!InitializeCommandBuffer()) |
| 315 return; |
| 316 } |
| 317 |
| 318 gles2_implementation_->Viewport(0, 0, window.width, window.height); |
| 319 |
| 320 // Schedule the first call to Draw. |
| 321 browser->pluginthreadasynccall(npp_, Draw3DCallback, this); |
| 322 } |
| 289 } | 323 } |
| 324 |
| 325 void PluginObject::Draw3D() { |
| 326 // Render some stuff. |
| 327 gles2::g_gl_impl = gles2_implementation_.get(); |
| 328 GLFromCPPTestFunction(); |
| 329 gles2::GetGLContext()->SwapBuffers(); |
| 330 helper_->Flush(); |
| 331 gles2::g_gl_impl = NULL; |
| 332 |
| 333 // Schedule another call to Draw. |
| 334 browser->pluginthreadasynccall(npp_, Draw3DCallback, this); |
| 335 } |
| 336 |
| 337 bool PluginObject::InitializeCommandBuffer() { |
| 338 const static int32 kCommandBufferSize = 512 * 1024; |
| 339 command_buffer_.reset(new CommandBufferPepper(npp_, browser)); |
| 340 if (command_buffer_->Initialize(kCommandBufferSize)) { |
| 341 helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); |
| 342 if (helper_->Initialize()) { |
| 343 |
| 344 const int32 kTransferBufferSize = 512 * 1024; |
| 345 int32 transfer_buffer_id = |
| 346 command_buffer_->CreateTransferBuffer(kTransferBufferSize); |
| 347 gpu::Buffer transfer_buffer = |
| 348 command_buffer_->GetTransferBuffer(transfer_buffer_id); |
| 349 if (transfer_buffer.ptr) { |
| 350 gles2_implementation_.reset(new gpu::gles2::GLES2Implementation( |
| 351 helper_.get(), |
| 352 transfer_buffer.size, |
| 353 transfer_buffer.ptr, |
| 354 transfer_buffer_id)); |
| 355 return true; |
| 356 } |
| 357 } |
| 358 |
| 359 helper_.reset(); |
| 360 } |
| 361 |
| 362 command_buffer_.reset(); |
| 363 |
| 364 return false; |
| 365 } |
| OLD | NEW |