summaryrefslogtreecommitdiffstats
path: root/o3d/gpu_plugin/gpu_processor_win.cc
diff options
context:
space:
mode:
authorapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-24 19:19:25 +0000
committerapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-24 19:19:25 +0000
commit2331a49ecb27f38888bf4f60f24e054cbb8a8890 (patch)
treede3d03558bd82742292cebb81f1ed68ba1626342 /o3d/gpu_plugin/gpu_processor_win.cc
parentdfb5a4cc453d4a78e655d6f4cb5e11e8ced54c1b (diff)
downloadchromium_src-2331a49ecb27f38888bf4f60f24e054cbb8a8890.zip
chromium_src-2331a49ecb27f38888bf4f60f24e054cbb8a8890.tar.gz
chromium_src-2331a49ecb27f38888bf4f60f24e054cbb8a8890.tar.bz2
GPUProcessor uses O3D command buffer service to render to a window.
Added libraries that contain a subset of the O3D command buffer code independent on NaCl. Extracted Upcall interface from CommandBufferEngine. Now this works in JavaScript to clear the GPU plugin element to a random color: // BEGIN_FRAME sharedMemory.setInt32(putOffset++, 0x00000201); // CLEAR sharedMemory.setInt32(putOffset++, 0x00000408); sharedMemory.setInt32(putOffset++, 7); sharedMemory.setFloat(putOffset++, Math.random()); sharedMemory.setFloat(putOffset++, Math.random()); sharedMemory.setFloat(putOffset++, Math.random()); sharedMemory.setFloat(putOffset++, 1); sharedMemory.setFloat(putOffset++, 0.5); sharedMemory.setInt32(putOffset++, 0); // END_FRAME sharedMemory.setInt32(putOffset++, 0x00000301); TEST=none BUG=none Review URL: http://codereview.chromium.org/234001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27098 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/gpu_plugin/gpu_processor_win.cc')
-rw-r--r--o3d/gpu_plugin/gpu_processor_win.cc85
1 files changed, 65 insertions, 20 deletions
diff --git a/o3d/gpu_plugin/gpu_processor_win.cc b/o3d/gpu_plugin/gpu_processor_win.cc
index 88a84e3..acd667f 100644
--- a/o3d/gpu_plugin/gpu_processor_win.cc
+++ b/o3d/gpu_plugin/gpu_processor_win.cc
@@ -9,30 +9,75 @@
namespace o3d {
namespace gpu_plugin {
-GPUProcessor::GPUProcessor(const NPObjectPointer<CommandBuffer>& command_buffer)
- : command_buffer_(command_buffer),
- window_handle_(NULL),
- window_width_(0),
- window_height_(0) {
+GPUProcessor::GPUProcessor(NPP npp,
+ const NPObjectPointer<CommandBuffer>& command_buffer)
+ : npp_(npp),
+ command_buffer_(command_buffer),
+ commands_per_update_(100) {
+ gapi_.reset(new command_buffer::GAPID3D9);
+
+ decoder_.reset(new command_buffer::GAPIDecoder(gapi_.get()));
+
+ NPObjectPointer<CHRSharedMemory> ring_buffer =
+ command_buffer->GetRingBuffer();
+
+ if (ring_buffer.Get()) {
+ parser_.reset(new command_buffer::CommandParser(ring_buffer->ptr,
+ ring_buffer->size,
+ 0,
+ ring_buffer->size,
+ 0,
+ decoder_.get()));
+ } else {
+ parser_.reset(new command_buffer::CommandParser(NULL, 0, 0, 0, 0,
+ decoder_.get()));
+ }
}
-void GPUProcessor::SetWindow(HWND handle, int width, int height) {
- window_handle_ = handle;
- window_width_ = width;
- window_height_ = height;
+GPUProcessor::GPUProcessor(NPP npp,
+ const NPObjectPointer<CommandBuffer>& command_buffer,
+ command_buffer::GAPID3D9* gapi,
+ command_buffer::GAPIDecoder* decoder,
+ command_buffer::CommandParser* parser,
+ int commands_per_update)
+ : npp_(npp),
+ command_buffer_(command_buffer),
+ commands_per_update_(commands_per_update) {
+ gapi_.reset(gapi);
+ decoder_.reset(decoder);
+ parser_.reset(parser);
+}
+
+bool GPUProcessor::Initialize(HWND handle) {
+ // Cannot reinitialize.
+ DCHECK(gapi_->hwnd() == NULL);
+
+ // Initialize GAPI immediately if the window handle is valid.
+ if (handle) {
+ gapi_->set_hwnd(handle);
+ return gapi_->Initialize();
+ } else {
+ return true;
+ }
}
-void GPUProcessor::DrawRectangle(uint32 color,
- int left, int top, int right, int bottom) {
- if (!window_handle_)
- return;
-
- HBRUSH brush = ::CreateSolidBrush(color);
- HDC dc = ::GetDC(window_handle_);
- RECT rect = { left, right, top, bottom };
- ::FillRect(dc, &rect, brush);
- ::ReleaseDC(window_handle_, dc);
- ::DeleteObject(brush);
+void GPUProcessor::Destroy() {
+ // Destroy GAPI if window handle has not already become invalid.
+ if (gapi_->hwnd()) {
+ gapi_->Destroy();
+ gapi_->set_hwnd(NULL);
+ }
+}
+
+void GPUProcessor::SetWindow(HWND handle, int width, int height) {
+ if (handle == NULL) {
+ // Destroy GAPI when the window handle becomes invalid.
+ Destroy();
+ } else {
+ if (handle != gapi_->hwnd()) {
+ Initialize(handle);
+ }
+ }
}
} // namespace gpu_plugin