Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 emulate GLES2 over command buffers. | 5 // A class to emulate GLES2 over command buffers. |
| 6 | 6 |
| 7 #include "../client/gles2_implementation.h" | 7 #include "../client/gles2_implementation.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <queue> | 11 #include <queue> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <limits> | 13 #include <limits> |
| 14 #include <stdio.h> | 14 #include <stdio.h> |
| 15 #include <string.h> | 15 #include <string.h> |
| 16 #include <GLES2/gl2ext.h> | 16 #include <GLES2/gl2ext.h> |
| 17 #include <GLES2/gl2extchromium.h> | 17 #include <GLES2/gl2extchromium.h> |
| 18 #include "../client/buffer_tracker.h" | 18 #include "../client/buffer_tracker.h" |
| 19 #include "../client/gpu_memory_buffer.h" | |
| 20 #include "../client/gpu_memory_buffer_factory.h" | |
| 21 #include "../client/gpu_memory_buffer_tracker.h" | |
| 19 #include "../client/mapped_memory.h" | 22 #include "../client/mapped_memory.h" |
| 20 #include "../client/program_info_manager.h" | 23 #include "../client/program_info_manager.h" |
| 21 #include "../client/query_tracker.h" | 24 #include "../client/query_tracker.h" |
| 22 #include "../client/transfer_buffer.h" | 25 #include "../client/transfer_buffer.h" |
| 23 #include "../client/vertex_array_object_manager.h" | 26 #include "../client/vertex_array_object_manager.h" |
| 24 #include "../common/gles2_cmd_utils.h" | 27 #include "../common/gles2_cmd_utils.h" |
| 25 #include "../common/trace_event.h" | 28 #include "../common/trace_event.h" |
| 26 | 29 |
| 27 #if defined(__native_client__) && !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) | 30 #if defined(__native_client__) && !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) |
| 28 #define GLES2_SUPPORT_CLIENT_SIDE_ARRAYS | 31 #define GLES2_SUPPORT_CLIENT_SIDE_ARRAYS |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 unpack_skip_pixels_(0), | 94 unpack_skip_pixels_(0), |
| 92 pack_reverse_row_order_(false), | 95 pack_reverse_row_order_(false), |
| 93 active_texture_unit_(0), | 96 active_texture_unit_(0), |
| 94 bound_framebuffer_(0), | 97 bound_framebuffer_(0), |
| 95 bound_read_framebuffer_(0), | 98 bound_read_framebuffer_(0), |
| 96 bound_renderbuffer_(0), | 99 bound_renderbuffer_(0), |
| 97 current_program_(0), | 100 current_program_(0), |
| 98 bound_array_buffer_id_(0), | 101 bound_array_buffer_id_(0), |
| 99 bound_pixel_pack_transfer_buffer_id_(0), | 102 bound_pixel_pack_transfer_buffer_id_(0), |
| 100 bound_pixel_unpack_transfer_buffer_id_(0), | 103 bound_pixel_unpack_transfer_buffer_id_(0), |
| 104 bound_gpu_memory_buffer_id_(0), | |
| 101 error_bits_(0), | 105 error_bits_(0), |
| 102 debug_(false), | 106 debug_(false), |
| 103 use_count_(0), | 107 use_count_(0), |
| 104 current_query_(NULL), | 108 current_query_(NULL), |
| 105 error_message_callback_(NULL) { | 109 error_message_callback_(NULL), |
| 110 gpu_memory_buffer_factory_(NULL) { | |
|
greggman
2013/05/03 23:48:01
as this is a scoped_ptr initialization to null is
kaanb
2013/05/06 18:20:53
Done.
| |
| 106 GPU_DCHECK(helper); | 111 GPU_DCHECK(helper); |
| 107 GPU_DCHECK(transfer_buffer); | 112 GPU_DCHECK(transfer_buffer); |
| 108 | 113 |
| 109 char temp[128]; | 114 char temp[128]; |
| 110 sprintf(temp, "%p", static_cast<void*>(this)); | 115 sprintf(temp, "%p", static_cast<void*>(this)); |
| 111 this_in_hex_ = std::string(temp); | 116 this_in_hex_ = std::string(temp); |
| 112 | 117 |
| 113 GPU_CLIENT_LOG_CODE_BLOCK({ | 118 GPU_CLIENT_LOG_CODE_BLOCK({ |
| 114 debug_ = CommandLine::ForCurrentProcess()->HasSwitch( | 119 debug_ = CommandLine::ForCurrentProcess()->HasSwitch( |
| 115 switches::kEnableGPUClientLogging); | 120 switches::kEnableGPUClientLogging); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 static_state_.int_state.num_compressed_texture_formats); | 171 static_state_.int_state.num_compressed_texture_formats); |
| 167 util_.set_num_shader_binary_formats( | 172 util_.set_num_shader_binary_formats( |
| 168 static_state_.int_state.num_shader_binary_formats); | 173 static_state_.int_state.num_shader_binary_formats); |
| 169 | 174 |
| 170 texture_units_.reset( | 175 texture_units_.reset( |
| 171 new TextureUnit[ | 176 new TextureUnit[ |
| 172 static_state_.int_state.max_combined_texture_image_units]); | 177 static_state_.int_state.max_combined_texture_image_units]); |
| 173 | 178 |
| 174 query_tracker_.reset(new QueryTracker(mapped_memory_.get())); | 179 query_tracker_.reset(new QueryTracker(mapped_memory_.get())); |
| 175 buffer_tracker_.reset(new BufferTracker(mapped_memory_.get())); | 180 buffer_tracker_.reset(new BufferTracker(mapped_memory_.get())); |
| 181 gpu_memory_buffer_tracker_.reset(new GpuMemoryBufferTracker( | |
| 182 gpu_memory_buffer_factory_.get())); | |
| 176 | 183 |
| 177 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) | 184 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) |
| 178 GetIdHandler(id_namespaces::kBuffers)->MakeIds( | 185 GetIdHandler(id_namespaces::kBuffers)->MakeIds( |
| 179 this, kClientSideArrayId, arraysize(reserved_ids_), &reserved_ids_[0]); | 186 this, kClientSideArrayId, arraysize(reserved_ids_), &reserved_ids_[0]); |
| 180 #endif | 187 #endif |
| 181 | 188 |
| 182 vertex_array_object_manager_.reset(new VertexArrayObjectManager( | 189 vertex_array_object_manager_.reset(new VertexArrayObjectManager( |
| 183 static_state_.int_state.max_vertex_attribs, | 190 static_state_.int_state.max_vertex_attribs, |
| 184 reserved_ids_[0], | 191 reserved_ids_[0], |
| 185 reserved_ids_[1])); | 192 reserved_ids_[1])); |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 *params = bound_read_framebuffer_; | 630 *params = bound_read_framebuffer_; |
| 624 return true; | 631 return true; |
| 625 } | 632 } |
| 626 return false; | 633 return false; |
| 627 case GL_RENDERBUFFER_BINDING: | 634 case GL_RENDERBUFFER_BINDING: |
| 628 if (share_group_->bind_generates_resource()) { | 635 if (share_group_->bind_generates_resource()) { |
| 629 *params = bound_renderbuffer_; | 636 *params = bound_renderbuffer_; |
| 630 return true; | 637 return true; |
| 631 } | 638 } |
| 632 return false; | 639 return false; |
| 640 case GL_IMAGE_BUFFER_BINDING_CHROMIUM: | |
| 641 *params = bound_gpu_memory_buffer_id_; | |
|
greggman
2013/05/03 23:48:01
can you gate this on if there is a factory? If no
kaanb
2013/05/06 18:20:53
Done.
| |
| 642 return true; | |
| 633 default: | 643 default: |
| 634 return false; | 644 return false; |
| 635 } | 645 } |
| 636 } | 646 } |
| 637 | 647 |
| 638 bool GLES2Implementation::GetBooleanvHelper(GLenum pname, GLboolean* params) { | 648 bool GLES2Implementation::GetBooleanvHelper(GLenum pname, GLboolean* params) { |
| 639 // TODO(gman): Make this handle pnames that return more than 1 value. | 649 // TODO(gman): Make this handle pnames that return more than 1 value. |
| 640 GLint value; | 650 GLint value; |
| 641 if (!GetHelper(pname, &value)) { | 651 if (!GetHelper(pname, &value)) { |
| 642 return false; | 652 return false; |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1238 } | 1248 } |
| 1239 } | 1249 } |
| 1240 | 1250 |
| 1241 GPU_DCHECK_EQ(total_size, offset); | 1251 GPU_DCHECK_EQ(total_size, offset); |
| 1242 | 1252 |
| 1243 helper_->ShaderSourceBucket(shader, kResultBucketId); | 1253 helper_->ShaderSourceBucket(shader, kResultBucketId); |
| 1244 helper_->SetBucketSize(kResultBucketId, 0); | 1254 helper_->SetBucketSize(kResultBucketId, 0); |
| 1245 CheckGLError(); | 1255 CheckGLError(); |
| 1246 } | 1256 } |
| 1247 | 1257 |
| 1258 void GLES2Implementation::GetBoundGpuMemoryBuffer( | |
| 1259 const char* function_name, GLuint* buffer_id) { | |
| 1260 *buffer_id = bound_gpu_memory_buffer_id_; | |
| 1261 | |
| 1262 if (*buffer_id == 0) { | |
| 1263 SetGLError(GL_INVALID_OPERATION, function_name, "no buffer bound"); | |
| 1264 } | |
| 1265 | |
| 1266 return; | |
|
greggman
2013/05/03 23:48:01
no need for return in void function?
kaanb
2013/05/06 18:20:53
Done.
| |
| 1267 } | |
| 1268 | |
| 1248 void GLES2Implementation::BufferDataHelper( | 1269 void GLES2Implementation::BufferDataHelper( |
| 1249 GLenum target, GLsizeiptr size, const void* data, GLenum usage) { | 1270 GLenum target, GLsizeiptr size, const void* data, GLenum usage) { |
| 1250 if (size < 0) { | 1271 if (size < 0) { |
| 1251 SetGLError(GL_INVALID_VALUE, "glBufferData", "size < 0"); | 1272 SetGLError(GL_INVALID_VALUE, "glBufferData", "size < 0"); |
| 1252 return; | 1273 return; |
| 1253 } | 1274 } |
| 1254 | 1275 |
| 1255 GLuint buffer_id; | 1276 GLuint buffer_id; |
| 1256 if (GetBoundPixelTransferBuffer(target, "glBufferData", &buffer_id)) { | 1277 if (GetBoundPixelTransferBuffer(target, "glBufferData", &buffer_id)) { |
| 1257 if (!buffer_id) { | 1278 if (!buffer_id) { |
| (...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2022 std::string str; | 2043 std::string str; |
| 2023 if (GetBucketAsString(kResultBucketId, &str)) { | 2044 if (GetBucketAsString(kResultBucketId, &str)) { |
| 2024 // Adds extensions implemented on client side only. | 2045 // Adds extensions implemented on client side only. |
| 2025 switch (name) { | 2046 switch (name) { |
| 2026 case GL_EXTENSIONS: | 2047 case GL_EXTENSIONS: |
| 2027 str += std::string(str.empty() ? "" : " ") + | 2048 str += std::string(str.empty() ? "" : " ") + |
| 2028 "GL_CHROMIUM_flipy " | 2049 "GL_CHROMIUM_flipy " |
| 2029 "GL_CHROMIUM_map_sub " | 2050 "GL_CHROMIUM_map_sub " |
| 2030 "GL_CHROMIUM_shallow_flush " | 2051 "GL_CHROMIUM_shallow_flush " |
| 2031 "GL_EXT_unpack_subimage"; | 2052 "GL_EXT_unpack_subimage"; |
| 2053 if (gpu_memory_buffer_factory_ != NULL) { | |
| 2054 str += " "; | |
| 2055 str += "GL_CHROMIUM_gpu_memory_buffer"; | |
| 2056 } | |
| 2032 break; | 2057 break; |
| 2033 default: | 2058 default: |
| 2034 break; | 2059 break; |
| 2035 } | 2060 } |
| 2036 | 2061 |
| 2037 // Because of WebGL the extensions can change. We have to cache each unique | 2062 // Because of WebGL the extensions can change. We have to cache each unique |
| 2038 // result since we don't know when the client will stop referring to a | 2063 // result since we don't know when the client will stop referring to a |
| 2039 // previous one it queries. | 2064 // previous one it queries. |
| 2040 GLStringMap::iterator it = gl_strings_.find(name); | 2065 GLStringMap::iterator it = gl_strings_.find(name); |
| 2041 if (it == gl_strings_.end()) { | 2066 if (it == gl_strings_.end()) { |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2267 | 2292 |
| 2268 void GLES2Implementation::GenVertexArraysOESHelper( | 2293 void GLES2Implementation::GenVertexArraysOESHelper( |
| 2269 GLsizei n, const GLuint* arrays) { | 2294 GLsizei n, const GLuint* arrays) { |
| 2270 vertex_array_object_manager_->GenVertexArrays(n, arrays); | 2295 vertex_array_object_manager_->GenVertexArrays(n, arrays); |
| 2271 } | 2296 } |
| 2272 | 2297 |
| 2273 void GLES2Implementation::GenQueriesEXTHelper( | 2298 void GLES2Implementation::GenQueriesEXTHelper( |
| 2274 GLsizei /* n */, const GLuint* /* queries */) { | 2299 GLsizei /* n */, const GLuint* /* queries */) { |
| 2275 } | 2300 } |
| 2276 | 2301 |
| 2302 void GLES2Implementation::GenImageBuffersHelper( | |
| 2303 GLsizei /* n */, const GLuint* /* queries */) { | |
| 2304 } | |
| 2305 | |
| 2277 // NOTE #1: On old versions of OpenGL, calling glBindXXX with an unused id | 2306 // NOTE #1: On old versions of OpenGL, calling glBindXXX with an unused id |
| 2278 // generates a new resource. On newer versions of OpenGL they don't. The code | 2307 // generates a new resource. On newer versions of OpenGL they don't. The code |
| 2279 // related to binding below will need to change if we switch to the new OpenGL | 2308 // related to binding below will need to change if we switch to the new OpenGL |
| 2280 // model. Specifically it assumes a bind will succeed which is always true in | 2309 // model. Specifically it assumes a bind will succeed which is always true in |
| 2281 // the old model but possibly not true in the new model if another context has | 2310 // the old model but possibly not true in the new model if another context has |
| 2282 // deleted the resource. | 2311 // deleted the resource. |
| 2283 | 2312 |
| 2284 bool GLES2Implementation::BindBufferHelper( | 2313 bool GLES2Implementation::BindBufferHelper( |
| 2285 GLenum target, GLuint buffer) { | 2314 GLenum target, GLuint buffer) { |
| 2286 // TODO(gman): See note #1 above. | 2315 // TODO(gman): See note #1 above. |
| 2287 bool changed = false; | 2316 bool changed = false; |
| 2288 switch (target) { | 2317 switch (target) { |
| 2289 case GL_ARRAY_BUFFER: | 2318 case GL_ARRAY_BUFFER: |
| 2290 if (bound_array_buffer_id_ != buffer) { | 2319 if (bound_array_buffer_id_ != buffer) { |
| 2291 bound_array_buffer_id_ = buffer; | 2320 bound_array_buffer_id_ = buffer; |
| 2292 changed = true; | 2321 changed = true; |
| 2293 } | 2322 } |
| 2294 break; | 2323 break; |
| 2295 case GL_ELEMENT_ARRAY_BUFFER: | 2324 case GL_ELEMENT_ARRAY_BUFFER: |
| 2296 changed = vertex_array_object_manager_->BindElementArray(buffer); | 2325 changed = vertex_array_object_manager_->BindElementArray(buffer); |
| 2297 break; | 2326 break; |
| 2298 case GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM: | 2327 case GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM: |
| 2299 bound_pixel_pack_transfer_buffer_id_ = buffer; | 2328 bound_pixel_pack_transfer_buffer_id_ = buffer; |
| 2300 break; | 2329 break; |
| 2301 case GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM: | 2330 case GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM: |
| 2302 bound_pixel_unpack_transfer_buffer_id_ = buffer; | 2331 bound_pixel_unpack_transfer_buffer_id_ = buffer; |
| 2303 break; | 2332 break; |
| 2333 case GL_IMAGE_BUFFER_CHROMIUM: | |
| 2334 bound_gpu_memory_buffer_id_ = buffer; | |
|
reveman
2013/05/03 22:45:00
The id returned from GenImageBuffers/GenImage is n
kaanb
2013/05/06 18:20:53
I was thinking I could just store the buffer_id an
| |
| 2335 break; | |
| 2304 default: | 2336 default: |
| 2305 changed = true; | 2337 changed = true; |
| 2306 break; | 2338 break; |
| 2307 } | 2339 } |
| 2308 // TODO(gman): There's a bug here. If the target is invalid the ID will not be | 2340 // TODO(gman): There's a bug here. If the target is invalid the ID will not be |
| 2309 // used even though it's marked it as used here. | 2341 // used even though it's marked it as used here. |
| 2310 GetIdHandler(id_namespaces::kBuffers)->MarkAsUsedForBind(buffer); | 2342 GetIdHandler(id_namespaces::kBuffers)->MarkAsUsedForBind(buffer); |
| 2311 return changed; | 2343 return changed; |
| 2312 } | 2344 } |
| 2313 | 2345 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2528 vertex_array_object_manager_->DeleteVertexArrays(n, arrays); | 2560 vertex_array_object_manager_->DeleteVertexArrays(n, arrays); |
| 2529 if (!GetIdHandler(id_namespaces::kVertexArrays)->FreeIds( | 2561 if (!GetIdHandler(id_namespaces::kVertexArrays)->FreeIds( |
| 2530 this, n, arrays, &GLES2Implementation::DeleteVertexArraysOESStub)) { | 2562 this, n, arrays, &GLES2Implementation::DeleteVertexArraysOESStub)) { |
| 2531 SetGLError( | 2563 SetGLError( |
| 2532 GL_INVALID_VALUE, | 2564 GL_INVALID_VALUE, |
| 2533 "glDeleteVertexArraysOES", "id not created by this context."); | 2565 "glDeleteVertexArraysOES", "id not created by this context."); |
| 2534 return; | 2566 return; |
| 2535 } | 2567 } |
| 2536 } | 2568 } |
| 2537 | 2569 |
| 2570 void GLES2Implementation::DeleteImageBuffersHelper( | |
| 2571 GLsizei n, const GLuint* imagebuffers) { | |
| 2572 if (!GetIdHandler(id_namespaces::kImageBuffers)->FreeIds( | |
| 2573 this, n, imagebuffers, &GLES2Implementation::DeleteImageBuffersStub)) { | |
| 2574 SetGLError( | |
| 2575 GL_INVALID_VALUE, | |
| 2576 "glDeleteImageBuffers", "id not created by this context."); | |
| 2577 return; | |
| 2578 } | |
| 2579 | |
| 2580 for (GLsizei ii = 0; ii < n; ++ii) { | |
| 2581 if (imagebuffers[ii] == bound_gpu_memory_buffer_id_) { | |
| 2582 bound_gpu_memory_buffer_id_ = 0; | |
| 2583 } | |
| 2584 | |
| 2585 GpuMemoryBuffer* gpu_buffer = | |
| 2586 gpu_memory_buffer_tracker_->GetBuffer(imagebuffers[ii]); | |
| 2587 if (gpu_buffer) { | |
| 2588 gpu_memory_buffer_tracker_->RemoveBuffer(imagebuffers[ii]); | |
| 2589 } | |
| 2590 } | |
| 2591 } | |
| 2592 | |
| 2593 void GLES2Implementation::DeleteImageBuffersStub( | |
| 2594 GLsizei n, const GLuint* imagebuffers) { | |
| 2595 helper_->DeleteImageBuffersImmediate(n, imagebuffers); | |
| 2596 } | |
| 2597 | |
| 2538 void GLES2Implementation::DeleteVertexArraysOESStub( | 2598 void GLES2Implementation::DeleteVertexArraysOESStub( |
| 2539 GLsizei n, const GLuint* arrays) { | 2599 GLsizei n, const GLuint* arrays) { |
| 2540 helper_->DeleteVertexArraysOESImmediate(n, arrays); | 2600 helper_->DeleteVertexArraysOESImmediate(n, arrays); |
| 2541 } | 2601 } |
| 2542 | 2602 |
| 2543 void GLES2Implementation::DeleteTexturesStub( | 2603 void GLES2Implementation::DeleteTexturesStub( |
| 2544 GLsizei n, const GLuint* textures) { | 2604 GLsizei n, const GLuint* textures) { |
| 2545 helper_->DeleteTexturesImmediate(n, textures); | 2605 helper_->DeleteTexturesImmediate(n, textures); |
| 2546 } | 2606 } |
| 2547 | 2607 |
| (...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3383 SetGLError(GL_INVALID_ENUM, "glMapBufferCHROMIUM", "bad access mode"); | 3443 SetGLError(GL_INVALID_ENUM, "glMapBufferCHROMIUM", "bad access mode"); |
| 3384 return NULL; | 3444 return NULL; |
| 3385 } | 3445 } |
| 3386 break; | 3446 break; |
| 3387 case GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM: | 3447 case GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM: |
| 3388 if (access != GL_WRITE_ONLY) { | 3448 if (access != GL_WRITE_ONLY) { |
| 3389 SetGLError(GL_INVALID_ENUM, "glMapBufferCHROMIUM", "bad access mode"); | 3449 SetGLError(GL_INVALID_ENUM, "glMapBufferCHROMIUM", "bad access mode"); |
| 3390 return NULL; | 3450 return NULL; |
| 3391 } | 3451 } |
| 3392 break; | 3452 break; |
| 3453 case GL_IMAGE_BUFFER_CHROMIUM: | |
| 3454 break; | |
| 3393 default: | 3455 default: |
| 3394 SetGLError( | 3456 SetGLError( |
| 3395 GL_INVALID_ENUM, "glMapBufferCHROMIUM", "invalid target"); | 3457 GL_INVALID_ENUM, "glMapBufferCHROMIUM", "invalid target"); |
| 3396 return NULL; | 3458 return NULL; |
| 3397 } | 3459 } |
| 3460 | |
| 3398 GLuint buffer_id; | 3461 GLuint buffer_id; |
| 3399 GetBoundPixelTransferBuffer(target, "glMapBufferCHROMIUM", &buffer_id); | 3462 switch(target) { |
| 3400 if (!buffer_id) { | 3463 case GL_IMAGE_BUFFER_CHROMIUM: { |
| 3401 return NULL; | 3464 GetBoundGpuMemoryBuffer("glMapBufferCHROMIUM", &buffer_id); |
| 3465 if (buffer_id == 0) { | |
| 3466 return NULL; | |
| 3467 } | |
| 3468 GpuMemoryBuffer* gpu_buffer = | |
| 3469 gpu_memory_buffer_tracker_->GetBuffer(buffer_id); | |
| 3470 if (!gpu_buffer) { | |
| 3471 SetGLError(GL_INVALID_OPERATION, "glMapBufferCHROMIUM", | |
| 3472 "invalid GPU memory buffer"); | |
| 3473 return NULL; | |
| 3474 } | |
| 3475 GpuMemoryBuffer::AccessMode mode = GpuMemoryBuffer::READ_ONLY; | |
| 3476 switch(access) { | |
| 3477 case GL_WRITE_ONLY: | |
| 3478 mode = GpuMemoryBuffer::WRITE_ONLY; | |
| 3479 break; | |
| 3480 case GL_READ_ONLY: | |
| 3481 mode = GpuMemoryBuffer::READ_ONLY; | |
| 3482 break; | |
| 3483 // TODO(kaanb): should we add GL_READ_WRITE to gl2ext.h? | |
| 3484 default: | |
| 3485 SetGLError( | |
| 3486 GL_INVALID_ENUM, "glMapBufferCHROMIUM", | |
| 3487 "invalid GPU access mode"); | |
| 3488 return NULL; | |
| 3489 } | |
| 3490 | |
| 3491 if (gpu_buffer->IsMapped()) { | |
| 3492 SetGLError(GL_INVALID_OPERATION, "glMapBufferCHROMIUM", | |
| 3493 "already mapped"); | |
| 3494 return NULL; | |
| 3495 } | |
| 3496 | |
| 3497 void* mapped_buffer = NULL; | |
| 3498 gpu_buffer->Map(mode, &mapped_buffer); | |
| 3499 CheckGLError(); | |
| 3500 return mapped_buffer; | |
| 3501 } | |
| 3502 case GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM: | |
| 3503 case GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM: { | |
| 3504 GetBoundPixelTransferBuffer(target, "glMapBufferCHROMIUM", &buffer_id); | |
| 3505 if (!buffer_id) { | |
| 3506 return NULL; | |
| 3507 } | |
| 3508 BufferTracker::Buffer* buffer = buffer_tracker_->GetBuffer(buffer_id); | |
| 3509 if (!buffer) { | |
| 3510 SetGLError(GL_INVALID_OPERATION, "glMapBufferCHROMIUM", | |
| 3511 "invalid buffer"); | |
| 3512 return NULL; | |
| 3513 } | |
| 3514 if (buffer->mapped()) { | |
| 3515 SetGLError(GL_INVALID_OPERATION, "glMapBufferCHROMIUM", | |
| 3516 "already mapped"); | |
| 3517 return NULL; | |
| 3518 } | |
| 3519 // Here we wait for previous transfer operations to be finished. | |
| 3520 // TODO(hubbe): AsyncTex(Sub)Image2dCHROMIUM does not currently work | |
| 3521 // with this method of synchronization. Until this is fixed, | |
| 3522 // MapBufferCHROMIUM will not block even if the transfer is not ready | |
| 3523 // for these calls. | |
| 3524 if (buffer->transfer_ready_token()) { | |
| 3525 helper_->WaitForToken(buffer->transfer_ready_token()); | |
| 3526 buffer->set_transfer_ready_token(0); | |
| 3527 } | |
| 3528 buffer->set_mapped(true); | |
| 3529 | |
| 3530 GPU_DCHECK(buffer->address()); | |
| 3531 GPU_CLIENT_LOG(" returned " << buffer->address()); | |
| 3532 CheckGLError(); | |
| 3533 return buffer->address(); | |
| 3534 } | |
| 3535 default: | |
| 3536 return NULL; | |
| 3402 } | 3537 } |
| 3403 BufferTracker::Buffer* buffer = buffer_tracker_->GetBuffer(buffer_id); | 3538 return NULL; |
| 3404 if (!buffer) { | |
| 3405 SetGLError(GL_INVALID_OPERATION, "glMapBufferCHROMIUM", "invalid buffer"); | |
| 3406 return NULL; | |
| 3407 } | |
| 3408 if (buffer->mapped()) { | |
| 3409 SetGLError(GL_INVALID_OPERATION, "glMapBufferCHROMIUM", "already mapped"); | |
| 3410 return NULL; | |
| 3411 } | |
| 3412 // Here we wait for previous transfer operations to be finished. | |
| 3413 // TODO(hubbe): AsyncTex(Sub)Image2dCHROMIUM does not currently work | |
| 3414 // with this method of synchronization. Until this is fixed, | |
| 3415 // MapBufferCHROMIUM will not block even if the transfer is not ready | |
| 3416 // for these calls. | |
| 3417 if (buffer->transfer_ready_token()) { | |
| 3418 helper_->WaitForToken(buffer->transfer_ready_token()); | |
| 3419 buffer->set_transfer_ready_token(0); | |
| 3420 } | |
| 3421 buffer->set_mapped(true); | |
| 3422 | |
| 3423 GPU_DCHECK(buffer->address()); | |
| 3424 GPU_CLIENT_LOG(" returned " << buffer->address()); | |
| 3425 CheckGLError(); | |
| 3426 return buffer->address(); | |
| 3427 } | 3539 } |
| 3428 | 3540 |
| 3429 GLboolean GLES2Implementation::UnmapBufferCHROMIUM(GLuint target) { | 3541 GLboolean GLES2Implementation::UnmapBufferCHROMIUM(GLuint target) { |
| 3430 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 3542 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 3431 GPU_CLIENT_LOG( | 3543 GPU_CLIENT_LOG( |
| 3432 "[" << GetLogPrefix() << "] glUnmapBufferCHROMIUM(" << target << ")"); | 3544 "[" << GetLogPrefix() << "] glUnmapBufferCHROMIUM(" << target << ")"); |
| 3433 GLuint buffer_id; | 3545 GLuint buffer_id; |
| 3434 if (!GetBoundPixelTransferBuffer(target, "glMapBufferCHROMIUM", &buffer_id)) { | 3546 switch(target) { |
| 3435 SetGLError(GL_INVALID_ENUM, "glUnmapBufferCHROMIUM", "invalid target"); | 3547 case GL_IMAGE_BUFFER_CHROMIUM: { |
| 3548 GetBoundGpuMemoryBuffer("glUnmapBufferCHROMIUM", &buffer_id); | |
| 3549 if (buffer_id == 0) { | |
| 3550 break; | |
| 3551 } | |
| 3552 GpuMemoryBuffer* gpu_buffer = | |
| 3553 gpu_memory_buffer_tracker_->GetBuffer(buffer_id); | |
| 3554 | |
| 3555 if (!gpu_buffer->IsMapped()) { | |
| 3556 SetGLError(GL_INVALID_OPERATION, "glUnmapBufferCHROMIUM", "not mapped"); | |
| 3557 break; | |
| 3558 } | |
| 3559 gpu_buffer->Unmap(); | |
| 3560 return true; | |
| 3561 } | |
| 3562 case GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM: | |
| 3563 case GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM: { | |
| 3564 if (!GetBoundPixelTransferBuffer(target, "glMapBufferCHROMIUM", | |
| 3565 &buffer_id)) { | |
| 3566 SetGLError(GL_INVALID_ENUM, "glUnmapBufferCHROMIUM", "invalid target"); | |
| 3567 break; | |
| 3568 } | |
| 3569 if (!buffer_id) { | |
| 3570 break; | |
| 3571 } | |
| 3572 BufferTracker::Buffer* buffer = buffer_tracker_->GetBuffer(buffer_id); | |
| 3573 if (!buffer) { | |
| 3574 SetGLError(GL_INVALID_OPERATION, "glUnmapBufferCHROMIUM", | |
| 3575 "invalid buffer"); | |
| 3576 break; | |
| 3577 } | |
| 3578 if (!buffer->mapped()) { | |
| 3579 SetGLError(GL_INVALID_OPERATION, "glUnmapBufferCHROMIUM", "not mapped"); | |
| 3580 break; | |
| 3581 } | |
| 3582 buffer->set_mapped(false); | |
| 3583 return true; | |
| 3584 } | |
| 3585 default: | |
| 3586 SetGLError(GL_INVALID_ENUM, "glUnmapBufferCHROMIUM", "invalid target"); | |
| 3436 } | 3587 } |
| 3437 if (!buffer_id) { | |
| 3438 return false; | |
| 3439 } | |
| 3440 BufferTracker::Buffer* buffer = buffer_tracker_->GetBuffer(buffer_id); | |
| 3441 if (!buffer) { | |
| 3442 SetGLError(GL_INVALID_OPERATION, "glMapBufferCHROMIUM", "invalid buffer"); | |
| 3443 return false; | |
| 3444 } | |
| 3445 if (!buffer->mapped()) { | |
| 3446 SetGLError(GL_INVALID_OPERATION, "glMapBufferCHROMIUM", "not mapped"); | |
| 3447 return false; | |
| 3448 } | |
| 3449 buffer->set_mapped(false); | |
| 3450 CheckGLError(); | 3588 CheckGLError(); |
| 3451 return true; | 3589 return false; |
| 3452 } | 3590 } |
| 3453 | 3591 |
| 3454 void GLES2Implementation::AsyncTexImage2DCHROMIUM( | 3592 void GLES2Implementation::AsyncTexImage2DCHROMIUM( |
| 3455 GLenum target, GLint level, GLint internalformat, GLsizei width, | 3593 GLenum target, GLint level, GLint internalformat, GLsizei width, |
| 3456 GLsizei height, GLint border, GLenum format, GLenum type, | 3594 GLsizei height, GLint border, GLenum format, GLenum type, |
| 3457 const void* pixels) { | 3595 const void* pixels) { |
| 3458 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 3596 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 3459 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glTexImage2D(" | 3597 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glTexImage2D(" |
| 3460 << GLES2Util::GetStringTextureTarget(target) << ", " | 3598 << GLES2Util::GetStringTextureTarget(target) << ", " |
| 3461 << level << ", " | 3599 << level << ", " |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3556 helper_->WaitAsyncTexImage2DCHROMIUM(target); | 3694 helper_->WaitAsyncTexImage2DCHROMIUM(target); |
| 3557 CheckGLError(); | 3695 CheckGLError(); |
| 3558 } | 3696 } |
| 3559 | 3697 |
| 3560 GLuint GLES2Implementation::InsertSyncPointCHROMIUM() { | 3698 GLuint GLES2Implementation::InsertSyncPointCHROMIUM() { |
| 3561 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 3699 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 3562 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glInsertSyncPointCHROMIUM"); | 3700 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glInsertSyncPointCHROMIUM"); |
| 3563 return helper_->InsertSyncPointCHROMIUM(); | 3701 return helper_->InsertSyncPointCHROMIUM(); |
| 3564 } | 3702 } |
| 3565 | 3703 |
| 3704 void GLES2Implementation::CreateGpuMemoryBuffer2DCHROMIUMHelper( | |
| 3705 GLuint image_id, GLint width, GLint height) { | |
| 3706 if (width < 0) { | |
| 3707 SetGLError(GL_INVALID_VALUE, "glCreateGpuMemoryBuffer2DCHROMIUM", | |
| 3708 "width < 0"); | |
| 3709 return; | |
| 3710 } | |
| 3711 | |
| 3712 if (height < 0) { | |
| 3713 SetGLError(GL_INVALID_VALUE, "glCreateGpuMemoryBuffer2DCHROMIUM", | |
| 3714 "height < 0"); | |
| 3715 return; | |
| 3716 } | |
| 3717 | |
| 3718 if (gpu_memory_buffer_tracker_->GetBuffer(image_id) != NULL) { | |
| 3719 SetGLError(GL_INVALID_VALUE, "glCreateGpuMemoryBuffer2DCHROMIUM", | |
| 3720 "existing image_id"); | |
| 3721 return; | |
| 3722 } | |
| 3723 | |
| 3724 if (width != 0 && height != 0) { | |
| 3725 // Create new buffer. | |
| 3726 gpu_memory_buffer_tracker_->CreateBuffer(image_id, width, height); | |
| 3727 } | |
| 3728 } | |
| 3729 | |
| 3730 void GLES2Implementation::CreateGpuMemoryBuffer2DCHROMIUM( | |
| 3731 GLuint image_id, GLint width, GLint height) { | |
| 3732 GPU_CLIENT_SINGLE_THREAD_CHECK(); | |
| 3733 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glCreateGpuMemoryBuffer2DCHROMIUM(" | |
| 3734 << image_id << ", " | |
| 3735 << width << ", " | |
| 3736 << height << ")"); | |
| 3737 CreateGpuMemoryBuffer2DCHROMIUMHelper(image_id, width, height); | |
| 3738 CheckGLError(); | |
| 3739 } | |
| 3740 | |
| 3566 // Include the auto-generated part of this file. We split this because it means | 3741 // Include the auto-generated part of this file. We split this because it means |
| 3567 // we can easily edit the non-auto generated parts right here in this file | 3742 // we can easily edit the non-auto generated parts right here in this file |
| 3568 // instead of having to edit some template or the code generator. | 3743 // instead of having to edit some template or the code generator. |
| 3569 #include "../client/gles2_implementation_impl_autogen.h" | 3744 #include "../client/gles2_implementation_impl_autogen.h" |
| 3570 | 3745 |
| 3571 } // namespace gles2 | 3746 } // namespace gles2 |
| 3572 } // namespace gpu | 3747 } // namespace gpu |
| OLD | NEW |