Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 #include "gpu/command_buffer/service/mailbox_manager.h" | 45 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 46 #include "gpu/command_buffer/service/memory_tracking.h" | 46 #include "gpu/command_buffer/service/memory_tracking.h" |
| 47 #include "gpu/command_buffer/service/program_manager.h" | 47 #include "gpu/command_buffer/service/program_manager.h" |
| 48 #include "gpu/command_buffer/service/query_manager.h" | 48 #include "gpu/command_buffer/service/query_manager.h" |
| 49 #include "gpu/command_buffer/service/renderbuffer_manager.h" | 49 #include "gpu/command_buffer/service/renderbuffer_manager.h" |
| 50 #include "gpu/command_buffer/service/shader_manager.h" | 50 #include "gpu/command_buffer/service/shader_manager.h" |
| 51 #include "gpu/command_buffer/service/shader_translator.h" | 51 #include "gpu/command_buffer/service/shader_translator.h" |
| 52 #include "gpu/command_buffer/service/shader_translator_cache.h" | 52 #include "gpu/command_buffer/service/shader_translator_cache.h" |
| 53 #include "gpu/command_buffer/service/stream_texture.h" | 53 #include "gpu/command_buffer/service/stream_texture.h" |
| 54 #include "gpu/command_buffer/service/stream_texture_manager.h" | 54 #include "gpu/command_buffer/service/stream_texture_manager.h" |
| 55 #include "gpu/command_buffer/service/texture_definition.h" | |
| 56 #include "gpu/command_buffer/service/texture_manager.h" | 55 #include "gpu/command_buffer/service/texture_manager.h" |
| 57 #include "gpu/command_buffer/service/vertex_attrib_manager.h" | 56 #include "gpu/command_buffer/service/vertex_attrib_manager.h" |
| 58 #include "gpu/command_buffer/service/vertex_array_manager.h" | 57 #include "gpu/command_buffer/service/vertex_array_manager.h" |
| 59 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" | 58 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" |
| 60 #include "ui/gl/gl_bindings.h" | 59 #include "ui/gl/gl_bindings.h" |
| 61 #include "ui/gl/gl_image.h" | 60 #include "ui/gl/gl_image.h" |
| 62 #include "ui/gl/gl_implementation.h" | 61 #include "ui/gl/gl_implementation.h" |
| 63 #include "ui/gl/gl_surface.h" | 62 #include "ui/gl/gl_surface.h" |
| 64 #if defined(OS_MACOSX) | 63 #if defined(OS_MACOSX) |
| 65 #include "ui/surface/io_surface_support_mac.h" | 64 #include "ui/surface/io_surface_support_mac.h" |
| (...skipping 2188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2254 state_.texture_units[tt].bound_texture_2d = ref; | 2253 state_.texture_units[tt].bound_texture_2d = ref; |
| 2255 glBindTexture(GL_TEXTURE_2D, ref->service_id()); | 2254 glBindTexture(GL_TEXTURE_2D, ref->service_id()); |
| 2256 } | 2255 } |
| 2257 glActiveTexture(GL_TEXTURE0); | 2256 glActiveTexture(GL_TEXTURE0); |
| 2258 CHECK_GL_ERROR(); | 2257 CHECK_GL_ERROR(); |
| 2259 | 2258 |
| 2260 ContextCreationAttribParser attrib_parser; | 2259 ContextCreationAttribParser attrib_parser; |
| 2261 if (!attrib_parser.Parse(attribs)) | 2260 if (!attrib_parser.Parse(attribs)) |
| 2262 return false; | 2261 return false; |
| 2263 | 2262 |
| 2264 // These are NOT if the back buffer has these proprorties. They are | |
| 2265 // if we want the command buffer to enforce them regardless of what | |
| 2266 // the real backbuffer is assuming the real back buffer gives us more than | |
| 2267 // we ask for. In other words, if we ask for RGB and we get RGBA then we'll | |
| 2268 // make it appear RGB. If on the other hand we ask for RGBA nd get RGB we | |
| 2269 // can't do anything about that. | |
| 2270 | |
| 2271 GLint v = 0; | |
| 2272 glGetIntegerv(GL_ALPHA_BITS, &v); | |
| 2273 // This checks if the user requested RGBA and we have RGBA then RGBA. If the | |
| 2274 // user requested RGB then RGB. If the user did not specify a preference than | |
| 2275 // use whatever we were given. Same for DEPTH and STENCIL. | |
| 2276 back_buffer_color_format_ = | |
| 2277 (attrib_parser.alpha_size_ != 0 && v > 0) ? GL_RGBA : GL_RGB; | |
| 2278 glGetIntegerv(GL_DEPTH_BITS, &v); | |
| 2279 back_buffer_has_depth_ = attrib_parser.depth_size_ != 0 && v > 0; | |
| 2280 glGetIntegerv(GL_STENCIL_BITS, &v); | |
| 2281 back_buffer_has_stencil_ = attrib_parser.stencil_size_ != 0 && v > 0; | |
| 2282 | |
| 2283 if (offscreen) { | 2263 if (offscreen) { |
| 2284 if (attrib_parser.samples_ > 0 && attrib_parser.sample_buffers_ > 0 && | 2264 if (attrib_parser.samples_ > 0 && attrib_parser.sample_buffers_ > 0 && |
| 2285 features().chromium_framebuffer_multisample) { | 2265 features().chromium_framebuffer_multisample) { |
| 2286 // Per ext_framebuffer_multisample spec, need max bound on sample count. | 2266 // Per ext_framebuffer_multisample spec, need max bound on sample count. |
| 2287 // max_sample_count must be initialized to a sane value. If | 2267 // max_sample_count must be initialized to a sane value. If |
| 2288 // glGetIntegerv() throws a GL error, it leaves its argument unchanged. | 2268 // glGetIntegerv() throws a GL error, it leaves its argument unchanged. |
| 2289 GLint max_sample_count = 1; | 2269 GLint max_sample_count = 1; |
| 2290 glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_sample_count); | 2270 glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_sample_count); |
| 2291 offscreen_target_samples_ = std::min(attrib_parser.samples_, | 2271 offscreen_target_samples_ = std::min(attrib_parser.samples_, |
| 2292 max_sample_count); | 2272 max_sample_count); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2401 if (offscreen_saved_frame_buffer_->CheckStatus() != | 2381 if (offscreen_saved_frame_buffer_->CheckStatus() != |
| 2402 GL_FRAMEBUFFER_COMPLETE) { | 2382 GL_FRAMEBUFFER_COMPLETE) { |
| 2403 LOG(ERROR) << "Offscreen saved FBO was incomplete."; | 2383 LOG(ERROR) << "Offscreen saved FBO was incomplete."; |
| 2404 Destroy(true); | 2384 Destroy(true); |
| 2405 return false; | 2385 return false; |
| 2406 } | 2386 } |
| 2407 | 2387 |
| 2408 // Bind to the new default frame buffer (the offscreen target frame buffer). | 2388 // Bind to the new default frame buffer (the offscreen target frame buffer). |
| 2409 // This should now be associated with ID zero. | 2389 // This should now be associated with ID zero. |
| 2410 DoBindFramebuffer(GL_FRAMEBUFFER, 0); | 2390 DoBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 2391 } else { | |
| 2392 glBindFramebufferEXT(GL_FRAMEBUFFER, GetBackbufferServiceId()); | |
| 2393 // These are NOT if the back buffer has these proprorties. They are | |
| 2394 // if we want the command buffer to enforce them regardless of what | |
| 2395 // the real backbuffer is assuming the real back buffer gives us more than | |
| 2396 // we ask for. In other words, if we ask for RGB and we get RGBA then we'll | |
| 2397 // make it appear RGB. If on the other hand we ask for RGBA nd get RGB we | |
| 2398 // can't do anything about that. | |
| 2399 | |
| 2400 GLint v = 0; | |
| 2401 glGetIntegerv(GL_ALPHA_BITS, &v); | |
| 2402 // This checks if the user requested RGBA and we have RGBA then RGBA. If the | |
| 2403 // user requested RGB then RGB. If the user did not specify a preference | |
| 2404 // than use whatever we were given. Same for DEPTH and STENCIL. | |
| 2405 back_buffer_color_format_ = | |
| 2406 (attrib_parser.alpha_size_ != 0 && v > 0) ? GL_RGBA : GL_RGB; | |
| 2407 glGetIntegerv(GL_DEPTH_BITS, &v); | |
| 2408 back_buffer_has_depth_ = attrib_parser.depth_size_ != 0 && v > 0; | |
| 2409 glGetIntegerv(GL_STENCIL_BITS, &v); | |
| 2410 back_buffer_has_stencil_ = attrib_parser.stencil_size_ != 0 && v > 0; | |
|
piman
2013/05/23 02:33:01
These values are only used in the !offscreen case,
| |
| 2411 } | 2411 } |
| 2412 | 2412 |
| 2413 // OpenGL ES 2.0 implicitly enables the desktop GL capability | 2413 // OpenGL ES 2.0 implicitly enables the desktop GL capability |
| 2414 // VERTEX_PROGRAM_POINT_SIZE and doesn't expose this enum. This fact | 2414 // VERTEX_PROGRAM_POINT_SIZE and doesn't expose this enum. This fact |
| 2415 // isn't well documented; it was discovered in the Khronos OpenGL ES | 2415 // isn't well documented; it was discovered in the Khronos OpenGL ES |
| 2416 // mailing list archives. It also implicitly enables the desktop GL | 2416 // mailing list archives. It also implicitly enables the desktop GL |
| 2417 // capability GL_POINT_SPRITE to provide access to the gl_PointCoord | 2417 // capability GL_POINT_SPRITE to provide access to the gl_PointCoord |
| 2418 // variable in fragment shaders. | 2418 // variable in fragment shaders. |
| 2419 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { | 2419 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 2420 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); | 2420 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); |
| (...skipping 7427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9848 "mailbox[0]", static_cast<unsigned char>(mailbox[0])); | 9848 "mailbox[0]", static_cast<unsigned char>(mailbox[0])); |
| 9849 | 9849 |
| 9850 TextureRef* texture_ref = GetTextureInfoForTarget(target); | 9850 TextureRef* texture_ref = GetTextureInfoForTarget(target); |
| 9851 if (!texture_ref) { | 9851 if (!texture_ref) { |
| 9852 LOCAL_SET_GL_ERROR( | 9852 LOCAL_SET_GL_ERROR( |
| 9853 GL_INVALID_OPERATION, | 9853 GL_INVALID_OPERATION, |
| 9854 "glProduceTextureCHROMIUM", "unknown texture for target"); | 9854 "glProduceTextureCHROMIUM", "unknown texture for target"); |
| 9855 return; | 9855 return; |
| 9856 } | 9856 } |
| 9857 | 9857 |
| 9858 TextureDefinition* definition = texture_manager()->Save(texture_ref); | 9858 Texture* produced = texture_manager()->Produce(texture_ref); |
| 9859 if (!definition) { | 9859 if (!produced) { |
| 9860 LOCAL_SET_GL_ERROR( | 9860 LOCAL_SET_GL_ERROR( |
| 9861 GL_INVALID_OPERATION, | 9861 GL_INVALID_OPERATION, |
| 9862 "glProduceTextureCHROMIUM", "invalid texture"); | 9862 "glProduceTextureCHROMIUM", "invalid texture"); |
| 9863 return; | 9863 return; |
| 9864 } | 9864 } |
| 9865 | 9865 |
| 9866 if (!group_->mailbox_manager()->ProduceTexture( | 9866 if (!group_->mailbox_manager()->ProduceTexture( |
| 9867 target, | 9867 target, |
| 9868 *reinterpret_cast<const MailboxName*>(mailbox), | 9868 *reinterpret_cast<const MailboxName*>(mailbox), |
| 9869 definition, | 9869 produced)) { |
| 9870 texture_manager())) { | |
| 9871 bool success = texture_manager()->Restore( | |
| 9872 "glProductTextureCHROMIUM", this, texture_ref, definition); | |
| 9873 DCHECK(success); | |
| 9874 LOCAL_SET_GL_ERROR( | 9870 LOCAL_SET_GL_ERROR( |
| 9875 GL_INVALID_OPERATION, | 9871 GL_INVALID_OPERATION, |
| 9876 "glProduceTextureCHROMIUM", "invalid mailbox name"); | 9872 "glProduceTextureCHROMIUM", "invalid mailbox name"); |
| 9877 return; | 9873 return; |
| 9878 } | 9874 } |
| 9879 | |
| 9880 glBindTexture(texture_ref->texture()->target(), texture_ref->service_id()); | |
| 9881 } | 9875 } |
| 9882 | 9876 |
| 9883 void GLES2DecoderImpl::DoConsumeTextureCHROMIUM(GLenum target, | 9877 void GLES2DecoderImpl::DoConsumeTextureCHROMIUM(GLenum target, |
| 9884 const GLbyte* mailbox) { | 9878 const GLbyte* mailbox) { |
| 9885 TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoConsumeTextureCHROMIUM", | 9879 TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoConsumeTextureCHROMIUM", |
| 9886 "context", logger_.GetLogPrefix(), | 9880 "context", logger_.GetLogPrefix(), |
| 9887 "mailbox[0]", static_cast<unsigned char>(mailbox[0])); | 9881 "mailbox[0]", static_cast<unsigned char>(mailbox[0])); |
| 9888 | 9882 |
| 9889 TextureRef* texture_ref = GetTextureInfoForTarget(target); | 9883 scoped_refptr<TextureRef> texture_ref = |
| 9884 GetTextureInfoForTargetUnlessDefault(target); | |
| 9890 if (!texture_ref) { | 9885 if (!texture_ref) { |
| 9891 LOCAL_SET_GL_ERROR( | 9886 LOCAL_SET_GL_ERROR( |
| 9892 GL_INVALID_OPERATION, | 9887 GL_INVALID_OPERATION, |
| 9893 "glConsumeTextureCHROMIUM", "unknown texture for target"); | 9888 "glConsumeTextureCHROMIUM", "unknown texture for target"); |
| 9894 return; | 9889 return; |
| 9895 } | 9890 } |
| 9896 | 9891 GLuint client_id = texture_ref->client_id(); |
| 9897 scoped_ptr<TextureDefinition> definition( | 9892 if (!client_id) { |
| 9893 LOCAL_SET_GL_ERROR( | |
| 9894 GL_INVALID_OPERATION, | |
| 9895 "glConsumeTextureCHROMIUM", "unknown texture for target"); | |
| 9896 return; | |
| 9897 } | |
| 9898 Texture* texture = | |
| 9898 group_->mailbox_manager()->ConsumeTexture( | 9899 group_->mailbox_manager()->ConsumeTexture( |
| 9899 target, | 9900 target, |
| 9900 *reinterpret_cast<const MailboxName*>(mailbox))); | 9901 *reinterpret_cast<const MailboxName*>(mailbox)); |
| 9901 if (!definition.get()) { | 9902 if (!texture) { |
| 9902 LOCAL_SET_GL_ERROR( | 9903 LOCAL_SET_GL_ERROR( |
| 9903 GL_INVALID_OPERATION, | 9904 GL_INVALID_OPERATION, |
| 9904 "glConsumeTextureCHROMIUM", "invalid mailbox name"); | 9905 "glConsumeTextureCHROMIUM", "invalid mailbox name"); |
| 9905 return; | 9906 return; |
| 9906 } | 9907 } |
| 9907 | 9908 if (texture->target() != target) { |
| 9908 if (!texture_manager()->Restore( | |
| 9909 "glConsumeTextureCHROMIUM", this, texture_ref, definition.release())) { | |
| 9910 LOCAL_SET_GL_ERROR( | 9909 LOCAL_SET_GL_ERROR( |
| 9911 GL_INVALID_OPERATION, | 9910 GL_INVALID_OPERATION, |
| 9912 "glConsumeTextureCHROMIUM", "invalid texture"); | 9911 "glConsumeTextureCHROMIUM", "invalid target"); |
| 9913 return; | 9912 return; |
| 9914 } | 9913 } |
| 9914 | |
| 9915 DeleteTexturesHelper(1, &client_id); | |
| 9916 texture_ref = texture_manager()->Consume(client_id, texture); | |
| 9917 glBindTexture(target, texture_ref->service_id()); | |
| 9918 | |
| 9919 TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; | |
| 9920 unit.bind_target = target; | |
| 9921 switch (target) { | |
| 9922 case GL_TEXTURE_2D: | |
| 9923 unit.bound_texture_2d = texture_ref; | |
| 9924 break; | |
| 9925 case GL_TEXTURE_CUBE_MAP: | |
| 9926 unit.bound_texture_cube_map = texture_ref; | |
| 9927 break; | |
| 9928 case GL_TEXTURE_EXTERNAL_OES: | |
| 9929 unit.bound_texture_external_oes = texture_ref; | |
| 9930 break; | |
| 9931 case GL_TEXTURE_RECTANGLE_ARB: | |
| 9932 unit.bound_texture_rectangle_arb = texture_ref; | |
| 9933 break; | |
| 9934 default: | |
| 9935 NOTREACHED(); // Validation should prevent us getting here. | |
| 9936 break; | |
| 9937 } | |
| 9915 } | 9938 } |
| 9916 | 9939 |
| 9917 void GLES2DecoderImpl::DoInsertEventMarkerEXT( | 9940 void GLES2DecoderImpl::DoInsertEventMarkerEXT( |
| 9918 GLsizei length, const GLchar* marker) { | 9941 GLsizei length, const GLchar* marker) { |
| 9919 if (!marker) { | 9942 if (!marker) { |
| 9920 marker = ""; | 9943 marker = ""; |
| 9921 } | 9944 } |
| 9922 debug_marker_manager_.SetMarker( | 9945 debug_marker_manager_.SetMarker( |
| 9923 length ? std::string(marker, length) : std::string(marker)); | 9946 length ? std::string(marker, length) : std::string(marker)); |
| 9924 } | 9947 } |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10351 return error::kNoError; | 10374 return error::kNoError; |
| 10352 } | 10375 } |
| 10353 | 10376 |
| 10354 // Include the auto-generated part of this file. We split this because it means | 10377 // Include the auto-generated part of this file. We split this because it means |
| 10355 // we can easily edit the non-auto generated parts right here in this file | 10378 // we can easily edit the non-auto generated parts right here in this file |
| 10356 // instead of having to edit some template or the code generator. | 10379 // instead of having to edit some template or the code generator. |
| 10357 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 10380 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 10358 | 10381 |
| 10359 } // namespace gles2 | 10382 } // namespace gles2 |
| 10360 } // namespace gpu | 10383 } // namespace gpu |
| OLD | NEW |