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| identified by |child_id|. The |handle| returned can be
31 // used by the |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
,
37 const AllocationCallback
& callback
);
39 // Notify that GPU memory buffer has been deleted by |child_process|.
40 static void DeletedByChildProcess(gfx::GpuMemoryBufferType type
,
41 const gfx::GpuMemoryBufferId
& id
,
42 base::ProcessHandle child_process
);
44 // Creates an instance from the given |handle|. |size| and |internalformat|
45 // should match what was used to allocate the |handle|.
46 static scoped_ptr
<GpuMemoryBufferImpl
> CreateFromHandle(
47 const gfx::GpuMemoryBufferHandle
& handle
,
48 const gfx::Size
& size
,
49 unsigned internalformat
);
51 // Returns true if |internalformat| is a format recognized by this base class.
52 static bool IsFormatValid(unsigned internalformat
);
54 // Returns true if |usage| is recognized by this base class.
55 static bool IsUsageValid(unsigned usage
);
57 // Returns the number of bytes per pixel that must be used by an
58 // implementation when using |internalformat|.
59 static size_t BytesPerPixel(unsigned internalformat
);
61 // Overridden from gfx::GpuMemoryBuffer:
62 virtual bool IsMapped() const OVERRIDE
;
65 GpuMemoryBufferImpl(const gfx::Size
& size
, unsigned internalformat
);
67 const gfx::Size size_
;
68 const unsigned internalformat_
;
71 DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImpl
);
74 } // namespace content
76 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_