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 "components/view_manager/gles2/command_buffer_driver.h" | 5 #include "components/view_manager/gles2/command_buffer_driver.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
10 #include "components/view_manager/gles2/command_buffer_type_conversions.h" | 10 #include "components/view_manager/gles2/command_buffer_type_conversions.h" |
11 #include "components/view_manager/gles2/mojo_buffer_backing.h" | 11 #include "components/view_manager/gles2/mojo_buffer_backing.h" |
12 #include "gpu/command_buffer/common/constants.h" | 12 #include "gpu/command_buffer/common/constants.h" |
13 #include "gpu/command_buffer/common/value_state.h" | 13 #include "gpu/command_buffer/common/value_state.h" |
14 #include "gpu/command_buffer/service/command_buffer_service.h" | 14 #include "gpu/command_buffer/service/command_buffer_service.h" |
15 #include "gpu/command_buffer/service/context_group.h" | 15 #include "gpu/command_buffer/service/context_group.h" |
16 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 16 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
17 #include "gpu/command_buffer/service/gpu_scheduler.h" | 17 #include "gpu/command_buffer/service/gpu_scheduler.h" |
18 #include "gpu/command_buffer/service/image_factory.h" | |
18 #include "gpu/command_buffer/service/image_manager.h" | 19 #include "gpu/command_buffer/service/image_manager.h" |
19 #include "gpu/command_buffer/service/mailbox_manager.h" | 20 #include "gpu/command_buffer/service/mailbox_manager.h" |
20 #include "gpu/command_buffer/service/memory_tracking.h" | 21 #include "gpu/command_buffer/service/memory_tracking.h" |
21 #include "gpu/command_buffer/service/sync_point_manager.h" | 22 #include "gpu/command_buffer/service/sync_point_manager.h" |
22 #include "gpu/command_buffer/service/valuebuffer_manager.h" | 23 #include "gpu/command_buffer/service/valuebuffer_manager.h" |
24 #include "mojo/converters/geometry/geometry_type_converters.h" | |
25 #include "mojo/platform_handle/platform_handle_functions.h" | |
26 #include "ui/gfx/gpu_memory_buffer.h" | |
23 #include "ui/gfx/vsync_provider.h" | 27 #include "ui/gfx/vsync_provider.h" |
24 #include "ui/gl/gl_context.h" | 28 #include "ui/gl/gl_context.h" |
29 #include "ui/gl/gl_image_shared_memory.h" | |
25 #include "ui/gl/gl_surface.h" | 30 #include "ui/gl/gl_surface.h" |
26 | 31 |
27 namespace gles2 { | 32 namespace gles2 { |
28 | 33 |
29 namespace { | 34 namespace { |
30 | 35 |
31 class MemoryTrackerStub : public gpu::gles2::MemoryTracker { | 36 class MemoryTrackerStub : public gpu::gles2::MemoryTracker { |
32 public: | 37 public: |
33 MemoryTrackerStub() {} | 38 MemoryTrackerStub() {} |
34 | 39 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 } | 220 } |
216 | 221 |
217 void CommandBufferDriver::DestroyTransferBuffer(int32_t id) { | 222 void CommandBufferDriver::DestroyTransferBuffer(int32_t id) { |
218 command_buffer_->DestroyTransferBuffer(id); | 223 command_buffer_->DestroyTransferBuffer(id); |
219 } | 224 } |
220 | 225 |
221 void CommandBufferDriver::Echo(const mojo::Callback<void()>& callback) { | 226 void CommandBufferDriver::Echo(const mojo::Callback<void()>& callback) { |
222 callback.Run(); | 227 callback.Run(); |
223 } | 228 } |
224 | 229 |
230 void CommandBufferDriver::CreateImage(int32_t id, | |
231 mojo::ScopedHandle memory_handle, | |
232 int32 type, | |
233 mojo::SizePtr size, | |
234 int32_t format, | |
235 int32_t internal_format) { | |
236 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); | |
237 if (image_manager->LookupImage(id)) { | |
238 LOG(ERROR) << "Image already exists with same ID."; | |
239 return; | |
240 } | |
241 | |
242 gfx::GpuMemoryBuffer::Format gpu_format = | |
243 static_cast<gfx::GpuMemoryBuffer::Format>(format); | |
244 if (!gpu::ImageFactory::IsGpuMemoryBufferFormatSupported( | |
245 gpu_format, decoder_->GetCapabilities())) { | |
246 LOG(ERROR) << "Format is not supported."; | |
247 return; | |
248 } | |
249 | |
250 gfx::Size gfx_size = size.To<gfx::Size>(); | |
251 if (!gpu::ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat( | |
252 gfx_size, gpu_format)) { | |
253 LOG(ERROR) << "Invalid image size for format."; | |
254 return; | |
255 } | |
256 | |
257 if (!gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( | |
258 internal_format, gpu_format)) { | |
259 LOG(ERROR) << "Incompatible image format."; | |
260 return; | |
261 } | |
262 | |
263 if (type != gfx::SHARED_MEMORY_BUFFER) { | |
264 NOTIMPLEMENTED(); | |
265 return; | |
266 } | |
267 | |
268 gfx::GpuMemoryBufferHandle gfx_handle; | |
269 // TODO(jam): create mojo enum for this and converter | |
270 gfx_handle.type = static_cast<gfx::GpuMemoryBufferType>(type); | |
271 gfx_handle.id = id; | |
272 | |
273 MojoPlatformHandle platform_handle; | |
274 MojoResult extract_result = MojoExtractPlatformHandle( | |
275 memory_handle.release().value(), | |
276 &platform_handle); | |
277 if (extract_result != MOJO_RESULT_OK) { | |
278 NOTREACHED(); | |
279 return; | |
280 } | |
281 | |
282 #if defined(OS_WIN) | |
283 gfx_handle.handle = platform_handle; | |
284 #else | |
285 gfx_handle.handle = base::FileDescriptor(platform_handle, false); | |
tfarina
2015/10/26 12:12:08
Unfortunately this does not work on Mac:
../../co
| |
286 #endif | |
287 | |
288 scoped_refptr<gfx::GLImageSharedMemory> image = | |
289 new gfx::GLImageSharedMemory(gfx_size, internal_format); | |
290 // TODO(jam): also need a mojo enum for this enum | |
291 if (!image->Initialize(gfx_handle, gpu_format)) { | |
292 NOTREACHED(); | |
293 return; | |
294 } | |
295 | |
296 image_manager->AddImage(image.get(), id); | |
297 } | |
298 | |
299 void CommandBufferDriver::DestroyImage(int32_t id) { | |
300 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); | |
301 if (!image_manager->LookupImage(id)) { | |
302 LOG(ERROR) << "Image with ID doesn't exist."; | |
303 return; | |
304 } | |
305 image_manager->RemoveImage(id); | |
306 } | |
307 | |
225 void CommandBufferDriver::OnParseError() { | 308 void CommandBufferDriver::OnParseError() { |
226 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); | 309 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); |
227 OnContextLost(state.context_lost_reason); | 310 OnContextLost(state.context_lost_reason); |
228 } | 311 } |
229 | 312 |
230 void CommandBufferDriver::OnResize(gfx::Size size, float scale_factor) { | 313 void CommandBufferDriver::OnResize(gfx::Size size, float scale_factor) { |
231 surface_->Resize(size); | 314 surface_->Resize(size); |
232 } | 315 } |
233 | 316 |
234 bool CommandBufferDriver::OnWaitSyncPoint(uint32_t sync_point) { | 317 bool CommandBufferDriver::OnWaitSyncPoint(uint32_t sync_point) { |
(...skipping 25 matching lines...) Expand all Loading... | |
260 | 343 |
261 void CommandBufferDriver::DestroyDecoder() { | 344 void CommandBufferDriver::DestroyDecoder() { |
262 if (decoder_) { | 345 if (decoder_) { |
263 bool have_context = decoder_->MakeCurrent(); | 346 bool have_context = decoder_->MakeCurrent(); |
264 decoder_->Destroy(have_context); | 347 decoder_->Destroy(have_context); |
265 decoder_.reset(); | 348 decoder_.reset(); |
266 } | 349 } |
267 } | 350 } |
268 | 351 |
269 } // namespace gles2 | 352 } // namespace gles2 |
OLD | NEW |