Skip to content

Commit

Permalink
Add a new parameter dest_type to the GL_CHROMIUM_copy_texture extension.
Browse files Browse the repository at this point in the history
It is used to define the destination texture if needed, which is possible
for texImage2D(..., canvas) and texImage2D(..., video) in WebGL.

BUG=

Review URL: https://chromiumcodereview.appspot.com/13613006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195269 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jun.a.jiang@intel.com committed Apr 19, 2013
1 parent db7ee15 commit a4a6bdd
Show file tree
Hide file tree
Showing 24 changed files with 127 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1602,8 +1602,21 @@ DELEGATE_TO_GL_3(getQueryivEXT, GetQueryivEXT, WGC3Denum, WGC3Denum, WGC3Dint*)
DELEGATE_TO_GL_3(getQueryObjectuivEXT, GetQueryObjectuivEXT,
WebGLId, WGC3Denum, WGC3Duint*)

DELEGATE_TO_GL_5(copyTextureCHROMIUM, CopyTextureCHROMIUM, WGC3Denum,
WebGLId, WebGLId, WGC3Dint, WGC3Denum);
DELEGATE_TO_GL_6(copyTextureCHROMIUM, CopyTextureCHROMIUM, WGC3Denum,
WebGLId, WebGLId, WGC3Dint, WGC3Denum, WGC3Denum);

// This copyTextureCHROMIUM(...) has five parameters and delegates the call to
// CopyTextureCHROMIUM(...) with the sixth parameter set to GL_UNSIGNED_BYTE
// to bridge the parameter differences.
// TODO(jun.a.jiang@intel.com): once all clients switch to call
// the newer copyTextureCHROMIUM(...) with six parameters, this
// function will be removed.
void WebGraphicsContext3DCommandBufferImpl::copyTextureCHROMIUM(
WGC3Denum target, WebGLId source_id, WebGLId dest_id, WGC3Dint level,
WGC3Denum internal_format) {
gl_->CopyTextureCHROMIUM(target, source_id, dest_id, level, internal_format,
GL_UNSIGNED_BYTE);
}

DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM,
WebGLId, WGC3Dint, const WGC3Dchar*)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,11 @@ class WebGraphicsContext3DCommandBufferImpl
WebGLId dest_id, WGC3Dint level,
WGC3Denum internal_format);

virtual void copyTextureCHROMIUM(WGC3Denum target, WebGLId source_id,
WebGLId dest_id, WGC3Dint level,
WGC3Denum internal_format,
WGC3Denum dest_type);

virtual void bindUniformLocationCHROMIUM(WebGLId program, WGC3Dint location,
const WGC3Dchar* uniform);

Expand Down
10 changes: 7 additions & 3 deletions gpu/GLES2/extensions/CHROMIUM/CHROMIUM_copy_texture.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ New Procedures and Functions

void glCopyTextureCHROMIUM (GLenum target, GLenum source_id,
GLenum dest_id, GLint level,
GLint internal_format)
GLint internal_format, GLenum dest_type)

Copies the contents of texture referred to by <source_id> to texture
<dest_id>.

Texture level 0 is copied from the source image to level <level> of the
destination texture.
destination texture. The level parameter must be 0 at present.

The internal format of the destination texture is converted to that
specified by <internal_format>
specified by <internal_format>.

The format type of the destination texture is converted to that specified
by <dest_type>.

<target> uses the same parameters as TexImage2D.

Expand Down Expand Up @@ -80,3 +83,4 @@ New State
Revision History

8/1/2011 Documented the extension
7/4/2013 Add a new parameter dest_type to glCopyTextureCHROMIUM()
4 changes: 2 additions & 2 deletions gpu/GLES2/gl2extchromium.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,11 @@ typedef void (GL_APIENTRYP PFNGLBINDUNIFORMLOCATIONCHROMIUMPROC) (
#ifdef GL_GLEXT_PROTOTYPES
GL_APICALL void GL_APIENTRY glCopyTextureCHROMIUM(
GLenum target, GLenum source_id, GLenum dest_id, GLint level,
GLint internalformat);
GLint internalformat, GLenum dest_type);
#endif
typedef void (GL_APIENTRYP PFNGLCOPYTEXTURECHROMIUMPROC) (
GLenum target, GLenum source_id, GLenum dest_id, GLint level,
GLint internalformat);
GLint internalformat, GLenum dest_type);
#endif /* GL_CHROMIUM_copy_texture */

/* GL_CHROMIUM_lose_context */
Expand Down
4 changes: 2 additions & 2 deletions gpu/command_buffer/client/gles2_c_lib_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,9 @@ void GLES2TexImageIOSurface2DCHROMIUM(
}
void GLES2CopyTextureCHROMIUM(
GLenum target, GLenum source_id, GLenum dest_id, GLint level,
GLint internalformat) {
GLint internalformat, GLenum dest_type) {
gles2::GetGLContext()->CopyTextureCHROMIUM(
target, source_id, dest_id, level, internalformat);
target, source_id, dest_id, level, internalformat, dest_type);
}
void GLES2DrawArraysInstancedANGLE(
GLenum mode, GLint first, GLsizei count, GLsizei primcount) {
Expand Down
4 changes: 2 additions & 2 deletions gpu/command_buffer/client/gles2_cmd_helper_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -1866,11 +1866,11 @@

void CopyTextureCHROMIUM(
GLenum target, GLenum source_id, GLenum dest_id, GLint level,
GLint internalformat) {
GLint internalformat, GLenum dest_type) {
gles2::cmds::CopyTextureCHROMIUM* c =
GetCmdSpace<gles2::cmds::CopyTextureCHROMIUM>();
if (c) {
c->Init(target, source_id, dest_id, level, internalformat);
c->Init(target, source_id, dest_id, level, internalformat, dest_type);
}
}

Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/client/gles2_implementation_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ virtual void TexImageIOSurface2DCHROMIUM(

virtual void CopyTextureCHROMIUM(
GLenum target, GLenum source_id, GLenum dest_id, GLint level,
GLint internalformat) OVERRIDE;
GLint internalformat, GLenum dest_type) OVERRIDE;

virtual void DrawArraysInstancedANGLE(
GLenum mode, GLint first, GLsizei count, GLsizei primcount) OVERRIDE;
Expand Down
6 changes: 3 additions & 3 deletions gpu/command_buffer/client/gles2_implementation_impl_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -1630,11 +1630,11 @@ void GLES2Implementation::TexImageIOSurface2DCHROMIUM(

void GLES2Implementation::CopyTextureCHROMIUM(
GLenum target, GLenum source_id, GLenum dest_id, GLint level,
GLint internalformat) {
GLint internalformat, GLenum dest_type) {
GPU_CLIENT_SINGLE_THREAD_CHECK();
GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glCopyTextureCHROMIUM(" << GLES2Util::GetStringEnum(target) << ", " << GLES2Util::GetStringEnum(source_id) << ", " << GLES2Util::GetStringEnum(dest_id) << ", " << level << ", " << internalformat << ")"); // NOLINT
GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glCopyTextureCHROMIUM(" << GLES2Util::GetStringEnum(target) << ", " << GLES2Util::GetStringEnum(source_id) << ", " << GLES2Util::GetStringEnum(dest_id) << ", " << level << ", " << internalformat << ", " << GLES2Util::GetStringPixelType(dest_type) << ")"); // NOLINT
helper_->CopyTextureCHROMIUM(
target, source_id, dest_id, level, internalformat);
target, source_id, dest_id, level, internalformat, dest_type);
CheckGLError();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1678,9 +1678,9 @@ TEST_F(GLES2ImplementationTest, CopyTextureCHROMIUM) {
cmds::CopyTextureCHROMIUM cmd;
};
Cmds expected;
expected.cmd.Init(1, 2, 3, 4, GL_ALPHA);
expected.cmd.Init(1, 2, 3, 4, GL_ALPHA, GL_UNSIGNED_BYTE);

gl_->CopyTextureCHROMIUM(1, 2, 3, 4, GL_ALPHA);
gl_->CopyTextureCHROMIUM(1, 2, 3, 4, GL_ALPHA, GL_UNSIGNED_BYTE);
EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
}

Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/client/gles2_interface_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ virtual void TexImageIOSurface2DCHROMIUM(
GLuint plane) = 0;
virtual void CopyTextureCHROMIUM(
GLenum target, GLenum source_id, GLenum dest_id, GLint level,
GLint internalformat) = 0;
GLint internalformat, GLenum dest_type) = 0;
virtual void DrawArraysInstancedANGLE(
GLenum mode, GLint first, GLsizei count, GLsizei primcount) = 0;
virtual void DrawElementsInstancedANGLE(
Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/client/gles2_interface_stub_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ virtual void TexImageIOSurface2DCHROMIUM(
GLuint plane) OVERRIDE;
virtual void CopyTextureCHROMIUM(
GLenum target, GLenum source_id, GLenum dest_id, GLint level,
GLint internalformat) OVERRIDE;
GLint internalformat, GLenum dest_type) OVERRIDE;
virtual void DrawArraysInstancedANGLE(
GLenum mode, GLint first, GLsizei count, GLsizei primcount) OVERRIDE;
virtual void DrawElementsInstancedANGLE(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ void GLES2InterfaceStub::TexImageIOSurface2DCHROMIUM(
}
void GLES2InterfaceStub::CopyTextureCHROMIUM(
GLenum /* target */, GLenum /* source_id */, GLenum /* dest_id */,
GLint /* level */, GLint /* internalformat */) {
GLint /* level */, GLint /* internalformat */, GLenum /* dest_type */) {
}
void GLES2InterfaceStub::DrawArraysInstancedANGLE(
GLenum /* mode */, GLint /* first */, GLsizei /* count */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ virtual void TexImageIOSurface2DCHROMIUM(
GLuint plane) OVERRIDE;
virtual void CopyTextureCHROMIUM(
GLenum target, GLenum source_id, GLenum dest_id, GLint level,
GLint internalformat) OVERRIDE;
GLint internalformat, GLenum dest_type) OVERRIDE;
virtual void DrawArraysInstancedANGLE(
GLenum mode, GLint first, GLsizei count, GLsizei primcount) OVERRIDE;
virtual void DrawElementsInstancedANGLE(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1066,9 +1066,10 @@ void GLES2TraceImplementation::TexImageIOSurface2DCHROMIUM(

void GLES2TraceImplementation::CopyTextureCHROMIUM(
GLenum target, GLenum source_id, GLenum dest_id, GLint level,
GLint internalformat) {
GLint internalformat, GLenum dest_type) {
TRACE_EVENT_BINARY_EFFICIENT0("gpu", "GLES2Trace::CopyTextureCHROMIUM");
gl_->CopyTextureCHROMIUM(target, source_id, dest_id, level, internalformat);
gl_->CopyTextureCHROMIUM(
target, source_id, dest_id, level, internalformat, dest_type);
}

void GLES2TraceImplementation::DrawArraysInstancedANGLE(
Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/cmd_buffer_functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ GL_APICALL void GL_APIENTRY glDestroyStreamTextureCHROMIUM (GLuint textu
GL_APICALL void GL_APIENTRY glGetTranslatedShaderSourceANGLE (GLidShader shader, GLsizeiNotNegative bufsize, GLsizeiOptional* length, char* source);
GL_APICALL void GL_APIENTRY glPostSubBufferCHROMIUM (GLint x, GLint y, GLint width, GLint height);
GL_APICALL void GL_APIENTRY glTexImageIOSurface2DCHROMIUM (GLenumTextureBindTarget target, GLsizei width, GLsizei height, GLuint ioSurfaceId, GLuint plane);
GL_APICALL void GL_APIENTRY glCopyTextureCHROMIUM (GLenum target, GLenum source_id, GLenum dest_id, GLint level, GLintTextureInternalFormat internalformat);
GL_APICALL void GL_APIENTRY glCopyTextureCHROMIUM (GLenum target, GLenum source_id, GLenum dest_id, GLint level, GLintTextureInternalFormat internalformat, GLenumPixelType dest_type);
GL_APICALL void GL_APIENTRY glDrawArraysInstancedANGLE (GLenumDrawMode mode, GLint first, GLsizei count, GLsizei primcount);
GL_APICALL void GL_APIENTRY glDrawElementsInstancedANGLE (GLenumDrawMode mode, GLsizei count, GLenumIndexType type, const void* indices, GLsizei primcount);
GL_APICALL void GL_APIENTRY glVertexAttribDivisorANGLE (GLuint index, GLuint divisor);
Expand Down
16 changes: 11 additions & 5 deletions gpu/command_buffer/common/gles2_cmd_format_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -9890,20 +9890,23 @@ struct CopyTextureCHROMIUM {

void Init(
GLenum _target, GLenum _source_id, GLenum _dest_id, GLint _level,
GLint _internalformat) {
GLint _internalformat, GLenum _dest_type) {
SetHeader();
target = _target;
source_id = _source_id;
dest_id = _dest_id;
level = _level;
internalformat = _internalformat;
dest_type = _dest_type;
}

void* Set(
void* cmd, GLenum _target, GLenum _source_id, GLenum _dest_id,
GLint _level, GLint _internalformat) {
GLint _level, GLint _internalformat, GLenum _dest_type) {
static_cast<ValueType*>(
cmd)->Init(_target, _source_id, _dest_id, _level, _internalformat);
cmd)->Init(
_target, _source_id, _dest_id, _level, _internalformat,
_dest_type);
return NextCmdAddress<ValueType>(cmd);
}

Expand All @@ -9913,10 +9916,11 @@ struct CopyTextureCHROMIUM {
uint32 dest_id;
int32 level;
int32 internalformat;
uint32 dest_type;
};

COMPILE_ASSERT(sizeof(CopyTextureCHROMIUM) == 24,
Sizeof_CopyTextureCHROMIUM_is_not_24);
COMPILE_ASSERT(sizeof(CopyTextureCHROMIUM) == 28,
Sizeof_CopyTextureCHROMIUM_is_not_28);
COMPILE_ASSERT(offsetof(CopyTextureCHROMIUM, header) == 0,
OffsetOf_CopyTextureCHROMIUM_header_not_0);
COMPILE_ASSERT(offsetof(CopyTextureCHROMIUM, target) == 4,
Expand All @@ -9929,6 +9933,8 @@ COMPILE_ASSERT(offsetof(CopyTextureCHROMIUM, level) == 16,
OffsetOf_CopyTextureCHROMIUM_level_not_16);
COMPILE_ASSERT(offsetof(CopyTextureCHROMIUM, internalformat) == 20,
OffsetOf_CopyTextureCHROMIUM_internalformat_not_20);
COMPILE_ASSERT(offsetof(CopyTextureCHROMIUM, dest_type) == 24,
OffsetOf_CopyTextureCHROMIUM_dest_type_not_24);

struct DrawArraysInstancedANGLE {
typedef DrawArraysInstancedANGLE ValueType;
Expand Down
4 changes: 3 additions & 1 deletion gpu/command_buffer/common/gles2_cmd_format_test_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -3883,7 +3883,8 @@ TEST_F(GLES2FormatTest, CopyTextureCHROMIUM) {
static_cast<GLenum>(12),
static_cast<GLenum>(13),
static_cast<GLint>(14),
static_cast<GLint>(15));
static_cast<GLint>(15),
static_cast<GLenum>(16));
EXPECT_EQ(static_cast<uint32>(cmds::CopyTextureCHROMIUM::kCmdId),
cmd.header.command);
EXPECT_EQ(sizeof(cmd), cmd.header.size * 4u);
Expand All @@ -3892,6 +3893,7 @@ TEST_F(GLES2FormatTest, CopyTextureCHROMIUM) {
EXPECT_EQ(static_cast<GLenum>(13), cmd.dest_id);
EXPECT_EQ(static_cast<GLint>(14), cmd.level);
EXPECT_EQ(static_cast<GLint>(15), cmd.internalformat);
EXPECT_EQ(static_cast<GLenum>(16), cmd.dest_type);
CheckBytesWrittenMatchesExpectedSize(
next_cmd, sizeof(cmd));
}
Expand Down
16 changes: 7 additions & 9 deletions gpu/command_buffer/service/gles2_cmd_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,8 @@ class GLES2DecoderImpl : public GLES2Decoder {
GLuint source_id,
GLuint target_id,
GLint level,
GLenum internal_format);
GLenum internal_format,
GLenum dest_type);

// Wrapper for TexStorage2DEXT.
void DoTexStorage2DEXT(
Expand Down Expand Up @@ -9618,7 +9619,7 @@ static GLenum ExtractFormatFromStorageFormat(GLenum internalformat) {

void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
GLenum target, GLuint source_id, GLuint dest_id, GLint level,
GLenum internal_format) {
GLenum internal_format, GLenum dest_type) {
Texture* dest_texture = GetTexture(dest_id);
Texture* source_texture = GetTexture(source_id);

Expand Down Expand Up @@ -9684,18 +9685,14 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
return;
}

GLenum dest_type;
GLenum dest_type_previous;
GLenum dest_internal_format;
bool dest_level_defined = dest_texture->GetLevelSize(
GL_TEXTURE_2D, level, &dest_width, &dest_height);

if (dest_level_defined) {
dest_texture->GetLevelType(GL_TEXTURE_2D, level, &dest_type,
dest_texture->GetLevelType(GL_TEXTURE_2D, level, &dest_type_previous,
&dest_internal_format);
} else {
GLenum source_internal_format;
source_texture->GetLevelType(GL_TEXTURE_2D, 0, &dest_type,
&source_internal_format);
}

// Set source texture's width and height to be the same as
Expand All @@ -9708,7 +9705,8 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
// 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_internal_format != internal_format ||
dest_type_previous != dest_type) {
// Ensure that the glTexImage2D succeeds.
LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM");
glBindTexture(GL_TEXTURE_2D, dest_texture->service_id());
Expand Down
9 changes: 8 additions & 1 deletion gpu/command_buffer/service/gles2_cmd_decoder_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -3030,12 +3030,19 @@ error::Error GLES2DecoderImpl::HandleCopyTextureCHROMIUM(
GLenum dest_id = static_cast<GLenum>(c.dest_id);
GLint level = static_cast<GLint>(c.level);
GLint internalformat = static_cast<GLint>(c.internalformat);
GLenum dest_type = static_cast<GLenum>(c.dest_type);
if (!validators_->texture_internal_format.IsValid(internalformat)) {
LOCAL_SET_GL_ERROR(
GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "internalformat GL_INVALID_VALUE"); // NOLINT
return error::kNoError;
}
DoCopyTextureCHROMIUM(target, source_id, dest_id, level, internalformat);
if (!validators_->pixel_type.IsValid(dest_type)) {
LOCAL_SET_GL_ERROR_INVALID_ENUM("glCopyTextureCHROMIUM", dest_type,
"dest_type");
return error::kNoError;
}
DoCopyTextureCHROMIUM(
target, source_id, dest_id, level, internalformat, dest_type);
return error::kNoError;
}

Expand Down
Loading

0 comments on commit a4a6bdd

Please sign in to comment.