| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // A class to emluate GLES2 over command buffers. | 5 // A class to emluate GLES2 over command buffers. |
| 6 | 6 |
| 7 #include "../client/gles2_implementation.h" | 7 #include "../client/gles2_implementation.h" |
| 8 #include "../common/gles2_cmd_utils.h" | 8 #include "../common/gles2_cmd_utils.h" |
| 9 | 9 |
| 10 namespace gpu { | 10 namespace gpu { |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 bound_element_array_buffer_id_(0), | 343 bound_element_array_buffer_id_(0), |
| 344 #endif | 344 #endif |
| 345 error_bits_(0) { | 345 error_bits_(0) { |
| 346 // Allocate space for simple GL results. | 346 // Allocate space for simple GL results. |
| 347 result_buffer_ = transfer_buffer_.Alloc(kMaxSizeOfSimpleResult); | 347 result_buffer_ = transfer_buffer_.Alloc(kMaxSizeOfSimpleResult); |
| 348 result_shm_offset_ = transfer_buffer_.GetOffset(result_buffer_); | 348 result_shm_offset_ = transfer_buffer_.GetOffset(result_buffer_); |
| 349 | 349 |
| 350 #if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) | 350 #if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) |
| 351 GLint max_vertex_attribs; | 351 GLint max_vertex_attribs; |
| 352 GetIntegerv(GL_MAX_VERTEX_ATTRIBS, &max_vertex_attribs); | 352 GetIntegerv(GL_MAX_VERTEX_ATTRIBS, &max_vertex_attribs); |
| 353 id_allocator_.MarkAsUsed(kClientSideArrayId); | 353 buffer_id_allocator_.MarkAsUsed(kClientSideArrayId); |
| 354 id_allocator_.MarkAsUsed(kClientSideElementArrayId); | 354 buffer_id_allocator_.MarkAsUsed(kClientSideElementArrayId); |
| 355 | 355 |
| 356 reserved_ids_[0] = kClientSideArrayId; | 356 reserved_ids_[0] = kClientSideArrayId; |
| 357 reserved_ids_[1] = kClientSideElementArrayId; | 357 reserved_ids_[1] = kClientSideElementArrayId; |
| 358 | 358 |
| 359 client_side_buffer_helper_.reset(new ClientSideBufferHelper( | 359 client_side_buffer_helper_.reset(new ClientSideBufferHelper( |
| 360 max_vertex_attribs, | 360 max_vertex_attribs, |
| 361 kClientSideArrayId, | 361 kClientSideArrayId, |
| 362 kClientSideElementArrayId)); | 362 kClientSideElementArrayId)); |
| 363 #endif | 363 #endif |
| 364 } | 364 } |
| 365 | 365 |
| 366 GLES2Implementation::~GLES2Implementation() { | 366 GLES2Implementation::~GLES2Implementation() { |
| 367 GLuint buffers[] = { kClientSideArrayId, kClientSideElementArrayId, }; | 367 GLuint buffers[] = { kClientSideArrayId, kClientSideElementArrayId, }; |
| 368 DeleteBuffers(arraysize(buffers), &buffers[0]); | 368 DeleteBuffers(arraysize(buffers), &buffers[0]); |
| 369 transfer_buffer_.Free(result_buffer_); | 369 transfer_buffer_.Free(result_buffer_); |
| 370 } | 370 } |
| 371 | 371 |
| 372 void GLES2Implementation::MakeIds(GLsizei n, GLuint* ids) { | 372 void GLES2Implementation::MakeIds( |
| 373 IdAllocator* id_allocator, GLsizei n, GLuint* ids) { |
| 373 for (GLsizei ii = 0; ii < n; ++ii) { | 374 for (GLsizei ii = 0; ii < n; ++ii) { |
| 374 ids[ii] = id_allocator_.AllocateID(); | 375 ids[ii] = id_allocator->AllocateID(); |
| 375 } | 376 } |
| 376 } | 377 } |
| 377 | 378 |
| 378 void GLES2Implementation::FreeIds(GLsizei n, const GLuint* ids) { | 379 void GLES2Implementation::FreeIds( |
| 380 IdAllocator* id_allocator, GLsizei n, const GLuint* ids) { |
| 379 for (GLsizei ii = 0; ii < n; ++ii) { | 381 for (GLsizei ii = 0; ii < n; ++ii) { |
| 380 id_allocator_.FreeID(ids[ii]); | 382 id_allocator->FreeID(ids[ii]); |
| 381 } | 383 } |
| 382 } | 384 } |
| 383 | 385 |
| 384 void GLES2Implementation::WaitForCmd() { | 386 void GLES2Implementation::WaitForCmd() { |
| 385 helper_->CommandBufferHelper::Finish(); | 387 helper_->CommandBufferHelper::Finish(); |
| 386 } | 388 } |
| 387 | 389 |
| 388 GLenum GLES2Implementation::GetError() { | 390 GLenum GLES2Implementation::GetError() { |
| 389 return GetGLError(); | 391 return GetGLError(); |
| 390 } | 392 } |
| (...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 temp_xoffset += num_pixels; | 1175 temp_xoffset += num_pixels; |
| 1174 temp_width -= num_pixels; | 1176 temp_width -= num_pixels; |
| 1175 } | 1177 } |
| 1176 ++yoffset; | 1178 ++yoffset; |
| 1177 dest += padded_row_size; | 1179 dest += padded_row_size; |
| 1178 } | 1180 } |
| 1179 } | 1181 } |
| 1180 } | 1182 } |
| 1181 | 1183 |
| 1182 #if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) | 1184 #if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) |
| 1183 bool GLES2Implementation::IsReservedId(GLuint id) { | 1185 bool GLES2Implementation::IsBufferReservedId(GLuint id) { |
| 1184 for (size_t ii = 0; ii < arraysize(reserved_ids_); ++ii) { | 1186 for (size_t ii = 0; ii < arraysize(reserved_ids_); ++ii) { |
| 1185 if (id == reserved_ids_[ii]) { | 1187 if (id == reserved_ids_[ii]) { |
| 1186 return true; | 1188 return true; |
| 1187 } | 1189 } |
| 1188 } | 1190 } |
| 1189 return false; | 1191 return false; |
| 1190 } | 1192 } |
| 1191 #else | 1193 #else |
| 1192 bool GLES2Implementation::IsReservedId(GLuint) { // NOLINT | 1194 bool GLES2Implementation::IsBufferReservedId(GLuint) { // NOLINT |
| 1193 return false; | 1195 return false; |
| 1194 } | 1196 } |
| 1195 #endif | 1197 #endif |
| 1196 | 1198 |
| 1197 #if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) | 1199 #if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) |
| 1198 | 1200 |
| 1199 void GLES2Implementation::BindBuffer(GLenum target, GLuint buffer) { | 1201 void GLES2Implementation::BindBuffer(GLenum target, GLuint buffer) { |
| 1200 if (IsReservedId(buffer)) { | 1202 if (IsBufferReservedId(buffer)) { |
| 1201 SetGLError(GL_INVALID_OPERATION); | 1203 SetGLError(GL_INVALID_OPERATION); |
| 1202 return; | 1204 return; |
| 1203 } | 1205 } |
| 1204 if (buffer != 0) { | 1206 if (buffer != 0) { |
| 1205 id_allocator_.MarkAsUsed(buffer); | 1207 buffer_id_allocator_.MarkAsUsed(buffer); |
| 1206 } | 1208 } |
| 1207 switch (target) { | 1209 switch (target) { |
| 1208 case GL_ARRAY_BUFFER: | 1210 case GL_ARRAY_BUFFER: |
| 1209 bound_array_buffer_id_ = buffer; | 1211 bound_array_buffer_id_ = buffer; |
| 1210 break; | 1212 break; |
| 1211 case GL_ELEMENT_ARRAY_BUFFER: | 1213 case GL_ELEMENT_ARRAY_BUFFER: |
| 1212 bound_element_array_buffer_id_ = buffer; | 1214 bound_element_array_buffer_id_ = buffer; |
| 1213 break; | 1215 break; |
| 1214 default: | 1216 default: |
| 1215 break; | 1217 break; |
| 1216 } | 1218 } |
| 1217 helper_->BindBuffer(target, buffer); | 1219 helper_->BindBuffer(target, buffer); |
| 1218 } | 1220 } |
| 1219 | 1221 |
| 1220 void GLES2Implementation::DeleteBuffers(GLsizei n, const GLuint* buffers) { | 1222 void GLES2Implementation::DeleteBuffers(GLsizei n, const GLuint* buffers) { |
| 1221 FreeIds(n, buffers); | 1223 FreeIds(&buffer_id_allocator_, n, buffers); |
| 1222 for (GLsizei ii = 0; ii < n; ++ii) { | 1224 for (GLsizei ii = 0; ii < n; ++ii) { |
| 1223 if (buffers[ii] == bound_array_buffer_id_) { | 1225 if (buffers[ii] == bound_array_buffer_id_) { |
| 1224 bound_array_buffer_id_ = 0; | 1226 bound_array_buffer_id_ = 0; |
| 1225 } | 1227 } |
| 1226 if (buffers[ii] == bound_element_array_buffer_id_) { | 1228 if (buffers[ii] == bound_element_array_buffer_id_) { |
| 1227 bound_element_array_buffer_id_ = 0; | 1229 bound_element_array_buffer_id_ = 0; |
| 1228 } | 1230 } |
| 1229 } | 1231 } |
| 1230 // TODO(gman): compute the number of buffers we can delete in 1 call | 1232 // TODO(gman): compute the number of buffers we can delete in 1 call |
| 1231 // based on the size of command buffer and the limit of argument size | 1233 // based on the size of command buffer and the limit of argument size |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1327 helper_->GetVertexAttribiv( | 1329 helper_->GetVertexAttribiv( |
| 1328 index, pname, result_shm_id(), result_shm_offset()); | 1330 index, pname, result_shm_id(), result_shm_offset()); |
| 1329 WaitForCmd(); | 1331 WaitForCmd(); |
| 1330 result->CopyResult(params); | 1332 result->CopyResult(params); |
| 1331 } | 1333 } |
| 1332 | 1334 |
| 1333 #endif // defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) | 1335 #endif // defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) |
| 1334 | 1336 |
| 1335 } // namespace gles2 | 1337 } // namespace gles2 |
| 1336 } // namespace gpu | 1338 } // namespace gpu |
| OLD | NEW |