Standardize usage of virtual/override/final in content/
[chromium-blink-merge.git] / content / common / gpu / client / gpu_memory_buffer_impl.h
blob727e54125adc5f952bebb447100ed944c6aa42c6
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"
13 namespace content {
15 // Provides common implementation of a GPU memory buffer.
16 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
17 public:
18 typedef base::Callback<void(scoped_ptr<GpuMemoryBufferImpl> buffer)>
19 CreationCallback;
20 typedef base::Callback<void(const gfx::GpuMemoryBufferHandle& handle)>
21 AllocationCallback;
22 typedef base::Closure DestructionCallback;
24 ~GpuMemoryBufferImpl() override;
26 // Creates a GPU memory buffer instance with |size| and |format| for |usage|
27 // by the current process and |client_id|.
28 static void Create(const gfx::Size& size,
29 Format format,
30 Usage usage,
31 int client_id,
32 const CreationCallback& callback);
34 // Allocates a GPU memory buffer with |size| and |internalformat| for |usage|
35 // by |child_process| and |child_client_id|. The |handle| returned can be
36 // used by the |child_process| to create an instance of this class.
37 static void AllocateForChildProcess(const gfx::Size& size,
38 Format format,
39 Usage usage,
40 base::ProcessHandle child_process,
41 int child_client_id,
42 const AllocationCallback& callback);
44 // Notify that GPU memory buffer has been deleted by |child_process|.
45 static void DeletedByChildProcess(gfx::GpuMemoryBufferType type,
46 const gfx::GpuMemoryBufferId& id,
47 base::ProcessHandle child_process);
49 // Creates an instance from the given |handle|. |size| and |internalformat|
50 // should match what was used to allocate the |handle|. |callback| is
51 // called when instance is deleted, which is not necessarily on the same
52 // thread as this function was called on and instance was created on.
53 static scoped_ptr<GpuMemoryBufferImpl> CreateFromHandle(
54 const gfx::GpuMemoryBufferHandle& handle,
55 const gfx::Size& size,
56 Format format,
57 const DestructionCallback& callback);
59 // Type-checking upcast routine. Returns an NULL on failure.
60 static GpuMemoryBufferImpl* FromClientBuffer(ClientBuffer buffer);
62 // Returns the number of bytes per pixel that must be used by an
63 // implementation when using |format|.
64 static size_t BytesPerPixel(Format format);
66 // Overridden from gfx::GpuMemoryBuffer:
67 bool IsMapped() const override;
68 Format GetFormat() const override;
69 ClientBuffer AsClientBuffer() override;
71 protected:
72 GpuMemoryBufferImpl(const gfx::Size& size,
73 Format format,
74 const DestructionCallback& callback);
76 const gfx::Size size_;
77 const Format format_;
78 const DestructionCallback callback_;
79 bool mapped_;
81 DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImpl);
84 } // namespace content
86 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_