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 "content/common/gpu/gpu_memory_buffer_factory_x11_pixmap.h"
9 #include "ui/gl/gl_image.h"
10 #include "ui/gl/gl_image_shared_memory.h"
15 class GpuMemoryBufferFactoryImpl
: public GpuMemoryBufferFactory
{
17 // Overridden from GpuMemoryBufferFactory:
18 virtual gfx::GpuMemoryBufferHandle
CreateGpuMemoryBuffer(
19 const gfx::GpuMemoryBufferHandle
& handle
,
20 const gfx::Size
& size
,
21 unsigned internalformat
,
22 unsigned usage
) OVERRIDE
{
23 switch (handle
.type
) {
24 case gfx::X11_PIXMAP_BUFFER
:
25 x11_pixmap_factory_
.CreateGpuMemoryBuffer(handle
.global_id
,
30 return gfx::GpuMemoryBufferHandle();
33 virtual void DestroyGpuMemoryBuffer(
34 const gfx::GpuMemoryBufferHandle
& handle
) OVERRIDE
{
35 switch (handle
.type
) {
36 case gfx::X11_PIXMAP_BUFFER
:
37 x11_pixmap_factory_
.DestroyGpuMemoryBuffer(handle
.global_id
);
44 virtual scoped_refptr
<gfx::GLImage
> CreateImageForGpuMemoryBuffer(
45 const gfx::GpuMemoryBufferHandle
& handle
,
46 const gfx::Size
& size
,
47 unsigned internalformat
,
48 int client_id
) OVERRIDE
{
49 switch (handle
.type
) {
50 case gfx::SHARED_MEMORY_BUFFER
: {
51 scoped_refptr
<gfx::GLImageSharedMemory
> image(
52 new gfx::GLImageSharedMemory(size
, internalformat
));
53 if (!image
->Initialize(handle
))
58 case gfx::X11_PIXMAP_BUFFER
:
59 // Verify that client is the owner of the buffer we're about to use.
60 if (handle
.global_id
.secondary_id
!= client_id
)
61 return scoped_refptr
<gfx::GLImage
>();
63 return x11_pixmap_factory_
.CreateImageForGpuMemoryBuffer(
64 handle
.global_id
, size
, internalformat
);
67 return scoped_refptr
<gfx::GLImage
>();
72 GpuMemoryBufferFactoryX11Pixmap x11_pixmap_factory_
;
78 scoped_ptr
<GpuMemoryBufferFactory
> GpuMemoryBufferFactory::Create() {
79 return make_scoped_ptr
<GpuMemoryBufferFactory
>(
80 new GpuMemoryBufferFactoryImpl
);
83 } // namespace content