OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> |
| 10 #include <queue> |
9 #include <GLES2/gl2ext.h> | 11 #include <GLES2/gl2ext.h> |
10 #include <GLES2/gles2_command_buffer.h> | 12 #include <GLES2/gles2_command_buffer.h> |
11 #include "../client/mapped_memory.h" | 13 #include "../client/mapped_memory.h" |
| 14 #include "../client/program_info_manager.h" |
12 #include "../common/gles2_cmd_utils.h" | 15 #include "../common/gles2_cmd_utils.h" |
13 #include "../common/id_allocator.h" | 16 #include "../common/id_allocator.h" |
14 #include "../common/trace_event.h" | 17 #include "../common/trace_event.h" |
15 | 18 |
16 #if defined(__native_client__) && !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) | 19 #if defined(__native_client__) && !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) |
17 #define GLES2_SUPPORT_CLIENT_SIDE_ARRAYS | 20 #define GLES2_SUPPORT_CLIENT_SIDE_ARRAYS |
18 #endif | 21 #endif |
19 | 22 |
20 #if defined(GPU_CLIENT_DEBUG) | 23 #if defined(GPU_CLIENT_DEBUG) |
21 #include "ui/gfx/gl/gl_switches.h" | 24 #include "ui/gfx/gl/gl_switches.h" |
(...skipping 22 matching lines...) Expand all Loading... |
44 } | 47 } |
45 } else { | 48 } else { |
46 for (GLsizei ii = 0; ii < n; ++ii) { | 49 for (GLsizei ii = 0; ii < n; ++ii) { |
47 ids[ii] = id_allocator_.AllocateIDAtOrAbove(id_offset); | 50 ids[ii] = id_allocator_.AllocateIDAtOrAbove(id_offset); |
48 id_offset = ids[ii] + 1; | 51 id_offset = ids[ii] + 1; |
49 } | 52 } |
50 } | 53 } |
51 } | 54 } |
52 | 55 |
53 // Overridden from IdHandlerInterface. | 56 // Overridden from IdHandlerInterface. |
54 virtual void FreeIds(GLsizei n, const GLuint* ids) { | 57 virtual bool FreeIds(GLsizei n, const GLuint* ids) { |
55 for (GLsizei ii = 0; ii < n; ++ii) { | 58 for (GLsizei ii = 0; ii < n; ++ii) { |
56 id_allocator_.FreeID(ids[ii]); | 59 id_allocator_.FreeID(ids[ii]); |
57 } | 60 } |
| 61 return true; |
58 } | 62 } |
59 | 63 |
60 // Overridden from IdHandlerInterface. | 64 // Overridden from IdHandlerInterface. |
61 virtual bool MarkAsUsedForBind(GLuint id) { | 65 virtual bool MarkAsUsedForBind(GLuint id) { |
62 return id == 0 ? true : id_allocator_.MarkAsUsed(id); | 66 return id == 0 ? true : id_allocator_.MarkAsUsed(id); |
63 } | 67 } |
64 private: | 68 private: |
65 IdAllocator id_allocator_; | 69 IdAllocator id_allocator_; |
66 }; | 70 }; |
67 | 71 |
68 // An id handler for non-shared ids that are never reused. | 72 // An id handler for non-shared ids that are never reused. |
69 class NonSharedNonReusedIdHandler : public IdHandlerInterface { | 73 class NonSharedNonReusedIdHandler : public IdHandlerInterface { |
70 public: | 74 public: |
71 NonSharedNonReusedIdHandler() : last_id_(0) { } | 75 NonSharedNonReusedIdHandler() : last_id_(0) { } |
72 virtual ~NonSharedNonReusedIdHandler() { } | 76 virtual ~NonSharedNonReusedIdHandler() { } |
73 | 77 |
74 // Overridden from IdHandlerInterface. | 78 // Overridden from IdHandlerInterface. |
75 virtual void MakeIds(GLuint id_offset, GLsizei n, GLuint* ids) { | 79 virtual void MakeIds(GLuint id_offset, GLsizei n, GLuint* ids) { |
76 for (GLsizei ii = 0; ii < n; ++ii) { | 80 for (GLsizei ii = 0; ii < n; ++ii) { |
77 ids[ii] = ++last_id_ + id_offset; | 81 ids[ii] = ++last_id_ + id_offset; |
78 } | 82 } |
79 } | 83 } |
80 | 84 |
81 // Overridden from IdHandlerInterface. | 85 // Overridden from IdHandlerInterface. |
82 virtual void FreeIds(GLsizei /* n */, const GLuint* /* ids */) { | 86 virtual bool FreeIds(GLsizei /* n */, const GLuint* /* ids */) { |
83 // Ids are never freed. | 87 // Ids are never freed. |
| 88 return true; |
84 } | 89 } |
85 | 90 |
86 // Overridden from IdHandlerInterface. | 91 // Overridden from IdHandlerInterface. |
87 virtual bool MarkAsUsedForBind(GLuint /* id */) { | 92 virtual bool MarkAsUsedForBind(GLuint /* id */) { |
88 // This is only used for Shaders and Programs which have no bind. | 93 // This is only used for Shaders and Programs which have no bind. |
89 return false; | 94 return false; |
90 } | 95 } |
91 | 96 |
92 private: | 97 private: |
93 GLuint last_id_; | 98 GLuint last_id_; |
94 }; | 99 }; |
95 | 100 |
96 // An id handler for shared ids. | 101 // An id handler for shared ids. |
97 class SharedIdHandler : public IdHandlerInterface { | 102 class SharedIdHandler : public IdHandlerInterface { |
98 public: | 103 public: |
99 SharedIdHandler( | 104 SharedIdHandler( |
100 GLES2Implementation* gles2, | 105 GLES2Implementation* gles2, |
101 id_namespaces::IdNamespaces id_namespace) | 106 id_namespaces::IdNamespaces id_namespace) |
102 : gles2_(gles2), | 107 : gles2_(gles2), |
103 id_namespace_(id_namespace) { | 108 id_namespace_(id_namespace) { |
104 } | 109 } |
105 | 110 |
106 virtual ~SharedIdHandler() { } | 111 virtual ~SharedIdHandler() { } |
107 | 112 |
108 virtual void MakeIds(GLuint id_offset, GLsizei n, GLuint* ids) { | 113 virtual void MakeIds(GLuint id_offset, GLsizei n, GLuint* ids) { |
109 gles2_->GenSharedIdsCHROMIUM(id_namespace_, id_offset, n, ids); | 114 gles2_->GenSharedIdsCHROMIUM(id_namespace_, id_offset, n, ids); |
110 } | 115 } |
111 | 116 |
112 virtual void FreeIds(GLsizei n, const GLuint* ids) { | 117 virtual bool FreeIds(GLsizei n, const GLuint* ids) { |
113 gles2_->DeleteSharedIdsCHROMIUM(id_namespace_, n, ids); | 118 gles2_->DeleteSharedIdsCHROMIUM(id_namespace_, n, ids); |
| 119 return true; |
114 } | 120 } |
115 | 121 |
116 virtual bool MarkAsUsedForBind(GLuint) { // NOLINT | 122 virtual bool MarkAsUsedForBind(GLuint /* id */) { |
117 // This has no meaning for shared resources. | 123 // This has no meaning for shared resources. |
118 return true; | 124 return true; |
119 } | 125 } |
120 | 126 |
121 private: | 127 private: |
122 GLES2Implementation* gles2_; | 128 GLES2Implementation* gles2_; |
123 id_namespaces::IdNamespaces id_namespace_; | 129 id_namespaces::IdNamespaces id_namespace_; |
124 }; | 130 }; |
125 | 131 |
| 132 // An id handler for shared ids that requires ids are made before using and |
| 133 // that only the context that created the id can delete it. |
| 134 // Assumes the service will enforce that non made ids generate an error. |
| 135 class StrictSharedIdHandler : public IdHandlerInterface { |
| 136 public: |
| 137 StrictSharedIdHandler( |
| 138 GLES2Implementation* gles2, |
| 139 id_namespaces::IdNamespaces id_namespace) |
| 140 : gles2_(gles2), |
| 141 id_namespace_(id_namespace) { |
| 142 } |
| 143 |
| 144 virtual ~StrictSharedIdHandler() { } |
| 145 |
| 146 virtual void MakeIds(GLuint id_offset, GLsizei n, GLuint* ids) { |
| 147 for (GLsizei ii = 0; ii < n; ++ii) { |
| 148 ids[ii] = GetId(id_offset); |
| 149 } |
| 150 } |
| 151 |
| 152 virtual bool FreeIds(GLsizei n, const GLuint* ids) { |
| 153 // OpenGL sematics. If any id is bad none of them get freed. |
| 154 for (GLsizei ii = 0; ii < n; ++ii) { |
| 155 GLuint id = ids[ii]; |
| 156 if (id != 0) { |
| 157 ResourceIdSet::iterator it = used_ids_.find(id); |
| 158 if (it == used_ids_.end()) { |
| 159 return false; |
| 160 } |
| 161 } |
| 162 } |
| 163 for (GLsizei ii = 0; ii < n; ++ii) { |
| 164 GLuint id = ids[ii]; |
| 165 if (id != 0) { |
| 166 ResourceIdSet::iterator it = used_ids_.find(id); |
| 167 if (it != used_ids_.end()) { |
| 168 used_ids_.erase(it); |
| 169 free_ids_.push(id); |
| 170 } |
| 171 } |
| 172 } |
| 173 return true; |
| 174 } |
| 175 |
| 176 virtual bool MarkAsUsedForBind(GLuint /* id */) { |
| 177 // This has no meaning for shared resources. |
| 178 return true; |
| 179 } |
| 180 |
| 181 private: |
| 182 static const GLsizei kNumIdsToGet = 2048; |
| 183 typedef std::queue<GLuint> ResourceIdQueue; |
| 184 typedef std::set<GLuint> ResourceIdSet; |
| 185 |
| 186 GLuint GetId(GLuint id_offset) { |
| 187 if (free_ids_.empty()) { |
| 188 GLuint ids[kNumIdsToGet]; |
| 189 gles2_->GenSharedIdsCHROMIUM(id_namespace_, id_offset, kNumIdsToGet, ids); |
| 190 for (GLsizei ii = 0; ii < kNumIdsToGet; ++ii) { |
| 191 free_ids_.push(ids[ii]); |
| 192 } |
| 193 } |
| 194 GLuint id = free_ids_.front(); |
| 195 free_ids_.pop(); |
| 196 used_ids_.insert(id); |
| 197 return id; |
| 198 } |
| 199 |
| 200 bool FreeId(GLuint id) { |
| 201 ResourceIdSet::iterator it = used_ids_.find(id); |
| 202 if (it == used_ids_.end()) { |
| 203 return false; |
| 204 } |
| 205 used_ids_.erase(it); |
| 206 free_ids_.push(id); |
| 207 return true; |
| 208 } |
| 209 |
| 210 GLES2Implementation* gles2_; |
| 211 id_namespaces::IdNamespaces id_namespace_; |
| 212 ResourceIdSet used_ids_; |
| 213 ResourceIdQueue free_ids_; |
| 214 }; |
| 215 |
| 216 #ifndef _MSC_VER |
| 217 const GLsizei StrictSharedIdHandler::kNumIdsToGet; |
| 218 #endif |
| 219 |
126 static GLsizei RoundUpToMultipleOf4(GLsizei size) { | 220 static GLsizei RoundUpToMultipleOf4(GLsizei size) { |
127 return (size + 3) & ~3; | 221 return (size + 3) & ~3; |
128 } | 222 } |
129 | 223 |
130 // This class tracks VertexAttribPointers and helps emulate client side buffers. | 224 // This class tracks VertexAttribPointers and helps emulate client side buffers. |
131 // | 225 // |
132 // The way client side buffers work is we shadow all the Vertex Attribs so we | 226 // The way client side buffers work is we shadow all the Vertex Attribs so we |
133 // know which ones are pointing to client side buffers. | 227 // know which ones are pointing to client side buffers. |
134 // | 228 // |
135 // At Draw time, for any attribs pointing to client side buffers we copy them | 229 // At Draw time, for any attribs pointing to client side buffers we copy them |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 #endif | 522 #endif |
429 | 523 |
430 COMPILE_ASSERT(gpu::kInvalidResource == 0, | 524 COMPILE_ASSERT(gpu::kInvalidResource == 0, |
431 INVALID_RESOURCE_NOT_0_AS_GL_EXPECTS); | 525 INVALID_RESOURCE_NOT_0_AS_GL_EXPECTS); |
432 | 526 |
433 GLES2Implementation::GLES2Implementation( | 527 GLES2Implementation::GLES2Implementation( |
434 GLES2CmdHelper* helper, | 528 GLES2CmdHelper* helper, |
435 size_t transfer_buffer_size, | 529 size_t transfer_buffer_size, |
436 void* transfer_buffer, | 530 void* transfer_buffer, |
437 int32 transfer_buffer_id, | 531 int32 transfer_buffer_id, |
438 bool share_resources) | 532 bool share_resources, |
| 533 bool bind_generates_resource) |
439 : helper_(helper), | 534 : helper_(helper), |
440 transfer_buffer_( | 535 transfer_buffer_( |
441 kStartingOffset, | 536 kStartingOffset, |
442 transfer_buffer_size - kStartingOffset, | 537 transfer_buffer_size - kStartingOffset, |
443 helper, | 538 helper, |
444 static_cast<char*>(transfer_buffer) + kStartingOffset), | 539 static_cast<char*>(transfer_buffer) + kStartingOffset), |
445 transfer_buffer_id_(transfer_buffer_id), | 540 transfer_buffer_id_(transfer_buffer_id), |
446 pack_alignment_(4), | 541 pack_alignment_(4), |
447 unpack_alignment_(4), | 542 unpack_alignment_(4), |
448 unpack_flip_y_(false), | 543 unpack_flip_y_(false), |
449 active_texture_unit_(0), | 544 active_texture_unit_(0), |
450 bound_framebuffer_(0), | 545 bound_framebuffer_(0), |
451 bound_renderbuffer_(0), | 546 bound_renderbuffer_(0), |
452 bound_array_buffer_id_(0), | 547 bound_array_buffer_id_(0), |
453 bound_element_array_buffer_id_(0), | 548 bound_element_array_buffer_id_(0), |
454 client_side_array_id_(0), | 549 client_side_array_id_(0), |
455 client_side_element_array_id_(0), | 550 client_side_element_array_id_(0), |
456 error_bits_(0), | 551 error_bits_(0), |
457 debug_(false), | 552 debug_(false), |
458 sharing_resources_(share_resources) { | 553 sharing_resources_(share_resources), |
| 554 bind_generates_resource_(bind_generates_resource) { |
459 GPU_CLIENT_LOG_CODE_BLOCK({ | 555 GPU_CLIENT_LOG_CODE_BLOCK({ |
460 debug_ = CommandLine::ForCurrentProcess()->HasSwitch( | 556 debug_ = CommandLine::ForCurrentProcess()->HasSwitch( |
461 switches::kEnableGPUClientLogging); | 557 switches::kEnableGPUClientLogging); |
462 }); | 558 }); |
463 | 559 |
464 // Allocate space for simple GL results. | 560 // Allocate space for simple GL results. |
465 result_buffer_ = transfer_buffer; | 561 result_buffer_ = transfer_buffer; |
466 result_shm_offset_ = 0; | 562 result_shm_offset_ = 0; |
467 memset(&reserved_ids_, 0, sizeof(reserved_ids_)); | 563 memset(&reserved_ids_, 0, sizeof(reserved_ids_)); |
468 | 564 |
469 mapped_memory_.reset(new MappedMemoryManager(helper_)); | 565 mapped_memory_.reset(new MappedMemoryManager(helper_)); |
470 | 566 |
471 if (share_resources) { | 567 if (share_resources) { |
472 buffer_id_handler_.reset( | 568 if (!bind_generates_resource) { |
473 new SharedIdHandler(this, id_namespaces::kBuffers)); | 569 buffer_id_handler_.reset( |
474 framebuffer_id_handler_.reset( | 570 new StrictSharedIdHandler(this, id_namespaces::kBuffers)); |
475 new SharedIdHandler(this, id_namespaces::kFramebuffers)); | 571 framebuffer_id_handler_.reset( |
476 renderbuffer_id_handler_.reset( | 572 new StrictSharedIdHandler(this, id_namespaces::kFramebuffers)); |
477 new SharedIdHandler(this, id_namespaces::kRenderbuffers)); | 573 renderbuffer_id_handler_.reset( |
478 program_and_shader_id_handler_.reset( | 574 new StrictSharedIdHandler(this, id_namespaces::kRenderbuffers)); |
479 new SharedIdHandler(this, id_namespaces::kProgramsAndShaders)); | 575 program_and_shader_id_handler_.reset( |
480 texture_id_handler_.reset( | 576 new StrictSharedIdHandler(this, id_namespaces::kProgramsAndShaders)); |
481 new SharedIdHandler(this, id_namespaces::kTextures)); | 577 texture_id_handler_.reset( |
| 578 new StrictSharedIdHandler(this, id_namespaces::kTextures)); |
| 579 } else { |
| 580 buffer_id_handler_.reset( |
| 581 new SharedIdHandler(this, id_namespaces::kBuffers)); |
| 582 framebuffer_id_handler_.reset( |
| 583 new SharedIdHandler(this, id_namespaces::kFramebuffers)); |
| 584 renderbuffer_id_handler_.reset( |
| 585 new SharedIdHandler(this, id_namespaces::kRenderbuffers)); |
| 586 program_and_shader_id_handler_.reset( |
| 587 new SharedIdHandler(this, id_namespaces::kProgramsAndShaders)); |
| 588 texture_id_handler_.reset( |
| 589 new SharedIdHandler(this, id_namespaces::kTextures)); |
| 590 } |
482 } else { | 591 } else { |
483 buffer_id_handler_.reset(new NonSharedIdHandler()); | 592 buffer_id_handler_.reset(new NonSharedIdHandler()); |
484 framebuffer_id_handler_.reset(new NonSharedIdHandler()); | 593 framebuffer_id_handler_.reset(new NonSharedIdHandler()); |
485 renderbuffer_id_handler_.reset(new NonSharedIdHandler()); | 594 renderbuffer_id_handler_.reset(new NonSharedIdHandler()); |
486 program_and_shader_id_handler_.reset(new NonSharedNonReusedIdHandler()); | 595 program_and_shader_id_handler_.reset(new NonSharedNonReusedIdHandler()); |
487 texture_id_handler_.reset(new NonSharedIdHandler()); | 596 texture_id_handler_.reset(new NonSharedIdHandler()); |
488 } | 597 } |
489 | 598 |
490 static const GLenum pnames[] = { | 599 static const GLenum pnames[] = { |
491 GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, | 600 GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, |
(...skipping 15 matching lines...) Expand all Loading... |
507 util_.set_num_shader_binary_formats( | 616 util_.set_num_shader_binary_formats( |
508 gl_state_.num_shader_binary_formats); | 617 gl_state_.num_shader_binary_formats); |
509 | 618 |
510 GetMultipleIntegervCHROMIUM( | 619 GetMultipleIntegervCHROMIUM( |
511 pnames, arraysize(pnames), &gl_state_.max_combined_texture_image_units, | 620 pnames, arraysize(pnames), &gl_state_.max_combined_texture_image_units, |
512 sizeof(gl_state_)); | 621 sizeof(gl_state_)); |
513 | 622 |
514 texture_units_.reset( | 623 texture_units_.reset( |
515 new TextureUnit[gl_state_.max_combined_texture_image_units]); | 624 new TextureUnit[gl_state_.max_combined_texture_image_units]); |
516 | 625 |
| 626 program_info_manager_.reset(ProgramInfoManager::Create(sharing_resources_)); |
| 627 |
517 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) | 628 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) |
518 buffer_id_handler_->MakeIds( | 629 buffer_id_handler_->MakeIds( |
519 kClientSideArrayId, arraysize(reserved_ids_), &reserved_ids_[0]); | 630 kClientSideArrayId, arraysize(reserved_ids_), &reserved_ids_[0]); |
520 | 631 |
521 client_side_buffer_helper_.reset(new ClientSideBufferHelper( | 632 client_side_buffer_helper_.reset(new ClientSideBufferHelper( |
522 gl_state_.max_vertex_attribs, | 633 gl_state_.max_vertex_attribs, |
523 reserved_ids_[0], | 634 reserved_ids_[0], |
524 reserved_ids_[1])); | 635 reserved_ids_[1])); |
525 #endif | 636 #endif |
526 } | 637 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 case GL_MAX_VERTEX_UNIFORM_VECTORS: | 806 case GL_MAX_VERTEX_UNIFORM_VECTORS: |
696 *params = gl_state_.max_vertex_uniform_vectors; | 807 *params = gl_state_.max_vertex_uniform_vectors; |
697 return true; | 808 return true; |
698 case GL_NUM_COMPRESSED_TEXTURE_FORMATS: | 809 case GL_NUM_COMPRESSED_TEXTURE_FORMATS: |
699 *params = gl_state_.num_compressed_texture_formats; | 810 *params = gl_state_.num_compressed_texture_formats; |
700 return true; | 811 return true; |
701 case GL_NUM_SHADER_BINARY_FORMATS: | 812 case GL_NUM_SHADER_BINARY_FORMATS: |
702 *params = gl_state_.num_shader_binary_formats; | 813 *params = gl_state_.num_shader_binary_formats; |
703 return true; | 814 return true; |
704 case GL_ARRAY_BUFFER_BINDING: | 815 case GL_ARRAY_BUFFER_BINDING: |
705 *params = bound_array_buffer_id_; | 816 if (bind_generates_resource_) { |
706 return true; | 817 *params = bound_array_buffer_id_; |
| 818 return true; |
| 819 } |
| 820 return false; |
707 case GL_ELEMENT_ARRAY_BUFFER_BINDING: | 821 case GL_ELEMENT_ARRAY_BUFFER_BINDING: |
708 *params = bound_element_array_buffer_id_; | 822 if (bind_generates_resource_) { |
709 return true; | 823 *params = bound_element_array_buffer_id_; |
| 824 return true; |
| 825 } |
| 826 return false; |
710 case GL_ACTIVE_TEXTURE: | 827 case GL_ACTIVE_TEXTURE: |
711 *params = active_texture_unit_ + GL_TEXTURE0; | 828 *params = active_texture_unit_ + GL_TEXTURE0; |
712 return true; | 829 return true; |
713 case GL_TEXTURE_BINDING_2D: | 830 case GL_TEXTURE_BINDING_2D: |
714 *params = texture_units_[active_texture_unit_].bound_texture_2d; | 831 if (bind_generates_resource_) { |
715 return true; | 832 *params = texture_units_[active_texture_unit_].bound_texture_2d; |
| 833 return true; |
| 834 } |
| 835 return false; |
716 case GL_TEXTURE_BINDING_CUBE_MAP: | 836 case GL_TEXTURE_BINDING_CUBE_MAP: |
717 *params = texture_units_[active_texture_unit_].bound_texture_cube_map; | 837 if (bind_generates_resource_) { |
718 return true; | 838 *params = texture_units_[active_texture_unit_].bound_texture_cube_map; |
| 839 return true; |
| 840 } |
| 841 return false; |
719 case GL_FRAMEBUFFER_BINDING: | 842 case GL_FRAMEBUFFER_BINDING: |
720 *params = bound_framebuffer_; | 843 if (bind_generates_resource_) { |
721 return true; | 844 *params = bound_framebuffer_; |
| 845 return true; |
| 846 } |
| 847 return false; |
722 case GL_RENDERBUFFER_BINDING: | 848 case GL_RENDERBUFFER_BINDING: |
723 *params = bound_renderbuffer_; | 849 if (bind_generates_resource_) { |
724 return true; | 850 *params = bound_renderbuffer_; |
| 851 return true; |
| 852 } |
| 853 return false; |
725 default: | 854 default: |
726 return false; | 855 return false; |
727 } | 856 } |
728 } | 857 } |
729 | 858 |
730 bool GLES2Implementation::GetBooleanvHelper(GLenum pname, GLboolean* params) { | 859 bool GLES2Implementation::GetBooleanvHelper(GLenum pname, GLboolean* params) { |
731 // TODO(gman): Make this handle pnames that return more than 1 value. | 860 // TODO(gman): Make this handle pnames that return more than 1 value. |
732 GLint value; | 861 GLint value; |
733 if (!GetHelper(pname, &value)) { | 862 if (!GetHelper(pname, &value)) { |
734 return false; | 863 return false; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 GLuint namespace_id, GLuint id_offset, GLsizei n, GLuint* ids) { | 976 GLuint namespace_id, GLuint id_offset, GLsizei n, GLuint* ids) { |
848 GPU_CLIENT_LOG("[" << this << "] glGenSharedIdsCHROMIUMTextures(" | 977 GPU_CLIENT_LOG("[" << this << "] glGenSharedIdsCHROMIUMTextures(" |
849 << namespace_id << ", " << id_offset << ", " << n << ", " << | 978 << namespace_id << ", " << id_offset << ", " << n << ", " << |
850 static_cast<void*>(ids) << ")"); | 979 static_cast<void*>(ids) << ")"); |
851 GPU_CLIENT_LOG_CODE_BLOCK({ | 980 GPU_CLIENT_LOG_CODE_BLOCK({ |
852 for (GLsizei i = 0; i < n; ++i) { | 981 for (GLsizei i = 0; i < n; ++i) { |
853 GPU_CLIENT_LOG(" " << i << ": " << ids[i]); | 982 GPU_CLIENT_LOG(" " << i << ": " << ids[i]); |
854 } | 983 } |
855 }); | 984 }); |
856 TRACE_EVENT0("gpu", "GLES2::GenSharedIdsCHROMIUM"); | 985 TRACE_EVENT0("gpu", "GLES2::GenSharedIdsCHROMIUM"); |
857 GLint* id_buffer = transfer_buffer_.AllocTyped<GLint>(n); | 986 GLsizei max_size = transfer_buffer_.GetLargestFreeOrPendingSize(); |
858 helper_->GenSharedIdsCHROMIUM(namespace_id, id_offset, n, | 987 GLsizei max_num_per = max_size / sizeof(ids[0]); |
859 transfer_buffer_id_, | 988 while (n) { |
860 transfer_buffer_.GetOffset(id_buffer)); | 989 GLsizei num = std::min(n, max_num_per); |
861 WaitForCmd(); | 990 GLint* id_buffer = transfer_buffer_.AllocTyped<GLint>(num); |
862 memcpy(ids, id_buffer, sizeof(*ids) * n); | 991 helper_->GenSharedIdsCHROMIUM( |
863 transfer_buffer_.FreePendingToken(id_buffer, helper_->InsertToken()); | 992 namespace_id, id_offset, num, |
| 993 transfer_buffer_id_, |
| 994 transfer_buffer_.GetOffset(id_buffer)); |
| 995 WaitForCmd(); |
| 996 memcpy(ids, id_buffer, sizeof(*ids) * num); |
| 997 transfer_buffer_.FreePendingToken(id_buffer, helper_->InsertToken()); |
| 998 n -= num; |
| 999 ids += num; |
| 1000 } |
864 } | 1001 } |
865 | 1002 |
866 void GLES2Implementation::DeleteSharedIdsCHROMIUM( | 1003 void GLES2Implementation::DeleteSharedIdsCHROMIUM( |
867 GLuint namespace_id, GLsizei n, const GLuint* ids) { | 1004 GLuint namespace_id, GLsizei n, const GLuint* ids) { |
868 GPU_CLIENT_LOG("[" << this << "] glDeleteSharedIdsCHROMIUM(" | 1005 GPU_CLIENT_LOG("[" << this << "] glDeleteSharedIdsCHROMIUM(" |
869 << namespace_id << ", " << n << ", " | 1006 << namespace_id << ", " << n << ", " |
870 << static_cast<const void*>(ids) << ")"); | 1007 << static_cast<const void*>(ids) << ")"); |
871 GPU_CLIENT_LOG_CODE_BLOCK({ | 1008 GPU_CLIENT_LOG_CODE_BLOCK({ |
872 for (GLsizei i = 0; i < n; ++i) { | 1009 for (GLsizei i = 0; i < n; ++i) { |
873 GPU_CLIENT_LOG(" " << i << ": " << ids[i]); | 1010 GPU_CLIENT_LOG(" " << i << ": " << ids[i]); |
874 } | 1011 } |
875 }); | 1012 }); |
876 TRACE_EVENT0("gpu", "GLES2::DeleteSharedIdsCHROMIUM"); | 1013 TRACE_EVENT0("gpu", "GLES2::DeleteSharedIdsCHROMIUM"); |
877 GLint* id_buffer = transfer_buffer_.AllocTyped<GLint>(n); | 1014 GLsizei max_size = transfer_buffer_.GetLargestFreeOrPendingSize(); |
878 memcpy(id_buffer, ids, sizeof(*ids) * n); | 1015 GLsizei max_num_per = max_size / sizeof(ids[0]); |
879 helper_->DeleteSharedIdsCHROMIUM(namespace_id, n, | 1016 while (n) { |
880 transfer_buffer_id_, | 1017 GLsizei num = std::min(n, max_num_per); |
881 transfer_buffer_.GetOffset(id_buffer)); | 1018 GLint* id_buffer = transfer_buffer_.AllocTyped<GLint>(num); |
882 WaitForCmd(); | 1019 memcpy(id_buffer, ids, sizeof(*ids) * num); |
883 transfer_buffer_.FreePendingToken(id_buffer, helper_->InsertToken()); | 1020 helper_->DeleteSharedIdsCHROMIUM( |
| 1021 namespace_id, num, |
| 1022 transfer_buffer_id_, |
| 1023 transfer_buffer_.GetOffset(id_buffer)); |
| 1024 WaitForCmd(); |
| 1025 transfer_buffer_.FreePendingToken(id_buffer, helper_->InsertToken()); |
| 1026 n -= num; |
| 1027 ids += num; |
| 1028 } |
884 } | 1029 } |
885 | 1030 |
886 void GLES2Implementation::RegisterSharedIdsCHROMIUM( | 1031 void GLES2Implementation::RegisterSharedIdsCHROMIUM( |
887 GLuint namespace_id, GLsizei n, const GLuint* ids) { | 1032 GLuint namespace_id, GLsizei n, const GLuint* ids) { |
888 GPU_CLIENT_LOG("[" << this << "] glRegisterSharedIdsCHROMIUM(" | 1033 GPU_CLIENT_LOG("[" << this << "] glRegisterSharedIdsCHROMIUM(" |
889 << namespace_id << ", " << n << ", " | 1034 << namespace_id << ", " << n << ", " |
890 << static_cast<const void*>(ids) << ")"); | 1035 << static_cast<const void*>(ids) << ")"); |
891 GPU_CLIENT_LOG_CODE_BLOCK({ | 1036 GPU_CLIENT_LOG_CODE_BLOCK({ |
892 for (GLsizei i = 0; i < n; ++i) { | 1037 for (GLsizei i = 0; i < n; ++i) { |
893 GPU_CLIENT_LOG(" " << i << ": " << ids[i]); | 1038 GPU_CLIENT_LOG(" " << i << ": " << ids[i]); |
894 } | 1039 } |
895 }); | 1040 }); |
896 TRACE_EVENT0("gpu", "GLES2::RegisterSharedIdsCHROMIUM"); | 1041 TRACE_EVENT0("gpu", "GLES2::RegisterSharedIdsCHROMIUM"); |
897 GLint* id_buffer = transfer_buffer_.AllocTyped<GLint>(n); | 1042 GLsizei max_size = transfer_buffer_.GetLargestFreeOrPendingSize(); |
898 memcpy(id_buffer, ids, sizeof(*ids) * n); | 1043 GLsizei max_num_per = max_size / sizeof(ids[0]); |
899 helper_->RegisterSharedIdsCHROMIUM(namespace_id, n, | 1044 while (n) { |
900 transfer_buffer_id_, | 1045 GLsizei num = std::min(n, max_num_per); |
901 transfer_buffer_.GetOffset(id_buffer)); | 1046 GLint* id_buffer = transfer_buffer_.AllocTyped<GLint>(n); |
902 WaitForCmd(); | 1047 memcpy(id_buffer, ids, sizeof(*ids) * n); |
903 transfer_buffer_.FreePendingToken(id_buffer, helper_->InsertToken()); | 1048 helper_->RegisterSharedIdsCHROMIUM( |
| 1049 namespace_id, n, |
| 1050 transfer_buffer_id_, |
| 1051 transfer_buffer_.GetOffset(id_buffer)); |
| 1052 WaitForCmd(); |
| 1053 transfer_buffer_.FreePendingToken(id_buffer, helper_->InsertToken()); |
| 1054 n -= num; |
| 1055 ids += num; |
| 1056 } |
904 } | 1057 } |
905 | 1058 |
906 void GLES2Implementation::BindAttribLocation( | 1059 void GLES2Implementation::BindAttribLocation( |
907 GLuint program, GLuint index, const char* name) { | 1060 GLuint program, GLuint index, const char* name) { |
908 GPU_CLIENT_LOG("[" << this << "] glBindAttribLocation(" << program << ", " | 1061 GPU_CLIENT_LOG("[" << this << "] glBindAttribLocation(" << program << ", " |
909 << index << ", " << name << ")"); | 1062 << index << ", " << name << ")"); |
910 SetBucketAsString(kResultBucketId, name); | 1063 SetBucketAsString(kResultBucketId, name); |
911 helper_->BindAttribLocationBucket(program, index, kResultBucketId); | 1064 helper_->BindAttribLocationBucket(program, index, kResultBucketId); |
912 helper_->SetBucketSize(kResultBucketId, 0); | 1065 helper_->SetBucketSize(kResultBucketId, 0); |
913 } | 1066 } |
(...skipping 19 matching lines...) Expand all Loading... |
933 index, pname, result_shm_id(), result_shm_offset()); | 1086 index, pname, result_shm_id(), result_shm_offset()); |
934 WaitForCmd(); | 1087 WaitForCmd(); |
935 result->CopyResult(ptr); | 1088 result->CopyResult(ptr); |
936 GPU_CLIENT_LOG_CODE_BLOCK({ | 1089 GPU_CLIENT_LOG_CODE_BLOCK({ |
937 for (int32 i = 0; i < result->GetNumResults(); ++i) { | 1090 for (int32 i = 0; i < result->GetNumResults(); ++i) { |
938 GPU_CLIENT_LOG(" " << i << ": " << result->GetData()[i]); | 1091 GPU_CLIENT_LOG(" " << i << ": " << result->GetData()[i]); |
939 } | 1092 } |
940 }); | 1093 }); |
941 } | 1094 } |
942 | 1095 |
| 1096 bool GLES2Implementation::DeleteProgramHelper(GLuint program) { |
| 1097 if (!program_and_shader_id_handler_->FreeIds(1, &program)) { |
| 1098 SetGLError( |
| 1099 GL_INVALID_VALUE, |
| 1100 "glDeleteProgram: id not created by this context."); |
| 1101 return false; |
| 1102 } |
| 1103 program_info_manager_->DeleteInfo(program); |
| 1104 helper_->DeleteProgram(program); |
| 1105 Flush(); |
| 1106 return true; |
| 1107 } |
| 1108 |
| 1109 bool GLES2Implementation::DeleteShaderHelper(GLuint shader) { |
| 1110 if (!program_and_shader_id_handler_->FreeIds(1, &shader)) { |
| 1111 SetGLError( |
| 1112 GL_INVALID_VALUE, |
| 1113 "glDeleteShader: id not created by this context."); |
| 1114 return false; |
| 1115 } |
| 1116 program_info_manager_->DeleteInfo(shader); |
| 1117 helper_->DeleteShader(shader); |
| 1118 Flush(); |
| 1119 return true; |
| 1120 } |
| 1121 |
| 1122 GLint GLES2Implementation::GetAttribLocationHelper( |
| 1123 GLuint program, const char* name) { |
| 1124 typedef GetAttribLocationBucket::Result Result; |
| 1125 Result* result = GetResultAs<Result*>(); |
| 1126 *result = -1; |
| 1127 SetBucketAsCString(kResultBucketId, name); |
| 1128 helper_->GetAttribLocationBucket( |
| 1129 program, kResultBucketId, result_shm_id(), result_shm_offset()); |
| 1130 WaitForCmd(); |
| 1131 helper_->SetBucketSize(kResultBucketId, 0); |
| 1132 return *result; |
| 1133 } |
| 1134 |
943 GLint GLES2Implementation::GetAttribLocation( | 1135 GLint GLES2Implementation::GetAttribLocation( |
944 GLuint program, const char* name) { | 1136 GLuint program, const char* name) { |
945 GPU_CLIENT_LOG("[" << this << "] glGetAttribLocation(" << program | 1137 GPU_CLIENT_LOG("[" << this << "] glGetAttribLocation(" << program |
946 << ", " << name << ")"); | 1138 << ", " << name << ")"); |
947 TRACE_EVENT0("gpu", "GLES2::GetAttribLocation"); | 1139 TRACE_EVENT0("gpu", "GLES2::GetAttribLocation"); |
948 typedef GetAttribLocationBucket::Result Result; | 1140 GLint loc = program_info_manager_->GetAttribLocation(this, program, name); |
949 Result* result = GetResultAs<Result*>(); | 1141 GPU_CLIENT_LOG("returned " << loc); |
950 *result = -1; | 1142 return loc; |
951 SetBucketAsCString(kResultBucketId, name); | |
952 helper_->GetAttribLocationBucket(program, kResultBucketId, | |
953 result_shm_id(), result_shm_offset()); | |
954 WaitForCmd(); | |
955 helper_->SetBucketSize(kResultBucketId, 0); | |
956 GPU_CLIENT_LOG("returned " << *result); | |
957 return *result; | |
958 } | 1143 } |
959 | 1144 |
960 GLint GLES2Implementation::GetUniformLocation( | 1145 GLint GLES2Implementation::GetUniformLocationHelper( |
961 GLuint program, const char* name) { | 1146 GLuint program, const char* name) { |
962 GPU_CLIENT_LOG("[" << this << "] glGetUniformLocation(" << program | |
963 << ", " << name << ")"); | |
964 TRACE_EVENT0("gpu", "GLES2::GetUniformLocation"); | |
965 typedef GetUniformLocationBucket::Result Result; | 1147 typedef GetUniformLocationBucket::Result Result; |
966 Result* result = GetResultAs<Result*>(); | 1148 Result* result = GetResultAs<Result*>(); |
967 *result = -1; | 1149 *result = -1; |
968 SetBucketAsCString(kResultBucketId, name); | 1150 SetBucketAsCString(kResultBucketId, name); |
969 helper_->GetUniformLocationBucket(program, kResultBucketId, | 1151 helper_->GetUniformLocationBucket(program, kResultBucketId, |
970 result_shm_id(), result_shm_offset()); | 1152 result_shm_id(), result_shm_offset()); |
971 WaitForCmd(); | 1153 WaitForCmd(); |
972 helper_->SetBucketSize(kResultBucketId, 0); | 1154 helper_->SetBucketSize(kResultBucketId, 0); |
973 GPU_CLIENT_LOG("returned " << *result); | |
974 return *result; | 1155 return *result; |
975 } | 1156 } |
976 | 1157 |
| 1158 GLint GLES2Implementation::GetUniformLocation( |
| 1159 GLuint program, const char* name) { |
| 1160 GPU_CLIENT_LOG("[" << this << "] glGetUniformLocation(" << program |
| 1161 << ", " << name << ")"); |
| 1162 TRACE_EVENT0("gpu", "GLES2::GetUniformLocation"); |
| 1163 GLint loc = program_info_manager_->GetUniformLocation(this, program, name); |
| 1164 GPU_CLIENT_LOG("returned " << loc); |
| 1165 return loc; |
| 1166 } |
| 1167 |
| 1168 bool GLES2Implementation::GetProgramivHelper( |
| 1169 GLuint program, GLenum pname, GLint* params) { |
| 1170 return program_info_manager_->GetProgramiv(this, program, pname, params); |
| 1171 } |
| 1172 |
| 1173 void GLES2Implementation::LinkProgram(GLuint program) { |
| 1174 GPU_CLIENT_LOG("[" << this << "] glLinkProgram(" << program << ")"); |
| 1175 helper_->LinkProgram(program); |
| 1176 program_info_manager_->CreateInfo(program); |
| 1177 } |
977 | 1178 |
978 void GLES2Implementation::ShaderBinary( | 1179 void GLES2Implementation::ShaderBinary( |
979 GLsizei n, const GLuint* shaders, GLenum binaryformat, const void* binary, | 1180 GLsizei n, const GLuint* shaders, GLenum binaryformat, const void* binary, |
980 GLsizei length) { | 1181 GLsizei length) { |
981 GPU_CLIENT_LOG("[" << this << "] glShaderBinary(" << n << ", " | 1182 GPU_CLIENT_LOG("[" << this << "] glShaderBinary(" << n << ", " |
982 << static_cast<const void*>(shaders) << ", " | 1183 << static_cast<const void*>(shaders) << ", " |
983 << GLES2Util::GetStringEnum(binaryformat) << ", " | 1184 << GLES2Util::GetStringEnum(binaryformat) << ", " |
984 << static_cast<const void*>(binary) << ", " | 1185 << static_cast<const void*>(binary) << ", " |
985 << length << ")"); | 1186 << length << ")"); |
986 if (n < 0) { | 1187 if (n < 0) { |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1420 row_source += part_size; | 1621 row_source += part_size; |
1421 temp_xoffset += num_pixels; | 1622 temp_xoffset += num_pixels; |
1422 temp_width -= num_pixels; | 1623 temp_width -= num_pixels; |
1423 } | 1624 } |
1424 ++yoffset; | 1625 ++yoffset; |
1425 source += padded_row_size; | 1626 source += padded_row_size; |
1426 } | 1627 } |
1427 } | 1628 } |
1428 } | 1629 } |
1429 | 1630 |
1430 void GLES2Implementation::GetActiveAttrib( | 1631 bool GLES2Implementation::GetActiveAttribHelper( |
1431 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, | 1632 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, |
1432 GLenum* type, char* name) { | 1633 GLenum* type, char* name) { |
1433 GPU_CLIENT_LOG("[" << this << "] glGetActiveAttrib(" | 1634 // Clear the bucket so if the command fails nothing will be in it. |
1434 << program << ", " << index << ", " << bufsize << ", " | |
1435 << static_cast<const void*>(length) << ", " | |
1436 << static_cast<const void*>(size) << ", " | |
1437 << static_cast<const void*>(type) << ", " | |
1438 << static_cast<const void*>(name) << ", "); | |
1439 if (bufsize < 0) { | |
1440 SetGLError(GL_INVALID_VALUE, "glGetActiveAttrib: bufsize < 0"); | |
1441 return; | |
1442 } | |
1443 TRACE_EVENT0("gpu", "GLES2::GetActiveAttrib"); | |
1444 // Clear the bucket so if we the command fails nothing will be in it. | |
1445 helper_->SetBucketSize(kResultBucketId, 0); | 1635 helper_->SetBucketSize(kResultBucketId, 0); |
1446 typedef gles2::GetActiveAttrib::Result Result; | 1636 typedef gles2::GetActiveAttrib::Result Result; |
1447 Result* result = static_cast<Result*>(result_buffer_); | 1637 Result* result = static_cast<Result*>(result_buffer_); |
1448 // Set as failed so if the command fails we'll recover. | 1638 // Set as failed so if the command fails we'll recover. |
1449 result->success = false; | 1639 result->success = false; |
1450 helper_->GetActiveAttrib(program, index, kResultBucketId, | 1640 helper_->GetActiveAttrib(program, index, kResultBucketId, |
1451 result_shm_id(), result_shm_offset()); | 1641 result_shm_id(), result_shm_offset()); |
1452 WaitForCmd(); | 1642 WaitForCmd(); |
1453 if (result->success) { | 1643 if (result->success) { |
1454 if (size) { | 1644 if (size) { |
1455 *size = result->size; | 1645 *size = result->size; |
1456 GPU_CLIENT_LOG(" size: " << *size); | |
1457 } | 1646 } |
1458 if (type) { | 1647 if (type) { |
1459 *type = result->type; | 1648 *type = result->type; |
1460 GPU_CLIENT_LOG(" type: " << GLES2Util::GetStringEnum(*type)); | |
1461 } | 1649 } |
1462 if (length || name) { | 1650 if (length || name) { |
1463 std::vector<int8> str; | 1651 std::vector<int8> str; |
1464 GetBucketContents(kResultBucketId, &str); | 1652 GetBucketContents(kResultBucketId, &str); |
1465 GLsizei max_size = std::min(static_cast<size_t>(bufsize) - 1, | 1653 GLsizei max_size = std::min(static_cast<size_t>(bufsize) - 1, |
1466 std::max(static_cast<size_t>(0), | 1654 std::max(static_cast<size_t>(0), |
1467 str.size() - 1)); | 1655 str.size() - 1)); |
1468 if (length) { | 1656 if (length) { |
1469 *length = max_size; | 1657 *length = max_size; |
1470 } | 1658 } |
1471 if (name && bufsize > 0) { | 1659 if (name && bufsize > 0) { |
1472 memcpy(name, &str[0], max_size); | 1660 memcpy(name, &str[0], max_size); |
1473 name[max_size] = '\0'; | 1661 name[max_size] = '\0'; |
1474 GPU_CLIENT_LOG(" name: " << name); | |
1475 } | 1662 } |
1476 } | 1663 } |
1477 } | 1664 } |
| 1665 return result->success != 0; |
1478 } | 1666 } |
1479 | 1667 |
1480 void GLES2Implementation::GetActiveUniform( | 1668 void GLES2Implementation::GetActiveAttrib( |
1481 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, | 1669 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, |
1482 GLenum* type, char* name) { | 1670 GLenum* type, char* name) { |
1483 GPU_CLIENT_LOG("[" << this << "] glGetActiveUniform(" | 1671 GPU_CLIENT_LOG("[" << this << "] glGetActiveAttrib(" |
1484 << program << ", " << index << ", " << bufsize << ", " | 1672 << program << ", " << index << ", " << bufsize << ", " |
1485 << static_cast<const void*>(length) << ", " | 1673 << static_cast<const void*>(length) << ", " |
1486 << static_cast<const void*>(size) << ", " | 1674 << static_cast<const void*>(size) << ", " |
1487 << static_cast<const void*>(type) << ", " | 1675 << static_cast<const void*>(type) << ", " |
1488 << static_cast<const void*>(name) << ", "); | 1676 << static_cast<const void*>(name) << ", "); |
1489 if (bufsize < 0) { | 1677 if (bufsize < 0) { |
1490 SetGLError(GL_INVALID_VALUE, "glGetActiveUniform: bufsize < 0"); | 1678 SetGLError(GL_INVALID_VALUE, "glGetActiveAttrib: bufsize < 0"); |
1491 return; | 1679 return; |
1492 } | 1680 } |
1493 TRACE_EVENT0("gpu", "GLES2::GetActiveUniform"); | 1681 TRACE_EVENT0("gpu", "GLES2::GetActiveAttrib"); |
1494 // Clear the bucket so if we the command fails nothing will be in it. | 1682 bool success = program_info_manager_->GetActiveAttrib( |
| 1683 this, program, index, bufsize, length, size, type, name); |
| 1684 if (success) { |
| 1685 if (size) { |
| 1686 GPU_CLIENT_LOG(" size: " << *size); |
| 1687 } |
| 1688 if (type) { |
| 1689 GPU_CLIENT_LOG(" type: " << GLES2Util::GetStringEnum(*type)); |
| 1690 } |
| 1691 if (name) { |
| 1692 GPU_CLIENT_LOG(" name: " << name); |
| 1693 } |
| 1694 } |
| 1695 } |
| 1696 |
| 1697 bool GLES2Implementation::GetActiveUniformHelper( |
| 1698 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, |
| 1699 GLenum* type, char* name) { |
| 1700 // Clear the bucket so if the command fails nothing will be in it. |
1495 helper_->SetBucketSize(kResultBucketId, 0); | 1701 helper_->SetBucketSize(kResultBucketId, 0); |
1496 typedef gles2::GetActiveUniform::Result Result; | 1702 typedef gles2::GetActiveUniform::Result Result; |
1497 Result* result = static_cast<Result*>(result_buffer_); | 1703 Result* result = static_cast<Result*>(result_buffer_); |
1498 // Set as failed so if the command fails we'll recover. | 1704 // Set as failed so if the command fails we'll recover. |
1499 result->success = false; | 1705 result->success = false; |
1500 helper_->GetActiveUniform(program, index, kResultBucketId, | 1706 helper_->GetActiveUniform(program, index, kResultBucketId, |
1501 result_shm_id(), result_shm_offset()); | 1707 result_shm_id(), result_shm_offset()); |
1502 WaitForCmd(); | 1708 WaitForCmd(); |
1503 if (result->success) { | 1709 if (result->success) { |
1504 if (size) { | 1710 if (size) { |
1505 *size = result->size; | 1711 *size = result->size; |
1506 GPU_CLIENT_LOG(" size: " << *size); | |
1507 } | 1712 } |
1508 if (type) { | 1713 if (type) { |
1509 *type = result->type; | 1714 *type = result->type; |
1510 GPU_CLIENT_LOG(" type: " << GLES2Util::GetStringEnum(*type)); | |
1511 } | 1715 } |
1512 if (length || name) { | 1716 if (length || name) { |
1513 std::vector<int8> str; | 1717 std::vector<int8> str; |
1514 GetBucketContents(kResultBucketId, &str); | 1718 GetBucketContents(kResultBucketId, &str); |
1515 GLsizei max_size = std::min(static_cast<size_t>(bufsize) - 1, | 1719 GLsizei max_size = std::min(static_cast<size_t>(bufsize) - 1, |
1516 std::max(static_cast<size_t>(0), | 1720 std::max(static_cast<size_t>(0), |
1517 str.size() - 1)); | 1721 str.size() - 1)); |
1518 if (length) { | 1722 if (length) { |
1519 *length = max_size; | 1723 *length = max_size; |
1520 } | 1724 } |
1521 if (name && bufsize > 0) { | 1725 if (name && bufsize > 0) { |
1522 memcpy(name, &str[0], max_size); | 1726 memcpy(name, &str[0], max_size); |
1523 name[max_size] = '\0'; | 1727 name[max_size] = '\0'; |
1524 GPU_CLIENT_LOG(" name: " << name); | |
1525 } | 1728 } |
1526 } | 1729 } |
1527 } | 1730 } |
| 1731 return result->success != 0; |
| 1732 } |
| 1733 |
| 1734 void GLES2Implementation::GetActiveUniform( |
| 1735 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, |
| 1736 GLenum* type, char* name) { |
| 1737 GPU_CLIENT_LOG("[" << this << "] glGetActiveUniform(" |
| 1738 << program << ", " << index << ", " << bufsize << ", " |
| 1739 << static_cast<const void*>(length) << ", " |
| 1740 << static_cast<const void*>(size) << ", " |
| 1741 << static_cast<const void*>(type) << ", " |
| 1742 << static_cast<const void*>(name) << ", "); |
| 1743 if (bufsize < 0) { |
| 1744 SetGLError(GL_INVALID_VALUE, "glGetActiveUniform: bufsize < 0"); |
| 1745 return; |
| 1746 } |
| 1747 TRACE_EVENT0("gpu", "GLES2::GetActiveUniform"); |
| 1748 bool success = program_info_manager_->GetActiveUniform( |
| 1749 this, program, index, bufsize, length, size, type, name); |
| 1750 if (success) { |
| 1751 if (size) { |
| 1752 GPU_CLIENT_LOG(" size: " << *size); |
| 1753 } |
| 1754 if (type) { |
| 1755 GPU_CLIENT_LOG(" type: " << GLES2Util::GetStringEnum(*type)); |
| 1756 } |
| 1757 if (name) { |
| 1758 GPU_CLIENT_LOG(" name: " << name); |
| 1759 } |
| 1760 } |
1528 } | 1761 } |
1529 | 1762 |
1530 void GLES2Implementation::GetAttachedShaders( | 1763 void GLES2Implementation::GetAttachedShaders( |
1531 GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders) { | 1764 GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders) { |
1532 GPU_CLIENT_LOG("[" << this << "] glGetAttachedShaders(" | 1765 GPU_CLIENT_LOG("[" << this << "] glGetAttachedShaders(" |
1533 << program << ", " << maxcount << ", " | 1766 << program << ", " << maxcount << ", " |
1534 << static_cast<const void*>(count) << ", " | 1767 << static_cast<const void*>(count) << ", " |
1535 << static_cast<const void*>(shaders) << ", "); | 1768 << static_cast<const void*>(shaders) << ", "); |
1536 if (maxcount < 0) { | 1769 if (maxcount < 0) { |
1537 SetGLError(GL_INVALID_VALUE, "glGetAttachedShaders: maxcount < 0"); | 1770 SetGLError(GL_INVALID_VALUE, "glGetAttachedShaders: maxcount < 0"); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1893 return false; | 2126 return false; |
1894 } | 2127 } |
1895 #else | 2128 #else |
1896 bool GLES2Implementation::IsBufferReservedId(GLuint /* id */) { | 2129 bool GLES2Implementation::IsBufferReservedId(GLuint /* id */) { |
1897 return false; | 2130 return false; |
1898 } | 2131 } |
1899 #endif | 2132 #endif |
1900 | 2133 |
1901 void GLES2Implementation::DeleteBuffersHelper( | 2134 void GLES2Implementation::DeleteBuffersHelper( |
1902 GLsizei n, const GLuint* buffers) { | 2135 GLsizei n, const GLuint* buffers) { |
1903 buffer_id_handler_->FreeIds(n, buffers); | 2136 if (!buffer_id_handler_->FreeIds(n, buffers)) { |
| 2137 SetGLError( |
| 2138 GL_INVALID_VALUE, |
| 2139 "glDeleteBuffers: id not created by this context."); |
| 2140 return; |
| 2141 } |
1904 for (GLsizei ii = 0; ii < n; ++ii) { | 2142 for (GLsizei ii = 0; ii < n; ++ii) { |
1905 if (buffers[ii] == bound_array_buffer_id_) { | 2143 if (buffers[ii] == bound_array_buffer_id_) { |
1906 bound_array_buffer_id_ = 0; | 2144 bound_array_buffer_id_ = 0; |
1907 } | 2145 } |
1908 if (buffers[ii] == bound_element_array_buffer_id_) { | 2146 if (buffers[ii] == bound_element_array_buffer_id_) { |
1909 bound_element_array_buffer_id_ = 0; | 2147 bound_element_array_buffer_id_ = 0; |
1910 } | 2148 } |
1911 } | 2149 } |
| 2150 helper_->DeleteBuffersImmediate(n, buffers); |
| 2151 Flush(); |
1912 } | 2152 } |
1913 | 2153 |
1914 void GLES2Implementation::DeleteFramebuffersHelper( | 2154 void GLES2Implementation::DeleteFramebuffersHelper( |
1915 GLsizei n, const GLuint* framebuffers) { | 2155 GLsizei n, const GLuint* framebuffers) { |
1916 framebuffer_id_handler_->FreeIds(n, framebuffers); | 2156 if (!framebuffer_id_handler_->FreeIds(n, framebuffers)) { |
| 2157 SetGLError( |
| 2158 GL_INVALID_VALUE, |
| 2159 "glDeleteFramebuffers: id not created by this context."); |
| 2160 return; |
| 2161 } |
1917 for (GLsizei ii = 0; ii < n; ++ii) { | 2162 for (GLsizei ii = 0; ii < n; ++ii) { |
1918 if (framebuffers[ii] == bound_framebuffer_) { | 2163 if (framebuffers[ii] == bound_framebuffer_) { |
1919 bound_framebuffer_ = 0; | 2164 bound_framebuffer_ = 0; |
1920 } | 2165 } |
1921 } | 2166 } |
| 2167 helper_->DeleteFramebuffersImmediate(n, framebuffers); |
| 2168 Flush(); |
1922 } | 2169 } |
1923 | 2170 |
1924 void GLES2Implementation::DeleteRenderbuffersHelper( | 2171 void GLES2Implementation::DeleteRenderbuffersHelper( |
1925 GLsizei n, const GLuint* renderbuffers) { | 2172 GLsizei n, const GLuint* renderbuffers) { |
1926 renderbuffer_id_handler_->FreeIds(n, renderbuffers); | 2173 if (!renderbuffer_id_handler_->FreeIds(n, renderbuffers)) { |
| 2174 SetGLError( |
| 2175 GL_INVALID_VALUE, |
| 2176 "glDeleteRenderbuffers: id not created by this context."); |
| 2177 return; |
| 2178 } |
1927 for (GLsizei ii = 0; ii < n; ++ii) { | 2179 for (GLsizei ii = 0; ii < n; ++ii) { |
1928 if (renderbuffers[ii] == bound_renderbuffer_) { | 2180 if (renderbuffers[ii] == bound_renderbuffer_) { |
1929 bound_renderbuffer_ = 0; | 2181 bound_renderbuffer_ = 0; |
1930 } | 2182 } |
1931 } | 2183 } |
| 2184 helper_->DeleteRenderbuffersImmediate(n, renderbuffers); |
| 2185 Flush(); |
1932 } | 2186 } |
1933 | 2187 |
1934 void GLES2Implementation::DeleteTexturesHelper( | 2188 void GLES2Implementation::DeleteTexturesHelper( |
1935 GLsizei n, const GLuint* textures) { | 2189 GLsizei n, const GLuint* textures) { |
1936 texture_id_handler_->FreeIds(n, textures); | 2190 if (!texture_id_handler_->FreeIds(n, textures)) { |
| 2191 SetGLError( |
| 2192 GL_INVALID_VALUE, |
| 2193 "glDeleteTextures: id not created by this context."); |
| 2194 return; |
| 2195 } |
1937 for (GLsizei ii = 0; ii < n; ++ii) { | 2196 for (GLsizei ii = 0; ii < n; ++ii) { |
1938 for (GLint tt = 0; tt < gl_state_.max_combined_texture_image_units; ++tt) { | 2197 for (GLint tt = 0; tt < gl_state_.max_combined_texture_image_units; ++tt) { |
1939 TextureUnit& unit = texture_units_[active_texture_unit_]; | 2198 TextureUnit& unit = texture_units_[active_texture_unit_]; |
1940 if (textures[ii] == unit.bound_texture_2d) { | 2199 if (textures[ii] == unit.bound_texture_2d) { |
1941 unit.bound_texture_2d = 0; | 2200 unit.bound_texture_2d = 0; |
1942 } | 2201 } |
1943 if (textures[ii] == unit.bound_texture_cube_map) { | 2202 if (textures[ii] == unit.bound_texture_cube_map) { |
1944 unit.bound_texture_cube_map = 0; | 2203 unit.bound_texture_cube_map = 0; |
1945 } | 2204 } |
1946 } | 2205 } |
1947 } | 2206 } |
| 2207 helper_->DeleteTexturesImmediate(n, textures); |
| 2208 Flush(); |
1948 } | 2209 } |
1949 | 2210 |
1950 void GLES2Implementation::DisableVertexAttribArray(GLuint index) { | 2211 void GLES2Implementation::DisableVertexAttribArray(GLuint index) { |
1951 GPU_CLIENT_LOG( | 2212 GPU_CLIENT_LOG( |
1952 "[" << this << "] glDisableVertexAttribArray(" << index << ")"); | 2213 "[" << this << "] glDisableVertexAttribArray(" << index << ")"); |
1953 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) | 2214 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) |
1954 client_side_buffer_helper_->SetAttribEnable(index, false); | 2215 client_side_buffer_helper_->SetAttribEnable(index, false); |
1955 #endif | 2216 #endif |
1956 helper_->DisableVertexAttribArray(index); | 2217 helper_->DisableVertexAttribArray(index); |
1957 } | 2218 } |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2314 // TODO(gman): We should be able to free without a token. | 2575 // TODO(gman): We should be able to free without a token. |
2315 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); | 2576 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); |
2316 GPU_CLIENT_LOG(" returned"); | 2577 GPU_CLIENT_LOG(" returned"); |
2317 GPU_CLIENT_LOG_CODE_BLOCK({ | 2578 GPU_CLIENT_LOG_CODE_BLOCK({ |
2318 for (int i = 0; i < num_results; ++i) { | 2579 for (int i = 0; i < num_results; ++i) { |
2319 GPU_CLIENT_LOG(" " << i << ": " << (results[i])); | 2580 GPU_CLIENT_LOG(" " << i << ": " << (results[i])); |
2320 } | 2581 } |
2321 }); | 2582 }); |
2322 } | 2583 } |
2323 | 2584 |
| 2585 void GLES2Implementation::GetProgramInfoCHROMIUMHelper( |
| 2586 GLuint program, std::vector<int8>* result) { |
| 2587 GPU_DCHECK(result); |
| 2588 // Clear the bucket so if the command fails nothing will be in it. |
| 2589 helper_->SetBucketSize(kResultBucketId, 0); |
| 2590 helper_->GetProgramInfoCHROMIUM(program, kResultBucketId); |
| 2591 GetBucketContents(kResultBucketId, result); |
| 2592 } |
| 2593 |
2324 void GLES2Implementation::GetProgramInfoCHROMIUM( | 2594 void GLES2Implementation::GetProgramInfoCHROMIUM( |
2325 GLuint program, GLsizei bufsize, GLsizei* size, void* info) { | 2595 GLuint program, GLsizei bufsize, GLsizei* size, void* info) { |
2326 if (bufsize < 0) { | 2596 if (bufsize < 0) { |
2327 SetGLError(GL_INVALID_VALUE, "glProgramInfoCHROMIUM: bufsize less than 0."); | 2597 SetGLError(GL_INVALID_VALUE, "glProgramInfoCHROMIUM: bufsize less than 0."); |
2328 return; | 2598 return; |
2329 } | 2599 } |
2330 if (size == NULL) { | 2600 if (size == NULL) { |
2331 SetGLError(GL_INVALID_VALUE, "glProgramInfoCHROMIUM: size is null."); | 2601 SetGLError(GL_INVALID_VALUE, "glProgramInfoCHROMIUM: size is null."); |
2332 return; | 2602 return; |
2333 } | 2603 } |
2334 // Make sure they've set size to 0 else the value will be undefined on | 2604 // Make sure they've set size to 0 else the value will be undefined on |
2335 // lost context. | 2605 // lost context. |
2336 GPU_DCHECK(*size == 0); | 2606 GPU_DCHECK(*size == 0); |
2337 // Clear the bucket so if the command fails nothing will be in it. | |
2338 helper_->SetBucketSize(kResultBucketId, 0); | |
2339 helper_->GetProgramInfoCHROMIUM(program, kResultBucketId); | |
2340 std::vector<int8> result; | 2607 std::vector<int8> result; |
2341 GetBucketContents(kResultBucketId, &result); | 2608 GetProgramInfoCHROMIUMHelper(program, &result); |
2342 if (result.size() == 0) { | 2609 if (result.empty()) { |
2343 return; | 2610 return; |
2344 } | 2611 } |
2345 *size = result.size(); | 2612 *size = result.size(); |
2346 if (!info) { | 2613 if (!info) { |
2347 return; | 2614 return; |
2348 } | 2615 } |
2349 if (static_cast<size_t>(bufsize) < result.size()) { | 2616 if (static_cast<size_t>(bufsize) < result.size()) { |
2350 SetGLError(GL_INVALID_OPERATION, | 2617 SetGLError(GL_INVALID_OPERATION, |
2351 "glProgramInfoCHROMIUM: bufsize is too small for result."); | 2618 "glProgramInfoCHROMIUM: bufsize is too small for result."); |
2352 return; | 2619 return; |
2353 } | 2620 } |
2354 memcpy(info, &result[0], result.size()); | 2621 memcpy(info, &result[0], result.size()); |
2355 } | 2622 } |
2356 | 2623 |
2357 } // namespace gles2 | 2624 } // namespace gles2 |
2358 } // namespace gpu | 2625 } // namespace gpu |
| 2626 |
OLD | NEW |