| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/gles2/command_buffer_client_impl.h" | 5 #include "mojo/gles2/command_buffer_client_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
| 7 #include <limits> | 10 #include <limits> |
| 8 #include <utility> | 11 #include <utility> |
| 9 | 12 |
| 10 #include "base/logging.h" | 13 #include "base/logging.h" |
| 11 #include "base/process/process_handle.h" | 14 #include "base/process/process_handle.h" |
| 12 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
| 13 #include "components/mus/gles2/command_buffer_type_conversions.h" | 16 #include "components/mus/gles2/command_buffer_type_conversions.h" |
| 14 #include "components/mus/gles2/mojo_buffer_backing.h" | 17 #include "components/mus/gles2/mojo_buffer_backing.h" |
| 15 #include "components/mus/gles2/mojo_gpu_memory_buffer.h" | 18 #include "components/mus/gles2/mojo_gpu_memory_buffer.h" |
| 16 #include "gpu/command_buffer/common/sync_token.h" | 19 #include "gpu/command_buffer/common/sync_token.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 DCHECK_EQ(gpu::CommandBufferNamespace::MOJO, info->command_buffer_namespace); | 118 DCHECK_EQ(gpu::CommandBufferNamespace::MOJO, info->command_buffer_namespace); |
| 116 command_buffer_id_ = info->command_buffer_id; | 119 command_buffer_id_ = info->command_buffer_id; |
| 117 capabilities_ = info->capabilities.To<gpu::Capabilities>(); | 120 capabilities_ = info->capabilities.To<gpu::Capabilities>(); |
| 118 return true; | 121 return true; |
| 119 } | 122 } |
| 120 | 123 |
| 121 gpu::CommandBuffer::State CommandBufferClientImpl::GetLastState() { | 124 gpu::CommandBuffer::State CommandBufferClientImpl::GetLastState() { |
| 122 return last_state_; | 125 return last_state_; |
| 123 } | 126 } |
| 124 | 127 |
| 125 int32 CommandBufferClientImpl::GetLastToken() { | 128 int32_t CommandBufferClientImpl::GetLastToken() { |
| 126 TryUpdateState(); | 129 TryUpdateState(); |
| 127 return last_state_.token; | 130 return last_state_.token; |
| 128 } | 131 } |
| 129 | 132 |
| 130 void CommandBufferClientImpl::Flush(int32 put_offset) { | 133 void CommandBufferClientImpl::Flush(int32_t put_offset) { |
| 131 if (last_put_offset_ == put_offset) | 134 if (last_put_offset_ == put_offset) |
| 132 return; | 135 return; |
| 133 | 136 |
| 134 last_put_offset_ = put_offset; | 137 last_put_offset_ = put_offset; |
| 135 command_buffer_->Flush(put_offset); | 138 command_buffer_->Flush(put_offset); |
| 136 flushed_fence_sync_release_ = next_fence_sync_release_ - 1; | 139 flushed_fence_sync_release_ = next_fence_sync_release_ - 1; |
| 137 } | 140 } |
| 138 | 141 |
| 139 void CommandBufferClientImpl::OrderingBarrier(int32_t put_offset) { | 142 void CommandBufferClientImpl::OrderingBarrier(int32_t put_offset) { |
| 140 // TODO(jamesr): Implement this more efficiently. | 143 // TODO(jamesr): Implement this more efficiently. |
| 141 Flush(put_offset); | 144 Flush(put_offset); |
| 142 } | 145 } |
| 143 | 146 |
| 144 void CommandBufferClientImpl::WaitForTokenInRange(int32 start, int32 end) { | 147 void CommandBufferClientImpl::WaitForTokenInRange(int32_t start, int32_t end) { |
| 145 TryUpdateState(); | 148 TryUpdateState(); |
| 146 while (!InRange(start, end, last_state_.token) && | 149 while (!InRange(start, end, last_state_.token) && |
| 147 last_state_.error == gpu::error::kNoError) { | 150 last_state_.error == gpu::error::kNoError) { |
| 148 MakeProgressAndUpdateState(); | 151 MakeProgressAndUpdateState(); |
| 149 TryUpdateState(); | 152 TryUpdateState(); |
| 150 } | 153 } |
| 151 } | 154 } |
| 152 | 155 |
| 153 void CommandBufferClientImpl::WaitForGetOffsetInRange(int32 start, int32 end) { | 156 void CommandBufferClientImpl::WaitForGetOffsetInRange(int32_t start, |
| 157 int32_t end) { |
| 154 TryUpdateState(); | 158 TryUpdateState(); |
| 155 while (!InRange(start, end, last_state_.get_offset) && | 159 while (!InRange(start, end, last_state_.get_offset) && |
| 156 last_state_.error == gpu::error::kNoError) { | 160 last_state_.error == gpu::error::kNoError) { |
| 157 MakeProgressAndUpdateState(); | 161 MakeProgressAndUpdateState(); |
| 158 TryUpdateState(); | 162 TryUpdateState(); |
| 159 } | 163 } |
| 160 } | 164 } |
| 161 | 165 |
| 162 void CommandBufferClientImpl::SetGetBuffer(int32 shm_id) { | 166 void CommandBufferClientImpl::SetGetBuffer(int32_t shm_id) { |
| 163 command_buffer_->SetGetBuffer(shm_id); | 167 command_buffer_->SetGetBuffer(shm_id); |
| 164 last_put_offset_ = -1; | 168 last_put_offset_ = -1; |
| 165 } | 169 } |
| 166 | 170 |
| 167 scoped_refptr<gpu::Buffer> CommandBufferClientImpl::CreateTransferBuffer( | 171 scoped_refptr<gpu::Buffer> CommandBufferClientImpl::CreateTransferBuffer( |
| 168 size_t size, | 172 size_t size, |
| 169 int32* id) { | 173 int32_t* id) { |
| 170 if (size >= std::numeric_limits<uint32_t>::max()) | 174 if (size >= std::numeric_limits<uint32_t>::max()) |
| 171 return NULL; | 175 return NULL; |
| 172 | 176 |
| 173 void* memory = NULL; | 177 void* memory = NULL; |
| 174 mojo::ScopedSharedBufferHandle handle; | 178 mojo::ScopedSharedBufferHandle handle; |
| 175 mojo::ScopedSharedBufferHandle duped; | 179 mojo::ScopedSharedBufferHandle duped; |
| 176 if (!CreateMapAndDupSharedBuffer(size, &memory, &handle, &duped)) { | 180 if (!CreateMapAndDupSharedBuffer(size, &memory, &handle, &duped)) { |
| 177 if (last_state_.error == gpu::error::kNoError) | 181 if (last_state_.error == gpu::error::kNoError) |
| 178 last_state_.error = gpu::error::kLostContext; | 182 last_state_.error = gpu::error::kLostContext; |
| 179 return NULL; | 183 return NULL; |
| 180 } | 184 } |
| 181 | 185 |
| 182 *id = ++next_transfer_buffer_id_; | 186 *id = ++next_transfer_buffer_id_; |
| 183 | 187 |
| 184 command_buffer_->RegisterTransferBuffer(*id, std::move(duped), | 188 command_buffer_->RegisterTransferBuffer(*id, std::move(duped), |
| 185 static_cast<uint32_t>(size)); | 189 static_cast<uint32_t>(size)); |
| 186 | 190 |
| 187 scoped_ptr<gpu::BufferBacking> backing( | 191 scoped_ptr<gpu::BufferBacking> backing( |
| 188 new mus::MojoBufferBacking(std::move(handle), memory, size)); | 192 new mus::MojoBufferBacking(std::move(handle), memory, size)); |
| 189 scoped_refptr<gpu::Buffer> buffer(new gpu::Buffer(std::move(backing))); | 193 scoped_refptr<gpu::Buffer> buffer(new gpu::Buffer(std::move(backing))); |
| 190 return buffer; | 194 return buffer; |
| 191 } | 195 } |
| 192 | 196 |
| 193 void CommandBufferClientImpl::DestroyTransferBuffer(int32 id) { | 197 void CommandBufferClientImpl::DestroyTransferBuffer(int32_t id) { |
| 194 command_buffer_->DestroyTransferBuffer(id); | 198 command_buffer_->DestroyTransferBuffer(id); |
| 195 } | 199 } |
| 196 | 200 |
| 197 gpu::Capabilities CommandBufferClientImpl::GetCapabilities() { | 201 gpu::Capabilities CommandBufferClientImpl::GetCapabilities() { |
| 198 return capabilities_; | 202 return capabilities_; |
| 199 } | 203 } |
| 200 | 204 |
| 201 int32_t CommandBufferClientImpl::CreateImage(ClientBuffer buffer, | 205 int32_t CommandBufferClientImpl::CreateImage(ClientBuffer buffer, |
| 202 size_t width, | 206 size_t width, |
| 203 size_t height, | 207 size_t height, |
| 204 unsigned internalformat) { | 208 unsigned internalformat) { |
| 205 int32 new_id = ++next_image_id_; | 209 int32_t new_id = ++next_image_id_; |
| 206 | 210 |
| 207 mojo::SizePtr size = mojo::Size::New(); | 211 mojo::SizePtr size = mojo::Size::New(); |
| 208 size->width = static_cast<int32_t>(width); | 212 size->width = static_cast<int32_t>(width); |
| 209 size->height = static_cast<int32_t>(height); | 213 size->height = static_cast<int32_t>(height); |
| 210 | 214 |
| 211 mus::MojoGpuMemoryBufferImpl* gpu_memory_buffer = | 215 mus::MojoGpuMemoryBufferImpl* gpu_memory_buffer = |
| 212 mus::MojoGpuMemoryBufferImpl::FromClientBuffer(buffer); | 216 mus::MojoGpuMemoryBufferImpl::FromClientBuffer(buffer); |
| 213 gfx::GpuMemoryBufferHandle handle = gpu_memory_buffer->GetHandle(); | 217 gfx::GpuMemoryBufferHandle handle = gpu_memory_buffer->GetHandle(); |
| 214 | 218 |
| 215 bool requires_sync_point = false; | 219 bool requires_sync_point = false; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 243 NOTIMPLEMENTED(); | 247 NOTIMPLEMENTED(); |
| 244 // TODO(jam): need to support this if we support types other than | 248 // TODO(jam): need to support this if we support types other than |
| 245 // SHARED_MEMORY_BUFFER. | 249 // SHARED_MEMORY_BUFFER. |
| 246 //gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer, | 250 //gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer, |
| 247 // InsertSyncPoint()); | 251 // InsertSyncPoint()); |
| 248 } | 252 } |
| 249 | 253 |
| 250 return new_id; | 254 return new_id; |
| 251 } | 255 } |
| 252 | 256 |
| 253 void CommandBufferClientImpl::DestroyImage(int32 id) { | 257 void CommandBufferClientImpl::DestroyImage(int32_t id) { |
| 254 command_buffer_->DestroyImage(id); | 258 command_buffer_->DestroyImage(id); |
| 255 } | 259 } |
| 256 | 260 |
| 257 int32_t CommandBufferClientImpl::CreateGpuMemoryBufferImage( | 261 int32_t CommandBufferClientImpl::CreateGpuMemoryBufferImage( |
| 258 size_t width, | 262 size_t width, |
| 259 size_t height, | 263 size_t height, |
| 260 unsigned internalformat, | 264 unsigned internalformat, |
| 261 unsigned usage) { | 265 unsigned usage) { |
| 262 scoped_ptr<gfx::GpuMemoryBuffer> buffer(mus::MojoGpuMemoryBufferImpl::Create( | 266 scoped_ptr<gfx::GpuMemoryBuffer> buffer(mus::MojoGpuMemoryBufferImpl::Create( |
| 263 gfx::Size(static_cast<int>(width), static_cast<int>(height)), | 267 gfx::Size(static_cast<int>(width), static_cast<int>(height)), |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 | 392 |
| 389 // It is also safe to wait on the same context. | 393 // It is also safe to wait on the same context. |
| 390 if (sync_token->namespace_id() == gpu::CommandBufferNamespace::MOJO && | 394 if (sync_token->namespace_id() == gpu::CommandBufferNamespace::MOJO && |
| 391 sync_token->command_buffer_id() == GetCommandBufferID()) | 395 sync_token->command_buffer_id() == GetCommandBufferID()) |
| 392 return true; | 396 return true; |
| 393 | 397 |
| 394 return false; | 398 return false; |
| 395 } | 399 } |
| 396 | 400 |
| 397 } // namespace gles2 | 401 } // namespace gles2 |
| OLD | NEW |