Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2884)

Unified Diff: gpu/command_buffer/common/buffer.h

Issue 213353005: Refactor gpu::Buffer to allow different types of backing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix pointer alignment in tests Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gpu/command_buffer/client/mapped_memory_unittest.cc ('k') | gpu/command_buffer/common/buffer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/common/buffer.h
diff --git a/gpu/command_buffer/common/buffer.h b/gpu/command_buffer/common/buffer.h
index e9a15580fd66c3e8e0c4ecd846381c58a9909797..5a310351b4b064047a099fe6cfa47883f5081f2b 100644
--- a/gpu/command_buffer/common/buffer.h
+++ b/gpu/command_buffer/common/buffer.h
@@ -17,12 +17,34 @@ namespace base {
namespace gpu {
+class GPU_EXPORT BufferBacking {
+ public:
+ virtual ~BufferBacking() {}
+ virtual void* GetMemory() const = 0;
+ virtual size_t GetSize() const = 0;
+};
+
+class GPU_EXPORT SharedMemoryBufferBacking : public BufferBacking {
+ public:
+ SharedMemoryBufferBacking(scoped_ptr<base::SharedMemory> shared_memory,
+ size_t size);
+ virtual ~SharedMemoryBufferBacking();
+ virtual void* GetMemory() const OVERRIDE;
+ virtual size_t GetSize() const OVERRIDE;
+ base::SharedMemory* shared_memory() { return shared_memory_.get(); }
+
+ private:
+ scoped_ptr<base::SharedMemory> shared_memory_;
+ size_t size_;
+ DISALLOW_COPY_AND_ASSIGN(SharedMemoryBufferBacking);
+};
+
// Buffer owns a piece of shared-memory of a certain size.
class GPU_EXPORT Buffer : public base::RefCountedThreadSafe<Buffer> {
public:
- Buffer(scoped_ptr<base::SharedMemory> shared_memory, size_t size);
+ explicit Buffer(scoped_ptr<BufferBacking> backing);
- base::SharedMemory* shared_memory() const { return shared_memory_.get(); }
+ BufferBacking* backing() const { return backing_.get(); }
void* memory() const { return memory_; }
size_t size() const { return size_; }
@@ -33,13 +55,26 @@ class GPU_EXPORT Buffer : public base::RefCountedThreadSafe<Buffer> {
friend class base::RefCountedThreadSafe<Buffer>;
~Buffer();
- scoped_ptr<base::SharedMemory> shared_memory_;
+ scoped_ptr<BufferBacking> backing_;
void* memory_;
size_t size_;
DISALLOW_COPY_AND_ASSIGN(Buffer);
};
+static inline scoped_ptr<BufferBacking> MakeBackingFromSharedMemory(
+ scoped_ptr<base::SharedMemory> shared_memory,
+ size_t size) {
+ return scoped_ptr<BufferBacking>(
+ new SharedMemoryBufferBacking(shared_memory.Pass(), size));
+}
+
+static inline scoped_refptr<Buffer> MakeBufferFromSharedMemory(
+ scoped_ptr<base::SharedMemory> shared_memory,
+ size_t size) {
+ return new Buffer(MakeBackingFromSharedMemory(shared_memory.Pass(), size));
+}
+
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_COMMON_BUFFER_H_
« no previous file with comments | « gpu/command_buffer/client/mapped_memory_unittest.cc ('k') | gpu/command_buffer/common/buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698