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