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

Unified 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: Fix comments in tests Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: gpu/command_buffer/service/gles2_cmd_decoder.cc
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc
index 29d4d5d14e6925ecb99c98dca01097106bcc69b1..8bd16b31ef54fa08bffdd8e9c1ca81575b0f1127 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -969,6 +969,13 @@ class GLES2DecoderImpl : public GLES2Decoder,
GLint xoffset,
GLint yoffset);
+ void DoCopyCompressedTextureCHROMIUM(GLenum target,
+ GLuint source_id,
+ GLuint dest_id,
+ GLenum internal_format,
+ GLenum dest_type,
+ GLsizei source_size);
+
// Wrapper for TexStorage2DEXT.
void DoTexStorage2DEXT(
GLenum target,
@@ -1697,6 +1704,11 @@ class GLES2DecoderImpl : public GLES2Decoder,
TextureRef* source_texture_ref,
TextureRef* dest_texture_ref,
GLenum dest_internal_format);
+ bool ValidateCopyCompressedTextureCHROMIUM(const char* function_name,
+ GLenum target,
+ TextureRef* source_texture_ref,
+ TextureRef* dest_texture_ref,
+ GLenum dest_internal_format);
void RenderWarning(const char* filename, int line, const std::string& msg);
void PerformanceWarning(
@@ -11523,6 +11535,67 @@ bool GLES2DecoderImpl::ValidateCopyTextureCHROMIUM(
return true;
}
+bool GLES2DecoderImpl::ValidateCopyCompressedTextureCHROMIUM(
+ const char* function_name,
+ GLenum target,
+ TextureRef* source_texture_ref,
+ TextureRef* dest_texture_ref,
+ GLenum dest_internal_format) {
+ if (!source_texture_ref || !dest_texture_ref) {
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown texture id");
+ return false;
+ }
+
+ if (GL_TEXTURE_2D != target) {
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name,
+ "invalid texture target");
+ return false;
+ }
+
+ Texture* source_texture = source_texture_ref->texture();
+ Texture* dest_texture = dest_texture_ref->texture();
+ if (source_texture == dest_texture) {
+ LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name,
+ "source and destination textures are the same");
+ return false;
+ }
+
+ if (dest_texture->target() != GL_TEXTURE_2D ||
+ (source_texture->target() != GL_TEXTURE_2D &&
+ source_texture->target() != GL_TEXTURE_RECTANGLE_ARB &&
+ source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) {
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name,
+ "invalid texture target binding");
+ return false;
+ }
+
+ GLenum source_type = 0;
+ GLenum source_internal_format = 0;
+ source_texture->GetLevelType(source_texture->target(), 0, &source_type,
+ &source_internal_format);
+
+ if (dest_internal_format != source_internal_format) {
+ LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name,
+ "source and destination formats doesn't match");
+ return false;
+ }
+
+ bool valid_format =
+ dest_internal_format == GL_ATC_RGB_AMD ||
+ dest_internal_format == GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD ||
+ dest_internal_format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||
+ dest_internal_format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT ||
+ dest_internal_format == GL_ETC1_RGB8_OES;
+
+ if (!valid_format) {
+ LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name,
+ "invalid internal format");
+ return false;
+ }
+
+ return true;
+}
+
void GLES2DecoderImpl::DoCopyTextureCHROMIUM(GLenum target,
GLuint source_id,
GLuint dest_id,
@@ -11813,6 +11886,160 @@ void GLES2DecoderImpl::DoCopySubTextureCHROMIUM(GLenum target,
DoDidUseTexImageIfNeeded(source_texture, source_texture->target());
}
+void GLES2DecoderImpl::DoCopyCompressedTextureCHROMIUM(GLenum target,
+ GLuint source_id,
+ GLuint dest_id,
+ GLenum internal_format,
+ GLenum dest_type,
+ GLsizei source_size) {
+ TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyCompressedTextureCHROMIUM");
+
+ TextureRef* source_texture_ref = GetTexture(source_id);
+ TextureRef* dest_texture_ref = GetTexture(dest_id);
+ Texture* source_texture = source_texture_ref->texture();
+ Texture* dest_texture = dest_texture_ref->texture();
+ int source_width = 0;
+ int source_height = 0;
+ gfx::GLImage* image =
+ source_texture->GetLevelImage(source_texture->target(), 0);
+ if (image) {
+ gfx::Size size = image->GetSize();
+ source_width = size.width();
+ source_height = size.height();
+ if (source_width <= 0 || source_height <= 0) {
+ LOCAL_SET_GL_ERROR(
+ GL_INVALID_VALUE,
+ "glCopyCompressedTextureChromium", "invalid image size");
+ return;
+ }
+ } else {
+ if (!source_texture->GetLevelSize(
+ source_texture->target(), 0, &source_width, &source_height)) {
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE,
+ "glCopyCompressedTextureChromium",
+ "source texture has no level 0");
+ return;
+ }
+
+ // Check that this type of texture is allowed.
+ if (!texture_manager()->ValidForTarget(source_texture->target(), 0,
+ source_width, source_height, 1)) {
+ LOCAL_SET_GL_ERROR(
+ GL_INVALID_VALUE, "glCopyCompressedTextureCHROMIUM",
+ "Bad dimensions");
+ return;
+ }
+ }
+
+ GLenum source_type = 0;
+ GLenum source_internal_format = 0;
+ source_texture->GetLevelType(
+ source_texture->target(), 0, &source_type, &source_internal_format);
+
+ if (dest_texture->IsImmutable()) {
+ LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION,
+ "glCopyCompressedTextureCHROMIUM",
+ "texture is immutable");
+ return;
+ }
+
+ if (!ValidateCopyCompressedTextureCHROMIUM(
+ "glCopyCompressedTextureCHROMIUM",
+ target,
+ source_texture_ref, dest_texture_ref,
+ internal_format)) {
+ return;
+ }
+
+ // Clear the source texture if necessary.
+ if (!texture_manager()->ClearTextureLevel(this, source_texture_ref,
+ source_texture->target(), 0)) {
+ LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopyCompressedTextureCHROMIUM",
+ "dimensions too big");
+ return;
+ }
+
+ GLenum dest_type_previous = dest_type;
+ GLenum dest_internal_format = internal_format;
+ int dest_width = 0;
+ int dest_height = 0;
+ bool dest_level_defined =
+ dest_texture->GetLevelSize(GL_TEXTURE_2D, 0, &dest_width, &dest_height);
+
+ if (dest_level_defined) {
+ dest_texture->GetLevelType(GL_TEXTURE_2D, 0, &dest_type_previous,
+ &dest_internal_format);
+ }
+
+ // Resize the destination texture to the dimensions of the source texture.
+ if (!dest_level_defined || dest_width != source_width ||
+ dest_height != source_height ||
+ dest_internal_format != internal_format ||
+ dest_type_previous != dest_type) {
+ // Ensure that the glCompressedTexImage2D succeeds.
+ LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyCompressedTextureCHROMIUM");
+ glBindTexture(GL_TEXTURE_2D, dest_texture->service_id());
+ glCompressedTexImage2D(GL_TEXTURE_2D, 0, internal_format, source_width,
+ source_height, 0, source_size, NULL);
+ GLenum error = LOCAL_PEEK_GL_ERROR("glCopyCompressedTextureCHROMIUM");
+ if (error != GL_NO_ERROR) {
+ RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D);
+ return;
+ }
+
+ texture_manager()->SetLevelInfo(
+ dest_texture_ref, GL_TEXTURE_2D, 0, internal_format, source_width,
+ source_height, 1, 0, internal_format, dest_type, true);
+ } else {
+ texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0,
+ true);
piman 2015/05/28 20:34:27 We should only do that after we successfully fille
christiank 2015/06/05 12:53:31 Can I keep this code as is, now that I have update
+ }
+
+ ScopedModifyPixels modify(dest_texture_ref);
+
+ DCHECK(!unpack_flip_y_);
+ DCHECK(!(unpack_premultiply_alpha_ ^ unpack_unpremultiply_alpha_));
piman 2015/05/28 20:34:27 These can't be DCHECKed, we can't trust the client
christiank 2015/06/05 12:53:31 Fixed.
+
+ // Try using GLImage::CopyTexImage when possible.
+ if (image) {
+ glBindTexture(GL_TEXTURE_2D, dest_texture->service_id());
+ if (image->CopyTexImage(GL_TEXTURE_2D))
+ return;
+ }
+
+ // As a fallback, read back the texture data and upload it again.
+ if (!feature_info_->gl_version_info().is_es) {
reveman 2015/05/28 14:06:48 can you early out at the top of this function if t
christiank 2015/05/28 14:40:29 We still want to use GLImage::CopyTexImage on Open
reveman 2015/05/28 16:33:08 Ok, that's a problem. If a texture is backed by an
christiank 2015/06/01 12:14:16 It's rather important as Android is my primary dri
+ DoWillUseTexImageIfNeeded(source_texture, source_texture->target());
+
+ scoped_ptr<GLbyte[]> image_data(new GLbyte[source_size]);
piman 2015/05/28 20:34:27 We can't trust source_size from the client. Instea
christiank 2015/06/05 12:53:31 I see. What's the best way of storing the byte siz
+ glBindTexture(GL_TEXTURE_2D, source_texture->service_id());
+ glGetCompressedTexImage(GL_TEXTURE_2D, 0, image_data.get());
reveman 2015/05/28 14:06:49 can you add a TRACE_EVENT around this somehow? I u
christiank 2015/06/05 12:53:31 I added an event to trace both the inefficient glG
+
+ glBindTexture(GL_TEXTURE_2D, dest_texture->service_id());
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
piman 2015/05/28 20:34:27 Why do we do these? I don't think they belong.
christiank 2015/06/05 12:53:31 We don't, you're right. Wrong thinking on my part.
+
+ glCompressedTexImage2D(GL_TEXTURE_2D, 0, internal_format, source_width,
+ source_height, 0, source_size, image_data.get());
+ GLenum error = LOCAL_PEEK_GL_ERROR("glCopyCompressedTextureCHROMIUM");
+ if (error != GL_NO_ERROR) {
+ RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D);
+ return;
+ }
+
+ texture_manager()->SetLevelInfo(
+ dest_texture_ref, GL_TEXTURE_2D, 0, internal_format, source_width,
+ source_height, 1, 0, internal_format, dest_type, true);
+
+ DoDidUseTexImageIfNeeded(source_texture, source_texture->target());
+ } else {
+ LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCopyCompressedTextureCHROMIUM",
+ "platform doesn't support copying compressed textures");
+ }
+}
+
static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) {
switch (internalformat) {
case GL_RGB565:

Powered by Google App Engine
This is Rietveld 408576698