| 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_io_surface.h" | 5 #include "content/common/gpu/gpu_memory_buffer_factory_io_surface.h" |
| 6 | 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
| 8 | 8 |
| 9 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" | 9 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" |
| 10 #include "ui/gl/gl_image_io_surface.h" | 10 #include "ui/gl/gl_image_io_surface.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { | 32 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { |
| 33 } | 33 } |
| 34 | 34 |
| 35 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { | 35 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { |
| 36 } | 36 } |
| 37 | 37 |
| 38 gfx::GpuMemoryBufferHandle | 38 gfx::GpuMemoryBufferHandle |
| 39 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( | 39 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( |
| 40 const gfx::GpuMemoryBufferId& id, | 40 gfx::GpuMemoryBufferId id, |
| 41 const gfx::Size& size, | 41 const gfx::Size& size, |
| 42 gfx::GpuMemoryBuffer::Format format) { | 42 gfx::GpuMemoryBuffer::Format format, |
| 43 int client_id) { |
| 43 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; | 44 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; |
| 44 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, | 45 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, |
| 45 0, | 46 0, |
| 46 &kCFTypeDictionaryKeyCallBacks, | 47 &kCFTypeDictionaryKeyCallBacks, |
| 47 &kCFTypeDictionaryValueCallBacks)); | 48 &kCFTypeDictionaryValueCallBacks)); |
| 48 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); | 49 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); |
| 49 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); | 50 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); |
| 50 AddIntegerValue(properties, | 51 AddIntegerValue(properties, |
| 51 kIOSurfaceBytesPerElement, | 52 kIOSurfaceBytesPerElement, |
| 52 GpuMemoryBufferImpl::BytesPerPixel(format)); | 53 GpuMemoryBufferImpl::BytesPerPixel(format)); |
| 53 AddIntegerValue(properties, | 54 AddIntegerValue(properties, |
| 54 kIOSurfacePixelFormat, | 55 kIOSurfacePixelFormat, |
| 55 GpuMemoryBufferImplIOSurface::PixelFormat(format)); | 56 GpuMemoryBufferImplIOSurface::PixelFormat(format)); |
| 56 // TODO(reveman): Remove this when using a mach_port_t to transfer | 57 // TODO(reveman): Remove this when using a mach_port_t to transfer |
| 57 // IOSurface to browser and renderer process. crbug.com/323304 | 58 // IOSurface to browser and renderer process. crbug.com/323304 |
| 58 AddBooleanValue(properties, kIOSurfaceIsGlobal, true); | 59 AddBooleanValue(properties, kIOSurfaceIsGlobal, true); |
| 59 | 60 |
| 60 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); | 61 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); |
| 61 if (!io_surface) | 62 if (!io_surface) |
| 62 return gfx::GpuMemoryBufferHandle(); | 63 return gfx::GpuMemoryBufferHandle(); |
| 63 | 64 |
| 64 IOSurfaceMapKey key(id.primary_id, id.secondary_id); | 65 IOSurfaceMapKey key(id, client_id); |
| 65 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); | 66 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); |
| 66 io_surfaces_[key] = io_surface; | 67 io_surfaces_[key] = io_surface; |
| 67 | 68 |
| 68 gfx::GpuMemoryBufferHandle handle; | 69 gfx::GpuMemoryBufferHandle handle; |
| 69 handle.type = gfx::IO_SURFACE_BUFFER; | 70 handle.type = gfx::IO_SURFACE_BUFFER; |
| 70 handle.global_id = id; | 71 handle.id = id; |
| 71 handle.io_surface_id = IOSurfaceGetID(io_surface); | 72 handle.io_surface_id = IOSurfaceGetID(io_surface); |
| 72 return handle; | 73 return handle; |
| 73 } | 74 } |
| 74 | 75 |
| 75 void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer( | 76 void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer( |
| 76 const gfx::GpuMemoryBufferId& id) { | 77 gfx::GpuMemoryBufferId id, |
| 77 IOSurfaceMapKey key(id.primary_id, id.secondary_id); | 78 int client_id) { |
| 79 IOSurfaceMapKey key(id, client_id); |
| 78 IOSurfaceMap::iterator it = io_surfaces_.find(key); | 80 IOSurfaceMap::iterator it = io_surfaces_.find(key); |
| 79 if (it != io_surfaces_.end()) | 81 if (it != io_surfaces_.end()) |
| 80 io_surfaces_.erase(it); | 82 io_surfaces_.erase(it); |
| 81 } | 83 } |
| 82 | 84 |
| 83 scoped_refptr<gfx::GLImage> | 85 scoped_refptr<gfx::GLImage> |
| 84 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( | 86 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( |
| 85 const gfx::GpuMemoryBufferId& id, | 87 gfx::GpuMemoryBufferId id, |
| 86 const gfx::Size& size, | 88 const gfx::Size& size, |
| 87 gfx::GpuMemoryBuffer::Format format) { | 89 gfx::GpuMemoryBuffer::Format format, |
| 88 IOSurfaceMapKey key(id.primary_id, id.secondary_id); | 90 int client_id) { |
| 91 IOSurfaceMapKey key(id, client_id); |
| 89 IOSurfaceMap::iterator it = io_surfaces_.find(key); | 92 IOSurfaceMap::iterator it = io_surfaces_.find(key); |
| 90 if (it == io_surfaces_.end()) | 93 if (it == io_surfaces_.end()) |
| 91 return scoped_refptr<gfx::GLImage>(); | 94 return scoped_refptr<gfx::GLImage>(); |
| 92 | 95 |
| 93 scoped_refptr<gfx::GLImageIOSurface> image(new gfx::GLImageIOSurface(size)); | 96 scoped_refptr<gfx::GLImageIOSurface> image(new gfx::GLImageIOSurface(size)); |
| 94 if (!image->Initialize(it->second.get())) | 97 if (!image->Initialize(it->second.get())) |
| 95 return scoped_refptr<gfx::GLImage>(); | 98 return scoped_refptr<gfx::GLImage>(); |
| 96 | 99 |
| 97 return image; | 100 return image; |
| 98 } | 101 } |
| 99 | 102 |
| 100 } // namespace content | 103 } // namespace content |
| OLD | NEW |