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.
5 #include "content/common/gpu/gpu_memory_buffer_factory.h"
7 #include "base/logging.h"
8 #include "gpu/command_buffer/service/image_factory.h"
9 #include "ui/gl/gl_image.h"
10 #include "ui/gl/gl_image_shared_memory.h"
15 class GpuMemoryBufferFactoryImpl
: public GpuMemoryBufferFactory
,
16 public gpu::ImageFactory
{
18 // Overridden from GpuMemoryBufferFactory:
19 virtual gfx::GpuMemoryBufferHandle
CreateGpuMemoryBuffer(
20 gfx::GpuMemoryBufferType type
,
21 gfx::GpuMemoryBufferId id
,
22 const gfx::Size
& size
,
23 gfx::GpuMemoryBuffer::Format format
,
24 gfx::GpuMemoryBuffer::Usage usage
,
25 int client_id
) override
{
27 return gfx::GpuMemoryBufferHandle();
29 virtual void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferType type
,
30 gfx::GpuMemoryBufferId id
,
31 int client_id
) override
{
34 virtual gpu::ImageFactory
* AsImageFactory() override
{ return this; }
36 // Overridden from gpu::ImageFactory:
37 virtual scoped_refptr
<gfx::GLImage
> CreateImageForGpuMemoryBuffer(
38 const gfx::GpuMemoryBufferHandle
& handle
,
39 const gfx::Size
& size
,
40 gfx::GpuMemoryBuffer::Format format
,
41 unsigned internalformat
,
42 int client_id
) override
{
43 switch (handle
.type
) {
44 case gfx::SHARED_MEMORY_BUFFER
: {
45 scoped_refptr
<gfx::GLImageSharedMemory
> image(
46 new gfx::GLImageSharedMemory(size
, internalformat
));
47 if (!image
->Initialize(handle
, format
))
54 return scoped_refptr
<gfx::GLImage
>();
62 scoped_ptr
<GpuMemoryBufferFactory
> GpuMemoryBufferFactory::Create() {
63 return make_scoped_ptr
<GpuMemoryBufferFactory
>(
64 new GpuMemoryBufferFactoryImpl
);
67 } // namespace content