| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/services/gles2/command_buffer_impl.h" | 5 #include "mojo/services/gles2/command_buffer_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
| 9 | 9 |
| 10 #include "gpu/command_buffer/common/constants.h" | 10 #include "gpu/command_buffer/common/constants.h" |
| 11 #include "gpu/command_buffer/service/command_buffer_service.h" | 11 #include "gpu/command_buffer/service/command_buffer_service.h" |
| 12 #include "gpu/command_buffer/service/context_group.h" | 12 #include "gpu/command_buffer/service/context_group.h" |
| 13 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 13 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 14 #include "gpu/command_buffer/service/gpu_control_service.h" | 14 #include "gpu/command_buffer/service/gpu_control_service.h" |
| 15 #include "gpu/command_buffer/service/gpu_scheduler.h" | 15 #include "gpu/command_buffer/service/gpu_scheduler.h" |
| 16 #include "gpu/command_buffer/service/image_manager.h" | 16 #include "gpu/command_buffer/service/image_manager.h" |
| 17 #include "gpu/command_buffer/service/mailbox_manager.h" | 17 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 18 #include "gpu/command_buffer/service/memory_tracking.h" | 18 #include "gpu/command_buffer/service/memory_tracking.h" |
| 19 #include "mojo/public/cpp/bindings/allocation_scope.h" | 19 #include "mojo/public/cpp/bindings/allocation_scope.h" |
| 20 #include "mojo/services/gles2/command_buffer_type_conversions.h" | 20 #include "mojo/services/gles2/command_buffer_type_conversions.h" |
| 21 #include "mojo/services/gles2/mojo_buffer_backing.h" |
| 21 #include "ui/gl/gl_context.h" | 22 #include "ui/gl/gl_context.h" |
| 22 #include "ui/gl/gl_surface.h" | 23 #include "ui/gl/gl_surface.h" |
| 23 | 24 |
| 24 namespace mojo { | 25 namespace mojo { |
| 25 namespace services { | 26 namespace services { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 class MemoryTrackerStub : public gpu::gles2::MemoryTracker { | 30 class MemoryTrackerStub : public gpu::gles2::MemoryTracker { |
| 30 public: | 31 public: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 49 | 50 |
| 50 CommandBufferImpl::CommandBufferImpl(ScopedCommandBufferClientHandle client, | 51 CommandBufferImpl::CommandBufferImpl(ScopedCommandBufferClientHandle client, |
| 51 gfx::AcceleratedWidget widget, | 52 gfx::AcceleratedWidget widget, |
| 52 const gfx::Size& size) | 53 const gfx::Size& size) |
| 53 : client_(client.Pass(), this), widget_(widget), size_(size) {} | 54 : client_(client.Pass(), this), widget_(widget), size_(size) {} |
| 54 | 55 |
| 55 CommandBufferImpl::~CommandBufferImpl() { client_->DidDestroy(); } | 56 CommandBufferImpl::~CommandBufferImpl() { client_->DidDestroy(); } |
| 56 | 57 |
| 57 void CommandBufferImpl::Initialize( | 58 void CommandBufferImpl::Initialize( |
| 58 ScopedCommandBufferSyncClientHandle sync_client, | 59 ScopedCommandBufferSyncClientHandle sync_client, |
| 59 const ShmHandle& shared_state) { | 60 mojo::ScopedSharedBufferHandle shared_state) { |
| 60 sync_client_.reset(sync_client.Pass(), NULL); | 61 sync_client_.reset(sync_client.Pass(), NULL); |
| 61 sync_client_->DidInitialize(DoInitialize(shared_state)); | 62 sync_client_->DidInitialize(DoInitialize(shared_state.Pass())); |
| 62 } | 63 } |
| 63 | 64 |
| 64 bool CommandBufferImpl::DoInitialize(const ShmHandle& shared_state) { | 65 bool CommandBufferImpl::DoInitialize( |
| 66 mojo::ScopedSharedBufferHandle shared_state) { |
| 65 // TODO(piman): offscreen surface. | 67 // TODO(piman): offscreen surface. |
| 66 scoped_refptr<gfx::GLSurface> surface = | 68 scoped_refptr<gfx::GLSurface> surface = |
| 67 gfx::GLSurface::CreateViewGLSurface(widget_); | 69 gfx::GLSurface::CreateViewGLSurface(widget_); |
| 68 if (!surface.get()) | 70 if (!surface.get()) |
| 69 return false; | 71 return false; |
| 70 | 72 |
| 71 // TODO(piman): context sharing, virtual contexts, gpu preference. | 73 // TODO(piman): context sharing, virtual contexts, gpu preference. |
| 72 scoped_refptr<gfx::GLContext> context = gfx::GLContext::CreateGLContext( | 74 scoped_refptr<gfx::GLContext> context = gfx::GLContext::CreateGLContext( |
| 73 NULL, surface.get(), gfx::PreferIntegratedGpu); | 75 NULL, surface.get(), gfx::PreferIntegratedGpu); |
| 74 if (!context.get()) | 76 if (!context.get()) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 command_buffer_->SetPutOffsetChangeCallback(base::Bind( | 114 command_buffer_->SetPutOffsetChangeCallback(base::Bind( |
| 113 &gpu::GpuScheduler::PutChanged, base::Unretained(scheduler_.get()))); | 115 &gpu::GpuScheduler::PutChanged, base::Unretained(scheduler_.get()))); |
| 114 command_buffer_->SetGetBufferChangeCallback(base::Bind( | 116 command_buffer_->SetGetBufferChangeCallback(base::Bind( |
| 115 &gpu::GpuScheduler::SetGetBuffer, base::Unretained(scheduler_.get()))); | 117 &gpu::GpuScheduler::SetGetBuffer, base::Unretained(scheduler_.get()))); |
| 116 command_buffer_->SetParseErrorCallback( | 118 command_buffer_->SetParseErrorCallback( |
| 117 base::Bind(&CommandBufferImpl::OnParseError, base::Unretained(this))); | 119 base::Bind(&CommandBufferImpl::OnParseError, base::Unretained(this))); |
| 118 | 120 |
| 119 // TODO(piman): other callbacks | 121 // TODO(piman): other callbacks |
| 120 | 122 |
| 121 const size_t kSize = sizeof(gpu::CommandBufferSharedState); | 123 const size_t kSize = sizeof(gpu::CommandBufferSharedState); |
| 122 scoped_ptr<base::SharedMemory> shared_state_shm( | 124 scoped_ptr<gpu::BufferBacking> backing( |
| 123 new base::SharedMemory(shared_state, false)); | 125 gles2::MojoBufferBacking::Create(shared_state.Pass(), kSize)); |
| 124 if (!shared_state_shm->Map(kSize)) | 126 if (!backing.get()) |
| 125 return false; | 127 return false; |
| 126 | 128 |
| 127 command_buffer_->SetSharedStateBuffer( | 129 command_buffer_->SetSharedStateBuffer(backing.Pass()); |
| 128 gpu::MakeBackingFromSharedMemory(shared_state_shm.Pass(), kSize)); | |
| 129 return true; | 130 return true; |
| 130 } | 131 } |
| 131 | 132 |
| 132 void CommandBufferImpl::SetGetBuffer(int32_t buffer) { | 133 void CommandBufferImpl::SetGetBuffer(int32_t buffer) { |
| 133 command_buffer_->SetGetBuffer(buffer); | 134 command_buffer_->SetGetBuffer(buffer); |
| 134 } | 135 } |
| 135 | 136 |
| 136 void CommandBufferImpl::Flush(int32_t put_offset) { | 137 void CommandBufferImpl::Flush(int32_t put_offset) { |
| 137 command_buffer_->Flush(put_offset); | 138 command_buffer_->Flush(put_offset); |
| 138 } | 139 } |
| 139 | 140 |
| 140 void CommandBufferImpl::MakeProgress(int32_t last_get_offset) { | 141 void CommandBufferImpl::MakeProgress(int32_t last_get_offset) { |
| 141 // TODO(piman): handle out-of-order. | 142 // TODO(piman): handle out-of-order. |
| 142 AllocationScope scope; | 143 AllocationScope scope; |
| 143 sync_client_->DidMakeProgress(command_buffer_->GetState()); | 144 sync_client_->DidMakeProgress(command_buffer_->GetState()); |
| 144 } | 145 } |
| 145 | 146 |
| 146 void CommandBufferImpl::RegisterTransferBuffer(int32_t id, | 147 void CommandBufferImpl::RegisterTransferBuffer( |
| 147 const ShmHandle& transfer_buffer, | 148 int32_t id, |
| 148 uint32_t size) { | 149 mojo::ScopedSharedBufferHandle transfer_buffer, |
| 150 uint32_t size) { |
| 149 // Take ownership of the memory and map it into this process. | 151 // Take ownership of the memory and map it into this process. |
| 150 // This validates the size. | 152 // This validates the size. |
| 151 scoped_ptr<base::SharedMemory> shared_memory( | 153 scoped_ptr<gpu::BufferBacking> backing( |
| 152 new base::SharedMemory(transfer_buffer, false)); | 154 gles2::MojoBufferBacking::Create(transfer_buffer.Pass(), size)); |
| 153 if (!shared_memory->Map(size)) { | 155 if (!backing.get()) { |
| 154 DVLOG(0) << "Failed to map shared memory."; | 156 DVLOG(0) << "Failed to map shared memory."; |
| 155 return; | 157 return; |
| 156 } | 158 } |
| 157 | 159 command_buffer_->RegisterTransferBuffer(id, backing.Pass()); |
| 158 command_buffer_->RegisterTransferBuffer( | |
| 159 id, gpu::MakeBackingFromSharedMemory(shared_memory.Pass(), size)); | |
| 160 } | 160 } |
| 161 | 161 |
| 162 void CommandBufferImpl::DestroyTransferBuffer(int32_t id) { | 162 void CommandBufferImpl::DestroyTransferBuffer(int32_t id) { |
| 163 command_buffer_->DestroyTransferBuffer(id); | 163 command_buffer_->DestroyTransferBuffer(id); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void CommandBufferImpl::Echo(const Callback<void()>& callback) { | 166 void CommandBufferImpl::Echo(const Callback<void()>& callback) { |
| 167 callback.Run(); | 167 callback.Run(); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void CommandBufferImpl::RequestAnimationFrames() { | 170 void CommandBufferImpl::RequestAnimationFrames() { |
| 171 timer_.Start(FROM_HERE, | 171 timer_.Start(FROM_HERE, |
| 172 base::TimeDelta::FromMilliseconds(16), | 172 base::TimeDelta::FromMilliseconds(16), |
| 173 this, | 173 this, |
| 174 &CommandBufferImpl::DrawAnimationFrame); | 174 &CommandBufferImpl::DrawAnimationFrame); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void CommandBufferImpl::CancelAnimationFrames() { timer_.Stop(); } | 177 void CommandBufferImpl::CancelAnimationFrames() { timer_.Stop(); } |
| 178 | 178 |
| 179 void CommandBufferImpl::OnParseError() { | 179 void CommandBufferImpl::OnParseError() { |
| 180 gpu::CommandBuffer::State state = command_buffer_->GetState(); | 180 gpu::CommandBuffer::State state = command_buffer_->GetState(); |
| 181 client_->LostContext(state.context_lost_reason); | 181 client_->LostContext(state.context_lost_reason); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void CommandBufferImpl::DrawAnimationFrame() { client_->DrawAnimationFrame(); } | 184 void CommandBufferImpl::DrawAnimationFrame() { client_->DrawAnimationFrame(); } |
| 185 | 185 |
| 186 } // namespace services | 186 } // namespace services |
| 187 } // namespace mojo | 187 } // namespace mojo |
| OLD | NEW |