summaryrefslogtreecommitdiffstats
path: root/o3d/core
diff options
context:
space:
mode:
authorapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-19 18:43:09 +0000
committerapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-19 18:43:09 +0000
commit52f88d8d6be4ddfad56c25d3c9a13cd22a768628 (patch)
treeccf9de7149854ab9c04fe451fb8b58a9de41e9d4 /o3d/core
parent52d08b12e8e7ff7c9b865837a2aeb17fb9dc2d42 (diff)
downloadchromium_src-52f88d8d6be4ddfad56c25d3c9a13cd22a768628.zip
chromium_src-52f88d8d6be4ddfad56c25d3c9a13cd22a768628.tar.gz
chromium_src-52f88d8d6be4ddfad56c25d3c9a13cd22a768628.tar.bz2
Changed O3D to use CommandBuffer in-process. Still not connecting to the GPU plugin.
I removed all the NaCl dependencies. Synchronous messages are now sent by NPAPI. Removed BufferSyncInterface and replaced it with CommandBuffer. CommandBufferHelper now uses NPAPI. Changed some unsigned ints to int32s because NPAPI doesn't support unsigned int. There are now two subclasses of RendererCB. RendererCBLocal is for use with an in-process CommandBuffer. RendererCBRemote is for use with an out-of-process CommandBuffer. I'm going to rearrange the locations of the source files under gpu_plugin next. CommandBuffer and GPUProcessor probably belong in the command_buffer_service library now. np_utils and system_services should be standalone libraries. TEST=none BUG=none Review URL: http://codereview.chromium.org/266068 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29429 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/core')
-rw-r--r--o3d/core/build.scons20
-rw-r--r--o3d/core/core.gyp20
-rw-r--r--o3d/core/cross/command_buffer/display_window_cb.h (renamed from o3d/core/win/command_buffer/win32_cb_server.h)87
-rw-r--r--o3d/core/cross/command_buffer/effect_cb.cc7
-rw-r--r--o3d/core/cross/command_buffer/renderer_cb.cc289
-rw-r--r--o3d/core/cross/command_buffer/renderer_cb.h98
-rw-r--r--o3d/core/cross/renderer_test.cc5
-rw-r--r--o3d/core/win/command_buffer/win32_cb_server.cc120
8 files changed, 342 insertions, 304 deletions
diff --git a/o3d/core/build.scons b/o3d/core/build.scons
index bb7217e..62e803e 100644
--- a/o3d/core/build.scons
+++ b/o3d/core/build.scons
@@ -175,29 +175,11 @@ elif 'RENDERER_GL' in env['CPPDEFINES'] :
'cross/gl/utils_gl.cc',
"cross/gl/sampler_gl.cc",
]
-elif 'RENDERER_CB' in env['CPPDEFINES'] :
- platform_inputs += [
- 'cross/command_buffer/buffer_cb.cc',
- 'cross/command_buffer/effect_cb.cc',
- 'cross/command_buffer/install_check.cc',
- 'cross/command_buffer/param_cache_cb.cc',
- 'cross/command_buffer/primitive_cb.cc',
- 'cross/command_buffer/renderer_cb.cc',
- 'cross/command_buffer/render_surface_cb.cc',
- 'cross/command_buffer/sampler_cb.cc',
- 'cross/command_buffer/states_cb.cc',
- 'cross/command_buffer/stream_bank_cb.cc',
- 'cross/command_buffer/texture_cb.cc',
- ]
- if env['TARGET_PLATFORM'] == 'WINDOWS':
- platform_inputs += [
- 'win/command_buffer/win32_cb_server.cc',
- ]
elif 'RENDERER_MOCK' in env['CPPDEFINES'] :
platform_inputs += [ ]
else :
print 'No renderer defined, exiting.\n'
- print """Add 'RENDERER=gl', 'RENDERER=d3d' or 'RENDERER=cb' to the command line."""
+ print """Add 'RENDERER=gl' or 'RENDERER=d3d' to the command line."""
Exit(1)
if env['TARGET_PLATFORM'] == 'MAC':
diff --git a/o3d/core/core.gyp b/o3d/core/core.gyp
index e4bc0f4..9216f36 100644
--- a/o3d/core/core.gyp
+++ b/o3d/core/core.gyp
@@ -318,8 +318,6 @@
'type': 'static_library',
'dependencies': [
'../../skia/skia.gyp:skia',
- '../command_buffer/command_buffer.gyp:command_buffer_client',
- '../command_buffer/command_buffer.gyp:command_buffer_service',
],
'sources': [
],
@@ -396,6 +394,16 @@
],
['renderer == "cb"',
{
+ 'dependencies': [
+ '../command_buffer/command_buffer.gyp:command_buffer_client',
+ '../command_buffer/command_buffer.gyp:command_buffer_service',
+ '../gpu_plugin/gpu_plugin.gyp:np_utils',
+
+ # These dependencies is only needed for RendererCBLocal. They can
+ # be removed when RendererCBLocal is not needed.
+ '../gpu_plugin/gpu_plugin.gyp:command_buffer',
+ '../gpu_plugin/gpu_plugin.gyp:np_utils',
+ ],
'sources': [
'cross/command_buffer/buffer_cb.cc',
'cross/command_buffer/buffer_cb.h',
@@ -422,14 +430,6 @@
],
},
],
- ['renderer == "cb" and OS == "win"',
- {
- 'sources': [
- 'win/command_buffer/win32_cb_server.cc',
- 'win/command_buffer/win32_cb_server.h',
- ],
- },
- ],
],
},
{
diff --git a/o3d/core/win/command_buffer/win32_cb_server.h b/o3d/core/cross/command_buffer/display_window_cb.h
index 49a34f7..52cd08a 100644
--- a/o3d/core/win/command_buffer/win32_cb_server.h
+++ b/o3d/core/cross/command_buffer/display_window_cb.h
@@ -30,52 +30,61 @@
*/
-// This file declares the Win32CBServer class, helper class that runs a command
-// buffer server in a separate win32 thread.
-
-#ifndef O3D_CORE_WIN_COMMAND_BUFFER_WIN32_CB_SERVER_H_
-#define O3D_CORE_WIN_COMMAND_BUFFER_WIN32_CB_SERVER_H_
-
-#include "core/cross/precompile.h"
-#include "core/cross/features.h"
-#include "command_buffer/common/cross/rpc_imc.h"
-#include "command_buffer/client/cross/buffer_sync_proxy.h"
-#if defined(CB_SERVICE_D3D9)
-#include "command_buffer/service/win/d3d9/gapi_d3d9.h"
-#elif defined(CB_SERVICE_GL)
-#include "command_buffer/service/cross/gl/gapi_gl.h"
-#endif
+#ifndef O3D_CORE_WIN_DISPLAY_WINDOW_CB_H_
+#define O3D_CORE_WIN_DISPLAY_WINDOW_CB_H_
+#include "core/cross/display_window.h"
+#include "gpu_plugin/np_utils/np_object_pointer.h"
namespace o3d {
-// The current Renderer API assumes we connect directly to the window. This
-// class creates a command buffer server in a separate thread, and sets up the
-// communication socket.
-// This code will go away once we fix the API, and provide a separate mechanism
-// to connect to the service.
-class Win32CBServer {
+// DisplayWindow subclass without information needed to connect to and use
+// an out-of-process command buffer renderer.
+class DisplayWindowCB : public DisplayWindow {
public:
- explicit Win32CBServer(HWND window, Features* features);
- ~Win32CBServer();
+ DisplayWindowCB() : npp_(NULL), width_(0), height_(0) {}
+ virtual ~DisplayWindowCB() {}
- // Gets the (client-side) command buffer interface.
- command_buffer::BufferSyncInterface *GetInterface() { return proxy_.get(); }
+ NPP npp() const {
+ return npp_;
+ }
- private:
- static DWORD WINAPI ThreadMain(LPVOID param);
+ void set_npp(NPP npp) {
+ npp_ = npp;
+ }
-#if defined(CB_SERVICE_D3D9)
- command_buffer::GAPID3D9 gapi_;
-#elif defined(CB_SERVICE_GL)
- command_buffer::GAPIGL gapi_;
-#endif
- nacl::HtpHandle socket_pair_[2];
- scoped_ptr<command_buffer::IMCSender> imc_sender_;
- scoped_ptr<command_buffer::BufferSyncProxy> proxy_;
- HANDLE thread_;
-};
+ gpu_plugin::NPObjectPointer<NPObject> command_buffer() const {
+ return command_buffer_;
+ }
+
+ void set_command_buffer(
+ const gpu_plugin::NPObjectPointer<NPObject> command_buffer) {
+ command_buffer_ = command_buffer;
+ }
+
+ int width() const {
+ return width_;
+ }
-} // namespace o3d
+ void set_width(int width) {
+ width_ = width;
+ }
+
+ int height() const {
+ return height_;
+ }
+
+ void set_height(int height) {
+ height_ = height;
+ }
+
+ private:
+ NPP npp_;
+ gpu_plugin::NPObjectPointer<NPObject> command_buffer_;
+ int width_;
+ int height_;
+ DISALLOW_COPY_AND_ASSIGN(DisplayWindowCB);
+};
+} // end namespace o3d
-#endif // O3D_CORE_WIN_COMMAND_BUFFER_WIN32_CB_SERVER_H_
+#endif // O3D_CORE_WIN_DISPLAY_WINDOW_CB_H_
diff --git a/o3d/core/cross/command_buffer/effect_cb.cc b/o3d/core/cross/command_buffer/effect_cb.cc
index b69be352..172d717 100644
--- a/o3d/core/cross/command_buffer/effect_cb.cc
+++ b/o3d/core/cross/command_buffer/effect_cb.cc
@@ -37,18 +37,18 @@
#include "core/cross/semantic_manager.h"
#include "core/cross/service_locator.h"
#include "core/cross/command_buffer/effect_cb.h"
-#include "command_buffer/common/cross/buffer_sync_api.h"
+#include "command_buffer/common/cross/constants.h"
#include "command_buffer/common/cross/cmd_buffer_format.h"
#include "command_buffer/client/cross/fenced_allocator.h"
#include "command_buffer/client/cross/cmd_buffer_helper.h"
namespace o3d {
-using command_buffer::BufferSyncInterface;
using command_buffer::CommandBufferEntry;
using command_buffer::CommandBufferHelper;
using command_buffer::ResourceId;
namespace effect_param = command_buffer::effect_param;
+namespace parse_error = command_buffer::parse_error;
namespace vertex_struct = command_buffer::vertex_struct;
EffectCB::EffectCB(ServiceLocator *service_locator, RendererCB *renderer)
@@ -101,8 +101,7 @@ bool EffectCB::LoadFromFXString(const String& source) {
// NOTE: we're calling Finish to check the command result, to see if
// the effect has succesfully compiled.
helper->Finish();
- if (renderer_->sync_interface()->GetParseError() !=
- BufferSyncInterface::kParseNoError) {
+ if (renderer_->GetParseError() != parse_error::kParseNoError) {
O3D_ERROR(service_locator()) << "Effect failed to compile.";
renderer_->effect_ids().FreeID(resource_id);
return false;
diff --git a/o3d/core/cross/command_buffer/renderer_cb.cc b/o3d/core/cross/command_buffer/renderer_cb.cc
index d576874..4db474f 100644
--- a/o3d/core/cross/command_buffer/renderer_cb.cc
+++ b/o3d/core/cross/command_buffer/renderer_cb.cc
@@ -47,119 +47,66 @@
#include "core/cross/command_buffer/states_cb.h"
#include "core/cross/command_buffer/stream_bank_cb.h"
#include "core/cross/command_buffer/texture_cb.h"
+#include "core/cross/command_buffer/display_window_cb.h"
#include "core/cross/renderer_platform.h"
-
-#ifdef OS_WIN
-#include "core/win/command_buffer/win32_cb_server.h"
-#endif
+#include "gpu_plugin/command_buffer.h"
+#include "gpu_plugin/gpu_processor.h"
+#include "gpu_plugin/np_utils/np_browser.h"
+#include "gpu_plugin/np_utils/np_utils.h"
+#include "gpu_plugin/system_services/shared_memory.h"
namespace o3d {
using command_buffer::GAPIInterface;
using command_buffer::CommandBufferHelper;
+using gpu_plugin::CommandBuffer;
+using gpu_plugin::GPUProcessor;
+using gpu_plugin::NPBrowser;
+using gpu_plugin::NPCreateObject;
+using gpu_plugin::NPGetProperty;
+using gpu_plugin::NPInvoke;
+using gpu_plugin::NPInvokeVoid;
+using gpu_plugin::NPObjectPointer;
+using gpu_plugin::SharedMemory;
RendererCB::RendererCB(ServiceLocator* service_locator,
- unsigned int command_buffer_size,
- unsigned int transfer_memory_size)
+ int32 transfer_memory_size)
: Renderer(service_locator),
- cmd_buffer_size_(command_buffer_size),
transfer_memory_size_(transfer_memory_size),
- transfer_shm_(command_buffer::kRPCInvalidHandle),
- transfer_shm_id_(0),
+ transfer_shm_id_(command_buffer::kInvalidSharedMemoryId),
transfer_shm_address_(NULL),
- sync_interface_(NULL),
+ npp_(NULL),
helper_(NULL),
allocator_(NULL),
- cb_server_(NULL),
frame_token_(0),
state_manager_(new StateManager) {
- DCHECK_GT(command_buffer_size, 0U);
- DCHECK_GT(transfer_memory_size, 0U);
- transfer_shm_ = command_buffer::CreateShm(transfer_memory_size);
- transfer_shm_address_ = command_buffer::MapShm(transfer_shm_,
- transfer_memory_size);
+ DCHECK_GT(transfer_memory_size, 0);
state_manager_->AddStateHandlers(this);
}
RendererCB::~RendererCB() {
Destroy();
- command_buffer::UnmapShm(transfer_shm_address_, transfer_memory_size_);
- command_buffer::DestroyShm(transfer_shm_);
}
-static const unsigned int kDefaultCommandBufferSize = 256 << 10;
-// This should be enough to hold the biggest possible buffer
-// (2048x2048xABGR16F texture = 32MB)
-static const unsigned int kDefaultTransferMemorySize = 32 << 20;
-
-RendererCB *RendererCB::CreateDefault(ServiceLocator* service_locator) {
- return new RendererCB(service_locator, kDefaultCommandBufferSize,
- kDefaultTransferMemorySize);
-}
-
-Renderer::InitStatus RendererCB::InitPlatformSpecific(
- const DisplayWindow& display,
- bool off_screen) {
- if (off_screen) {
- // TODO: Off-screen support ?
- return UNINITIALIZED; // equivalent to 0/false
+void RendererCB::Destroy() {
+ if (transfer_shm_id_ >= 0) {
+ NPInvokeVoid(npp_, command_buffer_, "unregisterObject", transfer_shm_id_);
+ transfer_shm_id_ = command_buffer::kInvalidSharedMemoryId;
}
-#ifdef OS_WIN
- const DisplayWindowWindows &display_platform =
- static_cast<const DisplayWindowWindows&>(display);
- // Creates a Win32CBServer based on the HWND, and creates the
- // command buffer helper, and initializes it. Also, create the
- // FencedAllocator for the transfer memory.
- cb_server_ = new Win32CBServer(display_platform.hwnd(), features());
- sync_interface_ = cb_server_->GetInterface();
-
- RECT windowRect;
- ::GetWindowRect(display_platform.hwnd(), &windowRect);
- int width = windowRect.right - windowRect.left;
- int height = windowRect.bottom - windowRect.top;
- InitCommon(width, height);
- return SUCCESS;
-#else
- // TODO: Implement Mac/Linux support before shipping
- // command buffers.
- return UNINITIALIZED;
-#endif
-}
+ transfer_shm_ = NPObjectPointer<NPObject>();
-void RendererCB::InitCommon(unsigned int width, unsigned int height) {
- sync_interface_->InitConnection();
- transfer_shm_id_ = sync_interface_->RegisterSharedMemory(
- transfer_shm_, transfer_memory_size_);
- helper_ = new CommandBufferHelper(sync_interface_);
- helper_->Init(cmd_buffer_size_);
- frame_token_ = helper_->InsertToken();
- allocator_ = new FencedAllocatorWrapper(transfer_memory_size_,
- helper_,
- transfer_shm_address_);
- SetClientSize(width, height);
-}
-
-void RendererCB::Destroy() {
if (allocator_) {
delete allocator_;
allocator_ = NULL;
}
+
if (helper_) {
helper_->Finish();
- if (sync_interface_) {
- sync_interface_->CloseConnection();
- sync_interface_->UnregisterSharedMemory(transfer_shm_id_);
- sync_interface_ = NULL;
- }
delete helper_;
helper_ = NULL;
}
-#ifdef OS_WIN
- if (cb_server_) {
- delete cb_server_;
- cb_server_ = NULL;
- }
-#endif
+
+ npp_ = NULL;
}
void RendererCB::ApplyDirtyStates() {
@@ -314,10 +261,8 @@ const int* RendererCB::GetRGBAUByteNSwizzleTable() {
return swizzle_table;
}
-// This is a factory function for creating Renderer objects. Since
-// we're implementing command buffers, we only ever return a CB renderer.
-Renderer* Renderer::CreateDefaultRenderer(ServiceLocator* service_locator) {
- return RendererCB::CreateDefault(service_locator);
+command_buffer::parse_error::ParseError RendererCB::GetParseError() {
+ return helper_->GetParseError();
}
// Creates and returns a platform specific RenderDepthStencilSurface object.
@@ -330,4 +275,180 @@ RenderDepthStencilSurface::Ref RendererCB::CreateDepthStencilSurface(
height,
this));
}
+
+Renderer::InitStatus RendererCB::InitPlatformSpecific(
+ const DisplayWindow& display_window,
+ bool off_screen) {
+ if (off_screen) {
+ // TODO: Off-screen support ?
+ return UNINITIALIZED; // equivalent to 0/false
+ }
+
+ const DisplayWindowCB& display_platform =
+ static_cast<const DisplayWindowCB&>(display_window);
+
+ npp_ = display_platform.npp();
+ command_buffer_ = display_platform.command_buffer();
+ DCHECK(command_buffer_.Get());
+
+ // Create and initialize a CommandBufferHelper.
+ helper_ = new CommandBufferHelper(npp_, command_buffer_);
+ if (!helper_->Initialize()) {
+ Destroy();
+ return INITIALIZATION_ERROR;
+ }
+
+ // Create and map a block of memory for the transfer buffer.
+ transfer_shm_ = CreateSharedMemory(transfer_memory_size_, npp_);
+ if (!transfer_shm_.Get()) {
+ Destroy();
+ return INITIALIZATION_ERROR;
+ }
+ size_t size_bytes;
+ transfer_shm_address_ = NPBrowser::get()->MapMemory(npp_,
+ transfer_shm_.Get(),
+ &size_bytes);
+ if (!transfer_shm_address_) {
+ Destroy();
+ return INITIALIZATION_ERROR;
+ }
+ DCHECK(size_bytes == transfer_memory_size_);
+
+ // Register the transfer buffer so it can be identified with an integer
+ // in future commands.
+ if (!NPInvoke(npp_, command_buffer_, "registerObject", transfer_shm_,
+ &transfer_shm_id_)) {
+ Destroy();
+ return INITIALIZATION_ERROR;
+ }
+ DCHECK_GE(transfer_shm_id_, 0);
+
+ // Insert a token.
+ frame_token_ = helper_->InsertToken();
+ if (frame_token_ < 0) {
+ Destroy();
+ return INITIALIZATION_ERROR;
+ }
+
+ // Create a fenced allocator.
+ allocator_ = new FencedAllocatorWrapper(transfer_memory_size_,
+ helper_,
+ transfer_shm_address_);
+
+ SetClientSize(display_platform.width(), display_platform.height());
+
+ return SUCCESS;
+}
+
+static const unsigned int kDefaultCommandBufferSize = 256 << 10;
+
+// This should be enough to hold the biggest possible buffer
+// (2048x2048xABGR16F texture = 32MB)
+static const int32 kDefaultTransferMemorySize = 32 << 20;
+
+RendererCBLocal *RendererCBLocal::CreateDefault(
+ ServiceLocator* service_locator) {
+ return new RendererCBLocal(service_locator,
+ kDefaultTransferMemorySize);
+}
+
+RendererCBLocal::RendererCBLocal(ServiceLocator* service_locator,
+ int32 transfer_memory_size)
+ : RendererCB(service_locator, transfer_memory_size) {
+}
+
+RendererCBLocal::~RendererCBLocal() {
+}
+
+NPObjectPointer<CommandBuffer> RendererCBLocal::CreateCommandBuffer(
+ NPP npp, void* hwnd, int32 size) {
+#if defined(OS_WIN)
+ NPObjectPointer<SharedMemory> ring_buffer =
+ NPCreateObject<SharedMemory>(npp);
+ if (!ring_buffer->Initialize(size))
+ return NPObjectPointer<CommandBuffer>();
+
+ size_t mapped_size;
+ if (!NPBrowser::get()->MapMemory(npp,
+ ring_buffer.Get(),
+ &mapped_size)) {
+ return NPObjectPointer<CommandBuffer>();
+ }
+
+ DCHECK(mapped_size == size);
+
+ NPObjectPointer<CommandBuffer> command_buffer =
+ NPCreateObject<CommandBuffer>(npp);
+ if (!command_buffer->Initialize(ring_buffer))
+ return NPObjectPointer<CommandBuffer>();
+
+ scoped_refptr<GPUProcessor> gpu_processor(
+ new GPUProcessor(npp, command_buffer.Get()));
+ if (!gpu_processor->Initialize(reinterpret_cast<HWND>(hwnd)))
+ return NPObjectPointer<CommandBuffer>();
+
+ command_buffer->SetPutOffsetChangeCallback(
+ NewCallback(gpu_processor.get(), &GPUProcessor::ProcessCommands));
+
+ return command_buffer;
+
+#else
+ return NPObjectPointer<CommandBuffer>();
+#endif
+}
+
+NPObjectPointer<NPObject> RendererCBLocal::CreateSharedMemory(int32 size,
+ NPP npp) {
+ NPObjectPointer<SharedMemory> shared_memory =
+ NPCreateObject<SharedMemory>(npp);
+
+ if (!shared_memory->Initialize(size))
+ return NPObjectPointer<NPObject>();
+
+ return shared_memory;
+}
+
+RendererCBRemote *RendererCBRemote::CreateDefault(
+ ServiceLocator* service_locator) {
+ return new RendererCBRemote(service_locator,
+ kDefaultTransferMemorySize);
+}
+
+RendererCBRemote::RendererCBRemote(ServiceLocator* service_locator,
+ int32 transfer_memory_size)
+ : RendererCB(service_locator, transfer_memory_size) {
+}
+
+RendererCBRemote::~RendererCBRemote() {
+}
+
+NPObjectPointer<NPObject> RendererCBRemote::CreateSharedMemory(int32 size,
+ NPP npp) {
+ NPObjectPointer<NPObject> shared_memory;
+
+ NPObjectPointer<NPObject> window = NPObjectPointer<NPObject>::FromReturned(
+ NPBrowser::get()->GetWindowNPObject(npp));
+ if (!window.Get())
+ return shared_memory;
+
+ NPObjectPointer<NPObject> chromium;
+ if (!NPGetProperty(npp, window, "chromium", &chromium) || !chromium.Get())
+ return shared_memory;
+
+ NPObjectPointer<NPObject> system;
+ if (!NPGetProperty(npp, chromium, "system", &system) || !system.Get())
+ return shared_memory;
+
+ if (!NPInvoke(npp, system, "createSharedMemory", size,
+ &shared_memory)) {
+ return shared_memory;
+ }
+
+ return shared_memory;
+}
+
+Renderer* Renderer::CreateDefaultRenderer(ServiceLocator* service_locator) {
+ return RendererCBLocal::CreateDefault(service_locator);
+}
+
} // namespace o3d
diff --git a/o3d/core/cross/command_buffer/renderer_cb.h b/o3d/core/cross/command_buffer/renderer_cb.h
index 643e05e..5668c21 100644
--- a/o3d/core/cross/command_buffer/renderer_cb.h
+++ b/o3d/core/cross/command_buffer/renderer_cb.h
@@ -38,9 +38,11 @@
#include "core/cross/precompile.h"
#include <vector>
#include "core/cross/renderer.h"
-#include "command_buffer/common/cross/rpc.h"
+#include "command_buffer/common/cross/constants.h"
#include "command_buffer/common/cross/resource.h"
#include "command_buffer/client/cross/id_allocator.h"
+#include "gpu_plugin/command_buffer.h"
+#include "gpu_plugin/np_utils/np_object_pointer.h"
namespace o3d {
namespace command_buffer {
@@ -61,15 +63,7 @@ class RendererCB : public Renderer {
typedef command_buffer::IdAllocator IdAllocator;
typedef command_buffer::FencedAllocatorWrapper FencedAllocatorWrapper;
- // Creates a default RendererCB.
- // The default command buffer is 256K entries.
- // The default transfer buffer is 16MB.
- static RendererCB *CreateDefault(ServiceLocator* service_locator);
- ~RendererCB();
-
- // Initialises the renderer for use, claiming hardware resources.
- virtual InitStatus InitPlatformSpecific(const DisplayWindow& display_window,
- bool off_screen);
+ virtual ~RendererCB();
// Handles the plugin resize event.
virtual void Resize(int width, int height);
@@ -170,13 +164,8 @@ class RendererCB : public Renderer {
// Gets the command buffer helper.
command_buffer::CommandBufferHelper *helper() const { return helper_; }
- // Gets the sync interface.
- command_buffer::BufferSyncInterface *sync_interface() const {
- return sync_interface_;
- }
-
// Gets the registered ID of the transfer shared memory.
- unsigned int transfer_shm_id() const { return transfer_shm_id_; }
+ int32 transfer_shm_id() const { return transfer_shm_id_; }
// Gets the base address of the transfer shared memory.
void *transfer_shm_address() const { return transfer_shm_address_; }
@@ -189,10 +178,11 @@ class RendererCB : public Renderer {
// Overridden from Renderer.
virtual const int* GetRGBAUByteNSwizzleTable();
+ command_buffer::parse_error::ParseError GetParseError();
+
protected:
// Protected so that callers are forced to call the factory method.
- RendererCB(ServiceLocator* service_locator, unsigned int command_buffer_size,
- unsigned int transfer_memory_size);
+ RendererCB(ServiceLocator* service_locator, int32 transfer_memory_size);
// Overridden from Renderer.
virtual bool PlatformSpecificBeginDraw();
@@ -254,19 +244,24 @@ class RendererCB : public Renderer {
// Overridden from Renderer.
virtual void ApplyDirtyStates();
- private:
- // Performs cross-platform initialization.
- void InitCommon(unsigned int width, unsigned int height);
+ protected:
+ // Initializes the renderer for use, claiming hardware resources.
+ virtual InitStatus InitPlatformSpecific(const DisplayWindow& display_window,
+ bool off_screen);
- unsigned int cmd_buffer_size_;
- unsigned int transfer_memory_size_;
- command_buffer::RPCShmHandle transfer_shm_;
- unsigned int transfer_shm_id_;
+ // Create a shared memory object of the given size.
+ virtual gpu_plugin::NPObjectPointer<NPObject>
+ CreateSharedMemory(int32 size, NPP npp) = 0;
+
+ private:
+ int32 transfer_memory_size_;
+ gpu_plugin::NPObjectPointer<NPObject> transfer_shm_;
+ int32 transfer_shm_id_;
void *transfer_shm_address_;
- command_buffer::BufferSyncInterface *sync_interface_;
+ NPP npp_;
+ gpu_plugin::NPObjectPointer<NPObject> command_buffer_;
command_buffer::CommandBufferHelper *helper_;
FencedAllocatorWrapper *allocator_;
- Win32CBServer *cb_server_;
IdAllocator vertex_buffer_ids_;
IdAllocator index_buffer_ids_;
@@ -277,7 +272,7 @@ class RendererCB : public Renderer {
IdAllocator sampler_ids_;
IdAllocator render_surface_ids_;
IdAllocator depth_surface_ids_;
- unsigned int frame_token_;
+ int32 frame_token_;
class StateManager;
scoped_ptr<StateManager> state_manager_;
@@ -285,6 +280,53 @@ class RendererCB : public Renderer {
DISALLOW_COPY_AND_ASSIGN(RendererCB);
};
+// This subclass initializes itself with a locally created in-process
+// CommandBuffer and GPUProcessor. This class will eventually go away and the
+// code in RendererCBRemote will be merged into RendererCB.
+class RendererCBLocal : public RendererCB {
+ public:
+ static gpu_plugin::NPObjectPointer<gpu_plugin::CommandBuffer>
+ CreateCommandBuffer(NPP npp, void* hwnd, int32 size);
+
+ // Creates a default RendererCBLocal.
+ static RendererCBLocal *CreateDefault(ServiceLocator* service_locator);
+
+ protected:
+ RendererCBLocal(ServiceLocator* service_locator,
+ int32 transfer_memory_size);
+ virtual ~RendererCBLocal();
+
+ // Create a shared memory object of the given size using the system services
+ // library directly.
+ virtual gpu_plugin::NPObjectPointer<NPObject>
+ CreateSharedMemory(int32 size, NPP npp);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(RendererCBLocal);
+};
+
+// This subclass initializes itself with a remotely created, potentially out-
+// of-process CommandBuffer. It requires that the browser supports the "system
+// service" to create shared memory, which is not available in the mange branch
+// of Chrome. Use RendererCBLocal for now.
+class RendererCBRemote : public RendererCB {
+ public:
+ // Creates a default RendererCBRemote.
+ static RendererCBRemote *CreateDefault(ServiceLocator* service_locator);
+
+ protected:
+ RendererCBRemote(ServiceLocator* service_locator, int32 transfer_memory_size);
+ virtual ~RendererCBRemote();
+
+ // Create a shared memory object using the browser's
+ // chromium.system.createSharedMemory method.
+ virtual gpu_plugin::NPObjectPointer<NPObject>
+ CreateSharedMemory(int32 size, NPP npp);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(RendererCBRemote);
+};
+
} // namespace o3d
#endif // O3D_CORE_CROSS_COMMAND_BUFFER_RENDERER_CB_H_
diff --git a/o3d/core/cross/renderer_test.cc b/o3d/core/cross/renderer_test.cc
index 680d377..2cde1a9 100644
--- a/o3d/core/cross/renderer_test.cc
+++ b/o3d/core/cross/renderer_test.cc
@@ -78,6 +78,10 @@ TEST_F(RendererTest, CreateDefaultRenderer) {
TEST_F(RendererTest, InitAndDestroyRenderer) {
+// TODO(apatrick): This test will not work as is with command buffers because
+// it attempts to create a Renderer using the same ring buffer as the
+// Renderer created in main.
+#if !defined(RENDERER_CB)
scoped_ptr<Renderer> renderer(
Renderer::CreateDefaultRenderer(service_locator()));
EXPECT_TRUE(renderer->Init(*g_display_window, false));
@@ -100,6 +104,7 @@ TEST_F(RendererTest, InitAndDestroyRenderer) {
// check that the renderer no longer has a Cg Context.
EXPECT_FALSE(gl_renderer->cg_context() != NULL);
#endif
+#endif // RENDERER_CB
}
// Offscreen is only supported on D3D currently
diff --git a/o3d/core/win/command_buffer/win32_cb_server.cc b/o3d/core/win/command_buffer/win32_cb_server.cc
deleted file mode 100644
index 7b70466..0000000
--- a/o3d/core/win/command_buffer/win32_cb_server.cc
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-// This file contains the implementation of the Win32CBServer class.
-
-#include "core/cross/precompile.h"
-#include "core/win/command_buffer/win32_cb_server.h"
-#include "command_buffer/service/cross/buffer_rpc.h"
-#include "command_buffer/service/cross/cmd_buffer_engine.h"
-#include "command_buffer/service/cross/gapi_decoder.h"
-
-namespace o3d {
-
-using command_buffer::GAPIDecoder;
-using command_buffer::IMCSender;
-using command_buffer::IMCMessageProcessor;
-using command_buffer::BufferSyncProxy;
-using command_buffer::CommandBufferEngine;
-
-Win32CBServer::Win32CBServer(HWND window, Features* features)
- : gapi_(),
- proxy_(NULL),
- imc_sender_(NULL),
- thread_(NULL) {
- gapi_.set_hwnd(window);
-
-#if defined(CB_RENDERER_GL)
- gapi_.set_anti_aliased(!features->not_anti_aliased());
-#endif
-
- nacl::Handle handles[2];
- nacl::SocketPair(handles);
-
- socket_pair_[0] = nacl::CreateImcDesc(handles[0]);
- socket_pair_[1] = nacl::CreateImcDesc(handles[1]);
- imc_sender_.reset(new IMCSender(socket_pair_[0]));
- proxy_.reset(new BufferSyncProxy(imc_sender_.get()));
-
- thread_ = ::CreateThread(NULL, 0, ThreadMain, this, 0, NULL);
-}
-
-Win32CBServer::~Win32CBServer() {
- imc_sender_->SendCall(command_buffer::POISONED_MESSAGE_ID, NULL, 0, NULL,
- 0);
- ::WaitForSingleObject(thread_, INFINITE);
- ::CloseHandle(thread_);
-
- nacl::Close(socket_pair_[0]);
- nacl::Close(socket_pair_[1]);
-}
-
-DWORD WINAPI Win32CBServer::ThreadMain(LPVOID param) {
- Win32CBServer *server = static_cast<Win32CBServer *>(param);
-
- scoped_ptr<GAPIDecoder> decoder(new GAPIDecoder(&server->gapi_));
- scoped_ptr<CommandBufferEngine> engine(
- new CommandBufferEngine(decoder.get()));
- decoder->set_engine(engine.get());
-
- IMCMessageProcessor processor(server->socket_pair_[1], engine->rpc_impl());
- engine->set_process_interface(&processor);
- IMCSender sender(server->socket_pair_[1]);
- engine->set_client_rpc(&sender);
-
- server->gapi_.Initialize();
- bool running = true;
- while (running) {
- MSG msg;
- while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- if (msg.message == WM_QUIT) {
- running = false;
- break;
- }
- }
- if (!running) break;
- // DoWork() will block if there is nothing to be done, meaning we are only
- // going to handle message after commands are sent. It should happen at
- // least once a frame, so it's OK.
- // TODO: figure out a way to wait on the socket OR messages with
- // MsgWaitForMultipleObjects. Asynchronous ("overlapped") read on the
- // socket may let us do that.
- running = engine->DoWork();
- }
- server->gapi_.Destroy();
-
- return 0;
-}
-
-} // namespace o3d