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 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1184 GLenum buffer_mode); | 1184 GLenum buffer_mode); |
1185 | 1185 |
1186 // Clear any textures used by the current program. | 1186 // Clear any textures used by the current program. |
1187 bool ClearUnclearedTextures(); | 1187 bool ClearUnclearedTextures(); |
1188 | 1188 |
1189 // Clears any uncleared attachments attached to the given frame buffer. | 1189 // Clears any uncleared attachments attached to the given frame buffer. |
1190 // Returns false if there was a generated GL error. | 1190 // Returns false if there was a generated GL error. |
1191 void ClearUnclearedAttachments(GLenum target, Framebuffer* framebuffer); | 1191 void ClearUnclearedAttachments(GLenum target, Framebuffer* framebuffer); |
1192 | 1192 |
1193 // overridden from GLES2Decoder | 1193 // overridden from GLES2Decoder |
1194 bool ClearLevel(unsigned service_id, | 1194 bool ClearLevel(Texture* texture, |
1195 unsigned bind_target, | |
1196 unsigned target, | 1195 unsigned target, |
1197 int level, | 1196 int level, |
1198 unsigned internal_format, | 1197 unsigned internal_format, |
1199 unsigned format, | 1198 unsigned format, |
1200 unsigned type, | 1199 unsigned type, |
1201 int width, | 1200 int width, |
1202 int height, | 1201 int height, |
1203 bool is_texture_immutable) override; | 1202 bool is_texture_immutable) override; |
1204 | 1203 |
1205 // Restore all GL state that affects clearing. | 1204 // Restore all GL state that affects clearing. |
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2438 const gfx::Size& size, | 2437 const gfx::Size& size, |
2439 const DisallowedFeatures& disallowed_features, | 2438 const DisallowedFeatures& disallowed_features, |
2440 const std::vector<int32>& attribs) { | 2439 const std::vector<int32>& attribs) { |
2441 TRACE_EVENT0("gpu", "GLES2DecoderImpl::Initialize"); | 2440 TRACE_EVENT0("gpu", "GLES2DecoderImpl::Initialize"); |
2442 DCHECK(context->IsCurrent(surface.get())); | 2441 DCHECK(context->IsCurrent(surface.get())); |
2443 DCHECK(!context_.get()); | 2442 DCHECK(!context_.get()); |
2444 | 2443 |
2445 surfaceless_ = surface->IsSurfaceless() && !offscreen; | 2444 surfaceless_ = surface->IsSurfaceless() && !offscreen; |
2446 | 2445 |
2447 set_initialized(); | 2446 set_initialized(); |
2448 gpu_tracer_.reset(new GPUTracer(this)); | |
2449 gpu_state_tracer_ = GPUStateTracer::Create(&state_); | 2447 gpu_state_tracer_ = GPUStateTracer::Create(&state_); |
2450 | 2448 |
2451 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 2449 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
2452 switches::kEnableGPUDebugging)) { | 2450 switches::kEnableGPUDebugging)) { |
2453 set_debug(true); | 2451 set_debug(true); |
2454 } | 2452 } |
2455 | 2453 |
2456 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 2454 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
2457 switches::kEnableGPUCommandLogging)) { | 2455 switches::kEnableGPUCommandLogging)) { |
2458 set_log_commands(true); | 2456 set_log_commands(true); |
(...skipping 10 matching lines...) Expand all Loading... |
2469 | 2467 |
2470 // Take ownership of the context and surface. The surface can be replaced with | 2468 // Take ownership of the context and surface. The surface can be replaced with |
2471 // SetSurface. | 2469 // SetSurface. |
2472 context_ = context; | 2470 context_ = context; |
2473 surface_ = surface; | 2471 surface_ = surface; |
2474 | 2472 |
2475 ContextCreationAttribHelper attrib_parser; | 2473 ContextCreationAttribHelper attrib_parser; |
2476 if (!attrib_parser.Parse(attribs)) | 2474 if (!attrib_parser.Parse(attribs)) |
2477 return false; | 2475 return false; |
2478 | 2476 |
| 2477 // Create GPU Tracer for timing values. |
| 2478 gpu_tracer_.reset(new GPUTracer(this)); |
| 2479 |
2479 // Save the loseContextWhenOutOfMemory context creation attribute. | 2480 // Save the loseContextWhenOutOfMemory context creation attribute. |
2480 lose_context_when_out_of_memory_ = | 2481 lose_context_when_out_of_memory_ = |
2481 attrib_parser.lose_context_when_out_of_memory; | 2482 attrib_parser.lose_context_when_out_of_memory; |
2482 | 2483 |
2483 // If the failIfMajorPerformanceCaveat context creation attribute was true | 2484 // If the failIfMajorPerformanceCaveat context creation attribute was true |
2484 // and we are using a software renderer, fail. | 2485 // and we are using a software renderer, fail. |
2485 if (attrib_parser.fail_if_major_perf_caveat && | 2486 if (attrib_parser.fail_if_major_perf_caveat && |
2486 feature_info_->feature_flags().is_swiftshader) { | 2487 feature_info_->feature_flags().is_swiftshader) { |
2487 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. | 2488 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
2488 Destroy(true); | 2489 Destroy(true); |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2851 DoGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, | 2852 DoGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, |
2852 &caps.max_transform_feedback_separate_attribs); | 2853 &caps.max_transform_feedback_separate_attribs); |
2853 DoGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, | 2854 DoGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, |
2854 &caps.max_uniform_buffer_bindings); | 2855 &caps.max_uniform_buffer_bindings); |
2855 DoGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, | 2856 DoGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, |
2856 &caps.uniform_buffer_offset_alignment); | 2857 &caps.uniform_buffer_offset_alignment); |
2857 } | 2858 } |
2858 | 2859 |
2859 caps.egl_image_external = | 2860 caps.egl_image_external = |
2860 feature_info_->feature_flags().oes_egl_image_external; | 2861 feature_info_->feature_flags().oes_egl_image_external; |
| 2862 caps.texture_format_atc = |
| 2863 feature_info_->feature_flags().ext_texture_format_atc; |
2861 caps.texture_format_bgra8888 = | 2864 caps.texture_format_bgra8888 = |
2862 feature_info_->feature_flags().ext_texture_format_bgra8888; | 2865 feature_info_->feature_flags().ext_texture_format_bgra8888; |
| 2866 caps.texture_format_dxt1 = |
| 2867 feature_info_->feature_flags().ext_texture_format_dxt1; |
| 2868 caps.texture_format_dxt5 = |
| 2869 feature_info_->feature_flags().ext_texture_format_dxt5; |
2863 caps.texture_format_etc1 = | 2870 caps.texture_format_etc1 = |
2864 feature_info_->feature_flags().oes_compressed_etc1_rgb8_texture; | 2871 feature_info_->feature_flags().oes_compressed_etc1_rgb8_texture; |
2865 caps.texture_format_etc1_npot = | 2872 caps.texture_format_etc1_npot = |
2866 caps.texture_format_etc1 && !workarounds().etc1_power_of_two_only; | 2873 caps.texture_format_etc1 && !workarounds().etc1_power_of_two_only; |
2867 caps.texture_rectangle = feature_info_->feature_flags().arb_texture_rectangle; | 2874 caps.texture_rectangle = feature_info_->feature_flags().arb_texture_rectangle; |
2868 caps.texture_usage = feature_info_->feature_flags().angle_texture_usage; | 2875 caps.texture_usage = feature_info_->feature_flags().angle_texture_usage; |
2869 caps.texture_storage = feature_info_->feature_flags().ext_texture_storage; | 2876 caps.texture_storage = feature_info_->feature_flags().ext_texture_storage; |
2870 caps.discard_framebuffer = | 2877 caps.discard_framebuffer = |
2871 feature_info_->feature_flags().ext_discard_framebuffer; | 2878 feature_info_->feature_flags().ext_discard_framebuffer; |
2872 caps.sync_query = feature_info_->feature_flags().chromium_sync_query; | 2879 caps.sync_query = feature_info_->feature_flags().chromium_sync_query; |
(...skipping 2253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5126 | 5133 |
5127 error::Error GLES2DecoderImpl::HandleDeleteShader(uint32 immediate_data_size, | 5134 error::Error GLES2DecoderImpl::HandleDeleteShader(uint32 immediate_data_size, |
5128 const void* cmd_data) { | 5135 const void* cmd_data) { |
5129 const gles2::cmds::DeleteShader& c = | 5136 const gles2::cmds::DeleteShader& c = |
5130 *static_cast<const gles2::cmds::DeleteShader*>(cmd_data); | 5137 *static_cast<const gles2::cmds::DeleteShader*>(cmd_data); |
5131 GLuint client_id = c.shader; | 5138 GLuint client_id = c.shader; |
5132 if (client_id) { | 5139 if (client_id) { |
5133 Shader* shader = GetShader(client_id); | 5140 Shader* shader = GetShader(client_id); |
5134 if (shader) { | 5141 if (shader) { |
5135 if (!shader->IsDeleted()) { | 5142 if (!shader->IsDeleted()) { |
5136 glDeleteShader(shader->service_id()); | 5143 shader_manager()->Delete(shader); |
5137 shader_manager()->MarkAsDeleted(shader); | |
5138 } | 5144 } |
5139 } else { | 5145 } else { |
5140 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glDeleteShader", "unknown shader"); | 5146 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glDeleteShader", "unknown shader"); |
5141 } | 5147 } |
5142 } | 5148 } |
5143 return error::kNoError; | 5149 return error::kNoError; |
5144 } | 5150 } |
5145 | 5151 |
5146 error::Error GLES2DecoderImpl::HandleDeleteProgram(uint32 immediate_data_size, | 5152 error::Error GLES2DecoderImpl::HandleDeleteProgram(uint32 immediate_data_size, |
5147 const void* cmd_data) { | 5153 const void* cmd_data) { |
(...skipping 3250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8398 } | 8404 } |
8399 | 8405 |
8400 void GLES2DecoderImpl::DoBufferSubData( | 8406 void GLES2DecoderImpl::DoBufferSubData( |
8401 GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) { | 8407 GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) { |
8402 // Just delegate it. Some validation is actually done before this. | 8408 // Just delegate it. Some validation is actually done before this. |
8403 buffer_manager()->ValidateAndDoBufferSubData( | 8409 buffer_manager()->ValidateAndDoBufferSubData( |
8404 &state_, target, offset, size, data); | 8410 &state_, target, offset, size, data); |
8405 } | 8411 } |
8406 | 8412 |
8407 bool GLES2DecoderImpl::ClearLevel( | 8413 bool GLES2DecoderImpl::ClearLevel( |
8408 unsigned service_id, | 8414 Texture* texture, |
8409 unsigned bind_target, | |
8410 unsigned target, | 8415 unsigned target, |
8411 int level, | 8416 int level, |
8412 unsigned internal_format, | 8417 unsigned internal_format, |
8413 unsigned format, | 8418 unsigned format, |
8414 unsigned type, | 8419 unsigned type, |
8415 int width, | 8420 int width, |
8416 int height, | 8421 int height, |
8417 bool is_texture_immutable) { | 8422 bool is_texture_immutable) { |
8418 uint32 channels = GLES2Util::GetChannelsForFormat(format); | 8423 uint32 channels = GLES2Util::GetChannelsForFormat(format); |
8419 if (feature_info_->feature_flags().angle_depth_texture && | 8424 if (feature_info_->feature_flags().angle_depth_texture && |
8420 (channels & GLES2Util::kDepth) != 0) { | 8425 (channels & GLES2Util::kDepth) != 0) { |
8421 // It's a depth format and ANGLE doesn't allow texImage2D or texSubImage2D | 8426 // It's a depth format and ANGLE doesn't allow texImage2D or texSubImage2D |
8422 // on depth formats. | 8427 // on depth formats. |
8423 GLuint fb = 0; | 8428 GLuint fb = 0; |
8424 glGenFramebuffersEXT(1, &fb); | 8429 glGenFramebuffersEXT(1, &fb); |
8425 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb); | 8430 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb); |
8426 | 8431 |
8427 bool have_stencil = (channels & GLES2Util::kStencil) != 0; | 8432 bool have_stencil = (channels & GLES2Util::kStencil) != 0; |
8428 GLenum attachment = have_stencil ? GL_DEPTH_STENCIL_ATTACHMENT : | 8433 GLenum attachment = have_stencil ? GL_DEPTH_STENCIL_ATTACHMENT : |
8429 GL_DEPTH_ATTACHMENT; | 8434 GL_DEPTH_ATTACHMENT; |
8430 | 8435 |
8431 glFramebufferTexture2DEXT( | 8436 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT, attachment, target, |
8432 GL_DRAW_FRAMEBUFFER_EXT, attachment, target, service_id, level); | 8437 texture->service_id(), level); |
8433 // ANGLE promises a depth only attachment ok. | 8438 // ANGLE promises a depth only attachment ok. |
8434 if (glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT) != | 8439 if (glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT) != |
8435 GL_FRAMEBUFFER_COMPLETE) { | 8440 GL_FRAMEBUFFER_COMPLETE) { |
8436 return false; | 8441 return false; |
8437 } | 8442 } |
8438 glClearStencil(0); | 8443 glClearStencil(0); |
8439 state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); | 8444 state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); |
8440 state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); | 8445 state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); |
8441 glClearDepth(1.0f); | 8446 glClearDepth(1.0f); |
8442 state_.SetDeviceDepthMask(GL_TRUE); | 8447 state_.SetDeviceDepthMask(GL_TRUE); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8481 NULL, NULL)) { | 8486 NULL, NULL)) { |
8482 return false; | 8487 return false; |
8483 } | 8488 } |
8484 } else { | 8489 } else { |
8485 tile_height = height; | 8490 tile_height = height; |
8486 } | 8491 } |
8487 | 8492 |
8488 // Assumes the size has already been checked. | 8493 // Assumes the size has already been checked. |
8489 scoped_ptr<char[]> zero(new char[size]); | 8494 scoped_ptr<char[]> zero(new char[size]); |
8490 memset(zero.get(), 0, size); | 8495 memset(zero.get(), 0, size); |
8491 glBindTexture(bind_target, service_id); | 8496 glBindTexture(texture->target(), texture->service_id()); |
8492 | 8497 |
| 8498 bool has_images = texture->HasImages(); |
8493 GLint y = 0; | 8499 GLint y = 0; |
8494 while (y < height) { | 8500 while (y < height) { |
8495 GLint h = y + tile_height > height ? height - y : tile_height; | 8501 GLint h = y + tile_height > height ? height - y : tile_height; |
8496 if (is_texture_immutable || h != height) { | 8502 if (is_texture_immutable || h != height || has_images) { |
8497 glTexSubImage2D(target, level, 0, y, width, h, format, type, zero.get()); | 8503 glTexSubImage2D(target, level, 0, y, width, h, format, type, zero.get()); |
8498 } else { | 8504 } else { |
8499 glTexImage2D( | 8505 glTexImage2D( |
8500 target, level, internal_format, width, h, 0, format, type, | 8506 target, level, internal_format, width, h, 0, format, type, |
8501 zero.get()); | 8507 zero.get()); |
8502 } | 8508 } |
8503 y += tile_height; | 8509 y += tile_height; |
8504 } | 8510 } |
8505 TextureRef* texture = texture_manager()->GetTextureInfoForTarget( | 8511 TextureRef* bound_texture = |
8506 &state_, bind_target); | 8512 texture_manager()->GetTextureInfoForTarget(&state_, texture->target()); |
8507 glBindTexture(bind_target, texture ? texture->service_id() : 0); | 8513 glBindTexture(texture->target(), |
| 8514 bound_texture ? bound_texture->service_id() : 0); |
8508 return true; | 8515 return true; |
8509 } | 8516 } |
8510 | 8517 |
8511 namespace { | 8518 namespace { |
8512 | 8519 |
8513 const int kS3TCBlockWidth = 4; | 8520 const int kS3TCBlockWidth = 4; |
8514 const int kS3TCBlockHeight = 4; | 8521 const int kS3TCBlockHeight = 4; |
8515 const int kS3TCDXT1BlockSize = 8; | 8522 const int kS3TCDXT1BlockSize = 8; |
8516 const int kS3TCDXT3AndDXT5BlockSize = 16; | 8523 const int kS3TCDXT3AndDXT5BlockSize = 16; |
8517 | 8524 |
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9158 GLint copyWidth = 0; | 9165 GLint copyWidth = 0; |
9159 GLint copyHeight = 0; | 9166 GLint copyHeight = 0; |
9160 Clip(x, width, size.width(), ©X, ©Width); | 9167 Clip(x, width, size.width(), ©X, ©Width); |
9161 Clip(y, height, size.height(), ©Y, ©Height); | 9168 Clip(y, height, size.height(), ©Y, ©Height); |
9162 | 9169 |
9163 if (copyX != x || | 9170 if (copyX != x || |
9164 copyY != y || | 9171 copyY != y || |
9165 copyWidth != width || | 9172 copyWidth != width || |
9166 copyHeight != height) { | 9173 copyHeight != height) { |
9167 // some part was clipped so clear the texture. | 9174 // some part was clipped so clear the texture. |
9168 if (!ClearLevel( | 9175 if (!ClearLevel(texture, target, level, internal_format, internal_format, |
9169 texture->service_id(), texture->target(), | 9176 GL_UNSIGNED_BYTE, width, height, texture->IsImmutable())) { |
9170 target, level, internal_format, internal_format, GL_UNSIGNED_BYTE, | |
9171 width, height, texture->IsImmutable())) { | |
9172 LOCAL_SET_GL_ERROR( | 9177 LOCAL_SET_GL_ERROR( |
9173 GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too big"); | 9178 GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too big"); |
9174 return; | 9179 return; |
9175 } | 9180 } |
9176 if (copyHeight > 0 && copyWidth > 0) { | 9181 if (copyHeight > 0 && copyWidth > 0) { |
9177 GLint dx = copyX - x; | 9182 GLint dx = copyX - x; |
9178 GLint dy = copyY - y; | 9183 GLint dy = copyY - y; |
9179 GLint destX = dx; | 9184 GLint destX = dx; |
9180 GLint destY = dy; | 9185 GLint destY = dy; |
9181 ScopedModifyPixels modify(texture_ref); | 9186 ScopedModifyPixels modify(texture_ref); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9434 GL_OUT_OF_MEMORY, "glTexSubImage2D", "dimensions too big"); | 9439 GL_OUT_OF_MEMORY, "glTexSubImage2D", "dimensions too big"); |
9435 return error::kNoError; | 9440 return error::kNoError; |
9436 } | 9441 } |
9437 ScopedTextureUploadTimer timer(&texture_state_); | 9442 ScopedTextureUploadTimer timer(&texture_state_); |
9438 glTexSubImage2D( | 9443 glTexSubImage2D( |
9439 target, level, xoffset, yoffset, width, height, format, type, data); | 9444 target, level, xoffset, yoffset, width, height, format, type, data); |
9440 return error::kNoError; | 9445 return error::kNoError; |
9441 } | 9446 } |
9442 | 9447 |
9443 if (!texture_state_.texsubimage2d_faster_than_teximage2d && | 9448 if (!texture_state_.texsubimage2d_faster_than_teximage2d && |
9444 !texture->IsImmutable()) { | 9449 !texture->IsImmutable() && |
| 9450 !texture->HasImages()) { |
9445 ScopedTextureUploadTimer timer(&texture_state_); | 9451 ScopedTextureUploadTimer timer(&texture_state_); |
9446 GLenum internal_format; | 9452 GLenum internal_format; |
9447 GLenum tex_type; | 9453 GLenum tex_type; |
9448 texture->GetLevelType(target, level, &tex_type, &internal_format); | 9454 texture->GetLevelType(target, level, &tex_type, &internal_format); |
9449 // NOTE: In OpenGL ES 2.0 border is always zero. If that changes we'll need | 9455 // NOTE: In OpenGL ES 2.0 border is always zero. If that changes we'll need |
9450 // to look it up. | 9456 // to look it up. |
9451 glTexImage2D( | 9457 glTexImage2D( |
9452 target, level, internal_format, width, height, 0, format, type, data); | 9458 target, level, internal_format, width, height, 0, format, type, data); |
9453 } else { | 9459 } else { |
9454 ScopedTextureUploadTimer timer(&texture_state_); | 9460 ScopedTextureUploadTimer timer(&texture_state_); |
(...skipping 2666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12121 } | 12127 } |
12122 } | 12128 } |
12123 | 12129 |
12124 // Include the auto-generated part of this file. We split this because it means | 12130 // Include the auto-generated part of this file. We split this because it means |
12125 // we can easily edit the non-auto generated parts right here in this file | 12131 // we can easily edit the non-auto generated parts right here in this file |
12126 // instead of having to edit some template or the code generator. | 12132 // instead of having to edit some template or the code generator. |
12127 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 12133 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
12128 | 12134 |
12129 } // namespace gles2 | 12135 } // namespace gles2 |
12130 } // namespace gpu | 12136 } // namespace gpu |
OLD | NEW |