| 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 device2d_(NULL), | 301 device2d_(NULL), |
| 302 device3d_(NULL), | 302 device3d_(NULL), |
| 303 #if !defined(INDEPENDENT_PLUGIN) | 303 #if !defined(INDEPENDENT_PLUGIN) |
| 304 pgl_context_(NULL), | 304 pgl_context_(NULL), |
| 305 #endif | 305 #endif |
| 306 deviceaudio_(NULL) { | 306 deviceaudio_(NULL) { |
| 307 memset(&context_audio_, 0, sizeof(context_audio_)); | 307 memset(&context_audio_, 0, sizeof(context_audio_)); |
| 308 } | 308 } |
| 309 | 309 |
| 310 PluginObject::~PluginObject() { | 310 PluginObject::~PluginObject() { |
| 311 #if !defined(INDEPENDENT_PLUGIN) |
| 312 if (pgl_context_) |
| 313 Destroy3D(); |
| 314 #endif |
| 315 |
| 311 deviceaudio_->destroyContext(npp_, &context_audio_); | 316 deviceaudio_->destroyContext(npp_, &context_audio_); |
| 312 // FIXME(brettw) destroy the context. | 317 // FIXME(brettw) destroy the context. |
| 313 browser->releaseobject(test_object_); | 318 browser->releaseobject(test_object_); |
| 314 } | 319 } |
| 315 | 320 |
| 316 // static | 321 // static |
| 317 NPClass* PluginObject::GetPluginClass() { | 322 NPClass* PluginObject::GetPluginClass() { |
| 318 return &plugin_class; | 323 return &plugin_class; |
| 319 } | 324 } |
| 320 | 325 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 345 CHECK(device2d_); | 350 CHECK(device2d_); |
| 346 | 351 |
| 347 device3d_ = extensions->acquireDevice(npp_, NPPepper3DDevice); | 352 device3d_ = extensions->acquireDevice(npp_, NPPepper3DDevice); |
| 348 CHECK(device3d_); | 353 CHECK(device3d_); |
| 349 | 354 |
| 350 deviceaudio_ = extensions->acquireDevice(npp_, NPPepperAudioDevice); | 355 deviceaudio_ = extensions->acquireDevice(npp_, NPPepperAudioDevice); |
| 351 CHECK(deviceaudio_); | 356 CHECK(deviceaudio_); |
| 352 } | 357 } |
| 353 | 358 |
| 354 void PluginObject::SetWindow(const NPWindow& window) { | 359 void PluginObject::SetWindow(const NPWindow& window) { |
| 360 width_ = window.width; |
| 361 height_ = window.height; |
| 362 |
| 355 if (dimensions_ == 2) { | 363 if (dimensions_ == 2) { |
| 356 width_ = window.width; | |
| 357 height_ = window.height; | |
| 358 | |
| 359 NPDeviceContext2DConfig config; | 364 NPDeviceContext2DConfig config; |
| 360 NPDeviceContext2D context; | 365 NPDeviceContext2D context; |
| 361 device2d_->initializeContext(npp_, &config, &context); | 366 device2d_->initializeContext(npp_, &config, &context); |
| 362 | 367 |
| 363 DrawSampleBitmap(context.region, width_, height_); | 368 DrawSampleBitmap(context.region, width_, height_); |
| 364 | 369 |
| 365 // TODO(brettw) figure out why this cast is necessary, the functions seem to | 370 // TODO(brettw) figure out why this cast is necessary, the functions seem to |
| 366 // match. Could be a calling convention mismatch? | 371 // match. Could be a calling convention mismatch? |
| 367 NPDeviceFlushContextCallbackPtr callback = | 372 NPDeviceFlushContextCallbackPtr callback = |
| 368 reinterpret_cast<NPDeviceFlushContextCallbackPtr>(&FlushCallback); | 373 reinterpret_cast<NPDeviceFlushContextCallbackPtr>(&FlushCallback); |
| 369 device2d_->flushContext(npp_, &context, callback, NULL); | 374 device2d_->flushContext(npp_, &context, callback, NULL); |
| 370 } else { | 375 } else { |
| 371 #if !defined(INDEPENDENT_PLUGIN) | 376 #if !defined(INDEPENDENT_PLUGIN) |
| 372 if (!pgl_context_) { | 377 if (!pgl_context_) |
| 373 // Initialize a 3D context. | 378 Initialize3D(); |
| 374 NPDeviceContext3DConfig config; | |
| 375 config.commandBufferSize = kCommandBufferSize; | |
| 376 device3d_->initializeContext(npp_, &config, &context3d_); | |
| 377 | |
| 378 // Create a PGL context. | |
| 379 pgl_context_ = pglCreateContext(npp_, device3d_, &context3d_); | |
| 380 } | |
| 381 | |
| 382 // Reset the viewport to new window size. | |
| 383 pglMakeCurrent(pgl_context_); | |
| 384 glViewport(0, 0, window.width, window.height); | |
| 385 pglMakeCurrent(NULL); | |
| 386 | 379 |
| 387 // Schedule the first call to Draw. | 380 // Schedule the first call to Draw. |
| 388 browser->pluginthreadasynccall(npp_, Draw3DCallback, this); | 381 browser->pluginthreadasynccall(npp_, Draw3DCallback, this); |
| 389 #endif | 382 #endif |
| 390 } | 383 } |
| 391 | 384 |
| 392 // testing any field would do | 385 // testing any field would do |
| 393 if (!context_audio_.config.callback) { | 386 if (!context_audio_.config.callback) { |
| 394 NPDeviceContextAudioConfig cfg; | 387 NPDeviceContextAudioConfig cfg; |
| 395 cfg.sampleRate = 44100; | 388 cfg.sampleRate = 44100; |
| 396 cfg.sampleType = NPAudioSampleTypeInt16; | 389 cfg.sampleType = NPAudioSampleTypeInt16; |
| 397 cfg.outputChannelMap = NPAudioChannelStereo; | 390 cfg.outputChannelMap = NPAudioChannelStereo; |
| 398 cfg.inputChannelMap = NPAudioChannelNone; | 391 cfg.inputChannelMap = NPAudioChannelNone; |
| 399 cfg.sampleFrameCount = 2048; | 392 cfg.sampleFrameCount = 2048; |
| 400 cfg.flags = 0; | 393 cfg.flags = 0; |
| 401 cfg.callback = &SineWaveCallback<200, int16>; | 394 cfg.callback = &SineWaveCallback<200, int16>; |
| 402 deviceaudio_->initializeContext(npp_, &cfg, &context_audio_); | 395 deviceaudio_->initializeContext(npp_, &cfg, &context_audio_); |
| 403 } | 396 } |
| 404 } | 397 } |
| 405 | 398 |
| 399 void PluginObject::Initialize3D() { |
| 400 #if !defined(INDEPENDENT_PLUGIN) |
| 401 DCHECK(!pgl_context_); |
| 402 |
| 403 // Initialize a 3D context. |
| 404 NPDeviceContext3DConfig config; |
| 405 config.commandBufferSize = kCommandBufferSize; |
| 406 device3d_->initializeContext(npp_, &config, &context3d_); |
| 407 |
| 408 // Create a PGL context. |
| 409 pgl_context_ = pglCreateContext(npp_, device3d_, &context3d_); |
| 410 |
| 411 // Initialize the demo GL state. |
| 412 pglMakeCurrent(pgl_context_); |
| 413 GLFromCPPInit(); |
| 414 pglMakeCurrent(NULL); |
| 415 #endif // INDEPENDENT_PLUGIN |
| 416 } |
| 417 |
| 418 void PluginObject::Destroy3D() { |
| 419 #if !defined(INDEPENDENT_PLUGIN) |
| 420 DCHECK(pgl_context_); |
| 421 |
| 422 // Destroy the PGL context. |
| 423 pglDestroyContext(pgl_context_); |
| 424 pgl_context_ = NULL; |
| 425 |
| 426 // Destroy the Device3D context. |
| 427 device3d_->destroyContext(npp_, &context3d_); |
| 428 #endif // INDEPENDENT_PLUGIN |
| 429 } |
| 430 |
| 406 void PluginObject::Draw3D() { | 431 void PluginObject::Draw3D() { |
| 407 #if !defined(INDEPENDENT_PLUGIN) | 432 #if !defined(INDEPENDENT_PLUGIN) |
| 408 // Render some stuff. | 433 if (!pglMakeCurrent(pgl_context_) && pglGetError() == PGL_CONTEXT_LOST) { |
| 409 pglMakeCurrent(pgl_context_); | 434 Destroy3D(); |
| 410 GLFromCPPTestFunction(); | 435 Initialize3D(); |
| 436 pglMakeCurrent(pgl_context_); |
| 437 } |
| 438 |
| 439 glViewport(0, 0, width_, height_); |
| 440 GLFromCPPDraw(); |
| 411 pglSwapBuffers(); | 441 pglSwapBuffers(); |
| 412 pglMakeCurrent(NULL); | 442 pglMakeCurrent(NULL); |
| 413 | 443 |
| 414 // Schedule another call to Draw. | 444 // Schedule another call to Draw. |
| 415 browser->pluginthreadasynccall(npp_, Draw3DCallback, this); | 445 browser->pluginthreadasynccall(npp_, Draw3DCallback, this); |
| 416 #endif | 446 #endif // INDEPENDENT_PLUGIN |
| 417 } | 447 } |
| OLD | NEW |