OLD | NEW |
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 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 bool enforce_internal_framebuffer, | 632 bool enforce_internal_framebuffer, |
633 bool internal); | 633 bool internal); |
634 ~ScopedResolvedFrameBufferBinder(); | 634 ~ScopedResolvedFrameBufferBinder(); |
635 | 635 |
636 private: | 636 private: |
637 GLES2DecoderImpl* decoder_; | 637 GLES2DecoderImpl* decoder_; |
638 bool resolve_and_bind_; | 638 bool resolve_and_bind_; |
639 DISALLOW_COPY_AND_ASSIGN(ScopedResolvedFrameBufferBinder); | 639 DISALLOW_COPY_AND_ASSIGN(ScopedResolvedFrameBufferBinder); |
640 }; | 640 }; |
641 | 641 |
642 class ScopedModifyPixels { | |
643 public: | |
644 explicit ScopedModifyPixels(TextureRef* ref); | |
645 ~ScopedModifyPixels(); | |
646 | |
647 private: | |
648 TextureRef* ref_; | |
649 }; | |
650 | |
651 ScopedModifyPixels::ScopedModifyPixels(TextureRef* ref) : ref_(ref) { | |
652 if (ref_) | |
653 ref_->texture()->OnWillModifyPixels(); | |
654 } | |
655 | |
656 ScopedModifyPixels::~ScopedModifyPixels() { | |
657 if (ref_) | |
658 ref_->texture()->OnDidModifyPixels(); | |
659 } | |
660 | |
661 class ScopedRenderTo { | |
662 public: | |
663 explicit ScopedRenderTo(Framebuffer* framebuffer) | |
664 : ScopedRenderTo(framebuffer, 0) {} | |
665 ScopedRenderTo(Framebuffer* framebuffer, GLenum attachment); | |
666 ~ScopedRenderTo(); | |
667 | |
668 private: | |
669 const Framebuffer* framebuffer_; | |
670 GLenum attachment_; | |
671 }; | |
672 | |
673 ScopedRenderTo::ScopedRenderTo(Framebuffer* framebuffer, GLenum attachment) | |
674 : framebuffer_(framebuffer), | |
675 attachment_(attachment) { | |
676 if (framebuffer_) | |
677 framebuffer_->OnWillRenderTo(attachment_); | |
678 } | |
679 | |
680 ScopedRenderTo::~ScopedRenderTo() { | |
681 if (framebuffer_) | |
682 framebuffer_->OnDidRenderTo(attachment_); | |
683 } | |
684 | |
685 // Encapsulates an OpenGL texture. | 642 // Encapsulates an OpenGL texture. |
686 class BackTexture { | 643 class BackTexture { |
687 public: | 644 public: |
688 explicit BackTexture(MemoryTracker* memory_tracker, ContextState* state); | 645 explicit BackTexture(MemoryTracker* memory_tracker, ContextState* state); |
689 ~BackTexture(); | 646 ~BackTexture(); |
690 | 647 |
691 // Create a new render texture. | 648 // Create a new render texture. |
692 void Create(); | 649 void Create(); |
693 | 650 |
694 // Set the initial size and format of a render texture or resize it. | 651 // Set the initial size and format of a render texture or resize it. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 | 784 |
828 GLES2Decoder::~GLES2Decoder() { | 785 GLES2Decoder::~GLES2Decoder() { |
829 } | 786 } |
830 | 787 |
831 void GLES2Decoder::BeginDecoding() {} | 788 void GLES2Decoder::BeginDecoding() {} |
832 | 789 |
833 void GLES2Decoder::EndDecoding() {} | 790 void GLES2Decoder::EndDecoding() {} |
834 | 791 |
835 // This class implements GLES2Decoder so we don't have to expose all the GLES2 | 792 // This class implements GLES2Decoder so we don't have to expose all the GLES2 |
836 // cmd stuff to outside this class. | 793 // cmd stuff to outside this class. |
837 class GLES2DecoderImpl : public GLES2Decoder, | 794 class GLES2DecoderImpl : public GLES2Decoder, public ErrorStateClient { |
838 public FramebufferManager::TextureDetachObserver, | |
839 public ErrorStateClient { | |
840 public: | 795 public: |
841 explicit GLES2DecoderImpl(ContextGroup* group); | 796 explicit GLES2DecoderImpl(ContextGroup* group); |
842 ~GLES2DecoderImpl() override; | 797 ~GLES2DecoderImpl() override; |
843 | 798 |
844 // Overridden from AsyncAPIInterface. | 799 // Overridden from AsyncAPIInterface. |
845 Error DoCommand(unsigned int command, | 800 Error DoCommand(unsigned int command, |
846 unsigned int arg_count, | 801 unsigned int arg_count, |
847 const void* args) override; | 802 const void* args) override; |
848 | 803 |
849 error::Error DoCommands(unsigned int num_commands, | 804 error::Error DoCommands(unsigned int num_commands, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 | 913 |
959 // These check the state of the currently bound framebuffer or the | 914 // These check the state of the currently bound framebuffer or the |
960 // backbuffer if no framebuffer is bound. | 915 // backbuffer if no framebuffer is bound. |
961 // Check with all attached and enabled color attachments. | 916 // Check with all attached and enabled color attachments. |
962 bool BoundFramebufferHasColorAttachmentWithAlpha(); | 917 bool BoundFramebufferHasColorAttachmentWithAlpha(); |
963 bool BoundFramebufferHasDepthAttachment(); | 918 bool BoundFramebufferHasDepthAttachment(); |
964 bool BoundFramebufferHasStencilAttachment(); | 919 bool BoundFramebufferHasStencilAttachment(); |
965 | 920 |
966 error::ContextLostReason GetContextLostReason() override; | 921 error::ContextLostReason GetContextLostReason() override; |
967 | 922 |
968 // Overridden from FramebufferManager::TextureDetachObserver: | |
969 void OnTextureRefDetachedFromFramebuffer(TextureRef* texture) override; | |
970 | |
971 // Overriden from ErrorStateClient. | 923 // Overriden from ErrorStateClient. |
972 void OnContextLostError() override; | 924 void OnContextLostError() override; |
973 void OnOutOfMemoryError() override; | 925 void OnOutOfMemoryError() override; |
974 | 926 |
975 // Ensure Renderbuffer corresponding to last DoBindRenderbuffer() is bound. | 927 // Ensure Renderbuffer corresponding to last DoBindRenderbuffer() is bound. |
976 void EnsureRenderbufferBound(); | 928 void EnsureRenderbufferBound(); |
977 | 929 |
978 // Helpers to facilitate calling into compatible extensions. | 930 // Helpers to facilitate calling into compatible extensions. |
979 static void RenderbufferStorageMultisampleHelper( | 931 static void RenderbufferStorageMultisampleHelper( |
980 const FeatureInfo* feature_info, | 932 const FeatureInfo* feature_info, |
(...skipping 981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1962 bool IsDrawValid( | 1914 bool IsDrawValid( |
1963 const char* function_name, GLuint max_vertex_accessed, bool instanced, | 1915 const char* function_name, GLuint max_vertex_accessed, bool instanced, |
1964 GLsizei primcount); | 1916 GLsizei primcount); |
1965 | 1917 |
1966 // Returns true if successful, simulated will be true if attrib0 was | 1918 // Returns true if successful, simulated will be true if attrib0 was |
1967 // simulated. | 1919 // simulated. |
1968 bool SimulateAttrib0( | 1920 bool SimulateAttrib0( |
1969 const char* function_name, GLuint max_vertex_accessed, bool* simulated); | 1921 const char* function_name, GLuint max_vertex_accessed, bool* simulated); |
1970 void RestoreStateForAttrib(GLuint attrib, bool restore_array_binding); | 1922 void RestoreStateForAttrib(GLuint attrib, bool restore_array_binding); |
1971 | 1923 |
1972 // If an image is bound to texture, this will call Will/DidUseTexImage | 1924 // Copies the image to the texture currently bound to |textarget|. The image |
1973 // if needed. | 1925 // state of |texture| is updated to reflect the new state. |
1974 void DoWillUseTexImageIfNeeded(Texture* texture, GLenum textarget); | 1926 void DoCopyTexImage(Texture* texture, GLenum textarget, gfx::GLImage* image); |
1975 void DoDidUseTexImageIfNeeded(Texture* texture, GLenum textarget); | 1927 |
| 1928 // This will call DoCopyTexImage if texture has an image but that image is |
| 1929 // not bound or copied to the texture. |
| 1930 void DoCopyTexImageIfNeeded(Texture* texture, GLenum textarget); |
1976 | 1931 |
1977 // Returns false if textures were replaced. | 1932 // Returns false if textures were replaced. |
1978 bool PrepareTexturesForRender(); | 1933 bool PrepareTexturesForRender(); |
1979 void RestoreStateForTextures(); | 1934 void RestoreStateForTextures(); |
1980 | 1935 |
1981 // Returns true if GL_FIXED attribs were simulated. | 1936 // Returns true if GL_FIXED attribs were simulated. |
1982 bool SimulateFixedAttribs( | 1937 bool SimulateFixedAttribs( |
1983 const char* function_name, | 1938 const char* function_name, |
1984 GLuint max_vertex_accessed, bool* simulated, GLsizei primcount); | 1939 GLuint max_vertex_accessed, bool* simulated, GLsizei primcount); |
1985 void RestoreStateForSimulatedFixedAttribs(); | 1940 void RestoreStateForSimulatedFixedAttribs(); |
(...skipping 1299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3285 } | 3240 } |
3286 | 3241 |
3287 if (workarounds().gl_clear_broken) { | 3242 if (workarounds().gl_clear_broken) { |
3288 DCHECK(!clear_framebuffer_blit_.get()); | 3243 DCHECK(!clear_framebuffer_blit_.get()); |
3289 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glClearWorkaroundInit"); | 3244 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glClearWorkaroundInit"); |
3290 clear_framebuffer_blit_.reset(new ClearFramebufferResourceManager(this)); | 3245 clear_framebuffer_blit_.reset(new ClearFramebufferResourceManager(this)); |
3291 if (LOCAL_PEEK_GL_ERROR("glClearWorkaroundInit") != GL_NO_ERROR) | 3246 if (LOCAL_PEEK_GL_ERROR("glClearWorkaroundInit") != GL_NO_ERROR) |
3292 return false; | 3247 return false; |
3293 } | 3248 } |
3294 | 3249 |
3295 framebuffer_manager()->AddObserver(this); | |
3296 | |
3297 return true; | 3250 return true; |
3298 } | 3251 } |
3299 | 3252 |
3300 Capabilities GLES2DecoderImpl::GetCapabilities() { | 3253 Capabilities GLES2DecoderImpl::GetCapabilities() { |
3301 DCHECK(initialized()); | 3254 DCHECK(initialized()); |
3302 Capabilities caps; | 3255 Capabilities caps; |
3303 caps.VisitPrecisions([](GLenum shader, GLenum type, | 3256 caps.VisitPrecisions([](GLenum shader, GLenum type, |
3304 Capabilities::ShaderPrecision* shader_precision) { | 3257 Capabilities::ShaderPrecision* shader_precision) { |
3305 GLint range[2] = {0, 0}; | 3258 GLint range[2] = {0, 0}; |
3306 GLint precision = 0; | 3259 GLint precision = 0; |
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4386 fragment_translator_ = NULL; | 4339 fragment_translator_ = NULL; |
4387 vertex_translator_ = NULL; | 4340 vertex_translator_ = NULL; |
4388 | 4341 |
4389 // Destroy the GPU Tracer which may own some in process GPU Timings. | 4342 // Destroy the GPU Tracer which may own some in process GPU Timings. |
4390 if (gpu_tracer_) { | 4343 if (gpu_tracer_) { |
4391 gpu_tracer_->Destroy(have_context); | 4344 gpu_tracer_->Destroy(have_context); |
4392 gpu_tracer_.reset(); | 4345 gpu_tracer_.reset(); |
4393 } | 4346 } |
4394 | 4347 |
4395 if (group_.get()) { | 4348 if (group_.get()) { |
4396 framebuffer_manager()->RemoveObserver(this); | |
4397 group_->Destroy(this, have_context); | 4349 group_->Destroy(this, have_context); |
4398 group_ = NULL; | 4350 group_ = NULL; |
4399 } | 4351 } |
4400 | 4352 |
4401 if (context_.get()) { | 4353 if (context_.get()) { |
4402 context_->ReleaseCurrent(NULL); | 4354 context_->ReleaseCurrent(NULL); |
4403 context_ = NULL; | 4355 context_ = NULL; |
4404 } | 4356 } |
4405 | 4357 |
4406 #if defined(OS_MACOSX) | 4358 #if defined(OS_MACOSX) |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5230 attachment = GL_STENCIL_ATTACHMENT; | 5182 attachment = GL_STENCIL_ATTACHMENT; |
5231 break; | 5183 break; |
5232 default: | 5184 default: |
5233 NOTREACHED(); | 5185 NOTREACHED(); |
5234 return; | 5186 return; |
5235 } | 5187 } |
5236 } | 5188 } |
5237 translated_attachments[i] = attachment; | 5189 translated_attachments[i] = attachment; |
5238 } | 5190 } |
5239 | 5191 |
5240 ScopedRenderTo do_render(framebuffer); | |
5241 if (feature_info_->gl_version_info().is_es3) { | 5192 if (feature_info_->gl_version_info().is_es3) { |
5242 glInvalidateFramebuffer( | 5193 glInvalidateFramebuffer( |
5243 target, numAttachments, translated_attachments.get()); | 5194 target, numAttachments, translated_attachments.get()); |
5244 } else { | 5195 } else { |
5245 glDiscardFramebufferEXT( | 5196 glDiscardFramebufferEXT( |
5246 target, numAttachments, translated_attachments.get()); | 5197 target, numAttachments, translated_attachments.get()); |
5247 } | 5198 } |
5248 } | 5199 } |
5249 | 5200 |
5250 void GLES2DecoderImpl::DoEnableVertexAttribArray(GLuint index) { | 5201 void GLES2DecoderImpl::DoEnableVertexAttribArray(GLuint index) { |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6008 } | 5959 } |
6009 return error::kNoError; | 5960 return error::kNoError; |
6010 } | 5961 } |
6011 | 5962 |
6012 error::Error GLES2DecoderImpl::DoClear(GLbitfield mask) { | 5963 error::Error GLES2DecoderImpl::DoClear(GLbitfield mask) { |
6013 DCHECK(!ShouldDeferDraws()); | 5964 DCHECK(!ShouldDeferDraws()); |
6014 if (CheckBoundFramebuffersValid("glClear")) { | 5965 if (CheckBoundFramebuffersValid("glClear")) { |
6015 ApplyDirtyState(); | 5966 ApplyDirtyState(); |
6016 // TODO(zmo): Filter out INTEGER/SIGNED INTEGER images to avoid | 5967 // TODO(zmo): Filter out INTEGER/SIGNED INTEGER images to avoid |
6017 // undefined results. | 5968 // undefined results. |
6018 ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); | |
6019 if (workarounds().gl_clear_broken) { | 5969 if (workarounds().gl_clear_broken) { |
6020 ScopedGLErrorSuppressor suppressor("GLES2DecoderImpl::ClearWorkaround", | 5970 ScopedGLErrorSuppressor suppressor("GLES2DecoderImpl::ClearWorkaround", |
6021 GetErrorState()); | 5971 GetErrorState()); |
6022 if (!BoundFramebufferHasDepthAttachment()) | 5972 if (!BoundFramebufferHasDepthAttachment()) |
6023 mask &= ~GL_DEPTH_BUFFER_BIT; | 5973 mask &= ~GL_DEPTH_BUFFER_BIT; |
6024 if (!BoundFramebufferHasStencilAttachment()) | 5974 if (!BoundFramebufferHasStencilAttachment()) |
6025 mask &= ~GL_STENCIL_BUFFER_BIT; | 5975 mask &= ~GL_STENCIL_BUFFER_BIT; |
6026 clear_framebuffer_blit_->ClearFramebuffer( | 5976 clear_framebuffer_blit_->ClearFramebuffer( |
6027 this, GetBoundReadFrameBufferSize(), mask, state_.color_clear_red, | 5977 this, GetBoundReadFrameBufferSize(), mask, state_.color_clear_red, |
6028 state_.color_clear_green, state_.color_clear_blue, | 5978 state_.color_clear_green, state_.color_clear_blue, |
(...skipping 13 matching lines...) Expand all Loading... |
6042 | 5992 |
6043 switch (buffer) { | 5993 switch (buffer) { |
6044 case GL_COLOR: | 5994 case GL_COLOR: |
6045 case GL_STENCIL: | 5995 case GL_STENCIL: |
6046 break; | 5996 break; |
6047 default: | 5997 default: |
6048 LOCAL_SET_GL_ERROR( | 5998 LOCAL_SET_GL_ERROR( |
6049 GL_INVALID_ENUM, "glClearBufferiv", "invalid buffer"); | 5999 GL_INVALID_ENUM, "glClearBufferiv", "invalid buffer"); |
6050 return; | 6000 return; |
6051 } | 6001 } |
6052 GLenum attachment = 0; | |
6053 if (buffer == GL_COLOR) { | 6002 if (buffer == GL_COLOR) { |
6054 if (drawbuffer < 0 || | 6003 if (drawbuffer < 0 || |
6055 drawbuffer >= static_cast<GLint>(group_->max_draw_buffers())) { | 6004 drawbuffer >= static_cast<GLint>(group_->max_draw_buffers())) { |
6056 LOCAL_SET_GL_ERROR( | 6005 LOCAL_SET_GL_ERROR( |
6057 GL_INVALID_VALUE, "glClearBufferiv", "invalid drawBuffer"); | 6006 GL_INVALID_VALUE, "glClearBufferiv", "invalid drawBuffer"); |
6058 return; | 6007 return; |
6059 } | 6008 } |
6060 GLenum internal_format = | 6009 GLenum internal_format = |
6061 GetBoundColorDrawBufferInternalFormat(drawbuffer); | 6010 GetBoundColorDrawBufferInternalFormat(drawbuffer); |
6062 if (!GLES2Util::IsSignedIntegerFormat(internal_format)) { | 6011 if (!GLES2Util::IsSignedIntegerFormat(internal_format)) { |
6063 // To avoid undefined results, return without calling the gl function. | 6012 // To avoid undefined results, return without calling the gl function. |
6064 return; | 6013 return; |
6065 } | 6014 } |
6066 attachment = static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + drawbuffer); | |
6067 } else { | 6015 } else { |
6068 DCHECK(buffer == GL_STENCIL); | 6016 DCHECK(buffer == GL_STENCIL); |
6069 if (drawbuffer != 0) { | 6017 if (drawbuffer != 0) { |
6070 LOCAL_SET_GL_ERROR( | 6018 LOCAL_SET_GL_ERROR( |
6071 GL_INVALID_VALUE, "glClearBufferiv", "invalid drawBuffer"); | 6019 GL_INVALID_VALUE, "glClearBufferiv", "invalid drawBuffer"); |
6072 return; | 6020 return; |
6073 } | 6021 } |
6074 if (!BoundFramebufferHasStencilAttachment()) { | 6022 if (!BoundFramebufferHasStencilAttachment()) { |
6075 return; | 6023 return; |
6076 } | 6024 } |
6077 attachment = GL_STENCIL_ATTACHMENT; | |
6078 } | 6025 } |
6079 MarkDrawBufferAsCleared(buffer, drawbuffer); | 6026 MarkDrawBufferAsCleared(buffer, drawbuffer); |
6080 { | 6027 glClearBufferiv(buffer, drawbuffer, value); |
6081 ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get(), | |
6082 attachment); | |
6083 glClearBufferiv(buffer, drawbuffer, value); | |
6084 } | |
6085 } | 6028 } |
6086 | 6029 |
6087 void GLES2DecoderImpl::DoClearBufferuiv( | 6030 void GLES2DecoderImpl::DoClearBufferuiv( |
6088 GLenum buffer, GLint drawbuffer, const GLuint* value) { | 6031 GLenum buffer, GLint drawbuffer, const GLuint* value) { |
6089 if (!CheckBoundDrawFramebufferValid("glClearBufferuiv")) | 6032 if (!CheckBoundDrawFramebufferValid("glClearBufferuiv")) |
6090 return; | 6033 return; |
6091 ApplyDirtyState(); | 6034 ApplyDirtyState(); |
6092 | 6035 |
6093 switch (buffer) { | 6036 switch (buffer) { |
6094 case GL_COLOR: | 6037 case GL_COLOR: |
6095 break; | 6038 break; |
6096 default: | 6039 default: |
6097 LOCAL_SET_GL_ERROR( | 6040 LOCAL_SET_GL_ERROR( |
6098 GL_INVALID_ENUM, "glClearBufferuiv", "invalid buffer"); | 6041 GL_INVALID_ENUM, "glClearBufferuiv", "invalid buffer"); |
6099 return; | 6042 return; |
6100 } | 6043 } |
6101 if (drawbuffer < 0 || | 6044 if (drawbuffer < 0 || |
6102 drawbuffer >= static_cast<GLint>(group_->max_draw_buffers())) { | 6045 drawbuffer >= static_cast<GLint>(group_->max_draw_buffers())) { |
6103 LOCAL_SET_GL_ERROR( | 6046 LOCAL_SET_GL_ERROR( |
6104 GL_INVALID_VALUE, "glClearBufferuiv", "invalid drawBuffer"); | 6047 GL_INVALID_VALUE, "glClearBufferuiv", "invalid drawBuffer"); |
6105 return; | 6048 return; |
6106 } | 6049 } |
6107 GLenum internal_format = | 6050 GLenum internal_format = |
6108 GetBoundColorDrawBufferInternalFormat(drawbuffer); | 6051 GetBoundColorDrawBufferInternalFormat(drawbuffer); |
6109 if (!GLES2Util::IsUnsignedIntegerFormat(internal_format)) { | 6052 if (!GLES2Util::IsUnsignedIntegerFormat(internal_format)) { |
6110 // To avoid undefined results, return without calling the gl function. | 6053 // To avoid undefined results, return without calling the gl function. |
6111 return; | 6054 return; |
6112 } | 6055 } |
6113 MarkDrawBufferAsCleared(buffer, drawbuffer); | 6056 MarkDrawBufferAsCleared(buffer, drawbuffer); |
6114 GLenum attachment = static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + drawbuffer); | 6057 glClearBufferuiv(buffer, drawbuffer, value); |
6115 { | |
6116 ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get(), | |
6117 attachment); | |
6118 glClearBufferuiv(buffer, drawbuffer, value); | |
6119 } | |
6120 } | 6058 } |
6121 | 6059 |
6122 void GLES2DecoderImpl::DoClearBufferfv( | 6060 void GLES2DecoderImpl::DoClearBufferfv( |
6123 GLenum buffer, GLint drawbuffer, const GLfloat* value) { | 6061 GLenum buffer, GLint drawbuffer, const GLfloat* value) { |
6124 if (!CheckBoundDrawFramebufferValid("glClearBufferfv")) | 6062 if (!CheckBoundDrawFramebufferValid("glClearBufferfv")) |
6125 return; | 6063 return; |
6126 ApplyDirtyState(); | 6064 ApplyDirtyState(); |
6127 | 6065 |
6128 switch (buffer) { | 6066 switch (buffer) { |
6129 case GL_COLOR: | 6067 case GL_COLOR: |
6130 case GL_DEPTH: | 6068 case GL_DEPTH: |
6131 break; | 6069 break; |
6132 default: | 6070 default: |
6133 LOCAL_SET_GL_ERROR( | 6071 LOCAL_SET_GL_ERROR( |
6134 GL_INVALID_ENUM, "glClearBufferfv", "invalid buffer"); | 6072 GL_INVALID_ENUM, "glClearBufferfv", "invalid buffer"); |
6135 return; | 6073 return; |
6136 } | 6074 } |
6137 GLenum attachment = 0; | |
6138 if (buffer == GL_COLOR) { | 6075 if (buffer == GL_COLOR) { |
6139 if (drawbuffer < 0 || | 6076 if (drawbuffer < 0 || |
6140 drawbuffer >= static_cast<GLint>(group_->max_draw_buffers())) { | 6077 drawbuffer >= static_cast<GLint>(group_->max_draw_buffers())) { |
6141 LOCAL_SET_GL_ERROR( | 6078 LOCAL_SET_GL_ERROR( |
6142 GL_INVALID_VALUE, "glClearBufferfv", "invalid drawBuffer"); | 6079 GL_INVALID_VALUE, "glClearBufferfv", "invalid drawBuffer"); |
6143 return; | 6080 return; |
6144 } | 6081 } |
6145 GLenum internal_format = | 6082 GLenum internal_format = |
6146 GetBoundColorDrawBufferInternalFormat(drawbuffer); | 6083 GetBoundColorDrawBufferInternalFormat(drawbuffer); |
6147 if (GLES2Util::IsIntegerFormat(internal_format)) { | 6084 if (GLES2Util::IsIntegerFormat(internal_format)) { |
6148 // To avoid undefined results, return without calling the gl function. | 6085 // To avoid undefined results, return without calling the gl function. |
6149 return; | 6086 return; |
6150 } | 6087 } |
6151 attachment = static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + drawbuffer); | |
6152 } else { | 6088 } else { |
6153 DCHECK(buffer == GL_DEPTH); | 6089 DCHECK(buffer == GL_DEPTH); |
6154 if (drawbuffer != 0) { | 6090 if (drawbuffer != 0) { |
6155 LOCAL_SET_GL_ERROR( | 6091 LOCAL_SET_GL_ERROR( |
6156 GL_INVALID_VALUE, "glClearBufferfv", "invalid drawBuffer"); | 6092 GL_INVALID_VALUE, "glClearBufferfv", "invalid drawBuffer"); |
6157 return; | 6093 return; |
6158 } | 6094 } |
6159 if (!BoundFramebufferHasDepthAttachment()) { | 6095 if (!BoundFramebufferHasDepthAttachment()) { |
6160 return; | 6096 return; |
6161 } | 6097 } |
6162 attachment = GL_DEPTH_ATTACHMENT; | |
6163 } | 6098 } |
6164 MarkDrawBufferAsCleared(buffer, drawbuffer); | 6099 MarkDrawBufferAsCleared(buffer, drawbuffer); |
6165 { | 6100 glClearBufferfv(buffer, drawbuffer, value); |
6166 ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get(), | |
6167 attachment); | |
6168 glClearBufferfv(buffer, drawbuffer, value); | |
6169 } | |
6170 } | 6101 } |
6171 | 6102 |
6172 void GLES2DecoderImpl::DoClearBufferfi( | 6103 void GLES2DecoderImpl::DoClearBufferfi( |
6173 GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) { | 6104 GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) { |
6174 if (!CheckBoundDrawFramebufferValid("glClearBufferfi")) | 6105 if (!CheckBoundDrawFramebufferValid("glClearBufferfi")) |
6175 return; | 6106 return; |
6176 ApplyDirtyState(); | 6107 ApplyDirtyState(); |
6177 | 6108 |
6178 switch (buffer) { | 6109 switch (buffer) { |
6179 case GL_DEPTH_STENCIL: | 6110 case GL_DEPTH_STENCIL: |
6180 break; | 6111 break; |
6181 default: | 6112 default: |
6182 LOCAL_SET_GL_ERROR( | 6113 LOCAL_SET_GL_ERROR( |
6183 GL_INVALID_ENUM, "glClearBufferfi", "invalid buffer"); | 6114 GL_INVALID_ENUM, "glClearBufferfi", "invalid buffer"); |
6184 return; | 6115 return; |
6185 } | 6116 } |
6186 if (drawbuffer != 0) { | 6117 if (drawbuffer != 0) { |
6187 LOCAL_SET_GL_ERROR( | 6118 LOCAL_SET_GL_ERROR( |
6188 GL_INVALID_VALUE, "glClearBufferfi", "invalid drawBuffer"); | 6119 GL_INVALID_VALUE, "glClearBufferfi", "invalid drawBuffer"); |
6189 return; | 6120 return; |
6190 } | 6121 } |
6191 if (!BoundFramebufferHasDepthAttachment() && | 6122 if (!BoundFramebufferHasDepthAttachment() && |
6192 !BoundFramebufferHasStencilAttachment()) { | 6123 !BoundFramebufferHasStencilAttachment()) { |
6193 return; | 6124 return; |
6194 } | 6125 } |
6195 MarkDrawBufferAsCleared(GL_DEPTH, drawbuffer); | 6126 MarkDrawBufferAsCleared(GL_DEPTH, drawbuffer); |
6196 MarkDrawBufferAsCleared(GL_STENCIL, drawbuffer); | 6127 MarkDrawBufferAsCleared(GL_STENCIL, drawbuffer); |
6197 { | 6128 glClearBufferfi(buffer, drawbuffer, depth, stencil); |
6198 ScopedRenderTo do_render_depth( | |
6199 framebuffer_state_.bound_draw_framebuffer.get(), | |
6200 GL_DEPTH_ATTACHMENT); | |
6201 ScopedRenderTo do_render_stencil( | |
6202 framebuffer_state_.bound_draw_framebuffer.get(), | |
6203 GL_STENCIL_ATTACHMENT); | |
6204 glClearBufferfi(buffer, drawbuffer, depth, stencil); | |
6205 } | |
6206 } | 6129 } |
6207 | 6130 |
6208 void GLES2DecoderImpl::DoFramebufferRenderbuffer( | 6131 void GLES2DecoderImpl::DoFramebufferRenderbuffer( |
6209 GLenum target, GLenum attachment, GLenum renderbuffertarget, | 6132 GLenum target, GLenum attachment, GLenum renderbuffertarget, |
6210 GLuint client_renderbuffer_id) { | 6133 GLuint client_renderbuffer_id) { |
6211 Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); | 6134 Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); |
6212 if (!framebuffer) { | 6135 if (!framebuffer) { |
6213 LOCAL_SET_GL_ERROR( | 6136 LOCAL_SET_GL_ERROR( |
6214 GL_INVALID_OPERATION, | 6137 GL_INVALID_OPERATION, |
6215 "glFramebufferRenderbuffer", "no framebuffer bound"); | 6138 "glFramebufferRenderbuffer", "no framebuffer bound"); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6406 } | 6329 } |
6407 | 6330 |
6408 if (!texture_manager()->ValidForTarget(textarget, level, 0, 0, 1)) { | 6331 if (!texture_manager()->ValidForTarget(textarget, level, 0, 0, 1)) { |
6409 LOCAL_SET_GL_ERROR( | 6332 LOCAL_SET_GL_ERROR( |
6410 GL_INVALID_VALUE, | 6333 GL_INVALID_VALUE, |
6411 name, "level out of range"); | 6334 name, "level out of range"); |
6412 return; | 6335 return; |
6413 } | 6336 } |
6414 | 6337 |
6415 if (texture_ref) | 6338 if (texture_ref) |
6416 DoWillUseTexImageIfNeeded(texture_ref->texture(), textarget); | 6339 DoCopyTexImageIfNeeded(texture_ref->texture(), textarget); |
6417 | 6340 |
6418 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(name); | 6341 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(name); |
6419 if (0 == samples) { | 6342 if (0 == samples) { |
6420 glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level); | 6343 glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level); |
6421 } else { | 6344 } else { |
6422 if (features().use_img_for_multisampled_render_to_texture) { | 6345 if (features().use_img_for_multisampled_render_to_texture) { |
6423 glFramebufferTexture2DMultisampleIMG(target, attachment, textarget, | 6346 glFramebufferTexture2DMultisampleIMG(target, attachment, textarget, |
6424 service_id, level, samples); | 6347 service_id, level, samples); |
6425 } else { | 6348 } else { |
6426 glFramebufferTexture2DMultisampleEXT(target, attachment, textarget, | 6349 glFramebufferTexture2DMultisampleEXT(target, attachment, textarget, |
6427 service_id, level, samples); | 6350 service_id, level, samples); |
6428 } | 6351 } |
6429 } | 6352 } |
6430 GLenum error = LOCAL_PEEK_GL_ERROR(name); | 6353 GLenum error = LOCAL_PEEK_GL_ERROR(name); |
6431 if (error == GL_NO_ERROR) { | 6354 if (error == GL_NO_ERROR) { |
6432 framebuffer->AttachTexture(attachment, texture_ref, textarget, level, | 6355 framebuffer->AttachTexture(attachment, texture_ref, textarget, level, |
6433 samples); | 6356 samples); |
6434 } | 6357 } |
6435 if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { | 6358 if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { |
6436 framebuffer_state_.clear_state_dirty = true; | 6359 framebuffer_state_.clear_state_dirty = true; |
6437 } | 6360 } |
6438 | 6361 |
6439 if (texture_ref) | |
6440 DoDidUseTexImageIfNeeded(texture_ref->texture(), textarget); | |
6441 | |
6442 OnFboChanged(); | 6362 OnFboChanged(); |
6443 } | 6363 } |
6444 | 6364 |
6445 void GLES2DecoderImpl::DoFramebufferTextureLayer( | 6365 void GLES2DecoderImpl::DoFramebufferTextureLayer( |
6446 GLenum target, GLenum attachment, GLuint client_texture_id, | 6366 GLenum target, GLenum attachment, GLuint client_texture_id, |
6447 GLint level, GLint layer) { | 6367 GLint level, GLint layer) { |
6448 // TODO(zmo): Unsafe ES3 API, missing states update. | 6368 // TODO(zmo): Unsafe ES3 API, missing states update. |
6449 GLuint service_id = 0; | 6369 GLuint service_id = 0; |
6450 TextureRef* texture_ref = NULL; | 6370 TextureRef* texture_ref = NULL; |
6451 if (client_texture_id) { | 6371 if (client_texture_id) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6571 GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, | 6491 GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
6572 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, | 6492 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
6573 GLbitfield mask, GLenum filter) { | 6493 GLbitfield mask, GLenum filter) { |
6574 DCHECK(!ShouldDeferReads() && !ShouldDeferDraws()); | 6494 DCHECK(!ShouldDeferReads() && !ShouldDeferDraws()); |
6575 | 6495 |
6576 if (!CheckBoundFramebuffersValid("glBlitFramebufferCHROMIUM")) { | 6496 if (!CheckBoundFramebuffersValid("glBlitFramebufferCHROMIUM")) { |
6577 return; | 6497 return; |
6578 } | 6498 } |
6579 | 6499 |
6580 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); | 6500 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
6581 ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); | |
6582 BlitFramebufferHelper( | 6501 BlitFramebufferHelper( |
6583 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); | 6502 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
6584 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, | 6503 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, |
6585 state_.enable_flags.scissor_test); | 6504 state_.enable_flags.scissor_test); |
6586 } | 6505 } |
6587 | 6506 |
6588 void GLES2DecoderImpl::EnsureRenderbufferBound() { | 6507 void GLES2DecoderImpl::EnsureRenderbufferBound() { |
6589 if (!state_.bound_renderbuffer_valid) { | 6508 if (!state_.bound_renderbuffer_valid) { |
6590 state_.bound_renderbuffer_valid = true; | 6509 state_.bound_renderbuffer_valid = true; |
6591 glBindRenderbufferEXT(GL_RENDERBUFFER, | 6510 glBindRenderbufferEXT(GL_RENDERBUFFER, |
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7631 const char* filename, int line, const std::string& msg) { | 7550 const char* filename, int line, const std::string& msg) { |
7632 logger_.LogMessage(filename, line, std::string("RENDER WARNING: ") + msg); | 7551 logger_.LogMessage(filename, line, std::string("RENDER WARNING: ") + msg); |
7633 } | 7552 } |
7634 | 7553 |
7635 void GLES2DecoderImpl::PerformanceWarning( | 7554 void GLES2DecoderImpl::PerformanceWarning( |
7636 const char* filename, int line, const std::string& msg) { | 7555 const char* filename, int line, const std::string& msg) { |
7637 logger_.LogMessage(filename, line, | 7556 logger_.LogMessage(filename, line, |
7638 std::string("PERFORMANCE WARNING: ") + msg); | 7557 std::string("PERFORMANCE WARNING: ") + msg); |
7639 } | 7558 } |
7640 | 7559 |
7641 void GLES2DecoderImpl::DoWillUseTexImageIfNeeded( | 7560 void GLES2DecoderImpl::DoCopyTexImage(Texture* texture, |
7642 Texture* texture, GLenum textarget) { | 7561 GLenum textarget, |
| 7562 gfx::GLImage* image) { |
| 7563 // Note: We update the state to COPIED prior to calling CopyTexImage() |
| 7564 // as that allows the GLImage implemenatation to set it back to UNBOUND |
| 7565 // and ensure that CopyTexImage() is called each time the texture is |
| 7566 // used. |
| 7567 texture->SetLevelImage(textarget, 0, image, Texture::COPIED); |
| 7568 bool rv = image->CopyTexImage(textarget); |
| 7569 DCHECK(rv) << "Both BindTexImage() and CopyTexImage() failed"; |
| 7570 } |
| 7571 |
| 7572 void GLES2DecoderImpl::DoCopyTexImageIfNeeded(Texture* texture, |
| 7573 GLenum textarget) { |
7643 // Image is already in use if texture is attached to a framebuffer. | 7574 // Image is already in use if texture is attached to a framebuffer. |
7644 if (texture && !texture->IsAttachedToFramebuffer()) { | 7575 if (texture && !texture->IsAttachedToFramebuffer()) { |
7645 gfx::GLImage* image = texture->GetLevelImage(textarget, 0); | 7576 Texture::ImageState image_state; |
7646 if (image) { | 7577 gfx::GLImage* image = texture->GetLevelImage(textarget, 0, &image_state); |
| 7578 if (image && image_state == Texture::UNBOUND) { |
7647 ScopedGLErrorSuppressor suppressor( | 7579 ScopedGLErrorSuppressor suppressor( |
7648 "GLES2DecoderImpl::DoWillUseTexImageIfNeeded", | 7580 "GLES2DecoderImpl::DoCopyTexImageIfNeeded", GetErrorState()); |
7649 GetErrorState()); | |
7650 glBindTexture(textarget, texture->service_id()); | 7581 glBindTexture(textarget, texture->service_id()); |
7651 image->WillUseTexImage(); | 7582 DoCopyTexImage(texture, textarget, image); |
7652 RestoreCurrentTextureBindings(&state_, textarget); | 7583 RestoreCurrentTextureBindings(&state_, textarget); |
7653 } | 7584 } |
7654 } | 7585 } |
7655 } | |
7656 | |
7657 void GLES2DecoderImpl::DoDidUseTexImageIfNeeded( | |
7658 Texture* texture, GLenum textarget) { | |
7659 // Image is still in use if texture is attached to a framebuffer. | |
7660 if (texture && !texture->IsAttachedToFramebuffer()) { | |
7661 gfx::GLImage* image = texture->GetLevelImage(textarget, 0); | |
7662 if (image) { | |
7663 ScopedGLErrorSuppressor suppressor( | |
7664 "GLES2DecoderImpl::DoDidUseTexImageIfNeeded", | |
7665 GetErrorState()); | |
7666 glBindTexture(textarget, texture->service_id()); | |
7667 image->DidUseTexImage(); | |
7668 RestoreCurrentTextureBindings(&state_, textarget); | |
7669 } | |
7670 } | |
7671 } | 7586 } |
7672 | 7587 |
7673 bool GLES2DecoderImpl::PrepareTexturesForRender() { | 7588 bool GLES2DecoderImpl::PrepareTexturesForRender() { |
7674 DCHECK(state_.current_program.get()); | 7589 DCHECK(state_.current_program.get()); |
7675 if (!texture_manager()->HaveUnrenderableTextures() && | 7590 if (!texture_manager()->HaveUnrenderableTextures() && |
7676 !texture_manager()->HaveImages()) { | 7591 !texture_manager()->HaveImages()) { |
7677 return true; | 7592 return true; |
7678 } | 7593 } |
7679 bool textures_set = false; | 7594 bool textures_set = false; |
7680 const Program::SamplerIndices& sampler_indices = | 7595 const Program::SamplerIndices& sampler_indices = |
(...skipping 24 matching lines...) Expand all Loading... |
7705 std::string("texture bound to texture unit ") + | 7620 std::string("texture bound to texture unit ") + |
7706 base::UintToString(texture_unit_index) + | 7621 base::UintToString(texture_unit_index) + |
7707 " is not renderable. It maybe non-power-of-2 and have" | 7622 " is not renderable. It maybe non-power-of-2 and have" |
7708 " incompatible texture filtering."); | 7623 " incompatible texture filtering."); |
7709 } | 7624 } |
7710 continue; | 7625 continue; |
7711 } | 7626 } |
7712 | 7627 |
7713 if (textarget != GL_TEXTURE_CUBE_MAP) { | 7628 if (textarget != GL_TEXTURE_CUBE_MAP) { |
7714 Texture* texture = texture_ref->texture(); | 7629 Texture* texture = texture_ref->texture(); |
7715 gfx::GLImage* image = texture->GetLevelImage(textarget, 0); | 7630 Texture::ImageState image_state; |
7716 if (image && !texture->IsAttachedToFramebuffer()) { | 7631 gfx::GLImage* image = |
| 7632 texture->GetLevelImage(textarget, 0, &image_state); |
| 7633 if (image && image_state == Texture::UNBOUND && |
| 7634 !texture->IsAttachedToFramebuffer()) { |
7717 ScopedGLErrorSuppressor suppressor( | 7635 ScopedGLErrorSuppressor suppressor( |
7718 "GLES2DecoderImpl::PrepareTexturesForRender", GetErrorState()); | 7636 "GLES2DecoderImpl::PrepareTexturesForRender", GetErrorState()); |
7719 textures_set = true; | 7637 textures_set = true; |
7720 glActiveTexture(GL_TEXTURE0 + texture_unit_index); | 7638 glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
7721 image->WillUseTexImage(); | 7639 DoCopyTexImage(texture, textarget, image); |
7722 continue; | 7640 continue; |
7723 } | 7641 } |
7724 } | 7642 } |
7725 } | 7643 } |
7726 // else: should this be an error? | 7644 // else: should this be an error? |
7727 } | 7645 } |
7728 } | 7646 } |
7729 return !textures_set; | 7647 return !textures_set; |
7730 } | 7648 } |
7731 | 7649 |
(...skipping 14 matching lines...) Expand all Loading... |
7746 if (!texture_ref || !texture_manager()->CanRender(texture_ref)) { | 7664 if (!texture_ref || !texture_manager()->CanRender(texture_ref)) { |
7747 glActiveTexture(GL_TEXTURE0 + texture_unit_index); | 7665 glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
7748 // Get the texture_ref info that was previously bound here. | 7666 // Get the texture_ref info that was previously bound here. |
7749 texture_ref = texture_unit.bind_target == GL_TEXTURE_2D | 7667 texture_ref = texture_unit.bind_target == GL_TEXTURE_2D |
7750 ? texture_unit.bound_texture_2d.get() | 7668 ? texture_unit.bound_texture_2d.get() |
7751 : texture_unit.bound_texture_cube_map.get(); | 7669 : texture_unit.bound_texture_cube_map.get(); |
7752 glBindTexture(texture_unit.bind_target, | 7670 glBindTexture(texture_unit.bind_target, |
7753 texture_ref ? texture_ref->service_id() : 0); | 7671 texture_ref ? texture_ref->service_id() : 0); |
7754 continue; | 7672 continue; |
7755 } | 7673 } |
7756 | |
7757 if (texture_unit.bind_target != GL_TEXTURE_CUBE_MAP) { | |
7758 Texture* texture = texture_ref->texture(); | |
7759 gfx::GLImage* image = | |
7760 texture->GetLevelImage(texture_unit.bind_target, 0); | |
7761 if (image && !texture->IsAttachedToFramebuffer()) { | |
7762 ScopedGLErrorSuppressor suppressor( | |
7763 "GLES2DecoderImpl::RestoreStateForTextures", GetErrorState()); | |
7764 glActiveTexture(GL_TEXTURE0 + texture_unit_index); | |
7765 image->DidUseTexImage(); | |
7766 continue; | |
7767 } | |
7768 } | |
7769 } | 7674 } |
7770 } | 7675 } |
7771 } | 7676 } |
7772 // Set the active texture back to whatever the user had it as. | 7677 // Set the active texture back to whatever the user had it as. |
7773 glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); | 7678 glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); |
7774 } | 7679 } |
7775 | 7680 |
7776 bool GLES2DecoderImpl::ClearUnclearedTextures() { | 7681 bool GLES2DecoderImpl::ClearUnclearedTextures() { |
7777 // Only check if there are some uncleared textures. | 7682 // Only check if there are some uncleared textures. |
7778 if (!texture_manager()->HaveUnsafeTextures()) { | 7683 if (!texture_manager()->HaveUnsafeTextures()) { |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8114 if (!SimulateAttrib0( | 8019 if (!SimulateAttrib0( |
8115 function_name, max_vertex_accessed, &simulated_attrib_0)) { | 8020 function_name, max_vertex_accessed, &simulated_attrib_0)) { |
8116 return error::kNoError; | 8021 return error::kNoError; |
8117 } | 8022 } |
8118 bool simulated_fixed_attribs = false; | 8023 bool simulated_fixed_attribs = false; |
8119 if (SimulateFixedAttribs( | 8024 if (SimulateFixedAttribs( |
8120 function_name, max_vertex_accessed, &simulated_fixed_attribs, | 8025 function_name, max_vertex_accessed, &simulated_fixed_attribs, |
8121 primcount)) { | 8026 primcount)) { |
8122 bool textures_set = !PrepareTexturesForRender(); | 8027 bool textures_set = !PrepareTexturesForRender(); |
8123 ApplyDirtyState(); | 8028 ApplyDirtyState(); |
8124 ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); | |
8125 if (!instanced) { | 8029 if (!instanced) { |
8126 glDrawArrays(mode, first, count); | 8030 glDrawArrays(mode, first, count); |
8127 } else { | 8031 } else { |
8128 glDrawArraysInstancedANGLE(mode, first, count, primcount); | 8032 glDrawArraysInstancedANGLE(mode, first, count, primcount); |
8129 } | 8033 } |
8130 if (textures_set) { | 8034 if (textures_set) { |
8131 RestoreStateForTextures(); | 8035 RestoreStateForTextures(); |
8132 } | 8036 } |
8133 if (simulated_fixed_attribs) { | 8037 if (simulated_fixed_attribs) { |
8134 RestoreStateForSimulatedFixedAttribs(); | 8038 RestoreStateForSimulatedFixedAttribs(); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8251 // TODO(gman): Refactor to hide these details in BufferManager or | 8155 // TODO(gman): Refactor to hide these details in BufferManager or |
8252 // VertexAttribManager. | 8156 // VertexAttribManager. |
8253 const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset); | 8157 const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset); |
8254 bool used_client_side_array = false; | 8158 bool used_client_side_array = false; |
8255 if (element_array_buffer->IsClientSideArray()) { | 8159 if (element_array_buffer->IsClientSideArray()) { |
8256 used_client_side_array = true; | 8160 used_client_side_array = true; |
8257 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | 8161 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
8258 indices = element_array_buffer->GetRange(offset, 0); | 8162 indices = element_array_buffer->GetRange(offset, 0); |
8259 } | 8163 } |
8260 | 8164 |
8261 ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); | |
8262 if (!instanced) { | 8165 if (!instanced) { |
8263 glDrawElements(mode, count, type, indices); | 8166 glDrawElements(mode, count, type, indices); |
8264 } else { | 8167 } else { |
8265 glDrawElementsInstancedANGLE(mode, count, type, indices, primcount); | 8168 glDrawElementsInstancedANGLE(mode, count, type, indices, primcount); |
8266 } | 8169 } |
8267 | 8170 |
8268 if (used_client_side_array) { | 8171 if (used_client_side_array) { |
8269 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, | 8172 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, |
8270 element_array_buffer->service_id()); | 8173 element_array_buffer->service_id()); |
8271 } | 8174 } |
(...skipping 1210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9482 const void* cmd_data) { | 9385 const void* cmd_data) { |
9483 const gles2::cmds::ScheduleOverlayPlaneCHROMIUM& c = | 9386 const gles2::cmds::ScheduleOverlayPlaneCHROMIUM& c = |
9484 *static_cast<const gles2::cmds::ScheduleOverlayPlaneCHROMIUM*>(cmd_data); | 9387 *static_cast<const gles2::cmds::ScheduleOverlayPlaneCHROMIUM*>(cmd_data); |
9485 TextureRef* ref = texture_manager()->GetTexture(c.overlay_texture_id); | 9388 TextureRef* ref = texture_manager()->GetTexture(c.overlay_texture_id); |
9486 if (!ref) { | 9389 if (!ref) { |
9487 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, | 9390 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
9488 "glScheduleOverlayPlaneCHROMIUM", | 9391 "glScheduleOverlayPlaneCHROMIUM", |
9489 "unknown texture"); | 9392 "unknown texture"); |
9490 return error::kNoError; | 9393 return error::kNoError; |
9491 } | 9394 } |
| 9395 Texture::ImageState image_state; |
9492 gfx::GLImage* image = | 9396 gfx::GLImage* image = |
9493 ref->texture()->GetLevelImage(ref->texture()->target(), 0); | 9397 ref->texture()->GetLevelImage(ref->texture()->target(), 0, &image_state); |
9494 if (!image) { | 9398 if (!image || image_state != Texture::BOUND) { |
9495 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, | 9399 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
9496 "glScheduleOverlayPlaneCHROMIUM", | 9400 "glScheduleOverlayPlaneCHROMIUM", |
9497 "unsupported texture format"); | 9401 "unsupported texture format"); |
9498 return error::kNoError; | 9402 return error::kNoError; |
9499 } | 9403 } |
9500 gfx::OverlayTransform transform = GetGFXOverlayTransform(c.plane_transform); | 9404 gfx::OverlayTransform transform = GetGFXOverlayTransform(c.plane_transform); |
9501 if (transform == gfx::OVERLAY_TRANSFORM_INVALID) { | 9405 if (transform == gfx::OVERLAY_TRANSFORM_INVALID) { |
9502 LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, | 9406 LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, |
9503 "glScheduleOverlayPlaneCHROMIUM", | 9407 "glScheduleOverlayPlaneCHROMIUM", |
9504 "invalid transform enum"); | 9408 "invalid transform enum"); |
(...skipping 1583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11088 Clip(x, width, size.width(), ©X, ©Width); | 10992 Clip(x, width, size.width(), ©X, ©Width); |
11089 Clip(y, height, size.height(), ©Y, ©Height); | 10993 Clip(y, height, size.height(), ©Y, ©Height); |
11090 | 10994 |
11091 if (copyX != x || | 10995 if (copyX != x || |
11092 copyY != y || | 10996 copyY != y || |
11093 copyWidth != width || | 10997 copyWidth != width || |
11094 copyHeight != height) { | 10998 copyHeight != height) { |
11095 // some part was clipped so clear the rect. | 10999 // some part was clipped so clear the rect. |
11096 scoped_ptr<char[]> zero(new char[pixels_size]); | 11000 scoped_ptr<char[]> zero(new char[pixels_size]); |
11097 memset(zero.get(), 0, pixels_size); | 11001 memset(zero.get(), 0, pixels_size); |
11098 ScopedModifyPixels modify(texture_ref); | |
11099 glTexImage2D(target, level, internal_format, width, height, border, | 11002 glTexImage2D(target, level, internal_format, width, height, border, |
11100 format, type, zero.get()); | 11003 format, type, zero.get()); |
11101 if (copyHeight > 0 && copyWidth > 0) { | 11004 if (copyHeight > 0 && copyWidth > 0) { |
11102 GLint dx = copyX - x; | 11005 GLint dx = copyX - x; |
11103 GLint dy = copyY - y; | 11006 GLint dy = copyY - y; |
11104 GLint destX = dx; | 11007 GLint destX = dx; |
11105 GLint destY = dy; | 11008 GLint destY = dy; |
11106 glCopyTexSubImage2D(target, level, | 11009 glCopyTexSubImage2D(target, level, |
11107 destX, destY, copyX, copyY, | 11010 destX, destY, copyX, copyY, |
11108 copyWidth, copyHeight); | 11011 copyWidth, copyHeight); |
11109 } | 11012 } |
11110 } else { | 11013 } else { |
11111 ScopedModifyPixels modify(texture_ref); | |
11112 glCopyTexImage2D(target, level, internal_format, | 11014 glCopyTexImage2D(target, level, internal_format, |
11113 copyX, copyY, copyWidth, copyHeight, border); | 11015 copyX, copyY, copyWidth, copyHeight, border); |
11114 } | 11016 } |
11115 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTexImage2D"); | 11017 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTexImage2D"); |
11116 if (error == GL_NO_ERROR) { | 11018 if (error == GL_NO_ERROR) { |
11117 texture_manager()->SetLevelInfo(texture_ref, target, level, internal_format, | 11019 texture_manager()->SetLevelInfo(texture_ref, target, level, internal_format, |
11118 width, height, 1, border, format, | 11020 width, height, 1, border, format, |
11119 type, gfx::Rect(width, height)); | 11021 type, gfx::Rect(width, height)); |
11120 } | 11022 } |
11121 | 11023 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11228 uint32 pixels_size = 0; | 11130 uint32 pixels_size = 0; |
11229 if (!GLES2Util::ComputeImageDataSizes( | 11131 if (!GLES2Util::ComputeImageDataSizes( |
11230 width, height, 1, format, type, state_.unpack_alignment, &pixels_size, | 11132 width, height, 1, format, type, state_.unpack_alignment, &pixels_size, |
11231 NULL, NULL)) { | 11133 NULL, NULL)) { |
11232 LOCAL_SET_GL_ERROR( | 11134 LOCAL_SET_GL_ERROR( |
11233 GL_INVALID_VALUE, "glCopyTexSubImage2D", "dimensions too large"); | 11135 GL_INVALID_VALUE, "glCopyTexSubImage2D", "dimensions too large"); |
11234 return; | 11136 return; |
11235 } | 11137 } |
11236 scoped_ptr<char[]> zero(new char[pixels_size]); | 11138 scoped_ptr<char[]> zero(new char[pixels_size]); |
11237 memset(zero.get(), 0, pixels_size); | 11139 memset(zero.get(), 0, pixels_size); |
11238 ScopedModifyPixels modify(texture_ref); | |
11239 glTexSubImage2D( | 11140 glTexSubImage2D( |
11240 target, level, xoffset, yoffset, width, height, | 11141 target, level, xoffset, yoffset, width, height, |
11241 format, type, zero.get()); | 11142 format, type, zero.get()); |
11242 } | 11143 } |
11243 | 11144 |
11244 if (copyHeight > 0 && copyWidth > 0) { | 11145 if (copyHeight > 0 && copyWidth > 0) { |
11245 GLint dx = copyX - x; | 11146 GLint dx = copyX - x; |
11246 GLint dy = copyY - y; | 11147 GLint dy = copyY - y; |
11247 GLint destX = xoffset + dx; | 11148 GLint destX = xoffset + dx; |
11248 GLint destY = yoffset + dy; | 11149 GLint destY = yoffset + dy; |
11249 ScopedModifyPixels modify(texture_ref); | |
11250 glCopyTexSubImage2D(target, level, | 11150 glCopyTexSubImage2D(target, level, |
11251 destX, destY, copyX, copyY, | 11151 destX, destY, copyX, copyY, |
11252 copyWidth, copyHeight); | 11152 copyWidth, copyHeight); |
11253 } | 11153 } |
11254 | 11154 |
11255 // This may be a slow command. Exit command processing to allow for | 11155 // This may be a slow command. Exit command processing to allow for |
11256 // context preemption and GPU watchdog checks. | 11156 // context preemption and GPU watchdog checks. |
11257 ExitCommandProcessingEarly(); | 11157 ExitCommandProcessingEarly(); |
11258 } | 11158 } |
11259 | 11159 |
(...skipping 1962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13222 | 13122 |
13223 texture_manager()->SetLevelInfo( | 13123 texture_manager()->SetLevelInfo( |
13224 dest_texture_ref, GL_TEXTURE_2D, 0, internal_format, source_width, | 13124 dest_texture_ref, GL_TEXTURE_2D, 0, internal_format, source_width, |
13225 source_height, 1, 0, internal_format, dest_type, | 13125 source_height, 1, 0, internal_format, dest_type, |
13226 gfx::Rect(source_width, source_height)); | 13126 gfx::Rect(source_width, source_height)); |
13227 } else { | 13127 } else { |
13228 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, | 13128 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, |
13229 true); | 13129 true); |
13230 } | 13130 } |
13231 | 13131 |
13232 ScopedModifyPixels modify(dest_texture_ref); | 13132 // Try using GLImage::CopyTexImage when possible. |
13233 | |
13234 // Try using GLImage::CopyTexSubImage when possible. | |
13235 bool unpack_premultiply_alpha_change = | 13133 bool unpack_premultiply_alpha_change = |
13236 (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0; | 13134 (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0; |
13237 if (image && !unpack_flip_y && !unpack_premultiply_alpha_change) { | 13135 if (image && !unpack_flip_y && !unpack_premultiply_alpha_change) { |
13238 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); | 13136 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
13239 if (image->CopyTexSubImage(GL_TEXTURE_2D, gfx::Point(0, 0), | 13137 if (image->CopyTexImage(GL_TEXTURE_2D)) |
13240 gfx::Rect(0, 0, source_width, source_height))) { | |
13241 return; | 13138 return; |
13242 } | |
13243 } | 13139 } |
13244 | 13140 |
13245 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); | 13141 DoCopyTexImageIfNeeded(source_texture, source_texture->target()); |
13246 | 13142 |
13247 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix | 13143 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix |
13248 // before presenting. | 13144 // before presenting. |
13249 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { | 13145 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { |
13250 // TODO(hkuang): get the StreamTexture transform matrix in GPU process | 13146 // TODO(hkuang): get the StreamTexture transform matrix in GPU process |
13251 // instead of using kIdentityMatrix crbug.com/226218. | 13147 // instead of using kIdentityMatrix crbug.com/226218. |
13252 copy_texture_CHROMIUM_->DoCopyTextureWithTransform( | 13148 copy_texture_CHROMIUM_->DoCopyTextureWithTransform( |
13253 this, source_texture->target(), source_texture->service_id(), | 13149 this, source_texture->target(), source_texture->service_id(), |
13254 dest_texture->service_id(), source_width, source_height, | 13150 dest_texture->service_id(), source_width, source_height, |
13255 unpack_flip_y == GL_TRUE, | 13151 unpack_flip_y == GL_TRUE, |
13256 unpack_premultiply_alpha == GL_TRUE, | 13152 unpack_premultiply_alpha == GL_TRUE, |
13257 unpack_unmultiply_alpha == GL_TRUE, | 13153 unpack_unmultiply_alpha == GL_TRUE, |
13258 kIdentityMatrix); | 13154 kIdentityMatrix); |
13259 } else { | 13155 } else { |
13260 copy_texture_CHROMIUM_->DoCopyTexture( | 13156 copy_texture_CHROMIUM_->DoCopyTexture( |
13261 this, source_texture->target(), source_texture->service_id(), | 13157 this, source_texture->target(), source_texture->service_id(), |
13262 source_internal_format, dest_texture->service_id(), internal_format, | 13158 source_internal_format, dest_texture->service_id(), internal_format, |
13263 source_width, source_height, | 13159 source_width, source_height, |
13264 unpack_flip_y == GL_TRUE, | 13160 unpack_flip_y == GL_TRUE, |
13265 unpack_premultiply_alpha == GL_TRUE, | 13161 unpack_premultiply_alpha == GL_TRUE, |
13266 unpack_unmultiply_alpha == GL_TRUE); | 13162 unpack_unmultiply_alpha == GL_TRUE); |
13267 } | 13163 } |
13268 | |
13269 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); | |
13270 } | 13164 } |
13271 | 13165 |
13272 void GLES2DecoderImpl::DoCopySubTextureCHROMIUM( | 13166 void GLES2DecoderImpl::DoCopySubTextureCHROMIUM( |
13273 GLenum target, | 13167 GLenum target, |
13274 GLuint source_id, | 13168 GLuint source_id, |
13275 GLuint dest_id, | 13169 GLuint dest_id, |
13276 GLint xoffset, | 13170 GLint xoffset, |
13277 GLint yoffset, | 13171 GLint yoffset, |
13278 GLint x, | 13172 GLint x, |
13279 GLint y, | 13173 GLint y, |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13392 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopySubTextureCHROMIUM", | 13286 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopySubTextureCHROMIUM", |
13393 "destination texture dimensions too big"); | 13287 "destination texture dimensions too big"); |
13394 return; | 13288 return; |
13395 } | 13289 } |
13396 } | 13290 } |
13397 } else { | 13291 } else { |
13398 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, | 13292 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, |
13399 true); | 13293 true); |
13400 } | 13294 } |
13401 | 13295 |
13402 ScopedModifyPixels modify(dest_texture_ref); | |
13403 | |
13404 // Try using GLImage::CopyTexSubImage when possible. | 13296 // Try using GLImage::CopyTexSubImage when possible. |
13405 bool unpack_premultiply_alpha_change = | 13297 bool unpack_premultiply_alpha_change = |
13406 (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0; | 13298 (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0; |
13407 if (image && !unpack_flip_y && !unpack_premultiply_alpha_change) { | 13299 if (image && !unpack_flip_y && !unpack_premultiply_alpha_change) { |
13408 ScopedTextureBinder binder( | 13300 ScopedTextureBinder binder( |
13409 &state_, dest_texture->service_id(), GL_TEXTURE_2D); | 13301 &state_, dest_texture->service_id(), GL_TEXTURE_2D); |
13410 if (image->CopyTexSubImage(GL_TEXTURE_2D, gfx::Point(xoffset, yoffset), | 13302 if (image->CopyTexSubImage(GL_TEXTURE_2D, gfx::Point(xoffset, yoffset), |
13411 gfx::Rect(x, y, width, height))) { | 13303 gfx::Rect(x, y, width, height))) { |
13412 return; | 13304 return; |
13413 } | 13305 } |
13414 } | 13306 } |
13415 | 13307 |
13416 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); | 13308 DoCopyTexImageIfNeeded(source_texture, source_texture->target()); |
13417 | 13309 |
13418 // TODO(hkuang): get the StreamTexture transform matrix in GPU process. | 13310 // TODO(hkuang): get the StreamTexture transform matrix in GPU process. |
13419 // crbug.com/226218. | 13311 // crbug.com/226218. |
13420 copy_texture_CHROMIUM_->DoCopySubTexture( | 13312 copy_texture_CHROMIUM_->DoCopySubTexture( |
13421 this, source_texture->target(), source_texture->service_id(), | 13313 this, source_texture->target(), source_texture->service_id(), |
13422 source_internal_format, dest_texture->service_id(), dest_internal_format, | 13314 source_internal_format, dest_texture->service_id(), dest_internal_format, |
13423 xoffset, yoffset, x, y, width, height, dest_width, dest_height, | 13315 xoffset, yoffset, x, y, width, height, dest_width, dest_height, |
13424 source_width, source_height, | 13316 source_width, source_height, |
13425 unpack_flip_y == GL_TRUE, | 13317 unpack_flip_y == GL_TRUE, |
13426 unpack_premultiply_alpha == GL_TRUE, | 13318 unpack_premultiply_alpha == GL_TRUE, |
13427 unpack_unmultiply_alpha == GL_TRUE); | 13319 unpack_unmultiply_alpha == GL_TRUE); |
13428 | |
13429 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); | |
13430 } | 13320 } |
13431 | 13321 |
13432 void GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM(GLenum target, | 13322 void GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM(GLenum target, |
13433 GLuint source_id, | 13323 GLuint source_id, |
13434 GLuint dest_id) { | 13324 GLuint dest_id) { |
13435 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM"); | 13325 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM"); |
13436 | 13326 |
13437 TextureRef* source_texture_ref = GetTexture(source_id); | 13327 TextureRef* source_texture_ref = GetTexture(source_id); |
13438 TextureRef* dest_texture_ref = GetTexture(dest_id); | 13328 TextureRef* dest_texture_ref = GetTexture(dest_id); |
13439 Texture* source_texture = source_texture_ref->texture(); | 13329 Texture* source_texture = source_texture_ref->texture(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13505 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, | 13395 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, |
13506 source_texture->target(), 0)) { | 13396 source_texture->target(), 0)) { |
13507 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCompressedCopyTextureCHROMIUM", | 13397 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCompressedCopyTextureCHROMIUM", |
13508 "dimensions too big"); | 13398 "dimensions too big"); |
13509 return; | 13399 return; |
13510 } | 13400 } |
13511 | 13401 |
13512 ScopedTextureBinder binder( | 13402 ScopedTextureBinder binder( |
13513 &state_, dest_texture->service_id(), GL_TEXTURE_2D); | 13403 &state_, dest_texture->service_id(), GL_TEXTURE_2D); |
13514 | 13404 |
13515 ScopedModifyPixels modify(dest_texture_ref); | |
13516 | |
13517 // Try using GLImage::CopyTexImage when possible. | 13405 // Try using GLImage::CopyTexImage when possible. |
13518 if (image) { | 13406 if (image) { |
13519 GLenum dest_type = 0; | 13407 GLenum dest_type = 0; |
13520 GLenum dest_internal_format = 0; | 13408 GLenum dest_internal_format = 0; |
13521 int dest_width = 0; | 13409 int dest_width = 0; |
13522 int dest_height = 0; | 13410 int dest_height = 0; |
13523 bool dest_level_defined = dest_texture->GetLevelSize( | 13411 bool dest_level_defined = dest_texture->GetLevelSize( |
13524 GL_TEXTURE_2D, 0, &dest_width, &dest_height, nullptr); | 13412 GL_TEXTURE_2D, 0, &dest_width, &dest_height, nullptr); |
13525 | 13413 |
13526 if (dest_level_defined) { | 13414 if (dest_level_defined) { |
(...skipping 25 matching lines...) Expand all Loading... |
13552 | 13440 |
13553 texture_manager()->SetLevelInfo( | 13441 texture_manager()->SetLevelInfo( |
13554 dest_texture_ref, GL_TEXTURE_2D, 0, source_internal_format, | 13442 dest_texture_ref, GL_TEXTURE_2D, 0, source_internal_format, |
13555 source_width, source_height, 1, 0, source_internal_format, | 13443 source_width, source_height, 1, 0, source_internal_format, |
13556 source_type, gfx::Rect(source_width, source_height)); | 13444 source_type, gfx::Rect(source_width, source_height)); |
13557 } else { | 13445 } else { |
13558 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, | 13446 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, |
13559 true); | 13447 true); |
13560 } | 13448 } |
13561 | 13449 |
13562 if (image->CopyTexSubImage(GL_TEXTURE_2D, gfx::Point(0, 0), | 13450 if (image->CopyTexImage(GL_TEXTURE_2D)) |
13563 gfx::Rect(0, 0, source_width, source_height))) { | |
13564 return; | 13451 return; |
13565 } | |
13566 } | 13452 } |
13567 | 13453 |
13568 TRACE_EVENT0( | 13454 TRACE_EVENT0( |
13569 "gpu", | 13455 "gpu", |
13570 "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM, fallback"); | 13456 "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM, fallback"); |
13571 | 13457 |
13572 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); | 13458 DoCopyTexImageIfNeeded(source_texture, source_texture->target()); |
13573 | 13459 |
13574 // As a fallback, copy into a non-compressed GL_RGBA texture. | 13460 // As a fallback, copy into a non-compressed GL_RGBA texture. |
13575 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedCopyTextureCHROMIUM"); | 13461 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedCopyTextureCHROMIUM"); |
13576 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, source_width, source_height, | 13462 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, source_width, source_height, |
13577 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 13463 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
13578 GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedCopyTextureCHROMIUM"); | 13464 GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedCopyTextureCHROMIUM"); |
13579 if (error != GL_NO_ERROR) { | 13465 if (error != GL_NO_ERROR) { |
13580 RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D); | 13466 RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D); |
13581 return; | 13467 return; |
13582 } | 13468 } |
(...skipping 11 matching lines...) Expand all Loading... |
13594 copy_texture_CHROMIUM_->DoCopyTextureWithTransform( | 13480 copy_texture_CHROMIUM_->DoCopyTextureWithTransform( |
13595 this, source_texture->target(), source_texture->service_id(), | 13481 this, source_texture->target(), source_texture->service_id(), |
13596 dest_texture->service_id(), source_width, source_height, | 13482 dest_texture->service_id(), source_width, source_height, |
13597 false, false, false, kIdentityMatrix); | 13483 false, false, false, kIdentityMatrix); |
13598 } else { | 13484 } else { |
13599 copy_texture_CHROMIUM_->DoCopyTexture( | 13485 copy_texture_CHROMIUM_->DoCopyTexture( |
13600 this, source_texture->target(), source_texture->service_id(), | 13486 this, source_texture->target(), source_texture->service_id(), |
13601 source_internal_format, dest_texture->service_id(), GL_RGBA, | 13487 source_internal_format, dest_texture->service_id(), GL_RGBA, |
13602 source_width, source_height, false, false, false); | 13488 source_width, source_height, false, false, false); |
13603 } | 13489 } |
13604 | |
13605 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); | |
13606 } | 13490 } |
13607 | 13491 |
13608 void GLES2DecoderImpl::DoCompressedCopySubTextureCHROMIUM(GLenum target, | 13492 void GLES2DecoderImpl::DoCompressedCopySubTextureCHROMIUM(GLenum target, |
13609 GLuint source_id, | 13493 GLuint source_id, |
13610 GLuint dest_id, | 13494 GLuint dest_id, |
13611 GLint xoffset, | 13495 GLint xoffset, |
13612 GLint yoffset, | 13496 GLint yoffset, |
13613 GLint x, | 13497 GLint x, |
13614 GLint y, | 13498 GLint y, |
13615 GLsizei width, | 13499 GLsizei width, |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13744 } | 13628 } |
13745 } | 13629 } |
13746 } else { | 13630 } else { |
13747 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, | 13631 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, |
13748 true); | 13632 true); |
13749 } | 13633 } |
13750 | 13634 |
13751 ScopedTextureBinder binder( | 13635 ScopedTextureBinder binder( |
13752 &state_, dest_texture->service_id(), GL_TEXTURE_2D); | 13636 &state_, dest_texture->service_id(), GL_TEXTURE_2D); |
13753 | 13637 |
13754 ScopedModifyPixels modify(dest_texture_ref); | |
13755 | |
13756 // Try using GLImage::CopyTexSubImage when possible. | 13638 // Try using GLImage::CopyTexSubImage when possible. |
13757 if (image) { | 13639 if (image && |
13758 if (image->CopyTexSubImage(GL_TEXTURE_2D, gfx::Point(xoffset, yoffset), | 13640 image->CopyTexSubImage(GL_TEXTURE_2D, gfx::Point(xoffset, yoffset), |
13759 gfx::Rect(x, y, width, height))) { | 13641 gfx::Rect(x, y, width, height))) { |
13760 return; | 13642 return; |
13761 } | |
13762 } | 13643 } |
13763 | 13644 |
13764 TRACE_EVENT0( | 13645 TRACE_EVENT0( |
13765 "gpu", | 13646 "gpu", |
13766 "GLES2DecoderImpl::DoCompressedCopySubTextureCHROMIUM, fallback"); | 13647 "GLES2DecoderImpl::DoCompressedCopySubTextureCHROMIUM, fallback"); |
13767 | 13648 |
13768 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); | 13649 DoCopyTexImageIfNeeded(source_texture, source_texture->target()); |
13769 | 13650 |
13770 // As a fallback, copy into a non-compressed GL_RGBA texture. | 13651 // As a fallback, copy into a non-compressed GL_RGBA texture. |
13771 if (dest_internal_format != GL_RGBA) { | 13652 if (dest_internal_format != GL_RGBA) { |
13772 // To preserve the contents of the original destination texture we must | 13653 // To preserve the contents of the original destination texture we must |
13773 // first copy the original destination texture to a temporary storage, then | 13654 // first copy the original destination texture to a temporary storage, then |
13774 // copy it back to the original destination texture. | 13655 // copy it back to the original destination texture. |
13775 GLuint tmp_service_id; | 13656 GLuint tmp_service_id; |
13776 glGenTextures(1, &tmp_service_id); | 13657 glGenTextures(1, &tmp_service_id); |
13777 DCHECK_NE(0u, tmp_service_id); | 13658 DCHECK_NE(0u, tmp_service_id); |
13778 | 13659 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13811 glDeleteTextures(1, &tmp_service_id); | 13692 glDeleteTextures(1, &tmp_service_id); |
13812 } | 13693 } |
13813 | 13694 |
13814 // TODO(hkuang): get the StreamTexture transform matrix in GPU process. | 13695 // TODO(hkuang): get the StreamTexture transform matrix in GPU process. |
13815 // crbug.com/226218. | 13696 // crbug.com/226218. |
13816 copy_texture_CHROMIUM_->DoCopySubTexture( | 13697 copy_texture_CHROMIUM_->DoCopySubTexture( |
13817 this, source_texture->target(), source_texture->service_id(), | 13698 this, source_texture->target(), source_texture->service_id(), |
13818 source_internal_format, dest_texture->service_id(), GL_RGBA, | 13699 source_internal_format, dest_texture->service_id(), GL_RGBA, |
13819 xoffset, yoffset, x, y, width, height, dest_width, dest_height, | 13700 xoffset, yoffset, x, y, width, height, dest_width, dest_height, |
13820 source_width, source_height, false, false, false); | 13701 source_width, source_height, false, false, false); |
13821 | |
13822 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); | |
13823 } | 13702 } |
13824 | 13703 |
13825 void GLES2DecoderImpl::DoTexStorage2DEXT( | 13704 void GLES2DecoderImpl::DoTexStorage2DEXT( |
13826 GLenum target, | 13705 GLenum target, |
13827 GLint levels, | 13706 GLint levels, |
13828 GLenum internal_format, | 13707 GLenum internal_format, |
13829 GLsizei width, | 13708 GLsizei width, |
13830 GLsizei height) { | 13709 GLsizei height) { |
13831 TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoTexStorage2DEXT", | 13710 TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoTexStorage2DEXT", |
13832 "width", width, "height", height); | 13711 "width", width, "height", height); |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14225 // accidents. | 14104 // accidents. |
14226 TextureRef* texture_ref = | 14105 TextureRef* texture_ref = |
14227 texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); | 14106 texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
14228 if (!texture_ref) { | 14107 if (!texture_ref) { |
14229 LOCAL_SET_GL_ERROR( | 14108 LOCAL_SET_GL_ERROR( |
14230 GL_INVALID_OPERATION, | 14109 GL_INVALID_OPERATION, |
14231 "glBindTexImage2DCHROMIUM", "no texture bound"); | 14110 "glBindTexImage2DCHROMIUM", "no texture bound"); |
14232 return; | 14111 return; |
14233 } | 14112 } |
14234 | 14113 |
14235 gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); | 14114 gfx::GLImage* image = image_manager()->LookupImage(image_id); |
14236 if (!gl_image) { | 14115 if (!image) { |
14237 LOCAL_SET_GL_ERROR( | 14116 LOCAL_SET_GL_ERROR( |
14238 GL_INVALID_OPERATION, | 14117 GL_INVALID_OPERATION, |
14239 "glBindTexImage2DCHROMIUM", "no image found with the given ID"); | 14118 "glBindTexImage2DCHROMIUM", "no image found with the given ID"); |
14240 return; | 14119 return; |
14241 } | 14120 } |
14242 | 14121 |
| 14122 Texture::ImageState image_state = Texture::UNBOUND; |
| 14123 |
14243 { | 14124 { |
14244 ScopedGLErrorSuppressor suppressor( | 14125 ScopedGLErrorSuppressor suppressor( |
14245 "GLES2DecoderImpl::DoBindTexImage2DCHROMIUM", GetErrorState()); | 14126 "GLES2DecoderImpl::DoBindTexImage2DCHROMIUM", GetErrorState()); |
14246 if (!gl_image->BindTexImage(target)) { | 14127 |
14247 LOCAL_SET_GL_ERROR( | 14128 // Note: We fallback to using CopyTexImage() before the texture is used |
14248 GL_INVALID_OPERATION, | 14129 // when BindTexImage() fails. |
14249 "glBindTexImage2DCHROMIUM", "fail to bind image with the given ID"); | 14130 if (image->BindTexImage(target)) |
14250 return; | 14131 image_state = Texture::BOUND; |
14251 } | |
14252 } | 14132 } |
14253 | 14133 |
14254 gfx::Size size = gl_image->GetSize(); | 14134 gfx::Size size = image->GetSize(); |
| 14135 GLenum internalformat = image->GetInternalFormat(); |
14255 texture_manager()->SetLevelInfo( | 14136 texture_manager()->SetLevelInfo( |
14256 texture_ref, target, 0, gl_image->GetInternalFormat(), size.width(), | 14137 texture_ref, target, 0, internalformat, size.width(), size.height(), 1, 0, |
14257 size.height(), 1, 0, gl_image->GetInternalFormat(), GL_UNSIGNED_BYTE, | 14138 internalformat, GL_UNSIGNED_BYTE, gfx::Rect(size)); |
14258 gfx::Rect(size)); | 14139 texture_manager()->SetLevelImage(texture_ref, target, 0, image, image_state); |
14259 texture_manager()->SetLevelImage(texture_ref, target, 0, gl_image); | |
14260 } | 14140 } |
14261 | 14141 |
14262 void GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM( | 14142 void GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM( |
14263 GLenum target, GLint image_id) { | 14143 GLenum target, GLint image_id) { |
14264 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM"); | 14144 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM"); |
14265 | 14145 |
14266 // Default target might be conceptually valid, but disallow it to avoid | 14146 // Default target might be conceptually valid, but disallow it to avoid |
14267 // accidents. | 14147 // accidents. |
14268 TextureRef* texture_ref = | 14148 TextureRef* texture_ref = |
14269 texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); | 14149 texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
14270 if (!texture_ref) { | 14150 if (!texture_ref) { |
14271 LOCAL_SET_GL_ERROR( | 14151 LOCAL_SET_GL_ERROR( |
14272 GL_INVALID_OPERATION, | 14152 GL_INVALID_OPERATION, |
14273 "glReleaseTexImage2DCHROMIUM", "no texture bound"); | 14153 "glReleaseTexImage2DCHROMIUM", "no texture bound"); |
14274 return; | 14154 return; |
14275 } | 14155 } |
14276 | 14156 |
14277 gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); | 14157 gfx::GLImage* image = image_manager()->LookupImage(image_id); |
14278 if (!gl_image) { | 14158 if (!image) { |
14279 LOCAL_SET_GL_ERROR( | 14159 LOCAL_SET_GL_ERROR( |
14280 GL_INVALID_OPERATION, | 14160 GL_INVALID_OPERATION, |
14281 "glReleaseTexImage2DCHROMIUM", "no image found with the given ID"); | 14161 "glReleaseTexImage2DCHROMIUM", "no image found with the given ID"); |
14282 return; | 14162 return; |
14283 } | 14163 } |
14284 | 14164 |
| 14165 Texture::ImageState image_state; |
| 14166 |
14285 // Do nothing when image is not currently bound. | 14167 // Do nothing when image is not currently bound. |
14286 if (texture_ref->texture()->GetLevelImage(target, 0) != gl_image) | 14168 if (texture_ref->texture()->GetLevelImage(target, 0, &image_state) != image) |
14287 return; | 14169 return; |
14288 | 14170 |
14289 { | 14171 if (image_state == Texture::BOUND) { |
14290 ScopedGLErrorSuppressor suppressor( | 14172 ScopedGLErrorSuppressor suppressor( |
14291 "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM", GetErrorState()); | 14173 "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM", GetErrorState()); |
14292 gl_image->ReleaseTexImage(target); | 14174 |
| 14175 image->ReleaseTexImage(target); |
| 14176 texture_manager()->SetLevelInfo(texture_ref, target, 0, GL_RGBA, 0, 0, 1, 0, |
| 14177 GL_RGBA, GL_UNSIGNED_BYTE, gfx::Rect()); |
14293 } | 14178 } |
14294 | 14179 |
14295 texture_manager()->SetLevelInfo( | 14180 texture_manager()->SetLevelImage(texture_ref, target, 0, nullptr, |
14296 texture_ref, target, 0, gl_image->GetInternalFormat(), 0, 0, 1, 0, | 14181 Texture::UNBOUND); |
14297 gl_image->GetInternalFormat(), GL_UNSIGNED_BYTE, gfx::Rect()); | |
14298 } | 14182 } |
14299 | 14183 |
14300 error::Error GLES2DecoderImpl::HandleTraceBeginCHROMIUM( | 14184 error::Error GLES2DecoderImpl::HandleTraceBeginCHROMIUM( |
14301 uint32 immediate_data_size, | 14185 uint32 immediate_data_size, |
14302 const void* cmd_data) { | 14186 const void* cmd_data) { |
14303 const gles2::cmds::TraceBeginCHROMIUM& c = | 14187 const gles2::cmds::TraceBeginCHROMIUM& c = |
14304 *static_cast<const gles2::cmds::TraceBeginCHROMIUM*>(cmd_data); | 14188 *static_cast<const gles2::cmds::TraceBeginCHROMIUM*>(cmd_data); |
14305 Bucket* category_bucket = GetBucket(c.category_bucket_id); | 14189 Bucket* category_bucket = GetBucket(c.category_bucket_id); |
14306 Bucket* name_bucket = GetBucket(c.name_bucket_id); | 14190 Bucket* name_bucket = GetBucket(c.name_bucket_id); |
14307 if (!category_bucket || category_bucket->size() == 0 || | 14191 if (!category_bucket || category_bucket->size() == 0 || |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14642 // the contexts in the share group. | 14526 // the contexts in the share group. |
14643 LOG(ERROR) << "glUnmapBuffer unexpectedly returned GL_FALSE"; | 14527 LOG(ERROR) << "glUnmapBuffer unexpectedly returned GL_FALSE"; |
14644 // Need to lose current context before broadcasting! | 14528 // Need to lose current context before broadcasting! |
14645 MarkContextLost(error::kGuilty); | 14529 MarkContextLost(error::kGuilty); |
14646 group_->LoseContexts(error::kInnocent); | 14530 group_->LoseContexts(error::kInnocent); |
14647 return error::kLostContext; | 14531 return error::kLostContext; |
14648 } | 14532 } |
14649 return error::kNoError; | 14533 return error::kNoError; |
14650 } | 14534 } |
14651 | 14535 |
14652 void GLES2DecoderImpl::OnTextureRefDetachedFromFramebuffer( | |
14653 TextureRef* texture_ref) { | |
14654 Texture* texture = texture_ref->texture(); | |
14655 DoDidUseTexImageIfNeeded(texture, texture->target()); | |
14656 } | |
14657 | |
14658 // Note that GL_LOST_CONTEXT is specific to GLES. | 14536 // Note that GL_LOST_CONTEXT is specific to GLES. |
14659 // For desktop GL we have to query the reset status proactively. | 14537 // For desktop GL we have to query the reset status proactively. |
14660 void GLES2DecoderImpl::OnContextLostError() { | 14538 void GLES2DecoderImpl::OnContextLostError() { |
14661 if (!WasContextLost()) { | 14539 if (!WasContextLost()) { |
14662 // Need to lose current context before broadcasting! | 14540 // Need to lose current context before broadcasting! |
14663 CheckResetStatus(); | 14541 CheckResetStatus(); |
14664 group_->LoseContexts(error::kUnknown); | 14542 group_->LoseContexts(error::kUnknown); |
14665 reset_by_robustness_extension_ = true; | 14543 reset_by_robustness_extension_ = true; |
14666 } | 14544 } |
14667 } | 14545 } |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15102 return error::kNoError; | 14980 return error::kNoError; |
15103 } | 14981 } |
15104 | 14982 |
15105 // Include the auto-generated part of this file. We split this because it means | 14983 // Include the auto-generated part of this file. We split this because it means |
15106 // we can easily edit the non-auto generated parts right here in this file | 14984 // we can easily edit the non-auto generated parts right here in this file |
15107 // instead of having to edit some template or the code generator. | 14985 // instead of having to edit some template or the code generator. |
15108 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 14986 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
15109 | 14987 |
15110 } // namespace gles2 | 14988 } // namespace gles2 |
15111 } // namespace gpu | 14989 } // namespace gpu |
OLD | NEW |