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