| 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 <vector> |
| 10 |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "content/common/mac/io_surface_manager.h" |
| 10 #include "ui/gl/gl_image_io_surface.h" | 13 #include "ui/gl/gl_image_io_surface.h" |
| 11 | 14 |
| 12 namespace content { | 15 namespace content { |
| 13 namespace { | 16 namespace { |
| 14 | 17 |
| 15 void AddBooleanValue(CFMutableDictionaryRef dictionary, | |
| 16 const CFStringRef key, | |
| 17 bool value) { | |
| 18 CFDictionaryAddValue( | |
| 19 dictionary, key, value ? kCFBooleanTrue : kCFBooleanFalse); | |
| 20 } | |
| 21 | |
| 22 void AddIntegerValue(CFMutableDictionaryRef dictionary, | 18 void AddIntegerValue(CFMutableDictionaryRef dictionary, |
| 23 const CFStringRef key, | 19 const CFStringRef key, |
| 24 int32 value) { | 20 int32 value) { |
| 25 base::ScopedCFTypeRef<CFNumberRef> number( | 21 base::ScopedCFTypeRef<CFNumberRef> number( |
| 26 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); | 22 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); |
| 27 CFDictionaryAddValue(dictionary, key, number.get()); | 23 CFDictionaryAddValue(dictionary, key, number.get()); |
| 28 } | 24 } |
| 29 | 25 |
| 30 int32 BytesPerPixel(gfx::GpuMemoryBuffer::Format format) { | 26 int32 BytesPerPixel(gfx::GpuMemoryBuffer::Format format) { |
| 31 switch (format) { | 27 switch (format) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 gfx::PluginWindowHandle surface_handle) { | 110 gfx::PluginWindowHandle surface_handle) { |
| 115 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; | 111 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; |
| 116 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, | 112 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, |
| 117 0, | 113 0, |
| 118 &kCFTypeDictionaryKeyCallBacks, | 114 &kCFTypeDictionaryKeyCallBacks, |
| 119 &kCFTypeDictionaryValueCallBacks)); | 115 &kCFTypeDictionaryValueCallBacks)); |
| 120 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); | 116 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); |
| 121 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); | 117 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); |
| 122 AddIntegerValue(properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); | 118 AddIntegerValue(properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); |
| 123 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); | 119 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); |
| 124 // TODO(reveman): Remove this when using a mach_port_t to transfer | |
| 125 // IOSurface to browser and renderer process. crbug.com/323304 | |
| 126 AddBooleanValue(properties, kIOSurfaceIsGlobal, true); | |
| 127 | 120 |
| 128 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); | 121 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); |
| 129 if (!io_surface) | 122 if (!io_surface) |
| 130 return gfx::GpuMemoryBufferHandle(); | 123 return gfx::GpuMemoryBufferHandle(); |
| 131 | 124 |
| 125 if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id, |
| 126 io_surface)) { |
| 127 return gfx::GpuMemoryBufferHandle(); |
| 128 } |
| 129 |
| 132 { | 130 { |
| 133 base::AutoLock lock(io_surfaces_lock_); | 131 base::AutoLock lock(io_surfaces_lock_); |
| 134 | 132 |
| 135 IOSurfaceMapKey key(id, client_id); | 133 IOSurfaceMapKey key(id, client_id); |
| 136 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); | 134 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); |
| 137 io_surfaces_[key] = io_surface; | 135 io_surfaces_[key] = io_surface; |
| 138 } | 136 } |
| 139 | 137 |
| 140 gfx::GpuMemoryBufferHandle handle; | 138 gfx::GpuMemoryBufferHandle handle; |
| 141 handle.type = gfx::IO_SURFACE_BUFFER; | 139 handle.type = gfx::IO_SURFACE_BUFFER; |
| 142 handle.id = id; | 140 handle.id = id; |
| 143 handle.io_surface_id = IOSurfaceGetID(io_surface); | |
| 144 return handle; | 141 return handle; |
| 145 } | 142 } |
| 146 | 143 |
| 147 void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer( | 144 void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer( |
| 148 gfx::GpuMemoryBufferId id, | 145 gfx::GpuMemoryBufferId id, |
| 149 int client_id) { | 146 int client_id) { |
| 150 base::AutoLock lock(io_surfaces_lock_); | 147 { |
| 148 base::AutoLock lock(io_surfaces_lock_); |
| 151 | 149 |
| 152 IOSurfaceMapKey key(id, client_id); | 150 IOSurfaceMapKey key(id, client_id); |
| 153 DCHECK(io_surfaces_.find(key) != io_surfaces_.end()); | 151 DCHECK(io_surfaces_.find(key) != io_surfaces_.end()); |
| 154 io_surfaces_.erase(key); | 152 io_surfaces_.erase(key); |
| 153 } |
| 154 |
| 155 IOSurfaceManager::GetInstance()->UnregisterIOSurface(id, client_id); |
| 155 } | 156 } |
| 156 | 157 |
| 157 gpu::ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() { | 158 gpu::ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() { |
| 158 return this; | 159 return this; |
| 159 } | 160 } |
| 160 | 161 |
| 161 scoped_refptr<gfx::GLImage> | 162 scoped_refptr<gfx::GLImage> |
| 162 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( | 163 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( |
| 163 const gfx::GpuMemoryBufferHandle& handle, | 164 const gfx::GpuMemoryBufferHandle& handle, |
| 164 const gfx::Size& size, | 165 const gfx::Size& size, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 175 | 176 |
| 176 scoped_refptr<gfx::GLImageIOSurface> image( | 177 scoped_refptr<gfx::GLImageIOSurface> image( |
| 177 new gfx::GLImageIOSurface(size, internalformat)); | 178 new gfx::GLImageIOSurface(size, internalformat)); |
| 178 if (!image->Initialize(it->second.get(), format)) | 179 if (!image->Initialize(it->second.get(), format)) |
| 179 return scoped_refptr<gfx::GLImage>(); | 180 return scoped_refptr<gfx::GLImage>(); |
| 180 | 181 |
| 181 return image; | 182 return image; |
| 182 } | 183 } |
| 183 | 184 |
| 184 } // namespace content | 185 } // namespace content |
| OLD | NEW |