| OLD | NEW |
| 1 // Copyright (c) 2010 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 "gpu/command_buffer/common/constants.h" |
| 5 #include "gpu/pgl/command_buffer_pepper.h" | 6 #include "gpu/pgl/command_buffer_pepper.h" |
| 7 |
| 6 #ifdef __native_client__ | 8 #ifdef __native_client__ |
| 7 #include <assert.h> | 9 #include <assert.h> |
| 8 #define NOTREACHED() assert(0) | 10 #define NOTREACHED() assert(0) |
| 9 #else | 11 #else |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 #endif // __native_client__ | 13 #endif // __native_client__ |
| 12 | 14 |
| 13 using base::SharedMemory; | 15 using base::SharedMemory; |
| 14 using gpu::Buffer; | 16 using gpu::Buffer; |
| 17 using gpu::CommandBuffer; |
| 15 | 18 |
| 16 CommandBufferPepper::CommandBufferPepper(NPP npp, | 19 CommandBufferPepper::CommandBufferPepper(NPP npp, |
| 17 NPDevice* device, | 20 NPDevice* device, |
| 18 NPDeviceContext3D* context) | 21 NPDeviceContext3D* context) |
| 19 : npp_(npp), | 22 : npp_(npp), |
| 20 device_(device), | 23 device_(device), |
| 21 context_(context) { | 24 context_(context) { |
| 22 } | 25 } |
| 23 | 26 |
| 24 CommandBufferPepper::~CommandBufferPepper() { | 27 CommandBufferPepper::~CommandBufferPepper() { |
| 25 } | 28 } |
| 26 | 29 |
| 27 // Not implemented in CommandBufferPepper. | 30 // Not implemented in CommandBufferPepper. |
| 28 bool CommandBufferPepper::Initialize(int32 size) { | 31 bool CommandBufferPepper::Initialize(int32 size) { |
| 29 NOTREACHED(); | 32 NOTREACHED(); |
| 30 return false; | 33 return false; |
| 31 } | 34 } |
| 32 | 35 |
| 33 Buffer CommandBufferPepper::GetRingBuffer() { | 36 Buffer CommandBufferPepper::GetRingBuffer() { |
| 34 Buffer buffer; | 37 Buffer buffer; |
| 35 buffer.ptr = context_->commandBuffer; | 38 buffer.ptr = context_->commandBuffer; |
| 36 buffer.size = context_->commandBufferEntries * sizeof(int32); | 39 buffer.size = context_->commandBufferEntries * sizeof(int32); |
| 37 return buffer; | 40 return buffer; |
| 38 } | 41 } |
| 39 | 42 |
| 40 int32 CommandBufferPepper::GetSize() { | 43 CommandBuffer::State CommandBufferPepper::GetState() { |
| 41 return context_->commandBufferEntries; | 44 if (NPERR_NO_ERROR != device_->flushContext(npp_, context_, NULL, NULL)) |
| 45 context_->error = gpu::parse_error::kParseGenericError; |
| 46 |
| 47 return ConvertState(); |
| 42 } | 48 } |
| 43 | 49 |
| 44 int32 CommandBufferPepper::SyncOffsets(int32 put_offset) { | 50 CommandBuffer::State CommandBufferPepper::Flush(int32 put_offset) { |
| 45 context_->putOffset = put_offset; | 51 context_->putOffset = put_offset; |
| 52 |
| 46 if (NPERR_NO_ERROR != device_->flushContext(npp_, context_, NULL, NULL)) | 53 if (NPERR_NO_ERROR != device_->flushContext(npp_, context_, NULL, NULL)) |
| 47 return -1; | 54 context_->error = gpu::parse_error::kParseGenericError; |
| 48 | 55 |
| 49 return context_->getOffset; | 56 return ConvertState(); |
| 50 } | |
| 51 | |
| 52 int32 CommandBufferPepper::GetGetOffset() { | |
| 53 int32 value; | |
| 54 if (NPERR_NO_ERROR != device_->getStateContext( | |
| 55 npp_, | |
| 56 context_, | |
| 57 NPDeviceContext3DState_GetOffset, | |
| 58 &value)) { | |
| 59 return -1; | |
| 60 } | |
| 61 | |
| 62 return value; | |
| 63 } | 57 } |
| 64 | 58 |
| 65 void CommandBufferPepper::SetGetOffset(int32 get_offset) { | 59 void CommandBufferPepper::SetGetOffset(int32 get_offset) { |
| 66 // Not implemented by proxy. | 60 // Not implemented by proxy. |
| 67 NOTREACHED(); | 61 NOTREACHED(); |
| 68 } | 62 } |
| 69 | 63 |
| 70 int32 CommandBufferPepper::GetPutOffset() { | |
| 71 int32 value; | |
| 72 if (NPERR_NO_ERROR != device_->getStateContext( | |
| 73 npp_, | |
| 74 context_, | |
| 75 NPDeviceContext3DState_PutOffset, | |
| 76 &value)) { | |
| 77 return -1; | |
| 78 } | |
| 79 | |
| 80 return value; | |
| 81 } | |
| 82 | |
| 83 int32 CommandBufferPepper::CreateTransferBuffer(size_t size) { | 64 int32 CommandBufferPepper::CreateTransferBuffer(size_t size) { |
| 84 int32 id; | 65 int32 id; |
| 85 if (NPERR_NO_ERROR != device_->createBuffer(npp_, context_, size, &id)) | 66 if (NPERR_NO_ERROR != device_->createBuffer(npp_, context_, size, &id)) |
| 86 return -1; | 67 return -1; |
| 87 | 68 |
| 88 return id; | 69 return id; |
| 89 } | 70 } |
| 90 | 71 |
| 91 void CommandBufferPepper::DestroyTransferBuffer(int32 id) { | 72 void CommandBufferPepper::DestroyTransferBuffer(int32 id) { |
| 92 device_->destroyBuffer(npp_, context_, id); | 73 device_->destroyBuffer(npp_, context_, id); |
| 93 } | 74 } |
| 94 | 75 |
| 95 Buffer CommandBufferPepper::GetTransferBuffer(int32 id) { | 76 Buffer CommandBufferPepper::GetTransferBuffer(int32 id) { |
| 96 NPDeviceBuffer np_buffer; | 77 NPDeviceBuffer np_buffer; |
| 97 if (NPERR_NO_ERROR != device_->mapBuffer(npp_, context_, id, &np_buffer)) | 78 if (NPERR_NO_ERROR != device_->mapBuffer(npp_, context_, id, &np_buffer)) |
| 98 return Buffer(); | 79 return Buffer(); |
| 99 | 80 |
| 100 Buffer buffer; | 81 Buffer buffer; |
| 101 buffer.ptr = np_buffer.ptr; | 82 buffer.ptr = np_buffer.ptr; |
| 102 buffer.size = np_buffer.size; | 83 buffer.size = np_buffer.size; |
| 103 return buffer; | 84 return buffer; |
| 104 } | 85 } |
| 105 | 86 |
| 106 int32 CommandBufferPepper::GetToken() { | |
| 107 int32 value; | |
| 108 if (NPERR_NO_ERROR != device_->getStateContext( | |
| 109 npp_, | |
| 110 context_, | |
| 111 NPDeviceContext3DState_Token, | |
| 112 &value)) { | |
| 113 return -1; | |
| 114 } | |
| 115 | |
| 116 return value; | |
| 117 } | |
| 118 | |
| 119 void CommandBufferPepper::SetToken(int32 token) { | 87 void CommandBufferPepper::SetToken(int32 token) { |
| 120 // Not implemented by proxy. | 88 // Not implemented by proxy. |
| 121 NOTREACHED(); | 89 NOTREACHED(); |
| 122 } | 90 } |
| 123 | 91 |
| 124 int32 CommandBufferPepper::ResetParseError() { | 92 void CommandBufferPepper::SetParseError( |
| 125 int32 value; | 93 gpu::parse_error::ParseError parse_error) { |
| 126 if (NPERR_NO_ERROR != device_->getStateContext( | |
| 127 npp_, | |
| 128 context_, | |
| 129 NPDeviceContext3DState_ParseError, | |
| 130 &value)) { | |
| 131 return -1; | |
| 132 } | |
| 133 | |
| 134 return value; | |
| 135 } | |
| 136 | |
| 137 void CommandBufferPepper::SetParseError(int32 parse_error) { | |
| 138 // Not implemented by proxy. | 94 // Not implemented by proxy. |
| 139 NOTREACHED(); | 95 NOTREACHED(); |
| 140 } | 96 } |
| 141 | 97 |
| 142 bool CommandBufferPepper::GetErrorStatus() { | 98 CommandBuffer::State CommandBufferPepper::ConvertState() { |
| 143 int32 value; | 99 CommandBuffer::State state; |
| 144 if (NPERR_NO_ERROR != device_->getStateContext( | 100 state.size = context_->commandBufferEntries; |
| 145 npp_, | 101 state.get_offset = context_->getOffset; |
| 146 context_, | 102 state.put_offset = context_->putOffset; |
| 147 NPDeviceContext3DState_ErrorStatus, | 103 state.token = context_->token; |
| 148 &value)) { | 104 state.error = static_cast<gpu::parse_error::ParseError>( |
| 149 return value != 0; | 105 context_->error); |
| 150 } | 106 return state; |
| 151 | |
| 152 return true; | |
| 153 } | 107 } |
| 154 | |
| 155 void CommandBufferPepper::RaiseErrorStatus() { | |
| 156 // Not implemented by proxy. | |
| 157 NOTREACHED(); | |
| 158 } | |
| OLD | NEW |