Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 977853002: Reland of Revert of gpu: introduce glCopySubTextureCHROMIUM (patchset #1 id:1 of https://codereview… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Apply image opt when offsets are zero Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 #if defined(OS_WIN) 75 #if defined(OS_WIN)
76 #include "base/win/win_util.h" 76 #include "base/win/win_util.h"
77 #endif 77 #endif
78 78
79 namespace gpu { 79 namespace gpu {
80 namespace gles2 { 80 namespace gles2 {
81 81
82 namespace { 82 namespace {
83 83
84 static const char kOESDerivativeExtension[] = "GL_OES_standard_derivatives"; 84 const char kOESDerivativeExtension[] = "GL_OES_standard_derivatives";
85 static const char kEXTFragDepthExtension[] = "GL_EXT_frag_depth"; 85 const char kEXTFragDepthExtension[] = "GL_EXT_frag_depth";
86 static const char kEXTDrawBuffersExtension[] = "GL_EXT_draw_buffers"; 86 const char kEXTDrawBuffersExtension[] = "GL_EXT_draw_buffers";
87 static const char kEXTShaderTextureLodExtension[] = "GL_EXT_shader_texture_lod"; 87 const char kEXTShaderTextureLodExtension[] = "GL_EXT_shader_texture_lod";
88
89 const GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f,
90 0.0f, 1.0f, 0.0f, 0.0f,
91 0.0f, 0.0f, 1.0f, 0.0f,
92 0.0f, 0.0f, 0.0f, 1.0f};
88 93
89 static bool PrecisionMeetsSpecForHighpFloat(GLint rangeMin, 94 static bool PrecisionMeetsSpecForHighpFloat(GLint rangeMin,
90 GLint rangeMax, 95 GLint rangeMax,
91 GLint precision) { 96 GLint precision) {
92 return (rangeMin >= 62) && (rangeMax >= 62) && (precision >= 16); 97 return (rangeMin >= 62) && (rangeMax >= 62) && (precision >= 16);
93 } 98 }
94 99
95 static void GetShaderPrecisionFormatImpl(GLenum shader_type, 100 static void GetShaderPrecisionFormatImpl(GLenum shader_type,
96 GLenum precision_type, 101 GLenum precision_type,
97 GLint *range, GLint *precision) { 102 GLint *range, GLint *precision) {
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 const void * data); 934 const void * data);
930 935
931 // Wrapper for TexImageIOSurface2DCHROMIUM. 936 // Wrapper for TexImageIOSurface2DCHROMIUM.
932 void DoTexImageIOSurface2DCHROMIUM( 937 void DoTexImageIOSurface2DCHROMIUM(
933 GLenum target, 938 GLenum target,
934 GLsizei width, 939 GLsizei width,
935 GLsizei height, 940 GLsizei height,
936 GLuint io_surface_id, 941 GLuint io_surface_id,
937 GLuint plane); 942 GLuint plane);
938 943
939 void DoCopyTextureCHROMIUM( 944 void DoCopyTextureCHROMIUM(GLenum target,
940 GLenum target, 945 GLuint source_id,
941 GLuint source_id, 946 GLuint dest_id,
942 GLuint target_id, 947 GLenum internal_format,
943 GLint level, 948 GLenum dest_type);
944 GLenum internal_format, 949
945 GLenum dest_type); 950 void DoCopySubTextureCHROMIUM(GLenum target,
951 GLuint source_id,
952 GLuint dest_id,
953 GLint xoffset,
954 GLint yoffset);
946 955
947 // Wrapper for TexStorage2DEXT. 956 // Wrapper for TexStorage2DEXT.
948 void DoTexStorage2DEXT( 957 void DoTexStorage2DEXT(
949 GLenum target, 958 GLenum target,
950 GLint levels, 959 GLint levels,
951 GLenum internal_format, 960 GLenum internal_format,
952 GLsizei width, 961 GLsizei width,
953 GLsizei height); 962 GLsizei height);
954 963
955 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); 964 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key);
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 const char* function_name, 1660 const char* function_name,
1652 GLint level, GLsizei width, GLsizei height, GLenum format); 1661 GLint level, GLsizei width, GLsizei height, GLenum format);
1653 bool ValidateCompressedTexFuncData( 1662 bool ValidateCompressedTexFuncData(
1654 const char* function_name, 1663 const char* function_name,
1655 GLsizei width, GLsizei height, GLenum format, size_t size); 1664 GLsizei width, GLsizei height, GLenum format, size_t size);
1656 bool ValidateCompressedTexSubDimensions( 1665 bool ValidateCompressedTexSubDimensions(
1657 const char* function_name, 1666 const char* function_name,
1658 GLenum target, GLint level, GLint xoffset, GLint yoffset, 1667 GLenum target, GLint level, GLint xoffset, GLint yoffset,
1659 GLsizei width, GLsizei height, GLenum format, 1668 GLsizei width, GLsizei height, GLenum format,
1660 Texture* texture); 1669 Texture* texture);
1670 bool ValidateCopyTextureCHROMIUM(const char* function_name,
1671 GLenum target,
1672 TextureRef* source_texture_ref,
1673 TextureRef* dest_texture_ref,
1674 GLenum dest_internal_format);
1661 1675
1662 void RenderWarning(const char* filename, int line, const std::string& msg); 1676 void RenderWarning(const char* filename, int line, const std::string& msg);
1663 void PerformanceWarning( 1677 void PerformanceWarning(
1664 const char* filename, int line, const std::string& msg); 1678 const char* filename, int line, const std::string& msg);
1665 1679
1666 const FeatureInfo::FeatureFlags& features() const { 1680 const FeatureInfo::FeatureFlags& features() const {
1667 return feature_info_->feature_flags(); 1681 return feature_info_->feature_flags();
1668 } 1682 }
1669 1683
1670 const FeatureInfo::Workarounds& workarounds() const { 1684 const FeatureInfo::Workarounds& workarounds() const {
(...skipping 9269 matching lines...) Expand 10 before | Expand all | Expand 10 after
10940 return GL_LUMINANCE_ALPHA; 10954 return GL_LUMINANCE_ALPHA;
10941 case GL_BGRA8_EXT: 10955 case GL_BGRA8_EXT:
10942 return GL_BGRA_EXT; 10956 return GL_BGRA_EXT;
10943 case GL_SRGB8_ALPHA8_EXT: 10957 case GL_SRGB8_ALPHA8_EXT:
10944 return GL_SRGB_ALPHA_EXT; 10958 return GL_SRGB_ALPHA_EXT;
10945 default: 10959 default:
10946 return GL_NONE; 10960 return GL_NONE;
10947 } 10961 }
10948 } 10962 }
10949 10963
10950 void GLES2DecoderImpl::DoCopyTextureCHROMIUM( 10964 bool GLES2DecoderImpl::ValidateCopyTextureCHROMIUM(
10951 GLenum target, GLuint source_id, GLuint dest_id, GLint level, 10965 const char* function_name,
10952 GLenum internal_format, GLenum dest_type) { 10966 GLenum target,
10953 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); 10967 TextureRef* source_texture_ref,
10954 10968 TextureRef* dest_texture_ref,
10955 TextureRef* dest_texture_ref = GetTexture(dest_id); 10969 GLenum dest_internal_format) {
10956 TextureRef* source_texture_ref = GetTexture(source_id);
10957
10958 if (!source_texture_ref || !dest_texture_ref) { 10970 if (!source_texture_ref || !dest_texture_ref) {
10959 LOCAL_SET_GL_ERROR( 10971 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown texture id");
10960 GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "unknown texture id"); 10972 return false;
10961 return;
10962 } 10973 }
10963 10974
10964 if (GL_TEXTURE_2D != target) { 10975 if (GL_TEXTURE_2D != target) {
10965 LOCAL_SET_GL_ERROR( 10976 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name,
10966 GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "invalid texture target"); 10977 "invalid texture target");
10967 return; 10978 return false;
10968 } 10979 }
10969 10980
10970 Texture* source_texture = source_texture_ref->texture(); 10981 Texture* source_texture = source_texture_ref->texture();
10971 Texture* dest_texture = dest_texture_ref->texture(); 10982 Texture* dest_texture = dest_texture_ref->texture();
10983 if (source_texture == dest_texture) {
10984 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name,
10985 "source and destination textures are the same");
10986 return false;
10987 }
10988
10972 if (dest_texture->target() != GL_TEXTURE_2D || 10989 if (dest_texture->target() != GL_TEXTURE_2D ||
10973 (source_texture->target() != GL_TEXTURE_2D && 10990 (source_texture->target() != GL_TEXTURE_2D &&
10974 source_texture->target() != GL_TEXTURE_RECTANGLE_ARB && 10991 source_texture->target() != GL_TEXTURE_RECTANGLE_ARB &&
10975 source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) { 10992 source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) {
10976 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, 10993 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name,
10977 "glCopyTextureCHROMIUM",
10978 "invalid texture target binding"); 10994 "invalid texture target binding");
10979 return; 10995 return false;
10980 } 10996 }
10981 10997
10982 int source_width, source_height, dest_width, dest_height; 10998 GLenum source_type = 0;
10999 GLenum source_internal_format = 0;
11000 source_texture->GetLevelType(source_texture->target(), 0, &source_type,
11001 &source_internal_format);
10983 11002
11003 // The destination format should be GL_RGB, or GL_RGBA. GL_ALPHA,
11004 // GL_LUMINANCE, and GL_LUMINANCE_ALPHA are not supported because they are not
11005 // renderable on some platforms.
11006 bool valid_dest_format = dest_internal_format == GL_RGB ||
11007 dest_internal_format == GL_RGBA ||
11008 dest_internal_format == GL_BGRA_EXT;
11009 bool valid_source_format = source_internal_format == GL_ALPHA ||
11010 source_internal_format == GL_RGB ||
11011 source_internal_format == GL_RGBA ||
11012 source_internal_format == GL_LUMINANCE ||
11013 source_internal_format == GL_LUMINANCE_ALPHA ||
11014 source_internal_format == GL_BGRA_EXT;
11015 if (!valid_source_format || !valid_dest_format) {
11016 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name,
11017 "invalid internal format");
11018 return false;
11019 }
11020 return true;
11021 }
11022
11023 void GLES2DecoderImpl::DoCopyTextureCHROMIUM(GLenum target,
11024 GLuint source_id,
11025 GLuint dest_id,
11026 GLenum internal_format,
11027 GLenum dest_type) {
11028 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM");
11029
11030 TextureRef* source_texture_ref = GetTexture(source_id);
11031 TextureRef* dest_texture_ref = GetTexture(dest_id);
11032 Texture* source_texture = source_texture_ref->texture();
11033 Texture* dest_texture = dest_texture_ref->texture();
11034 int source_width = 0;
11035 int source_height = 0;
10984 gfx::GLImage* image = 11036 gfx::GLImage* image =
10985 source_texture->GetLevelImage(source_texture->target(), 0); 11037 source_texture->GetLevelImage(source_texture->target(), 0);
10986 if (image) { 11038 if (image) {
10987 gfx::Size size = image->GetSize(); 11039 gfx::Size size = image->GetSize();
10988 source_width = size.width(); 11040 source_width = size.width();
10989 source_height = size.height(); 11041 source_height = size.height();
10990 if (source_width <= 0 || source_height <= 0) { 11042 if (source_width <= 0 || source_height <= 0) {
10991 LOCAL_SET_GL_ERROR( 11043 LOCAL_SET_GL_ERROR(
10992 GL_INVALID_VALUE, 11044 GL_INVALID_VALUE,
10993 "glCopyTextureChromium", "invalid image size"); 11045 "glCopyTextureChromium", "invalid image size");
10994 return; 11046 return;
10995 } 11047 }
10996 } else { 11048 } else {
10997 if (!source_texture->GetLevelSize( 11049 if (!source_texture->GetLevelSize(
10998 source_texture->target(), 0, &source_width, &source_height)) { 11050 source_texture->target(), 0, &source_width, &source_height)) {
10999 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, 11051 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE,
11000 "glCopyTextureChromium", 11052 "glCopyTextureChromium",
11001 "source texture has no level 0"); 11053 "source texture has no level 0");
11002 return; 11054 return;
11003 } 11055 }
11004 11056
11005 // Check that this type of texture is allowed. 11057 // Check that this type of texture is allowed.
11006 if (!texture_manager()->ValidForTarget( 11058 if (!texture_manager()->ValidForTarget(source_texture->target(), 0,
11007 source_texture->target(), level, source_width, source_height, 1)) { 11059 source_width, source_height, 1)) {
11008 LOCAL_SET_GL_ERROR( 11060 LOCAL_SET_GL_ERROR(
11009 GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "Bad dimensions"); 11061 GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "Bad dimensions");
11010 return; 11062 return;
11011 } 11063 }
11012 } 11064 }
11013 11065
11014 // Clear the source texture if necessary.
11015 if (!texture_manager()->ClearTextureLevel(
11016 this, source_texture_ref, source_texture->target(), 0)) {
11017 LOCAL_SET_GL_ERROR(
11018 GL_OUT_OF_MEMORY, "glCopyTextureCHROMIUM", "dimensions too big");
11019 return;
11020 }
11021
11022 GLenum source_type = 0; 11066 GLenum source_type = 0;
11023 GLenum source_internal_format = 0; 11067 GLenum source_internal_format = 0;
11024 source_texture->GetLevelType( 11068 source_texture->GetLevelType(
11025 source_texture->target(), 0, &source_type, &source_internal_format); 11069 source_texture->target(), 0, &source_type, &source_internal_format);
11026 11070
11027 // The destination format should be GL_RGB, or GL_RGBA. GL_ALPHA, 11071 if (dest_texture->IsImmutable()) {
11028 // GL_LUMINANCE, and GL_LUMINANCE_ALPHA are not supported because they are not 11072 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCopyTextureCHROMIUM",
11029 // renderable on some platforms. 11073 "texture is immutable");
11030 bool valid_dest_format = internal_format == GL_RGB ||
11031 internal_format == GL_RGBA ||
11032 internal_format == GL_BGRA_EXT;
11033 bool valid_source_format = source_internal_format == GL_ALPHA ||
11034 source_internal_format == GL_RGB ||
11035 source_internal_format == GL_RGBA ||
11036 source_internal_format == GL_LUMINANCE ||
11037 source_internal_format == GL_LUMINANCE_ALPHA ||
11038 source_internal_format == GL_BGRA_EXT;
11039 if (!valid_source_format || !valid_dest_format) {
11040 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION,
11041 "glCopyTextureCHROMIUM",
11042 "invalid internal format");
11043 return; 11074 return;
11044 } 11075 }
11045 11076
11077 if (!ValidateCopyTextureCHROMIUM("glCopyTextureCHROMIUM", target,
11078 source_texture_ref, dest_texture_ref,
11079 internal_format)) {
11080 return;
11081 }
11082
11083 // Clear the source texture if necessary.
11084 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref,
11085 source_texture->target(), 0)) {
11086 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopyTextureCHROMIUM",
11087 "dimensions too big");
11088 return;
11089 }
11090
11046 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is 11091 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is
11047 // needed because it takes 10s of milliseconds to initialize. 11092 // needed because it takes 10s of milliseconds to initialize.
11048 if (!copy_texture_CHROMIUM_.get()) { 11093 if (!copy_texture_CHROMIUM_.get()) {
11049 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); 11094 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM");
11050 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); 11095 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager());
11051 copy_texture_CHROMIUM_->Initialize(this); 11096 copy_texture_CHROMIUM_->Initialize(this);
11052 RestoreCurrentFramebufferBindings(); 11097 RestoreCurrentFramebufferBindings();
11053 if (LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM") != GL_NO_ERROR) 11098 if (LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM") != GL_NO_ERROR)
11054 return; 11099 return;
11055 } 11100 }
11056 11101
11057 GLenum dest_type_previous = dest_type; 11102 GLenum dest_type_previous = dest_type;
11058 GLenum dest_internal_format = internal_format; 11103 GLenum dest_internal_format = internal_format;
11059 bool dest_level_defined = dest_texture->GetLevelSize( 11104 int dest_width = 0;
11060 GL_TEXTURE_2D, level, &dest_width, &dest_height); 11105 int dest_height = 0;
11106 bool dest_level_defined =
11107 dest_texture->GetLevelSize(GL_TEXTURE_2D, 0, &dest_width, &dest_height);
11061 11108
11062 if (dest_level_defined) { 11109 if (dest_level_defined) {
11063 dest_texture->GetLevelType(GL_TEXTURE_2D, level, &dest_type_previous, 11110 dest_texture->GetLevelType(GL_TEXTURE_2D, 0, &dest_type_previous,
11064 &dest_internal_format); 11111 &dest_internal_format);
11065 } 11112 }
11066 11113
11067 // Resize the destination texture to the dimensions of the source texture. 11114 // Resize the destination texture to the dimensions of the source texture.
11068 if (!dest_level_defined || dest_width != source_width || 11115 if (!dest_level_defined || dest_width != source_width ||
11069 dest_height != source_height || 11116 dest_height != source_height ||
11070 dest_internal_format != internal_format || 11117 dest_internal_format != internal_format ||
11071 dest_type_previous != dest_type) { 11118 dest_type_previous != dest_type) {
11072 // Ensure that the glTexImage2D succeeds. 11119 // Ensure that the glTexImage2D succeeds.
11073 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); 11120 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM");
11074 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); 11121 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id());
11075 glTexImage2D( 11122 glTexImage2D(GL_TEXTURE_2D, 0, internal_format, source_width, source_height,
11076 GL_TEXTURE_2D, level, internal_format, source_width, source_height, 11123 0, internal_format, dest_type, NULL);
11077 0, internal_format, dest_type, NULL);
11078 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM"); 11124 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM");
11079 if (error != GL_NO_ERROR) { 11125 if (error != GL_NO_ERROR) {
11080 RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D); 11126 RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D);
11081 return; 11127 return;
11082 } 11128 }
11083 11129
11084 texture_manager()->SetLevelInfo( 11130 texture_manager()->SetLevelInfo(
11085 dest_texture_ref, GL_TEXTURE_2D, level, internal_format, source_width, 11131 dest_texture_ref, GL_TEXTURE_2D, 0, internal_format, source_width,
11086 source_height, 1, 0, internal_format, dest_type, true); 11132 source_height, 1, 0, internal_format, dest_type, true);
11087 } else { 11133 } else {
11088 texture_manager()->SetLevelCleared( 11134 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0,
11089 dest_texture_ref, GL_TEXTURE_2D, level, true); 11135 true);
11090 } 11136 }
11091 11137
11092 ScopedModifyPixels modify(dest_texture_ref); 11138 ScopedModifyPixels modify(dest_texture_ref);
11093 11139
11094 // Try using GLImage::CopyTexImage when possible. 11140 // Try using GLImage::CopyTexImage when possible.
11095 bool unpack_premultiply_alpha_change = 11141 bool unpack_premultiply_alpha_change =
11096 unpack_premultiply_alpha_ ^ unpack_unpremultiply_alpha_; 11142 unpack_premultiply_alpha_ ^ unpack_unpremultiply_alpha_;
11097 if (image && !unpack_flip_y_ && !unpack_premultiply_alpha_change && !level) { 11143 if (image && !unpack_flip_y_ && !unpack_premultiply_alpha_change) {
11098 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); 11144 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id());
11099 if (image->CopyTexImage(GL_TEXTURE_2D)) 11145 if (image->CopyTexImage(GL_TEXTURE_2D))
reveman 2015/03/05 13:46:23 Are we still allowed to use CopyTexImage in the Do
dshwang 2015/03/05 14:55:59 It's not needed for zero/one-copy. currently no cl
reveman 2015/03/05 18:20:00 You can keep it if you like. I just wanted to make
11100 return; 11146 return;
11101 } 11147 }
11102 11148
11103 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); 11149 DoWillUseTexImageIfNeeded(source_texture, source_texture->target());
11104 11150
11105 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix 11151 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix
11106 // before presenting. 11152 // before presenting.
11107 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { 11153 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) {
11108 // TODO(hkuang): get the StreamTexture transform matrix in GPU process 11154 // TODO(hkuang): get the StreamTexture transform matrix in GPU process
11109 // instead of using default matrix crbug.com/226218. 11155 // instead of using kIdentityMatrix crbug.com/226218.
11110 const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f,
11111 0.0f, 1.0f, 0.0f, 0.0f,
11112 0.0f, 0.0f, 1.0f, 0.0f,
11113 0.0f, 0.0f, 0.0f, 1.0f};
11114 copy_texture_CHROMIUM_->DoCopyTextureWithTransform( 11156 copy_texture_CHROMIUM_->DoCopyTextureWithTransform(
11115 this, 11157 this, source_texture->target(), source_texture->service_id(),
11116 source_texture->target(), 11158 dest_texture->service_id(), source_width, source_height, unpack_flip_y_,
11117 source_texture->service_id(), 11159 unpack_premultiply_alpha_, unpack_unpremultiply_alpha_,
11118 dest_texture->service_id(), 11160 kIdentityMatrix);
11119 level,
11120 source_width,
11121 source_height,
11122 unpack_flip_y_,
11123 unpack_premultiply_alpha_,
11124 unpack_unpremultiply_alpha_,
11125 default_matrix);
11126 } else { 11161 } else {
11127 copy_texture_CHROMIUM_->DoCopyTexture(this, 11162 copy_texture_CHROMIUM_->DoCopyTexture(
11128 source_texture->target(), 11163 this, source_texture->target(), source_texture->service_id(),
11129 source_texture->service_id(), 11164 source_internal_format, dest_texture->service_id(), internal_format,
11130 source_internal_format, 11165 source_width, source_height, unpack_flip_y_, unpack_premultiply_alpha_,
11131 dest_texture->service_id(), 11166 unpack_unpremultiply_alpha_);
11132 level,
11133 internal_format,
11134 source_width,
11135 source_height,
11136 unpack_flip_y_,
11137 unpack_premultiply_alpha_,
11138 unpack_unpremultiply_alpha_);
11139 } 11167 }
11140 11168
11141 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); 11169 DoDidUseTexImageIfNeeded(source_texture, source_texture->target());
11170 }
11171
11172 void GLES2DecoderImpl::DoCopySubTextureCHROMIUM(GLenum target,
11173 GLuint source_id,
11174 GLuint dest_id,
11175 GLint xoffset,
11176 GLint yoffset) {
11177 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopySubTextureCHROMIUM");
11178
11179 TextureRef* source_texture_ref = GetTexture(source_id);
11180 TextureRef* dest_texture_ref = GetTexture(dest_id);
11181 Texture* source_texture = source_texture_ref->texture();
11182 Texture* dest_texture = dest_texture_ref->texture();
11183 int source_width = 0;
11184 int source_height = 0;
11185 gfx::GLImage* image =
11186 source_texture->GetLevelImage(source_texture->target(), 0);
11187 if (image) {
11188 gfx::Size size = image->GetSize();
11189 source_width = size.width();
11190 source_height = size.height();
11191 if (source_width <= 0 || source_height <= 0) {
11192 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM",
11193 "invalid image size");
11194 return;
11195 }
11196 } else {
11197 if (!source_texture->GetLevelSize(source_texture->target(), 0,
11198 &source_width, &source_height)) {
11199 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM",
11200 "source texture has no level 0");
11201 return;
11202 }
11203
11204 // Check that this type of texture is allowed.
11205 if (!texture_manager()->ValidForTarget(source_texture->target(), 0,
11206 source_width, source_height, 1)) {
11207 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM",
11208 "source texture bad dimensions");
11209 return;
11210 }
11211 }
11212
11213 GLenum source_type = 0;
11214 GLenum source_internal_format = 0;
11215 source_texture->GetLevelType(source_texture->target(), 0, &source_type,
11216 &source_internal_format);
11217 GLenum dest_type = 0;
11218 GLenum dest_internal_format = 0;
11219 bool dest_level_defined = dest_texture->GetLevelType(
11220 dest_texture->target(), 0, &dest_type, &dest_internal_format);
11221 if (!dest_level_defined) {
11222 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCopySubTextureCHROMIUM",
11223 "destination texture is not defined");
11224 return;
11225 }
11226 if (!dest_texture->ValidForTexture(dest_texture->target(), 0, xoffset,
11227 yoffset, source_width, source_height,
11228 dest_type)) {
11229 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM",
11230 "destination texture bad dimensions.");
11231 return;
11232 }
11233
11234 if (!ValidateCopyTextureCHROMIUM("glCopySubTextureCHROMIUM", target,
11235 source_texture_ref, dest_texture_ref,
11236 dest_internal_format)) {
11237 return;
11238 }
11239
11240 // Clear the source texture if necessary.
11241 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref,
11242 source_texture->target(), 0)) {
11243 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopySubTextureCHROMIUM",
11244 "source texture dimensions too big");
11245 return;
11246 }
11247
11248 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is
11249 // needed because it takes 10s of milliseconds to initialize.
11250 if (!copy_texture_CHROMIUM_.get()) {
11251 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopySubTextureCHROMIUM");
11252 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager());
11253 copy_texture_CHROMIUM_->Initialize(this);
11254 RestoreCurrentFramebufferBindings();
11255 if (LOCAL_PEEK_GL_ERROR("glCopySubTextureCHROMIUM") != GL_NO_ERROR)
11256 return;
11257 }
11258
11259 int dest_width = 0;
11260 int dest_height = 0;
11261 bool ok =
11262 dest_texture->GetLevelSize(GL_TEXTURE_2D, 0, &dest_width, &dest_height);
11263 DCHECK(ok);
11264 if (xoffset != 0 || yoffset != 0 || source_width != dest_width ||
11265 source_height != dest_height) {
11266 if (!texture_manager()->ClearTextureLevel(this, dest_texture_ref, target,
11267 0)) {
11268 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopySubTextureCHROMIUM",
11269 "destination texture dimensions too big");
11270 return;
11271 }
11272 } else {
11273 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0,
11274 true);
11275 }
11276
11277 ScopedModifyPixels modify(dest_texture_ref);
11278
11279 // Try using GLImage::CopyTexSubImage when possible.
11280 bool unpack_premultiply_alpha_change =
11281 unpack_premultiply_alpha_ ^ unpack_unpremultiply_alpha_;
11282 if (image && !unpack_flip_y_ && !unpack_premultiply_alpha_change &&
11283 !xoffset && !yoffset) {
11284 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id());
11285 if (image->CopyTexImage(GL_TEXTURE_2D))
11286 return;
11287 }
11288
11289 DoWillUseTexImageIfNeeded(source_texture, source_texture->target());
11290
11291 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix
11292 // before presenting.
11293 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) {
11294 // TODO(hkuang): get the StreamTexture transform matrix in GPU process
11295 // instead of using kIdentityMatrix crbug.com/226218.
11296 copy_texture_CHROMIUM_->DoCopySubTextureWithTransform(
11297 this, source_texture->target(), source_texture->service_id(),
11298 dest_texture->service_id(), xoffset, yoffset, dest_width, dest_height,
11299 source_width, source_height, unpack_flip_y_, unpack_premultiply_alpha_,
11300 unpack_unpremultiply_alpha_, kIdentityMatrix);
11301 } else {
11302 copy_texture_CHROMIUM_->DoCopySubTexture(
11303 this, source_texture->target(), source_texture->service_id(),
11304 source_internal_format, dest_texture->service_id(),
11305 dest_internal_format, xoffset, yoffset, dest_width, dest_height,
11306 source_width, source_height, unpack_flip_y_, unpack_premultiply_alpha_,
11307 unpack_unpremultiply_alpha_);
11308 }
11309
11310 DoDidUseTexImageIfNeeded(source_texture, source_texture->target());
11142 } 11311 }
11143 11312
11144 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { 11313 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) {
11145 switch (internalformat) { 11314 switch (internalformat) {
11146 case GL_RGB565: 11315 case GL_RGB565:
11147 return GL_UNSIGNED_SHORT_5_6_5; 11316 return GL_UNSIGNED_SHORT_5_6_5;
11148 case GL_RGBA4: 11317 case GL_RGBA4:
11149 return GL_UNSIGNED_SHORT_4_4_4_4; 11318 return GL_UNSIGNED_SHORT_4_4_4_4;
11150 case GL_RGB5_A1: 11319 case GL_RGB5_A1:
11151 return GL_UNSIGNED_SHORT_5_5_5_1; 11320 return GL_UNSIGNED_SHORT_5_5_5_1;
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
11733 DCHECK(matrix_mode == GL_PATH_PROJECTION_CHROMIUM || 11902 DCHECK(matrix_mode == GL_PATH_PROJECTION_CHROMIUM ||
11734 matrix_mode == GL_PATH_MODELVIEW_CHROMIUM); 11903 matrix_mode == GL_PATH_MODELVIEW_CHROMIUM);
11735 11904
11736 if (!features().chromium_path_rendering) { 11905 if (!features().chromium_path_rendering) {
11737 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, 11906 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION,
11738 "glMatrixLoadIdentityCHROMIUM", 11907 "glMatrixLoadIdentityCHROMIUM",
11739 "function not available"); 11908 "function not available");
11740 return; 11909 return;
11741 } 11910 }
11742 11911
11743 static GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
11744 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
11745 0.0f, 0.0f, 0.0f, 1.0f};
11746
11747 GLfloat* target_matrix = matrix_mode == GL_PATH_PROJECTION_CHROMIUM 11912 GLfloat* target_matrix = matrix_mode == GL_PATH_PROJECTION_CHROMIUM
11748 ? state_.projection_matrix 11913 ? state_.projection_matrix
11749 : state_.modelview_matrix; 11914 : state_.modelview_matrix;
11750 memcpy(target_matrix, kIdentityMatrix, sizeof(kIdentityMatrix)); 11915 memcpy(target_matrix, kIdentityMatrix, sizeof(kIdentityMatrix));
11751 // The matrix_mode is either GL_PATH_MODELVIEW_NV or GL_PATH_PROJECTION_NV 11916 // The matrix_mode is either GL_PATH_MODELVIEW_NV or GL_PATH_PROJECTION_NV
11752 // since the values of the _NV and _CHROMIUM tokens match. 11917 // since the values of the _NV and _CHROMIUM tokens match.
11753 glMatrixLoadIdentityEXT(matrix_mode); 11918 glMatrixLoadIdentityEXT(matrix_mode);
11754 } 11919 }
11755 11920
11756 bool GLES2DecoderImpl::ValidateAsyncTransfer( 11921 bool GLES2DecoderImpl::ValidateAsyncTransfer(
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
12139 } 12304 }
12140 } 12305 }
12141 12306
12142 // Include the auto-generated part of this file. We split this because it means 12307 // Include the auto-generated part of this file. We split this because it means
12143 // we can easily edit the non-auto generated parts right here in this file 12308 // we can easily edit the non-auto generated parts right here in this file
12144 // instead of having to edit some template or the code generator. 12309 // instead of having to edit some template or the code generator.
12145 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 12310 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
12146 12311
12147 } // namespace gles2 12312 } // namespace gles2
12148 } // namespace gpu 12313 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.cc ('k') | gpu/command_buffer/service/gles2_cmd_decoder_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698