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