summaryrefslogtreecommitdiffstats
path: root/gpu
diff options
context:
space:
mode:
authorapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-22 23:28:15 +0000
committerapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-22 23:28:15 +0000
commit7477ea6f6a173b586622fd276433a346760ffbf4 (patch)
tree678229a49ae5c4bb1a54a61374466cdddf57db59 /gpu
parente4f7cec0a45a803faf00875a070090b165ff1fc5 (diff)
downloadchromium_src-7477ea6f6a173b586622fd276433a346760ffbf4.zip
chromium_src-7477ea6f6a173b586622fd276433a346760ffbf4.tar.gz
chromium_src-7477ea6f6a173b586622fd276433a346760ffbf4.tar.bz2
Added Pepper 3D device that instantiates the GPU plugin and sends GLES2 commands to it via a command buffer.
Added API for managing buffers to Pepper 3D device. Removed DCHECK from WebPluginImpl::SetWindow that checks against a windowless plugin being given a window handle. Please check this! Now an initially windowless plugin instance gets a handle when it requests a Pepper 3D context. Perhaps the window handle should be concealed from the underlying plugin isntance. Removed enable_gpu gyp variable and C macro. GPU code is always built on windows but not mac or linux. It is enabled at runtime with the --enable-gpu-plugin switch. Redesigned CommandBuffer interface so it exposes shared memory through a Buffer. This was necessary because Pepper has no notion of shared memory handles. The Buffer exposes the shared memory as both a handle (through base::SharedMemory) and the mapped address and size. Refactored CommandBufferEngine so mapped shared memory addresses and sizes are returned with a single call rather than two separate calls. Added 3D demo to pepper test plugin. TEST=try servers BUG=none Review URL: http://codereview.chromium.org/367002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35185 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r--gpu/command_buffer/client/cmd_buffer_helper.cc10
-rw-r--r--gpu/command_buffer/client/cmd_buffer_helper.h6
-rw-r--r--gpu/command_buffer/client/cmd_buffer_helper_test.cc21
-rw-r--r--gpu/command_buffer/client/fenced_allocator.h2
-rw-r--r--gpu/command_buffer/client/fenced_allocator_test.cc20
-rw-r--r--gpu/command_buffer/client/gles2_cmd_helper.h2
-rw-r--r--gpu/command_buffer/client/gles2_demo.cc18
-rw-r--r--gpu/command_buffer/client/gles2_implementation.h1
-rw-r--r--gpu/command_buffer/client/id_allocator.h6
-rw-r--r--gpu/command_buffer/client/id_allocator_test.cc2
-rw-r--r--gpu/command_buffer/common/buffer.h29
-rw-r--r--gpu/command_buffer/common/command_buffer.h16
-rw-r--r--gpu/command_buffer/common/command_buffer_mock.h10
-rw-r--r--gpu/command_buffer/common/gles2_cmd_format.h8
-rw-r--r--gpu/command_buffer/common/resource.h1
-rw-r--r--gpu/command_buffer/service/cmd_buffer_engine.h10
-rw-r--r--gpu/command_buffer/service/command_buffer_service.cc44
-rw-r--r--gpu/command_buffer/service/command_buffer_service.h6
-rw-r--r--gpu/command_buffer/service/command_buffer_service_unittest.cc37
-rw-r--r--gpu/command_buffer/service/common_decoder.cc10
-rw-r--r--gpu/command_buffer/service/common_decoder_unittest.cc14
-rw-r--r--gpu/command_buffer/service/gpu_processor.cc36
-rw-r--r--gpu/command_buffer/service/gpu_processor.h19
-rw-r--r--gpu/command_buffer/service/gpu_processor_mock.h6
-rw-r--r--gpu/command_buffer/service/gpu_processor_unittest.cc90
-rw-r--r--gpu/command_buffer/service/gpu_processor_win.cc35
-rw-r--r--gpu/gpu.gyp31
-rw-r--r--gpu/gpu_plugin/gpu_plugin.cc6
-rw-r--r--gpu/gpu_plugin/gpu_plugin.h8
29 files changed, 247 insertions, 257 deletions
diff --git a/gpu/command_buffer/client/cmd_buffer_helper.cc b/gpu/command_buffer/client/cmd_buffer_helper.cc
index 3d3f9af..45c0866 100644
--- a/gpu/command_buffer/client/cmd_buffer_helper.cc
+++ b/gpu/command_buffer/client/cmd_buffer_helper.cc
@@ -9,8 +9,6 @@
namespace gpu {
-using gpu::CommandBuffer;
-
CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer)
: command_buffer_(command_buffer),
entries_(NULL),
@@ -23,14 +21,10 @@ CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer)
bool CommandBufferHelper::Initialize() {
ring_buffer_ = command_buffer_->GetRingBuffer();
- if (!ring_buffer_)
- return false;
-
- // Map the ring buffer into this process.
- if (!ring_buffer_->Map(ring_buffer_->max_size()))
+ if (!ring_buffer_.ptr)
return false;
- entries_ = static_cast<CommandBufferEntry*>(ring_buffer_->memory());
+ entries_ = static_cast<CommandBufferEntry*>(ring_buffer_.ptr);
entry_count_ = command_buffer_->GetSize();
get_ = command_buffer_->GetGetOffset();
put_ = command_buffer_->GetPutOffset();
diff --git a/gpu/command_buffer/client/cmd_buffer_helper.h b/gpu/command_buffer/client/cmd_buffer_helper.h
index 1f191f1..6c134fa 100644
--- a/gpu/command_buffer/client/cmd_buffer_helper.h
+++ b/gpu/command_buffer/client/cmd_buffer_helper.h
@@ -31,7 +31,7 @@ namespace gpu {
// // commands have been executed.
class CommandBufferHelper {
public:
- explicit CommandBufferHelper(gpu::CommandBuffer* command_buffer);
+ explicit CommandBufferHelper(CommandBuffer* command_buffer);
virtual ~CommandBufferHelper();
bool Initialize();
@@ -170,8 +170,8 @@ class CommandBufferHelper {
return (get_ - put_ - 1 + entry_count_) % entry_count_;
}
- gpu::CommandBuffer* command_buffer_;
- ::base::SharedMemory* ring_buffer_;
+ CommandBuffer* command_buffer_;
+ Buffer ring_buffer_;
CommandBufferEntry *entries_;
int32 entry_count_;
int32 token_;
diff --git a/gpu/command_buffer/client/cmd_buffer_helper_test.cc b/gpu/command_buffer/client/cmd_buffer_helper_test.cc
index 4c915fc..6c8fa6c 100644
--- a/gpu/command_buffer/client/cmd_buffer_helper_test.cc
+++ b/gpu/command_buffer/client/cmd_buffer_helper_test.cc
@@ -14,8 +14,6 @@
namespace gpu {
-using gpu::CommandBufferService;
-using gpu::GPUProcessor;
using testing::Return;
using testing::Mock;
using testing::Truly;
@@ -41,16 +39,15 @@ class CommandBufferHelperTest : public testing::Test {
.WillRepeatedly(Return(parse_error::kParseNoError));
command_buffer_.reset(new CommandBufferService);
- base::SharedMemory* ring_buffer = command_buffer_->Initialize(
- kNumCommandEntries);
+ command_buffer_->Initialize(kNumCommandEntries);
+ Buffer ring_buffer = command_buffer_->GetRingBuffer();
-
- parser_ = new gpu::CommandParser(ring_buffer->memory(),
- kCommandBufferSizeBytes,
- 0,
- kCommandBufferSizeBytes,
- 0,
- api_mock_.get());
+ parser_ = new CommandParser(ring_buffer.ptr,
+ ring_buffer.size,
+ 0,
+ ring_buffer.size,
+ 0,
+ api_mock_.get());
scoped_refptr<GPUProcessor> gpu_processor(new GPUProcessor(
command_buffer_.get(), NULL, parser_, 1));
@@ -111,7 +108,7 @@ class CommandBufferHelperTest : public testing::Test {
MessageLoop message_loop_;
scoped_ptr<AsyncAPIMock> api_mock_;
scoped_ptr<CommandBufferService> command_buffer_;
- gpu::CommandParser* parser_;
+ CommandParser* parser_;
scoped_ptr<CommandBufferHelper> helper_;
Sequence sequence_;
};
diff --git a/gpu/command_buffer/client/fenced_allocator.h b/gpu/command_buffer/client/fenced_allocator.h
index 83584c4..ab68c1a 100644
--- a/gpu/command_buffer/client/fenced_allocator.h
+++ b/gpu/command_buffer/client/fenced_allocator.h
@@ -128,7 +128,7 @@ class FencedAllocator {
// the other functions that return a block index).
Offset AllocInBlock(BlockIndex index, unsigned int size);
- gpu::CommandBufferHelper *helper_;
+ CommandBufferHelper *helper_;
Container blocks_;
DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocator);
diff --git a/gpu/command_buffer/client/fenced_allocator_test.cc b/gpu/command_buffer/client/fenced_allocator_test.cc
index 4c621fa..a086463 100644
--- a/gpu/command_buffer/client/fenced_allocator_test.cc
+++ b/gpu/command_buffer/client/fenced_allocator_test.cc
@@ -16,8 +16,6 @@
namespace gpu {
-using gpu::CommandBufferService;
-using gpu::GPUProcessor;
using testing::Return;
using testing::Mock;
using testing::Truly;
@@ -42,15 +40,15 @@ class BaseFencedAllocatorTest : public testing::Test {
Return(parse_error::kParseNoError)));
command_buffer_.reset(new CommandBufferService);
- base::SharedMemory* ring_buffer = command_buffer_->Initialize(
- kBufferSize / sizeof(CommandBufferEntry));
+ command_buffer_->Initialize(kBufferSize / sizeof(CommandBufferEntry));
+ Buffer ring_buffer = command_buffer_->GetRingBuffer();
- parser_ = new gpu::CommandParser(ring_buffer->memory(),
- kBufferSize,
- 0,
- kBufferSize,
- 0,
- api_mock_.get());
+ parser_ = new CommandParser(ring_buffer.ptr,
+ ring_buffer.size,
+ 0,
+ ring_buffer.size,
+ 0,
+ api_mock_.get());
scoped_refptr<GPUProcessor> gpu_processor(new GPUProcessor(
command_buffer_.get(), NULL, parser_, INT_MAX));
@@ -71,7 +69,7 @@ class BaseFencedAllocatorTest : public testing::Test {
MessageLoop message_loop_;
scoped_ptr<AsyncAPIMock> api_mock_;
scoped_ptr<CommandBufferService> command_buffer_;
- gpu::CommandParser* parser_;
+ CommandParser* parser_;
scoped_ptr<CommandBufferHelper> helper_;
};
diff --git a/gpu/command_buffer/client/gles2_cmd_helper.h b/gpu/command_buffer/client/gles2_cmd_helper.h
index 383e7e5..015ce0e 100644
--- a/gpu/command_buffer/client/gles2_cmd_helper.h
+++ b/gpu/command_buffer/client/gles2_cmd_helper.h
@@ -14,7 +14,7 @@ namespace gles2 {
// A class that helps write GL command buffers.
class GLES2CmdHelper : public CommandBufferHelper {
public:
- explicit GLES2CmdHelper(gpu::CommandBuffer* command_buffer)
+ explicit GLES2CmdHelper(CommandBuffer* command_buffer)
: CommandBufferHelper(command_buffer) {
}
virtual ~GLES2CmdHelper() {
diff --git a/gpu/command_buffer/client/gles2_demo.cc b/gpu/command_buffer/client/gles2_demo.cc
index 465aa83..5b99f01 100644
--- a/gpu/command_buffer/client/gles2_demo.cc
+++ b/gpu/command_buffer/client/gles2_demo.cc
@@ -25,6 +25,7 @@
#include "gpu/command_buffer/client/gles2_demo_cc.h"
using base::SharedMemory;
+using gpu::Buffer;
using gpu::GPUProcessor;
using gpu::CommandBufferService;
using gpu::gles2::GLES2CmdHelper;
@@ -45,9 +46,8 @@ GLES2Demo::GLES2Demo() {
bool GLES2Demo::Setup(void* hwnd, int32 size) {
scoped_ptr<CommandBufferService> command_buffer(new CommandBufferService);
- if (!command_buffer->Initialize(size)) {
+ if (!command_buffer->Initialize(size))
return NULL;
- }
scoped_refptr<GPUProcessor> gpu_processor(
new GPUProcessor(command_buffer.get()));
@@ -67,19 +67,15 @@ bool GLES2Demo::Setup(void* hwnd, int32 size) {
size_t transfer_buffer_size = 512 * 1024;
int32 transfer_buffer_id =
command_buffer->CreateTransferBuffer(transfer_buffer_size);
- ::base::SharedMemory* shared_memory =
+ Buffer transfer_buffer =
command_buffer->GetTransferBuffer(transfer_buffer_id);
- if (!shared_memory->Map(transfer_buffer_size)) {
- return false;
- }
- void* transfer_buffer = shared_memory->memory();
- if (!transfer_buffer) {
+ if (!transfer_buffer.ptr)
return false;
- }
+
gles2::g_gl_impl = new GLES2Implementation(helper,
- transfer_buffer_size,
- transfer_buffer,
+ transfer_buffer.size,
+ transfer_buffer.ptr,
transfer_buffer_id);
return command_buffer.release() != NULL;
diff --git a/gpu/command_buffer/client/gles2_implementation.h b/gpu/command_buffer/client/gles2_implementation.h
index 6cdf22e..6415d67 100644
--- a/gpu/command_buffer/client/gles2_implementation.h
+++ b/gpu/command_buffer/client/gles2_implementation.h
@@ -5,7 +5,6 @@
#ifndef GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_
#define GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_
-#include "base/shared_memory.h"
#include "gpu/command_buffer/common/gles2_cmd_utils.h"
#include "gpu/command_buffer/client/gles2_cmd_helper.h"
#include "gpu/command_buffer/client/id_allocator.h"
diff --git a/gpu/command_buffer/client/id_allocator.h b/gpu/command_buffer/client/id_allocator.h
index 2b78f98..2731366 100644
--- a/gpu/command_buffer/client/id_allocator.h
+++ b/gpu/command_buffer/client/id_allocator.h
@@ -21,19 +21,19 @@ class IdAllocator {
IdAllocator();
// Allocates a new resource ID.
- gpu::ResourceId AllocateID() {
+ ResourceId AllocateID() {
unsigned int bit = FindFirstFree();
SetBit(bit, true);
return bit;
}
// Frees a resource ID.
- void FreeID(gpu::ResourceId id) {
+ void FreeID(ResourceId id) {
SetBit(id, false);
}
// Checks whether or not a resource ID is in use.
- bool InUse(gpu::ResourceId id) {
+ bool InUse(ResourceId id) {
return GetBit(id);
}
private:
diff --git a/gpu/command_buffer/client/id_allocator_test.cc b/gpu/command_buffer/client/id_allocator_test.cc
index d764f01..df457db 100644
--- a/gpu/command_buffer/client/id_allocator_test.cc
+++ b/gpu/command_buffer/client/id_allocator_test.cc
@@ -9,8 +9,6 @@
namespace gpu {
-using gpu::ResourceId;
-
class IdAllocatorTest : public testing::Test {
protected:
virtual void SetUp() {}
diff --git a/gpu/command_buffer/common/buffer.h b/gpu/command_buffer/common/buffer.h
new file mode 100644
index 0000000..ed3cdf5
--- /dev/null
+++ b/gpu/command_buffer/common/buffer.h
@@ -0,0 +1,29 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef GPU_COMMAND_BUFFER_COMMON_BUFFER_H_
+#define GPU_COMMAND_BUFFER_COMMON_BUFFER_H_
+
+namespace base {
+ class SharedMemory;
+}
+
+namespace gpu {
+
+// Address and size of a buffer and optionally a shared memory object. This
+// type has value semantics.
+struct Buffer {
+ Buffer() : ptr(NULL), size(0), shared_memory(NULL) {
+ }
+
+ void* ptr;
+ size_t size;
+
+ // Null if the buffer is not shared memory or if it is not exposed as such.
+ base::SharedMemory* shared_memory;
+};
+
+} // namespace gpu
+
+#endif // GPU_COMMAND_BUFFER_COMMON_BUFFER_H_
diff --git a/gpu/command_buffer/common/command_buffer.h b/gpu/command_buffer/common/command_buffer.h
index 92e38ff..0f1f0f3 100644
--- a/gpu/command_buffer/common/command_buffer.h
+++ b/gpu/command_buffer/common/command_buffer.h
@@ -5,8 +5,8 @@
#ifndef GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_
#define GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_
-#include "base/shared_memory.h"
#include "base/task.h"
+#include "gpu/command_buffer/common/buffer.h"
namespace gpu {
@@ -21,10 +21,10 @@ class CommandBuffer {
// Initialize the command buffer with the given size (number of command
// entries).
- virtual base::SharedMemory* Initialize(int32 size) = 0;
+ virtual bool Initialize(int32 size) = 0;
- // Gets the shared memory ring buffer object for the command buffer.
- virtual base::SharedMemory* GetRingBuffer() = 0;
+ // Gets the ring buffer for the command buffer.
+ virtual Buffer GetRingBuffer() = 0;
virtual int32 GetSize() = 0;
@@ -54,15 +54,15 @@ class CommandBuffer {
// Takes ownership of callback. The callback is invoked on the plugin thread.
virtual void SetPutOffsetChangeCallback(Callback0::Type* callback) = 0;
- // Create a shared memory transfer buffer and return a handle that uniquely
+ // Create a transfer buffer and return a handle that uniquely
// identifies it or -1 on error.
virtual int32 CreateTransferBuffer(size_t size) = 0;
- // Destroy a shared memory transfer buffer and recycle the handle.
+ // Destroy a transfer buffer and recycle the handle.
virtual void DestroyTransferBuffer(int32 id) = 0;
- // Get the shared memory associated with a handle.
- virtual base::SharedMemory* GetTransferBuffer(int32 handle) = 0;
+ // Get the transfer buffer associated with a handle.
+ virtual Buffer GetTransferBuffer(int32 handle) = 0;
// Get the current token value. This is used for by the writer to defer
// changes to shared memory objects until the reader has reached a certain
diff --git a/gpu/command_buffer/common/command_buffer_mock.h b/gpu/command_buffer/common/command_buffer_mock.h
index 79d5682..0048ac1 100644
--- a/gpu/command_buffer/common/command_buffer_mock.h
+++ b/gpu/command_buffer/common/command_buffer_mock.h
@@ -16,13 +16,13 @@ class MockCommandBuffer : public CommandBuffer {
public:
MockCommandBuffer() {
ON_CALL(*this, GetRingBuffer())
- .WillByDefault(testing::Return(static_cast<base::SharedMemory*>(NULL)));
+ .WillByDefault(testing::Return(Buffer()));
ON_CALL(*this, GetTransferBuffer(testing::_))
- .WillByDefault(testing::Return(static_cast<base::SharedMemory*>(NULL)));
+ .WillByDefault(testing::Return(Buffer()));
}
- MOCK_METHOD1(Initialize, base::SharedMemory*(int32 size));
- MOCK_METHOD0(GetRingBuffer, base::SharedMemory*());
+ MOCK_METHOD1(Initialize, bool(int32 size));
+ MOCK_METHOD0(GetRingBuffer, Buffer());
MOCK_METHOD0(GetSize, int32());
MOCK_METHOD1(SyncOffsets, int32(int32 put_offset));
MOCK_METHOD0(GetGetOffset, int32());
@@ -31,7 +31,7 @@ class MockCommandBuffer : public CommandBuffer {
MOCK_METHOD1(SetPutOffsetChangeCallback, void(Callback0::Type* callback));
MOCK_METHOD1(CreateTransferBuffer, int32(size_t size));
MOCK_METHOD1(DestroyTransferBuffer, void(int32 handle));
- MOCK_METHOD1(GetTransferBuffer, base::SharedMemory*(int32 handle));
+ MOCK_METHOD1(GetTransferBuffer, Buffer(int32 handle));
MOCK_METHOD0(GetToken, int32());
MOCK_METHOD1(SetToken, void(int32 token));
MOCK_METHOD0(ResetParseError, int32());
diff --git a/gpu/command_buffer/common/gles2_cmd_format.h b/gpu/command_buffer/common/gles2_cmd_format.h
index 8b37982..e6f2b78 100644
--- a/gpu/command_buffer/common/gles2_cmd_format.h
+++ b/gpu/command_buffer/common/gles2_cmd_format.h
@@ -69,7 +69,7 @@ struct GetAttribLocation {
return NextCmdAddress<ValueType>(cmd);
}
- gpu::CommandHeader header;
+ CommandHeader header;
uint32 program;
uint32 name_shm_id;
uint32 name_shm_offset;
@@ -132,7 +132,7 @@ struct GetAttribLocationImmediate {
return NextImmediateCmdAddressTotalSize<ValueType>(cmd, total_size);
}
- gpu::CommandHeader header;
+ CommandHeader header;
uint32 program;
uint32 location_shm_id;
uint32 location_shm_offset;
@@ -189,7 +189,7 @@ struct GetUniformLocation {
return NextCmdAddress<ValueType>(cmd);
}
- gpu::CommandHeader header;
+ CommandHeader header;
uint32 program;
uint32 name_shm_id;
uint32 name_shm_offset;
@@ -252,7 +252,7 @@ struct GetUniformLocationImmediate {
return NextImmediateCmdAddressTotalSize<ValueType>(cmd, total_size);
}
- gpu::CommandHeader header;
+ CommandHeader header;
uint32 program;
uint32 location_shm_id;
uint32 location_shm_offset;
diff --git a/gpu/command_buffer/common/resource.h b/gpu/command_buffer/common/resource.h
index 2dae7df..f72395a 100644
--- a/gpu/command_buffer/common/resource.h
+++ b/gpu/command_buffer/common/resource.h
@@ -10,7 +10,6 @@
#include <algorithm>
#include "base/basictypes.h"
-#include "base/scoped_ptr.h"
#include "gpu/command_buffer/common/types.h"
#include "gpu/command_buffer/common/logging.h"
diff --git a/gpu/command_buffer/service/cmd_buffer_engine.h b/gpu/command_buffer/service/cmd_buffer_engine.h
index 7457a2f..09419a0 100644
--- a/gpu/command_buffer/service/cmd_buffer_engine.h
+++ b/gpu/command_buffer/service/cmd_buffer_engine.h
@@ -9,6 +9,7 @@
#define GPU_COMMAND_BUFFER_SERVICE_CMD_BUFFER_ENGINE_H_
#include "base/basictypes.h"
+#include "gpu/command_buffer/common/buffer.h"
namespace gpu {
@@ -20,15 +21,10 @@ class CommandBufferEngine {
virtual ~CommandBufferEngine() {
}
- // Gets the base address of a registered shared memory buffer.
+ // Gets the base address and size of a registered shared memory buffer.
// Parameters:
// shm_id: the identifier for the shared memory buffer.
- virtual void *GetSharedMemoryAddress(int32 shm_id) = 0;
-
- // Gets the size of a registered shared memory buffer.
- // Parameters:
- // shm_id: the identifier for the shared memory buffer.
- virtual size_t GetSharedMemorySize(int32 shm_id) = 0;
+ virtual Buffer GetSharedMemoryBuffer(int32 shm_id) = 0;
// Sets the token value.
virtual void set_token(int32 token) = 0;
diff --git a/gpu/command_buffer/service/command_buffer_service.cc b/gpu/command_buffer/service/command_buffer_service.cc
index e2dffec..17e7a61 100644
--- a/gpu/command_buffer/service/command_buffer_service.cc
+++ b/gpu/command_buffer/service/command_buffer_service.cc
@@ -6,6 +6,8 @@
#include <limits>
+#include "gpu/command_buffer/common/cmd_buffer_common.h"
+
using ::base::SharedMemory;
namespace gpu {
@@ -24,7 +26,7 @@ CommandBufferService::CommandBufferService()
CommandBufferService::~CommandBufferService() {
}
-base::SharedMemory* CommandBufferService::Initialize(int32 size) {
+bool CommandBufferService::Initialize(int32 size) {
// Fail if already initialized.
if (ring_buffer_.get())
return false;
@@ -32,17 +34,24 @@ base::SharedMemory* CommandBufferService::Initialize(int32 size) {
size_ = size;
ring_buffer_.reset(new SharedMemory);
- if (ring_buffer_->Create(std::wstring(), false, false, size_)) {
- if (ring_buffer_->Map(size_))
- return ring_buffer_.get();
+ size_t size_bytes = size * sizeof(CommandBufferEntry);
+ if (ring_buffer_->Create(std::wstring(), false, false, size_bytes)) {
+ if (ring_buffer_->Map(size_bytes))
+ return true;
}
ring_buffer_.reset();
- return NULL;
+ return false;
}
-SharedMemory* CommandBufferService::GetRingBuffer() {
- return ring_buffer_.get();
+Buffer CommandBufferService::GetRingBuffer() {
+ Buffer buffer;
+ if (ring_buffer_.get()) {
+ buffer.ptr = ring_buffer_->memory();
+ buffer.size = ring_buffer_->max_size();
+ buffer.shared_memory = ring_buffer_.get();
+ }
+ return buffer;
}
int32 CommandBufferService::GetSize() {
@@ -123,14 +132,27 @@ void CommandBufferService::DestroyTransferBuffer(int32 handle) {
}
}
-::base::SharedMemory* CommandBufferService::GetTransferBuffer(int32 handle) {
+Buffer CommandBufferService::GetTransferBuffer(int32 handle) {
if (handle < 0)
- return NULL;
+ return Buffer();
if (static_cast<size_t>(handle) >= registered_objects_.size())
- return NULL;
+ return Buffer();
+
+ base::SharedMemory* shared_memory = registered_objects_[handle].get();
+ if (!shared_memory)
+ return Buffer();
+
+ if (!shared_memory->memory()) {
+ if (!shared_memory->Map(shared_memory->max_size()))
+ return Buffer();
+ }
- return registered_objects_[handle].get();
+ Buffer buffer;
+ buffer.ptr = shared_memory->memory();
+ buffer.size = shared_memory->max_size();
+ buffer.shared_memory = shared_memory;
+ return buffer;
}
int32 CommandBufferService::GetToken() {
diff --git a/gpu/command_buffer/service/command_buffer_service.h b/gpu/command_buffer/service/command_buffer_service.h
index 6784581..18860ea 100644
--- a/gpu/command_buffer/service/command_buffer_service.h
+++ b/gpu/command_buffer/service/command_buffer_service.h
@@ -24,8 +24,8 @@ class CommandBufferService : public CommandBuffer {
virtual ~CommandBufferService();
// CommandBuffer implementation:
- virtual base::SharedMemory* Initialize(int32 size);
- virtual base::SharedMemory* GetRingBuffer();
+ virtual bool Initialize(int32 size);
+ virtual Buffer GetRingBuffer();
virtual int32 GetSize();
virtual int32 SyncOffsets(int32 put_offset);
virtual int32 GetGetOffset();
@@ -34,7 +34,7 @@ class CommandBufferService : public CommandBuffer {
virtual void SetPutOffsetChangeCallback(Callback0::Type* callback);
virtual int32 CreateTransferBuffer(size_t size);
virtual void DestroyTransferBuffer(int32 id);
- virtual base::SharedMemory* GetTransferBuffer(int32 handle);
+ virtual Buffer GetTransferBuffer(int32 handle);
virtual int32 GetToken();
virtual void SetToken(int32 token);
virtual int32 ResetParseError();
diff --git a/gpu/command_buffer/service/command_buffer_service_unittest.cc b/gpu/command_buffer/service/command_buffer_service_unittest.cc
index b5749af..98ec0ec 100644
--- a/gpu/command_buffer/service/command_buffer_service_unittest.cc
+++ b/gpu/command_buffer/service/command_buffer_service_unittest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/thread.h"
+#include "gpu/command_buffer/common/cmd_buffer_common.h"
#include "gpu/command_buffer/service/command_buffer_service.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -26,20 +27,28 @@ class CommandBufferServiceTest : public testing::Test {
};
TEST_F(CommandBufferServiceTest, NullRingBufferByDefault) {
- EXPECT_TRUE(NULL == command_buffer_->GetRingBuffer());
+ EXPECT_TRUE(NULL == command_buffer_->GetRingBuffer().ptr);
}
TEST_F(CommandBufferServiceTest, InitializesCommandBuffer) {
- base::SharedMemory* ring_buffer = command_buffer_->Initialize(1024);
- EXPECT_TRUE(NULL != ring_buffer);
- EXPECT_EQ(ring_buffer, command_buffer_->GetRingBuffer());
- EXPECT_GT(command_buffer_->GetSize(), 0);
+ EXPECT_TRUE(command_buffer_->Initialize(1024));
+ EXPECT_TRUE(NULL != command_buffer_->GetRingBuffer().ptr);
+ EXPECT_EQ(1024, command_buffer_->GetSize());
+ EXPECT_EQ(1024 * sizeof(CommandBufferEntry),
+ command_buffer_->GetRingBuffer().size);
+}
+
+TEST_F(CommandBufferServiceTest, InitializationSizeIsInEntriesNotBytes) {
+ EXPECT_TRUE(command_buffer_->Initialize(1024));
+ EXPECT_TRUE(NULL != command_buffer_->GetRingBuffer().ptr);
+ EXPECT_GE(1024 * sizeof(CommandBufferEntry),
+ command_buffer_->GetRingBuffer().size);
}
TEST_F(CommandBufferServiceTest, InitializeFailsSecondTime) {
SharedMemory* ring_buffer = new SharedMemory;
- EXPECT_TRUE(NULL != command_buffer_->Initialize(1024));
- EXPECT_TRUE(NULL == command_buffer_->Initialize(1024));
+ EXPECT_TRUE(command_buffer_->Initialize(1024));
+ EXPECT_FALSE(command_buffer_->Initialize(1024));
}
TEST_F(CommandBufferServiceTest, GetAndPutOffsetsDefaultToZero) {
@@ -77,23 +86,23 @@ TEST_F(CommandBufferServiceTest, CanSyncGetAndPutOffset) {
}
TEST_F(CommandBufferServiceTest, ZeroHandleMapsToNull) {
- EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(0));
+ EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(0).ptr);
}
TEST_F(CommandBufferServiceTest, NegativeHandleMapsToNull) {
- EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(-1));
+ EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(-1).ptr);
}
TEST_F(CommandBufferServiceTest, OutOfRangeHandleMapsToNull) {
- EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(1));
+ EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(1).ptr);
}
TEST_F(CommandBufferServiceTest, CanCreateTransferBuffers) {
int32 handle = command_buffer_->CreateTransferBuffer(1024);
EXPECT_EQ(1, handle);
- SharedMemory* buffer = command_buffer_->GetTransferBuffer(handle);
- ASSERT_TRUE(NULL != buffer);
- EXPECT_EQ(1024, buffer->max_size());
+ Buffer buffer = command_buffer_->GetTransferBuffer(handle);
+ ASSERT_TRUE(NULL != buffer.ptr);
+ EXPECT_EQ(1024, buffer.size);
}
TEST_F(CommandBufferServiceTest, CreateTransferBufferReturnsDistinctHandles) {
@@ -111,7 +120,7 @@ TEST_F(CommandBufferServiceTest,
TEST_F(CommandBufferServiceTest, CannotUnregisterHandleZero) {
command_buffer_->DestroyTransferBuffer(0);
- EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(0));
+ EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(0).ptr);
EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024));
}
diff --git a/gpu/command_buffer/service/common_decoder.cc b/gpu/command_buffer/service/common_decoder.cc
index 591dfb7..4d3623d 100644
--- a/gpu/command_buffer/service/common_decoder.cc
+++ b/gpu/command_buffer/service/common_decoder.cc
@@ -35,14 +35,14 @@ bool CommonDecoder::Bucket::SetData(
void* CommonDecoder::GetAddressAndCheckSize(unsigned int shm_id,
unsigned int offset,
unsigned int size) {
- void* shm_addr = engine_->GetSharedMemoryAddress(shm_id);
- if (!shm_addr) return NULL;
- size_t shm_size = engine_->GetSharedMemorySize(shm_id);
+ Buffer buffer = engine_->GetSharedMemoryBuffer(shm_id);
+ if (!buffer.ptr)
+ return NULL;
unsigned int end = offset + size;
- if (end > shm_size || end < offset) {
+ if (end > buffer.size || end < offset) {
return NULL;
}
- return static_cast<int8 *>(shm_addr) + offset;
+ return static_cast<int8*>(buffer.ptr) + offset;
}
const char* CommonDecoder::GetCommonCommandName(
diff --git a/gpu/command_buffer/service/common_decoder_unittest.cc b/gpu/command_buffer/service/common_decoder_unittest.cc
index 54f1941..9a2db70 100644
--- a/gpu/command_buffer/service/common_decoder_unittest.cc
+++ b/gpu/command_buffer/service/common_decoder_unittest.cc
@@ -78,13 +78,13 @@ class MockCommandBufferEngine : public CommandBufferEngine {
}
// Overridden from CommandBufferEngine.
- virtual void* GetSharedMemoryAddress(int32 shm_id) {
- return (shm_id == kValidShmId) ? buffer_ : NULL;
- }
-
- // Overridden from CommandBufferEngine.
- virtual size_t GetSharedMemorySize(int32 shm_id) {
- return (shm_id == kValidShmId) ? kBufferSize : 0;
+ virtual Buffer GetSharedMemoryBuffer(int32 shm_id) {
+ Buffer buffer;
+ if (shm_id == kValidShmId) {
+ buffer.ptr = buffer_;
+ buffer.size = kBufferSize;
+ }
+ return buffer;
}
template <typename T>
diff --git a/gpu/command_buffer/service/gpu_processor.cc b/gpu/command_buffer/service/gpu_processor.cc
index 61449c0..0968215 100644
--- a/gpu/command_buffer/service/gpu_processor.cc
+++ b/gpu/command_buffer/service/gpu_processor.cc
@@ -20,16 +20,15 @@ void GPUProcessor::ProcessCommands() {
int commands_processed = 0;
while (commands_processed < commands_per_update_ && !parser_->IsEmpty()) {
- gpu::parse_error::ParseError parse_error =
- parser_->ProcessCommand();
+ parse_error::ParseError parse_error = parser_->ProcessCommand();
switch (parse_error) {
- case gpu::parse_error::kParseUnknownCommand:
- case gpu::parse_error::kParseInvalidArguments:
+ case parse_error::kParseUnknownCommand:
+ case parse_error::kParseInvalidArguments:
command_buffer_->SetParseError(parse_error);
break;
- case gpu::parse_error::kParseInvalidSize:
- case gpu::parse_error::kParseOutOfBounds:
+ case parse_error::kParseInvalidSize:
+ case parse_error::kParseOutOfBounds:
command_buffer_->SetParseError(parse_error);
command_buffer_->RaiseErrorStatus();
return;
@@ -46,29 +45,8 @@ void GPUProcessor::ProcessCommands() {
}
}
-void *GPUProcessor::GetSharedMemoryAddress(int32 shm_id) {
- ::base::SharedMemory* shared_memory =
- command_buffer_->GetTransferBuffer(shm_id);
- if (!shared_memory)
- return NULL;
-
- if (!shared_memory->memory()) {
- if (!shared_memory->Map(shared_memory->max_size()))
- return NULL;
- }
-
- return shared_memory->memory();
-}
-
-// TODO(apatrick): Consolidate this with the above and return both the address
-// and size.
-size_t GPUProcessor::GetSharedMemorySize(int32 shm_id) {
- ::base::SharedMemory* shared_memory =
- command_buffer_->GetTransferBuffer(shm_id);
- if (!shared_memory)
- return 0;
-
- return shared_memory->max_size();
+Buffer GPUProcessor::GetSharedMemoryBuffer(int32 shm_id) {
+ return command_buffer_->GetTransferBuffer(shm_id);
}
void GPUProcessor::set_token(int32 token) {
diff --git a/gpu/command_buffer/service/gpu_processor.h b/gpu/command_buffer/service/gpu_processor.h
index a594f0b..41325fa 100644
--- a/gpu/command_buffer/service/gpu_processor.h
+++ b/gpu/command_buffer/service/gpu_processor.h
@@ -18,8 +18,8 @@ namespace gpu {
// This class processes commands in a command buffer. It is event driven and
// posts tasks to the current message loop to do additional work.
-class GPUProcessor : public ::base::RefCounted<GPUProcessor>,
- public gpu::CommandBufferEngine {
+class GPUProcessor : public base::RefCounted<GPUProcessor>,
+ public CommandBufferEngine {
public:
explicit GPUProcessor(CommandBuffer* command_buffer);
@@ -37,21 +37,8 @@ class GPUProcessor : public ::base::RefCounted<GPUProcessor>,
virtual void ProcessCommands();
- virtual bool SetWindow(gfx::PluginWindowHandle handle, int width, int height);
-
// Implementation of CommandBufferEngine.
-
- // Gets the base address of a registered shared memory buffer.
- // Parameters:
- // shm_id: the identifier for the shared memory buffer.
- virtual void *GetSharedMemoryAddress(int32 shm_id);
-
- // Gets the size of a registered shared memory buffer.
- // Parameters:
- // shm_id: the identifier for the shared memory buffer.
- virtual size_t GetSharedMemorySize(int32 shm_id);
-
- // Sets the token value.
+ virtual Buffer GetSharedMemoryBuffer(int32 shm_id);
virtual void set_token(int32 token);
private:
diff --git a/gpu/command_buffer/service/gpu_processor_mock.h b/gpu/command_buffer/service/gpu_processor_mock.h
index be6a938..ca257e8 100644
--- a/gpu/command_buffer/service/gpu_processor_mock.h
+++ b/gpu/command_buffer/service/gpu_processor_mock.h
@@ -19,11 +19,7 @@ class MockGPUProcessor : public GPUProcessor {
MOCK_METHOD1(Initialize, bool(gfx::PluginWindowHandle handle));
MOCK_METHOD0(Destroy, void());
MOCK_METHOD0(ProcessCommands, void());
- MOCK_METHOD3(SetWindow, bool(gfx::PluginWindowHandle handle,
- int width,
- int height));
- MOCK_METHOD1(GetSharedMemoryAddress, void*(int32 shm_id));
- MOCK_METHOD1(GetSharedMemorySize, size_t(int32 shm_id));
+ MOCK_METHOD1(GetSharedMemoryBuffer, Buffer(int32 shm_id));
MOCK_METHOD1(set_token, void(int32 token));
private:
diff --git a/gpu/command_buffer/service/gpu_processor_unittest.cc b/gpu/command_buffer/service/gpu_processor_unittest.cc
index 5041371..304dc72 100644
--- a/gpu/command_buffer/service/gpu_processor_unittest.cc
+++ b/gpu/command_buffer/service/gpu_processor_unittest.cc
@@ -31,25 +31,26 @@ class GPUProcessorTest : public testing::Test {
shared_memory_->Create(std::wstring(), false, false, kRingBufferSize);
shared_memory_->Map(kRingBufferSize);
buffer_ = static_cast<int32*>(shared_memory_->memory());
-
+ shared_memory_buffer_.ptr = buffer_;
+ shared_memory_buffer_.size = kRingBufferSize;
memset(buffer_, 0, kRingBufferSize);
command_buffer_.reset(new MockCommandBuffer);
ON_CALL(*command_buffer_.get(), GetRingBuffer())
- .WillByDefault(Return(shared_memory_.get()));
+ .WillByDefault(Return(shared_memory_buffer_));
ON_CALL(*command_buffer_.get(), GetSize())
.WillByDefault(Return(kRingBufferEntries));
- async_api_.reset(new StrictMock<gpu::AsyncAPIMock>);
+ async_api_.reset(new StrictMock<AsyncAPIMock>);
decoder_ = gles2::GLES2Decoder::Create();
- parser_ = new gpu::CommandParser(buffer_,
- kRingBufferEntries,
- 0,
- kRingBufferEntries,
- 0,
- async_api_.get());
+ parser_ = new CommandParser(buffer_,
+ kRingBufferEntries,
+ 0,
+ kRingBufferEntries,
+ 0,
+ async_api_.get());
processor_ = new GPUProcessor(command_buffer_.get(),
decoder_,
@@ -67,10 +68,11 @@ class GPUProcessorTest : public testing::Test {
MessageLoop message_loop;
scoped_ptr<MockCommandBuffer> command_buffer_;
scoped_ptr<::base::SharedMemory> shared_memory_;
+ Buffer shared_memory_buffer_;
int32* buffer_;
- gpu::gles2::GLES2Decoder* decoder_;
- gpu::CommandParser* parser_;
- scoped_ptr<gpu::AsyncAPIMock> async_api_;
+ gles2::GLES2Decoder* decoder_;
+ CommandParser* parser_;
+ scoped_ptr<AsyncAPIMock> async_api_;
scoped_refptr<GPUProcessor> processor_;
};
@@ -81,14 +83,13 @@ TEST_F(GPUProcessorTest, ProcessorDoesNothingIfRingBufferIsEmpty) {
processor_->ProcessCommands();
- EXPECT_EQ(gpu::parse_error::kParseNoError,
+ EXPECT_EQ(parse_error::kParseNoError,
command_buffer_->ResetParseError());
EXPECT_FALSE(command_buffer_->GetErrorStatus());
}
TEST_F(GPUProcessorTest, ProcessesOneCommand) {
- gpu::CommandHeader* header =
- reinterpret_cast<gpu::CommandHeader*>(&buffer_[0]);
+ CommandHeader* header = reinterpret_cast<CommandHeader*>(&buffer_[0]);
header[0].command = 7;
header[0].size = 2;
buffer_[1] = 123;
@@ -98,18 +99,17 @@ TEST_F(GPUProcessorTest, ProcessesOneCommand) {
EXPECT_CALL(*command_buffer_, SetGetOffset(2));
EXPECT_CALL(*async_api_, DoCommand(7, 1, &buffer_[0]))
- .WillOnce(Return(gpu::parse_error::kParseNoError));
+ .WillOnce(Return(parse_error::kParseNoError));
processor_->ProcessCommands();
- EXPECT_EQ(gpu::parse_error::kParseNoError,
+ EXPECT_EQ(parse_error::kParseNoError,
command_buffer_->ResetParseError());
EXPECT_FALSE(command_buffer_->GetErrorStatus());
}
TEST_F(GPUProcessorTest, ProcessesTwoCommands) {
- gpu::CommandHeader* header =
- reinterpret_cast<gpu::CommandHeader*>(&buffer_[0]);
+ CommandHeader* header = reinterpret_cast<CommandHeader*>(&buffer_[0]);
header[0].command = 7;
header[0].size = 2;
buffer_[1] = 123;
@@ -121,17 +121,16 @@ TEST_F(GPUProcessorTest, ProcessesTwoCommands) {
EXPECT_CALL(*command_buffer_, SetGetOffset(3));
EXPECT_CALL(*async_api_, DoCommand(7, 1, &buffer_[0]))
- .WillOnce(Return(gpu::parse_error::kParseNoError));
+ .WillOnce(Return(parse_error::kParseNoError));
EXPECT_CALL(*async_api_, DoCommand(8, 0, &buffer_[2]))
- .WillOnce(Return(gpu::parse_error::kParseNoError));
+ .WillOnce(Return(parse_error::kParseNoError));
processor_->ProcessCommands();
}
TEST_F(GPUProcessorTest, PostsTaskToFinishRemainingCommands) {
- gpu::CommandHeader* header =
- reinterpret_cast<gpu::CommandHeader*>(&buffer_[0]);
+ CommandHeader* header = reinterpret_cast<CommandHeader*>(&buffer_[0]);
header[0].command = 7;
header[0].size = 2;
buffer_[1] = 123;
@@ -144,10 +143,10 @@ TEST_F(GPUProcessorTest, PostsTaskToFinishRemainingCommands) {
.WillOnce(Return(4));
EXPECT_CALL(*async_api_, DoCommand(7, 1, &buffer_[0]))
- .WillOnce(Return(gpu::parse_error::kParseNoError));
+ .WillOnce(Return(parse_error::kParseNoError));
EXPECT_CALL(*async_api_, DoCommand(8, 0, &buffer_[2]))
- .WillOnce(Return(gpu::parse_error::kParseNoError));
+ .WillOnce(Return(parse_error::kParseNoError));
EXPECT_CALL(*command_buffer_, SetGetOffset(3));
@@ -159,7 +158,7 @@ TEST_F(GPUProcessorTest, PostsTaskToFinishRemainingCommands) {
.WillOnce(Return(4));
EXPECT_CALL(*async_api_, DoCommand(9, 0, &buffer_[3]))
- .WillOnce(Return(gpu::parse_error::kParseNoError));
+ .WillOnce(Return(parse_error::kParseNoError));
EXPECT_CALL(*command_buffer_, SetGetOffset(4));
@@ -167,8 +166,7 @@ TEST_F(GPUProcessorTest, PostsTaskToFinishRemainingCommands) {
}
TEST_F(GPUProcessorTest, SetsErrorCodeOnCommandBuffer) {
- gpu::CommandHeader* header =
- reinterpret_cast<gpu::CommandHeader*>(&buffer_[0]);
+ CommandHeader* header = reinterpret_cast<CommandHeader*>(&buffer_[0]);
header[0].command = 7;
header[0].size = 1;
@@ -178,18 +176,17 @@ TEST_F(GPUProcessorTest, SetsErrorCodeOnCommandBuffer) {
EXPECT_CALL(*async_api_, DoCommand(7, 0, &buffer_[0]))
.WillOnce(Return(
- gpu::parse_error::kParseUnknownCommand));
+ parse_error::kParseUnknownCommand));
EXPECT_CALL(*command_buffer_,
- SetParseError(gpu::parse_error::kParseUnknownCommand));
+ SetParseError(parse_error::kParseUnknownCommand));
processor_->ProcessCommands();
}
TEST_F(GPUProcessorTest,
RecoverableParseErrorsAreNotClearedByFollowingSuccessfulCommands) {
- gpu::CommandHeader* header =
- reinterpret_cast<gpu::CommandHeader*>(&buffer_[0]);
+ CommandHeader* header = reinterpret_cast<CommandHeader*>(&buffer_[0]);
header[0].command = 7;
header[0].size = 1;
header[1].command = 8;
@@ -201,20 +198,20 @@ TEST_F(GPUProcessorTest,
EXPECT_CALL(*async_api_, DoCommand(7, 0, &buffer_[0]))
.WillOnce(Return(
- gpu::parse_error::kParseUnknownCommand));
+ parse_error::kParseUnknownCommand));
EXPECT_CALL(*async_api_, DoCommand(8, 0, &buffer_[1]))
- .WillOnce(Return(gpu::parse_error::kParseNoError));
+ .WillOnce(Return(parse_error::kParseNoError));
EXPECT_CALL(*command_buffer_,
- SetParseError(gpu::parse_error::kParseUnknownCommand));
+ SetParseError(parse_error::kParseUnknownCommand));
processor_->ProcessCommands();
}
TEST_F(GPUProcessorTest, UnrecoverableParseErrorsRaiseTheErrorStatus) {
- gpu::CommandHeader* header =
- reinterpret_cast<gpu::CommandHeader*>(&buffer_[0]);
+ CommandHeader* header =
+ reinterpret_cast<CommandHeader*>(&buffer_[0]);
header[0].command = 7;
header[0].size = 1;
header[1].command = 8;
@@ -224,10 +221,10 @@ TEST_F(GPUProcessorTest, UnrecoverableParseErrorsRaiseTheErrorStatus) {
.WillOnce(Return(2));
EXPECT_CALL(*async_api_, DoCommand(7, 0, &buffer_[0]))
- .WillOnce(Return(gpu::parse_error::kParseInvalidSize));
+ .WillOnce(Return(parse_error::kParseInvalidSize));
EXPECT_CALL(*command_buffer_,
- SetParseError(gpu::parse_error::kParseInvalidSize));
+ SetParseError(parse_error::kParseInvalidSize));
EXPECT_CALL(*command_buffer_, RaiseErrorStatus());
@@ -246,27 +243,20 @@ TEST_F(GPUProcessorTest, ProcessCommandsDoesNothingAfterUnrecoverableError) {
TEST_F(GPUProcessorTest, CanGetAddressOfSharedMemory) {
EXPECT_CALL(*command_buffer_.get(), GetTransferBuffer(7))
- .WillOnce(Return(shared_memory_.get()));
+ .WillOnce(Return(shared_memory_buffer_));
- EXPECT_EQ(&buffer_[0], processor_->GetSharedMemoryAddress(7));
+ EXPECT_EQ(&buffer_[0], processor_->GetSharedMemoryBuffer(7).ptr);
}
ACTION_P2(SetPointee, address, value) {
*address = value;
}
-TEST_F(GPUProcessorTest, GetAddressOfSharedMemoryMapsMemoryIfUnmapped) {
- EXPECT_CALL(*command_buffer_.get(), GetTransferBuffer(7))
- .WillOnce(Return(shared_memory_.get()));
-
- EXPECT_EQ(&buffer_[0], processor_->GetSharedMemoryAddress(7));
-}
-
TEST_F(GPUProcessorTest, CanGetSizeOfSharedMemory) {
EXPECT_CALL(*command_buffer_.get(), GetTransferBuffer(7))
- .WillOnce(Return(shared_memory_.get()));
+ .WillOnce(Return(shared_memory_buffer_));
- EXPECT_EQ(kRingBufferSize, processor_->GetSharedMemorySize(7));
+ EXPECT_EQ(kRingBufferSize, processor_->GetSharedMemoryBuffer(7).size);
}
TEST_F(GPUProcessorTest, SetTokenForwardsToCommandBuffer) {
diff --git a/gpu/command_buffer/service/gpu_processor_win.cc b/gpu/command_buffer/service/gpu_processor_win.cc
index c08e102..6a05845 100644
--- a/gpu/command_buffer/service/gpu_processor_win.cc
+++ b/gpu/command_buffer/service/gpu_processor_win.cc
@@ -37,19 +37,17 @@ bool GPUProcessor::Initialize(gfx::PluginWindowHandle handle) {
return false;
// Map the ring buffer and create the parser.
- ::base::SharedMemory* ring_buffer = command_buffer_->GetRingBuffer();
- if (ring_buffer) {
- size_t size = ring_buffer->max_size();
- if (!ring_buffer->Map(size)) {
- return false;
- }
-
- void* ptr = ring_buffer->memory();
- parser_.reset(new gpu::CommandParser(ptr, size, 0, size, 0,
- decoder_.get()));
+ Buffer ring_buffer = command_buffer_->GetRingBuffer();
+ if (ring_buffer.ptr) {
+ parser_.reset(new CommandParser(ring_buffer.ptr,
+ ring_buffer.size,
+ 0,
+ ring_buffer.size,
+ 0,
+ decoder_.get()));
} else {
- parser_.reset(new gpu::CommandParser(NULL, 0, 0, 0, 0,
- decoder_.get()));
+ parser_.reset(new CommandParser(NULL, 0, 0, 0, 0,
+ decoder_.get()));
}
// Initialize GAPI immediately if the window handle is valid.
@@ -64,17 +62,4 @@ void GPUProcessor::Destroy() {
decoder_->set_hwnd(NULL);
}
}
-
-bool GPUProcessor::SetWindow(gfx::PluginWindowHandle handle,
- int width,
- int height) {
- if (handle == NULL) {
- // Destroy GAPI when the window handle becomes invalid.
- Destroy();
- return true;
- } else {
- return Initialize(handle);
- }
-}
-
} // namespace gpu
diff --git a/gpu/gpu.gyp b/gpu/gpu.gyp
index 5a5c113..d4de4c5 100644
--- a/gpu/gpu.gyp
+++ b/gpu/gpu.gyp
@@ -85,6 +85,7 @@
],
'sources': [
'command_buffer/common/bitfield_helpers.h',
+ 'command_buffer/common/buffer.h',
'command_buffer/common/cmd_buffer_common.h',
'command_buffer/common/cmd_buffer_common.cc',
'command_buffer/common/command_buffer.h',
@@ -278,7 +279,7 @@
},
{
'target_name': 'gpu_plugin',
- 'type': '<(library)',
+ 'type': 'static_library',
'dependencies': [
'../base/base.gyp:base',
'command_buffer_service',
@@ -312,24 +313,40 @@
],
},
{
- 'target_name': 'gles2_demo',
- 'type': 'executable',
+ 'target_name': 'gles2_demo_lib',
+ 'type': 'static_library',
'dependencies': [
'command_buffer_client',
- 'command_buffer_service',
'gles2_lib',
'gles2_c_lib',
- 'gpu_plugin',
],
'sources': [
- 'command_buffer/client/gles2_demo.cc',
'command_buffer/client/gles2_demo_c.h',
'command_buffer/client/gles2_demo_c.c',
'command_buffer/client/gles2_demo_cc.h',
'command_buffer/client/gles2_demo_cc.cc',
],
},
- ]
+ ],
+ 'conditions': [
+ ['OS == "win"',
+ {
+ 'targets': [
+ {
+ 'target_name': 'gles2_demo',
+ 'type': 'executable',
+ 'dependencies': [
+ 'command_buffer_service',
+ 'gles2_demo_lib',
+ ],
+ 'sources': [
+ 'command_buffer/client/gles2_demo.cc',
+ ],
+ },
+ ],
+ },
+ ],
+ ],
}
# Local Variables:
diff --git a/gpu/gpu_plugin/gpu_plugin.cc b/gpu/gpu_plugin/gpu_plugin.cc
index e43caf1..10df734 100644
--- a/gpu/gpu_plugin/gpu_plugin.cc
+++ b/gpu/gpu_plugin/gpu_plugin.cc
@@ -47,7 +47,7 @@ NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) {
}
}
-NPError NP_GetEntryPoints(NPPluginFuncs* funcs) {
+NPError API_CALL NP_GetEntryPoints(NPPluginFuncs* funcs) {
funcs->newp = NPP_New;
funcs->destroy = NPP_Destroy;
funcs->setwindow = NPP_SetWindow;
@@ -61,7 +61,7 @@ NPError NP_GetEntryPoints(NPPluginFuncs* funcs) {
NPError API_CALL NP_Initialize(NPNetscapeFuncs *browser_funcs,
NPPluginFuncs* plugin_funcs) {
#else
-NPError NP_Initialize(NPNetscapeFuncs *browser_funcs) {
+NPError API_CALL NP_Initialize(NPNetscapeFuncs *browser_funcs) {
#endif
if (!browser_funcs)
return NPERR_INVALID_FUNCTABLE_ERROR;
@@ -73,7 +73,7 @@ NPError NP_Initialize(NPNetscapeFuncs *browser_funcs) {
return NPERR_NO_ERROR;
}
-NPError NP_Shutdown() {
+NPError API_CALL NP_Shutdown() {
return NPERR_NO_ERROR;
}
} // namespace gpu_plugin
diff --git a/gpu/gpu_plugin/gpu_plugin.h b/gpu/gpu_plugin/gpu_plugin.h
index a667872..b6bfc89 100644
--- a/gpu/gpu_plugin/gpu_plugin.h
+++ b/gpu/gpu_plugin/gpu_plugin.h
@@ -15,16 +15,16 @@ namespace gpu_plugin {
// Declarations of NPAPI plugin entry points.
-NPError NP_GetEntryPoints(NPPluginFuncs* funcs);
+NPError API_CALL NP_GetEntryPoints(NPPluginFuncs* funcs);
#if defined(OS_LINUX)
-NPError NP_Initialize(NPNetscapeFuncs *browser_funcs,
+NPError API_CALL NP_Initialize(NPNetscapeFuncs *browser_funcs,
NPPluginFuncs* plugin_funcs);
#else
-NPError NP_Initialize(NPNetscapeFuncs* browser_funcs);
+NPError API_CALL NP_Initialize(NPNetscapeFuncs* browser_funcs);
#endif
-NPError NP_Shutdown();
+NPError API_CALL NP_Shutdown();
} // namespace gpu_plugin