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

Side by Side Diff: gpu/command_buffer/client/gles2_implementation.cc

Issue 723343002: Update from https://crrev.com/304121 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
OLDNEW
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 "gpu/command_buffer/client/gles2_implementation.h" 7 #include "gpu/command_buffer/client/gles2_implementation.h"
8 8
9 #include <GLES2/gl2ext.h> 9 #include <GLES2/gl2ext.h>
10 #include <GLES2/gl2extchromium.h> 10 #include <GLES2/gl2extchromium.h>
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 const size_t GLES2Implementation::kMaxSizeOfSimpleResult; 42 const size_t GLES2Implementation::kMaxSizeOfSimpleResult;
43 const unsigned int GLES2Implementation::kStartingOffset; 43 const unsigned int GLES2Implementation::kStartingOffset;
44 #endif 44 #endif
45 45
46 GLES2Implementation::GLStaticState::GLStaticState() { 46 GLES2Implementation::GLStaticState::GLStaticState() {
47 } 47 }
48 48
49 GLES2Implementation::GLStaticState::~GLStaticState() { 49 GLES2Implementation::GLStaticState::~GLStaticState() {
50 } 50 }
51 51
52 GLES2Implementation::GLStaticState::IntState::IntState()
53 : max_combined_texture_image_units(0),
54 max_cube_map_texture_size(0),
55 max_fragment_uniform_vectors(0),
56 max_renderbuffer_size(0),
57 max_texture_image_units(0),
58 max_texture_size(0),
59 max_varying_vectors(0),
60 max_vertex_attribs(0),
61 max_vertex_texture_image_units(0),
62 max_vertex_uniform_vectors(0),
63 num_compressed_texture_formats(0),
64 num_shader_binary_formats(0),
65 bind_generates_resource_chromium(0) {}
66
67 GLES2Implementation::SingleThreadChecker::SingleThreadChecker( 52 GLES2Implementation::SingleThreadChecker::SingleThreadChecker(
68 GLES2Implementation* gles2_implementation) 53 GLES2Implementation* gles2_implementation)
69 : gles2_implementation_(gles2_implementation) { 54 : gles2_implementation_(gles2_implementation) {
70 CHECK_EQ(0, gles2_implementation_->use_count_); 55 CHECK_EQ(0, gles2_implementation_->use_count_);
71 ++gles2_implementation_->use_count_; 56 ++gles2_implementation_->use_count_;
72 } 57 }
73 58
74 GLES2Implementation::SingleThreadChecker::~SingleThreadChecker() { 59 GLES2Implementation::SingleThreadChecker::~SingleThreadChecker() {
75 --gles2_implementation_->use_count_; 60 --gles2_implementation_->use_count_;
76 CHECK_EQ(0, gles2_implementation_->use_count_); 61 CHECK_EQ(0, gles2_implementation_->use_count_);
(...skipping 15 matching lines...) Expand all
92 unpack_alignment_(4), 77 unpack_alignment_(4),
93 unpack_flip_y_(false), 78 unpack_flip_y_(false),
94 unpack_row_length_(0), 79 unpack_row_length_(0),
95 unpack_skip_rows_(0), 80 unpack_skip_rows_(0),
96 unpack_skip_pixels_(0), 81 unpack_skip_pixels_(0),
97 pack_reverse_row_order_(false), 82 pack_reverse_row_order_(false),
98 active_texture_unit_(0), 83 active_texture_unit_(0),
99 bound_framebuffer_(0), 84 bound_framebuffer_(0),
100 bound_read_framebuffer_(0), 85 bound_read_framebuffer_(0),
101 bound_renderbuffer_(0), 86 bound_renderbuffer_(0),
87 bound_valuebuffer_(0),
102 current_program_(0), 88 current_program_(0),
103 bound_array_buffer_id_(0), 89 bound_array_buffer_id_(0),
104 bound_pixel_pack_transfer_buffer_id_(0), 90 bound_pixel_pack_transfer_buffer_id_(0),
105 bound_pixel_unpack_transfer_buffer_id_(0), 91 bound_pixel_unpack_transfer_buffer_id_(0),
106 async_upload_token_(0), 92 async_upload_token_(0),
107 async_upload_sync_(NULL), 93 async_upload_sync_(NULL),
108 async_upload_sync_shm_id_(0), 94 async_upload_sync_shm_id_(0),
109 async_upload_sync_shm_offset_(0), 95 async_upload_sync_shm_offset_(0),
110 error_bits_(0), 96 error_bits_(0),
111 debug_(false), 97 debug_(false),
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 base::Unretained(this)), 152 base::Unretained(this)),
167 mapped_memory_limit)); 153 mapped_memory_limit));
168 154
169 unsigned chunk_size = 2 * 1024 * 1024; 155 unsigned chunk_size = 2 * 1024 * 1024;
170 if (mapped_memory_limit != kNoLimit) { 156 if (mapped_memory_limit != kNoLimit) {
171 // Use smaller chunks if the client is very memory conscientious. 157 // Use smaller chunks if the client is very memory conscientious.
172 chunk_size = std::min(mapped_memory_limit / 4, chunk_size); 158 chunk_size = std::min(mapped_memory_limit / 4, chunk_size);
173 } 159 }
174 mapped_memory_->set_chunk_size_multiple(chunk_size); 160 mapped_memory_->set_chunk_size_multiple(chunk_size);
175 161
176 if (!QueryAndCacheStaticState()) 162 GLStaticState::ShaderPrecisionMap* shader_precisions =
177 return false; 163 &static_state_.shader_precisions;
164 capabilities_.VisitPrecisions([shader_precisions](
165 GLenum shader, GLenum type, Capabilities::ShaderPrecision* result) {
166 const GLStaticState::ShaderPrecisionKey key(shader, type);
167 cmds::GetShaderPrecisionFormat::Result cached_result = {
168 true, result->min_range, result->max_range, result->precision};
169 shader_precisions->insert(std::make_pair(key, cached_result));
170 });
178 171
179 util_.set_num_compressed_texture_formats( 172 util_.set_num_compressed_texture_formats(
180 static_state_.int_state.num_compressed_texture_formats); 173 capabilities_.num_compressed_texture_formats);
181 util_.set_num_shader_binary_formats( 174 util_.set_num_shader_binary_formats(capabilities_.num_shader_binary_formats);
182 static_state_.int_state.num_shader_binary_formats);
183 175
184 texture_units_.reset( 176 texture_units_.reset(
185 new TextureUnit[ 177 new TextureUnit[capabilities_.max_combined_texture_image_units]);
186 static_state_.int_state.max_combined_texture_image_units]);
187 178
188 query_tracker_.reset(new QueryTracker(mapped_memory_.get())); 179 query_tracker_.reset(new QueryTracker(mapped_memory_.get()));
189 buffer_tracker_.reset(new BufferTracker(mapped_memory_.get())); 180 buffer_tracker_.reset(new BufferTracker(mapped_memory_.get()));
190 181
191 query_id_allocator_.reset(new IdAllocator()); 182 query_id_allocator_.reset(new IdAllocator());
192 if (support_client_side_arrays_) { 183 if (support_client_side_arrays_) {
193 GetIdHandler(id_namespaces::kBuffers)->MakeIds( 184 GetIdHandler(id_namespaces::kBuffers)->MakeIds(
194 this, kClientSideArrayId, arraysize(reserved_ids_), &reserved_ids_[0]); 185 this, kClientSideArrayId, arraysize(reserved_ids_), &reserved_ids_[0]);
195 } 186 }
196 187
197 vertex_array_object_manager_.reset(new VertexArrayObjectManager( 188 vertex_array_object_manager_.reset(new VertexArrayObjectManager(
198 static_state_.int_state.max_vertex_attribs, 189 capabilities_.max_vertex_attribs, reserved_ids_[0], reserved_ids_[1],
199 reserved_ids_[0],
200 reserved_ids_[1],
201 support_client_side_arrays_)); 190 support_client_side_arrays_));
202 191
203 // GL_BIND_GENERATES_RESOURCE_CHROMIUM state must be the same 192 // GL_BIND_GENERATES_RESOURCE_CHROMIUM state must be the same
204 // on Client & Service. 193 // on Client & Service.
205 if (static_state_.int_state.bind_generates_resource_chromium != 194 if (capabilities_.bind_generates_resource_chromium !=
206 (share_group_->bind_generates_resource() ? 1 : 0)) { 195 (share_group_->bind_generates_resource() ? 1 : 0)) {
207 SetGLError(GL_INVALID_OPERATION, 196 SetGLError(GL_INVALID_OPERATION,
208 "Initialize", 197 "Initialize",
209 "Service bind_generates_resource mismatch."); 198 "Service bind_generates_resource mismatch.");
210 return false; 199 return false;
211 } 200 }
212 201
213 return true; 202 return true;
214 } 203 }
215 204
216 bool GLES2Implementation::QueryAndCacheStaticState() {
217 TRACE_EVENT0("gpu", "GLES2Implementation::QueryAndCacheStaticState");
218 // Setup query for multiple GetIntegerv's
219 static const GLenum pnames[] = {
220 GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
221 GL_MAX_CUBE_MAP_TEXTURE_SIZE,
222 GL_MAX_FRAGMENT_UNIFORM_VECTORS,
223 GL_MAX_RENDERBUFFER_SIZE,
224 GL_MAX_TEXTURE_IMAGE_UNITS,
225 GL_MAX_TEXTURE_SIZE,
226 GL_MAX_VARYING_VECTORS,
227 GL_MAX_VERTEX_ATTRIBS,
228 GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS,
229 GL_MAX_VERTEX_UNIFORM_VECTORS,
230 GL_NUM_COMPRESSED_TEXTURE_FORMATS,
231 GL_NUM_SHADER_BINARY_FORMATS,
232 GL_BIND_GENERATES_RESOURCE_CHROMIUM,
233 };
234
235 GetMultipleIntegervState integerv_state(
236 pnames, arraysize(pnames),
237 &static_state_.int_state.max_combined_texture_image_units,
238 sizeof(static_state_.int_state));
239 if (!GetMultipleIntegervSetup(&integerv_state)) {
240 return false;
241 }
242
243 // Setup query for multiple GetShaderPrecisionFormat's
244 static const GLenum precision_params[][2] = {
245 { GL_VERTEX_SHADER, GL_LOW_INT },
246 { GL_VERTEX_SHADER, GL_MEDIUM_INT },
247 { GL_VERTEX_SHADER, GL_HIGH_INT },
248 { GL_VERTEX_SHADER, GL_LOW_FLOAT },
249 { GL_VERTEX_SHADER, GL_MEDIUM_FLOAT },
250 { GL_VERTEX_SHADER, GL_HIGH_FLOAT },
251 { GL_FRAGMENT_SHADER, GL_LOW_INT },
252 { GL_FRAGMENT_SHADER, GL_MEDIUM_INT },
253 { GL_FRAGMENT_SHADER, GL_HIGH_INT },
254 { GL_FRAGMENT_SHADER, GL_LOW_FLOAT },
255 { GL_FRAGMENT_SHADER, GL_MEDIUM_FLOAT },
256 { GL_FRAGMENT_SHADER, GL_HIGH_FLOAT },
257 };
258
259 GetAllShaderPrecisionFormatsState precision_state(
260 precision_params, arraysize(precision_params));
261 GetAllShaderPrecisionFormatsSetup(&precision_state);
262
263 // Allocate and partition transfer buffer for all requests
264 void* buffer = transfer_buffer_->Alloc(
265 integerv_state.transfer_buffer_size_needed +
266 precision_state.transfer_buffer_size_needed);
267 if (!buffer) {
268 SetGLError(GL_OUT_OF_MEMORY, "QueryAndCacheStaticState",
269 "Transfer buffer allocation failed.");
270 return false;
271 }
272 integerv_state.buffer = buffer;
273 precision_state.results_buffer =
274 static_cast<char*>(buffer) + integerv_state.transfer_buffer_size_needed;
275
276 // Make all the requests and wait once for all the results.
277 GetMultipleIntegervRequest(&integerv_state);
278 GetAllShaderPrecisionFormatsRequest(&precision_state);
279 WaitForCmd();
280 GetMultipleIntegervOnCompleted(&integerv_state);
281 GetAllShaderPrecisionFormatsOnCompleted(&precision_state);
282
283 // TODO(gman): We should be able to free without a token.
284 transfer_buffer_->FreePendingToken(buffer, helper_->InsertToken());
285 CheckGLError();
286
287 return true;
288 }
289
290 GLES2Implementation::~GLES2Implementation() { 205 GLES2Implementation::~GLES2Implementation() {
291 // Make sure the queries are finished otherwise we'll delete the 206 // Make sure the queries are finished otherwise we'll delete the
292 // shared memory (mapped_memory_) which will free the memory used 207 // shared memory (mapped_memory_) which will free the memory used
293 // by the queries. The GPU process when validating that memory is still 208 // by the queries. The GPU process when validating that memory is still
294 // shared will fail and abort (ie, it will stop running). 209 // shared will fail and abort (ie, it will stop running).
295 WaitForCmd(); 210 WaitForCmd();
296 query_tracker_.reset(); 211 query_tracker_.reset();
297 212
298 if (support_client_side_arrays_) 213 if (support_client_side_arrays_)
299 DeleteBuffers(arraysize(reserved_ids_), &reserved_ids_[0]); 214 DeleteBuffers(arraysize(reserved_ids_), &reserved_ids_[0]);
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 } 591 }
677 592
678 GPU_CLIENT_LOG("returned " << state); 593 GPU_CLIENT_LOG("returned " << state);
679 CheckGLError(); 594 CheckGLError();
680 return state; 595 return state;
681 } 596 }
682 597
683 bool GLES2Implementation::GetHelper(GLenum pname, GLint* params) { 598 bool GLES2Implementation::GetHelper(GLenum pname, GLint* params) {
684 switch (pname) { 599 switch (pname) {
685 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: 600 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
686 *params = static_state_.int_state.max_combined_texture_image_units; 601 *params = capabilities_.max_combined_texture_image_units;
687 return true; 602 return true;
688 case GL_MAX_CUBE_MAP_TEXTURE_SIZE: 603 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
689 *params = static_state_.int_state.max_cube_map_texture_size; 604 *params = capabilities_.max_cube_map_texture_size;
690 return true; 605 return true;
691 case GL_MAX_FRAGMENT_UNIFORM_VECTORS: 606 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
692 *params = static_state_.int_state.max_fragment_uniform_vectors; 607 *params = capabilities_.max_fragment_uniform_vectors;
693 return true; 608 return true;
694 case GL_MAX_RENDERBUFFER_SIZE: 609 case GL_MAX_RENDERBUFFER_SIZE:
695 *params = static_state_.int_state.max_renderbuffer_size; 610 *params = capabilities_.max_renderbuffer_size;
696 return true; 611 return true;
697 case GL_MAX_TEXTURE_IMAGE_UNITS: 612 case GL_MAX_TEXTURE_IMAGE_UNITS:
698 *params = static_state_.int_state.max_texture_image_units; 613 *params = capabilities_.max_texture_image_units;
699 return true; 614 return true;
700 case GL_MAX_TEXTURE_SIZE: 615 case GL_MAX_TEXTURE_SIZE:
701 *params = static_state_.int_state.max_texture_size; 616 *params = capabilities_.max_texture_size;
702 return true; 617 return true;
703 case GL_MAX_VARYING_VECTORS: 618 case GL_MAX_VARYING_VECTORS:
704 *params = static_state_.int_state.max_varying_vectors; 619 *params = capabilities_.max_varying_vectors;
705 return true; 620 return true;
706 case GL_MAX_VERTEX_ATTRIBS: 621 case GL_MAX_VERTEX_ATTRIBS:
707 *params = static_state_.int_state.max_vertex_attribs; 622 *params = capabilities_.max_vertex_attribs;
708 return true; 623 return true;
709 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: 624 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
710 *params = static_state_.int_state.max_vertex_texture_image_units; 625 *params = capabilities_.max_vertex_texture_image_units;
711 return true; 626 return true;
712 case GL_MAX_VERTEX_UNIFORM_VECTORS: 627 case GL_MAX_VERTEX_UNIFORM_VECTORS:
713 *params = static_state_.int_state.max_vertex_uniform_vectors; 628 *params = capabilities_.max_vertex_uniform_vectors;
714 return true; 629 return true;
715 case GL_NUM_COMPRESSED_TEXTURE_FORMATS: 630 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
716 *params = static_state_.int_state.num_compressed_texture_formats; 631 *params = capabilities_.num_compressed_texture_formats;
717 return true; 632 return true;
718 case GL_NUM_SHADER_BINARY_FORMATS: 633 case GL_NUM_SHADER_BINARY_FORMATS:
719 *params = static_state_.int_state.num_shader_binary_formats; 634 *params = capabilities_.num_shader_binary_formats;
720 return true; 635 return true;
721 case GL_ARRAY_BUFFER_BINDING: 636 case GL_ARRAY_BUFFER_BINDING:
722 if (share_group_->bind_generates_resource()) { 637 if (share_group_->bind_generates_resource()) {
723 *params = bound_array_buffer_id_; 638 *params = bound_array_buffer_id_;
724 return true; 639 return true;
725 } 640 }
726 return false; 641 return false;
727 case GL_ELEMENT_ARRAY_BUFFER_BINDING: 642 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
728 if (share_group_->bind_generates_resource()) { 643 if (share_group_->bind_generates_resource()) {
729 *params = 644 *params =
(...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after
2320 height -= num_rows; 2235 height -= num_rows;
2321 } 2236 }
2322 CheckGLError(); 2237 CheckGLError();
2323 } 2238 }
2324 2239
2325 void GLES2Implementation::ActiveTexture(GLenum texture) { 2240 void GLES2Implementation::ActiveTexture(GLenum texture) {
2326 GPU_CLIENT_SINGLE_THREAD_CHECK(); 2241 GPU_CLIENT_SINGLE_THREAD_CHECK();
2327 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glActiveTexture(" 2242 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glActiveTexture("
2328 << GLES2Util::GetStringEnum(texture) << ")"); 2243 << GLES2Util::GetStringEnum(texture) << ")");
2329 GLuint texture_index = texture - GL_TEXTURE0; 2244 GLuint texture_index = texture - GL_TEXTURE0;
2330 if (texture_index >= static_cast<GLuint>( 2245 if (texture_index >=
2331 static_state_.int_state.max_combined_texture_image_units)) { 2246 static_cast<GLuint>(capabilities_.max_combined_texture_image_units)) {
2332 SetGLErrorInvalidEnum( 2247 SetGLErrorInvalidEnum(
2333 "glActiveTexture", texture, "texture"); 2248 "glActiveTexture", texture, "texture");
2334 return; 2249 return;
2335 } 2250 }
2336 2251
2337 active_texture_unit_ = texture_index; 2252 active_texture_unit_ = texture_index;
2338 helper_->ActiveTexture(texture); 2253 helper_->ActiveTexture(texture);
2339 CheckGLError(); 2254 CheckGLError();
2340 } 2255 }
2341 2256
(...skipping 15 matching lines...) Expand all
2357 2272
2358 void GLES2Implementation::GenVertexArraysOESHelper( 2273 void GLES2Implementation::GenVertexArraysOESHelper(
2359 GLsizei n, const GLuint* arrays) { 2274 GLsizei n, const GLuint* arrays) {
2360 vertex_array_object_manager_->GenVertexArrays(n, arrays); 2275 vertex_array_object_manager_->GenVertexArrays(n, arrays);
2361 } 2276 }
2362 2277
2363 void GLES2Implementation::GenQueriesEXTHelper( 2278 void GLES2Implementation::GenQueriesEXTHelper(
2364 GLsizei /* n */, const GLuint* /* queries */) { 2279 GLsizei /* n */, const GLuint* /* queries */) {
2365 } 2280 }
2366 2281
2282 void GLES2Implementation::GenValuebuffersCHROMIUMHelper(
2283 GLsizei /* n */,
2284 const GLuint* /* valuebuffers */) {
2285 }
2286
2367 // NOTE #1: On old versions of OpenGL, calling glBindXXX with an unused id 2287 // NOTE #1: On old versions of OpenGL, calling glBindXXX with an unused id
2368 // generates a new resource. On newer versions of OpenGL they don't. The code 2288 // generates a new resource. On newer versions of OpenGL they don't. The code
2369 // related to binding below will need to change if we switch to the new OpenGL 2289 // related to binding below will need to change if we switch to the new OpenGL
2370 // model. Specifically it assumes a bind will succeed which is always true in 2290 // model. Specifically it assumes a bind will succeed which is always true in
2371 // the old model but possibly not true in the new model if another context has 2291 // the old model but possibly not true in the new model if another context has
2372 // deleted the resource. 2292 // deleted the resource.
2373 2293
2374 bool GLES2Implementation::BindBufferHelper( 2294 bool GLES2Implementation::BindBufferHelper(
2375 GLenum target, GLuint buffer_id) { 2295 GLenum target, GLuint buffer_id) {
2376 // TODO(gman): See note #1 above. 2296 // TODO(gman): See note #1 above.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
2506 GL_INVALID_OPERATION, "glBindVertexArrayOES", 2426 GL_INVALID_OPERATION, "glBindVertexArrayOES",
2507 "id was not generated with glGenVertexArrayOES"); 2427 "id was not generated with glGenVertexArrayOES");
2508 } 2428 }
2509 // Unlike other BindXXXHelpers we don't call MarkAsUsedForBind 2429 // Unlike other BindXXXHelpers we don't call MarkAsUsedForBind
2510 // because unlike other resources VertexArrayObject ids must 2430 // because unlike other resources VertexArrayObject ids must
2511 // be generated by GenVertexArrays. A random id to Bind will not 2431 // be generated by GenVertexArrays. A random id to Bind will not
2512 // generate a new object. 2432 // generate a new object.
2513 return changed; 2433 return changed;
2514 } 2434 }
2515 2435
2436 bool GLES2Implementation::BindValuebufferCHROMIUMHelper(GLenum target,
2437 GLuint valuebuffer) {
2438 bool changed = false;
2439 switch (target) {
2440 case GL_SUBSCRIBED_VALUES_BUFFER_CHROMIUM:
2441 if (bound_valuebuffer_ != valuebuffer) {
2442 bound_valuebuffer_ = valuebuffer;
2443 changed = true;
2444 }
2445 break;
2446 default:
2447 changed = true;
2448 break;
2449 }
2450 // TODO(gman): There's a bug here. If the target is invalid the ID will not be
2451 // used even though it's marked it as used here.
2452 GetIdHandler(id_namespaces::kValuebuffers)->MarkAsUsedForBind(valuebuffer);
2453 return changed;
2454 }
2455
2516 bool GLES2Implementation::UseProgramHelper(GLuint program) { 2456 bool GLES2Implementation::UseProgramHelper(GLuint program) {
2517 bool changed = false; 2457 bool changed = false;
2518 if (current_program_ != program) { 2458 if (current_program_ != program) {
2519 current_program_ = program; 2459 current_program_ = program;
2520 changed = true; 2460 changed = true;
2521 } 2461 }
2522 return changed; 2462 return changed;
2523 } 2463 }
2524 2464
2525 bool GLES2Implementation::IsBufferReservedId(GLuint id) { 2465 bool GLES2Implementation::IsBufferReservedId(GLuint id) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
2605 void GLES2Implementation::DeleteTexturesHelper( 2545 void GLES2Implementation::DeleteTexturesHelper(
2606 GLsizei n, const GLuint* textures) { 2546 GLsizei n, const GLuint* textures) {
2607 if (!GetIdHandler(id_namespaces::kTextures)->FreeIds( 2547 if (!GetIdHandler(id_namespaces::kTextures)->FreeIds(
2608 this, n, textures, &GLES2Implementation::DeleteTexturesStub)) { 2548 this, n, textures, &GLES2Implementation::DeleteTexturesStub)) {
2609 SetGLError( 2549 SetGLError(
2610 GL_INVALID_VALUE, 2550 GL_INVALID_VALUE,
2611 "glDeleteTextures", "id not created by this context."); 2551 "glDeleteTextures", "id not created by this context.");
2612 return; 2552 return;
2613 } 2553 }
2614 for (GLsizei ii = 0; ii < n; ++ii) { 2554 for (GLsizei ii = 0; ii < n; ++ii) {
2615 for (GLint tt = 0; 2555 for (GLint tt = 0; tt < capabilities_.max_combined_texture_image_units;
2616 tt < static_state_.int_state.max_combined_texture_image_units;
2617 ++tt) { 2556 ++tt) {
2618 TextureUnit& unit = texture_units_[tt]; 2557 TextureUnit& unit = texture_units_[tt];
2619 if (textures[ii] == unit.bound_texture_2d) { 2558 if (textures[ii] == unit.bound_texture_2d) {
2620 unit.bound_texture_2d = 0; 2559 unit.bound_texture_2d = 0;
2621 } 2560 }
2622 if (textures[ii] == unit.bound_texture_cube_map) { 2561 if (textures[ii] == unit.bound_texture_cube_map) {
2623 unit.bound_texture_cube_map = 0; 2562 unit.bound_texture_cube_map = 0;
2624 } 2563 }
2625 if (textures[ii] == unit.bound_texture_external_oes) { 2564 if (textures[ii] == unit.bound_texture_external_oes) {
2626 unit.bound_texture_external_oes = 0; 2565 unit.bound_texture_external_oes = 0;
2627 } 2566 }
2628 } 2567 }
2629 } 2568 }
2630 } 2569 }
2631 2570
2571 void GLES2Implementation::DeleteTexturesStub(GLsizei n,
2572 const GLuint* textures) {
2573 helper_->DeleteTexturesImmediate(n, textures);
2574 }
2575
2632 void GLES2Implementation::DeleteVertexArraysOESHelper( 2576 void GLES2Implementation::DeleteVertexArraysOESHelper(
2633 GLsizei n, const GLuint* arrays) { 2577 GLsizei n, const GLuint* arrays) {
2634 vertex_array_object_manager_->DeleteVertexArrays(n, arrays); 2578 vertex_array_object_manager_->DeleteVertexArrays(n, arrays);
2635 if (!GetIdHandler(id_namespaces::kVertexArrays)->FreeIds( 2579 if (!GetIdHandler(id_namespaces::kVertexArrays)->FreeIds(
2636 this, n, arrays, &GLES2Implementation::DeleteVertexArraysOESStub)) { 2580 this, n, arrays, &GLES2Implementation::DeleteVertexArraysOESStub)) {
2637 SetGLError( 2581 SetGLError(
2638 GL_INVALID_VALUE, 2582 GL_INVALID_VALUE,
2639 "glDeleteVertexArraysOES", "id not created by this context."); 2583 "glDeleteVertexArraysOES", "id not created by this context.");
2640 return; 2584 return;
2641 } 2585 }
2642 } 2586 }
2643 2587
2644 void GLES2Implementation::DeleteVertexArraysOESStub( 2588 void GLES2Implementation::DeleteVertexArraysOESStub(
2645 GLsizei n, const GLuint* arrays) { 2589 GLsizei n, const GLuint* arrays) {
2646 helper_->DeleteVertexArraysOESImmediate(n, arrays); 2590 helper_->DeleteVertexArraysOESImmediate(n, arrays);
2647 } 2591 }
2648 2592
2649 void GLES2Implementation::DeleteTexturesStub( 2593 void GLES2Implementation::DeleteValuebuffersCHROMIUMHelper(
2650 GLsizei n, const GLuint* textures) { 2594 GLsizei n,
2651 helper_->DeleteTexturesImmediate(n, textures); 2595 const GLuint* valuebuffers) {
2596 if (!GetIdHandler(id_namespaces::kValuebuffers)
2597 ->FreeIds(this, n, valuebuffers,
2598 &GLES2Implementation::DeleteValuebuffersCHROMIUMStub)) {
2599 SetGLError(GL_INVALID_VALUE, "glDeleteValuebuffersCHROMIUM",
2600 "id not created by this context.");
2601 return;
2602 }
2603 for (GLsizei ii = 0; ii < n; ++ii) {
2604 if (valuebuffers[ii] == bound_valuebuffer_) {
2605 bound_valuebuffer_ = 0;
2606 }
2607 }
2608 }
2609
2610 void GLES2Implementation::DeleteValuebuffersCHROMIUMStub(
2611 GLsizei n,
2612 const GLuint* valuebuffers) {
2613 helper_->DeleteValuebuffersCHROMIUMImmediate(n, valuebuffers);
2652 } 2614 }
2653 2615
2654 void GLES2Implementation::DisableVertexAttribArray(GLuint index) { 2616 void GLES2Implementation::DisableVertexAttribArray(GLuint index) {
2655 GPU_CLIENT_SINGLE_THREAD_CHECK(); 2617 GPU_CLIENT_SINGLE_THREAD_CHECK();
2656 GPU_CLIENT_LOG( 2618 GPU_CLIENT_LOG(
2657 "[" << GetLogPrefix() << "] glDisableVertexAttribArray(" << index << ")"); 2619 "[" << GetLogPrefix() << "] glDisableVertexAttribArray(" << index << ")");
2658 vertex_array_object_manager_->SetAttribEnable(index, false); 2620 vertex_array_object_manager_->SetAttribEnable(index, false);
2659 helper_->DisableVertexAttribArray(index); 2621 helper_->DisableVertexAttribArray(index);
2660 CheckGLError(); 2622 CheckGLError();
2661 } 2623 }
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
3027 GPU_CLIENT_SINGLE_THREAD_CHECK(); 2989 GPU_CLIENT_SINGLE_THREAD_CHECK();
3028 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glRateLimitOffscreenCHROMIUM()"); 2990 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glRateLimitOffscreenCHROMIUM()");
3029 // Wait if this would add too many rate limit tokens. 2991 // Wait if this would add too many rate limit tokens.
3030 if (rate_limit_tokens_.size() == kMaxSwapBuffers) { 2992 if (rate_limit_tokens_.size() == kMaxSwapBuffers) {
3031 helper_->WaitForToken(rate_limit_tokens_.front()); 2993 helper_->WaitForToken(rate_limit_tokens_.front());
3032 rate_limit_tokens_.pop(); 2994 rate_limit_tokens_.pop();
3033 } 2995 }
3034 rate_limit_tokens_.push(helper_->InsertToken()); 2996 rate_limit_tokens_.push(helper_->InsertToken());
3035 } 2997 }
3036 2998
3037 void GLES2Implementation::GetMultipleIntegervCHROMIUM(
3038 const GLenum* pnames, GLuint count, GLint* results, GLsizeiptr size) {
3039 GPU_CLIENT_SINGLE_THREAD_CHECK();
3040 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glGetMultipleIntegervCHROMIUM("
3041 << static_cast<const void*>(pnames) << ", "
3042 << count << ", " << results << ", "
3043 << size << ")");
3044 GPU_CLIENT_LOG_CODE_BLOCK({
3045 for (GLuint i = 0; i < count; ++i) {
3046 GPU_CLIENT_LOG(
3047 " " << i << ": " << GLES2Util::GetStringGLState(pnames[i]));
3048 }
3049 });
3050 DCHECK(size >= 0 && FitInt32NonNegative<GLsizeiptr>(size));
3051
3052 GetMultipleIntegervState state(pnames, count, results, size);
3053 if (!GetMultipleIntegervSetup(&state)) {
3054 return;
3055 }
3056 state.buffer = transfer_buffer_->Alloc(state.transfer_buffer_size_needed);
3057 if (!state.buffer) {
3058 SetGLError(GL_OUT_OF_MEMORY, "glGetMultipleIntegervCHROMIUM",
3059 "Transfer buffer allocation failed.");
3060 return;
3061 }
3062 GetMultipleIntegervRequest(&state);
3063 WaitForCmd();
3064 GetMultipleIntegervOnCompleted(&state);
3065
3066 GPU_CLIENT_LOG(" returned");
3067 GPU_CLIENT_LOG_CODE_BLOCK({
3068 for (int i = 0; i < state.num_results; ++i) {
3069 GPU_CLIENT_LOG(" " << i << ": " << (results[i]));
3070 }
3071 });
3072
3073 // TODO(gman): We should be able to free without a token.
3074 transfer_buffer_->FreePendingToken(state.buffer, helper_->InsertToken());
3075 CheckGLError();
3076 }
3077
3078 bool GLES2Implementation::GetMultipleIntegervSetup(
3079 GetMultipleIntegervState* state) {
3080 state->num_results = 0;
3081 for (GLuint ii = 0; ii < state->pnames_count; ++ii) {
3082 int num = util_.GLGetNumValuesReturned(state->pnames[ii]);
3083 if (!num) {
3084 SetGLErrorInvalidEnum(
3085 "glGetMultipleIntegervCHROMIUM", state->pnames[ii], "pname");
3086 return false;
3087 }
3088 state->num_results += num;
3089 }
3090 if (static_cast<size_t>(state->results_size) !=
3091 state->num_results * sizeof(GLint)) {
3092 SetGLError(GL_INVALID_VALUE, "glGetMultipleIntegervCHROMIUM", "bad size");
3093 return false;
3094 }
3095 for (int ii = 0; ii < state->num_results; ++ii) {
3096 if (state->results[ii] != 0) {
3097 SetGLError(GL_INVALID_VALUE,
3098 "glGetMultipleIntegervCHROMIUM", "results not set to zero.");
3099 return false;
3100 }
3101 }
3102 state->transfer_buffer_size_needed =
3103 state->pnames_count * sizeof(state->pnames[0]) +
3104 state->num_results * sizeof(state->results[0]);
3105 return true;
3106 }
3107
3108 void GLES2Implementation::GetMultipleIntegervRequest(
3109 GetMultipleIntegervState* state) {
3110 GLenum* pnames_buffer = static_cast<GLenum*>(state->buffer);
3111 state->results_buffer = pnames_buffer + state->pnames_count;
3112 memcpy(pnames_buffer, state->pnames, state->pnames_count * sizeof(GLenum));
3113 memset(state->results_buffer, 0, state->num_results * sizeof(GLint));
3114 helper_->GetMultipleIntegervCHROMIUM(
3115 transfer_buffer_->GetShmId(),
3116 transfer_buffer_->GetOffset(pnames_buffer),
3117 state->pnames_count,
3118 transfer_buffer_->GetShmId(),
3119 transfer_buffer_->GetOffset(state->results_buffer),
3120 state->results_size);
3121 }
3122
3123 void GLES2Implementation::GetMultipleIntegervOnCompleted(
3124 GetMultipleIntegervState* state) {
3125 memcpy(state->results, state->results_buffer, state->results_size);;
3126 }
3127
3128 void GLES2Implementation::GetAllShaderPrecisionFormatsSetup(
3129 GetAllShaderPrecisionFormatsState* state) {
3130 state->transfer_buffer_size_needed =
3131 state->precision_params_count *
3132 sizeof(cmds::GetShaderPrecisionFormat::Result);
3133 }
3134
3135 void GLES2Implementation::GetAllShaderPrecisionFormatsRequest(
3136 GetAllShaderPrecisionFormatsState* state) {
3137 typedef cmds::GetShaderPrecisionFormat::Result Result;
3138 Result* result = static_cast<Result*>(state->results_buffer);
3139
3140 for (int i = 0; i < state->precision_params_count; i++) {
3141 result->success = false;
3142 helper_->GetShaderPrecisionFormat(state->precision_params[i][0],
3143 state->precision_params[i][1],
3144 transfer_buffer_->GetShmId(),
3145 transfer_buffer_->GetOffset(result));
3146 result++;
3147 }
3148 }
3149
3150 void GLES2Implementation::GetAllShaderPrecisionFormatsOnCompleted(
3151 GetAllShaderPrecisionFormatsState* state) {
3152 typedef cmds::GetShaderPrecisionFormat::Result Result;
3153 Result* result = static_cast<Result*>(state->results_buffer);
3154
3155 for (int i = 0; i < state->precision_params_count; i++) {
3156 if (result->success) {
3157 const GLStaticState::ShaderPrecisionKey key(
3158 state->precision_params[i][0], state->precision_params[i][1]);
3159 static_state_.shader_precisions[key] = *result;
3160 }
3161 result++;
3162 }
3163 }
3164
3165 void GLES2Implementation::GetProgramInfoCHROMIUMHelper( 2999 void GLES2Implementation::GetProgramInfoCHROMIUMHelper(
3166 GLuint program, std::vector<int8>* result) { 3000 GLuint program, std::vector<int8>* result) {
3167 DCHECK(result); 3001 DCHECK(result);
3168 // Clear the bucket so if the command fails nothing will be in it. 3002 // Clear the bucket so if the command fails nothing will be in it.
3169 helper_->SetBucketSize(kResultBucketId, 0); 3003 helper_->SetBucketSize(kResultBucketId, 0);
3170 helper_->GetProgramInfoCHROMIUM(program, kResultBucketId); 3004 helper_->GetProgramInfoCHROMIUM(program, kResultBucketId);
3171 GetBucketContents(kResultBucketId, result); 3005 GetBucketContents(kResultBucketId, result);
3172 } 3006 }
3173 3007
3174 void GLES2Implementation::GetProgramInfoCHROMIUM( 3008 void GLES2Implementation::GetProgramInfoCHROMIUM(
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after
4068 return true; 3902 return true;
4069 } 3903 }
4070 3904
4071 // Include the auto-generated part of this file. We split this because it means 3905 // Include the auto-generated part of this file. We split this because it means
4072 // we can easily edit the non-auto generated parts right here in this file 3906 // we can easily edit the non-auto generated parts right here in this file
4073 // instead of having to edit some template or the code generator. 3907 // instead of having to edit some template or the code generator.
4074 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" 3908 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h"
4075 3909
4076 } // namespace gles2 3910 } // namespace gles2
4077 } // namespace gpu 3911 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation.h ('k') | gpu/command_buffer/client/gles2_implementation_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698