af72599c7f2c7b1eb01a23a85db02e00e576ceac
[platform/framework/web/crosswalk.git] / src / content / common / gpu / client / gpu_memory_buffer_impl.h
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.
4
5 #ifndef CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_
6 #define CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "ui/gfx/gpu_memory_buffer.h"
10 #include "ui/gfx/size.h"
11
12 namespace content {
13
14 // Provides common implementation of a GPU memory buffer.
15 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
16  public:
17   virtual ~GpuMemoryBufferImpl();
18
19   // Creates a GPU memory buffer instance with |size| and |internalformat| for
20   // |usage|.
21   static scoped_ptr<GpuMemoryBufferImpl> Create(const gfx::Size& size,
22                                                 unsigned internalformat,
23                                                 unsigned usage);
24
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,
30                                       unsigned usage,
31                                       base::ProcessHandle child_process,
32                                       gfx::GpuMemoryBufferHandle* handle);
33
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);
40
41   // Returns true if |internalformat| is a format recognized by this base class.
42   static bool IsFormatValid(unsigned internalformat);
43
44   // Returns true if |usage| is recognized by this base class.
45   static bool IsUsageValid(unsigned usage);
46
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);
50
51   // Overridden from gfx::GpuMemoryBuffer:
52   virtual bool IsMapped() const OVERRIDE;
53
54  protected:
55   GpuMemoryBufferImpl(const gfx::Size& size, unsigned internalformat);
56
57   const gfx::Size size_;
58   const unsigned internalformat_;
59   bool mapped_;
60
61   DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImpl);
62 };
63
64 }  // namespace content
65
66 #endif  // CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_