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 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <list> | 10 #include <list> |
(...skipping 2356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2367 // SetSurface. | 2367 // SetSurface. |
2368 context_ = context; | 2368 context_ = context; |
2369 surface_ = surface; | 2369 surface_ = surface; |
2370 | 2370 |
2371 ContextCreationAttribHelper attrib_parser; | 2371 ContextCreationAttribHelper attrib_parser; |
2372 if (!attrib_parser.Parse(attribs)) | 2372 if (!attrib_parser.Parse(attribs)) |
2373 return false; | 2373 return false; |
2374 | 2374 |
2375 // Save the loseContextWhenOutOfMemory context creation attribute. | 2375 // Save the loseContextWhenOutOfMemory context creation attribute. |
2376 lose_context_when_out_of_memory_ = | 2376 lose_context_when_out_of_memory_ = |
2377 attrib_parser.lose_context_when_out_of_memory_; | 2377 attrib_parser.lose_context_when_out_of_memory; |
2378 | 2378 |
2379 // If the failIfMajorPerformanceCaveat context creation attribute was true | 2379 // If the failIfMajorPerformanceCaveat context creation attribute was true |
2380 // and we are using a software renderer, fail. | 2380 // and we are using a software renderer, fail. |
2381 if (attrib_parser.fail_if_major_perf_caveat_ && | 2381 if (attrib_parser.fail_if_major_perf_caveat && |
2382 feature_info_->feature_flags().is_swiftshader) { | 2382 feature_info_->feature_flags().is_swiftshader) { |
2383 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. | 2383 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
2384 Destroy(true); | 2384 Destroy(true); |
2385 return false; | 2385 return false; |
2386 } | 2386 } |
2387 | 2387 |
2388 if (!group_->Initialize(this, disallowed_features)) { | 2388 if (!group_->Initialize(this, disallowed_features)) { |
2389 LOG(ERROR) << "GpuScheduler::InitializeCommon failed because group " | 2389 LOG(ERROR) << "GpuScheduler::InitializeCommon failed because group " |
2390 << "failed to initialize."; | 2390 << "failed to initialize."; |
2391 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. | 2391 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2454 state_.texture_units[tt].bound_texture_cube_map = ref; | 2454 state_.texture_units[tt].bound_texture_cube_map = ref; |
2455 glBindTexture(GL_TEXTURE_CUBE_MAP, ref ? ref->service_id() : 0); | 2455 glBindTexture(GL_TEXTURE_CUBE_MAP, ref ? ref->service_id() : 0); |
2456 ref = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); | 2456 ref = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); |
2457 state_.texture_units[tt].bound_texture_2d = ref; | 2457 state_.texture_units[tt].bound_texture_2d = ref; |
2458 glBindTexture(GL_TEXTURE_2D, ref ? ref->service_id() : 0); | 2458 glBindTexture(GL_TEXTURE_2D, ref ? ref->service_id() : 0); |
2459 } | 2459 } |
2460 glActiveTexture(GL_TEXTURE0); | 2460 glActiveTexture(GL_TEXTURE0); |
2461 CHECK_GL_ERROR(); | 2461 CHECK_GL_ERROR(); |
2462 | 2462 |
2463 if (offscreen) { | 2463 if (offscreen) { |
2464 if (attrib_parser.samples_ > 0 && attrib_parser.sample_buffers_ > 0 && | 2464 if (attrib_parser.samples > 0 && attrib_parser.sample_buffers > 0 && |
2465 features().chromium_framebuffer_multisample) { | 2465 features().chromium_framebuffer_multisample) { |
2466 // Per ext_framebuffer_multisample spec, need max bound on sample count. | 2466 // Per ext_framebuffer_multisample spec, need max bound on sample count. |
2467 // max_sample_count must be initialized to a sane value. If | 2467 // max_sample_count must be initialized to a sane value. If |
2468 // glGetIntegerv() throws a GL error, it leaves its argument unchanged. | 2468 // glGetIntegerv() throws a GL error, it leaves its argument unchanged. |
2469 GLint max_sample_count = 1; | 2469 GLint max_sample_count = 1; |
2470 glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_sample_count); | 2470 glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_sample_count); |
2471 offscreen_target_samples_ = std::min(attrib_parser.samples_, | 2471 offscreen_target_samples_ = std::min(attrib_parser.samples, |
2472 max_sample_count); | 2472 max_sample_count); |
2473 } else { | 2473 } else { |
2474 offscreen_target_samples_ = 1; | 2474 offscreen_target_samples_ = 1; |
2475 } | 2475 } |
2476 offscreen_target_buffer_preserved_ = attrib_parser.buffer_preserved_; | 2476 offscreen_target_buffer_preserved_ = attrib_parser.buffer_preserved; |
2477 | 2477 |
2478 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { | 2478 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
2479 const bool rgb8_supported = | 2479 const bool rgb8_supported = |
2480 context_->HasExtension("GL_OES_rgb8_rgba8"); | 2480 context_->HasExtension("GL_OES_rgb8_rgba8"); |
2481 // The only available default render buffer formats in GLES2 have very | 2481 // The only available default render buffer formats in GLES2 have very |
2482 // little precision. Don't enable multisampling unless 8-bit render | 2482 // little precision. Don't enable multisampling unless 8-bit render |
2483 // buffer formats are available--instead fall back to 8-bit textures. | 2483 // buffer formats are available--instead fall back to 8-bit textures. |
2484 if (rgb8_supported && offscreen_target_samples_ > 1) { | 2484 if (rgb8_supported && offscreen_target_samples_ > 1) { |
2485 offscreen_target_color_format_ = attrib_parser.alpha_size_ > 0 ? | 2485 offscreen_target_color_format_ = attrib_parser.alpha_size > 0 ? |
2486 GL_RGBA8 : GL_RGB8; | 2486 GL_RGBA8 : GL_RGB8; |
2487 } else { | 2487 } else { |
2488 offscreen_target_samples_ = 1; | 2488 offscreen_target_samples_ = 1; |
2489 offscreen_target_color_format_ = attrib_parser.alpha_size_ > 0 ? | 2489 offscreen_target_color_format_ = attrib_parser.alpha_size > 0 ? |
2490 GL_RGBA : GL_RGB; | 2490 GL_RGBA : GL_RGB; |
2491 } | 2491 } |
2492 | 2492 |
2493 // ANGLE only supports packed depth/stencil formats, so use it if it is | 2493 // ANGLE only supports packed depth/stencil formats, so use it if it is |
2494 // available. | 2494 // available. |
2495 const bool depth24_stencil8_supported = | 2495 const bool depth24_stencil8_supported = |
2496 feature_info_->feature_flags().packed_depth24_stencil8; | 2496 feature_info_->feature_flags().packed_depth24_stencil8; |
2497 VLOG(1) << "GL_OES_packed_depth_stencil " | 2497 VLOG(1) << "GL_OES_packed_depth_stencil " |
2498 << (depth24_stencil8_supported ? "" : "not ") << "supported."; | 2498 << (depth24_stencil8_supported ? "" : "not ") << "supported."; |
2499 if ((attrib_parser.depth_size_ > 0 || attrib_parser.stencil_size_ > 0) && | 2499 if ((attrib_parser.depth_size > 0 || attrib_parser.stencil_size > 0) && |
2500 depth24_stencil8_supported) { | 2500 depth24_stencil8_supported) { |
2501 offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; | 2501 offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; |
2502 offscreen_target_stencil_format_ = 0; | 2502 offscreen_target_stencil_format_ = 0; |
2503 } else { | 2503 } else { |
2504 // It may be the case that this depth/stencil combination is not | 2504 // It may be the case that this depth/stencil combination is not |
2505 // supported, but this will be checked later by CheckFramebufferStatus. | 2505 // supported, but this will be checked later by CheckFramebufferStatus. |
2506 offscreen_target_depth_format_ = attrib_parser.depth_size_ > 0 ? | 2506 offscreen_target_depth_format_ = attrib_parser.depth_size > 0 ? |
2507 GL_DEPTH_COMPONENT16 : 0; | 2507 GL_DEPTH_COMPONENT16 : 0; |
2508 offscreen_target_stencil_format_ = attrib_parser.stencil_size_ > 0 ? | 2508 offscreen_target_stencil_format_ = attrib_parser.stencil_size > 0 ? |
2509 GL_STENCIL_INDEX8 : 0; | 2509 GL_STENCIL_INDEX8 : 0; |
2510 } | 2510 } |
2511 } else { | 2511 } else { |
2512 offscreen_target_color_format_ = attrib_parser.alpha_size_ > 0 ? | 2512 offscreen_target_color_format_ = attrib_parser.alpha_size > 0 ? |
2513 GL_RGBA : GL_RGB; | 2513 GL_RGBA : GL_RGB; |
2514 | 2514 |
2515 // If depth is requested at all, use the packed depth stencil format if | 2515 // If depth is requested at all, use the packed depth stencil format if |
2516 // it's available, as some desktop GL drivers don't support any non-packed | 2516 // it's available, as some desktop GL drivers don't support any non-packed |
2517 // formats for depth attachments. | 2517 // formats for depth attachments. |
2518 const bool depth24_stencil8_supported = | 2518 const bool depth24_stencil8_supported = |
2519 feature_info_->feature_flags().packed_depth24_stencil8; | 2519 feature_info_->feature_flags().packed_depth24_stencil8; |
2520 VLOG(1) << "GL_EXT_packed_depth_stencil " | 2520 VLOG(1) << "GL_EXT_packed_depth_stencil " |
2521 << (depth24_stencil8_supported ? "" : "not ") << "supported."; | 2521 << (depth24_stencil8_supported ? "" : "not ") << "supported."; |
2522 | 2522 |
2523 if ((attrib_parser.depth_size_ > 0 || attrib_parser.stencil_size_ > 0) && | 2523 if ((attrib_parser.depth_size > 0 || attrib_parser.stencil_size > 0) && |
2524 depth24_stencil8_supported) { | 2524 depth24_stencil8_supported) { |
2525 offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; | 2525 offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; |
2526 offscreen_target_stencil_format_ = 0; | 2526 offscreen_target_stencil_format_ = 0; |
2527 } else { | 2527 } else { |
2528 offscreen_target_depth_format_ = attrib_parser.depth_size_ > 0 ? | 2528 offscreen_target_depth_format_ = attrib_parser.depth_size > 0 ? |
2529 GL_DEPTH_COMPONENT : 0; | 2529 GL_DEPTH_COMPONENT : 0; |
2530 offscreen_target_stencil_format_ = attrib_parser.stencil_size_ > 0 ? | 2530 offscreen_target_stencil_format_ = attrib_parser.stencil_size > 0 ? |
2531 GL_STENCIL_INDEX : 0; | 2531 GL_STENCIL_INDEX : 0; |
2532 } | 2532 } |
2533 } | 2533 } |
2534 | 2534 |
2535 offscreen_saved_color_format_ = attrib_parser.alpha_size_ > 0 ? | 2535 offscreen_saved_color_format_ = attrib_parser.alpha_size > 0 ? |
2536 GL_RGBA : GL_RGB; | 2536 GL_RGBA : GL_RGB; |
2537 | 2537 |
2538 // Create the target frame buffer. This is the one that the client renders | 2538 // Create the target frame buffer. This is the one that the client renders |
2539 // directly to. | 2539 // directly to. |
2540 offscreen_target_frame_buffer_.reset(new BackFramebuffer(this)); | 2540 offscreen_target_frame_buffer_.reset(new BackFramebuffer(this)); |
2541 offscreen_target_frame_buffer_->Create(); | 2541 offscreen_target_frame_buffer_->Create(); |
2542 // Due to GLES2 format limitations, either the color texture (for | 2542 // Due to GLES2 format limitations, either the color texture (for |
2543 // non-multisampling) or the color render buffer (for multisampling) will be | 2543 // non-multisampling) or the color render buffer (for multisampling) will be |
2544 // attached to the offscreen frame buffer. The render buffer has more | 2544 // attached to the offscreen frame buffer. The render buffer has more |
2545 // limited formats available to it, but the texture can't do multisampling. | 2545 // limited formats available to it, but the texture can't do multisampling. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2601 // we ask for. In other words, if we ask for RGB and we get RGBA then we'll | 2601 // we ask for. In other words, if we ask for RGB and we get RGBA then we'll |
2602 // make it appear RGB. If on the other hand we ask for RGBA nd get RGB we | 2602 // make it appear RGB. If on the other hand we ask for RGBA nd get RGB we |
2603 // can't do anything about that. | 2603 // can't do anything about that. |
2604 | 2604 |
2605 GLint v = 0; | 2605 GLint v = 0; |
2606 glGetIntegerv(GL_ALPHA_BITS, &v); | 2606 glGetIntegerv(GL_ALPHA_BITS, &v); |
2607 // This checks if the user requested RGBA and we have RGBA then RGBA. If the | 2607 // This checks if the user requested RGBA and we have RGBA then RGBA. If the |
2608 // user requested RGB then RGB. If the user did not specify a preference | 2608 // user requested RGB then RGB. If the user did not specify a preference |
2609 // than use whatever we were given. Same for DEPTH and STENCIL. | 2609 // than use whatever we were given. Same for DEPTH and STENCIL. |
2610 back_buffer_color_format_ = | 2610 back_buffer_color_format_ = |
2611 (attrib_parser.alpha_size_ != 0 && v > 0) ? GL_RGBA : GL_RGB; | 2611 (attrib_parser.alpha_size != 0 && v > 0) ? GL_RGBA : GL_RGB; |
2612 glGetIntegerv(GL_DEPTH_BITS, &v); | 2612 glGetIntegerv(GL_DEPTH_BITS, &v); |
2613 back_buffer_has_depth_ = attrib_parser.depth_size_ != 0 && v > 0; | 2613 back_buffer_has_depth_ = attrib_parser.depth_size != 0 && v > 0; |
2614 glGetIntegerv(GL_STENCIL_BITS, &v); | 2614 glGetIntegerv(GL_STENCIL_BITS, &v); |
2615 back_buffer_has_stencil_ = attrib_parser.stencil_size_ != 0 && v > 0; | 2615 back_buffer_has_stencil_ = attrib_parser.stencil_size != 0 && v > 0; |
2616 } | 2616 } |
2617 | 2617 |
2618 // OpenGL ES 2.0 implicitly enables the desktop GL capability | 2618 // OpenGL ES 2.0 implicitly enables the desktop GL capability |
2619 // VERTEX_PROGRAM_POINT_SIZE and doesn't expose this enum. This fact | 2619 // VERTEX_PROGRAM_POINT_SIZE and doesn't expose this enum. This fact |
2620 // isn't well documented; it was discovered in the Khronos OpenGL ES | 2620 // isn't well documented; it was discovered in the Khronos OpenGL ES |
2621 // mailing list archives. It also implicitly enables the desktop GL | 2621 // mailing list archives. It also implicitly enables the desktop GL |
2622 // capability GL_POINT_SPRITE to provide access to the gl_PointCoord | 2622 // capability GL_POINT_SPRITE to provide access to the gl_PointCoord |
2623 // variable in fragment shaders. | 2623 // variable in fragment shaders. |
2624 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { | 2624 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
2625 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); | 2625 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); |
(...skipping 8304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10930 } | 10930 } |
10931 } | 10931 } |
10932 | 10932 |
10933 // Include the auto-generated part of this file. We split this because it means | 10933 // Include the auto-generated part of this file. We split this because it means |
10934 // we can easily edit the non-auto generated parts right here in this file | 10934 // we can easily edit the non-auto generated parts right here in this file |
10935 // instead of having to edit some template or the code generator. | 10935 // instead of having to edit some template or the code generator. |
10936 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 10936 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
10937 | 10937 |
10938 } // namespace gles2 | 10938 } // namespace gles2 |
10939 } // namespace gpu | 10939 } // namespace gpu |
OLD | NEW |