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

Side by Side Diff: command_buffer/service/cross/common_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
(Empty)
1 /*
2 * Copyright 2009, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
30 */
31
32 #include "command_buffer/service/cross/common_decoder.h"
33 #include "command_buffer/service/cross/cmd_buffer_engine.h"
34
35 namespace o3d {
36 namespace command_buffer {
37
38 void* CommonDecoder::GetAddressAndCheckSize(unsigned int shm_id,
39 unsigned int offset,
40 unsigned int size) {
41 void* shm_addr = engine_->GetSharedMemoryAddress(shm_id);
42 if (!shm_addr) return NULL;
43 size_t shm_size = engine_->GetSharedMemorySize(shm_id);
44 unsigned int end = offset + size;
45 if (end > shm_size || end < offset) {
46 return NULL;
47 }
48 return static_cast<char *>(shm_addr) + offset;
apatrick 2009/10/28 16:44:01 char -> int8
49 }
50
51 const char* CommonDecoder::GetCommonCommandName(
52 cmd::CommandId command_id) const {
53 return cmd::GetCommandName(command_id);
54 }
55
56 namespace {
57
58 // A struct to hold info about each command.
59 struct CommandInfo {
60 int arg_flags; // How to handle the arguments for this command
61 int arg_count; // How many arguments are expected for this command.
62 };
63
64 // A table of CommandInfo for all the commands.
65 const CommandInfo g_command_info[] = {
66 #define COMMON_COMMAND_BUFFER_CMD_OP(name) { \
67 cmd::name::kArgFlags, \
68 sizeof(cmd::name) / sizeof(CommandBufferEntry) - 1, }, /* NOLINT */ \
69
70 COMMON_COMMAND_BUFFER_CMDS(COMMON_COMMAND_BUFFER_CMD_OP)
71
72 #undef COMMON_COMMAND_BUFFER_CMD_OP
73 };
74
75 } // anonymous namespace.
76
77 // Decode command with its arguments, and call the corresponding method.
78 // Note: args is a pointer to the command buffer. As such, it could be changed
79 // by a (malicious) client at any time, so if validation has to happen, it
80 // should operate on a copy of them.
81 parse_error::ParseError CommonDecoder::DoCommonCommand(
82 unsigned int command,
83 unsigned int arg_count,
84 const void* cmd_data) {
85 if (command < arraysize(g_command_info)) {
86 const CommandInfo& info = g_command_info[command];
87 unsigned int info_arg_count = static_cast<unsigned int>(info.arg_count);
88 if ((info.arg_flags == cmd::kFixed && arg_count == info_arg_count) ||
89 (info.arg_flags == cmd::kAtLeastN && arg_count >= info_arg_count)) {
90 switch (command) {
91 #define COMMON_COMMAND_BUFFER_CMD_OP(name) \
92 case cmd::name::kCmdId: \
93 return Handle ## name( \
94 arg_count, \
95 *static_cast<const cmd::name*>(cmd_data)); \
96
97 COMMON_COMMAND_BUFFER_CMDS(COMMON_COMMAND_BUFFER_CMD_OP)
98
99 #undef COMMON_COMMAND_BUFFER_CMD_OP
100 }
101 } else {
102 return parse_error::kParseInvalidArguments;
103 }
104 }
105 return DoCommonCommand(command, arg_count, cmd_data);
106 return parse_error::kParseUnknownCommand;
107 }
108
109 parse_error::ParseError CommonDecoder::HandleNoop(
110 uint32 arg_count,
111 const cmd::Noop& args) {
112 return parse_error::kParseNoError;
113 }
114
115 parse_error::ParseError CommonDecoder::HandleSetToken(
116 uint32 arg_count,
117 const cmd::SetToken& args) {
118 engine_->set_token(args.token);
119 return parse_error::kParseNoError;
120 }
121
122 } // namespace command_buffer
123 } // namespace o3d
124
125
126
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698