1 // Copyright 2013 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 #ifndef CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_
6 #define CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_
8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ui/gfx/gpu_memory_buffer.h"
11 #include "ui/gfx/size.h"
15 // Provides common implementation of a GPU memory buffer.
16 class GpuMemoryBufferImpl
: public gfx::GpuMemoryBuffer
{
18 typedef base::Callback
<void(const gfx::GpuMemoryBufferHandle
& handle
)>
21 virtual ~GpuMemoryBufferImpl();
23 // Creates a GPU memory buffer instance with |size| and |internalformat| for
25 static scoped_ptr
<GpuMemoryBufferImpl
> Create(const gfx::Size
& size
,
26 unsigned internalformat
,
29 // Allocates a GPU memory buffer with |size| and |internalformat| for |usage|
30 // by |child_process|. The |handle| returned can be used by the
31 // |child_process| to create an instance of this class.
32 static void AllocateForChildProcess(const gfx::Size
& size
,
33 unsigned internalformat
,
35 base::ProcessHandle child_process
,
36 const AllocationCallback
& callback
);
38 // Creates an instance from the given |handle|. |size| and |internalformat|
39 // should match what was used to allocate the |handle|.
40 static scoped_ptr
<GpuMemoryBufferImpl
> CreateFromHandle(
41 gfx::GpuMemoryBufferHandle handle
,
42 const gfx::Size
& size
,
43 unsigned internalformat
);
45 // Returns true if |internalformat| is a format recognized by this base class.
46 static bool IsFormatValid(unsigned internalformat
);
48 // Returns true if |usage| is recognized by this base class.
49 static bool IsUsageValid(unsigned usage
);
51 // Returns the number of bytes per pixel that must be used by an
52 // implementation when using |internalformat|.
53 static size_t BytesPerPixel(unsigned internalformat
);
55 // Overridden from gfx::GpuMemoryBuffer:
56 virtual bool IsMapped() const OVERRIDE
;
59 GpuMemoryBufferImpl(const gfx::Size
& size
, unsigned internalformat
);
61 const gfx::Size size_
;
62 const unsigned internalformat_
;
65 DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImpl
);
68 } // namespace content
70 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_