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 UI_GL_GPU_MEMORY_BUFFER_H_
6 #define UI_GL_GPU_MEMORY_BUFFER_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/scoped_ptr.h"
15 // Interface for creating and accessing a zero-copy GPU memory buffer.
16 // This design evolved from the generalization of GraphicBuffer API
17 // of Android framework.
19 // THREADING CONSIDERATIONS:
21 // This interface is thread-safe. However, multiple threads mapping
22 // a buffer for Write or ReadOrWrite simultaneously may result in undefined
23 // behavior and is not allowed.
24 class GpuMemoryBuffer
{
26 typedef base::Callback
<scoped_ptr
<gfx::GpuMemoryBuffer
>(gfx::Size
)> Create
;
33 // Frees a previously allocated buffer. Freeing a buffer that is still
34 // mapped in any process is undefined behavior.
35 virtual ~GpuMemoryBuffer() {}
37 // Maps the buffer so the client can write the bitmap data in |*vaddr|
38 // subsequently. This call may block, for instance if the hardware needs
39 // to finish rendering or if CPU caches need to be synchronized.
40 virtual void Map(AccessMode mode
, void** vaddr
) = 0;
42 // Unmaps the buffer. Called after all changes to the buffer are
44 virtual void Unmap() = 0;
46 // Returns the native pointer for the buffer.
47 virtual void* GetNativeBuffer() = 0;
49 // Returns the stride in pixels for the buffer.
50 virtual uint32
GetStride() = 0;
55 #endif // UI_GL_GPU_MEMORY_BUFFER_H_