| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/exo/shared_memory.h" | 5 #include "components/exo/shared_memory.h" |
| 6 | 6 |
| 7 #include <GLES2/gl2extchromium.h> | 7 #include <GLES2/gl2extchromium.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 15 #include "components/exo/buffer.h" | 15 #include "components/exo/buffer.h" |
| 16 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 16 #include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h" |
| 17 #include "third_party/khronos/GLES2/gl2.h" | 17 #include "third_party/khronos/GLES2/gl2.h" |
| 18 #include "ui/aura/env.h" | |
| 19 #include "ui/compositor/compositor.h" | 18 #include "ui/compositor/compositor.h" |
| 20 #include "ui/gfx/buffer_format_util.h" | 19 #include "ui/gfx/buffer_format_util.h" |
| 21 #include "ui/gfx/geometry/size.h" | 20 #include "ui/gfx/geometry/size.h" |
| 22 #include "ui/gfx/gpu_memory_buffer.h" | 21 #include "ui/gfx/gpu_memory_buffer.h" |
| 23 | 22 |
| 24 namespace exo { | 23 namespace exo { |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| 27 bool IsSupportedFormat(gfx::BufferFormat format) { | 26 bool IsSupportedFormat(gfx::BufferFormat format) { |
| 28 return format == gfx::BufferFormat::RGBX_8888 || | 27 return format == gfx::BufferFormat::RGBX_8888 || |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 return nullptr; | 62 return nullptr; |
| 64 } | 63 } |
| 65 | 64 |
| 66 gfx::GpuMemoryBufferHandle handle; | 65 gfx::GpuMemoryBufferHandle handle; |
| 67 handle.type = gfx::SHARED_MEMORY_BUFFER; | 66 handle.type = gfx::SHARED_MEMORY_BUFFER; |
| 68 handle.handle = base::SharedMemory::DuplicateHandle(shared_memory_.handle()); | 67 handle.handle = base::SharedMemory::DuplicateHandle(shared_memory_.handle()); |
| 69 handle.offset = offset; | 68 handle.offset = offset; |
| 70 handle.stride = stride; | 69 handle.stride = stride; |
| 71 | 70 |
| 72 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer = | 71 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer = |
| 73 aura::Env::GetInstance() | 72 gpu::GpuMemoryBufferImplSharedMemory::CreateFromHandle( |
| 74 ->context_factory() | 73 handle, size, format, gfx::BufferUsage::GPU_READ, |
| 75 ->GetGpuMemoryBufferManager() | 74 gpu::GpuMemoryBufferImpl::DestructionCallback()); |
| 76 ->CreateGpuMemoryBufferFromHandle(handle, size, format); | |
| 77 if (!gpu_memory_buffer) { | 75 if (!gpu_memory_buffer) { |
| 78 LOG(ERROR) << "Failed to create GpuMemoryBuffer from handle"; | 76 LOG(ERROR) << "Failed to create GpuMemoryBuffer from handle"; |
| 79 return nullptr; | 77 return nullptr; |
| 80 } | 78 } |
| 81 | 79 |
| 82 // Zero-copy doesn't provide a benefit in the case of shared memory as an | 80 // Zero-copy doesn't provide a benefit in the case of shared memory as an |
| 83 // implicit copy is required when trying to use these buffers as zero-copy | 81 // implicit copy is required when trying to use these buffers as zero-copy |
| 84 // buffers. Making the copy explicit allows the buffer to be reused earlier. | 82 // buffers. Making the copy explicit allows the buffer to be reused earlier. |
| 85 bool use_zero_copy = false; | 83 bool use_zero_copy = false; |
| 86 | 84 |
| 87 return base::MakeUnique<Buffer>( | 85 return base::MakeUnique<Buffer>( |
| 88 std::move(gpu_memory_buffer), GL_TEXTURE_2D, | 86 std::move(gpu_memory_buffer), GL_TEXTURE_2D, |
| 89 // COMMANDS_ISSUED queries are sufficient for shared memory | 87 // COMMANDS_ISSUED queries are sufficient for shared memory |
| 90 // buffers as binding to texture is implemented using a call to | 88 // buffers as binding to texture is implemented using a call to |
| 91 // glTexImage2D and the buffer can be reused as soon as that | 89 // glTexImage2D and the buffer can be reused as soon as that |
| 92 // command has been issued. | 90 // command has been issued. |
| 93 GL_COMMANDS_ISSUED_CHROMIUM, use_zero_copy, | 91 GL_COMMANDS_ISSUED_CHROMIUM, use_zero_copy, |
| 94 false /* is_overlay_candidate */); | 92 false /* is_overlay_candidate */); |
| 95 } | 93 } |
| 96 | 94 |
| 97 } // namespace exo | 95 } // namespace exo |
| OLD | NEW |