| 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 "content/common/gpu/gpu_memory_buffer_factory_shared_memory.h" | 5 #include "content/common/gpu/gpu_memory_buffer_factory_shared_memory.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" | 8 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" |
| 9 #include "ui/gl/gl_image.h" | 9 #include "ui/gl/gl_image.h" |
| 10 #include "ui/gl/gl_image_shared_memory.h" | 10 #include "ui/gl/gl_image_shared_memory.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 gfx::GpuMemoryBufferHandle | 32 gfx::GpuMemoryBufferHandle |
| 33 GpuMemoryBufferFactorySharedMemory::CreateGpuMemoryBuffer( | 33 GpuMemoryBufferFactorySharedMemory::CreateGpuMemoryBuffer( |
| 34 gfx::GpuMemoryBufferId id, | 34 gfx::GpuMemoryBufferId id, |
| 35 const gfx::Size& size, | 35 const gfx::Size& size, |
| 36 gfx::GpuMemoryBuffer::Format format, | 36 gfx::GpuMemoryBuffer::Format format, |
| 37 gfx::GpuMemoryBuffer::Usage usage, | 37 gfx::GpuMemoryBuffer::Usage usage, |
| 38 int client_id, | 38 int client_id, |
| 39 gfx::PluginWindowHandle surface_handle) { | 39 gfx::PluginWindowHandle surface_handle) { |
| 40 base::SharedMemory shared_memory; | 40 base::SharedMemory shared_memory; |
| 41 if (!shared_memory.CreateAnonymous( | 41 |
| 42 size.GetArea() * GpuMemoryBufferImpl::BytesPerPixel(format))) | 42 size_t stride_in_bytes = 0; |
| 43 if (!GpuMemoryBufferImpl::StrideInBytes( |
| 44 size.width(), format, &stride_in_bytes)) |
| 45 return gfx::GpuMemoryBufferHandle(); |
| 46 |
| 47 base::CheckedNumeric<size_t> size_in_bytes = stride_in_bytes; |
| 48 size_in_bytes *= size.height(); |
| 49 if (!size_in_bytes.IsValid()) |
| 50 return gfx::GpuMemoryBufferHandle(); |
| 51 |
| 52 if (!shared_memory.CreateAnonymous(size_in_bytes.ValueOrDie())) |
| 43 return gfx::GpuMemoryBufferHandle(); | 53 return gfx::GpuMemoryBufferHandle(); |
| 44 | 54 |
| 45 gfx::GpuMemoryBufferHandle handle; | 55 gfx::GpuMemoryBufferHandle handle; |
| 46 handle.type = gfx::SHARED_MEMORY_BUFFER; | 56 handle.type = gfx::SHARED_MEMORY_BUFFER; |
| 47 handle.id = id; | 57 handle.id = id; |
| 48 shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), &handle.handle); | 58 shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), &handle.handle); |
| 49 return handle; | 59 return handle; |
| 50 } | 60 } |
| 51 | 61 |
| 52 void GpuMemoryBufferFactorySharedMemory::DestroyGpuMemoryBuffer( | 62 void GpuMemoryBufferFactorySharedMemory::DestroyGpuMemoryBuffer( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 67 int client_id) { | 77 int client_id) { |
| 68 scoped_refptr<gfx::GLImageSharedMemory> image( | 78 scoped_refptr<gfx::GLImageSharedMemory> image( |
| 69 new gfx::GLImageSharedMemory(size, internalformat)); | 79 new gfx::GLImageSharedMemory(size, internalformat)); |
| 70 if (!image->Initialize(handle, format)) | 80 if (!image->Initialize(handle, format)) |
| 71 return scoped_refptr<gfx::GLImage>(); | 81 return scoped_refptr<gfx::GLImage>(); |
| 72 | 82 |
| 73 return image; | 83 return image; |
| 74 } | 84 } |
| 75 | 85 |
| 76 } // namespace content | 86 } // namespace content |
| OLD | NEW |