Chromium Code Reviews| 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 34ddc02171a0ff5e89669900151afc3dc263bb35..aaa44039a289dbe072095ccbcb6df7fdbbed22a4 100644 |
| --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc |
| +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc |
| @@ -50,6 +50,7 @@ |
| #include "gpu/command_buffer/service/program_manager.h" |
| #include "gpu/command_buffer/service/query_manager.h" |
| #include "gpu/command_buffer/service/renderbuffer_manager.h" |
| +#include "gpu/command_buffer/service/sampler_manager.h" |
| #include "gpu/command_buffer/service/shader_manager.h" |
| #include "gpu/command_buffer/service/shader_translator.h" |
| #include "gpu/command_buffer/service/texture_manager.h" |
| @@ -711,6 +712,8 @@ class GLES2DecoderImpl : public GLES2Decoder, public ErrorStateClient { |
| void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); |
| bool GenPathsCHROMIUMHelper(GLuint first_client_id, GLsizei range); |
| bool DeletePathsCHROMIUMHelper(GLuint first_client_id, GLsizei range); |
| + bool GenSamplersHelper(GLsizei n, const GLuint* client_ids); |
| + void DeleteSamplersHelper(GLsizei n, const GLuint* client_ids); |
| // Workarounds |
| void OnFboChanged() const; |
| @@ -740,6 +743,10 @@ class GLES2DecoderImpl : public GLES2Decoder, public ErrorStateClient { |
| return group_->program_manager(); |
| } |
| + SamplerManager* sampler_manager() { |
| + return group_->sampler_manager(); |
| + } |
| + |
| ShaderManager* shader_manager() { |
| return group_->shader_manager(); |
| } |
| @@ -798,6 +805,22 @@ class GLES2DecoderImpl : public GLES2Decoder, public ErrorStateClient { |
| texture_manager()->RemoveTexture(client_id); |
| } |
| + // Creates a Sampler for the given sampler. |
| + Sampler* CreateSampler( |
| + GLuint client_id, GLuint service_id) { |
| + return sampler_manager()->CreateSampler(client_id, service_id); |
| + } |
| + |
| + // Gets the sampler info for the given sampler. Returns NULL if none exists. |
| + Sampler* GetSampler(GLuint client_id) { |
| + return sampler_manager()->GetSampler(client_id); |
| + } |
| + |
| + // Deletes the sampler info for the given sampler. |
| + void RemoveSampler(GLuint client_id) { |
| + sampler_manager()->RemoveSampler(client_id); |
| + } |
| + |
| // Get the size (in pixels) of the currently bound frame buffer (either FBO |
| // or regular back buffer). |
| gfx::Size GetBoundReadFrameBufferSize(); |
| @@ -1358,6 +1381,9 @@ class GLES2DecoderImpl : public GLES2Decoder, public ErrorStateClient { |
| // Wrapper for glBindTexture since we need to track the current targets. |
| void DoBindTexture(GLenum target, GLuint texture); |
| + // Wrapper for glBindSampler since we need to track the current targets. |
| + void DoBindSampler(GLuint unit, GLuint sampler); |
| + |
| // Wrapper for glBindVertexArrayOES |
| void DoBindVertexArrayOES(GLuint array); |
| void EmulateVertexArrayState(); |
| @@ -1489,6 +1515,10 @@ class GLES2DecoderImpl : public GLES2Decoder, public ErrorStateClient { |
| void DoGetRenderbufferParameteriv( |
| GLenum target, GLenum pname, GLint* params); |
| + // Wrappers for glGetSamplerParameter. |
| + void DoGetSamplerParameterfv(GLuint client_id, GLenum pname, GLfloat* params); |
| + void DoGetSamplerParameteriv(GLuint client_id, GLenum pname, GLint* params); |
| + |
| // Wrapper for glGetShaderiv |
| void DoGetShaderiv(GLuint shader, GLenum pname, GLint* params); |
| @@ -1513,6 +1543,7 @@ class GLES2DecoderImpl : public GLES2Decoder, public ErrorStateClient { |
| bool DoIsRenderbuffer(GLuint client_id); |
| bool DoIsShader(GLuint client_id); |
| bool DoIsTexture(GLuint client_id); |
| + bool DoIsSampler(GLuint client_id); |
| bool DoIsVertexArrayOES(GLuint client_id); |
| bool DoIsPathCHROMIUM(GLuint client_id); |
| @@ -1554,10 +1585,13 @@ class GLES2DecoderImpl : public GLES2Decoder, public ErrorStateClient { |
| // Wrapper for glReleaseShaderCompiler. |
| void DoReleaseShaderCompiler() { } |
| - // Wrappers for glSamplerParameter*v functions. |
| + // Wrappers for glSamplerParameter functions. |
| + void DoSamplerParameterf(GLuint client_id, GLenum pname, GLfloat param); |
| + void DoSamplerParameteri(GLuint client_id, GLenum pname, GLint param); |
| void DoSamplerParameterfv( |
| - GLuint sampler, GLenum pname, const GLfloat* params); |
| - void DoSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* params); |
| + GLuint client_id, GLenum pname, const GLfloat* params); |
| + void DoSamplerParameteriv( |
| + GLuint client_id, GLenum pname, const GLint* params); |
| // Wrappers for glTexParameter functions. |
| void DoTexParameterf(GLenum target, GLenum pname, GLfloat param); |
| @@ -2692,6 +2726,7 @@ bool GLES2DecoderImpl::Initialize( |
| glGenBuffersARB(1, &fixed_attrib_buffer_id_); |
| state_.texture_units.resize(group_->max_texture_units()); |
| + state_.sampler_units.resize(group_->max_texture_units()); |
| for (uint32 tt = 0; tt < state_.texture_units.size(); ++tt) { |
| glActiveTexture(GL_TEXTURE0 + tt); |
| // We want the last bind to be 2D. |
| @@ -2714,6 +2749,9 @@ bool GLES2DecoderImpl::Initialize( |
| ref = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); |
| state_.texture_units[tt].bound_texture_2d = ref; |
| glBindTexture(GL_TEXTURE_2D, ref ? ref->service_id() : 0); |
| + |
| + if (features().enable_samplers) |
| + glBindSampler(tt, 0); |
|
piman
2015/12/05 02:45:19
nit: is it needed? it's the default state.
piman
2015/12/07 19:35:59
ping
|
| } |
| glActiveTexture(GL_TEXTURE0); |
| CHECK_GL_ERROR(); |
| @@ -3357,6 +3395,20 @@ bool GLES2DecoderImpl::GenTexturesHelper(GLsizei n, const GLuint* client_ids) { |
| return true; |
| } |
| +bool GLES2DecoderImpl::GenSamplersHelper(GLsizei n, const GLuint* client_ids) { |
| + for (GLsizei ii = 0; ii < n; ++ii) { |
| + if (GetSampler(client_ids[ii])) { |
| + return false; |
| + } |
| + } |
| + scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
| + glGenSamplers(n, service_ids.get()); |
| + for (GLsizei ii = 0; ii < n; ++ii) { |
| + CreateSampler(client_ids[ii], service_ids[ii]); |
| + } |
| + return true; |
| +} |
| + |
| bool GLES2DecoderImpl::GenPathsCHROMIUMHelper(GLuint first_client_id, |
| GLsizei range) { |
| GLuint last_client_id; |
| @@ -3526,6 +3578,19 @@ void GLES2DecoderImpl::DeleteTexturesHelper( |
| } |
| } |
| +void GLES2DecoderImpl::DeleteSamplersHelper( |
| + GLsizei n, const GLuint* client_ids) { |
| + for (GLsizei ii = 0; ii < n; ++ii) { |
| + Sampler* sampler = GetSampler(client_ids[ii]); |
| + if (sampler && !sampler->IsDeleted()) { |
| + // Unbind from current sampler units. |
| + state_.UnbindSampler(sampler); |
| + |
| + RemoveSampler(client_ids[ii]); |
| + } |
| + } |
| +} |
| + |
| // } // anonymous namespace |
| bool GLES2DecoderImpl::MakeCurrent() { |
| @@ -3969,6 +4034,7 @@ void GLES2DecoderImpl::Destroy(bool have_context) { |
| state_.vertex_attrib_manager = NULL; |
| state_.default_vertex_attrib_manager = NULL; |
| state_.texture_units.clear(); |
| + state_.sampler_units.clear(); |
| state_.bound_array_buffer = NULL; |
| state_.bound_copy_read_buffer = NULL; |
| state_.bound_copy_write_buffer = NULL; |
| @@ -4871,6 +4937,37 @@ void GLES2DecoderImpl::DoBindTexture(GLenum target, GLuint client_id) { |
| } |
| } |
| +void GLES2DecoderImpl::DoBindSampler(GLuint unit, GLuint client_id) { |
| + Sampler* sampler = NULL; |
| + GLuint service_id = 0; |
| + if (client_id != 0) { |
| + sampler = GetSampler(client_id); |
| + if (!sampler) { |
| + if (!group_->bind_generates_resource()) { |
|
piman
2015/12/05 02:45:19
Unlike textures or buffers, samplers are not impli
|
| + LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| + "glBindSampler", |
| + "id not generated by glGenSamplers"); |
| + return; |
| + } |
| + |
| + // It's a new id so make a texture texture for it. |
| + glGenSamplers(1, &service_id); |
| + DCHECK_NE(0u, service_id); |
| + sampler = CreateSampler(client_id, service_id); |
| + } |
| + } |
| + |
| + // Check the sampler exists |
| + if (sampler) { |
| + LogClientServiceForInfo(sampler, client_id, "glBindSampler"); |
| + glBindSampler(unit, sampler->service_id()); |
| + } else { |
| + glBindSampler(unit, 0); |
| + } |
| + |
| + state_.sampler_units[unit] = sampler; |
| +} |
| + |
| void GLES2DecoderImpl::DoDisableVertexAttribArray(GLuint index) { |
| if (state_.vertex_attrib_manager->Enable(index, false)) { |
| if (index != 0 || |
| @@ -6722,16 +6819,54 @@ void GLES2DecoderImpl::DoReadBuffer(GLenum src) { |
| glReadBuffer(src); |
| } |
| +void GLES2DecoderImpl::DoSamplerParameterf( |
| + GLuint client_id, GLenum pname, GLfloat param) { |
| + Sampler* sampler = GetSampler(client_id); |
| + if (!sampler) { |
| + LOCAL_SET_GL_ERROR( |
| + GL_INVALID_VALUE, "glSamplerParameterf", "unknown sampler"); |
| + return; |
| + } |
| + sampler_manager()->SetParameterf( |
| + "glSamplerParameterf", GetErrorState(), sampler, pname, param); |
| +} |
| + |
| +void GLES2DecoderImpl::DoSamplerParameteri( |
| + GLuint client_id, GLenum pname, GLint param) { |
| + Sampler* sampler = GetSampler(client_id); |
| + if (!sampler) { |
| + LOCAL_SET_GL_ERROR( |
| + GL_INVALID_VALUE, "glSamplerParameteri", "unknown sampler"); |
| + return; |
| + } |
| + sampler_manager()->SetParameteri( |
| + "glSamplerParameteri", GetErrorState(), sampler, pname, param); |
| +} |
| + |
| void GLES2DecoderImpl::DoSamplerParameterfv( |
| - GLuint sampler, GLenum pname, const GLfloat* params) { |
| + GLuint client_id, GLenum pname, const GLfloat* params) { |
| DCHECK(params); |
| - glSamplerParameterf(sampler, pname, params[0]); |
| + Sampler* sampler = GetSampler(client_id); |
| + if (!sampler) { |
| + LOCAL_SET_GL_ERROR( |
| + GL_INVALID_VALUE, "glSamplerParameterfv", "unknown sampler"); |
| + return; |
| + } |
| + sampler_manager()->SetParameterf( |
| + "glSamplerParameterfv", GetErrorState(), sampler, pname, params[0]); |
| } |
| void GLES2DecoderImpl::DoSamplerParameteriv( |
| - GLuint sampler, GLenum pname, const GLint* params) { |
| + GLuint client_id, GLenum pname, const GLint* params) { |
| DCHECK(params); |
| - glSamplerParameteri(sampler, pname, params[0]); |
| + Sampler* sampler = GetSampler(client_id); |
| + if (!sampler) { |
| + LOCAL_SET_GL_ERROR( |
| + GL_INVALID_VALUE, "glSamplerParameteriv", "unknown sampler"); |
| + return; |
| + } |
| + sampler_manager()->SetParameteri( |
| + "glSamplerParameteriv", GetErrorState(), sampler, pname, params[0]); |
| } |
| void GLES2DecoderImpl::DoTexParameterf( |
| @@ -8271,6 +8406,11 @@ bool GLES2DecoderImpl::DoIsTexture(GLuint client_id) { |
| return texture_ref && texture_ref->texture()->IsValid(); |
| } |
| +bool GLES2DecoderImpl::DoIsSampler(GLuint client_id) { |
| + const Sampler* sampler = GetSampler(client_id); |
| + return sampler && !sampler->IsDeleted(); |
| +} |
| + |
| void GLES2DecoderImpl::DoAttachShader( |
| GLuint program_client_id, GLint shader_client_id) { |
| Program* program = GetProgramInfoNotShader( |
| @@ -8361,6 +8501,28 @@ void GLES2DecoderImpl::GetVertexAttribHelper( |
| } |
| } |
| +void GLES2DecoderImpl::DoGetSamplerParameterfv( |
| + GLuint client_id, GLenum pname, GLfloat* params) { |
| + Sampler* sampler = GetSampler(client_id); |
| + if (!sampler) { |
| + LOCAL_SET_GL_ERROR( |
| + GL_INVALID_OPERATION, "glGetSamplerParamterfv", "unknown sampler"); |
| + return; |
| + } |
| + glGetSamplerParameterfv(sampler->service_id(), pname, params); |
| +} |
| + |
| +void GLES2DecoderImpl::DoGetSamplerParameteriv( |
| + GLuint client_id, GLenum pname, GLint* params) { |
| + Sampler* sampler = GetSampler(client_id); |
| + if (!sampler) { |
| + LOCAL_SET_GL_ERROR( |
| + GL_INVALID_OPERATION, "glGetSamplerParamteriv", "unknown sampler"); |
| + return; |
| + } |
| + glGetSamplerParameteriv(sampler->service_id(), pname, params); |
| +} |
| + |
| void GLES2DecoderImpl::DoGetTexParameterfv( |
| GLenum target, GLenum pname, GLfloat* params) { |
| InitTextureMaxAnisotropyIfNeeded(target, pname); |