| 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 "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/gl/gl_image_io_surface.h" | 10 #include "ui/gl/gl_image_io_surface.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 97 } |
| 98 | 98 |
| 99 gfx::GpuMemoryBufferHandle | 99 gfx::GpuMemoryBufferHandle |
| 100 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( | 100 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( |
| 101 gfx::GpuMemoryBufferId id, | 101 gfx::GpuMemoryBufferId id, |
| 102 const gfx::Size& size, | 102 const gfx::Size& size, |
| 103 gfx::GpuMemoryBuffer::Format format, | 103 gfx::GpuMemoryBuffer::Format format, |
| 104 gfx::GpuMemoryBuffer::Usage usage, | 104 gfx::GpuMemoryBuffer::Usage usage, |
| 105 int client_id, | 105 int client_id, |
| 106 gfx::PluginWindowHandle surface_handle) { | 106 gfx::PluginWindowHandle surface_handle) { |
| 107 DCHECK(thread_checker_.CalledOnValidThread()); |
| 107 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; | 108 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; |
| 108 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, | 109 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, |
| 109 0, | 110 0, |
| 110 &kCFTypeDictionaryKeyCallBacks, | 111 &kCFTypeDictionaryKeyCallBacks, |
| 111 &kCFTypeDictionaryValueCallBacks)); | 112 &kCFTypeDictionaryValueCallBacks)); |
| 112 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); | 113 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); |
| 113 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); | 114 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); |
| 114 AddIntegerValue(properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); | 115 AddIntegerValue(properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); |
| 115 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); | 116 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); |
| 116 // TODO(reveman): Remove this when using a mach_port_t to transfer | 117 // TODO(reveman): Remove this when using a mach_port_t to transfer |
| 117 // IOSurface to browser and renderer process. crbug.com/323304 | 118 // IOSurface to browser and renderer process. crbug.com/323304 |
| 118 AddBooleanValue(properties, kIOSurfaceIsGlobal, true); | 119 AddBooleanValue(properties, kIOSurfaceIsGlobal, true); |
| 119 | 120 |
| 120 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); | 121 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); |
| 121 if (!io_surface) | 122 if (!io_surface) |
| 122 return gfx::GpuMemoryBufferHandle(); | 123 return gfx::GpuMemoryBufferHandle(); |
| 123 | 124 |
| 124 { | 125 IOSurfaceMapKey key(id, client_id); |
| 125 base::AutoLock lock(io_surfaces_lock_); | 126 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); |
| 126 | 127 io_surfaces_[key] = io_surface; |
| 127 IOSurfaceMapKey key(id, client_id); | |
| 128 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); | |
| 129 io_surfaces_[key] = io_surface; | |
| 130 } | |
| 131 | 128 |
| 132 gfx::GpuMemoryBufferHandle handle; | 129 gfx::GpuMemoryBufferHandle handle; |
| 133 handle.type = gfx::IO_SURFACE_BUFFER; | 130 handle.type = gfx::IO_SURFACE_BUFFER; |
| 134 handle.id = id; | 131 handle.id = id; |
| 135 handle.io_surface_id = IOSurfaceGetID(io_surface); | 132 handle.io_surface_id = IOSurfaceGetID(io_surface); |
| 136 return handle; | 133 return handle; |
| 137 } | 134 } |
| 138 | 135 |
| 139 void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer( | 136 void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer( |
| 140 gfx::GpuMemoryBufferId id, | 137 gfx::GpuMemoryBufferId id, |
| 141 int client_id) { | 138 int client_id) { |
| 142 base::AutoLock lock(io_surfaces_lock_); | 139 DCHECK(thread_checker_.CalledOnValidThread()); |
| 143 | |
| 144 IOSurfaceMapKey key(id, client_id); | 140 IOSurfaceMapKey key(id, client_id); |
| 145 IOSurfaceMap::iterator it = io_surfaces_.find(key); | 141 IOSurfaceMap::iterator it = io_surfaces_.find(key); |
| 146 if (it != io_surfaces_.end()) | 142 if (it != io_surfaces_.end()) |
| 147 io_surfaces_.erase(it); | 143 io_surfaces_.erase(it); |
| 148 } | 144 } |
| 149 | 145 |
| 150 gpu::ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() { | 146 gpu::ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() { |
| 151 return this; | 147 return this; |
| 152 } | 148 } |
| 153 | 149 |
| 154 scoped_refptr<gfx::GLImage> | 150 scoped_refptr<gfx::GLImage> |
| 155 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( | 151 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( |
| 156 const gfx::GpuMemoryBufferHandle& handle, | 152 const gfx::GpuMemoryBufferHandle& handle, |
| 157 const gfx::Size& size, | 153 const gfx::Size& size, |
| 158 gfx::GpuMemoryBuffer::Format format, | 154 gfx::GpuMemoryBuffer::Format format, |
| 159 unsigned internalformat, | 155 unsigned internalformat, |
| 160 int client_id) { | 156 int client_id) { |
| 161 base::AutoLock lock(io_surfaces_lock_); | 157 DCHECK(thread_checker_.CalledOnValidThread()); |
| 162 | |
| 163 DCHECK_EQ(handle.type, gfx::IO_SURFACE_BUFFER); | 158 DCHECK_EQ(handle.type, gfx::IO_SURFACE_BUFFER); |
| 164 IOSurfaceMapKey key(handle.id, client_id); | 159 IOSurfaceMapKey key(handle.id, client_id); |
| 165 IOSurfaceMap::iterator it = io_surfaces_.find(key); | 160 IOSurfaceMap::iterator it = io_surfaces_.find(key); |
| 166 if (it == io_surfaces_.end()) | 161 if (it == io_surfaces_.end()) |
| 167 return scoped_refptr<gfx::GLImage>(); | 162 return scoped_refptr<gfx::GLImage>(); |
| 168 | 163 |
| 169 scoped_refptr<gfx::GLImageIOSurface> image(new gfx::GLImageIOSurface(size)); | 164 scoped_refptr<gfx::GLImageIOSurface> image(new gfx::GLImageIOSurface(size)); |
| 170 if (!image->Initialize(it->second.get())) | 165 if (!image->Initialize(it->second.get())) |
| 171 return scoped_refptr<gfx::GLImage>(); | 166 return scoped_refptr<gfx::GLImage>(); |
| 172 | 167 |
| 173 return image; | 168 return image; |
| 174 } | 169 } |
| 175 | 170 |
| 176 } // namespace content | 171 } // namespace content |
| OLD | NEW |