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