OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/common/gpu/gpu_memory_buffer_factory.h" |
| 6 |
| 7 #include "content/common/gpu/gpu_memory_buffer_factory_x11_pixmap.h" |
| 8 #include "ui/gl/gl_image.h" |
| 9 #include "ui/gl/gl_image_shared_memory.h" |
| 10 |
| 11 namespace content { |
| 12 namespace { |
| 13 |
| 14 class GpuMemoryBufferFactoryImpl : public GpuMemoryBufferFactory { |
| 15 public: |
| 16 // Overridden from GpuMemoryBufferFactory: |
| 17 virtual bool CreateGpuMemoryBuffer(const gfx::GpuMemoryBufferHandle& handle, |
| 18 const gfx::Size& size, |
| 19 unsigned internalformat, |
| 20 unsigned usage) OVERRIDE { |
| 21 switch (handle.type) { |
| 22 case gfx::X11_PIXMAP_BUFFER: |
| 23 x11_pixmap_factory_.CreateGpuMemoryBuffer(handle.global_id, |
| 24 handle.pixmap); |
| 25 return true; |
| 26 default: |
| 27 NOTREACHED(); |
| 28 return false; |
| 29 } |
| 30 } |
| 31 virtual void DestroyGpuMemoryBuffer( |
| 32 const gfx::GpuMemoryBufferHandle& handle) OVERRIDE { |
| 33 switch (handle.type) { |
| 34 case gfx::X11_PIXMAP_BUFFER: |
| 35 x11_pixmap_factory_.DestroyGpuMemoryBuffer(handle.global_id); |
| 36 break; |
| 37 default: |
| 38 NOTREACHED(); |
| 39 break; |
| 40 } |
| 41 } |
| 42 virtual scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( |
| 43 const gfx::GpuMemoryBufferHandle& handle, |
| 44 const gfx::Size& size, |
| 45 unsigned internalformat, |
| 46 int client_id) OVERRIDE { |
| 47 switch (handle.type) { |
| 48 case gfx::SHARED_MEMORY_BUFFER: { |
| 49 scoped_refptr<gfx::GLImageSharedMemory> image( |
| 50 new gfx::GLImageSharedMemory(size, internalformat)); |
| 51 if (!image->Initialize(handle)) |
| 52 return NULL; |
| 53 |
| 54 return image; |
| 55 } |
| 56 case gfx::X11_PIXMAP_BUFFER: |
| 57 // TODO: comment. |
| 58 if (handle.global_id.secondary_id != client_id) |
| 59 return scoped_refptr<gfx::GLImage>(); |
| 60 |
| 61 return x11_pixmap_factory_.AcquireImageForGpuMemoryBuffer( |
| 62 handle.global_id, size, internalformat); |
| 63 default: |
| 64 NOTREACHED(); |
| 65 return scoped_refptr<gfx::GLImage>(); |
| 66 } |
| 67 } |
| 68 |
| 69 private: |
| 70 GpuMemoryBufferFactoryX11Pixmap x11_pixmap_factory_; |
| 71 }; |
| 72 |
| 73 } // namespace |
| 74 |
| 75 // static |
| 76 scoped_ptr<GpuMemoryBufferFactory> GpuMemoryBufferFactory::Create() { |
| 77 return make_scoped_ptr<GpuMemoryBufferFactory>( |
| 78 new GpuMemoryBufferFactoryImpl); |
| 79 } |
| 80 |
| 81 } // namespace content |
OLD | NEW |