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

Side by Side Diff: command_buffer/service/cross/gapi_decoder.cc

Issue 329046: Splits the command buffers into common commands... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: '' Created 11 years, 1 month 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 18 matching lines...) Expand all
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 32
33 // This class contains the implementation of the GAPI decoder class, decoding 33 // This class contains the implementation of the GAPI decoder class, decoding
34 // GAPI commands into calls to a GAPIInterface class. 34 // GAPI commands into calls to a GAPIInterface class.
35 35
36 #include "base/cross/bits.h" 36 #include "base/cross/bits.h"
37 #include "command_buffer/common/cross/gapi_interface.h" 37 #include "command_buffer/common/cross/gapi_interface.h"
38 #include "command_buffer/service/cross/gapi_decoder.h" 38 #include "command_buffer/service/cross/gapi_decoder.h"
39 #include "command_buffer/service/cross/cmd_buffer_engine.h"
40 39
41 namespace o3d { 40 namespace o3d {
42 namespace command_buffer { 41 namespace command_buffer {
43 namespace o3d { 42 namespace o3d {
44 43
45 namespace { 44 namespace {
46 45
47 // Returns the address of the first byte after a struct. 46 // Returns the address of the first byte after a struct.
48 template <typename T> 47 template <typename T>
49 const void* AddressAfterStruct(const T& pod) { 48 const void* AddressAfterStruct(const T& pod) {
(...skipping 21 matching lines...) Expand all
71 name::kArgFlags, \ 70 name::kArgFlags, \
72 sizeof(name) / sizeof(CommandBufferEntry) - 1, }, /* NOLINT */ \ 71 sizeof(name) / sizeof(CommandBufferEntry) - 1, }, /* NOLINT */ \
73 72
74 O3D_COMMAND_BUFFER_CMDS(O3D_COMMAND_BUFFER_CMD_OP) 73 O3D_COMMAND_BUFFER_CMDS(O3D_COMMAND_BUFFER_CMD_OP)
75 74
76 #undef O3D_COMMAND_BUFFER_CMD_OP 75 #undef O3D_COMMAND_BUFFER_CMD_OP
77 }; 76 };
78 77
79 } // anonymous namespace. 78 } // anonymous namespace.
80 79
81 // Decode command with its arguments, and call the corresponding GAPIInterface 80 // Decode command with its arguments, and call the corresponding method.
82 // method.
83 // Note: args is a pointer to the command buffer. As such, it could be changed 81 // Note: args is a pointer to the command buffer. As such, it could be changed
84 // by a (malicious) client at any time, so if validation has to happen, it 82 // by a (malicious) client at any time, so if validation has to happen, it
85 // should operate on a copy of them. 83 // should operate on a copy of them.
86 parse_error::ParseError GAPIDecoder::DoCommand( 84 parse_error::ParseError GAPIDecoder::DoCommand(
87 unsigned int command, 85 unsigned int command,
88 unsigned int arg_count, 86 unsigned int arg_count,
89 const void* cmd_data) { 87 const void* cmd_data) {
90 if (command < arraysize(g_command_info)) { 88 unsigned int command_index = command - kStartPoint - 1;
91 const CommandInfo& info = g_command_info[command]; 89 if (command_index < arraysize(g_command_info)) {
92 unsigned int info_arg_count = static_cast<unsigned int>(info.arg_count); 90 const CommandInfo& info = g_command_info[command_index];
91 unsigned int info_arg_count = static_cast<unsigned int>(info.arg_count);
93 if ((info.arg_flags == cmd::kFixed && arg_count == info_arg_count) || 92 if ((info.arg_flags == cmd::kFixed && arg_count == info_arg_count) ||
94 (info.arg_flags == cmd::kAtLeastN && arg_count >= info_arg_count)) { 93 (info.arg_flags == cmd::kAtLeastN && arg_count >= info_arg_count)) {
95 switch (command) { 94 switch (command) {
96 #define O3D_COMMAND_BUFFER_CMD_OP(name) \ 95 #define O3D_COMMAND_BUFFER_CMD_OP(name) \
97 case name::kCmdId: \ 96 case name::kCmdId: \
98 return Handle ## name( \ 97 return Handle ## name( \
99 arg_count, \ 98 arg_count, \
100 *static_cast<const name*>(cmd_data)); \ 99 *static_cast<const name*>(cmd_data)); \
101 100
102 O3D_COMMAND_BUFFER_CMDS(O3D_COMMAND_BUFFER_CMD_OP) 101 O3D_COMMAND_BUFFER_CMDS(O3D_COMMAND_BUFFER_CMD_OP)
103 102
104 #undef O3D_COMMAND_BUFFER_CMD_OP 103 #undef O3D_COMMAND_BUFFER_CMD_OP
105 } 104 }
106 } else { 105 } else {
107 return parse_error::kParseInvalidArguments; 106 return parse_error::kParseInvalidArguments;
108 } 107 }
109 } 108 }
109 return DoCommonCommand(command, arg_count, cmd_data);
110 return parse_error::kParseUnknownCommand; 110 return parse_error::kParseUnknownCommand;
111 } 111 }
112 112
113 void *GAPIDecoder::GetAddressAndCheckSize(unsigned int shm_id, 113 // Overridden from AsyncAPIInterface.
114 unsigned int offset, 114 const char* GAPIDecoder::GetCommandName(unsigned int command_id) const {
115 unsigned int size) { 115 if (command_id > kStartPoint && command_id < kNumCommands) {
116 void * shm_addr = engine_->GetSharedMemoryAddress(shm_id); 116 return o3d::GetCommandName(static_cast<CommandId>(command_id));
117 if (!shm_addr) return NULL; 117 }
118 size_t shm_size = engine_->GetSharedMemorySize(shm_id); 118 return GetCommonCommandName(static_cast<cmd::CommandId>(command_id));
119 if (offset + size > shm_size) return NULL;
120 return static_cast<char *>(shm_addr) + offset;
121 }
122
123 parse_error::ParseError GAPIDecoder::HandleNoop(
124 uint32 arg_count,
125 const Noop& args) {
126 return parse_error::kParseNoError;
127 }
128
129 parse_error::ParseError GAPIDecoder::HandleSetToken(
130 uint32 arg_count,
131 const SetToken& args) {
132 engine_->set_token(args.token);
133 return parse_error::kParseNoError;
134 } 119 }
135 120
136 parse_error::ParseError GAPIDecoder::HandleBeginFrame( 121 parse_error::ParseError GAPIDecoder::HandleBeginFrame(
137 uint32 arg_count, 122 uint32 arg_count,
138 const BeginFrame& args) { 123 const BeginFrame& args) {
139 gapi_->BeginFrame(); 124 gapi_->BeginFrame();
140 return parse_error::kParseNoError; 125 return parse_error::kParseNoError;
141 } 126 }
142 127
143 parse_error::ParseError GAPIDecoder::HandleEndFrame( 128 parse_error::ParseError GAPIDecoder::HandleEndFrame(
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 parse_error::ParseError GAPIDecoder::HandleSetBackSurfaces( 931 parse_error::ParseError GAPIDecoder::HandleSetBackSurfaces(
947 uint32 arg_count, 932 uint32 arg_count,
948 const SetBackSurfaces& args) { 933 const SetBackSurfaces& args) {
949 gapi_->SetBackSurfaces(); 934 gapi_->SetBackSurfaces();
950 return parse_error::kParseNoError; 935 return parse_error::kParseNoError;
951 } 936 }
952 937
953 } // namespace o3d 938 } // namespace o3d
954 } // namespace command_buffer 939 } // namespace command_buffer
955 } // namespace o3d 940 } // namespace o3d
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698