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 "ui/gl/gl_image.h" |
| 8 #include "ui/gl/gl_image_io_surface.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 NOTREACHED(); |
| 22 return false; |
| 23 } |
| 24 virtual void DestroyGpuMemoryBuffer( |
| 25 const gfx::GpuMemoryBufferHandle& handle) OVERRIDE { |
| 26 NOTREACHED(); |
| 27 } |
| 28 virtual scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( |
| 29 const gfx::GpuMemoryBufferHandle& handle, |
| 30 const gfx::Size& size, |
| 31 unsigned internalformat, |
| 32 int client_id) OVERRIDE { |
| 33 switch (handle.type) { |
| 34 case gfx::SHARED_MEMORY_BUFFER: { |
| 35 scoped_refptr<gfx::GLImageSharedMemory> image( |
| 36 new gfx::GLImageSharedMemory(size, internalformat)); |
| 37 if (!image->Initialize(handle)) |
| 38 return NULL; |
| 39 |
| 40 return image; |
| 41 } |
| 42 case IO_SURFACE_BUFFER: { |
| 43 scoped_refptr<gfx::GLImageIOSurface> image( |
| 44 new gfx::GLImageIOSurface(size)); |
| 45 if (!image->Initialize(buffer)) |
| 46 return NULL; |
| 47 |
| 48 return image; |
| 49 } |
| 50 default: |
| 51 NOTREACHED(); |
| 52 return scoped_refptr<gfx::GLImage>(); |
| 53 } |
| 54 } |
| 55 }; |
| 56 |
| 57 } // namespace |
| 58 |
| 59 // static |
| 60 scoped_ptr<GpuMemoryBufferFactory> GpuMemoryBufferFactory::Create() { |
| 61 return make_scoped_ptr<GpuMemoryBufferFactory>( |
| 62 new GpuMemoryBufferFactoryImpl); |
| 63 } |
| 64 |
| 65 } // namespace content |
OLD | NEW |