OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #define PEPPER_APIS_ENABLED 1 | 5 #define PEPPER_APIS_ENABLED 1 |
6 | 6 |
7 #include "chrome/renderer/webplugin_delegate_pepper.h" | 7 #include "chrome/renderer/webplugin_delegate_pepper.h" |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 std::vector<std::string>(), | 345 std::vector<std::string>(), |
346 plugin_, | 346 plugin_, |
347 false)) { | 347 false)) { |
348 plugin_->SetAcceptsInputEvents(true); | 348 plugin_->SetAcceptsInputEvents(true); |
349 | 349 |
350 // Ask the GPU plugin to create a command buffer and return a proxy. | 350 // Ask the GPU plugin to create a command buffer and return a proxy. |
351 command_buffer_.reset(nested_delegate_->CreateCommandBuffer()); | 351 command_buffer_.reset(nested_delegate_->CreateCommandBuffer()); |
352 if (command_buffer_.get()) { | 352 if (command_buffer_.get()) { |
353 // Initialize the proxy command buffer. | 353 // Initialize the proxy command buffer. |
354 if (command_buffer_->Initialize(config->commandBufferEntries)) { | 354 if (command_buffer_->Initialize(config->commandBufferEntries)) { |
| 355 // Get the initial command buffer state. |
| 356 gpu::CommandBuffer::State state = command_buffer_->GetState(); |
| 357 |
355 // Initialize the 3D context. | 358 // Initialize the 3D context. |
356 context->reserved = NULL; | 359 context->reserved = NULL; |
357 Buffer ring_buffer = command_buffer_->GetRingBuffer(); | 360 Buffer ring_buffer = command_buffer_->GetRingBuffer(); |
358 context->commandBuffer = ring_buffer.ptr; | 361 context->commandBuffer = ring_buffer.ptr; |
359 context->commandBufferEntries = command_buffer_->GetSize(); | 362 context->commandBufferEntries = state.size; |
360 context->getOffset = command_buffer_->GetGetOffset(); | 363 Synchronize3DContext(context, state); |
361 context->putOffset = command_buffer_->GetPutOffset(); | |
362 | 364 |
363 // Ensure the service knows the window size before rendering anything. | 365 // Ensure the service knows the window size before rendering anything. |
364 nested_delegate_->UpdateGeometry(window_rect_, clip_rect_); | 366 nested_delegate_->UpdateGeometry(window_rect_, clip_rect_); |
365 // Save the implementation information (the CommandBuffer). | 367 // Save the implementation information (the CommandBuffer). |
366 Device3DImpl* impl = new Device3DImpl; | 368 Device3DImpl* impl = new Device3DImpl; |
367 impl->command_buffer = command_buffer_.get(); | 369 impl->command_buffer = command_buffer_.get(); |
368 context->reserved = impl; | 370 context->reserved = impl; |
369 | 371 |
370 return NPERR_NO_ERROR; | 372 return NPERR_NO_ERROR; |
371 } | 373 } |
(...skipping 13 matching lines...) Expand all Loading... |
385 NPDeviceContext3D* context, | 387 NPDeviceContext3D* context, |
386 int32 state, | 388 int32 state, |
387 int32 value) { | 389 int32 value) { |
388 return NPERR_GENERIC_ERROR; | 390 return NPERR_GENERIC_ERROR; |
389 } | 391 } |
390 | 392 |
391 NPError WebPluginDelegatePepper::Device3DGetStateContext( | 393 NPError WebPluginDelegatePepper::Device3DGetStateContext( |
392 NPDeviceContext3D* context, | 394 NPDeviceContext3D* context, |
393 int32 state, | 395 int32 state, |
394 int32* value) { | 396 int32* value) { |
395 #if defined(ENABLE_GPU) | 397 return NPERR_GENERIC_ERROR; |
396 if (!command_buffer_.get()) | |
397 return NPERR_GENERIC_ERROR; | |
398 | |
399 switch (state) { | |
400 case NPDeviceContext3DState_GetOffset: | |
401 context->getOffset = *value = command_buffer_->GetGetOffset(); | |
402 break; | |
403 case NPDeviceContext3DState_PutOffset: | |
404 *value = command_buffer_->GetPutOffset(); | |
405 break; | |
406 case NPDeviceContext3DState_Token: | |
407 *value = command_buffer_->GetToken(); | |
408 break; | |
409 case NPDeviceContext3DState_ParseError: | |
410 *value = command_buffer_->ResetParseError(); | |
411 break; | |
412 case NPDeviceContext3DState_ErrorStatus: | |
413 *value = command_buffer_->GetErrorStatus() ? 1 : 0; | |
414 break; | |
415 default: | |
416 return NPERR_GENERIC_ERROR; | |
417 }; | |
418 #endif // ENABLE_GPU | |
419 | |
420 return NPERR_NO_ERROR; | |
421 } | 398 } |
422 | 399 |
423 NPError WebPluginDelegatePepper::Device3DFlushContext( | 400 NPError WebPluginDelegatePepper::Device3DFlushContext( |
424 NPP id, | 401 NPP id, |
425 NPDeviceContext3D* context, | 402 NPDeviceContext3D* context, |
426 NPDeviceFlushContextCallbackPtr callback, | 403 NPDeviceFlushContextCallbackPtr callback, |
427 void* user_data) { | 404 void* user_data) { |
428 #if defined(ENABLE_GPU) | 405 #if defined(ENABLE_GPU) |
429 DCHECK(callback == NULL); | 406 gpu::CommandBuffer::State state; |
430 context->getOffset = command_buffer_->SyncOffsets(context->putOffset); | 407 // Only flush if new commands have been put in the command buffer. Otherwise |
| 408 // update the state to the current service state. |
| 409 if (context->putOffset == last_command_buffer_put_offset_) { |
| 410 state = command_buffer_->GetState(); |
| 411 } else { |
| 412 last_command_buffer_put_offset_ = context->putOffset; |
| 413 state = command_buffer_->Flush(context->putOffset); |
| 414 } |
| 415 Synchronize3DContext(context, state); |
431 #endif // ENABLE_GPU | 416 #endif // ENABLE_GPU |
432 return NPERR_NO_ERROR; | 417 return NPERR_NO_ERROR; |
433 } | 418 } |
434 | 419 |
435 NPError WebPluginDelegatePepper::Device3DDestroyContext( | 420 NPError WebPluginDelegatePepper::Device3DDestroyContext( |
436 NPDeviceContext3D* context) { | 421 NPDeviceContext3D* context) { |
437 #if defined(ENABLE_GPU) | 422 #if defined(ENABLE_GPU) |
438 command_buffer_.reset(); | 423 command_buffer_.reset(); |
439 | 424 |
440 if (nested_delegate_) { | 425 if (nested_delegate_) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 memset(context, 0, sizeof(NPDeviceContextAudio)); | 534 memset(context, 0, sizeof(NPDeviceContextAudio)); |
550 return NPERR_NO_ERROR; | 535 return NPERR_NO_ERROR; |
551 } | 536 } |
552 | 537 |
553 WebPluginDelegatePepper::WebPluginDelegatePepper( | 538 WebPluginDelegatePepper::WebPluginDelegatePepper( |
554 const base::WeakPtr<RenderView>& render_view, | 539 const base::WeakPtr<RenderView>& render_view, |
555 NPAPI::PluginInstance *instance) | 540 NPAPI::PluginInstance *instance) |
556 : render_view_(render_view), | 541 : render_view_(render_view), |
557 plugin_(NULL), | 542 plugin_(NULL), |
558 instance_(instance), | 543 instance_(instance), |
559 nested_delegate_(NULL) { | 544 nested_delegate_(NULL), |
| 545 last_command_buffer_put_offset_(-1) { |
560 // For now we keep a window struct, although it isn't used. | 546 // For now we keep a window struct, although it isn't used. |
561 memset(&window_, 0, sizeof(window_)); | 547 memset(&window_, 0, sizeof(window_)); |
562 // All Pepper plugins are windowless and transparent. | 548 // All Pepper plugins are windowless and transparent. |
563 // TODO(sehr): disable resetting these NPPVs by plugins. | 549 // TODO(sehr): disable resetting these NPPVs by plugins. |
564 instance->set_windowless(true); | 550 instance->set_windowless(true); |
565 instance->set_transparent(true); | 551 instance->set_transparent(true); |
566 } | 552 } |
567 | 553 |
568 WebPluginDelegatePepper::~WebPluginDelegatePepper() { | 554 WebPluginDelegatePepper::~WebPluginDelegatePepper() { |
569 DestroyInstance(); | 555 DestroyInstance(); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 BuildCharEvent(&event, &npevent); | 699 BuildCharEvent(&event, &npevent); |
714 break; | 700 break; |
715 case NPEventType_Minimize: | 701 case NPEventType_Minimize: |
716 case NPEventType_Focus: | 702 case NPEventType_Focus: |
717 case NPEventType_Device: | 703 case NPEventType_Device: |
718 // NOTIMPLEMENTED(); | 704 // NOTIMPLEMENTED(); |
719 break; | 705 break; |
720 } | 706 } |
721 return instance()->NPP_HandleEvent(&npevent) != 0; | 707 return instance()->NPP_HandleEvent(&npevent) != 0; |
722 } | 708 } |
| 709 |
| 710 #if defined(ENABLE_GPU) |
| 711 void WebPluginDelegatePepper::Synchronize3DContext( |
| 712 NPDeviceContext3D* context, |
| 713 gpu::CommandBuffer::State state) { |
| 714 context->getOffset = state.get_offset; |
| 715 context->putOffset = state.put_offset; |
| 716 context->token = state.token; |
| 717 context->error = static_cast<int32>(state.error); |
| 718 } |
| 719 #endif // ENABLE_GPU |
OLD | NEW |