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