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 <cmath> | 10 #include <cmath> |
| (...skipping 1948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1959 bool IsDrawValid( | 1959 bool IsDrawValid( |
| 1960 const char* function_name, GLuint max_vertex_accessed, bool instanced, | 1960 const char* function_name, GLuint max_vertex_accessed, bool instanced, |
| 1961 GLsizei primcount); | 1961 GLsizei primcount); |
| 1962 | 1962 |
| 1963 // Returns true if successful, simulated will be true if attrib0 was | 1963 // Returns true if successful, simulated will be true if attrib0 was |
| 1964 // simulated. | 1964 // simulated. |
| 1965 bool SimulateAttrib0( | 1965 bool SimulateAttrib0( |
| 1966 const char* function_name, GLuint max_vertex_accessed, bool* simulated); | 1966 const char* function_name, GLuint max_vertex_accessed, bool* simulated); |
| 1967 void RestoreStateForAttrib(GLuint attrib, bool restore_array_binding); | 1967 void RestoreStateForAttrib(GLuint attrib, bool restore_array_binding); |
| 1968 | 1968 |
| 1969 // If an image is bound to texture, this will call Will/DidUseTexImage | 1969 // Calls WillUseTexImage or copies the image to the texture currently bound |
| 1970 // to |textarget| based on the value of |image_state|. The new image state is | |
| 1971 // returned. | |
| 1972 Texture::ImageState DoWillUseTexImage(GLenum textarget, | |
| 1973 gfx::GLImage* image, | |
| 1974 Texture::ImageState image_state); | |
| 1975 | |
| 1976 // Calls DidUseTexImage based on the value of |image_state|. | |
| 1977 void DoDidUseTexImage(gfx::GLImage* image, Texture::ImageState image_state); | |
| 1978 | |
| 1979 // If an image is bound to texture, this will call DoWill/DidUseTexImage | |
| 1970 // if needed. | 1980 // if needed. |
| 1971 void DoWillUseTexImageIfNeeded(Texture* texture, GLenum textarget); | 1981 void DoWillUseTexImageIfNeeded(Texture* texture, GLenum textarget); |
| 1972 void DoDidUseTexImageIfNeeded(Texture* texture, GLenum textarget); | 1982 void DoDidUseTexImageIfNeeded(Texture* texture, GLenum textarget); |
| 1973 | 1983 |
| 1974 // Returns false if textures were replaced. | 1984 // Returns false if textures were replaced. |
| 1975 bool PrepareTexturesForRender(); | 1985 bool PrepareTexturesForRender(); |
| 1976 void RestoreStateForTextures(); | 1986 void RestoreStateForTextures(); |
| 1977 | 1987 |
| 1978 // Returns true if GL_FIXED attribs were simulated. | 1988 // Returns true if GL_FIXED attribs were simulated. |
| 1979 bool SimulateFixedAttribs( | 1989 bool SimulateFixedAttribs( |
| (...skipping 5635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7615 const char* filename, int line, const std::string& msg) { | 7625 const char* filename, int line, const std::string& msg) { |
| 7616 logger_.LogMessage(filename, line, std::string("RENDER WARNING: ") + msg); | 7626 logger_.LogMessage(filename, line, std::string("RENDER WARNING: ") + msg); |
| 7617 } | 7627 } |
| 7618 | 7628 |
| 7619 void GLES2DecoderImpl::PerformanceWarning( | 7629 void GLES2DecoderImpl::PerformanceWarning( |
| 7620 const char* filename, int line, const std::string& msg) { | 7630 const char* filename, int line, const std::string& msg) { |
| 7621 logger_.LogMessage(filename, line, | 7631 logger_.LogMessage(filename, line, |
| 7622 std::string("PERFORMANCE WARNING: ") + msg); | 7632 std::string("PERFORMANCE WARNING: ") + msg); |
| 7623 } | 7633 } |
| 7624 | 7634 |
| 7635 Texture::ImageState GLES2DecoderImpl::DoWillUseTexImage( | |
| 7636 GLenum textarget, | |
| 7637 gfx::GLImage* image, | |
| 7638 Texture::ImageState image_state) { | |
| 7639 switch (image_state) { | |
| 7640 case Texture::UNBOUND: { | |
| 7641 bool rv = image->CopyTexImage(textarget); | |
| 7642 DCHECK(rv) << "Both BindTexImage() and CopyTexImage() failed"; | |
| 7643 return Texture::COPIED; | |
|
Daniele Castagna
2015/10/14 18:40:35
nit: should this be UNBOUND, not that it matters.
reveman
2015/10/14 19:28:01
State should change to COPIED to prevent us from c
| |
| 7644 } | |
| 7645 case Texture::BOUND: | |
| 7646 image->WillUseTexImage(); | |
| 7647 return Texture::BOUND; | |
| 7648 case Texture::COPIED: | |
| 7649 return Texture::COPIED; | |
| 7650 } | |
| 7651 | |
| 7652 NOTREACHED(); | |
| 7653 return Texture::UNBOUND; | |
| 7654 } | |
| 7655 | |
| 7656 void GLES2DecoderImpl::DoDidUseTexImage(gfx::GLImage* image, | |
| 7657 Texture::ImageState image_state) { | |
| 7658 switch (image_state) { | |
| 7659 case Texture::BOUND: | |
| 7660 image->DidUseTexImage(); | |
| 7661 return; | |
| 7662 case Texture::UNBOUND: | |
| 7663 case Texture::COPIED: | |
| 7664 return; | |
| 7665 } | |
| 7666 | |
| 7667 NOTREACHED(); | |
| 7668 } | |
| 7669 | |
| 7625 void GLES2DecoderImpl::DoWillUseTexImageIfNeeded( | 7670 void GLES2DecoderImpl::DoWillUseTexImageIfNeeded( |
| 7626 Texture* texture, GLenum textarget) { | 7671 Texture* texture, GLenum textarget) { |
| 7627 // Image is already in use if texture is attached to a framebuffer. | 7672 // Image is already in use if texture is attached to a framebuffer. |
| 7628 if (texture && !texture->IsAttachedToFramebuffer()) { | 7673 if (texture && !texture->IsAttachedToFramebuffer()) { |
| 7629 gfx::GLImage* image = texture->GetLevelImage(textarget, 0); | 7674 Texture::ImageState image_state; |
| 7675 gfx::GLImage* image = texture->GetLevelImage(textarget, 0, &image_state); | |
| 7630 if (image) { | 7676 if (image) { |
| 7631 ScopedGLErrorSuppressor suppressor( | 7677 ScopedGLErrorSuppressor suppressor( |
| 7632 "GLES2DecoderImpl::DoWillUseTexImageIfNeeded", | 7678 "GLES2DecoderImpl::DoWillUseTexImageIfNeeded", |
| 7633 GetErrorState()); | 7679 GetErrorState()); |
| 7634 glBindTexture(textarget, texture->service_id()); | 7680 glBindTexture(textarget, texture->service_id()); |
| 7635 image->WillUseTexImage(); | 7681 Texture::ImageState new_image_state = |
| 7682 DoWillUseTexImage(textarget, image, image_state); | |
| 7636 RestoreCurrentTextureBindings(&state_, textarget); | 7683 RestoreCurrentTextureBindings(&state_, textarget); |
| 7684 texture->SetLevelImage(textarget, 0, image, new_image_state); | |
| 7637 } | 7685 } |
| 7638 } | 7686 } |
| 7639 } | 7687 } |
| 7640 | 7688 |
| 7641 void GLES2DecoderImpl::DoDidUseTexImageIfNeeded( | 7689 void GLES2DecoderImpl::DoDidUseTexImageIfNeeded( |
| 7642 Texture* texture, GLenum textarget) { | 7690 Texture* texture, GLenum textarget) { |
| 7643 // Image is still in use if texture is attached to a framebuffer. | 7691 // Image is still in use if texture is attached to a framebuffer. |
| 7644 if (texture && !texture->IsAttachedToFramebuffer()) { | 7692 if (texture && !texture->IsAttachedToFramebuffer()) { |
| 7645 gfx::GLImage* image = texture->GetLevelImage(textarget, 0); | 7693 Texture::ImageState image_state; |
| 7694 gfx::GLImage* image = texture->GetLevelImage(textarget, 0, &image_state); | |
| 7646 if (image) { | 7695 if (image) { |
| 7647 ScopedGLErrorSuppressor suppressor( | 7696 ScopedGLErrorSuppressor suppressor( |
| 7648 "GLES2DecoderImpl::DoDidUseTexImageIfNeeded", | 7697 "GLES2DecoderImpl::DoDidUseTexImageIfNeeded", |
| 7649 GetErrorState()); | 7698 GetErrorState()); |
| 7650 glBindTexture(textarget, texture->service_id()); | 7699 glBindTexture(textarget, texture->service_id()); |
| 7651 image->DidUseTexImage(); | 7700 DoDidUseTexImage(image, image_state); |
| 7652 RestoreCurrentTextureBindings(&state_, textarget); | 7701 RestoreCurrentTextureBindings(&state_, textarget); |
| 7653 } | 7702 } |
| 7654 } | 7703 } |
| 7655 } | 7704 } |
| 7656 | 7705 |
| 7657 bool GLES2DecoderImpl::PrepareTexturesForRender() { | 7706 bool GLES2DecoderImpl::PrepareTexturesForRender() { |
| 7658 DCHECK(state_.current_program.get()); | 7707 DCHECK(state_.current_program.get()); |
| 7659 if (!texture_manager()->HaveUnrenderableTextures() && | 7708 if (!texture_manager()->HaveUnrenderableTextures() && |
| 7660 !texture_manager()->HaveImages()) { | 7709 !texture_manager()->HaveImages()) { |
| 7661 return true; | 7710 return true; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 7689 std::string("texture bound to texture unit ") + | 7738 std::string("texture bound to texture unit ") + |
| 7690 base::UintToString(texture_unit_index) + | 7739 base::UintToString(texture_unit_index) + |
| 7691 " is not renderable. It maybe non-power-of-2 and have" | 7740 " is not renderable. It maybe non-power-of-2 and have" |
| 7692 " incompatible texture filtering."); | 7741 " incompatible texture filtering."); |
| 7693 } | 7742 } |
| 7694 continue; | 7743 continue; |
| 7695 } | 7744 } |
| 7696 | 7745 |
| 7697 if (textarget != GL_TEXTURE_CUBE_MAP) { | 7746 if (textarget != GL_TEXTURE_CUBE_MAP) { |
| 7698 Texture* texture = texture_ref->texture(); | 7747 Texture* texture = texture_ref->texture(); |
| 7699 gfx::GLImage* image = texture->GetLevelImage(textarget, 0); | 7748 Texture::ImageState image_state; |
| 7749 gfx::GLImage* image = | |
| 7750 texture->GetLevelImage(textarget, 0, &image_state); | |
| 7700 if (image && !texture->IsAttachedToFramebuffer()) { | 7751 if (image && !texture->IsAttachedToFramebuffer()) { |
| 7701 ScopedGLErrorSuppressor suppressor( | 7752 ScopedGLErrorSuppressor suppressor( |
| 7702 "GLES2DecoderImpl::PrepareTexturesForRender", GetErrorState()); | 7753 "GLES2DecoderImpl::PrepareTexturesForRender", GetErrorState()); |
| 7703 textures_set = true; | 7754 textures_set = true; |
| 7704 glActiveTexture(GL_TEXTURE0 + texture_unit_index); | 7755 glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 7705 image->WillUseTexImage(); | 7756 Texture::ImageState new_image_state = |
| 7757 DoWillUseTexImage(textarget, image, image_state); | |
| 7758 texture->SetLevelImage(textarget, 0, image, new_image_state); | |
| 7706 continue; | 7759 continue; |
| 7707 } | 7760 } |
| 7708 } | 7761 } |
| 7709 } | 7762 } |
| 7710 // else: should this be an error? | 7763 // else: should this be an error? |
| 7711 } | 7764 } |
| 7712 } | 7765 } |
| 7713 return !textures_set; | 7766 return !textures_set; |
| 7714 } | 7767 } |
| 7715 | 7768 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 7733 texture_ref = texture_unit.bind_target == GL_TEXTURE_2D | 7786 texture_ref = texture_unit.bind_target == GL_TEXTURE_2D |
| 7734 ? texture_unit.bound_texture_2d.get() | 7787 ? texture_unit.bound_texture_2d.get() |
| 7735 : texture_unit.bound_texture_cube_map.get(); | 7788 : texture_unit.bound_texture_cube_map.get(); |
| 7736 glBindTexture(texture_unit.bind_target, | 7789 glBindTexture(texture_unit.bind_target, |
| 7737 texture_ref ? texture_ref->service_id() : 0); | 7790 texture_ref ? texture_ref->service_id() : 0); |
| 7738 continue; | 7791 continue; |
| 7739 } | 7792 } |
| 7740 | 7793 |
| 7741 if (texture_unit.bind_target != GL_TEXTURE_CUBE_MAP) { | 7794 if (texture_unit.bind_target != GL_TEXTURE_CUBE_MAP) { |
| 7742 Texture* texture = texture_ref->texture(); | 7795 Texture* texture = texture_ref->texture(); |
| 7796 Texture::ImageState image_state; | |
| 7743 gfx::GLImage* image = | 7797 gfx::GLImage* image = |
| 7744 texture->GetLevelImage(texture_unit.bind_target, 0); | 7798 texture->GetLevelImage(texture_unit.bind_target, 0, &image_state); |
| 7745 if (image && !texture->IsAttachedToFramebuffer()) { | 7799 if (image && !texture->IsAttachedToFramebuffer()) { |
| 7746 ScopedGLErrorSuppressor suppressor( | 7800 ScopedGLErrorSuppressor suppressor( |
| 7747 "GLES2DecoderImpl::RestoreStateForTextures", GetErrorState()); | 7801 "GLES2DecoderImpl::RestoreStateForTextures", GetErrorState()); |
| 7748 glActiveTexture(GL_TEXTURE0 + texture_unit_index); | 7802 glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 7749 image->DidUseTexImage(); | 7803 DoDidUseTexImage(image, image_state); |
| 7750 continue; | 7804 continue; |
| 7751 } | 7805 } |
| 7752 } | 7806 } |
| 7753 } | 7807 } |
| 7754 } | 7808 } |
| 7755 } | 7809 } |
| 7756 // Set the active texture back to whatever the user had it as. | 7810 // Set the active texture back to whatever the user had it as. |
| 7757 glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); | 7811 glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); |
| 7758 } | 7812 } |
| 7759 | 7813 |
| (...skipping 1706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9466 const void* cmd_data) { | 9520 const void* cmd_data) { |
| 9467 const gles2::cmds::ScheduleOverlayPlaneCHROMIUM& c = | 9521 const gles2::cmds::ScheduleOverlayPlaneCHROMIUM& c = |
| 9468 *static_cast<const gles2::cmds::ScheduleOverlayPlaneCHROMIUM*>(cmd_data); | 9522 *static_cast<const gles2::cmds::ScheduleOverlayPlaneCHROMIUM*>(cmd_data); |
| 9469 TextureRef* ref = texture_manager()->GetTexture(c.overlay_texture_id); | 9523 TextureRef* ref = texture_manager()->GetTexture(c.overlay_texture_id); |
| 9470 if (!ref) { | 9524 if (!ref) { |
| 9471 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, | 9525 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
| 9472 "glScheduleOverlayPlaneCHROMIUM", | 9526 "glScheduleOverlayPlaneCHROMIUM", |
| 9473 "unknown texture"); | 9527 "unknown texture"); |
| 9474 return error::kNoError; | 9528 return error::kNoError; |
| 9475 } | 9529 } |
| 9530 Texture::ImageState image_state; | |
| 9476 gfx::GLImage* image = | 9531 gfx::GLImage* image = |
| 9477 ref->texture()->GetLevelImage(ref->texture()->target(), 0); | 9532 ref->texture()->GetLevelImage(ref->texture()->target(), 0, &image_state); |
| 9478 if (!image) { | 9533 if (!image || image_state != Texture::BOUND) { |
| 9479 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, | 9534 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
| 9480 "glScheduleOverlayPlaneCHROMIUM", | 9535 "glScheduleOverlayPlaneCHROMIUM", |
| 9481 "unsupported texture format"); | 9536 "unsupported texture format"); |
| 9482 return error::kNoError; | 9537 return error::kNoError; |
| 9483 } | 9538 } |
| 9484 gfx::OverlayTransform transform = GetGFXOverlayTransform(c.plane_transform); | 9539 gfx::OverlayTransform transform = GetGFXOverlayTransform(c.plane_transform); |
| 9485 if (transform == gfx::OVERLAY_TRANSFORM_INVALID) { | 9540 if (transform == gfx::OVERLAY_TRANSFORM_INVALID) { |
| 9486 LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, | 9541 LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, |
| 9487 "glScheduleOverlayPlaneCHROMIUM", | 9542 "glScheduleOverlayPlaneCHROMIUM", |
| 9488 "invalid transform enum"); | 9543 "invalid transform enum"); |
| (...skipping 3595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13084 GLboolean unpack_unmultiply_alpha) { | 13139 GLboolean unpack_unmultiply_alpha) { |
| 13085 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); | 13140 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); |
| 13086 | 13141 |
| 13087 TextureRef* source_texture_ref = GetTexture(source_id); | 13142 TextureRef* source_texture_ref = GetTexture(source_id); |
| 13088 TextureRef* dest_texture_ref = GetTexture(dest_id); | 13143 TextureRef* dest_texture_ref = GetTexture(dest_id); |
| 13089 Texture* source_texture = source_texture_ref->texture(); | 13144 Texture* source_texture = source_texture_ref->texture(); |
| 13090 Texture* dest_texture = dest_texture_ref->texture(); | 13145 Texture* dest_texture = dest_texture_ref->texture(); |
| 13091 int source_width = 0; | 13146 int source_width = 0; |
| 13092 int source_height = 0; | 13147 int source_height = 0; |
| 13093 gfx::GLImage* image = | 13148 gfx::GLImage* image = |
| 13094 source_texture->GetLevelImage(source_texture->target(), 0); | 13149 source_texture->GetLevelImage(source_texture->target(), 0, nullptr); |
| 13095 if (image) { | 13150 if (image) { |
| 13096 gfx::Size size = image->GetSize(); | 13151 gfx::Size size = image->GetSize(); |
| 13097 source_width = size.width(); | 13152 source_width = size.width(); |
| 13098 source_height = size.height(); | 13153 source_height = size.height(); |
| 13099 if (source_width <= 0 || source_height <= 0) { | 13154 if (source_width <= 0 || source_height <= 0) { |
| 13100 LOCAL_SET_GL_ERROR( | 13155 LOCAL_SET_GL_ERROR( |
| 13101 GL_INVALID_VALUE, | 13156 GL_INVALID_VALUE, |
| 13102 "glCopyTextureChromium", "invalid image size"); | 13157 "glCopyTextureChromium", "invalid image size"); |
| 13103 return; | 13158 return; |
| 13104 } | 13159 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13188 dest_texture_ref, GL_TEXTURE_2D, 0, internal_format, source_width, | 13243 dest_texture_ref, GL_TEXTURE_2D, 0, internal_format, source_width, |
| 13189 source_height, 1, 0, internal_format, dest_type, | 13244 source_height, 1, 0, internal_format, dest_type, |
| 13190 gfx::Rect(source_width, source_height)); | 13245 gfx::Rect(source_width, source_height)); |
| 13191 } else { | 13246 } else { |
| 13192 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, | 13247 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, |
| 13193 true); | 13248 true); |
| 13194 } | 13249 } |
| 13195 | 13250 |
| 13196 ScopedModifyPixels modify(dest_texture_ref); | 13251 ScopedModifyPixels modify(dest_texture_ref); |
| 13197 | 13252 |
| 13198 // Try using GLImage::CopyTexSubImage when possible. | 13253 // Try using GLImage::CopyTexImage when possible. |
| 13199 bool unpack_premultiply_alpha_change = | 13254 bool unpack_premultiply_alpha_change = |
| 13200 (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0; | 13255 (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0; |
| 13201 if (image && !unpack_flip_y && !unpack_premultiply_alpha_change) { | 13256 if (image && !unpack_flip_y && !unpack_premultiply_alpha_change) { |
| 13202 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); | 13257 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
| 13203 if (image->CopyTexSubImage(GL_TEXTURE_2D, gfx::Point(0, 0), | 13258 if (image->CopyTexImage(GL_TEXTURE_2D)) |
| 13204 gfx::Rect(0, 0, source_width, source_height))) { | |
| 13205 return; | 13259 return; |
| 13206 } | |
| 13207 } | 13260 } |
| 13208 | 13261 |
| 13209 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); | 13262 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); |
| 13210 | 13263 |
| 13211 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix | 13264 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix |
| 13212 // before presenting. | 13265 // before presenting. |
| 13213 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { | 13266 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { |
| 13214 // TODO(hkuang): get the StreamTexture transform matrix in GPU process | 13267 // TODO(hkuang): get the StreamTexture transform matrix in GPU process |
| 13215 // instead of using kIdentityMatrix crbug.com/226218. | 13268 // instead of using kIdentityMatrix crbug.com/226218. |
| 13216 copy_texture_CHROMIUM_->DoCopyTextureWithTransform( | 13269 copy_texture_CHROMIUM_->DoCopyTextureWithTransform( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13248 GLboolean unpack_unmultiply_alpha) { | 13301 GLboolean unpack_unmultiply_alpha) { |
| 13249 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopySubTextureCHROMIUM"); | 13302 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopySubTextureCHROMIUM"); |
| 13250 | 13303 |
| 13251 TextureRef* source_texture_ref = GetTexture(source_id); | 13304 TextureRef* source_texture_ref = GetTexture(source_id); |
| 13252 TextureRef* dest_texture_ref = GetTexture(dest_id); | 13305 TextureRef* dest_texture_ref = GetTexture(dest_id); |
| 13253 Texture* source_texture = source_texture_ref->texture(); | 13306 Texture* source_texture = source_texture_ref->texture(); |
| 13254 Texture* dest_texture = dest_texture_ref->texture(); | 13307 Texture* dest_texture = dest_texture_ref->texture(); |
| 13255 int source_width = 0; | 13308 int source_width = 0; |
| 13256 int source_height = 0; | 13309 int source_height = 0; |
| 13257 gfx::GLImage* image = | 13310 gfx::GLImage* image = |
| 13258 source_texture->GetLevelImage(source_texture->target(), 0); | 13311 source_texture->GetLevelImage(source_texture->target(), 0, nullptr); |
| 13259 if (image) { | 13312 if (image) { |
| 13260 gfx::Size size = image->GetSize(); | 13313 gfx::Size size = image->GetSize(); |
| 13261 source_width = size.width(); | 13314 source_width = size.width(); |
| 13262 source_height = size.height(); | 13315 source_height = size.height(); |
| 13263 if (source_width <= 0 || source_height <= 0) { | 13316 if (source_width <= 0 || source_height <= 0) { |
| 13264 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", | 13317 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", |
| 13265 "invalid image size"); | 13318 "invalid image size"); |
| 13266 return; | 13319 return; |
| 13267 } | 13320 } |
| 13268 } else { | 13321 } else { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13398 GLuint dest_id) { | 13451 GLuint dest_id) { |
| 13399 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM"); | 13452 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM"); |
| 13400 | 13453 |
| 13401 TextureRef* source_texture_ref = GetTexture(source_id); | 13454 TextureRef* source_texture_ref = GetTexture(source_id); |
| 13402 TextureRef* dest_texture_ref = GetTexture(dest_id); | 13455 TextureRef* dest_texture_ref = GetTexture(dest_id); |
| 13403 Texture* source_texture = source_texture_ref->texture(); | 13456 Texture* source_texture = source_texture_ref->texture(); |
| 13404 Texture* dest_texture = dest_texture_ref->texture(); | 13457 Texture* dest_texture = dest_texture_ref->texture(); |
| 13405 int source_width = 0; | 13458 int source_width = 0; |
| 13406 int source_height = 0; | 13459 int source_height = 0; |
| 13407 gfx::GLImage* image = | 13460 gfx::GLImage* image = |
| 13408 source_texture->GetLevelImage(source_texture->target(), 0); | 13461 source_texture->GetLevelImage(source_texture->target(), 0, nullptr); |
| 13409 if (image) { | 13462 if (image) { |
| 13410 gfx::Size size = image->GetSize(); | 13463 gfx::Size size = image->GetSize(); |
| 13411 source_width = size.width(); | 13464 source_width = size.width(); |
| 13412 source_height = size.height(); | 13465 source_height = size.height(); |
| 13413 if (source_width <= 0 || source_height <= 0) { | 13466 if (source_width <= 0 || source_height <= 0) { |
| 13414 LOCAL_SET_GL_ERROR( | 13467 LOCAL_SET_GL_ERROR( |
| 13415 GL_INVALID_VALUE, | 13468 GL_INVALID_VALUE, |
| 13416 "glCompressedCopyTextureCHROMIUM", "invalid image size"); | 13469 "glCompressedCopyTextureCHROMIUM", "invalid image size"); |
| 13417 return; | 13470 return; |
| 13418 } | 13471 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13516 | 13569 |
| 13517 texture_manager()->SetLevelInfo( | 13570 texture_manager()->SetLevelInfo( |
| 13518 dest_texture_ref, GL_TEXTURE_2D, 0, source_internal_format, | 13571 dest_texture_ref, GL_TEXTURE_2D, 0, source_internal_format, |
| 13519 source_width, source_height, 1, 0, source_internal_format, | 13572 source_width, source_height, 1, 0, source_internal_format, |
| 13520 source_type, gfx::Rect(source_width, source_height)); | 13573 source_type, gfx::Rect(source_width, source_height)); |
| 13521 } else { | 13574 } else { |
| 13522 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, | 13575 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, |
| 13523 true); | 13576 true); |
| 13524 } | 13577 } |
| 13525 | 13578 |
| 13526 if (image->CopyTexSubImage(GL_TEXTURE_2D, gfx::Point(0, 0), | 13579 if (image->CopyTexImage(GL_TEXTURE_2D)) |
| 13527 gfx::Rect(0, 0, source_width, source_height))) { | |
| 13528 return; | 13580 return; |
| 13529 } | |
| 13530 } | 13581 } |
| 13531 | 13582 |
| 13532 TRACE_EVENT0( | 13583 TRACE_EVENT0( |
| 13533 "gpu", | 13584 "gpu", |
| 13534 "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM, fallback"); | 13585 "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM, fallback"); |
| 13535 | 13586 |
| 13536 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); | 13587 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); |
| 13537 | 13588 |
| 13538 // As a fallback, copy into a non-compressed GL_RGBA texture. | 13589 // As a fallback, copy into a non-compressed GL_RGBA texture. |
| 13539 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedCopyTextureCHROMIUM"); | 13590 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedCopyTextureCHROMIUM"); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13580 GLsizei height) { | 13631 GLsizei height) { |
| 13581 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCompressedCopySubTextureCHROMIUM"); | 13632 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCompressedCopySubTextureCHROMIUM"); |
| 13582 | 13633 |
| 13583 TextureRef* source_texture_ref = GetTexture(source_id); | 13634 TextureRef* source_texture_ref = GetTexture(source_id); |
| 13584 TextureRef* dest_texture_ref = GetTexture(dest_id); | 13635 TextureRef* dest_texture_ref = GetTexture(dest_id); |
| 13585 Texture* source_texture = source_texture_ref->texture(); | 13636 Texture* source_texture = source_texture_ref->texture(); |
| 13586 Texture* dest_texture = dest_texture_ref->texture(); | 13637 Texture* dest_texture = dest_texture_ref->texture(); |
| 13587 int source_width = 0; | 13638 int source_width = 0; |
| 13588 int source_height = 0; | 13639 int source_height = 0; |
| 13589 gfx::GLImage* image = | 13640 gfx::GLImage* image = |
| 13590 source_texture->GetLevelImage(source_texture->target(), 0); | 13641 source_texture->GetLevelImage(source_texture->target(), 0, nullptr); |
| 13591 if (image) { | 13642 if (image) { |
| 13592 gfx::Size size = image->GetSize(); | 13643 gfx::Size size = image->GetSize(); |
| 13593 source_width = size.width(); | 13644 source_width = size.width(); |
| 13594 source_height = size.height(); | 13645 source_height = size.height(); |
| 13595 if (source_width <= 0 || source_height <= 0) { | 13646 if (source_width <= 0 || source_height <= 0) { |
| 13596 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCompressedCopySubTextureCHROMIUM", | 13647 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCompressedCopySubTextureCHROMIUM", |
| 13597 "invalid image size"); | 13648 "invalid image size"); |
| 13598 return; | 13649 return; |
| 13599 } | 13650 } |
| 13600 } else { | 13651 } else { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13711 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, | 13762 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, |
| 13712 true); | 13763 true); |
| 13713 } | 13764 } |
| 13714 | 13765 |
| 13715 ScopedTextureBinder binder( | 13766 ScopedTextureBinder binder( |
| 13716 &state_, dest_texture->service_id(), GL_TEXTURE_2D); | 13767 &state_, dest_texture->service_id(), GL_TEXTURE_2D); |
| 13717 | 13768 |
| 13718 ScopedModifyPixels modify(dest_texture_ref); | 13769 ScopedModifyPixels modify(dest_texture_ref); |
| 13719 | 13770 |
| 13720 // Try using GLImage::CopyTexSubImage when possible. | 13771 // Try using GLImage::CopyTexSubImage when possible. |
| 13721 if (image) { | 13772 if (image && |
| 13722 if (image->CopyTexSubImage(GL_TEXTURE_2D, gfx::Point(xoffset, yoffset), | 13773 image->CopyTexSubImage(GL_TEXTURE_2D, gfx::Point(xoffset, yoffset), |
| 13723 gfx::Rect(x, y, width, height))) { | 13774 gfx::Rect(x, y, width, height))) { |
| 13724 return; | 13775 return; |
| 13725 } | |
| 13726 } | 13776 } |
| 13727 | 13777 |
| 13728 TRACE_EVENT0( | 13778 TRACE_EVENT0( |
| 13729 "gpu", | 13779 "gpu", |
| 13730 "GLES2DecoderImpl::DoCompressedCopySubTextureCHROMIUM, fallback"); | 13780 "GLES2DecoderImpl::DoCompressedCopySubTextureCHROMIUM, fallback"); |
| 13731 | 13781 |
| 13732 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); | 13782 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); |
| 13733 | 13783 |
| 13734 // As a fallback, copy into a non-compressed GL_RGBA texture. | 13784 // As a fallback, copy into a non-compressed GL_RGBA texture. |
| 13735 if (dest_internal_format != GL_RGBA) { | 13785 if (dest_internal_format != GL_RGBA) { |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14189 // accidents. | 14239 // accidents. |
| 14190 TextureRef* texture_ref = | 14240 TextureRef* texture_ref = |
| 14191 texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); | 14241 texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
| 14192 if (!texture_ref) { | 14242 if (!texture_ref) { |
| 14193 LOCAL_SET_GL_ERROR( | 14243 LOCAL_SET_GL_ERROR( |
| 14194 GL_INVALID_OPERATION, | 14244 GL_INVALID_OPERATION, |
| 14195 "glBindTexImage2DCHROMIUM", "no texture bound"); | 14245 "glBindTexImage2DCHROMIUM", "no texture bound"); |
| 14196 return; | 14246 return; |
| 14197 } | 14247 } |
| 14198 | 14248 |
| 14199 gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); | 14249 gfx::GLImage* image = image_manager()->LookupImage(image_id); |
| 14200 if (!gl_image) { | 14250 if (!image) { |
| 14201 LOCAL_SET_GL_ERROR( | 14251 LOCAL_SET_GL_ERROR( |
| 14202 GL_INVALID_OPERATION, | 14252 GL_INVALID_OPERATION, |
| 14203 "glBindTexImage2DCHROMIUM", "no image found with the given ID"); | 14253 "glBindTexImage2DCHROMIUM", "no image found with the given ID"); |
| 14204 return; | 14254 return; |
| 14205 } | 14255 } |
| 14206 | 14256 |
| 14257 Texture::ImageState image_state = Texture::UNBOUND; | |
| 14258 | |
| 14207 { | 14259 { |
| 14208 ScopedGLErrorSuppressor suppressor( | 14260 ScopedGLErrorSuppressor suppressor( |
| 14209 "GLES2DecoderImpl::DoBindTexImage2DCHROMIUM", GetErrorState()); | 14261 "GLES2DecoderImpl::DoBindTexImage2DCHROMIUM", GetErrorState()); |
| 14210 if (!gl_image->BindTexImage(target)) { | 14262 |
| 14211 LOCAL_SET_GL_ERROR( | 14263 // Note: We fallback to a lazy GLImage::CopyTexImage() call in |
| 14212 GL_INVALID_OPERATION, | 14264 // DoWillUseTexImage() when BindTexImage() fails. |
| 14213 "glBindTexImage2DCHROMIUM", "fail to bind image with the given ID"); | 14265 if (image->BindTexImage(target)) |
| 14214 return; | 14266 image_state = Texture::BOUND; |
| 14215 } | |
| 14216 } | 14267 } |
| 14217 | 14268 |
| 14218 gfx::Size size = gl_image->GetSize(); | 14269 // GL_TEXTURE_EXTERNAL_OES is not a supported CopyTexImage() target. |
| 14270 if (target == GL_TEXTURE_EXTERNAL_OES && image_state == Texture::UNBOUND) { | |
| 14271 LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, "glBindTexImage2DCHROMIUM", | |
| 14272 "invalid target"); | |
| 14273 return; | |
| 14274 } | |
| 14275 | |
| 14276 gfx::Size size = image->GetSize(); | |
| 14219 texture_manager()->SetLevelInfo( | 14277 texture_manager()->SetLevelInfo( |
| 14220 texture_ref, target, 0, gl_image->GetInternalFormat(), size.width(), | 14278 texture_ref, target, 0, image->GetInternalFormat(), size.width(), |
| 14221 size.height(), 1, 0, gl_image->GetInternalFormat(), GL_UNSIGNED_BYTE, | 14279 size.height(), 1, 0, image->GetInternalFormat(), GL_UNSIGNED_BYTE, |
| 14222 gfx::Rect(size)); | 14280 gfx::Rect(size)); |
| 14223 texture_manager()->SetLevelImage(texture_ref, target, 0, gl_image); | 14281 texture_manager()->SetLevelImage(texture_ref, target, 0, image, image_state); |
| 14224 } | 14282 } |
| 14225 | 14283 |
| 14226 void GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM( | 14284 void GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM( |
| 14227 GLenum target, GLint image_id) { | 14285 GLenum target, GLint image_id) { |
| 14228 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM"); | 14286 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM"); |
| 14229 | 14287 |
| 14230 // Default target might be conceptually valid, but disallow it to avoid | 14288 // Default target might be conceptually valid, but disallow it to avoid |
| 14231 // accidents. | 14289 // accidents. |
| 14232 TextureRef* texture_ref = | 14290 TextureRef* texture_ref = |
| 14233 texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); | 14291 texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
| 14234 if (!texture_ref) { | 14292 if (!texture_ref) { |
| 14235 LOCAL_SET_GL_ERROR( | 14293 LOCAL_SET_GL_ERROR( |
| 14236 GL_INVALID_OPERATION, | 14294 GL_INVALID_OPERATION, |
| 14237 "glReleaseTexImage2DCHROMIUM", "no texture bound"); | 14295 "glReleaseTexImage2DCHROMIUM", "no texture bound"); |
| 14238 return; | 14296 return; |
| 14239 } | 14297 } |
| 14240 | 14298 |
| 14241 gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); | 14299 gfx::GLImage* image = image_manager()->LookupImage(image_id); |
| 14242 if (!gl_image) { | 14300 if (!image) { |
| 14243 LOCAL_SET_GL_ERROR( | 14301 LOCAL_SET_GL_ERROR( |
| 14244 GL_INVALID_OPERATION, | 14302 GL_INVALID_OPERATION, |
| 14245 "glReleaseTexImage2DCHROMIUM", "no image found with the given ID"); | 14303 "glReleaseTexImage2DCHROMIUM", "no image found with the given ID"); |
| 14246 return; | 14304 return; |
| 14247 } | 14305 } |
| 14248 | 14306 |
| 14307 Texture::ImageState image_state; | |
| 14308 | |
| 14249 // Do nothing when image is not currently bound. | 14309 // Do nothing when image is not currently bound. |
| 14250 if (texture_ref->texture()->GetLevelImage(target, 0) != gl_image) | 14310 if (texture_ref->texture()->GetLevelImage(target, 0, &image_state) != image) |
| 14251 return; | 14311 return; |
| 14252 | 14312 |
| 14253 { | 14313 { |
| 14254 ScopedGLErrorSuppressor suppressor( | 14314 ScopedGLErrorSuppressor suppressor( |
| 14255 "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM", GetErrorState()); | 14315 "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM", GetErrorState()); |
| 14256 gl_image->ReleaseTexImage(target); | 14316 |
| 14317 if (image_state == Texture::BOUND) | |
| 14318 image->ReleaseTexImage(target); | |
| 14319 | |
| 14320 if (image_state == Texture::COPIED) { | |
| 14321 // Effectively frees the texture storage without deleting the texture id. | |
| 14322 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, | |
| 14323 GL_UNSIGNED_BYTE, nullptr); | |
| 14324 } | |
| 14257 } | 14325 } |
| 14258 | 14326 |
| 14259 texture_manager()->SetLevelInfo( | 14327 texture_manager()->SetLevelInfo( |
| 14260 texture_ref, target, 0, gl_image->GetInternalFormat(), 0, 0, 1, 0, | 14328 texture_ref, target, 0, image->GetInternalFormat(), 0, 0, 1, 0, |
| 14261 gl_image->GetInternalFormat(), GL_UNSIGNED_BYTE, gfx::Rect()); | 14329 image->GetInternalFormat(), GL_UNSIGNED_BYTE, gfx::Rect()); |
| 14262 } | 14330 } |
| 14263 | 14331 |
| 14264 error::Error GLES2DecoderImpl::HandleTraceBeginCHROMIUM( | 14332 error::Error GLES2DecoderImpl::HandleTraceBeginCHROMIUM( |
| 14265 uint32 immediate_data_size, | 14333 uint32 immediate_data_size, |
| 14266 const void* cmd_data) { | 14334 const void* cmd_data) { |
| 14267 const gles2::cmds::TraceBeginCHROMIUM& c = | 14335 const gles2::cmds::TraceBeginCHROMIUM& c = |
| 14268 *static_cast<const gles2::cmds::TraceBeginCHROMIUM*>(cmd_data); | 14336 *static_cast<const gles2::cmds::TraceBeginCHROMIUM*>(cmd_data); |
| 14269 Bucket* category_bucket = GetBucket(c.category_bucket_id); | 14337 Bucket* category_bucket = GetBucket(c.category_bucket_id); |
| 14270 Bucket* name_bucket = GetBucket(c.name_bucket_id); | 14338 Bucket* name_bucket = GetBucket(c.name_bucket_id); |
| 14271 if (!category_bucket || category_bucket->size() == 0 || | 14339 if (!category_bucket || category_bucket->size() == 0 || |
| (...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15066 return error::kNoError; | 15134 return error::kNoError; |
| 15067 } | 15135 } |
| 15068 | 15136 |
| 15069 // Include the auto-generated part of this file. We split this because it means | 15137 // Include the auto-generated part of this file. We split this because it means |
| 15070 // we can easily edit the non-auto generated parts right here in this file | 15138 // we can easily edit the non-auto generated parts right here in this file |
| 15071 // instead of having to edit some template or the code generator. | 15139 // instead of having to edit some template or the code generator. |
| 15072 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 15140 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 15073 | 15141 |
| 15074 } // namespace gles2 | 15142 } // namespace gles2 |
| 15075 } // namespace gpu | 15143 } // namespace gpu |
| OLD | NEW |