| 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 10029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10040 } | 10040 } |
| 10041 | 10041 |
| 10042 // Clear the source texture if necessary. | 10042 // Clear the source texture if necessary. |
| 10043 if (!texture_manager()->ClearTextureLevel( | 10043 if (!texture_manager()->ClearTextureLevel( |
| 10044 this, source_texture_ref, source_texture->target(), 0)) { | 10044 this, source_texture_ref, source_texture->target(), 0)) { |
| 10045 LOCAL_SET_GL_ERROR( | 10045 LOCAL_SET_GL_ERROR( |
| 10046 GL_OUT_OF_MEMORY, "glCopyTextureCHROMIUM", "dimensions too big"); | 10046 GL_OUT_OF_MEMORY, "glCopyTextureCHROMIUM", "dimensions too big"); |
| 10047 return; | 10047 return; |
| 10048 } | 10048 } |
| 10049 | 10049 |
| 10050 GLenum source_type = 0; |
| 10051 GLenum source_internal_format = 0; |
| 10052 source_texture->GetLevelType( |
| 10053 source_texture->target(), 0, &source_type, &source_internal_format); |
| 10054 |
| 10055 // The destination format should be GL_RGB, or GL_RGBA. GL_ALPHA, |
| 10056 // GL_LUMINANCE, and GL_LUMINANCE_ALPHA are not supported because they are not |
| 10057 // renderable on some platforms. |
| 10058 bool valid_dest_format = |
| 10059 internal_format == GL_RGB || internal_format == GL_RGBA; |
| 10060 bool valid_source_format = source_internal_format == GL_ALPHA || |
| 10061 source_internal_format == GL_RGB || |
| 10062 source_internal_format == GL_RGBA || |
| 10063 source_internal_format == GL_LUMINANCE || |
| 10064 source_internal_format == GL_LUMINANCE_ALPHA || |
| 10065 source_internal_format == GL_BGRA_EXT; |
| 10066 if (!valid_source_format || !valid_dest_format) { |
| 10067 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 10068 "glCopyTextureCHROMIUM", |
| 10069 "invalid internal format"); |
| 10070 return; |
| 10071 } |
| 10072 |
| 10050 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is | 10073 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is |
| 10051 // needed because it takes 10s of milliseconds to initialize. | 10074 // needed because it takes 10s of milliseconds to initialize. |
| 10052 if (!copy_texture_CHROMIUM_.get()) { | 10075 if (!copy_texture_CHROMIUM_.get()) { |
| 10053 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); | 10076 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
| 10054 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); | 10077 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); |
| 10055 copy_texture_CHROMIUM_->Initialize(this); | 10078 copy_texture_CHROMIUM_->Initialize(this); |
| 10056 RestoreCurrentFramebufferBindings(); | 10079 RestoreCurrentFramebufferBindings(); |
| 10057 if (LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM") != GL_NO_ERROR) | 10080 if (LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM") != GL_NO_ERROR) |
| 10058 return; | 10081 return; |
| 10059 } | 10082 } |
| 10060 | 10083 |
| 10061 GLenum source_type = 0; | |
| 10062 GLenum source_internal_format = 0; | |
| 10063 source_texture->GetLevelType( | |
| 10064 source_texture->target(), 0, &source_type, &source_internal_format); | |
| 10065 | |
| 10066 GLenum dest_type_previous = dest_type; | 10084 GLenum dest_type_previous = dest_type; |
| 10067 GLenum dest_internal_format = internal_format; | 10085 GLenum dest_internal_format = internal_format; |
| 10068 bool dest_level_defined = dest_texture->GetLevelSize( | 10086 bool dest_level_defined = dest_texture->GetLevelSize( |
| 10069 GL_TEXTURE_2D, level, &dest_width, &dest_height); | 10087 GL_TEXTURE_2D, level, &dest_width, &dest_height); |
| 10070 | 10088 |
| 10071 if (dest_level_defined) { | 10089 if (dest_level_defined) { |
| 10072 dest_texture->GetLevelType(GL_TEXTURE_2D, level, &dest_type_previous, | 10090 dest_texture->GetLevelType(GL_TEXTURE_2D, level, &dest_type_previous, |
| 10073 &dest_internal_format); | 10091 &dest_internal_format); |
| 10074 } | 10092 } |
| 10075 | 10093 |
| 10076 // The destination format should be GL_ALPHA, GL_RGB, GL_RGBA, GL_LUMINANCE, | |
| 10077 // or GL_LUMINANCE_ALPHA. | |
| 10078 bool valid_dest_format = dest_internal_format >= GL_ALPHA && | |
| 10079 dest_internal_format <= GL_LUMINANCE_ALPHA; | |
| 10080 // The source format can be GL_BGRA_EXT. | |
| 10081 bool valid_source_format = (source_internal_format >= GL_ALPHA && | |
| 10082 source_internal_format <= GL_LUMINANCE_ALPHA) || | |
| 10083 source_internal_format == GL_BGRA_EXT; | |
| 10084 if (!valid_source_format || !valid_dest_format) { | |
| 10085 LOCAL_SET_GL_ERROR( | |
| 10086 GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "invalid internal format"); | |
| 10087 return; | |
| 10088 } | |
| 10089 | |
| 10090 // Resize the destination texture to the dimensions of the source texture. | 10094 // Resize the destination texture to the dimensions of the source texture. |
| 10091 if (!dest_level_defined || dest_width != source_width || | 10095 if (!dest_level_defined || dest_width != source_width || |
| 10092 dest_height != source_height || | 10096 dest_height != source_height || |
| 10093 dest_internal_format != internal_format || | 10097 dest_internal_format != internal_format || |
| 10094 dest_type_previous != dest_type) { | 10098 dest_type_previous != dest_type) { |
| 10095 // Ensure that the glTexImage2D succeeds. | 10099 // Ensure that the glTexImage2D succeeds. |
| 10096 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); | 10100 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
| 10097 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); | 10101 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
| 10098 glTexImage2D( | 10102 glTexImage2D( |
| 10099 GL_TEXTURE_2D, level, internal_format, source_width, source_height, | 10103 GL_TEXTURE_2D, level, internal_format, source_width, source_height, |
| (...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10957 } | 10961 } |
| 10958 } | 10962 } |
| 10959 | 10963 |
| 10960 // Include the auto-generated part of this file. We split this because it means | 10964 // Include the auto-generated part of this file. We split this because it means |
| 10961 // we can easily edit the non-auto generated parts right here in this file | 10965 // we can easily edit the non-auto generated parts right here in this file |
| 10962 // instead of having to edit some template or the code generator. | 10966 // instead of having to edit some template or the code generator. |
| 10963 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 10967 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 10964 | 10968 |
| 10965 } // namespace gles2 | 10969 } // namespace gles2 |
| 10966 } // namespace gpu | 10970 } // namespace gpu |
| OLD | NEW |