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

Side by Side Diff: core/cross/command_buffer/buffer_cb.cc

Issue 212018: Change command buffer client code to use structures.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: '' Created 11 years, 3 months 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
« no previous file with comments | « command_buffer/service/win/d3d9/texture_d3d9.cc ('k') | core/cross/command_buffer/effect_cb.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 has_data_(false), 49 has_data_(false),
50 resource_id_(command_buffer::kInvalidResource), 50 resource_id_(command_buffer::kInvalidResource),
51 renderer_(renderer) { 51 renderer_(renderer) {
52 } 52 }
53 53
54 54
55 VertexBufferCB::~VertexBufferCB() { 55 VertexBufferCB::~VertexBufferCB() {
56 ConcreteFree(); 56 ConcreteFree();
57 } 57 }
58 58
59 // Sends the DESTROY_VERTEX_BUFFER command, and frees the ID from the allocator. 59 // Sends the DestroyVertexBuffer command, and frees the ID from the allocator.
60 void VertexBufferCB::ConcreteFree() { 60 void VertexBufferCB::ConcreteFree() {
61 if (resource_id_ != command_buffer::kInvalidResource) { 61 if (resource_id_ != command_buffer::kInvalidResource) {
62 CommandBufferHelper *helper = renderer_->helper(); 62 CommandBufferHelper *helper = renderer_->helper();
63 CommandBufferEntry args[1]; 63 helper->DestroyVertexBuffer(resource_id_);
64 args[0].value_uint32 = resource_id_;
65 helper->AddCommand(command_buffer::DESTROY_VERTEX_BUFFER, 1, args);
66 renderer_->vertex_buffer_ids().FreeID(resource_id_); 64 renderer_->vertex_buffer_ids().FreeID(resource_id_);
67 resource_id_ = command_buffer::kInvalidResource; 65 resource_id_ = command_buffer::kInvalidResource;
68 } 66 }
69 } 67 }
70 68
71 // Allocates a resource ID, and sends the CREATE_VERTEX_BUFFER command. 69 // Allocates a resource ID, and sends the CreateVertexBuffer command.
72 bool VertexBufferCB::ConcreteAllocate(size_t size_in_bytes) { 70 bool VertexBufferCB::ConcreteAllocate(size_t size_in_bytes) {
73 ConcreteFree(); 71 ConcreteFree();
74 if (size_in_bytes > 0) { 72 if (size_in_bytes > 0) {
75 resource_id_ = renderer_->vertex_buffer_ids().AllocateID(); 73 resource_id_ = renderer_->vertex_buffer_ids().AllocateID();
76 CommandBufferHelper *helper = renderer_->helper(); 74 CommandBufferHelper *helper = renderer_->helper();
77 CommandBufferEntry args[3]; 75 helper->CreateVertexBuffer(resource_id_, size_in_bytes, 0);
78 args[0].value_uint32 = resource_id_;
79 args[1].value_uint32 = size_in_bytes;
80 args[2].value_uint32 = 0; // no flags.
81 helper->AddCommand(command_buffer::CREATE_VERTEX_BUFFER, 3, args);
82 has_data_ = false; 76 has_data_ = false;
83 } 77 }
84 return true; 78 return true;
85 } 79 }
86 80
87 // Allocates the locked region into the transfer shared memory area. If the 81 // Allocates the locked region into the transfer shared memory area. If the
88 // buffer resource contains data, copies it back (by sending the 82 // buffer resource contains data, copies it back (by sending the
89 // GET_VERTEX_BUFFER_DATA command). 83 // GetVertexBufferData command).
90 bool VertexBufferCB::ConcreteLock(AccessMode access_mode, void **buffer_data) { 84 bool VertexBufferCB::ConcreteLock(AccessMode access_mode, void **buffer_data) {
91 *buffer_data = NULL; 85 *buffer_data = NULL;
92 if (GetSizeInBytes() == 0 || lock_pointer_) 86 if (GetSizeInBytes() == 0 || lock_pointer_)
93 return false; 87 return false;
94 lock_pointer_ = renderer_->allocator()->Alloc(GetSizeInBytes()); 88 lock_pointer_ = renderer_->allocator()->Alloc(GetSizeInBytes());
95 if (!lock_pointer_) return false; 89 if (!lock_pointer_) return false;
96 if (has_data_) { 90 if (has_data_) {
97 CommandBufferHelper *helper = renderer_->helper(); 91 CommandBufferHelper *helper = renderer_->helper();
98 CommandBufferEntry args[5]; 92 helper->GetVertexBufferData(
99 args[0].value_uint32 = resource_id_; 93 resource_id_, 0, GetSizeInBytes(),
100 args[1].value_uint32 = 0; 94 renderer_->transfer_shm_id(),
101 args[2].value_uint32 = GetSizeInBytes(); 95 renderer_->allocator()->GetOffset(lock_pointer_));
102 args[3].value_uint32 = renderer_->transfer_shm_id();
103 args[4].value_uint32 = renderer_->allocator()->GetOffset(lock_pointer_);
104 helper->AddCommand(command_buffer::GET_VERTEX_BUFFER_DATA, 5, args);
105 helper->Finish(); 96 helper->Finish();
106 } 97 }
107 *buffer_data = lock_pointer_; 98 *buffer_data = lock_pointer_;
108 return true; 99 return true;
109 } 100 }
110 101
111 // Copies the data into the resource by sending the SET_VERTEX_BUFFER_DATA 102 // Copies the data into the resource by sending the SetVertexBufferData
112 // command, then frees the shared memory, pending the transfer completion. 103 // command, then frees the shared memory, pending the transfer completion.
113 bool VertexBufferCB::ConcreteUnlock() { 104 bool VertexBufferCB::ConcreteUnlock() {
114 if (GetSizeInBytes() == 0 || !lock_pointer_) 105 if (GetSizeInBytes() == 0 || !lock_pointer_)
115 return false; 106 return false;
116 CommandBufferHelper *helper = renderer_->helper(); 107 CommandBufferHelper *helper = renderer_->helper();
117 CommandBufferEntry args[5]; 108 helper->SetVertexBufferData(
118 args[0].value_uint32 = resource_id_; 109 resource_id_, 0, GetSizeInBytes(),
119 args[1].value_uint32 = 0; 110 renderer_->transfer_shm_id(),
120 args[2].value_uint32 = GetSizeInBytes(); 111 renderer_->allocator()->GetOffset(lock_pointer_));
121 args[3].value_uint32 = renderer_->transfer_shm_id(); 112
122 args[4].value_uint32 = renderer_->allocator()->GetOffset(lock_pointer_);
123 helper->AddCommand(command_buffer::SET_VERTEX_BUFFER_DATA, 5, args);
124 renderer_->allocator()->FreePendingToken(lock_pointer_, 113 renderer_->allocator()->FreePendingToken(lock_pointer_,
125 helper->InsertToken()); 114 helper->InsertToken());
126 lock_pointer_ = NULL; 115 lock_pointer_ = NULL;
127 has_data_ = true; 116 has_data_ = true;
128 return true; 117 return true;
129 } 118 }
130 119
131 IndexBufferCB::IndexBufferCB(ServiceLocator* service_locator, 120 IndexBufferCB::IndexBufferCB(ServiceLocator* service_locator,
132 RendererCB *renderer) 121 RendererCB *renderer)
133 : IndexBuffer(service_locator), 122 : IndexBuffer(service_locator),
134 lock_pointer_(NULL), 123 lock_pointer_(NULL),
135 has_data_(false), 124 has_data_(false),
136 resource_id_(command_buffer::kInvalidResource), 125 resource_id_(command_buffer::kInvalidResource),
137 renderer_(renderer) { 126 renderer_(renderer) {
138 } 127 }
139 128
140 129
141 IndexBufferCB::~IndexBufferCB() { 130 IndexBufferCB::~IndexBufferCB() {
142 ConcreteFree(); 131 ConcreteFree();
143 } 132 }
144 133
145 // Sends the DESTROY_INDEX_BUFFER command, and frees the ID from the allocator. 134 // Sends the DestroyIndexBuffer command, and frees the ID from the allocator.
146 void IndexBufferCB::ConcreteFree() { 135 void IndexBufferCB::ConcreteFree() {
147 if (resource_id_ != command_buffer::kInvalidResource) { 136 if (resource_id_ != command_buffer::kInvalidResource) {
148 CommandBufferHelper *helper = renderer_->helper(); 137 CommandBufferHelper *helper = renderer_->helper();
149 CommandBufferEntry args[1]; 138 helper->DestroyIndexBuffer(resource_id_);
150 args[0].value_uint32 = resource_id_;
151 helper->AddCommand(command_buffer::DESTROY_INDEX_BUFFER, 1, args);
152 renderer_->index_buffer_ids().FreeID(resource_id_); 139 renderer_->index_buffer_ids().FreeID(resource_id_);
153 resource_id_ = command_buffer::kInvalidResource; 140 resource_id_ = command_buffer::kInvalidResource;
154 } 141 }
155 } 142 }
156 143
157 // Allocates a resource ID, and sends the CREATE_INDEX_BUFFER command. 144 // Allocates a resource ID, and sends the CreateIndexBuffer command.
158 bool IndexBufferCB::ConcreteAllocate(size_t size_in_bytes) { 145 bool IndexBufferCB::ConcreteAllocate(size_t size_in_bytes) {
159 ConcreteFree(); 146 ConcreteFree();
160 if (size_in_bytes > 0) { 147 if (size_in_bytes > 0) {
161 resource_id_ = renderer_->index_buffer_ids().AllocateID(); 148 resource_id_ = renderer_->index_buffer_ids().AllocateID();
162 CommandBufferHelper *helper = renderer_->helper(); 149 CommandBufferHelper *helper = renderer_->helper();
163 CommandBufferEntry args[3]; 150 helper->CreateIndexBuffer(
164 args[0].value_uint32 = resource_id_; 151 resource_id_, size_in_bytes,
165 args[1].value_uint32 = size_in_bytes; 152 command_buffer::index_buffer::INDEX_32BIT);
166 args[2].value_uint32 = command_buffer::index_buffer::INDEX_32BIT;
167 helper->AddCommand(command_buffer::CREATE_INDEX_BUFFER, 3, args);
168 has_data_ = false; 153 has_data_ = false;
169 } 154 }
170 return true; 155 return true;
171 } 156 }
172 157
173 // Allocates the locked region into the transfer shared memory area. If the 158 // Allocates the locked region into the transfer shared memory area. If the
174 // buffer resource contains data, copies it back (by sending the 159 // buffer resource contains data, copies it back (by sending the
175 // GET_INDEX_BUFFER_DATA command). 160 // GetIndexBufferData command).
176 bool IndexBufferCB::ConcreteLock(AccessMode access_mode, void **buffer_data) { 161 bool IndexBufferCB::ConcreteLock(AccessMode access_mode, void **buffer_data) {
177 *buffer_data = NULL; 162 *buffer_data = NULL;
178 if (GetSizeInBytes() == 0 || lock_pointer_) 163 if (GetSizeInBytes() == 0 || lock_pointer_)
179 return false; 164 return false;
180 lock_pointer_ = renderer_->allocator()->Alloc(GetSizeInBytes()); 165 lock_pointer_ = renderer_->allocator()->Alloc(GetSizeInBytes());
181 if (!lock_pointer_) return false; 166 if (!lock_pointer_) return false;
182 if (has_data_) { 167 if (has_data_) {
183 CommandBufferHelper *helper = renderer_->helper(); 168 CommandBufferHelper *helper = renderer_->helper();
184 CommandBufferEntry args[5]; 169 helper->GetIndexBufferData(
185 args[0].value_uint32 = resource_id_; 170 resource_id_, 0, GetSizeInBytes(),
186 args[1].value_uint32 = 0; 171 renderer_->transfer_shm_id(),
187 args[2].value_uint32 = GetSizeInBytes(); 172 renderer_->allocator()->GetOffset(lock_pointer_));
188 args[3].value_uint32 = renderer_->transfer_shm_id();
189 args[4].value_uint32 = renderer_->allocator()->GetOffset(lock_pointer_);
190 helper->AddCommand(command_buffer::GET_INDEX_BUFFER_DATA, 5, args);
191 helper->Finish(); 173 helper->Finish();
192 } 174 }
193 *buffer_data = lock_pointer_; 175 *buffer_data = lock_pointer_;
194 return true; 176 return true;
195 } 177 }
196 178
197 // Copies the data into the resource by sending the SET_INDEX_BUFFER_DATA 179 // Copies the data into the resource by sending the SetIndexBufferData
198 // command, then frees the shared memory, pending the transfer completion. 180 // command, then frees the shared memory, pending the transfer completion.
199 bool IndexBufferCB::ConcreteUnlock() { 181 bool IndexBufferCB::ConcreteUnlock() {
200 if (GetSizeInBytes() == 0 || !lock_pointer_) 182 if (GetSizeInBytes() == 0 || !lock_pointer_)
201 return false; 183 return false;
202 CommandBufferHelper *helper = renderer_->helper(); 184 CommandBufferHelper *helper = renderer_->helper();
203 CommandBufferEntry args[5]; 185 helper->SetIndexBufferData(
204 args[0].value_uint32 = resource_id_; 186 resource_id_, 0, GetSizeInBytes(),
205 args[1].value_uint32 = 0; 187 renderer_->transfer_shm_id(),
206 args[2].value_uint32 = GetSizeInBytes(); 188 renderer_->allocator()->GetOffset(lock_pointer_));
207 args[3].value_uint32 = renderer_->transfer_shm_id();
208 args[4].value_uint32 = renderer_->allocator()->GetOffset(lock_pointer_);
209 helper->AddCommand(command_buffer::SET_INDEX_BUFFER_DATA, 5, args);
210 renderer_->allocator()->FreePendingToken(lock_pointer_, 189 renderer_->allocator()->FreePendingToken(lock_pointer_,
211 helper->InsertToken()); 190 helper->InsertToken());
212 lock_pointer_ = NULL; 191 lock_pointer_ = NULL;
213 has_data_ = true; 192 has_data_ = true;
214 return true; 193 return true;
215 } 194 }
216 195
217 } // namespace o3d 196 } // namespace o3d
OLDNEW
« no previous file with comments | « command_buffer/service/win/d3d9/texture_d3d9.cc ('k') | core/cross/command_buffer/effect_cb.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698