| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "webkit/tools/pepper_test_plugin/command_buffer_pepper.h" | 5 #include "gpu/pgl/command_buffer_pepper.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 | 7 |
| 8 using base::SharedMemory; | 8 using base::SharedMemory; |
| 9 using gpu::Buffer; | 9 using gpu::Buffer; |
| 10 | 10 |
| 11 CommandBufferPepper::CommandBufferPepper(NPP npp, NPNetscapeFuncs* browser) | 11 CommandBufferPepper::CommandBufferPepper(NPP npp, |
| 12 NPDevice* device, |
| 13 NPDeviceContext3D* context) |
| 12 : npp_(npp), | 14 : npp_(npp), |
| 13 browser_(browser), | 15 device_(device), |
| 14 extensions_(NULL), | 16 context_(context) { |
| 15 device_(NULL) { | |
| 16 } | 17 } |
| 17 | 18 |
| 18 CommandBufferPepper::~CommandBufferPepper() { | 19 CommandBufferPepper::~CommandBufferPepper() { |
| 19 if (device_) { | |
| 20 device_->destroyContext(npp_, &context_); | |
| 21 device_ = NULL; | |
| 22 } | |
| 23 } | 20 } |
| 24 | 21 |
| 22 // Not implemented in CommandBufferPepper. |
| 25 bool CommandBufferPepper::Initialize(int32 size) { | 23 bool CommandBufferPepper::Initialize(int32 size) { |
| 26 if (device_) | 24 NOTREACHED(); |
| 27 return false; | |
| 28 | |
| 29 // Get the pepper extensions. | |
| 30 browser_->getvalue(npp_, | |
| 31 NPNVPepperExtensions, | |
| 32 reinterpret_cast<void*>(&extensions_)); | |
| 33 CHECK(extensions_); | |
| 34 | |
| 35 // Acquire a 3D device. | |
| 36 device_ = extensions_->acquireDevice(npp_, NPPepper3DDevice); | |
| 37 if (device_) { | |
| 38 NPDeviceContext3DConfig config; | |
| 39 config.commandBufferEntries = size; | |
| 40 if (NPERR_NO_ERROR == device_->initializeContext(npp_, | |
| 41 &config, | |
| 42 &context_)) { | |
| 43 return true; | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 return false; | 25 return false; |
| 48 } | 26 } |
| 49 | 27 |
| 50 Buffer CommandBufferPepper::GetRingBuffer() { | 28 Buffer CommandBufferPepper::GetRingBuffer() { |
| 51 Buffer buffer; | 29 Buffer buffer; |
| 52 buffer.ptr = context_.commandBuffer; | 30 buffer.ptr = context_->commandBuffer; |
| 53 buffer.size = context_.commandBufferEntries * sizeof(int32); | 31 buffer.size = context_->commandBufferEntries * sizeof(int32); |
| 54 return buffer; | 32 return buffer; |
| 55 } | 33 } |
| 56 | 34 |
| 57 int32 CommandBufferPepper::GetSize() { | 35 int32 CommandBufferPepper::GetSize() { |
| 58 return context_.commandBufferEntries; | 36 return context_->commandBufferEntries; |
| 59 } | 37 } |
| 60 | 38 |
| 61 int32 CommandBufferPepper::SyncOffsets(int32 put_offset) { | 39 int32 CommandBufferPepper::SyncOffsets(int32 put_offset) { |
| 62 context_.putOffset = put_offset; | 40 context_->putOffset = put_offset; |
| 63 if (NPERR_NO_ERROR != device_->flushContext(npp_, &context_, NULL, NULL)) | 41 if (NPERR_NO_ERROR != device_->flushContext(npp_, context_, NULL, NULL)) |
| 64 return -1; | 42 return -1; |
| 65 | 43 |
| 66 return context_.getOffset; | 44 return context_->getOffset; |
| 67 } | 45 } |
| 68 | 46 |
| 69 int32 CommandBufferPepper::GetGetOffset() { | 47 int32 CommandBufferPepper::GetGetOffset() { |
| 70 int32 value; | 48 int32 value; |
| 71 if (NPERR_NO_ERROR != device_->getStateContext( | 49 if (NPERR_NO_ERROR != device_->getStateContext( |
| 72 npp_, | 50 npp_, |
| 73 &context_, | 51 context_, |
| 74 NPDeviceContext3DState_GetOffset, | 52 NPDeviceContext3DState_GetOffset, |
| 75 &value)) { | 53 &value)) { |
| 76 return -1; | 54 return -1; |
| 77 } | 55 } |
| 78 | 56 |
| 79 return value; | 57 return value; |
| 80 } | 58 } |
| 81 | 59 |
| 82 void CommandBufferPepper::SetGetOffset(int32 get_offset) { | 60 void CommandBufferPepper::SetGetOffset(int32 get_offset) { |
| 83 // Not implemented by proxy. | 61 // Not implemented by proxy. |
| 84 NOTREACHED(); | 62 NOTREACHED(); |
| 85 } | 63 } |
| 86 | 64 |
| 87 int32 CommandBufferPepper::GetPutOffset() { | 65 int32 CommandBufferPepper::GetPutOffset() { |
| 88 int32 value; | 66 int32 value; |
| 89 if (NPERR_NO_ERROR != device_->getStateContext( | 67 if (NPERR_NO_ERROR != device_->getStateContext( |
| 90 npp_, | 68 npp_, |
| 91 &context_, | 69 context_, |
| 92 NPDeviceContext3DState_PutOffset, | 70 NPDeviceContext3DState_PutOffset, |
| 93 &value)) { | 71 &value)) { |
| 94 return -1; | 72 return -1; |
| 95 } | 73 } |
| 96 | 74 |
| 97 return value; | 75 return value; |
| 98 } | 76 } |
| 99 | 77 |
| 100 int32 CommandBufferPepper::CreateTransferBuffer(size_t size) { | 78 int32 CommandBufferPepper::CreateTransferBuffer(size_t size) { |
| 101 int32 id; | 79 int32 id; |
| 102 if (NPERR_NO_ERROR != device_->createBuffer(npp_, &context_, size, &id)) | 80 if (NPERR_NO_ERROR != device_->createBuffer(npp_, context_, size, &id)) |
| 103 return -1; | 81 return -1; |
| 104 | 82 |
| 105 return id; | 83 return id; |
| 106 } | 84 } |
| 107 | 85 |
| 108 void CommandBufferPepper::DestroyTransferBuffer(int32 id) { | 86 void CommandBufferPepper::DestroyTransferBuffer(int32 id) { |
| 109 device_->destroyBuffer(npp_, &context_, id); | 87 device_->destroyBuffer(npp_, context_, id); |
| 110 } | 88 } |
| 111 | 89 |
| 112 Buffer CommandBufferPepper::GetTransferBuffer(int32 id) { | 90 Buffer CommandBufferPepper::GetTransferBuffer(int32 id) { |
| 113 NPDeviceBuffer np_buffer; | 91 NPDeviceBuffer np_buffer; |
| 114 if (NPERR_NO_ERROR != device_->mapBuffer(npp_, &context_, id, &np_buffer)) | 92 if (NPERR_NO_ERROR != device_->mapBuffer(npp_, context_, id, &np_buffer)) |
| 115 return Buffer(); | 93 return Buffer(); |
| 116 | 94 |
| 117 Buffer buffer; | 95 Buffer buffer; |
| 118 buffer.ptr = np_buffer.ptr; | 96 buffer.ptr = np_buffer.ptr; |
| 119 buffer.size = np_buffer.size; | 97 buffer.size = np_buffer.size; |
| 120 return buffer; | 98 return buffer; |
| 121 } | 99 } |
| 122 | 100 |
| 123 int32 CommandBufferPepper::GetToken() { | 101 int32 CommandBufferPepper::GetToken() { |
| 124 int32 value; | 102 int32 value; |
| 125 if (NPERR_NO_ERROR != device_->getStateContext( | 103 if (NPERR_NO_ERROR != device_->getStateContext( |
| 126 npp_, | 104 npp_, |
| 127 &context_, | 105 context_, |
| 128 NPDeviceContext3DState_Token, | 106 NPDeviceContext3DState_Token, |
| 129 &value)) { | 107 &value)) { |
| 130 return -1; | 108 return -1; |
| 131 } | 109 } |
| 132 | 110 |
| 133 return value; | 111 return value; |
| 134 } | 112 } |
| 135 | 113 |
| 136 void CommandBufferPepper::SetToken(int32 token) { | 114 void CommandBufferPepper::SetToken(int32 token) { |
| 137 // Not implemented by proxy. | 115 // Not implemented by proxy. |
| 138 NOTREACHED(); | 116 NOTREACHED(); |
| 139 } | 117 } |
| 140 | 118 |
| 141 int32 CommandBufferPepper::ResetParseError() { | 119 int32 CommandBufferPepper::ResetParseError() { |
| 142 int32 value; | 120 int32 value; |
| 143 if (NPERR_NO_ERROR != device_->getStateContext( | 121 if (NPERR_NO_ERROR != device_->getStateContext( |
| 144 npp_, | 122 npp_, |
| 145 &context_, | 123 context_, |
| 146 NPDeviceContext3DState_ParseError, | 124 NPDeviceContext3DState_ParseError, |
| 147 &value)) { | 125 &value)) { |
| 148 return -1; | 126 return -1; |
| 149 } | 127 } |
| 150 | 128 |
| 151 return value; | 129 return value; |
| 152 } | 130 } |
| 153 | 131 |
| 154 void CommandBufferPepper::SetParseError(int32 parse_error) { | 132 void CommandBufferPepper::SetParseError(int32 parse_error) { |
| 155 // Not implemented by proxy. | 133 // Not implemented by proxy. |
| 156 NOTREACHED(); | 134 NOTREACHED(); |
| 157 } | 135 } |
| 158 | 136 |
| 159 bool CommandBufferPepper::GetErrorStatus() { | 137 bool CommandBufferPepper::GetErrorStatus() { |
| 160 int32 value; | 138 int32 value; |
| 161 if (NPERR_NO_ERROR != device_->getStateContext( | 139 if (NPERR_NO_ERROR != device_->getStateContext( |
| 162 npp_, | 140 npp_, |
| 163 &context_, | 141 context_, |
| 164 NPDeviceContext3DState_ErrorStatus, | 142 NPDeviceContext3DState_ErrorStatus, |
| 165 &value)) { | 143 &value)) { |
| 166 return value != 0; | 144 return value != 0; |
| 167 } | 145 } |
| 168 | 146 |
| 169 return true; | 147 return true; |
| 170 } | 148 } |
| 171 | 149 |
| 172 void CommandBufferPepper::RaiseErrorStatus() { | 150 void CommandBufferPepper::RaiseErrorStatus() { |
| 173 // Not implemented by proxy. | 151 // Not implemented by proxy. |
| 174 NOTREACHED(); | 152 NOTREACHED(); |
| 175 } | 153 } |
| OLD | NEW |