| 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" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 void AddBooleanValue(CFMutableDictionaryRef dictionary, | 15 void AddBooleanValue(CFMutableDictionaryRef dictionary, |
| 16 const CFStringRef key, | 16 const CFStringRef key, |
| 17 bool value) { | 17 bool value) { |
| 18 CFDictionaryAddValue( | 18 CFDictionaryAddValue( |
| 19 dictionary, key, value ? kCFBooleanTrue : kCFBooleanFalse); | 19 dictionary, key, value ? kCFBooleanTrue : kCFBooleanFalse); |
| 20 } | 20 } |
| 21 | 21 |
| 22 void AddIntegerValue(CFMutableDictionaryRef dictionary, | 22 void AddIntegerValue(CFMutableDictionaryRef dictionary, |
| 23 const CFStringRef key, | 23 const CFStringRef key, |
| 24 int32 value) { | 24 int32 value) { |
| 25 base::ScopedCFTypeRef<CFNumberRef> number( | 25 base::ScopedCFTypeRef<CFNumberRef> number( |
| 26 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); | 26 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); |
| 27 CFDictionaryAddValue(dictionary, key, number.get()); | 27 CFDictionaryAddValue(dictionary, key, number.get()); |
| 28 } | 28 } |
| 29 | 29 |
| 30 int32 PixelFormat(gfx::GpuMemoryBuffer::Format format) { |
| 31 switch (format) { |
| 32 case gfx::GpuMemoryBuffer::BGRA_8888: |
| 33 return 'BGRA'; |
| 34 case gfx::GpuMemoryBuffer::RGBA_8888: |
| 35 case gfx::GpuMemoryBuffer::RGBX_8888: |
| 36 NOTREACHED(); |
| 37 return 0; |
| 38 } |
| 39 |
| 40 NOTREACHED(); |
| 41 return 0; |
| 42 } |
| 43 |
| 30 } // namespace | 44 } // namespace |
| 31 | 45 |
| 32 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { | 46 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { |
| 33 } | 47 } |
| 34 | 48 |
| 35 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { | 49 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { |
| 36 } | 50 } |
| 37 | 51 |
| 38 gfx::GpuMemoryBufferHandle | 52 gfx::GpuMemoryBufferHandle |
| 39 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( | 53 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( |
| 40 gfx::GpuMemoryBufferId id, | 54 gfx::GpuMemoryBufferId id, |
| 41 const gfx::Size& size, | 55 const gfx::Size& size, |
| 42 gfx::GpuMemoryBuffer::Format format, | 56 gfx::GpuMemoryBuffer::Format format, |
| 43 int client_id) { | 57 int client_id) { |
| 44 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; | 58 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; |
| 45 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, | 59 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, |
| 46 0, | 60 0, |
| 47 &kCFTypeDictionaryKeyCallBacks, | 61 &kCFTypeDictionaryKeyCallBacks, |
| 48 &kCFTypeDictionaryValueCallBacks)); | 62 &kCFTypeDictionaryValueCallBacks)); |
| 49 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); | 63 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); |
| 50 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); | 64 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); |
| 51 AddIntegerValue(properties, | 65 AddIntegerValue(properties, |
| 52 kIOSurfaceBytesPerElement, | 66 kIOSurfaceBytesPerElement, |
| 53 GpuMemoryBufferImpl::BytesPerPixel(format)); | 67 GpuMemoryBufferImpl::BytesPerPixel(format)); |
| 54 AddIntegerValue(properties, | 68 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); |
| 55 kIOSurfacePixelFormat, | |
| 56 GpuMemoryBufferImplIOSurface::PixelFormat(format)); | |
| 57 // TODO(reveman): Remove this when using a mach_port_t to transfer | 69 // TODO(reveman): Remove this when using a mach_port_t to transfer |
| 58 // IOSurface to browser and renderer process. crbug.com/323304 | 70 // IOSurface to browser and renderer process. crbug.com/323304 |
| 59 AddBooleanValue(properties, kIOSurfaceIsGlobal, true); | 71 AddBooleanValue(properties, kIOSurfaceIsGlobal, true); |
| 60 | 72 |
| 61 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); | 73 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); |
| 62 if (!io_surface) | 74 if (!io_surface) |
| 63 return gfx::GpuMemoryBufferHandle(); | 75 return gfx::GpuMemoryBufferHandle(); |
| 64 | 76 |
| 65 IOSurfaceMapKey key(id, client_id); | 77 IOSurfaceMapKey key(id, client_id); |
| 66 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); | 78 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 94 return scoped_refptr<gfx::GLImage>(); | 106 return scoped_refptr<gfx::GLImage>(); |
| 95 | 107 |
| 96 scoped_refptr<gfx::GLImageIOSurface> image(new gfx::GLImageIOSurface(size)); | 108 scoped_refptr<gfx::GLImageIOSurface> image(new gfx::GLImageIOSurface(size)); |
| 97 if (!image->Initialize(it->second.get())) | 109 if (!image->Initialize(it->second.get())) |
| 98 return scoped_refptr<gfx::GLImage>(); | 110 return scoped_refptr<gfx::GLImage>(); |
| 99 | 111 |
| 100 return image; | 112 return image; |
| 101 } | 113 } |
| 102 | 114 |
| 103 } // namespace content | 115 } // namespace content |
| OLD | NEW |