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 "gpu/ipc/service/gpu_memory_buffer_factory_io_surface.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ui/gfx/buffer_format_util.h" | 10 #include "ui/gfx/buffer_format_util.h" |
11 #include "ui/gfx/mac/io_surface.h" | 11 #include "ui/gfx/mac/io_surface.h" |
12 #include "ui/gl/gl_image_io_surface.h" | 12 #include "ui/gl/gl_image_io_surface.h" |
13 | 13 |
14 namespace content { | 14 namespace gpu { |
15 | 15 |
16 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { | 16 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { |
17 } | 17 } |
18 | 18 |
19 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { | 19 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { |
20 } | 20 } |
21 | 21 |
22 gfx::GpuMemoryBufferHandle | 22 gfx::GpuMemoryBufferHandle |
23 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( | 23 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( |
24 gfx::GpuMemoryBufferId id, | 24 gfx::GpuMemoryBufferId id, |
25 const gfx::Size& size, | 25 const gfx::Size& size, |
26 gfx::BufferFormat format, | 26 gfx::BufferFormat format, |
27 gfx::BufferUsage usage, | 27 gfx::BufferUsage usage, |
28 int client_id, | 28 int client_id, |
29 gpu::SurfaceHandle surface_handle) { | 29 SurfaceHandle surface_handle) { |
30 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( | 30 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( |
31 gfx::CreateIOSurface(size, format)); | 31 gfx::CreateIOSurface(size, format)); |
32 if (!io_surface) | 32 if (!io_surface) |
33 return gfx::GpuMemoryBufferHandle(); | 33 return gfx::GpuMemoryBufferHandle(); |
34 | 34 |
35 { | 35 { |
36 base::AutoLock lock(io_surfaces_lock_); | 36 base::AutoLock lock(io_surfaces_lock_); |
37 | 37 |
38 IOSurfaceMapKey key(id, client_id); | 38 IOSurfaceMapKey key(id, client_id); |
39 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); | 39 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); |
(...skipping 23 matching lines...) Expand all Loading... |
63 int client_id) { | 63 int client_id) { |
64 { | 64 { |
65 base::AutoLock lock(io_surfaces_lock_); | 65 base::AutoLock lock(io_surfaces_lock_); |
66 | 66 |
67 IOSurfaceMapKey key(id, client_id); | 67 IOSurfaceMapKey key(id, client_id); |
68 DCHECK(io_surfaces_.find(key) != io_surfaces_.end()); | 68 DCHECK(io_surfaces_.find(key) != io_surfaces_.end()); |
69 io_surfaces_.erase(key); | 69 io_surfaces_.erase(key); |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 gpu::ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() { | 73 ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() { |
74 return this; | 74 return this; |
75 } | 75 } |
76 | 76 |
77 scoped_refptr<gl::GLImage> | 77 scoped_refptr<gl::GLImage> |
78 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( | 78 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( |
79 const gfx::GpuMemoryBufferHandle& handle, | 79 const gfx::GpuMemoryBufferHandle& handle, |
80 const gfx::Size& size, | 80 const gfx::Size& size, |
81 gfx::BufferFormat format, | 81 gfx::BufferFormat format, |
82 unsigned internalformat, | 82 unsigned internalformat, |
83 int client_id) { | 83 int client_id) { |
84 base::AutoLock lock(io_surfaces_lock_); | 84 base::AutoLock lock(io_surfaces_lock_); |
85 | 85 |
86 DCHECK_EQ(handle.type, gfx::IO_SURFACE_BUFFER); | 86 DCHECK_EQ(handle.type, gfx::IO_SURFACE_BUFFER); |
87 IOSurfaceMapKey key(handle.id, client_id); | 87 IOSurfaceMapKey key(handle.id, client_id); |
88 IOSurfaceMap::iterator it = io_surfaces_.find(key); | 88 IOSurfaceMap::iterator it = io_surfaces_.find(key); |
89 if (it == io_surfaces_.end()) | 89 if (it == io_surfaces_.end()) |
90 return scoped_refptr<gl::GLImage>(); | 90 return scoped_refptr<gl::GLImage>(); |
91 | 91 |
92 scoped_refptr<gl::GLImageIOSurface> image( | 92 scoped_refptr<gl::GLImageIOSurface> image( |
93 new gl::GLImageIOSurface(size, internalformat)); | 93 new gl::GLImageIOSurface(size, internalformat)); |
94 if (!image->Initialize(it->second.get(), handle.id, format)) | 94 if (!image->Initialize(it->second.get(), handle.id, format)) |
95 return scoped_refptr<gl::GLImage>(); | 95 return scoped_refptr<gl::GLImage>(); |
96 | 96 |
97 return image; | 97 return image; |
98 } | 98 } |
99 | 99 |
100 } // namespace content | 100 } // namespace gpu |
OLD | NEW |