| 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/demos/framework/window.h" | 5 #include "gpu/demos/framework/window.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "gpu/command_buffer/client/gles2_implementation.h" | 8 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 9 #include "gpu/command_buffer/client/gles2_lib.h" | 9 #include "gpu/command_buffer/client/gles2_lib.h" |
| 10 #include "gpu/command_buffer/service/command_buffer_service.h" | 10 #include "gpu/command_buffer/service/command_buffer_service.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 demo_->InitWindowSize(width, height); | 44 demo_->InitWindowSize(width, height); |
| 45 return demo_->InitGL(); | 45 return demo_->InitGL(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void Window::OnPaint() { | 48 void Window::OnPaint() { |
| 49 demo_->Draw(); | 49 demo_->Draw(); |
| 50 ::gles2::GetGLContext()->SwapBuffers(); | 50 ::gles2::GetGLContext()->SwapBuffers(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // TODO(apatrick): It looks like all the resources allocated here leak. We |
| 54 // should fix that if we want to use this Window class for anything beyond this |
| 55 // simple use case. |
| 53 bool Window::CreateRenderContext(gfx::PluginWindowHandle hwnd) { | 56 bool Window::CreateRenderContext(gfx::PluginWindowHandle hwnd) { |
| 54 scoped_ptr<CommandBufferService> command_buffer(new CommandBufferService); | 57 scoped_ptr<CommandBufferService> command_buffer(new CommandBufferService); |
| 55 if (!command_buffer->Initialize(kCommandBufferSize)) { | 58 if (!command_buffer->Initialize(kCommandBufferSize)) { |
| 56 return false; | 59 return false; |
| 57 } | 60 } |
| 58 | 61 |
| 59 scoped_refptr<GPUProcessor> gpu_processor( | 62 GPUProcessor* gpu_processor( |
| 60 new GPUProcessor(command_buffer.get())); | 63 new GPUProcessor(command_buffer.get())); |
| 61 if (!gpu_processor->Initialize(hwnd)) { | 64 if (!gpu_processor->Initialize(hwnd, NULL, gfx::Size(), 0)) { |
| 62 return false; | 65 return false; |
| 63 } | 66 } |
| 64 | 67 |
| 65 command_buffer->SetPutOffsetChangeCallback( | 68 command_buffer->SetPutOffsetChangeCallback( |
| 66 NewCallback(gpu_processor.get(), &GPUProcessor::ProcessCommands)); | 69 NewCallback(gpu_processor, &GPUProcessor::ProcessCommands)); |
| 67 | 70 |
| 68 GLES2CmdHelper* helper = new GLES2CmdHelper(command_buffer.get()); | 71 GLES2CmdHelper* helper = new GLES2CmdHelper(command_buffer.get()); |
| 69 if (!helper->Initialize()) { | 72 if (!helper->Initialize()) { |
| 70 // TODO(alokp): cleanup. | 73 // TODO(alokp): cleanup. |
| 71 return false; | 74 return false; |
| 72 } | 75 } |
| 73 | 76 |
| 74 int32 transfer_buffer_id = | 77 int32 transfer_buffer_id = |
| 75 command_buffer->CreateTransferBuffer(kTransferBufferSize); | 78 command_buffer->CreateTransferBuffer(kTransferBufferSize); |
| 76 Buffer transfer_buffer = | 79 Buffer transfer_buffer = |
| 77 command_buffer->GetTransferBuffer(transfer_buffer_id); | 80 command_buffer->GetTransferBuffer(transfer_buffer_id); |
| 78 if (transfer_buffer.ptr == NULL) return false; | 81 if (transfer_buffer.ptr == NULL) return false; |
| 79 | 82 |
| 80 ::gles2::Initialize(); | 83 ::gles2::Initialize(); |
| 81 ::gles2::SetGLContext(new GLES2Implementation(helper, | 84 ::gles2::SetGLContext(new GLES2Implementation(helper, |
| 82 transfer_buffer.size, | 85 transfer_buffer.size, |
| 83 transfer_buffer.ptr, | 86 transfer_buffer.ptr, |
| 84 transfer_buffer_id)); | 87 transfer_buffer_id)); |
| 85 return command_buffer.release() != NULL; | 88 return command_buffer.release() != NULL; |
| 86 } | 89 } |
| 87 | 90 |
| 88 } // namespace demos | 91 } // namespace demos |
| 89 } // namespace gpu | 92 } // namespace gpu |
| 90 | 93 |
| OLD | NEW |