| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <stdlib.h> | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "gpu/command_buffer/service/command_buffer_service.h" | |
| 9 #include "gpu/command_buffer/service/gpu_processor.h" | |
| 10 #include "gpu/np_utils/np_utils.h" | |
| 11 #include "gpu/gpu_plugin/gpu_plugin_object.h" | |
| 12 | |
| 13 using ::base::SharedMemory; | |
| 14 using command_buffer::CommandBuffer; | |
| 15 using command_buffer::CommandBufferService; | |
| 16 using command_buffer::GPUProcessor; | |
| 17 using np_utils::NPBrowser; | |
| 18 using np_utils::NPObjectPointer; | |
| 19 | |
| 20 namespace gpu_plugin { | |
| 21 | |
| 22 const NPUTF8 GPUPluginObject::kPluginType[] = | |
| 23 "application/vnd.google.chrome.gpu-plugin"; | |
| 24 | |
| 25 GPUPluginObject::GPUPluginObject(NPP npp) | |
| 26 : npp_(npp), | |
| 27 status_(kWaitingForNew), | |
| 28 command_buffer_(new CommandBufferService), | |
| 29 processor_(new GPUProcessor(command_buffer_.get())) { | |
| 30 memset(&window_, 0, sizeof(window_)); | |
| 31 } | |
| 32 | |
| 33 NPError GPUPluginObject::New(NPMIMEType plugin_type, | |
| 34 int16 argc, | |
| 35 char* argn[], | |
| 36 char* argv[], | |
| 37 NPSavedData* saved) { | |
| 38 if (status_ != kWaitingForNew) | |
| 39 return NPERR_GENERIC_ERROR; | |
| 40 | |
| 41 status_ = kWaitingForSetWindow; | |
| 42 | |
| 43 return NPERR_NO_ERROR; | |
| 44 } | |
| 45 | |
| 46 NPError GPUPluginObject::SetWindow(NPWindow* new_window) { | |
| 47 if (status_ == kWaitingForNew || status_ == kDestroyed) | |
| 48 return NPERR_GENERIC_ERROR; | |
| 49 | |
| 50 // PlatformSpecificSetWindow advances the status depending on what happens. | |
| 51 NPError error = PlatformSpecificSetWindow(new_window); | |
| 52 if (error == NPERR_NO_ERROR) { | |
| 53 window_ = *new_window; | |
| 54 | |
| 55 if (event_sync_.Get()) { | |
| 56 NPInvokeVoid(npp_, | |
| 57 event_sync_, | |
| 58 "resize", | |
| 59 static_cast<int32>(window_.width), | |
| 60 static_cast<int32>(window_.height)); | |
| 61 } | |
| 62 } else { | |
| 63 memset(&window_, 0, sizeof(window_)); | |
| 64 } | |
| 65 | |
| 66 return error; | |
| 67 } | |
| 68 | |
| 69 int16 GPUPluginObject::HandleEvent(NPEvent* event) { | |
| 70 return 0; | |
| 71 } | |
| 72 | |
| 73 NPError GPUPluginObject::Destroy(NPSavedData** saved) { | |
| 74 if (status_ == kWaitingForNew || status_ == kDestroyed) | |
| 75 return NPERR_GENERIC_ERROR; | |
| 76 | |
| 77 if (command_buffer_.get()) { | |
| 78 command_buffer_->SetPutOffsetChangeCallback(NULL); | |
| 79 } | |
| 80 | |
| 81 status_ = kDestroyed; | |
| 82 | |
| 83 return NPERR_NO_ERROR; | |
| 84 } | |
| 85 | |
| 86 void GPUPluginObject::Release() { | |
| 87 DCHECK(status_ == kWaitingForNew || status_ == kDestroyed); | |
| 88 NPBrowser::get()->ReleaseObject(this); | |
| 89 } | |
| 90 | |
| 91 NPObject*GPUPluginObject::GetScriptableNPObject() { | |
| 92 NPBrowser::get()->RetainObject(this); | |
| 93 return this; | |
| 94 } | |
| 95 | |
| 96 CommandBuffer* GPUPluginObject::OpenCommandBuffer() { | |
| 97 if (status_ == kInitializationSuccessful) | |
| 98 return command_buffer_.get(); | |
| 99 | |
| 100 // SetWindow must have been called before OpenCommandBuffer. | |
| 101 // PlatformSpecificSetWindow advances the status to | |
| 102 // kWaitingForOpenCommandBuffer. | |
| 103 if (status_ != kWaitingForOpenCommandBuffer) | |
| 104 return NULL; | |
| 105 | |
| 106 scoped_ptr<SharedMemory> ring_buffer(new SharedMemory); | |
| 107 if (!ring_buffer->Create(std::wstring(), false, false, kCommandBufferSize)) | |
| 108 return NULL; | |
| 109 | |
| 110 if (command_buffer_->Initialize(ring_buffer.release())) { | |
| 111 if (processor_->Initialize(static_cast<HWND>(window_.window))) { | |
| 112 command_buffer_->SetPutOffsetChangeCallback( | |
| 113 NewCallback(processor_.get(), | |
| 114 &GPUProcessor::ProcessCommands)); | |
| 115 status_ = kInitializationSuccessful; | |
| 116 return command_buffer_.get(); | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 return NULL; | |
| 121 } | |
| 122 | |
| 123 } // namespace gpu_plugin | |
| OLD | NEW |