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.h" | 5 #include "content/common/gpu/gpu_memory_buffer_factory.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/common/gpu/gpu_memory_buffer_factory_io_surface.h" | 8 #include "content/common/gpu/gpu_memory_buffer_factory_io_surface.h" |
9 #include "gpu/command_buffer/service/image_factory.h" | 9 #include "gpu/command_buffer/service/image_factory.h" |
10 #include "ui/gl/gl_image.h" | 10 #include "ui/gl/gl_image.h" |
11 #include "ui/gl/gl_image_shared_memory.h" | 11 #include "ui/gl/gl_image_shared_memory.h" |
12 | 12 |
13 namespace content { | 13 namespace content { |
14 namespace { | 14 namespace { |
15 | 15 |
16 class GpuMemoryBufferFactoryImpl : public GpuMemoryBufferFactory, | 16 class GpuMemoryBufferFactoryImpl : public GpuMemoryBufferFactory, |
17 public gpu::ImageFactory { | 17 public gpu::ImageFactory { |
18 public: | 18 public: |
19 // Overridden from GpuMemoryBufferFactory: | 19 // Overridden from GpuMemoryBufferFactory: |
20 gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( | 20 gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( |
21 const gfx::GpuMemoryBufferHandle& handle, | 21 gfx::GpuMemoryBufferType type, |
| 22 gfx::GpuMemoryBufferId id, |
22 const gfx::Size& size, | 23 const gfx::Size& size, |
23 gfx::GpuMemoryBuffer::Format format, | 24 gfx::GpuMemoryBuffer::Format format, |
24 gfx::GpuMemoryBuffer::Usage usage) override { | 25 gfx::GpuMemoryBuffer::Usage usage, |
25 switch (handle.type) { | 26 int client_id) override { |
| 27 switch (type) { |
26 case gfx::IO_SURFACE_BUFFER: | 28 case gfx::IO_SURFACE_BUFFER: |
27 return io_surface_factory_.CreateGpuMemoryBuffer( | 29 return io_surface_factory_.CreateGpuMemoryBuffer( |
28 handle.global_id, size, format); | 30 id, size, format, client_id); |
29 default: | 31 default: |
30 NOTREACHED(); | 32 NOTREACHED(); |
31 return gfx::GpuMemoryBufferHandle(); | 33 return gfx::GpuMemoryBufferHandle(); |
32 } | 34 } |
33 } | 35 } |
34 void DestroyGpuMemoryBuffer( | 36 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferType type, |
35 const gfx::GpuMemoryBufferHandle& handle) override { | 37 gfx::GpuMemoryBufferId id, |
36 switch (handle.type) { | 38 int client_id) override { |
| 39 switch (type) { |
37 case gfx::IO_SURFACE_BUFFER: | 40 case gfx::IO_SURFACE_BUFFER: |
38 io_surface_factory_.DestroyGpuMemoryBuffer(handle.global_id); | 41 io_surface_factory_.DestroyGpuMemoryBuffer(id, client_id); |
39 break; | 42 break; |
40 default: | 43 default: |
41 NOTREACHED(); | 44 NOTREACHED(); |
42 break; | 45 break; |
43 } | 46 } |
44 } | 47 } |
45 gpu::ImageFactory* AsImageFactory() override { return this; } | 48 gpu::ImageFactory* AsImageFactory() override { return this; } |
46 | 49 |
47 // Overridden from gpu::ImageFactory: | 50 // Overridden from gpu::ImageFactory: |
48 scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( | 51 scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( |
49 const gfx::GpuMemoryBufferHandle& handle, | 52 const gfx::GpuMemoryBufferHandle& handle, |
50 const gfx::Size& size, | 53 const gfx::Size& size, |
51 gfx::GpuMemoryBuffer::Format format, | 54 gfx::GpuMemoryBuffer::Format format, |
52 unsigned internalformat, | 55 unsigned internalformat, |
53 int client_id) override { | 56 int client_id) override { |
54 switch (handle.type) { | 57 switch (handle.type) { |
55 case gfx::SHARED_MEMORY_BUFFER: { | 58 case gfx::SHARED_MEMORY_BUFFER: { |
56 scoped_refptr<gfx::GLImageSharedMemory> image( | 59 scoped_refptr<gfx::GLImageSharedMemory> image( |
57 new gfx::GLImageSharedMemory(size, internalformat)); | 60 new gfx::GLImageSharedMemory(size, internalformat)); |
58 if (!image->Initialize(handle, format)) | 61 if (!image->Initialize(handle, format)) |
59 return NULL; | 62 return NULL; |
60 | 63 |
61 return image; | 64 return image; |
62 } | 65 } |
63 case gfx::IO_SURFACE_BUFFER: { | 66 case gfx::IO_SURFACE_BUFFER: { |
64 // Verify that client is the owner of the buffer we're about to use. | |
65 if (handle.global_id.secondary_id != client_id) | |
66 return scoped_refptr<gfx::GLImage>(); | |
67 | |
68 return io_surface_factory_.CreateImageForGpuMemoryBuffer( | 67 return io_surface_factory_.CreateImageForGpuMemoryBuffer( |
69 handle.global_id, size, format); | 68 handle.id, size, format, client_id); |
70 } | 69 } |
71 default: | 70 default: |
72 NOTREACHED(); | 71 NOTREACHED(); |
73 return scoped_refptr<gfx::GLImage>(); | 72 return scoped_refptr<gfx::GLImage>(); |
74 } | 73 } |
75 } | 74 } |
76 | 75 |
77 private: | 76 private: |
78 GpuMemoryBufferFactoryIOSurface io_surface_factory_; | 77 GpuMemoryBufferFactoryIOSurface io_surface_factory_; |
79 }; | 78 }; |
80 | 79 |
81 } // namespace | 80 } // namespace |
82 | 81 |
83 // static | 82 // static |
84 scoped_ptr<GpuMemoryBufferFactory> GpuMemoryBufferFactory::Create() { | 83 scoped_ptr<GpuMemoryBufferFactory> GpuMemoryBufferFactory::Create() { |
85 return make_scoped_ptr<GpuMemoryBufferFactory>( | 84 return make_scoped_ptr<GpuMemoryBufferFactory>( |
86 new GpuMemoryBufferFactoryImpl); | 85 new GpuMemoryBufferFactoryImpl); |
87 } | 86 } |
88 | 87 |
89 } // namespace content | 88 } // namespace content |
OLD | NEW |