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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2009, Google Inc. 2 * Copyright 2009, Google Inc.
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 14 matching lines...) Expand all
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32 #ifndef GPU_COMMAND_BUFFER_SERVICE_CROSS_COMMON_DECODER_H_ 32 #ifndef GPU_COMMAND_BUFFER_SERVICE_CROSS_COMMON_DECODER_H_
33 #define GPU_COMMAND_BUFFER_SERVICE_CROSS_COMMON_DECODER_H_ 33 #define GPU_COMMAND_BUFFER_SERVICE_CROSS_COMMON_DECODER_H_
34 34
35 #include <map>
36 #include "base/linked_ptr.h"
37 #include "base/scoped_ptr.h"
35 #include "gpu/command_buffer/service/cmd_parser.h" 38 #include "gpu/command_buffer/service/cmd_parser.h"
36 39
37 namespace command_buffer { 40 namespace command_buffer {
38 41
39 class CommandBufferEngine; 42 class CommandBufferEngine;
40 43
41 // This class is a helper base class for implementing the common parts of the 44 // This class is a helper base class for implementing the common parts of the
42 // o3d/gl2 command buffer decoder. 45 // o3d/gl2 command buffer decoder.
43 class CommonDecoder : public AsyncAPIInterface { 46 class CommonDecoder : public AsyncAPIInterface {
44 public: 47 public:
45 typedef parse_error::ParseError ParseError; 48 typedef parse_error::ParseError ParseError;
46 49
50 // A bucket is a buffer to help collect memory across a command buffer. When
51 // creating a command buffer implementation of an existing API, sometimes that
52 // API has functions that take a pointer to data. A good example is OpenGL's
53 // glBufferData. Because the data is separated between client and service,
54 // there are 2 ways to get this data across. 1 is to put all the data in
55 // shared memory. The problem with this is the data can be arbitarily large
56 // and the host OS may not support that much shared memory. Another solution
57 // is to shuffle memory across a little bit at a time, collecting it on the
58 // service side and when it is all there then call glBufferData. Buckets
59 // implement this second solution. Using the common commands, SetBucketSize,
60 // SetBucketData, SetBucketDataImmediate the client can fill a bucket. It can
61 // then call a command that uses that bucket (like BufferDataBucket in the
62 // GLES2 command buffer implementation).
63 //
64 // If you are designing an API from scratch you can avoid this need for
65 // Buckets by making your API always take an offset and a size
66 // similar to glBufferSubData.
67 //
68 // Buckets also help pass strings to/from the service. To return a string of
69 // arbitary size, the service puts the string in a bucket. The client can
70 // then query the size of a bucket and request sections of the bucket to
71 // be passed across shared memory.
72 class Bucket {
73 public:
74 Bucket() : size_(0) {
75 }
76
77 size_t size() const {
78 return size_;
79 }
80
81 // Gets a pointer to a section the bucket. Returns NULL if offset or size is
82 // out of range.
83 const void* GetData(size_t offset, size_t size) const;
84
85 template <typename T>
86 T GetDataAs(size_t offset, size_t size) const {
87 return reinterpret_cast<T>(GetData(offset, size));
88 }
89
90 // Sets the size of the bucket.
91 void SetSize(size_t size);
92
93 // Sets a part of the bucket.
94 // Returns false if offset or size is out of range.
95 bool SetData(const void* src, size_t offset, size_t size);
96
97 private:
98 bool OffsetSizeValid(size_t offset, size_t size) const {
99 size_t temp = offset + size;
100 return temp <= size_ && temp >= offset;
101 }
102
103 size_t size_;
104 scoped_array<int8> data_;
105
106 DISALLOW_COPY_AND_ASSIGN(Bucket);
107 };
108
47 CommonDecoder() : engine_(NULL) { 109 CommonDecoder() : engine_(NULL) {
48 } 110 }
49 virtual ~CommonDecoder() { 111 virtual ~CommonDecoder() {
50 } 112 }
51 113
52 // Sets the engine, to get shared memory buffers from, and to set the token 114 // Sets the engine, to get shared memory buffers from, and to set the token
53 // to. 115 // to.
54 void set_engine(CommandBufferEngine* engine) { 116 void set_engine(CommandBufferEngine* engine) {
55 engine_ = engine; 117 engine_ = engine;
56 } 118 }
(...skipping 19 matching lines...) Expand all
76 // shm_id: the id of the shared memory buffer. 138 // shm_id: the id of the shared memory buffer.
77 // offset: the offset of the data in the shared memory buffer. 139 // offset: the offset of the data in the shared memory buffer.
78 // size: the size of the data. 140 // size: the size of the data.
79 // Returns: 141 // Returns:
80 // NULL if shm_id isn't a valid shared memory buffer ID or if the size 142 // NULL if shm_id isn't a valid shared memory buffer ID or if the size
81 // check fails. Return a pointer to the data otherwise. 143 // check fails. Return a pointer to the data otherwise.
82 void* GetAddressAndCheckSize(unsigned int shm_id, 144 void* GetAddressAndCheckSize(unsigned int shm_id,
83 unsigned int offset, 145 unsigned int offset,
84 unsigned int size); 146 unsigned int size);
85 147
148 // Typed version of GetAddressAndCheckSize.
149 template <typename T>
150 T GetSharedMemoryAs(unsigned int shm_id, unsigned int offset,
151 unsigned int size) {
152 return static_cast<T>(GetAddressAndCheckSize(shm_id, offset, size));
153 }
154
86 // Gets an name for a common command. 155 // Gets an name for a common command.
87 const char* GetCommonCommandName(cmd::CommandId command_id) const; 156 const char* GetCommonCommandName(cmd::CommandId command_id) const;
88 157
158 // Gets a bucket. Returns NULL if the bucket does not exist.
159 Bucket* GetBucket(uint32 bucket_id) const;
160
89 private: 161 private:
90 // Generate a member function prototype for each command in an automated and 162 // Generate a member function prototype for each command in an automated and
91 // typesafe way. 163 // typesafe way.
92 #define COMMON_COMMAND_BUFFER_CMD_OP(name) \ 164 #define COMMON_COMMAND_BUFFER_CMD_OP(name) \
93 parse_error::ParseError Handle ## name( \ 165 parse_error::ParseError Handle ## name( \
94 unsigned int arg_count, \ 166 uint32 immediate_data_size, \
95 const cmd::name& args); \ 167 const cmd::name& args); \
96 168
97 COMMON_COMMAND_BUFFER_CMDS(COMMON_COMMAND_BUFFER_CMD_OP) 169 COMMON_COMMAND_BUFFER_CMDS(COMMON_COMMAND_BUFFER_CMD_OP)
98 170
99 #undef COMMON_COMMAND_BUFFER_CMD_OP 171 #undef COMMON_COMMAND_BUFFER_CMD_OP
100 172
101 CommandBufferEngine* engine_; 173 CommandBufferEngine* engine_;
174
175 typedef std::map<uint32, linked_ptr<Bucket> > BucketMap;
176 BucketMap buckets_;
102 }; 177 };
103 178
104 } // namespace command_buffer 179 } // namespace command_buffer
105 180
106 #endif // GPU_COMMAND_BUFFER_SERVICE_CROSS_COMMON_DECODER_H_ 181 #endif // GPU_COMMAND_BUFFER_SERVICE_CROSS_COMMON_DECODER_H_
107 182
OLDNEW
« 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