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

Unified Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 2623863002: Support level > 0 for CopyTextureCHROMIUM extension (Closed)
Patch Set: Created 3 years, 11 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 954d5fd8737705a8f8e195eadf77040a167a614e..86f6f5e15ffcfd4b04ae90ca6ee4c8cee71a275e 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -2024,6 +2024,7 @@ class GLES2DecoderImpl : public GLES2Decoder, public ErrorStateClient {
CopyTextureMethod ValidateCopyTextureCHROMIUMInternalFormats(
const char* function_name,
TextureRef* source_texture_ref,
+ GLint source_level,
GLenum dest_internal_format);
bool ValidateCompressedCopyTextureCHROMIUM(const char* function_name,
TextureRef* source_texture_ref,
@@ -16193,12 +16194,13 @@ bool GLES2DecoderImpl::ValidateCopyTextureCHROMIUMTextures(
CopyTextureMethod GLES2DecoderImpl::ValidateCopyTextureCHROMIUMInternalFormats(
const char* function_name,
TextureRef* source_texture_ref,
+ GLint source_level,
GLenum dest_internal_format) {
GLenum source_type = 0;
GLenum source_internal_format = 0;
Texture* source_texture = source_texture_ref->texture();
- source_texture->GetLevelType(source_texture->target(), 0, &source_type,
- &source_internal_format);
+ source_texture->GetLevelType(source_texture->target(), source_level,
+ &source_type, &source_internal_format);
bool valid_dest_format = false;
// TODO(qiankun.miao@intel.com): ALPHA, LUMINANCE and LUMINANCE_ALPHA formats
@@ -16362,11 +16364,6 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM");
static const char kFunctionName[] = "glCopyTextureCHROMIUM";
- // TODO(qiankun.miao@intel.com): Remove this after level > 0 support is
- // implemented. See: https://crbug.com/612542.
- DCHECK(source_level == 0);
- DCHECK(dest_level == 0);
-
TextureRef* source_texture_ref = GetTexture(source_id);
TextureRef* dest_texture_ref = GetTexture(dest_id);
@@ -16375,6 +16372,13 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
return;
}
+ if (source_level < 0 || dest_level < 0 ||
+ (feature_info_->IsWebGL1OrES2Context() && source_level > 0)) {
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName,
+ "source_level or dest_level out of range");
+ return;
+ }
+
Texture* source_texture = source_texture_ref->texture();
Texture* dest_texture = dest_texture_ref->texture();
GLenum source_target = source_texture->target();
@@ -16382,24 +16386,39 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
GLenum source_type = 0;
GLenum source_internal_format = 0;
- source_texture->GetLevelType(source_target, 0, &source_type,
+ source_texture->GetLevelType(source_target, source_level, &source_type,
&source_internal_format);
GLenum format =
TextureManager::ExtractFormatFromStorageFormat(internal_format);
if (!texture_manager()->ValidateTextureParameters(
GetErrorState(), kFunctionName, true, format, dest_type,
- internal_format, 0)) {
+ internal_format, dest_level)) {
return;
}
CopyTextureMethod method = ValidateCopyTextureCHROMIUMInternalFormats(
- kFunctionName, source_texture_ref, internal_format);
+ kFunctionName, source_texture_ref, source_level, internal_format);
// INVALID_OPERATION is already generated by
// ValidateCopyTextureCHROMIUMInternalFormats.
- if (NOT_COPYABLE == method) {
+ if (method == NOT_COPYABLE) {
return;
}
+ // Draw to a fbo attaching level 0 of an intermediate texture,
+ // then copy from the fbo to dest texture level with glCopyTexImage2D.
+ // For WebGL 1.0 or OpenGL ES 2.0, DIRECT_DRAW path isn't available for
+ // dest_level > 0 due to level > 0 isn't supported by glFramebufferTexture2D
+ // in ES2 context. Go to DRAW_AND_COPY path in this case.
+ // TODO(qiankun.miao@intel.com): for WebGL 2.0 or OpenGL ES 3.0, both
+ // DIRECT_DRAW path for dest_level > 0 and DIRECT_COPY path for source_level >
+ // 0 are not available due to a framebuffer completeness bug:
+ // crbug.com/678526. Once the bug is fixed, the limitation for WebGL 2.0 and
+ // OpenGL ES 3.0 can be lifted.
+ if ((dest_level > 0 && method == DIRECT_DRAW) ||
+ (source_level > 0 && method == DIRECT_COPY)) {
+ method = DRAW_AND_COPY;
+ }
+
if (feature_info_->feature_flags().desktop_srgb_support) {
bool enable_framebuffer_srgb =
GetColorEncodingFromInternalFormat(source_internal_format) == GL_SRGB ||
@@ -16410,28 +16429,25 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
int source_width = 0;
int source_height = 0;
gl::GLImage* image =
- source_texture->GetLevelImage(source_target, 0);
+ source_texture->GetLevelImage(source_target, source_level);
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,
- "glCopyTextureChromium", "invalid image size");
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName, "invalid image size");
return;
}
} else {
- if (!source_texture->GetLevelSize(source_target, 0,
+ if (!source_texture->GetLevelSize(source_target, source_level,
&source_width, &source_height, nullptr)) {
- LOCAL_SET_GL_ERROR(GL_INVALID_VALUE,
- "glCopyTextureChromium",
- "source texture has no level 0");
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName,
+ "source texture has no data for level");
return;
}
// Check that this type of texture is allowed.
- if (!texture_manager()->ValidForTarget(source_target, 0,
+ if (!texture_manager()->ValidForTarget(source_target, source_level,
source_width, source_height, 1)) {
LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName, "Bad dimensions");
return;
@@ -16446,7 +16462,7 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
// Clear the source texture if necessary.
if (!texture_manager()->ClearTextureLevel(this, source_texture_ref,
- source_target, 0)) {
+ source_target, source_level)) {
LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, kFunctionName, "dimensions too big");
return;
}
@@ -16459,10 +16475,10 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
int dest_width = 0;
int dest_height = 0;
bool dest_level_defined = dest_texture->GetLevelSize(
- dest_target, 0, &dest_width, &dest_height, nullptr);
+ dest_target, dest_level, &dest_width, &dest_height, nullptr);
if (dest_level_defined) {
- dest_texture->GetLevelType(dest_target, 0, &dest_type_previous,
+ dest_texture->GetLevelType(dest_target, dest_level, &dest_type_previous,
&dest_internal_format);
}
@@ -16474,30 +16490,34 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
// Ensure that the glTexImage2D succeeds.
LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName);
glBindTexture(dest_target, dest_texture->service_id());
- glTexImage2D(dest_target, 0, TextureManager::AdjustTexInternalFormat(
- feature_info_.get(), internal_format),
+ glTexImage2D(dest_target, dest_level,
+ TextureManager::AdjustTexInternalFormat(feature_info_.get(),
+ internal_format),
source_width, source_height, 0,
TextureManager::AdjustTexFormat(feature_info_.get(), format),
- dest_type, NULL);
+ dest_type, nullptr);
GLenum error = LOCAL_PEEK_GL_ERROR(kFunctionName);
if (error != GL_NO_ERROR) {
RestoreCurrentTextureBindings(&state_, dest_target);
return;
}
- texture_manager()->SetLevelInfo(dest_texture_ref, dest_target, 0,
+ texture_manager()->SetLevelInfo(dest_texture_ref, dest_target, dest_level,
internal_format, source_width,
source_height, 1, 0, format, dest_type,
gfx::Rect(source_width, source_height));
dest_texture->ApplyFormatWorkarounds(feature_info_.get());
} else {
- texture_manager()->SetLevelCleared(dest_texture_ref, dest_target, 0, true);
+ texture_manager()->SetLevelCleared(dest_texture_ref, dest_target,
+ dest_level, true);
}
// Try using GLImage::CopyTexImage when possible.
bool unpack_premultiply_alpha_change =
(unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0;
- if (image && !unpack_flip_y && !unpack_premultiply_alpha_change) {
+ // TODO(qiankun.miao@intel.com): Support level > 0 for CopyTexImage.
+ if (image && dest_level == 0 && !unpack_flip_y &&
+ !unpack_premultiply_alpha_change) {
glBindTexture(dest_target, dest_texture->service_id());
if (image->CopyTexImage(dest_target))
return;
@@ -16510,13 +16530,13 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
if (source_target == GL_TEXTURE_EXTERNAL_OES) {
if (GLStreamTextureImage* image =
source_texture->GetLevelStreamTextureImage(GL_TEXTURE_EXTERNAL_OES,
- 0)) {
+ source_level)) {
GLfloat transform_matrix[16];
image->GetTextureMatrix(transform_matrix);
copy_texture_CHROMIUM_->DoCopyTextureWithTransform(
- this, source_target, source_texture->service_id(),
+ this, source_target, source_texture->service_id(), source_level,
source_internal_format, dest_target, dest_texture->service_id(),
- internal_format, source_width, source_height,
+ dest_level, internal_format, source_width, source_height,
unpack_flip_y == GL_TRUE, unpack_premultiply_alpha == GL_TRUE,
unpack_unmultiply_alpha == GL_TRUE, transform_matrix);
return;
@@ -16524,11 +16544,11 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
}
copy_texture_CHROMIUM_->DoCopyTexture(
- this, source_target, source_texture->service_id(), source_internal_format,
- dest_target, dest_texture->service_id(), internal_format, source_width,
- source_height, unpack_flip_y == GL_TRUE,
- unpack_premultiply_alpha == GL_TRUE, unpack_unmultiply_alpha == GL_TRUE,
- method);
+ this, source_target, source_texture->service_id(), source_level,
+ source_internal_format, dest_target, dest_texture->service_id(),
+ dest_level, internal_format, source_width, source_height,
+ unpack_flip_y == GL_TRUE, unpack_premultiply_alpha == GL_TRUE,
+ unpack_unmultiply_alpha == GL_TRUE, method);
}
void GLES2DecoderImpl::DoCopySubTextureCHROMIUM(
@@ -16547,11 +16567,6 @@ void GLES2DecoderImpl::DoCopySubTextureCHROMIUM(
GLboolean unpack_unmultiply_alpha) {
TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopySubTextureCHROMIUM");
- // TODO(qiankun.miao@intel.com): Remove this after level > 0 support is
- // implemented. See: https://crbug.com/612542.
- DCHECK(source_level == 0);
- DCHECK(dest_level == 0);
-
static const char kFunctionName[] = "glCopySubTextureCHROMIUM";
TextureRef* source_texture_ref = GetTexture(source_id);
TextureRef* dest_texture_ref = GetTexture(dest_id);
@@ -16561,6 +16576,13 @@ void GLES2DecoderImpl::DoCopySubTextureCHROMIUM(
return;
}
+ if (source_level < 0 || dest_level < 0 ||
+ (feature_info_->IsWebGL1OrES2Context() && source_level > 0)) {
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName,
+ "source_level or dest_level out of range");
+ return;
+ }
+
Texture* source_texture = source_texture_ref->texture();
Texture* dest_texture = dest_texture_ref->texture();
GLenum source_target = source_texture->target();
@@ -16568,7 +16590,7 @@ void GLES2DecoderImpl::DoCopySubTextureCHROMIUM(
int source_width = 0;
int source_height = 0;
gl::GLImage* image =
- source_texture->GetLevelImage(source_target, 0);
+ source_texture->GetLevelImage(source_target, source_level);
if (image) {
gfx::Size size = image->GetSize();
source_width = size.width();
@@ -16593,23 +16615,23 @@ void GLES2DecoderImpl::DoCopySubTextureCHROMIUM(
return;
}
} else {
- if (!source_texture->GetLevelSize(source_target, 0,
+ if (!source_texture->GetLevelSize(source_target, source_level,
&source_width, &source_height, nullptr)) {
LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName,
- "source texture has no level 0");
+ "source texture has no data for level");
return;
}
// Check that this type of texture is allowed.
- if (!texture_manager()->ValidForTarget(source_target, 0,
+ if (!texture_manager()->ValidForTarget(source_target, source_level,
source_width, source_height, 1)) {
LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName,
"source texture bad dimensions");
return;
}
- if (!source_texture->ValidForTexture(source_target, 0, x, y, 0, width,
- height, 1)) {
+ if (!source_texture->ValidForTexture(source_target, source_level, x, y, 0,
+ width, height, 1)) {
LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName,
"source texture bad dimensions.");
return;
@@ -16618,33 +16640,48 @@ void GLES2DecoderImpl::DoCopySubTextureCHROMIUM(
GLenum source_type = 0;
GLenum source_internal_format = 0;
- source_texture->GetLevelType(source_target, 0, &source_type,
+ source_texture->GetLevelType(source_target, source_level, &source_type,
&source_internal_format);
GLenum dest_type = 0;
GLenum dest_internal_format = 0;
bool dest_level_defined = dest_texture->GetLevelType(
- dest_target, 0, &dest_type, &dest_internal_format);
+ dest_target, dest_level, &dest_type, &dest_internal_format);
if (!dest_level_defined) {
LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, kFunctionName,
"destination texture is not defined");
return;
}
- if (!dest_texture->ValidForTexture(dest_target, 0, xoffset,
- yoffset, 0, width, height, 1)) {
+ if (!dest_texture->ValidForTexture(dest_target, dest_level, xoffset, yoffset,
+ 0, width, height, 1)) {
LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName,
"destination texture bad dimensions.");
return;
}
CopyTextureMethod method = ValidateCopyTextureCHROMIUMInternalFormats(
- kFunctionName, source_texture_ref, dest_internal_format);
+ kFunctionName, source_texture_ref, source_level, dest_internal_format);
// INVALID_OPERATION is already generated by
// ValidateCopyTextureCHROMIUMInternalFormats.
- if (NOT_COPYABLE == method) {
+ if (method == NOT_COPYABLE) {
return;
}
+ // Draw to a fbo attaching level 0 of an intermediate texture,
+ // then copy from the fbo to dest texture level with glCopyTexImage2D.
+ // For WebGL 1.0 or OpenGL ES 2.0, DIRECT_DRAW path isn't available for
+ // dest_level > 0 due to level > 0 isn't supported by glFramebufferTexture2D
+ // in ES2 context. Go to DRAW_AND_COPY path in this case.
+ // TODO(qiankun.miao@intel.com): for WebGL 2.0 or OpenGL ES 3.0, both
+ // DIRECT_DRAW path for dest_level > 0 and DIRECT_COPY path for source_level >
+ // 0 are not available due to a framebuffer completeness bug:
+ // crbug.com/678526. Once the bug is fixed, the limitation for WebGL 2.0 and
+ // OpenGL ES 3.0 can be lifted.
+ if ((dest_level > 0 && method == DIRECT_DRAW) ||
+ (source_level > 0 && method == DIRECT_COPY)) {
+ method = DRAW_AND_COPY;
+ }
+
if (feature_info_->feature_flags().desktop_srgb_support) {
bool enable_framebuffer_srgb =
GetColorEncodingFromInternalFormat(source_internal_format) == GL_SRGB ||
@@ -16654,7 +16691,7 @@ void GLES2DecoderImpl::DoCopySubTextureCHROMIUM(
// Clear the source texture if necessary.
if (!texture_manager()->ClearTextureLevel(this, source_texture_ref,
- source_target, 0)) {
+ source_target, source_level)) {
LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, kFunctionName,
"source texture dimensions too big");
return;
@@ -16665,38 +16702,41 @@ void GLES2DecoderImpl::DoCopySubTextureCHROMIUM(
int dest_width = 0;
int dest_height = 0;
- bool ok = dest_texture->GetLevelSize(
- dest_target, 0, &dest_width, &dest_height, nullptr);
+ bool ok = dest_texture->GetLevelSize(dest_target, dest_level, &dest_width,
+ &dest_height, nullptr);
DCHECK(ok);
if (xoffset != 0 || yoffset != 0 || width != dest_width ||
height != dest_height) {
gfx::Rect cleared_rect;
if (TextureManager::CombineAdjacentRects(
- dest_texture->GetLevelClearedRect(dest_target, 0),
+ dest_texture->GetLevelClearedRect(dest_target, dest_level),
gfx::Rect(xoffset, yoffset, width, height), &cleared_rect)) {
- DCHECK_GE(
- cleared_rect.size().GetArea(),
- dest_texture->GetLevelClearedRect(dest_target, 0).size().GetArea());
- texture_manager()->SetLevelClearedRect(dest_texture_ref, dest_target, 0,
- cleared_rect);
+ DCHECK_GE(cleared_rect.size().GetArea(),
+ dest_texture->GetLevelClearedRect(dest_target, dest_level)
+ .size()
+ .GetArea());
+ texture_manager()->SetLevelClearedRect(dest_texture_ref, dest_target,
+ dest_level, cleared_rect);
} else {
// Otherwise clear part of texture level that is not already cleared.
if (!texture_manager()->ClearTextureLevel(this, dest_texture_ref,
- dest_target, 0)) {
+ dest_target, dest_level)) {
LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, kFunctionName,
"destination texture dimensions too big");
return;
}
}
} else {
- texture_manager()->SetLevelCleared(dest_texture_ref, dest_target, 0,
- true);
+ texture_manager()->SetLevelCleared(dest_texture_ref, dest_target,
+ dest_level, true);
}
// Try using GLImage::CopyTexSubImage when possible.
bool unpack_premultiply_alpha_change =
(unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0;
- if (image && !unpack_flip_y && !unpack_premultiply_alpha_change) {
+ // TODO(qiankun.miao@intel.com): Support level > 0 for CopyTexSubImage.
+ if (image && dest_level == 0 && !unpack_flip_y &&
+ !unpack_premultiply_alpha_change) {
ScopedTextureBinder binder(
&state_, dest_texture->service_id(), dest_target);
if (image->CopyTexSubImage(dest_target, gfx::Point(xoffset, yoffset),
@@ -16712,26 +16752,26 @@ void GLES2DecoderImpl::DoCopySubTextureCHROMIUM(
if (source_target == GL_TEXTURE_EXTERNAL_OES) {
if (GLStreamTextureImage* image =
source_texture->GetLevelStreamTextureImage(GL_TEXTURE_EXTERNAL_OES,
- 0)) {
+ source_level)) {
GLfloat transform_matrix[16];
image->GetTextureMatrix(transform_matrix);
copy_texture_CHROMIUM_->DoCopySubTextureWithTransform(
- this, source_target, source_texture->service_id(),
+ this, source_target, source_texture->service_id(), source_level,
source_internal_format, dest_target, dest_texture->service_id(),
- dest_internal_format, xoffset, yoffset, x, y, width, height,
- dest_width, dest_height, source_width, source_height,
+ dest_level, dest_internal_format, xoffset, yoffset, x, y, width,
+ height, dest_width, dest_height, source_width, source_height,
unpack_flip_y == GL_TRUE, unpack_premultiply_alpha == GL_TRUE,
unpack_unmultiply_alpha == GL_TRUE, transform_matrix);
return;
}
}
copy_texture_CHROMIUM_->DoCopySubTexture(
- this, source_target, source_texture->service_id(), source_internal_format,
- dest_target, dest_texture->service_id(), dest_internal_format, xoffset,
- yoffset, x, y, width, height, dest_width, dest_height, source_width,
- source_height, unpack_flip_y == GL_TRUE,
- unpack_premultiply_alpha == GL_TRUE, unpack_unmultiply_alpha == GL_TRUE,
- method);
+ this, source_target, source_texture->service_id(), source_level,
+ source_internal_format, dest_target, dest_texture->service_id(),
+ dest_level, dest_internal_format, xoffset, yoffset, x, y, width, height,
+ dest_width, dest_height, source_width, source_height,
+ unpack_flip_y == GL_TRUE, unpack_premultiply_alpha == GL_TRUE,
+ unpack_unmultiply_alpha == GL_TRUE, method);
}
bool GLES2DecoderImpl::InitializeCopyTexImageBlitter(
@@ -16903,10 +16943,10 @@ void GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM(GLuint source_id,
gfx::Rect(source_width, source_height));
copy_texture_CHROMIUM_->DoCopyTexture(
- this, source_texture->target(), source_texture->service_id(),
+ this, source_texture->target(), source_texture->service_id(), 0,
source_internal_format, dest_texture->target(),
- dest_texture->service_id(), GL_RGBA, source_width, source_height, false,
- false, false, DIRECT_DRAW);
+ dest_texture->service_id(), 0, GL_RGBA, source_width, source_height,
+ false, false, false, DIRECT_DRAW);
}
void GLES2DecoderImpl::TexStorageImpl(GLenum target,

Powered by Google App Engine
This is Rietveld 408576698