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/memory/scoped_ptr.h"
9 #include "ui/gfx/gpu_memory_buffer.h"
10 #include "ui/gfx/size.h"
14 // Provides common implementation of a GPU memory buffer.
15 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
17 virtual ~GpuMemoryBufferImpl();
19 // Creates a GPU memory buffer instance with |size| and |internalformat| for
21 static scoped_ptr<GpuMemoryBufferImpl> Create(const gfx::Size& size,
22 unsigned internalformat,
25 // Allocates a GPU memory buffer with |size| and |internalformat| for |usage|
26 // by |child_process|. The |handle| returned can be used by the
27 // |child_process| to create an instance of this class.
28 static void AllocateForChildProcess(const gfx::Size& size,
29 unsigned internalformat,
31 base::ProcessHandle child_process,
32 gfx::GpuMemoryBufferHandle* handle);
34 // Creates an instance from the given |handle|. |size| and |internalformat|
35 // should match what was used to allocate the |handle|.
36 static scoped_ptr<GpuMemoryBufferImpl> CreateFromHandle(
37 gfx::GpuMemoryBufferHandle handle,
38 const gfx::Size& size,
39 unsigned internalformat);
41 // Returns true if |internalformat| is a format recognized by this base class.
42 static bool IsFormatValid(unsigned internalformat);
44 // Returns true if |usage| is recognized by this base class.
45 static bool IsUsageValid(unsigned usage);
47 // Returns the number of bytes per pixel that must be used by an
48 // implementation when using |internalformat|.
49 static size_t BytesPerPixel(unsigned internalformat);
51 // Overridden from gfx::GpuMemoryBuffer:
52 virtual bool IsMapped() const OVERRIDE;
55 GpuMemoryBufferImpl(const gfx::Size& size, unsigned internalformat);
57 const gfx::Size size_;
58 const unsigned internalformat_;
61 DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImpl);
64 } // namespace content
66 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_