| 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 #include <cmath> | 28 #include <cmath> |
| 29 #include <limits> | 29 #include <limits> |
| 30 #include <stdio.h> | 30 #include <stdio.h> |
| 31 #include <string> | 31 #include <string> |
| 32 | 32 |
| 33 #if defined(INDEPENDENT_PLUGIN) | 33 #if defined(INDEPENDENT_PLUGIN) |
| 34 #define CHECK(x) | 34 #define CHECK(x) |
| 35 #else | 35 #else |
| 36 #include "base/logging.h" | 36 #include "base/logging.h" |
| 37 #include "gpu/command_buffer/client/gles2_lib.h" | |
| 38 #include "gpu/command_buffer/client/gles2_demo_cc.h" | 37 #include "gpu/command_buffer/client/gles2_demo_cc.h" |
| 38 #include "gpu/command_buffer/common/gles2/gl2.h" |
| 39 #include "third_party/skia/include/core/SkBitmap.h" | 39 #include "third_party/skia/include/core/SkBitmap.h" |
| 40 #include "third_party/skia/include/core/SkCanvas.h" | 40 #include "third_party/skia/include/core/SkCanvas.h" |
| 41 #include "third_party/skia/include/effects/SkGradientShader.h" | 41 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 42 #endif | 42 #endif |
| 43 #include "webkit/tools/pepper_test_plugin/event_handler.h" | 43 #include "webkit/tools/pepper_test_plugin/event_handler.h" |
| 44 #include "webkit/tools/pepper_test_plugin/test_object.h" | 44 #include "webkit/tools/pepper_test_plugin/test_object.h" |
| 45 | 45 |
| 46 NPNetscapeFuncs* browser; | 46 NPNetscapeFuncs* browser; |
| 47 | 47 |
| 48 namespace { | 48 namespace { |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 T* buf = reinterpret_cast<T*>(context->outBuffer); | 280 T* buf = reinterpret_cast<T*>(context->outBuffer); |
| 281 for (size_t sample = 0; sample < n_samples; ++sample) { | 281 for (size_t sample = 0; sample < n_samples; ++sample) { |
| 282 T value = static_cast<T>(sin(th * t++) * std::numeric_limits<T>::max()); | 282 T value = static_cast<T>(sin(th * t++) * std::numeric_limits<T>::max()); |
| 283 for (size_t channel = 0; channel < n_channels; ++channel) { | 283 for (size_t channel = 0; channel < n_channels; ++channel) { |
| 284 *buf++ = value; | 284 *buf++ = value; |
| 285 } | 285 } |
| 286 } | 286 } |
| 287 context->config.userData = reinterpret_cast<void *>(t); | 287 context->config.userData = reinterpret_cast<void *>(t); |
| 288 } | 288 } |
| 289 | 289 |
| 290 const int32 kCommandBufferSize = 1024 * 1024; |
| 291 |
| 290 } // namespace | 292 } // namespace |
| 291 | 293 |
| 292 | 294 |
| 293 // PluginObject ---------------------------------------------------------------- | 295 // PluginObject ---------------------------------------------------------------- |
| 294 | 296 |
| 295 PluginObject::PluginObject(NPP npp) | 297 PluginObject::PluginObject(NPP npp) |
| 296 : npp_(npp), | 298 : npp_(npp), |
| 297 test_object_(browser->createobject(npp, GetTestClass())), | 299 test_object_(browser->createobject(npp, GetTestClass())), |
| 298 device2d_(NULL) { | 300 device2d_(NULL), |
| 301 device3d_(NULL), |
| 302 deviceaudio_(NULL), |
| 303 pgl_context_(NULL) { |
| 299 memset(&context_audio_, 0, sizeof(context_audio_)); | 304 memset(&context_audio_, 0, sizeof(context_audio_)); |
| 300 } | 305 } |
| 301 | 306 |
| 302 PluginObject::~PluginObject() { | 307 PluginObject::~PluginObject() { |
| 303 deviceaudio_->destroyContext(npp_, &context_audio_); | 308 deviceaudio_->destroyContext(npp_, &context_audio_); |
| 304 // FIXME(brettw) destroy the context. | 309 // FIXME(brettw) destroy the context. |
| 305 browser->releaseobject(test_object_); | 310 browser->releaseobject(test_object_); |
| 306 } | 311 } |
| 307 | 312 |
| 308 // static | 313 // static |
| (...skipping 20 matching lines...) Expand all Loading... |
| 329 } | 334 } |
| 330 | 335 |
| 331 if (!extensions) { | 336 if (!extensions) { |
| 332 browser->getvalue(npp_, NPNVPepperExtensions, | 337 browser->getvalue(npp_, NPNVPepperExtensions, |
| 333 reinterpret_cast<void*>(&extensions)); | 338 reinterpret_cast<void*>(&extensions)); |
| 334 CHECK(extensions); | 339 CHECK(extensions); |
| 335 } | 340 } |
| 336 device2d_ = extensions->acquireDevice(npp_, NPPepper2DDevice); | 341 device2d_ = extensions->acquireDevice(npp_, NPPepper2DDevice); |
| 337 CHECK(device2d_); | 342 CHECK(device2d_); |
| 338 | 343 |
| 344 device3d_ = extensions->acquireDevice(npp_, NPPepper3DDevice); |
| 345 CHECK(device3d_); |
| 346 |
| 339 deviceaudio_ = extensions->acquireDevice(npp_, NPPepperAudioDevice); | 347 deviceaudio_ = extensions->acquireDevice(npp_, NPPepperAudioDevice); |
| 340 CHECK(deviceaudio_); | 348 CHECK(deviceaudio_); |
| 341 } | 349 } |
| 342 | 350 |
| 343 void PluginObject::SetWindow(const NPWindow& window) { | 351 void PluginObject::SetWindow(const NPWindow& window) { |
| 344 if (dimensions_ == 2) { | 352 if (dimensions_ == 2) { |
| 345 width_ = window.width; | 353 width_ = window.width; |
| 346 height_ = window.height; | 354 height_ = window.height; |
| 347 | 355 |
| 348 NPDeviceContext2DConfig config; | 356 NPDeviceContext2DConfig config; |
| 349 NPDeviceContext2D context; | 357 NPDeviceContext2D context; |
| 350 device2d_->initializeContext(npp_, &config, &context); | 358 device2d_->initializeContext(npp_, &config, &context); |
| 351 | 359 |
| 352 DrawSampleBitmap(context.region, width_, height_); | 360 DrawSampleBitmap(context.region, width_, height_); |
| 353 | 361 |
| 354 // TODO(brettw) figure out why this cast is necessary, the functions seem to | 362 // TODO(brettw) figure out why this cast is necessary, the functions seem to |
| 355 // match. Could be a calling convention mismatch? | 363 // match. Could be a calling convention mismatch? |
| 356 NPDeviceFlushContextCallbackPtr callback = | 364 NPDeviceFlushContextCallbackPtr callback = |
| 357 reinterpret_cast<NPDeviceFlushContextCallbackPtr>(&FlushCallback); | 365 reinterpret_cast<NPDeviceFlushContextCallbackPtr>(&FlushCallback); |
| 358 device2d_->flushContext(npp_, &context, callback, NULL); | 366 device2d_->flushContext(npp_, &context, callback, NULL); |
| 359 } else { | 367 } else { |
| 360 #if !defined(INDEPENDENT_PLUGIN) | 368 #if !defined(INDEPENDENT_PLUGIN) |
| 361 if (!command_buffer_.get()) { | 369 if (!pgl_context_) { |
| 362 if (!InitializeCommandBuffer()) | 370 // Initialize a 3D context. |
| 363 return; | 371 NPDeviceContext3DConfig config; |
| 372 config.commandBufferEntries = kCommandBufferSize; |
| 373 device3d_->initializeContext(npp_, &config, &context3d_); |
| 374 |
| 375 // Create a PGL context. |
| 376 pgl_context_ = pglCreateContext(npp_, device3d_, &context3d_); |
| 364 } | 377 } |
| 365 | 378 |
| 366 gles2_implementation_->Viewport(0, 0, window.width, window.height); | 379 // Reset the viewport to new window size. |
| 380 pglMakeCurrent(pgl_context_); |
| 381 glViewport(0, 0, window.width, window.height); |
| 382 pglMakeCurrent(NULL); |
| 367 | 383 |
| 368 // Schedule the first call to Draw. | 384 // Schedule the first call to Draw. |
| 369 browser->pluginthreadasynccall(npp_, Draw3DCallback, this); | 385 browser->pluginthreadasynccall(npp_, Draw3DCallback, this); |
| 370 #endif | 386 #endif |
| 371 } | 387 } |
| 372 | 388 |
| 373 // testing any field would do | 389 // testing any field would do |
| 374 if (!context_audio_.config.callback) { | 390 if (!context_audio_.config.callback) { |
| 375 NPDeviceContextAudioConfig cfg; | 391 NPDeviceContextAudioConfig cfg; |
| 376 cfg.sampleRate = 44100; | 392 cfg.sampleRate = 44100; |
| 377 cfg.sampleType = NPAudioSampleTypeInt16; | 393 cfg.sampleType = NPAudioSampleTypeInt16; |
| 378 cfg.outputChannelMap = NPAudioChannelStereo; | 394 cfg.outputChannelMap = NPAudioChannelStereo; |
| 379 cfg.inputChannelMap = NPAudioChannelNone; | 395 cfg.inputChannelMap = NPAudioChannelNone; |
| 380 cfg.sampleFrameCount = 2048; | 396 cfg.sampleFrameCount = 2048; |
| 381 cfg.flags = 0; | 397 cfg.flags = 0; |
| 382 cfg.callback = &SineWaveCallback<200, int16>; | 398 cfg.callback = &SineWaveCallback<200, int16>; |
| 383 deviceaudio_->initializeContext(npp_, &cfg, &context_audio_); | 399 deviceaudio_->initializeContext(npp_, &cfg, &context_audio_); |
| 384 } | 400 } |
| 385 } | 401 } |
| 386 | 402 |
| 387 void PluginObject::Draw3D() { | 403 void PluginObject::Draw3D() { |
| 388 #if !defined(INDEPENDENT_PLUGIN) | 404 #if !defined(INDEPENDENT_PLUGIN) |
| 389 // Render some stuff. | 405 // Render some stuff. |
| 390 gles2::g_gl_impl = gles2_implementation_.get(); | 406 pglMakeCurrent(pgl_context_); |
| 391 GLFromCPPTestFunction(); | 407 GLFromCPPTestFunction(); |
| 392 gles2::GetGLContext()->SwapBuffers(); | 408 pglSwapBuffers(); |
| 393 helper_->Flush(); | 409 pglMakeCurrent(NULL); |
| 394 gles2::g_gl_impl = NULL; | |
| 395 | 410 |
| 396 // Schedule another call to Draw. | 411 // Schedule another call to Draw. |
| 397 browser->pluginthreadasynccall(npp_, Draw3DCallback, this); | 412 browser->pluginthreadasynccall(npp_, Draw3DCallback, this); |
| 398 #endif | 413 #endif |
| 399 } | 414 } |
| 400 | |
| 401 bool PluginObject::InitializeCommandBuffer() { | |
| 402 #if !defined(INDEPENDENT_PLUGIN) | |
| 403 const static int32 kCommandBufferSize = 512 * 1024; | |
| 404 command_buffer_.reset(new CommandBufferPepper(npp_, browser)); | |
| 405 if (command_buffer_->Initialize(kCommandBufferSize)) { | |
| 406 helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); | |
| 407 if (helper_->Initialize()) { | |
| 408 | |
| 409 const int32 kTransferBufferSize = 512 * 1024; | |
| 410 int32 transfer_buffer_id = | |
| 411 command_buffer_->CreateTransferBuffer(kTransferBufferSize); | |
| 412 gpu::Buffer transfer_buffer = | |
| 413 command_buffer_->GetTransferBuffer(transfer_buffer_id); | |
| 414 if (transfer_buffer.ptr) { | |
| 415 gles2_implementation_.reset(new gpu::gles2::GLES2Implementation( | |
| 416 helper_.get(), | |
| 417 transfer_buffer.size, | |
| 418 transfer_buffer.ptr, | |
| 419 transfer_buffer_id)); | |
| 420 return true; | |
| 421 } | |
| 422 } | |
| 423 | |
| 424 helper_.reset(); | |
| 425 } | |
| 426 | |
| 427 command_buffer_.reset(); | |
| 428 #endif | |
| 429 | |
| 430 return false; | |
| 431 } | |
| OLD | NEW |