| OLD | NEW |
| 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 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 namespace o3d { | 37 namespace o3d { |
| 38 namespace command_buffer { | 38 namespace command_buffer { |
| 39 | 39 |
| 40 CommandBufferHelper::CommandBufferHelper(BufferSyncInterface *interface) | 40 CommandBufferHelper::CommandBufferHelper(BufferSyncInterface *interface) |
| 41 : interface_(interface), | 41 : interface_(interface), |
| 42 entries_(NULL), | 42 entries_(NULL), |
| 43 entry_count_(0), | 43 entry_count_(0), |
| 44 token_(0) { | 44 token_(0) { |
| 45 // The interface should be connected already. | 45 // The interface should be connected already. |
| 46 DCHECK_NE(BufferSyncInterface::NOT_CONNECTED, interface_->GetStatus()); | 46 DCHECK_NE(BufferSyncInterface::kNotConnected, interface_->GetStatus()); |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool CommandBufferHelper::Init(unsigned int entry_count) { | 49 bool CommandBufferHelper::Init(unsigned int entry_count) { |
| 50 if (entry_count == 0) | 50 if (entry_count == 0) |
| 51 return false; | 51 return false; |
| 52 size_t size = entry_count * sizeof(CommandBufferEntry); // NOLINT | 52 size_t size = entry_count * sizeof(CommandBufferEntry); // NOLINT |
| 53 shm_handle_ = CreateShm(size); | 53 shm_handle_ = CreateShm(size); |
| 54 if (shm_handle_ == kRPCInvalidHandle) | 54 if (shm_handle_ == kRPCInvalidHandle) |
| 55 return false; | 55 return false; |
| 56 void *address = MapShm(shm_handle_, size); | 56 void *address = MapShm(shm_handle_, size); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 87 } | 87 } |
| 88 | 88 |
| 89 // Inserts a new token into the command stream. It uses an increasing value | 89 // Inserts a new token into the command stream. It uses an increasing value |
| 90 // scheme so that we don't lose tokens (a token has passed if the current token | 90 // scheme so that we don't lose tokens (a token has passed if the current token |
| 91 // value is higher than that token). Calls Finish() if the token value wraps, | 91 // value is higher than that token). Calls Finish() if the token value wraps, |
| 92 // which will be rare. | 92 // which will be rare. |
| 93 unsigned int CommandBufferHelper::InsertToken() { | 93 unsigned int CommandBufferHelper::InsertToken() { |
| 94 ++token_; | 94 ++token_; |
| 95 CommandBufferEntry args; | 95 CommandBufferEntry args; |
| 96 args.value_uint32 = token_; | 96 args.value_uint32 = token_; |
| 97 AddCommand(SET_TOKEN, 1, &args); | 97 AddCommand(command_buffer::kSetToken, 1, &args); |
| 98 if (token_ == 0) { | 98 if (token_ == 0) { |
| 99 // we wrapped | 99 // we wrapped |
| 100 Finish(); | 100 Finish(); |
| 101 last_token_read_ = interface_->GetToken(); | 101 last_token_read_ = interface_->GetToken(); |
| 102 DCHECK_EQ(token_, last_token_read_); | 102 DCHECK_EQ(token_, last_token_read_); |
| 103 } | 103 } |
| 104 return token_; | 104 return token_; |
| 105 } | 105 } |
| 106 | 106 |
| 107 // Waits until the current token value is greater or equal to the value passed | 107 // Waits until the current token value is greater or equal to the value passed |
| (...skipping 14 matching lines...) Expand all Loading... |
| 122 } | 122 } |
| 123 | 123 |
| 124 // Waits for get to change. In case get doesn't change or becomes invalid, | 124 // Waits for get to change. In case get doesn't change or becomes invalid, |
| 125 // check for an error. | 125 // check for an error. |
| 126 void CommandBufferHelper::WaitForGetChange() { | 126 void CommandBufferHelper::WaitForGetChange() { |
| 127 CommandBufferOffset new_get = interface_->WaitGetChanges(get_); | 127 CommandBufferOffset new_get = interface_->WaitGetChanges(get_); |
| 128 if (new_get == get_ || new_get == -1) { | 128 if (new_get == get_ || new_get == -1) { |
| 129 // If get_ didn't change or is invalid (-1), it means an error may have | 129 // If get_ didn't change or is invalid (-1), it means an error may have |
| 130 // occured. Check that. | 130 // occured. Check that. |
| 131 BufferSyncInterface::ParserStatus status = interface_->GetStatus(); | 131 BufferSyncInterface::ParserStatus status = interface_->GetStatus(); |
| 132 if (status != BufferSyncInterface::PARSING) { | 132 if (status != BufferSyncInterface::kParsing) { |
| 133 switch (status) { | 133 switch (status) { |
| 134 case BufferSyncInterface::NOT_CONNECTED: | 134 case BufferSyncInterface::kNotConnected: |
| 135 LOG(FATAL) << "Service disconnected."; | 135 LOG(FATAL) << "Service disconnected."; |
| 136 return; | 136 return; |
| 137 case BufferSyncInterface::NO_BUFFER: | 137 case BufferSyncInterface::kNoBuffer: |
| 138 LOG(FATAL) << "Service doesn't have a buffer set."; | 138 LOG(FATAL) << "Service doesn't have a buffer set."; |
| 139 return; | 139 return; |
| 140 case BufferSyncInterface::PARSE_ERROR: { | 140 case BufferSyncInterface::kParseError: { |
| 141 BufferSyncInterface::ParseError error = interface_->GetParseError(); | 141 BufferSyncInterface::ParseError error = interface_->GetParseError(); |
| 142 LOG(WARNING) << "Parse error: " << error; | 142 LOG(WARNING) << "Parse error: " << error; |
| 143 return; | 143 return; |
| 144 } | 144 } |
| 145 case BufferSyncInterface::PARSING: | 145 case BufferSyncInterface::kParsing: |
| 146 break; | 146 break; |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 get_ = new_get; | 150 get_ = new_get; |
| 151 } | 151 } |
| 152 | 152 |
| 153 // Waits for available entries, basically waiting until get >= put + count + 1. | 153 // Waits for available entries, basically waiting until get >= put + count + 1. |
| 154 // It actually waits for contiguous entries, so it may need to wrap the buffer | 154 // It actually waits for contiguous entries, so it may need to wrap the buffer |
| 155 // around, adding noops. Thus this function may change the value of put_. | 155 // around, adding noops. Thus this function may change the value of put_. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 174 } | 174 } |
| 175 put_ = 0; | 175 put_ = 0; |
| 176 } | 176 } |
| 177 // If we have enough room, return immediatly. | 177 // If we have enough room, return immediatly. |
| 178 if (count <= AvailableEntries()) return; | 178 if (count <= AvailableEntries()) return; |
| 179 // Otherwise flush, and wait until we do have enough room. | 179 // Otherwise flush, and wait until we do have enough room. |
| 180 Flush(); | 180 Flush(); |
| 181 while (AvailableEntries() < count) WaitForGetChange(); | 181 while (AvailableEntries() < count) WaitForGetChange(); |
| 182 } | 182 } |
| 183 | 183 |
| 184 CommandBufferEntry* CommandBufferHelper::GetSpace(uint32 entries) { |
| 185 WaitForAvailableEntries(entries); |
| 186 CommandBufferEntry* space = &entries_[put_]; |
| 187 put_ += entries; |
| 188 return space; |
| 189 } |
| 190 |
| 184 } // namespace command_buffer | 191 } // namespace command_buffer |
| 185 } // namespace o3d | 192 } // namespace o3d |
| OLD | NEW |