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> | 9 #include <vector> |
10 | 10 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 &kCFTypeDictionaryValueCallBacks)); | 118 &kCFTypeDictionaryValueCallBacks)); |
119 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); | 119 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); |
120 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); | 120 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); |
121 AddIntegerValue(properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); | 121 AddIntegerValue(properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); |
122 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); | 122 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); |
123 | 123 |
124 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); | 124 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); |
125 if (!io_surface) | 125 if (!io_surface) |
126 return gfx::GpuMemoryBufferHandle(); | 126 return gfx::GpuMemoryBufferHandle(); |
127 | 127 |
128 if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id, | 128 if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id.id, client_id, |
129 io_surface)) { | 129 io_surface)) { |
130 return gfx::GpuMemoryBufferHandle(); | 130 return gfx::GpuMemoryBufferHandle(); |
131 } | 131 } |
132 | 132 |
133 { | 133 { |
134 base::AutoLock lock(io_surfaces_lock_); | 134 base::AutoLock lock(io_surfaces_lock_); |
135 | 135 |
136 IOSurfaceMapKey key(id, client_id); | 136 IOSurfaceMapKey key(id.id, client_id); |
137 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); | 137 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); |
138 io_surfaces_[key] = io_surface; | 138 io_surfaces_[key] = io_surface; |
139 } | 139 } |
140 | 140 |
141 gfx::GpuMemoryBufferHandle handle; | 141 gfx::GpuMemoryBufferHandle handle; |
142 handle.type = gfx::IO_SURFACE_BUFFER; | 142 handle.type = gfx::IO_SURFACE_BUFFER; |
143 handle.id = id; | 143 handle.id = id; |
144 return handle; | 144 return handle; |
145 } | 145 } |
146 | 146 |
147 void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer( | 147 void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer( |
148 gfx::GpuMemoryBufferId id, | 148 gfx::GpuMemoryBufferId id, |
149 int client_id) { | 149 int client_id) { |
150 { | 150 { |
151 base::AutoLock lock(io_surfaces_lock_); | 151 base::AutoLock lock(io_surfaces_lock_); |
152 | 152 |
153 IOSurfaceMapKey key(id, client_id); | 153 IOSurfaceMapKey key(id.id, client_id); |
154 DCHECK(io_surfaces_.find(key) != io_surfaces_.end()); | 154 DCHECK(io_surfaces_.find(key) != io_surfaces_.end()); |
155 io_surfaces_.erase(key); | 155 io_surfaces_.erase(key); |
156 } | 156 } |
157 | 157 |
158 IOSurfaceManager::GetInstance()->UnregisterIOSurface(id, client_id); | 158 IOSurfaceManager::GetInstance()->UnregisterIOSurface(id.id, client_id); |
159 } | 159 } |
160 | 160 |
161 gpu::ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() { | 161 gpu::ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() { |
162 return this; | 162 return this; |
163 } | 163 } |
164 | 164 |
165 scoped_refptr<gfx::GLImage> | 165 scoped_refptr<gfx::GLImage> |
166 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( | 166 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( |
167 const gfx::GpuMemoryBufferHandle& handle, | 167 const gfx::GpuMemoryBufferHandle& handle, |
168 const gfx::Size& size, | 168 const gfx::Size& size, |
169 gfx::BufferFormat format, | 169 gfx::BufferFormat format, |
170 unsigned internalformat, | 170 unsigned internalformat, |
171 int client_id) { | 171 int client_id) { |
172 base::AutoLock lock(io_surfaces_lock_); | 172 base::AutoLock lock(io_surfaces_lock_); |
173 | 173 |
174 DCHECK_EQ(handle.type, gfx::IO_SURFACE_BUFFER); | 174 DCHECK_EQ(handle.type, gfx::IO_SURFACE_BUFFER); |
175 IOSurfaceMapKey key(handle.id, client_id); | 175 IOSurfaceMapKey key(handle.id.id, client_id); |
176 IOSurfaceMap::iterator it = io_surfaces_.find(key); | 176 IOSurfaceMap::iterator it = io_surfaces_.find(key); |
177 if (it == io_surfaces_.end()) | 177 if (it == io_surfaces_.end()) |
178 return scoped_refptr<gfx::GLImage>(); | 178 return scoped_refptr<gfx::GLImage>(); |
179 | 179 |
180 scoped_refptr<gfx::GLImageIOSurface> image( | 180 scoped_refptr<gfx::GLImageIOSurface> image( |
181 new gfx::GLImageIOSurface(size, internalformat)); | 181 new gfx::GLImageIOSurface(size, internalformat)); |
182 if (!image->Initialize(it->second.get(), format)) | 182 if (!image->Initialize(it->second.get(), format)) |
183 return scoped_refptr<gfx::GLImage>(); | 183 return scoped_refptr<gfx::GLImage>(); |
184 | 184 |
185 return image; | 185 return image; |
186 } | 186 } |
187 | 187 |
188 } // namespace content | 188 } // namespace content |
OLD | NEW |