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