| 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 <list> | 10 #include <list> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 #include "gpu/command_buffer/service/gpu_tracer.h" | 46 #include "gpu/command_buffer/service/gpu_tracer.h" |
| 47 #include "gpu/command_buffer/service/image_manager.h" | 47 #include "gpu/command_buffer/service/image_manager.h" |
| 48 #include "gpu/command_buffer/service/mailbox_manager.h" | 48 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 49 #include "gpu/command_buffer/service/memory_tracking.h" | 49 #include "gpu/command_buffer/service/memory_tracking.h" |
| 50 #include "gpu/command_buffer/service/program_manager.h" | 50 #include "gpu/command_buffer/service/program_manager.h" |
| 51 #include "gpu/command_buffer/service/query_manager.h" | 51 #include "gpu/command_buffer/service/query_manager.h" |
| 52 #include "gpu/command_buffer/service/renderbuffer_manager.h" | 52 #include "gpu/command_buffer/service/renderbuffer_manager.h" |
| 53 #include "gpu/command_buffer/service/shader_manager.h" | 53 #include "gpu/command_buffer/service/shader_manager.h" |
| 54 #include "gpu/command_buffer/service/shader_translator.h" | 54 #include "gpu/command_buffer/service/shader_translator.h" |
| 55 #include "gpu/command_buffer/service/shader_translator_cache.h" | 55 #include "gpu/command_buffer/service/shader_translator_cache.h" |
| 56 #include "gpu/command_buffer/service/stream_texture.h" | |
| 57 #include "gpu/command_buffer/service/stream_texture_manager.h" | |
| 58 #include "gpu/command_buffer/service/texture_manager.h" | 56 #include "gpu/command_buffer/service/texture_manager.h" |
| 59 #include "gpu/command_buffer/service/vertex_array_manager.h" | 57 #include "gpu/command_buffer/service/vertex_array_manager.h" |
| 60 #include "gpu/command_buffer/service/vertex_attrib_manager.h" | 58 #include "gpu/command_buffer/service/vertex_attrib_manager.h" |
| 61 #include "ui/gl/gl_bindings.h" | 59 #include "ui/gl/gl_bindings.h" |
| 62 #include "ui/gl/gl_fence.h" | 60 #include "ui/gl/gl_fence.h" |
| 63 #include "ui/gl/gl_image.h" | 61 #include "ui/gl/gl_image.h" |
| 64 #include "ui/gl/gl_implementation.h" | 62 #include "ui/gl/gl_implementation.h" |
| 65 #include "ui/gl/gl_surface.h" | 63 #include "ui/gl/gl_surface.h" |
| 66 | 64 |
| 67 #if defined(OS_MACOSX) | 65 #if defined(OS_MACOSX) |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 public: | 286 public: |
| 289 explicit ScopedGLErrorSuppressor( | 287 explicit ScopedGLErrorSuppressor( |
| 290 const char* function_name, GLES2DecoderImpl* decoder); | 288 const char* function_name, GLES2DecoderImpl* decoder); |
| 291 ~ScopedGLErrorSuppressor(); | 289 ~ScopedGLErrorSuppressor(); |
| 292 private: | 290 private: |
| 293 const char* function_name_; | 291 const char* function_name_; |
| 294 GLES2DecoderImpl* decoder_; | 292 GLES2DecoderImpl* decoder_; |
| 295 DISALLOW_COPY_AND_ASSIGN(ScopedGLErrorSuppressor); | 293 DISALLOW_COPY_AND_ASSIGN(ScopedGLErrorSuppressor); |
| 296 }; | 294 }; |
| 297 | 295 |
| 298 // Temporarily changes a decoder's bound 2D texture and restore it when this | 296 // Temporarily changes a decoder's bound texture and restore it when this |
| 299 // object goes out of scope. Also temporarily switches to using active texture | 297 // object goes out of scope. Also temporarily switches to using active texture |
| 300 // unit zero in case the client has changed that to something invalid. | 298 // unit zero in case the client has changed that to something invalid. |
| 301 class ScopedTexture2DBinder { | 299 class ScopedTextureBinder { |
| 302 public: | 300 public: |
| 303 ScopedTexture2DBinder(GLES2DecoderImpl* decoder, GLuint id); | 301 ScopedTextureBinder(GLES2DecoderImpl* decoder, GLenum target, GLuint id); |
| 304 ~ScopedTexture2DBinder(); | 302 ~ScopedTextureBinder(); |
| 305 | 303 |
| 306 private: | 304 private: |
| 307 GLES2DecoderImpl* decoder_; | 305 GLES2DecoderImpl* decoder_; |
| 308 DISALLOW_COPY_AND_ASSIGN(ScopedTexture2DBinder); | 306 DISALLOW_COPY_AND_ASSIGN(ScopedTextureBinder); |
| 309 }; | 307 }; |
| 310 | 308 |
| 311 // Temporarily changes a decoder's bound render buffer and restore it when this | 309 // Temporarily changes a decoder's bound render buffer and restore it when this |
| 312 // object goes out of scope. | 310 // object goes out of scope. |
| 313 class ScopedRenderBufferBinder { | 311 class ScopedRenderBufferBinder { |
| 314 public: | 312 public: |
| 315 ScopedRenderBufferBinder(GLES2DecoderImpl* decoder, GLuint id); | 313 ScopedRenderBufferBinder(GLES2DecoderImpl* decoder, GLuint id); |
| 316 ~ScopedRenderBufferBinder(); | 314 ~ScopedRenderBufferBinder(); |
| 317 | 315 |
| 318 private: | 316 private: |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 uint32* service_texture_id) OVERRIDE; | 623 uint32* service_texture_id) OVERRIDE; |
| 626 | 624 |
| 627 virtual uint32 GetTextureUploadCount() OVERRIDE; | 625 virtual uint32 GetTextureUploadCount() OVERRIDE; |
| 628 virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; | 626 virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; |
| 629 virtual base::TimeDelta GetTotalProcessingCommandsTime() OVERRIDE; | 627 virtual base::TimeDelta GetTotalProcessingCommandsTime() OVERRIDE; |
| 630 virtual void AddProcessingCommandsTime(base::TimeDelta) OVERRIDE; | 628 virtual void AddProcessingCommandsTime(base::TimeDelta) OVERRIDE; |
| 631 | 629 |
| 632 // Restores the current state to the user's settings. | 630 // Restores the current state to the user's settings. |
| 633 void RestoreCurrentFramebufferBindings(); | 631 void RestoreCurrentFramebufferBindings(); |
| 634 void RestoreCurrentRenderbufferBindings(); | 632 void RestoreCurrentRenderbufferBindings(); |
| 635 void RestoreCurrentTexture2DBindings(); | 633 void RestoreCurrentTextureBindings(GLenum target); |
| 636 | 634 |
| 637 // Sets DEPTH_TEST, STENCIL_TEST and color mask for the current framebuffer. | 635 // Sets DEPTH_TEST, STENCIL_TEST and color mask for the current framebuffer. |
| 638 void ApplyDirtyState(); | 636 void ApplyDirtyState(); |
| 639 | 637 |
| 640 // These check the state of the currently bound framebuffer or the | 638 // These check the state of the currently bound framebuffer or the |
| 641 // backbuffer if no framebuffer is bound. | 639 // backbuffer if no framebuffer is bound. |
| 642 // If all_draw_buffers is false, only check with COLOR_ATTACHMENT0, otherwise | 640 // If all_draw_buffers is false, only check with COLOR_ATTACHMENT0, otherwise |
| 643 // check with all attached and enabled color attachments. | 641 // check with all attached and enabled color attachments. |
| 644 bool BoundFramebufferHasColorAttachmentWithAlpha(bool all_draw_buffers); | 642 bool BoundFramebufferHasColorAttachmentWithAlpha(bool all_draw_buffers); |
| 645 bool BoundFramebufferHasDepthAttachment(); | 643 bool BoundFramebufferHasDepthAttachment(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 } | 715 } |
| 718 | 716 |
| 719 VertexArrayManager* vertex_array_manager() { | 717 VertexArrayManager* vertex_array_manager() { |
| 720 return vertex_array_manager_.get(); | 718 return vertex_array_manager_.get(); |
| 721 } | 719 } |
| 722 | 720 |
| 723 MemoryTracker* memory_tracker() { | 721 MemoryTracker* memory_tracker() { |
| 724 return group_->memory_tracker(); | 722 return group_->memory_tracker(); |
| 725 } | 723 } |
| 726 | 724 |
| 727 StreamTextureManager* stream_texture_manager() const { | |
| 728 return group_->stream_texture_manager(); | |
| 729 } | |
| 730 | |
| 731 bool EnsureGPUMemoryAvailable(size_t estimated_size) { | 725 bool EnsureGPUMemoryAvailable(size_t estimated_size) { |
| 732 MemoryTracker* tracker = memory_tracker(); | 726 MemoryTracker* tracker = memory_tracker(); |
| 733 if (tracker) { | 727 if (tracker) { |
| 734 return tracker->EnsureGPUMemoryAvailable(estimated_size); | 728 return tracker->EnsureGPUMemoryAvailable(estimated_size); |
| 735 } | 729 } |
| 736 return true; | 730 return true; |
| 737 } | 731 } |
| 738 | 732 |
| 739 bool IsOffscreenBufferMultisampled() const { | 733 bool IsOffscreenBufferMultisampled() const { |
| 740 return offscreen_target_samples_ > 1; | 734 return offscreen_target_samples_ > 1; |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1395 // Checks if the current program and vertex attributes are valid for drawing. | 1389 // Checks if the current program and vertex attributes are valid for drawing. |
| 1396 bool IsDrawValid( | 1390 bool IsDrawValid( |
| 1397 const char* function_name, GLuint max_vertex_accessed, GLsizei primcount); | 1391 const char* function_name, GLuint max_vertex_accessed, GLsizei primcount); |
| 1398 | 1392 |
| 1399 // Returns true if successful, simulated will be true if attrib0 was | 1393 // Returns true if successful, simulated will be true if attrib0 was |
| 1400 // simulated. | 1394 // simulated. |
| 1401 bool SimulateAttrib0( | 1395 bool SimulateAttrib0( |
| 1402 const char* function_name, GLuint max_vertex_accessed, bool* simulated); | 1396 const char* function_name, GLuint max_vertex_accessed, bool* simulated); |
| 1403 void RestoreStateForAttrib(GLuint attrib); | 1397 void RestoreStateForAttrib(GLuint attrib); |
| 1404 | 1398 |
| 1405 // If texture is a stream texture, this will update the stream to the newest | |
| 1406 // buffer. | |
| 1407 void UpdateStreamTextureIfNeeded(Texture* texture); | |
| 1408 | |
| 1409 // Returns false if unrenderable textures were replaced. | 1399 // Returns false if unrenderable textures were replaced. |
| 1410 bool PrepareTexturesForRender(); | 1400 bool PrepareTexturesForRender(); |
| 1411 void RestoreStateForNonRenderableTextures(); | 1401 void RestoreStateForNonRenderableTextures(); |
| 1412 | 1402 |
| 1413 // Returns true if GL_FIXED attribs were simulated. | 1403 // Returns true if GL_FIXED attribs were simulated. |
| 1414 bool SimulateFixedAttribs( | 1404 bool SimulateFixedAttribs( |
| 1415 const char* function_name, | 1405 const char* function_name, |
| 1416 GLuint max_vertex_accessed, bool* simulated, GLsizei primcount); | 1406 GLuint max_vertex_accessed, bool* simulated, GLsizei primcount); |
| 1417 void RestoreStateForSimulatedFixedAttribs(); | 1407 void RestoreStateForSimulatedFixedAttribs(); |
| 1418 | 1408 |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1762 : function_name_(function_name), | 1752 : function_name_(function_name), |
| 1763 decoder_(decoder) { | 1753 decoder_(decoder) { |
| 1764 ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(decoder_->GetErrorState(), | 1754 ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(decoder_->GetErrorState(), |
| 1765 function_name_); | 1755 function_name_); |
| 1766 } | 1756 } |
| 1767 | 1757 |
| 1768 ScopedGLErrorSuppressor::~ScopedGLErrorSuppressor() { | 1758 ScopedGLErrorSuppressor::~ScopedGLErrorSuppressor() { |
| 1769 ERRORSTATE_CLEAR_REAL_GL_ERRORS(decoder_->GetErrorState(), function_name_); | 1759 ERRORSTATE_CLEAR_REAL_GL_ERRORS(decoder_->GetErrorState(), function_name_); |
| 1770 } | 1760 } |
| 1771 | 1761 |
| 1772 ScopedTexture2DBinder::ScopedTexture2DBinder(GLES2DecoderImpl* decoder, | 1762 ScopedTextureBinder::ScopedTextureBinder(GLES2DecoderImpl* decoder, |
| 1773 GLuint id) | 1763 GLenum target, |
| 1774 : decoder_(decoder) { | 1764 GLuint id) |
| 1765 : decoder_(decoder), |
| 1766 target_(target) { |
| 1775 ScopedGLErrorSuppressor suppressor( | 1767 ScopedGLErrorSuppressor suppressor( |
| 1776 "ScopedTexture2DBinder::ctor", decoder_); | 1768 "ScopedTextureBinder::ctor", decoder_); |
| 1777 | 1769 |
| 1778 // TODO(apatrick): Check if there are any other states that need to be reset | 1770 // TODO(apatrick): Check if there are any other states that need to be reset |
| 1779 // before binding a new texture. | 1771 // before binding a new texture. |
| 1780 glActiveTexture(GL_TEXTURE0); | 1772 glActiveTexture(GL_TEXTURE0); |
| 1781 glBindTexture(GL_TEXTURE_2D, id); | 1773 glBindTexture(target, id); |
| 1782 } | 1774 } |
| 1783 | 1775 |
| 1784 ScopedTexture2DBinder::~ScopedTexture2DBinder() { | 1776 ScopedTextureBinder::~ScopedTextureBinder() { |
| 1785 ScopedGLErrorSuppressor suppressor( | 1777 ScopedGLErrorSuppressor suppressor( |
| 1786 "ScopedTexture2DBinder::dtor", decoder_); | 1778 "ScopedTextureBinder::dtor", decoder_); |
| 1787 decoder_->RestoreCurrentTexture2DBindings(); | 1779 decoder_->RestoreCurrentTextureBindings(target_); |
| 1788 } | 1780 } |
| 1789 | 1781 |
| 1790 ScopedRenderBufferBinder::ScopedRenderBufferBinder(GLES2DecoderImpl* decoder, | 1782 ScopedRenderBufferBinder::ScopedRenderBufferBinder(GLES2DecoderImpl* decoder, |
| 1791 GLuint id) | 1783 GLuint id) |
| 1792 : decoder_(decoder) { | 1784 : decoder_(decoder) { |
| 1793 ScopedGLErrorSuppressor suppressor( | 1785 ScopedGLErrorSuppressor suppressor( |
| 1794 "ScopedRenderBufferBinder::ctor", decoder_); | 1786 "ScopedRenderBufferBinder::ctor", decoder_); |
| 1795 glBindRenderbufferEXT(GL_RENDERBUFFER, id); | 1787 glBindRenderbufferEXT(GL_RENDERBUFFER, id); |
| 1796 } | 1788 } |
| 1797 | 1789 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1905 // This does not destroy the render texture because that would require that | 1897 // This does not destroy the render texture because that would require that |
| 1906 // the associated GL context was current. Just check that it was explicitly | 1898 // the associated GL context was current. Just check that it was explicitly |
| 1907 // destroyed. | 1899 // destroyed. |
| 1908 DCHECK_EQ(id_, 0u); | 1900 DCHECK_EQ(id_, 0u); |
| 1909 } | 1901 } |
| 1910 | 1902 |
| 1911 void BackTexture::Create() { | 1903 void BackTexture::Create() { |
| 1912 ScopedGLErrorSuppressor suppressor("BackTexture::Create", decoder_); | 1904 ScopedGLErrorSuppressor suppressor("BackTexture::Create", decoder_); |
| 1913 Destroy(); | 1905 Destroy(); |
| 1914 glGenTextures(1, &id_); | 1906 glGenTextures(1, &id_); |
| 1915 ScopedTexture2DBinder binder(decoder_, id_); | 1907 ScopedTextureBinder binder(decoder_, GL_TEXTURE_2D, id_); |
| 1916 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 1908 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1917 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 1909 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1918 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 1910 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1919 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 1911 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 1920 | 1912 |
| 1921 // TODO(apatrick): Attempt to diagnose crbug.com/97775. If SwapBuffers is | 1913 // TODO(apatrick): Attempt to diagnose crbug.com/97775. If SwapBuffers is |
| 1922 // never called on an offscreen context, no data will ever be uploaded to the | 1914 // never called on an offscreen context, no data will ever be uploaded to the |
| 1923 // saved offscreen color texture (it is deferred until to when SwapBuffers | 1915 // saved offscreen color texture (it is deferred until to when SwapBuffers |
| 1924 // is called). My idea is that some nvidia drivers might have a bug where | 1916 // is called). My idea is that some nvidia drivers might have a bug where |
| 1925 // deleting a texture that has never been populated might cause a | 1917 // deleting a texture that has never been populated might cause a |
| 1926 // crash. | 1918 // crash. |
| 1927 glTexImage2D( | 1919 glTexImage2D( |
| 1928 GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 1920 GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 1929 | 1921 |
| 1930 bytes_allocated_ = 16u * 16u * 4u; | 1922 bytes_allocated_ = 16u * 16u * 4u; |
| 1931 memory_tracker_.TrackMemAlloc(bytes_allocated_); | 1923 memory_tracker_.TrackMemAlloc(bytes_allocated_); |
| 1932 } | 1924 } |
| 1933 | 1925 |
| 1934 bool BackTexture::AllocateStorage( | 1926 bool BackTexture::AllocateStorage( |
| 1935 const gfx::Size& size, GLenum format, bool zero) { | 1927 const gfx::Size& size, GLenum format, bool zero) { |
| 1936 DCHECK_NE(id_, 0u); | 1928 DCHECK_NE(id_, 0u); |
| 1937 ScopedGLErrorSuppressor suppressor("BackTexture::AllocateStorage", decoder_); | 1929 ScopedGLErrorSuppressor suppressor("BackTexture::AllocateStorage", decoder_); |
| 1938 ScopedTexture2DBinder binder(decoder_, id_); | 1930 ScopedTextureBinder binder(decoder_, GL_TEXTURE_2D, id_); |
| 1939 uint32 image_size = 0; | 1931 uint32 image_size = 0; |
| 1940 GLES2Util::ComputeImageDataSizes( | 1932 GLES2Util::ComputeImageDataSizes( |
| 1941 size.width(), size.height(), format, GL_UNSIGNED_BYTE, 8, &image_size, | 1933 size.width(), size.height(), format, GL_UNSIGNED_BYTE, 8, &image_size, |
| 1942 NULL, NULL); | 1934 NULL, NULL); |
| 1943 | 1935 |
| 1944 if (!memory_tracker_.EnsureGPUMemoryAvailable(image_size)) { | 1936 if (!memory_tracker_.EnsureGPUMemoryAvailable(image_size)) { |
| 1945 return false; | 1937 return false; |
| 1946 } | 1938 } |
| 1947 | 1939 |
| 1948 scoped_ptr<char[]> zero_data; | 1940 scoped_ptr<char[]> zero_data; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1968 memory_tracker_.TrackMemFree(bytes_allocated_); | 1960 memory_tracker_.TrackMemFree(bytes_allocated_); |
| 1969 bytes_allocated_ = image_size; | 1961 bytes_allocated_ = image_size; |
| 1970 memory_tracker_.TrackMemAlloc(bytes_allocated_); | 1962 memory_tracker_.TrackMemAlloc(bytes_allocated_); |
| 1971 } | 1963 } |
| 1972 return success; | 1964 return success; |
| 1973 } | 1965 } |
| 1974 | 1966 |
| 1975 void BackTexture::Copy(const gfx::Size& size, GLenum format) { | 1967 void BackTexture::Copy(const gfx::Size& size, GLenum format) { |
| 1976 DCHECK_NE(id_, 0u); | 1968 DCHECK_NE(id_, 0u); |
| 1977 ScopedGLErrorSuppressor suppressor("BackTexture::Copy", decoder_); | 1969 ScopedGLErrorSuppressor suppressor("BackTexture::Copy", decoder_); |
| 1978 ScopedTexture2DBinder binder(decoder_, id_); | 1970 ScopedTextureBinder binder(decoder_, GL_TEXTURE_2D, id_); |
| 1979 glCopyTexImage2D(GL_TEXTURE_2D, | 1971 glCopyTexImage2D(GL_TEXTURE_2D, |
| 1980 0, // level | 1972 0, // level |
| 1981 format, | 1973 format, |
| 1982 0, 0, | 1974 0, 0, |
| 1983 size.width(), | 1975 size.width(), |
| 1984 size.height(), | 1976 size.height(), |
| 1985 0); // border | 1977 0); // border |
| 1986 } | 1978 } |
| 1987 | 1979 |
| 1988 void BackTexture::Destroy() { | 1980 void BackTexture::Destroy() { |
| (...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2894 state_.bound_read_framebuffer.get(), | 2886 state_.bound_read_framebuffer.get(), |
| 2895 GetBackbufferServiceId()); | 2887 GetBackbufferServiceId()); |
| 2896 RebindCurrentFramebuffer( | 2888 RebindCurrentFramebuffer( |
| 2897 GL_DRAW_FRAMEBUFFER_EXT, | 2889 GL_DRAW_FRAMEBUFFER_EXT, |
| 2898 state_.bound_draw_framebuffer.get(), | 2890 state_.bound_draw_framebuffer.get(), |
| 2899 GetBackbufferServiceId()); | 2891 GetBackbufferServiceId()); |
| 2900 } | 2892 } |
| 2901 OnFboChanged(); | 2893 OnFboChanged(); |
| 2902 } | 2894 } |
| 2903 | 2895 |
| 2904 void GLES2DecoderImpl::RestoreCurrentTexture2DBindings() { | 2896 void GLES2DecoderImpl::RestoreCurrentTextureBindings(GLenum target) { |
| 2905 TextureUnit& info = state_.texture_units[0]; | 2897 TextureUnit& info = state_.texture_units[0]; |
| 2906 GLuint last_id; | 2898 GLuint last_id; |
| 2907 if (info.bound_texture_2d.get()) { | 2899 scoped_refptr<TextureRef> texture_ref; |
| 2908 last_id = info.bound_texture_2d->service_id(); | 2900 switch (target) { |
| 2901 case GL_TEXTURE_2D: |
| 2902 texture_ref = info.bound_texture_2d; |
| 2903 break; |
| 2904 case GL_TEXTURE_CUBE_MAP: |
| 2905 texture_ref = info.bound_texture_cube_map; |
| 2906 break; |
| 2907 case GL_TEXTURE_EXTERNAL_OES: |
| 2908 texture_ref = info.bound_texture_external_oes; |
| 2909 break; |
| 2910 case GL_TEXTURE_RECTANGLE_ARB: |
| 2911 texture_ref = info.bound_texture_rectangle_arb; |
| 2912 break; |
| 2913 default: |
| 2914 NOTREACHED(); |
| 2915 break; |
| 2916 } |
| 2917 if (texture_ref.get()) { |
| 2918 last_id = texture_ref->service_id(); |
| 2909 } else { | 2919 } else { |
| 2910 last_id = 0; | 2920 last_id = 0; |
| 2911 } | 2921 } |
| 2912 | 2922 |
| 2913 glBindTexture(GL_TEXTURE_2D, last_id); | 2923 glBindTexture(target, last_id); |
| 2914 glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); | 2924 glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); |
| 2915 } | 2925 } |
| 2916 | 2926 |
| 2917 bool GLES2DecoderImpl::CheckFramebufferValid( | 2927 bool GLES2DecoderImpl::CheckFramebufferValid( |
| 2918 Framebuffer* framebuffer, | 2928 Framebuffer* framebuffer, |
| 2919 GLenum target, const char* func_name) { | 2929 GLenum target, const char* func_name) { |
| 2920 if (!framebuffer) { | 2930 if (!framebuffer) { |
| 2921 if (backbuffer_needs_clear_bits_) { | 2931 if (backbuffer_needs_clear_bits_) { |
| 2922 glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat( | 2932 glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat( |
| 2923 offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1); | 2933 offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1); |
| (...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3875 Texture* texture = texture_ref->texture(); | 3885 Texture* texture = texture_ref->texture(); |
| 3876 | 3886 |
| 3877 // Check the texture exists | 3887 // Check the texture exists |
| 3878 // Check that we are not trying to bind it to a different target. | 3888 // Check that we are not trying to bind it to a different target. |
| 3879 if (texture->target() != 0 && texture->target() != target) { | 3889 if (texture->target() != 0 && texture->target() != target) { |
| 3880 LOCAL_SET_GL_ERROR( | 3890 LOCAL_SET_GL_ERROR( |
| 3881 GL_INVALID_OPERATION, | 3891 GL_INVALID_OPERATION, |
| 3882 "glBindTexture", "texture bound to more than 1 target."); | 3892 "glBindTexture", "texture bound to more than 1 target."); |
| 3883 return; | 3893 return; |
| 3884 } | 3894 } |
| 3885 if (texture->IsStreamTexture() && target != GL_TEXTURE_EXTERNAL_OES) { | |
| 3886 LOCAL_SET_GL_ERROR( | |
| 3887 GL_INVALID_OPERATION, | |
| 3888 "glBindTexture", "illegal target for stream texture."); | |
| 3889 return; | |
| 3890 } | |
| 3891 LogClientServiceForInfo(texture, client_id, "glBindTexture"); | 3895 LogClientServiceForInfo(texture, client_id, "glBindTexture"); |
| 3892 if (texture->target() == 0) { | 3896 if (texture->target() == 0) { |
| 3893 texture_manager()->SetTarget(texture_ref, target); | 3897 texture_manager()->SetTarget(texture_ref, target); |
| 3894 } | 3898 } |
| 3895 glBindTexture(target, texture->service_id()); | 3899 glBindTexture(target, texture->service_id()); |
| 3896 | 3900 |
| 3897 TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; | 3901 TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
| 3898 unit.bind_target = target; | 3902 unit.bind_target = target; |
| 3899 switch (target) { | 3903 switch (target) { |
| 3900 case GL_TEXTURE_2D: | 3904 case GL_TEXTURE_2D: |
| (...skipping 1761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5662 } | 5666 } |
| 5663 // We know there will be no errors, because we only defer compilation on | 5667 // We know there will be no errors, because we only defer compilation on |
| 5664 // shaders that were previously compiled successfully. | 5668 // shaders that were previously compiled successfully. |
| 5665 program_manager()->ForceCompileShader(shader->deferred_compilation_source(), | 5669 program_manager()->ForceCompileShader(shader->deferred_compilation_source(), |
| 5666 shader, | 5670 shader, |
| 5667 translator, | 5671 translator, |
| 5668 feature_info_.get()); | 5672 feature_info_.get()); |
| 5669 } | 5673 } |
| 5670 } | 5674 } |
| 5671 | 5675 |
| 5672 void GLES2DecoderImpl::UpdateStreamTextureIfNeeded(Texture* texture) { | |
| 5673 if (texture && texture->IsStreamTexture()) { | |
| 5674 DCHECK(stream_texture_manager()); | |
| 5675 StreamTexture* stream_tex = | |
| 5676 stream_texture_manager()->LookupStreamTexture(texture->service_id()); | |
| 5677 if (stream_tex) | |
| 5678 stream_tex->Update(); | |
| 5679 } | |
| 5680 } | |
| 5681 | |
| 5682 bool GLES2DecoderImpl::PrepareTexturesForRender() { | 5676 bool GLES2DecoderImpl::PrepareTexturesForRender() { |
| 5683 DCHECK(state_.current_program.get()); | 5677 DCHECK(state_.current_program.get()); |
| 5684 bool have_unrenderable_textures = | 5678 bool have_unrenderable_textures = |
| 5685 texture_manager()->HaveUnrenderableTextures(); | 5679 texture_manager()->HaveUnrenderableTextures(); |
| 5686 if (!have_unrenderable_textures && !features().oes_egl_image_external) { | 5680 if (!have_unrenderable_textures && !features().oes_egl_image_external) { |
| 5687 return true; | 5681 return true; |
| 5688 } | 5682 } |
| 5689 | 5683 |
| 5690 bool textures_set = false; | 5684 bool textures_set = false; |
| 5691 const Program::SamplerIndices& sampler_indices = | 5685 const Program::SamplerIndices& sampler_indices = |
| 5692 state_.current_program->sampler_indices(); | 5686 state_.current_program->sampler_indices(); |
| 5693 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { | 5687 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
| 5694 const Program::UniformInfo* uniform_info = | 5688 const Program::UniformInfo* uniform_info = |
| 5695 state_.current_program->GetUniformInfo(sampler_indices[ii]); | 5689 state_.current_program->GetUniformInfo(sampler_indices[ii]); |
| 5696 DCHECK(uniform_info); | 5690 DCHECK(uniform_info); |
| 5697 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { | 5691 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 5698 GLuint texture_unit_index = uniform_info->texture_units[jj]; | 5692 GLuint texture_unit_index = uniform_info->texture_units[jj]; |
| 5699 if (texture_unit_index < state_.texture_units.size()) { | 5693 if (texture_unit_index < state_.texture_units.size()) { |
| 5700 TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; | 5694 TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
| 5701 TextureRef* texture = | 5695 TextureRef* texture = |
| 5702 texture_unit.GetInfoForSamplerType(uniform_info->type).get(); | 5696 texture_unit.GetInfoForSamplerType(uniform_info->type).get(); |
| 5703 if (texture) | 5697 if (texture && texture->texture()) { |
| 5704 UpdateStreamTextureIfNeeded(texture->texture()); | 5698 scoped_refptr<gfx::GLImage> image = texture->texture()->GetLevelImage( |
| 5699 texture->texture()->target(), 0); |
| 5700 if (image.get()) |
| 5701 image->WillUseTexImage(); |
| 5702 } |
| 5705 if (have_unrenderable_textures && | 5703 if (have_unrenderable_textures && |
| 5706 (!texture || !texture_manager()->CanRender(texture))) { | 5704 (!texture || !texture_manager()->CanRender(texture))) { |
| 5707 textures_set = true; | 5705 textures_set = true; |
| 5708 glActiveTexture(GL_TEXTURE0 + texture_unit_index); | 5706 glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 5709 glBindTexture( | 5707 glBindTexture( |
| 5710 GetBindTargetForSamplerType(uniform_info->type), | 5708 GetBindTargetForSamplerType(uniform_info->type), |
| 5711 texture_manager()->black_texture_id(uniform_info->type)); | 5709 texture_manager()->black_texture_id(uniform_info->type)); |
| 5712 LOCAL_RENDER_WARNING( | 5710 LOCAL_RENDER_WARNING( |
| 5713 std::string("texture bound to texture unit ") + | 5711 std::string("texture bound to texture unit ") + |
| 5714 base::IntToString(texture_unit_index) + | 5712 base::IntToString(texture_unit_index) + |
| (...skipping 3764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9479 *result = GL_ZERO; | 9477 *result = GL_ZERO; |
| 9480 TextureRef* texture_ref = texture_manager()->GetTexture(client_id); | 9478 TextureRef* texture_ref = texture_manager()->GetTexture(client_id); |
| 9481 if (!texture_ref) { | 9479 if (!texture_ref) { |
| 9482 LOCAL_SET_GL_ERROR( | 9480 LOCAL_SET_GL_ERROR( |
| 9483 GL_INVALID_VALUE, | 9481 GL_INVALID_VALUE, |
| 9484 "glCreateStreamTextureCHROMIUM", "bad texture id."); | 9482 "glCreateStreamTextureCHROMIUM", "bad texture id."); |
| 9485 return error::kNoError; | 9483 return error::kNoError; |
| 9486 } | 9484 } |
| 9487 | 9485 |
| 9488 Texture* texture = texture_ref->texture(); | 9486 Texture* texture = texture_ref->texture(); |
| 9489 if (texture->IsStreamTexture()) { | |
| 9490 LOCAL_SET_GL_ERROR( | |
| 9491 GL_INVALID_OPERATION, | |
| 9492 "glCreateStreamTextureCHROMIUM", "is already a stream texture."); | |
| 9493 return error::kNoError; | |
| 9494 } | |
| 9495 | |
| 9496 if (texture->target() && texture->target() != GL_TEXTURE_EXTERNAL_OES) { | 9487 if (texture->target() && texture->target() != GL_TEXTURE_EXTERNAL_OES) { |
| 9497 LOCAL_SET_GL_ERROR( | 9488 LOCAL_SET_GL_ERROR( |
| 9498 GL_INVALID_OPERATION, | 9489 GL_INVALID_OPERATION, |
| 9499 "glCreateStreamTextureCHROMIUM", | 9490 "glCreateStreamTextureCHROMIUM", |
| 9500 "is already bound to incompatible target."); | 9491 "is already bound to incompatible target."); |
| 9501 return error::kNoError; | 9492 return error::kNoError; |
| 9493 } else if (!texture->target()) { |
| 9494 texture_manager()->SetTarget(texture_ref, GL_TEXTURE_EXTERNAL_OES); |
| 9502 } | 9495 } |
| 9503 | 9496 |
| 9504 if (!stream_texture_manager()) | 9497 scoped_refptr<gfx::GLImage> image = |
| 9505 return error::kInvalidArguments; | 9498 gfx::GLImage::CreateGLImageForStreamTexture(); |
| 9506 | 9499 |
| 9507 GLuint object_id = stream_texture_manager()->CreateStreamTexture( | 9500 { |
| 9508 texture->service_id(), client_id); | 9501 ScopedTextureBinder binder( |
| 9502 this, GL_TEXTURE_EXTERNAL_OES, texture->service_id()); |
| 9503 if (!image->BindTexImage()) |
| 9504 image = NULL; |
| 9505 } |
| 9509 | 9506 |
| 9510 if (object_id) { | 9507 uint32 image_id = 0; |
| 9511 texture_manager()->SetStreamTexture(texture_ref, true); | 9508 if (image) { |
| 9509 image_id = group_->GetIdAllocator(id_namespaces::kImages)->AllocateID(); |
| 9510 image_manager()->AddImage(image, image_id); |
| 9511 texture_manager()->SetLevelInfo(texture_ref, |
| 9512 GL_TEXTURE_EXTERNAL_OES, |
| 9513 0, |
| 9514 GL_RGBA, |
| 9515 0, |
| 9516 0, |
| 9517 1, |
| 9518 0, |
| 9519 GL_RGBA, |
| 9520 GL_UNSIGNED_BYTE, |
| 9521 true); |
| 9522 texture_manager()->SetLevelImage( |
| 9523 texture_ref, GL_TEXTURE_EXTERNAL_OES, 0, image); |
| 9512 } else { | 9524 } else { |
| 9513 LOCAL_SET_GL_ERROR( | 9525 LOCAL_SET_GL_ERROR( |
| 9514 GL_OUT_OF_MEMORY, | 9526 GL_OUT_OF_MEMORY, |
| 9515 "glCreateStreamTextureCHROMIUM", "failed to create platform texture."); | 9527 "glCreateStreamTextureCHROMIUM", "failed to create platform texture."); |
| 9516 } | 9528 } |
| 9517 | 9529 |
| 9518 *result = object_id; | 9530 *result = image_id; |
| 9519 return error::kNoError; | 9531 return error::kNoError; |
| 9520 } | 9532 } |
| 9521 | 9533 |
| 9522 error::Error GLES2DecoderImpl::HandleDestroyStreamTextureCHROMIUM( | 9534 error::Error GLES2DecoderImpl::HandleDestroyStreamTextureCHROMIUM( |
| 9523 uint32 immediate_data_size, | 9535 uint32 immediate_data_size, |
| 9524 const cmds::DestroyStreamTextureCHROMIUM& c) { | 9536 const cmds::DestroyStreamTextureCHROMIUM& c) { |
| 9525 GLuint client_id = c.texture; | 9537 GLuint image_id = c.texture; |
| 9526 TextureRef* texture_ref = texture_manager()->GetTexture(client_id); | 9538 if (image_id && image_manager()->LookupImage(image_id)) { |
| 9527 if (texture_ref && texture_manager()->IsStreamTextureOwner(texture_ref)) { | 9539 image_manager()->RemoveImage(image_id); |
| 9528 if (!stream_texture_manager()) | 9540 group_->GetIdAllocator(id_namespaces::kImages)->FreeID(image_id); |
| 9529 return error::kInvalidArguments; | |
| 9530 | |
| 9531 stream_texture_manager()->DestroyStreamTexture(texture_ref->service_id()); | |
| 9532 texture_manager()->SetStreamTexture(texture_ref, false); | |
| 9533 } else { | 9541 } else { |
| 9534 LOCAL_SET_GL_ERROR( | 9542 LOCAL_SET_GL_ERROR( |
| 9535 GL_INVALID_VALUE, | 9543 GL_INVALID_VALUE, |
| 9536 "glDestroyStreamTextureCHROMIUM", "bad texture id."); | 9544 "glDestroyStreamTextureCHROMIUM", "bad texture id."); |
| 9537 } | 9545 } |
| 9538 | 9546 |
| 9539 return error::kNoError; | 9547 return error::kNoError; |
| 9540 } | 9548 } |
| 9541 | 9549 |
| 9542 #if defined(OS_MACOSX) | 9550 #if defined(OS_MACOSX) |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9733 if (!texture_manager()->ValidForTarget(GL_TEXTURE_2D, level, source_width, | 9741 if (!texture_manager()->ValidForTarget(GL_TEXTURE_2D, level, source_width, |
| 9734 source_height, 1)) { | 9742 source_height, 1)) { |
| 9735 LOCAL_SET_GL_ERROR( | 9743 LOCAL_SET_GL_ERROR( |
| 9736 GL_INVALID_VALUE, | 9744 GL_INVALID_VALUE, |
| 9737 "glCopyTextureCHROMIUM", "Bad dimensions"); | 9745 "glCopyTextureCHROMIUM", "Bad dimensions"); |
| 9738 return; | 9746 return; |
| 9739 } | 9747 } |
| 9740 } | 9748 } |
| 9741 | 9749 |
| 9742 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { | 9750 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { |
| 9743 UpdateStreamTextureIfNeeded(source_texture); | 9751 scoped_refptr<gfx::GLImage> image = |
| 9744 DCHECK(stream_texture_manager()); | 9752 source_texture->GetLevelImage(GL_TEXTURE_EXTERNAL_OES, 0); |
| 9745 StreamTexture* stream_tex = | 9753 if (!image) { |
| 9746 stream_texture_manager()->LookupStreamTexture( | |
| 9747 source_texture->service_id()); | |
| 9748 if (!stream_tex) { | |
| 9749 LOCAL_SET_GL_ERROR( | 9754 LOCAL_SET_GL_ERROR( |
| 9750 GL_INVALID_VALUE, | 9755 GL_INVALID_VALUE, |
| 9751 "glCopyTextureChromium", "Stream texture lookup failed"); | 9756 "glCopyTextureChromium", "Stream texture lookup failed"); |
| 9752 return; | 9757 return; |
| 9753 } | 9758 } |
| 9754 gfx::Size size = stream_tex->GetSize(); | 9759 image->WillUseTexImage(); |
| 9760 gfx::Size size = image->GetSize(); |
| 9755 source_width = size.width(); | 9761 source_width = size.width(); |
| 9756 source_height = size.height(); | 9762 source_height = size.height(); |
| 9757 if (source_width <= 0 || source_height <= 0) { | 9763 if (source_width <= 0 || source_height <= 0) { |
| 9758 LOCAL_SET_GL_ERROR( | 9764 LOCAL_SET_GL_ERROR( |
| 9759 GL_INVALID_VALUE, | 9765 GL_INVALID_VALUE, |
| 9760 "glCopyTextureChromium", "invalid streamtexture size"); | 9766 "glCopyTextureChromium", "invalid streamtexture size"); |
| 9761 return; | 9767 return; |
| 9762 } | 9768 } |
| 9763 } | 9769 } |
| 9764 | 9770 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 9789 dest_internal_format != internal_format || | 9795 dest_internal_format != internal_format || |
| 9790 dest_type_previous != dest_type) { | 9796 dest_type_previous != dest_type) { |
| 9791 // Ensure that the glTexImage2D succeeds. | 9797 // Ensure that the glTexImage2D succeeds. |
| 9792 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); | 9798 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
| 9793 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); | 9799 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
| 9794 glTexImage2D( | 9800 glTexImage2D( |
| 9795 GL_TEXTURE_2D, level, internal_format, source_width, source_height, | 9801 GL_TEXTURE_2D, level, internal_format, source_width, source_height, |
| 9796 0, internal_format, dest_type, NULL); | 9802 0, internal_format, dest_type, NULL); |
| 9797 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM"); | 9803 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM"); |
| 9798 if (error != GL_NO_ERROR) { | 9804 if (error != GL_NO_ERROR) { |
| 9799 RestoreCurrentTexture2DBindings(); | 9805 RestoreCurrentTextureBindings(GL_TEXTURE_2D); |
| 9800 return; | 9806 return; |
| 9801 } | 9807 } |
| 9802 | 9808 |
| 9803 texture_manager()->SetLevelInfo( | 9809 texture_manager()->SetLevelInfo( |
| 9804 dest_texture_ref, GL_TEXTURE_2D, level, internal_format, source_width, | 9810 dest_texture_ref, GL_TEXTURE_2D, level, internal_format, source_width, |
| 9805 source_height, 1, 0, internal_format, dest_type, true); | 9811 source_height, 1, 0, internal_format, dest_type, true); |
| 9806 } else { | 9812 } else { |
| 9807 texture_manager()->SetLevelCleared( | 9813 texture_manager()->SetLevelCleared( |
| 9808 dest_texture_ref, GL_TEXTURE_2D, level, true); | 9814 dest_texture_ref, GL_TEXTURE_2D, level, true); |
| 9809 } | 9815 } |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10503 return error::kNoError; | 10509 return error::kNoError; |
| 10504 } | 10510 } |
| 10505 | 10511 |
| 10506 // Include the auto-generated part of this file. We split this because it means | 10512 // Include the auto-generated part of this file. We split this because it means |
| 10507 // we can easily edit the non-auto generated parts right here in this file | 10513 // we can easily edit the non-auto generated parts right here in this file |
| 10508 // instead of having to edit some template or the code generator. | 10514 // instead of having to edit some template or the code generator. |
| 10509 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 10515 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 10510 | 10516 |
| 10511 } // namespace gles2 | 10517 } // namespace gles2 |
| 10512 } // namespace gpu | 10518 } // namespace gpu |
| OLD | NEW |