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

Unified Diff: gpu/command_buffer/service/common_decoder.h

Issue 479008: Implements bucket commands and adds unit tests to... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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/common/cmd_buffer_common.h ('k') | gpu/command_buffer/service/common_decoder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/service/common_decoder.h
===================================================================
--- gpu/command_buffer/service/common_decoder.h (revision 34064)
+++ gpu/command_buffer/service/common_decoder.h (working copy)
@@ -32,6 +32,9 @@
#ifndef GPU_COMMAND_BUFFER_SERVICE_CROSS_COMMON_DECODER_H_
#define GPU_COMMAND_BUFFER_SERVICE_CROSS_COMMON_DECODER_H_
+#include <map>
+#include "base/linked_ptr.h"
+#include "base/scoped_ptr.h"
#include "gpu/command_buffer/service/cmd_parser.h"
namespace command_buffer {
@@ -44,6 +47,65 @@
public:
typedef parse_error::ParseError ParseError;
+ // A bucket is a buffer to help collect memory across a command buffer. When
+ // creating a command buffer implementation of an existing API, sometimes that
+ // API has functions that take a pointer to data. A good example is OpenGL's
+ // glBufferData. Because the data is separated between client and service,
+ // there are 2 ways to get this data across. 1 is to put all the data in
+ // shared memory. The problem with this is the data can be arbitarily large
+ // and the host OS may not support that much shared memory. Another solution
+ // is to shuffle memory across a little bit at a time, collecting it on the
+ // service side and when it is all there then call glBufferData. Buckets
+ // implement this second solution. Using the common commands, SetBucketSize,
+ // SetBucketData, SetBucketDataImmediate the client can fill a bucket. It can
+ // then call a command that uses that bucket (like BufferDataBucket in the
+ // GLES2 command buffer implementation).
+ //
+ // If you are designing an API from scratch you can avoid this need for
+ // Buckets by making your API always take an offset and a size
+ // similar to glBufferSubData.
+ //
+ // Buckets also help pass strings to/from the service. To return a string of
+ // arbitary size, the service puts the string in a bucket. The client can
+ // then query the size of a bucket and request sections of the bucket to
+ // be passed across shared memory.
+ class Bucket {
+ public:
+ Bucket() : size_(0) {
+ }
+
+ size_t size() const {
+ return size_;
+ }
+
+ // Gets a pointer to a section the bucket. Returns NULL if offset or size is
+ // out of range.
+ const void* GetData(size_t offset, size_t size) const;
+
+ template <typename T>
+ T GetDataAs(size_t offset, size_t size) const {
+ return reinterpret_cast<T>(GetData(offset, size));
+ }
+
+ // Sets the size of the bucket.
+ void SetSize(size_t size);
+
+ // Sets a part of the bucket.
+ // Returns false if offset or size is out of range.
+ bool SetData(const void* src, size_t offset, size_t size);
+
+ private:
+ bool OffsetSizeValid(size_t offset, size_t size) const {
+ size_t temp = offset + size;
+ return temp <= size_ && temp >= offset;
+ }
+
+ size_t size_;
+ scoped_array<int8> data_;
+
+ DISALLOW_COPY_AND_ASSIGN(Bucket);
+ };
+
CommonDecoder() : engine_(NULL) {
}
virtual ~CommonDecoder() {
@@ -83,15 +145,25 @@
unsigned int offset,
unsigned int size);
+ // Typed version of GetAddressAndCheckSize.
+ template <typename T>
+ T GetSharedMemoryAs(unsigned int shm_id, unsigned int offset,
+ unsigned int size) {
+ return static_cast<T>(GetAddressAndCheckSize(shm_id, offset, size));
+ }
+
// Gets an name for a common command.
const char* GetCommonCommandName(cmd::CommandId command_id) const;
+ // Gets a bucket. Returns NULL if the bucket does not exist.
+ Bucket* GetBucket(uint32 bucket_id) const;
+
private:
// Generate a member function prototype for each command in an automated and
// typesafe way.
#define COMMON_COMMAND_BUFFER_CMD_OP(name) \
parse_error::ParseError Handle ## name( \
- unsigned int arg_count, \
+ uint32 immediate_data_size, \
const cmd::name& args); \
COMMON_COMMAND_BUFFER_CMDS(COMMON_COMMAND_BUFFER_CMD_OP)
@@ -99,6 +171,9 @@
#undef COMMON_COMMAND_BUFFER_CMD_OP
CommandBufferEngine* engine_;
+
+ typedef std::map<uint32, linked_ptr<Bucket> > BucketMap;
+ BucketMap buckets_;
};
} // namespace command_buffer
« no previous file with comments | « gpu/command_buffer/common/cmd_buffer_common.h ('k') | gpu/command_buffer/service/common_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698