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

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

Issue 1119723003: Add glCopyCompressedTextureCHROMIUM (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address issues Created 5 years, 6 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 <cmath> 10 #include <cmath>
(...skipping 30 matching lines...) Expand all
41 #include "gpu/command_buffer/service/error_state.h" 41 #include "gpu/command_buffer/service/error_state.h"
42 #include "gpu/command_buffer/service/feature_info.h" 42 #include "gpu/command_buffer/service/feature_info.h"
43 #include "gpu/command_buffer/service/framebuffer_manager.h" 43 #include "gpu/command_buffer/service/framebuffer_manager.h"
44 #include "gpu/command_buffer/service/gl_utils.h" 44 #include "gpu/command_buffer/service/gl_utils.h"
45 #include "gpu/command_buffer/service/gles2_cmd_clear_framebuffer.h" 45 #include "gpu/command_buffer/service/gles2_cmd_clear_framebuffer.h"
46 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" 46 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h"
47 #include "gpu/command_buffer/service/gles2_cmd_validation.h" 47 #include "gpu/command_buffer/service/gles2_cmd_validation.h"
48 #include "gpu/command_buffer/service/gpu_state_tracer.h" 48 #include "gpu/command_buffer/service/gpu_state_tracer.h"
49 #include "gpu/command_buffer/service/gpu_switches.h" 49 #include "gpu/command_buffer/service/gpu_switches.h"
50 #include "gpu/command_buffer/service/gpu_tracer.h" 50 #include "gpu/command_buffer/service/gpu_tracer.h"
51 #include "gpu/command_buffer/service/image_factory.h"
51 #include "gpu/command_buffer/service/image_manager.h" 52 #include "gpu/command_buffer/service/image_manager.h"
52 #include "gpu/command_buffer/service/mailbox_manager.h" 53 #include "gpu/command_buffer/service/mailbox_manager.h"
53 #include "gpu/command_buffer/service/memory_tracking.h" 54 #include "gpu/command_buffer/service/memory_tracking.h"
54 #include "gpu/command_buffer/service/program_manager.h" 55 #include "gpu/command_buffer/service/program_manager.h"
55 #include "gpu/command_buffer/service/query_manager.h" 56 #include "gpu/command_buffer/service/query_manager.h"
56 #include "gpu/command_buffer/service/renderbuffer_manager.h" 57 #include "gpu/command_buffer/service/renderbuffer_manager.h"
57 #include "gpu/command_buffer/service/shader_manager.h" 58 #include "gpu/command_buffer/service/shader_manager.h"
58 #include "gpu/command_buffer/service/shader_translator.h" 59 #include "gpu/command_buffer/service/shader_translator.h"
59 #include "gpu/command_buffer/service/shader_translator_cache.h" 60 #include "gpu/command_buffer/service/shader_translator_cache.h"
60 #include "gpu/command_buffer/service/texture_manager.h" 61 #include "gpu/command_buffer/service/texture_manager.h"
61 #include "gpu/command_buffer/service/valuebuffer_manager.h" 62 #include "gpu/command_buffer/service/valuebuffer_manager.h"
62 #include "gpu/command_buffer/service/vertex_array_manager.h" 63 #include "gpu/command_buffer/service/vertex_array_manager.h"
63 #include "gpu/command_buffer/service/vertex_attrib_manager.h" 64 #include "gpu/command_buffer/service/vertex_attrib_manager.h"
64 #include "third_party/smhasher/src/City.h" 65 #include "third_party/smhasher/src/City.h"
65 #include "ui/gl/gl_fence.h" 66 #include "ui/gl/gl_fence.h"
66 #include "ui/gl/gl_image.h" 67 #include "ui/gl/gl_image.h"
68 #include "ui/gl/gl_image_memory.h"
reveman 2015/06/12 14:23:35 nit: no longer needed
67 #include "ui/gl/gl_implementation.h" 69 #include "ui/gl/gl_implementation.h"
68 #include "ui/gl/gl_surface.h" 70 #include "ui/gl/gl_surface.h"
69 71
70 #if defined(OS_MACOSX) 72 #if defined(OS_MACOSX)
71 #include <IOSurface/IOSurfaceAPI.h> 73 #include <IOSurface/IOSurfaceAPI.h>
72 // Note that this must be included after gl_bindings.h to avoid conflicts. 74 // Note that this must be included after gl_bindings.h to avoid conflicts.
73 #include <OpenGL/CGLIOSurface.h> 75 #include <OpenGL/CGLIOSurface.h>
74 #endif 76 #endif
75 77
76 namespace gpu { 78 namespace gpu {
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 void DoCopySubTextureCHROMIUM(GLenum target, 1041 void DoCopySubTextureCHROMIUM(GLenum target,
1040 GLuint source_id, 1042 GLuint source_id,
1041 GLuint dest_id, 1043 GLuint dest_id,
1042 GLint xoffset, 1044 GLint xoffset,
1043 GLint yoffset, 1045 GLint yoffset,
1044 GLint x, 1046 GLint x,
1045 GLint y, 1047 GLint y,
1046 GLsizei width, 1048 GLsizei width,
1047 GLsizei height); 1049 GLsizei height);
1048 1050
1051 void DoCompressedCopyTextureCHROMIUM(GLenum target,
1052 GLuint source_id,
1053 GLuint dest_id);
1054
1049 // Wrapper for TexStorage2DEXT. 1055 // Wrapper for TexStorage2DEXT.
1050 void DoTexStorage2DEXT( 1056 void DoTexStorage2DEXT(
1051 GLenum target, 1057 GLenum target,
1052 GLint levels, 1058 GLint levels,
1053 GLenum internal_format, 1059 GLenum internal_format,
1054 GLsizei width, 1060 GLsizei width,
1055 GLsizei height); 1061 GLsizei height);
1056 1062
1057 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); 1063 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key);
1058 void DoProduceTextureDirectCHROMIUM(GLuint texture, GLenum target, 1064 void DoProduceTextureDirectCHROMIUM(GLuint texture, GLenum target,
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
1762 1768
1763 bool WasContextLost() const override; 1769 bool WasContextLost() const override;
1764 bool WasContextLostByRobustnessExtension() const override; 1770 bool WasContextLostByRobustnessExtension() const override;
1765 void MarkContextLost(error::ContextLostReason reason) override; 1771 void MarkContextLost(error::ContextLostReason reason) override;
1766 bool CheckResetStatus(); 1772 bool CheckResetStatus();
1767 1773
1768 #if defined(OS_MACOSX) 1774 #if defined(OS_MACOSX)
1769 void ReleaseIOSurfaceForTexture(GLuint texture_id); 1775 void ReleaseIOSurfaceForTexture(GLuint texture_id);
1770 #endif 1776 #endif
1771 1777
1778 bool GetCompressedTexSizeInBytes(
1779 const char* function_name, GLsizei width, GLsizei height, GLsizei depth,
1780 GLenum format, GLsizei* size_in_bytes);
1781
1772 bool ValidateCompressedTexDimensions( 1782 bool ValidateCompressedTexDimensions(
1773 const char* function_name, GLenum target, GLint level, 1783 const char* function_name, GLenum target, GLint level,
1774 GLsizei width, GLsizei height, GLsizei depth, GLenum format); 1784 GLsizei width, GLsizei height, GLsizei depth, GLenum format);
1775 bool ValidateCompressedTexFuncData( 1785 bool ValidateCompressedTexFuncData(
1776 const char* function_name, GLsizei width, GLsizei height, GLsizei depth, 1786 const char* function_name, GLsizei width, GLsizei height, GLsizei depth,
1777 GLenum format, GLsizei size); 1787 GLenum format, GLsizei size);
1778 bool ValidateCompressedTexSubDimensions( 1788 bool ValidateCompressedTexSubDimensions(
1779 const char* function_name, 1789 const char* function_name,
1780 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, 1790 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
1781 GLsizei width, GLsizei height, GLsizei depth, GLenum format, 1791 GLsizei width, GLsizei height, GLsizei depth, GLenum format,
1782 Texture* texture); 1792 Texture* texture);
1783 bool ValidateCopyTextureCHROMIUM(const char* function_name, 1793 bool ValidateCopyTextureCHROMIUM(const char* function_name,
1784 GLenum target, 1794 GLenum target,
1785 TextureRef* source_texture_ref, 1795 TextureRef* source_texture_ref,
1786 TextureRef* dest_texture_ref, 1796 TextureRef* dest_texture_ref,
1787 GLenum dest_internal_format); 1797 GLenum dest_internal_format);
1798 bool ValidateCompressedCopyTextureCHROMIUM(const char* function_name,
1799 GLenum target,
1800 TextureRef* source_texture_ref,
1801 TextureRef* dest_texture_ref);
1788 1802
1789 void RenderWarning(const char* filename, int line, const std::string& msg); 1803 void RenderWarning(const char* filename, int line, const std::string& msg);
1790 void PerformanceWarning( 1804 void PerformanceWarning(
1791 const char* filename, int line, const std::string& msg); 1805 const char* filename, int line, const std::string& msg);
1792 1806
1793 const FeatureInfo::FeatureFlags& features() const { 1807 const FeatureInfo::FeatureFlags& features() const {
1794 return feature_info_->feature_flags(); 1808 return feature_info_->feature_flags();
1795 } 1809 }
1796 1810
1797 const FeatureInfo::Workarounds& workarounds() const { 1811 const FeatureInfo::Workarounds& workarounds() const {
(...skipping 7224 matching lines...) Expand 10 before | Expand all | Expand 10 after
9022 return (size == 1) || 9036 return (size == 1) ||
9023 (size == 2) || !(size % kS3TCBlockWidth); 9037 (size == 2) || !(size % kS3TCBlockWidth);
9024 } 9038 }
9025 9039
9026 bool IsValidPVRTCSize(GLint level, GLsizei size) { 9040 bool IsValidPVRTCSize(GLint level, GLsizei size) {
9027 return GLES2Util::IsPOT(size); 9041 return GLES2Util::IsPOT(size);
9028 } 9042 }
9029 9043
9030 } // anonymous namespace. 9044 } // anonymous namespace.
9031 9045
9032 bool GLES2DecoderImpl::ValidateCompressedTexFuncData( 9046 bool GLES2DecoderImpl::GetCompressedTexSizeInBytes(
9033 const char* function_name, GLsizei width, GLsizei height, GLsizei depth, 9047 const char* function_name, GLsizei width, GLsizei height, GLsizei depth,
9034 GLenum format, GLsizei size) { 9048 GLenum format, GLsizei* size_in_bytes) {
9035 base::CheckedNumeric<GLsizei> bytes_required(0); 9049 base::CheckedNumeric<GLsizei> bytes_required(0);
9036 9050
9037 switch (format) { 9051 switch (format) {
9038 case GL_ATC_RGB_AMD: 9052 case GL_ATC_RGB_AMD:
9039 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 9053 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
9040 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 9054 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
9041 case GL_ETC1_RGB8_OES: 9055 case GL_ETC1_RGB8_OES:
9042 bytes_required = 9056 bytes_required =
9043 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; 9057 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth;
9044 bytes_required *= 9058 bytes_required *=
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
9095 bytes_required *= 9109 bytes_required *=
9096 (height + kEACAndETC2BlockSize - 1) / kEACAndETC2BlockSize; 9110 (height + kEACAndETC2BlockSize - 1) / kEACAndETC2BlockSize;
9097 bytes_required *= 16; 9111 bytes_required *= 16;
9098 bytes_required *= depth; 9112 bytes_required *= depth;
9099 break; 9113 break;
9100 default: 9114 default:
9101 LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, format, "format"); 9115 LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, format, "format");
9102 return false; 9116 return false;
9103 } 9117 }
9104 9118
9105 if (!bytes_required.IsValid() || size != bytes_required.ValueOrDefault(0)) { 9119 if (!bytes_required.IsValid()) {
9120 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "invalid size");
9121 return false;
9122 }
9123
9124 *size_in_bytes = bytes_required.ValueOrDie();
piman 2015/06/12 19:50:30 nit: ValueOrDefault(0). No need to generate code+s
christiank 2015/06/15 09:42:42 Done.
9125 return true;
9126 }
9127
9128 bool GLES2DecoderImpl::ValidateCompressedTexFuncData(
9129 const char* function_name, GLsizei width, GLsizei height, GLsizei depth,
9130 GLenum format, GLsizei size) {
9131 GLsizei bytes_required = 0;
9132 if (!GetCompressedTexSizeInBytes(
9133 function_name, width, height, depth, format, &bytes_required)) {
9134 return false;
9135 }
9136
9137 if (size != bytes_required) {
9106 LOCAL_SET_GL_ERROR( 9138 LOCAL_SET_GL_ERROR(
9107 GL_INVALID_VALUE, function_name, "size is not correct for dimensions"); 9139 GL_INVALID_VALUE, function_name, "size is not correct for dimensions");
9108 return false; 9140 return false;
9109 } 9141 }
9110 9142
9111 return true; 9143 return true;
9112 } 9144 }
9113 9145
9114 bool GLES2DecoderImpl::ValidateCompressedTexDimensions( 9146 bool GLES2DecoderImpl::ValidateCompressedTexDimensions(
9115 const char* function_name, GLenum target, GLint level, 9147 const char* function_name, GLenum target, GLint level,
(...skipping 2800 matching lines...) Expand 10 before | Expand all | Expand 10 after
11916 source_internal_format == GL_LUMINANCE_ALPHA || 11948 source_internal_format == GL_LUMINANCE_ALPHA ||
11917 source_internal_format == GL_BGRA_EXT; 11949 source_internal_format == GL_BGRA_EXT;
11918 if (!valid_source_format || !valid_dest_format) { 11950 if (!valid_source_format || !valid_dest_format) {
11919 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, 11951 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name,
11920 "invalid internal format"); 11952 "invalid internal format");
11921 return false; 11953 return false;
11922 } 11954 }
11923 return true; 11955 return true;
11924 } 11956 }
11925 11957
11958 bool GLES2DecoderImpl::ValidateCompressedCopyTextureCHROMIUM(
11959 const char* function_name,
11960 GLenum target,
11961 TextureRef* source_texture_ref,
11962 TextureRef* dest_texture_ref) {
11963 if (!source_texture_ref || !dest_texture_ref) {
11964 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown texture id");
11965 return false;
11966 }
11967
11968 if (GL_TEXTURE_2D != target) {
11969 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name,
11970 "invalid texture target");
11971 return false;
11972 }
11973
11974 Texture* source_texture = source_texture_ref->texture();
11975 Texture* dest_texture = dest_texture_ref->texture();
11976 if (source_texture == dest_texture) {
11977 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name,
11978 "source and destination textures are the same");
11979 return false;
11980 }
11981
11982 if (dest_texture->target() != GL_TEXTURE_2D ||
11983 (source_texture->target() != GL_TEXTURE_2D &&
11984 source_texture->target() != GL_TEXTURE_RECTANGLE_ARB &&
11985 source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) {
11986 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name,
11987 "invalid texture target binding");
11988 return false;
11989 }
11990
11991 GLenum source_type = 0;
11992 GLenum source_internal_format = 0;
11993 source_texture->GetLevelType(source_texture->target(), 0, &source_type,
11994 &source_internal_format);
11995
11996 bool valid_format =
11997 source_internal_format == GL_ATC_RGB_AMD ||
11998 source_internal_format == GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD ||
11999 source_internal_format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||
12000 source_internal_format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT ||
12001 source_internal_format == GL_ETC1_RGB8_OES;
12002
12003 if (!valid_format) {
12004 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name,
12005 "invalid internal format");
12006 return false;
12007 }
12008
12009 return true;
12010 }
12011
11926 void GLES2DecoderImpl::DoCopyTextureCHROMIUM(GLenum target, 12012 void GLES2DecoderImpl::DoCopyTextureCHROMIUM(GLenum target,
11927 GLuint source_id, 12013 GLuint source_id,
11928 GLuint dest_id, 12014 GLuint dest_id,
11929 GLenum internal_format, 12015 GLenum internal_format,
11930 GLenum dest_type) { 12016 GLenum dest_type) {
11931 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); 12017 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM");
11932 12018
11933 TextureRef* source_texture_ref = GetTexture(source_id); 12019 TextureRef* source_texture_ref = GetTexture(source_id);
11934 TextureRef* dest_texture_ref = GetTexture(dest_id); 12020 TextureRef* dest_texture_ref = GetTexture(dest_id);
11935 Texture* source_texture = source_texture_ref->texture(); 12021 Texture* source_texture = source_texture_ref->texture();
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
12221 copy_texture_CHROMIUM_->DoCopySubTexture( 12307 copy_texture_CHROMIUM_->DoCopySubTexture(
12222 this, source_texture->target(), source_texture->service_id(), 12308 this, source_texture->target(), source_texture->service_id(),
12223 source_internal_format, dest_texture->service_id(), dest_internal_format, 12309 source_internal_format, dest_texture->service_id(), dest_internal_format,
12224 xoffset, yoffset, x, y, width, height, dest_width, dest_height, 12310 xoffset, yoffset, x, y, width, height, dest_width, dest_height,
12225 source_width, source_height, unpack_flip_y_, unpack_premultiply_alpha_, 12311 source_width, source_height, unpack_flip_y_, unpack_premultiply_alpha_,
12226 unpack_unpremultiply_alpha_); 12312 unpack_unpremultiply_alpha_);
12227 12313
12228 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); 12314 DoDidUseTexImageIfNeeded(source_texture, source_texture->target());
12229 } 12315 }
12230 12316
12317 void GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM(GLenum target,
12318 GLuint source_id,
12319 GLuint dest_id) {
12320 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM");
12321
12322 TextureRef* source_texture_ref = GetTexture(source_id);
12323 TextureRef* dest_texture_ref = GetTexture(dest_id);
12324 Texture* source_texture = source_texture_ref->texture();
12325 Texture* dest_texture = dest_texture_ref->texture();
12326 int source_width = 0;
12327 int source_height = 0;
12328 gfx::GLImage* image =
12329 source_texture->GetLevelImage(source_texture->target(), 0);
12330 if (image) {
12331 gfx::Size size = image->GetSize();
12332 source_width = size.width();
12333 source_height = size.height();
12334 if (source_width <= 0 || source_height <= 0) {
12335 LOCAL_SET_GL_ERROR(
12336 GL_INVALID_VALUE,
12337 "glCompressedCopyTextureCHROMIUM", "invalid image size");
12338 return;
12339 }
12340 } else {
12341 if (!source_texture->GetLevelSize(source_texture->target(), 0,
12342 &source_width, &source_height, nullptr)) {
12343 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE,
12344 "glCompressedCopyTextureCHROMIUM",
12345 "source texture has no level 0");
12346 return;
12347 }
12348
12349 // Check that this type of texture is allowed.
12350 if (!texture_manager()->ValidForTarget(source_texture->target(), 0,
12351 source_width, source_height, 1)) {
12352 LOCAL_SET_GL_ERROR(
12353 GL_INVALID_VALUE, "glCompressedCopyTextureCHROMIUM",
12354 "Bad dimensions");
12355 return;
12356 }
12357 }
12358
12359 GLenum source_type = 0;
12360 GLenum source_internal_format = 0;
12361 source_texture->GetLevelType(
12362 source_texture->target(), 0, &source_type, &source_internal_format);
12363
12364 if (dest_texture->IsImmutable()) {
12365 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION,
12366 "glCompressedCopyTextureCHROMIUM",
12367 "texture is immutable");
12368 return;
12369 }
12370
12371 if (!ValidateCompressedCopyTextureCHROMIUM(
12372 "glCompressedCopyTextureCHROMIUM",
12373 target,
12374 source_texture_ref, dest_texture_ref)) {
12375 return;
12376 }
12377
12378 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is
12379 // needed because it takes 10s of milliseconds to initialize.
12380 if (!copy_texture_CHROMIUM_.get()) {
12381 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM");
12382 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager());
12383 copy_texture_CHROMIUM_->Initialize(this);
12384 RestoreCurrentFramebufferBindings();
12385 if (LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM") != GL_NO_ERROR)
12386 return;
12387 }
12388
12389 // Clear the source texture if necessary.
12390 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref,
12391 source_texture->target(), 0)) {
12392 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCompressedCopyTextureCHROMIUM",
12393 "dimensions too big");
12394 return;
12395 }
12396
12397 GLenum dest_type = 0;
12398 GLenum dest_internal_format = 0;
12399 int dest_width = 0;
12400 int dest_height = 0;
12401 bool dest_level_defined = dest_texture->GetLevelSize(
12402 GL_TEXTURE_2D, 0, &dest_width, &dest_height, nullptr);
12403
12404 if (dest_level_defined) {
12405 dest_texture->GetLevelType(GL_TEXTURE_2D, 0, &dest_type,
12406 &dest_internal_format);
12407 }
12408
12409 // Resize the destination texture to the dimensions of the source texture.
12410 if (!dest_level_defined || dest_width != source_width ||
12411 dest_height != source_height ||
12412 dest_internal_format != source_internal_format) {
piman 2015/06/12 19:50:30 Can we make sure we only go through here is we hav
christiank 2015/06/15 09:42:42 reveman actually suggested me to keep it like this
reveman 2015/06/15 14:44:56 Either way is fine with me. This just seemed a bit
christiank 2015/06/16 06:57:48 I have moved it into the if (image) clause for now
12413 GLsizei source_size = 0;
12414 if (!GetCompressedTexSizeInBytes(
12415 "glCompressedCopyTextureCHROMIUM", source_width, source_height,
12416 1, source_internal_format, &source_size)) {
12417 return;
piman 2015/06/12 19:50:30 This can't happen, can it? The only reason it coul
christiank 2015/06/15 09:42:42 What if a malicious renderer creates an image of o
piman 2015/06/15 18:35:03 source_* come from the source image/texture, they'
christiank 2015/06/16 06:57:49 No, you're right. For some reason I was in the min
12418 }
12419
12420 // Ensure that the glCompressedTexImage2D succeeds.
12421 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedCopyTextureCHROMIUM");
12422 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id());
12423 glCompressedTexImage2D(GL_TEXTURE_2D, 0, source_internal_format,
12424 source_width, source_height, 0, source_size,
12425 NULL);
12426 GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedCopyTextureCHROMIUM");
12427 if (error != GL_NO_ERROR) {
12428 RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D);
12429 return;
12430 }
12431
12432 texture_manager()->SetLevelInfo(
12433 dest_texture_ref, GL_TEXTURE_2D, 0, source_internal_format,
12434 source_width, source_height, 1, 0, source_internal_format,
12435 source_type, gfx::Rect(source_width, source_height));
12436 } else {
12437 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0,
12438 true);
12439 }
12440
12441 ScopedModifyPixels modify(dest_texture_ref);
12442
12443 bool unpack_premultiply_alpha_change =
12444 unpack_premultiply_alpha_ ^ unpack_unpremultiply_alpha_;
12445 if (unpack_flip_y_ || unpack_premultiply_alpha_change) {
12446 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCompressedCopyTextureCHROMIUM",
12447 "pixel-storage multipliers are not supported");
12448 }
piman 2015/06/12 19:50:30 This should be before we do GL calls (e.g. right a
christiank 2015/06/15 09:42:42 Done.
12449
12450 // Try using GLImage::CopyTexImage when possible.
12451 if (image) {
12452 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id());
12453 if (image->CopyTexSubImage(GL_TEXTURE_2D, gfx::Point(0, 0),
12454 gfx::Rect(0, 0, source_width, source_height))) {
piman 2015/06/12 19:50:30 Need to RestoreCurrentTextureBindings here.
christiank 2015/06/15 09:42:42 Done.
12455 return;
12456 }
12457 }
12458
12459 TRACE_EVENT0(
12460 "gpu",
12461 "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM, fallback");
12462
12463 DoWillUseTexImageIfNeeded(source_texture, source_texture->target());
12464
12465 // As a fallback, copy into a non-compressed GL_RGBA texture.
12466 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedCopyTextureCHROMIUM");
12467 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id());
piman 2015/06/12 19:50:30 We bind the dest_texture up to 3 times. Can we ins
christiank 2015/06/15 09:42:42 Done.
12468 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, source_width, source_height,
12469 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
12470 GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedCopyTextureCHROMIUM");
12471 if (error != GL_NO_ERROR) {
12472 RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D);
12473 return;
12474 }
12475
12476 texture_manager()->SetLevelInfo(
12477 dest_texture_ref, GL_TEXTURE_2D, 0, GL_RGBA, source_width,
12478 source_height, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
12479 gfx::Rect(source_width, source_height));
12480
12481 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix
12482 // before presenting.
12483 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) {
12484 // TODO(hkuang): get the StreamTexture transform matrix in GPU process
12485 // instead of using kIdentityMatrix crbug.com/226218.
12486 copy_texture_CHROMIUM_->DoCopyTextureWithTransform(
12487 this, source_texture->target(), source_texture->service_id(),
12488 dest_texture->service_id(), source_width, source_height,
12489 unpack_flip_y_, unpack_premultiply_alpha_,
12490 unpack_unpremultiply_alpha_, kIdentityMatrix);
12491 } else {
12492 copy_texture_CHROMIUM_->DoCopyTexture(
12493 this, source_texture->target(), source_texture->service_id(),
12494 source_internal_format, dest_texture->service_id(), GL_RGBA,
12495 source_width, source_height, unpack_flip_y_,
12496 unpack_premultiply_alpha_, unpack_unpremultiply_alpha_);
12497 }
12498
12499 DoDidUseTexImageIfNeeded(source_texture, source_texture->target());
piman 2015/06/12 19:50:30 RestoreCurrentTextureBindings here. Maybe this ca
christiank 2015/06/15 09:42:42 Done.
12500 }
12501
12231 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { 12502 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) {
12232 switch (internalformat) { 12503 switch (internalformat) {
12233 case GL_RGB565: 12504 case GL_RGB565:
12234 return GL_UNSIGNED_SHORT_5_6_5; 12505 return GL_UNSIGNED_SHORT_5_6_5;
12235 case GL_RGBA4: 12506 case GL_RGBA4:
12236 return GL_UNSIGNED_SHORT_4_4_4_4; 12507 return GL_UNSIGNED_SHORT_4_4_4_4;
12237 case GL_RGB5_A1: 12508 case GL_RGB5_A1:
12238 return GL_UNSIGNED_SHORT_5_5_5_1; 12509 return GL_UNSIGNED_SHORT_5_5_5_1;
12239 case GL_RGB8_OES: 12510 case GL_RGB8_OES:
12240 return GL_UNSIGNED_BYTE; 12511 return GL_UNSIGNED_BYTE;
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after
13426 } 13697 }
13427 } 13698 }
13428 13699
13429 // Include the auto-generated part of this file. We split this because it means 13700 // Include the auto-generated part of this file. We split this because it means
13430 // we can easily edit the non-auto generated parts right here in this file 13701 // we can easily edit the non-auto generated parts right here in this file
13431 // instead of having to edit some template or the code generator. 13702 // instead of having to edit some template or the code generator.
13432 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 13703 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
13433 13704
13434 } // namespace gles2 13705 } // namespace gles2
13435 } // namespace gpu 13706 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698