| 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 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 } | 652 } |
| 653 | 653 |
| 654 ImageManager* image_manager() { | 654 ImageManager* image_manager() { |
| 655 return group_->image_manager(); | 655 return group_->image_manager(); |
| 656 } | 656 } |
| 657 | 657 |
| 658 VertexArrayManager* vertex_array_manager() { | 658 VertexArrayManager* vertex_array_manager() { |
| 659 return vertex_array_manager_.get(); | 659 return vertex_array_manager_.get(); |
| 660 } | 660 } |
| 661 | 661 |
| 662 MemoryTracker* memory_tracker() { |
| 663 return group_->memory_tracker(); |
| 664 } |
| 665 |
| 666 bool EnsureGPUMemoryAvailable(size_t estimated_size) { |
| 667 MemoryTracker* tracker = memory_tracker(); |
| 668 if (tracker) { |
| 669 return tracker->EnsureGPUMemoryAvailable(estimated_size); |
| 670 } |
| 671 return true; |
| 672 } |
| 673 |
| 662 bool IsOffscreenBufferMultisampled() const { | 674 bool IsOffscreenBufferMultisampled() const { |
| 663 return offscreen_target_samples_ > 1; | 675 return offscreen_target_samples_ > 1; |
| 664 } | 676 } |
| 665 | 677 |
| 666 // Creates a TextureInfo for the given texture. | 678 // Creates a TextureInfo for the given texture. |
| 667 TextureManager::TextureInfo* CreateTextureInfo( | 679 TextureManager::TextureInfo* CreateTextureInfo( |
| 668 GLuint client_id, GLuint service_id) { | 680 GLuint client_id, GLuint service_id) { |
| 669 return texture_manager()->CreateTextureInfo(client_id, service_id); | 681 return texture_manager()->CreateTextureInfo(client_id, service_id); |
| 670 } | 682 } |
| 671 | 683 |
| (...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1819 } | 1831 } |
| 1820 | 1832 |
| 1821 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { | 1833 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { |
| 1822 decoder_->texture_upload_count_++; | 1834 decoder_->texture_upload_count_++; |
| 1823 decoder_->total_texture_upload_time_ += | 1835 decoder_->total_texture_upload_time_ += |
| 1824 base::TimeTicks::HighResNow() - begin_time_; | 1836 base::TimeTicks::HighResNow() - begin_time_; |
| 1825 } | 1837 } |
| 1826 | 1838 |
| 1827 Texture::Texture(GLES2DecoderImpl* decoder) | 1839 Texture::Texture(GLES2DecoderImpl* decoder) |
| 1828 : decoder_(decoder), | 1840 : decoder_(decoder), |
| 1829 memory_tracker_(decoder->GetContextGroup()->memory_tracker(), | 1841 memory_tracker_(decoder->memory_tracker(), MemoryTracker::kUnmanaged), |
| 1830 MemoryTracker::kUnmanaged), | |
| 1831 bytes_allocated_(0), | 1842 bytes_allocated_(0), |
| 1832 id_(0) { | 1843 id_(0) { |
| 1833 } | 1844 } |
| 1834 | 1845 |
| 1835 Texture::~Texture() { | 1846 Texture::~Texture() { |
| 1836 // This does not destroy the render texture because that would require that | 1847 // This does not destroy the render texture because that would require that |
| 1837 // the associated GL context was current. Just check that it was explicitly | 1848 // the associated GL context was current. Just check that it was explicitly |
| 1838 // destroyed. | 1849 // destroyed. |
| 1839 DCHECK_EQ(id_, 0u); | 1850 DCHECK_EQ(id_, 0u); |
| 1840 } | 1851 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1855 // is called). My idea is that some nvidia drivers might have a bug where | 1866 // is called). My idea is that some nvidia drivers might have a bug where |
| 1856 // deleting a texture that has never been populated might cause a | 1867 // deleting a texture that has never been populated might cause a |
| 1857 // crash. | 1868 // crash. |
| 1858 glTexImage2D( | 1869 glTexImage2D( |
| 1859 GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 1870 GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 1860 | 1871 |
| 1861 bytes_allocated_ = 16u * 16u * 4u; | 1872 bytes_allocated_ = 16u * 16u * 4u; |
| 1862 memory_tracker_.TrackMemAlloc(bytes_allocated_); | 1873 memory_tracker_.TrackMemAlloc(bytes_allocated_); |
| 1863 } | 1874 } |
| 1864 | 1875 |
| 1865 bool Texture::AllocateStorage(const gfx::Size& size, GLenum format, | 1876 bool Texture::AllocateStorage(const gfx::Size& size, GLenum format, bool zero) { |
| 1866 bool zero) { | |
| 1867 DCHECK_NE(id_, 0u); | 1877 DCHECK_NE(id_, 0u); |
| 1868 ScopedGLErrorSuppressor suppressor(decoder_); | 1878 ScopedGLErrorSuppressor suppressor(decoder_); |
| 1869 ScopedTexture2DBinder binder(decoder_, id_); | 1879 ScopedTexture2DBinder binder(decoder_, id_); |
| 1870 uint32 image_size = 0; | 1880 uint32 image_size = 0; |
| 1871 GLES2Util::ComputeImageDataSizes( | 1881 GLES2Util::ComputeImageDataSizes( |
| 1872 size.width(), size.height(), format, GL_UNSIGNED_BYTE, 8, &image_size, | 1882 size.width(), size.height(), format, GL_UNSIGNED_BYTE, 8, &image_size, |
| 1873 NULL, NULL); | 1883 NULL, NULL); |
| 1874 | 1884 |
| 1885 if (!memory_tracker_.EnsureGPUMemoryAvailable(image_size)) { |
| 1886 return false; |
| 1887 } |
| 1888 |
| 1875 scoped_array<char> zero_data; | 1889 scoped_array<char> zero_data; |
| 1876 if (zero) { | 1890 if (zero) { |
| 1877 zero_data.reset(new char[image_size]); | 1891 zero_data.reset(new char[image_size]); |
| 1878 memset(zero_data.get(), 0, image_size); | 1892 memset(zero_data.get(), 0, image_size); |
| 1879 } | 1893 } |
| 1880 | 1894 |
| 1881 WrappedTexImage2D(GL_TEXTURE_2D, | 1895 WrappedTexImage2D(GL_TEXTURE_2D, |
| 1882 0, // mip level | 1896 0, // mip level |
| 1883 format, | 1897 format, |
| 1884 size.width(), | 1898 size.width(), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1921 memory_tracker_.TrackMemFree(bytes_allocated_); | 1935 memory_tracker_.TrackMemFree(bytes_allocated_); |
| 1922 bytes_allocated_ = 0; | 1936 bytes_allocated_ = 0; |
| 1923 } | 1937 } |
| 1924 | 1938 |
| 1925 void Texture::Invalidate() { | 1939 void Texture::Invalidate() { |
| 1926 id_ = 0; | 1940 id_ = 0; |
| 1927 } | 1941 } |
| 1928 | 1942 |
| 1929 RenderBuffer::RenderBuffer(GLES2DecoderImpl* decoder) | 1943 RenderBuffer::RenderBuffer(GLES2DecoderImpl* decoder) |
| 1930 : decoder_(decoder), | 1944 : decoder_(decoder), |
| 1931 memory_tracker_(decoder->GetContextGroup()->memory_tracker(), | 1945 memory_tracker_(decoder->memory_tracker(), MemoryTracker::kUnmanaged), |
| 1932 MemoryTracker::kUnmanaged), | |
| 1933 bytes_allocated_(0), | 1946 bytes_allocated_(0), |
| 1934 id_(0) { | 1947 id_(0) { |
| 1935 } | 1948 } |
| 1936 | 1949 |
| 1937 RenderBuffer::~RenderBuffer() { | 1950 RenderBuffer::~RenderBuffer() { |
| 1938 // This does not destroy the render buffer because that would require that | 1951 // This does not destroy the render buffer because that would require that |
| 1939 // the associated GL context was current. Just check that it was explicitly | 1952 // the associated GL context was current. Just check that it was explicitly |
| 1940 // destroyed. | 1953 // destroyed. |
| 1941 DCHECK_EQ(id_, 0u); | 1954 DCHECK_EQ(id_, 0u); |
| 1942 } | 1955 } |
| 1943 | 1956 |
| 1944 void RenderBuffer::Create() { | 1957 void RenderBuffer::Create() { |
| 1945 ScopedGLErrorSuppressor suppressor(decoder_); | 1958 ScopedGLErrorSuppressor suppressor(decoder_); |
| 1946 Destroy(); | 1959 Destroy(); |
| 1947 glGenRenderbuffersEXT(1, &id_); | 1960 glGenRenderbuffersEXT(1, &id_); |
| 1948 } | 1961 } |
| 1949 | 1962 |
| 1950 bool RenderBuffer::AllocateStorage(const gfx::Size& size, GLenum format, | 1963 bool RenderBuffer::AllocateStorage(const gfx::Size& size, GLenum format, |
| 1951 GLsizei samples) { | 1964 GLsizei samples) { |
| 1952 ScopedGLErrorSuppressor suppressor(decoder_); | 1965 ScopedGLErrorSuppressor suppressor(decoder_); |
| 1953 ScopedRenderBufferBinder binder(decoder_, id_); | 1966 ScopedRenderBufferBinder binder(decoder_, id_); |
| 1967 |
| 1968 uint32 estimated_size = 0; |
| 1969 if (!RenderbufferManager::ComputeEstimatedRenderbufferSize( |
| 1970 size.width(), size.height(), samples, format, &estimated_size)) { |
| 1971 return false; |
| 1972 } |
| 1973 |
| 1974 if (!memory_tracker_.EnsureGPUMemoryAvailable(estimated_size)) { |
| 1975 return false; |
| 1976 } |
| 1977 |
| 1954 if (samples <= 1) { | 1978 if (samples <= 1) { |
| 1955 glRenderbufferStorageEXT(GL_RENDERBUFFER, | 1979 glRenderbufferStorageEXT(GL_RENDERBUFFER, |
| 1956 format, | 1980 format, |
| 1957 size.width(), | 1981 size.width(), |
| 1958 size.height()); | 1982 size.height()); |
| 1959 } else { | 1983 } else { |
| 1960 if (GLES2Decoder::IsAngle()) { | 1984 if (GLES2Decoder::IsAngle()) { |
| 1961 glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, | 1985 glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, |
| 1962 samples, | 1986 samples, |
| 1963 format, | 1987 format, |
| 1964 size.width(), | 1988 size.width(), |
| 1965 size.height()); | 1989 size.height()); |
| 1966 } else { | 1990 } else { |
| 1967 glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, | 1991 glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, |
| 1968 samples, | 1992 samples, |
| 1969 format, | 1993 format, |
| 1970 size.width(), | 1994 size.width(), |
| 1971 size.height()); | 1995 size.height()); |
| 1972 } | 1996 } |
| 1973 } | 1997 } |
| 1974 bool success = glGetError() == GL_NO_ERROR; | 1998 bool success = glGetError() == GL_NO_ERROR; |
| 1975 if (success) { | 1999 if (success) { |
| 1976 memory_tracker_.TrackMemFree(bytes_allocated_); | 2000 memory_tracker_.TrackMemFree(bytes_allocated_); |
| 1977 bytes_allocated_ = | 2001 bytes_allocated_ = estimated_size; |
| 1978 size.width() * size.height() * samples * | |
| 1979 GLES2Util::RenderbufferBytesPerPixel(format); | |
| 1980 memory_tracker_.TrackMemAlloc(bytes_allocated_); | 2002 memory_tracker_.TrackMemAlloc(bytes_allocated_); |
| 1981 } | 2003 } |
| 1982 return success; | 2004 return success; |
| 1983 } | 2005 } |
| 1984 | 2006 |
| 1985 void RenderBuffer::Destroy() { | 2007 void RenderBuffer::Destroy() { |
| 1986 if (id_ != 0) { | 2008 if (id_ != 0) { |
| 1987 ScopedGLErrorSuppressor suppressor(decoder_); | 2009 ScopedGLErrorSuppressor suppressor(decoder_); |
| 1988 glDeleteRenderbuffersEXT(1, &id_); | 2010 glDeleteRenderbuffersEXT(1, &id_); |
| 1989 id_ = 0; | 2011 id_ = 0; |
| (...skipping 2785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4775 if (!features().chromium_framebuffer_multisample) { | 4797 if (!features().chromium_framebuffer_multisample) { |
| 4776 SetGLError(GL_INVALID_OPERATION, | 4798 SetGLError(GL_INVALID_OPERATION, |
| 4777 "glRenderbufferStorageMultisampleEXT", "function not available"); | 4799 "glRenderbufferStorageMultisampleEXT", "function not available"); |
| 4778 return; | 4800 return; |
| 4779 } | 4801 } |
| 4780 | 4802 |
| 4781 RenderbufferManager::RenderbufferInfo* renderbuffer = | 4803 RenderbufferManager::RenderbufferInfo* renderbuffer = |
| 4782 GetRenderbufferInfoForTarget(GL_RENDERBUFFER); | 4804 GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 4783 if (!renderbuffer) { | 4805 if (!renderbuffer) { |
| 4784 SetGLError(GL_INVALID_OPERATION, | 4806 SetGLError(GL_INVALID_OPERATION, |
| 4785 "glGetRenderbufferStorageMultisample", "no renderbuffer bound"); | 4807 "glRenderbufferStorageMultisampleEXT", "no renderbuffer bound"); |
| 4786 return; | 4808 return; |
| 4787 } | 4809 } |
| 4788 | 4810 |
| 4789 if (samples > renderbuffer_manager()->max_samples()) { | 4811 if (samples > renderbuffer_manager()->max_samples()) { |
| 4790 SetGLError(GL_INVALID_VALUE, | 4812 SetGLError(GL_INVALID_VALUE, |
| 4791 "glGetRenderbufferStorageMultisample", "samples too large"); | 4813 "glRenderbufferStorageMultisampleEXT", "samples too large"); |
| 4792 return; | 4814 return; |
| 4793 } | 4815 } |
| 4794 | 4816 |
| 4795 if (width > renderbuffer_manager()->max_renderbuffer_size() || | 4817 if (width > renderbuffer_manager()->max_renderbuffer_size() || |
| 4796 height > renderbuffer_manager()->max_renderbuffer_size()) { | 4818 height > renderbuffer_manager()->max_renderbuffer_size()) { |
| 4797 SetGLError(GL_INVALID_VALUE, | 4819 SetGLError(GL_INVALID_VALUE, |
| 4798 "glGetRenderbufferStorageMultisample", "size too large"); | 4820 "glRenderbufferStorageMultisample", "dimensions too large"); |
| 4799 return; | 4821 return; |
| 4800 } | 4822 } |
| 4801 | 4823 |
| 4802 GLenum impl_format = internalformat; | 4824 uint32 estimated_size = 0; |
| 4803 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { | 4825 if (!RenderbufferManager::ComputeEstimatedRenderbufferSize( |
| 4804 switch (impl_format) { | 4826 width, height, samples, internalformat, &estimated_size)) { |
| 4805 case GL_DEPTH_COMPONENT16: | 4827 SetGLError(GL_OUT_OF_MEMORY, |
| 4806 impl_format = GL_DEPTH_COMPONENT; | 4828 "glRenderbufferStorageMultsampleEXT", "dimensions too large"); |
| 4807 break; | 4829 return; |
| 4808 case GL_RGBA4: | |
| 4809 case GL_RGB5_A1: | |
| 4810 impl_format = GL_RGBA; | |
| 4811 break; | |
| 4812 case GL_RGB565: | |
| 4813 impl_format = GL_RGB; | |
| 4814 break; | |
| 4815 } | |
| 4816 } | 4830 } |
| 4817 | 4831 |
| 4832 if (!EnsureGPUMemoryAvailable(estimated_size)) { |
| 4833 SetGLError(GL_OUT_OF_MEMORY, |
| 4834 "glRenderbufferStorageMultsampleEXT", "out of memory"); |
| 4835 return; |
| 4836 } |
| 4837 |
| 4838 GLenum impl_format = RenderbufferManager:: |
| 4839 InternalRenderbufferFormatToImplFormat(internalformat); |
| 4818 CopyRealGLErrorsToWrapper(); | 4840 CopyRealGLErrorsToWrapper(); |
| 4819 if (IsAngle()) { | 4841 if (IsAngle()) { |
| 4820 glRenderbufferStorageMultisampleANGLE( | 4842 glRenderbufferStorageMultisampleANGLE( |
| 4821 target, samples, impl_format, width, height); | 4843 target, samples, impl_format, width, height); |
| 4822 } else { | 4844 } else { |
| 4823 glRenderbufferStorageMultisampleEXT( | 4845 glRenderbufferStorageMultisampleEXT( |
| 4824 target, samples, impl_format, width, height); | 4846 target, samples, impl_format, width, height); |
| 4825 } | 4847 } |
| 4826 GLenum error = PeekGLError(); | 4848 GLenum error = PeekGLError(); |
| 4827 if (error == GL_NO_ERROR) { | 4849 if (error == GL_NO_ERROR) { |
| 4828 // TODO(gman): If renderbuffers tracked which framebuffers they were | 4850 // TODO(gman): If renderbuffers tracked which framebuffers they were |
| 4829 // attached to we could just mark those framebuffers as not complete. | 4851 // attached to we could just mark those framebuffers as not complete. |
| 4830 framebuffer_manager()->IncFramebufferStateChangeCount(); | 4852 framebuffer_manager()->IncFramebufferStateChangeCount(); |
| 4831 renderbuffer_manager()->SetInfo( | 4853 renderbuffer_manager()->SetInfo( |
| 4832 renderbuffer, samples, internalformat, width, height); | 4854 renderbuffer, samples, internalformat, width, height); |
| 4833 } | 4855 } |
| 4834 } | 4856 } |
| 4835 | 4857 |
| 4836 void GLES2DecoderImpl::DoRenderbufferStorage( | 4858 void GLES2DecoderImpl::DoRenderbufferStorage( |
| 4837 GLenum target, GLenum internalformat, GLsizei width, GLsizei height) { | 4859 GLenum target, GLenum internalformat, GLsizei width, GLsizei height) { |
| 4838 RenderbufferManager::RenderbufferInfo* renderbuffer = | 4860 RenderbufferManager::RenderbufferInfo* renderbuffer = |
| 4839 GetRenderbufferInfoForTarget(GL_RENDERBUFFER); | 4861 GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 4840 if (!renderbuffer) { | 4862 if (!renderbuffer) { |
| 4841 SetGLError(GL_INVALID_OPERATION, | 4863 SetGLError(GL_INVALID_OPERATION, |
| 4842 "glGetRenderbufferStorage", "no renderbuffer bound"); | 4864 "glRenderbufferStorage", "no renderbuffer bound"); |
| 4843 return; | 4865 return; |
| 4844 } | 4866 } |
| 4845 | 4867 |
| 4846 if (width > renderbuffer_manager()->max_renderbuffer_size() || | 4868 if (width > renderbuffer_manager()->max_renderbuffer_size() || |
| 4847 height > renderbuffer_manager()->max_renderbuffer_size()) { | 4869 height > renderbuffer_manager()->max_renderbuffer_size()) { |
| 4848 SetGLError(GL_INVALID_VALUE, | 4870 SetGLError(GL_INVALID_VALUE, |
| 4849 "glGetRenderbufferStorage", "size too large"); | 4871 "glRenderbufferStorage", "dimensions too large"); |
| 4850 return; | 4872 return; |
| 4851 } | 4873 } |
| 4852 | 4874 |
| 4853 GLenum impl_format = internalformat; | 4875 uint32 estimated_size = 0; |
| 4854 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { | 4876 if (!RenderbufferManager::ComputeEstimatedRenderbufferSize( |
| 4855 switch (impl_format) { | 4877 width, height, 1, internalformat, &estimated_size)) { |
| 4856 case GL_DEPTH_COMPONENT16: | 4878 SetGLError(GL_OUT_OF_MEMORY, "glRenderbufferStorage", |
| 4857 impl_format = GL_DEPTH_COMPONENT; | 4879 "dimensions too large"); |
| 4858 break; | 4880 return; |
| 4859 case GL_RGBA4: | 4881 } |
| 4860 case GL_RGB5_A1: | 4882 |
| 4861 impl_format = GL_RGBA; | 4883 if (!EnsureGPUMemoryAvailable(estimated_size)) { |
| 4862 break; | 4884 SetGLError(GL_OUT_OF_MEMORY, "glRenderbufferStorage", "out of memory"); |
| 4863 case GL_RGB565: | 4885 return; |
| 4864 impl_format = GL_RGB; | |
| 4865 break; | |
| 4866 } | |
| 4867 } | 4886 } |
| 4868 | 4887 |
| 4869 CopyRealGLErrorsToWrapper(); | 4888 CopyRealGLErrorsToWrapper(); |
| 4870 glRenderbufferStorageEXT(target, impl_format, width, height); | 4889 glRenderbufferStorageEXT( |
| 4890 target, RenderbufferManager:: |
| 4891 InternalRenderbufferFormatToImplFormat(internalformat), |
| 4892 width, height); |
| 4871 GLenum error = PeekGLError(); | 4893 GLenum error = PeekGLError(); |
| 4872 if (error == GL_NO_ERROR) { | 4894 if (error == GL_NO_ERROR) { |
| 4873 // TODO(gman): If tetxures tracked which framebuffers they were attached to | 4895 // TODO(gman): If tetxures tracked which framebuffers they were attached to |
| 4874 // we could just mark those framebuffers as not complete. | 4896 // we could just mark those framebuffers as not complete. |
| 4875 framebuffer_manager()->IncFramebufferStateChangeCount(); | 4897 framebuffer_manager()->IncFramebufferStateChangeCount(); |
| 4876 renderbuffer_manager()->SetInfo( | 4898 renderbuffer_manager()->SetInfo( |
| 4877 renderbuffer, 0, internalformat, width, height); | 4899 renderbuffer, 1, internalformat, width, height); |
| 4878 } | 4900 } |
| 4879 } | 4901 } |
| 4880 | 4902 |
| 4881 void GLES2DecoderImpl::DoLinkProgram(GLuint program) { | 4903 void GLES2DecoderImpl::DoLinkProgram(GLuint program) { |
| 4882 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoLinkProgram"); | 4904 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoLinkProgram"); |
| 4883 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( | 4905 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 4884 program, "glLinkProgram"); | 4906 program, "glLinkProgram"); |
| 4885 if (!info) { | 4907 if (!info) { |
| 4886 return; | 4908 return; |
| 4887 } | 4909 } |
| (...skipping 2196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7084 } | 7106 } |
| 7085 if (size < 0) { | 7107 if (size < 0) { |
| 7086 SetGLError(GL_INVALID_VALUE, "glBufferData", "size < 0"); | 7108 SetGLError(GL_INVALID_VALUE, "glBufferData", "size < 0"); |
| 7087 return; | 7109 return; |
| 7088 } | 7110 } |
| 7089 BufferManager::BufferInfo* info = GetBufferInfoForTarget(target); | 7111 BufferManager::BufferInfo* info = GetBufferInfoForTarget(target); |
| 7090 if (!info) { | 7112 if (!info) { |
| 7091 SetGLError(GL_INVALID_VALUE, "glBufferData", "unknown buffer"); | 7113 SetGLError(GL_INVALID_VALUE, "glBufferData", "unknown buffer"); |
| 7092 return; | 7114 return; |
| 7093 } | 7115 } |
| 7116 |
| 7117 if (!EnsureGPUMemoryAvailable(size)) { |
| 7118 SetGLError(GL_OUT_OF_MEMORY, "glBufferData", "out of memory"); |
| 7119 return; |
| 7120 } |
| 7121 |
| 7094 // Clear the buffer to 0 if no initial data was passed in. | 7122 // Clear the buffer to 0 if no initial data was passed in. |
| 7095 scoped_array<int8> zero; | 7123 scoped_array<int8> zero; |
| 7096 if (!data) { | 7124 if (!data) { |
| 7097 zero.reset(new int8[size]); | 7125 zero.reset(new int8[size]); |
| 7098 memset(zero.get(), 0, size); | 7126 memset(zero.get(), 0, size); |
| 7099 data = zero.get(); | 7127 data = zero.get(); |
| 7100 } | 7128 } |
| 7101 | 7129 |
| 7102 CopyRealGLErrorsToWrapper(); | 7130 CopyRealGLErrorsToWrapper(); |
| 7103 glBufferData(target, size, data, usage); | 7131 glBufferData(target, size, data, usage); |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7435 return error::kNoError; | 7463 return error::kNoError; |
| 7436 } | 7464 } |
| 7437 | 7465 |
| 7438 if (!ValidateCompressedTexDimensions( | 7466 if (!ValidateCompressedTexDimensions( |
| 7439 "glCompressedTexImage2D", level, width, height, internal_format) || | 7467 "glCompressedTexImage2D", level, width, height, internal_format) || |
| 7440 !ValidateCompressedTexFuncData( | 7468 !ValidateCompressedTexFuncData( |
| 7441 "glCompressedTexImage2D", width, height, internal_format, image_size)) { | 7469 "glCompressedTexImage2D", width, height, internal_format, image_size)) { |
| 7442 return error::kNoError; | 7470 return error::kNoError; |
| 7443 } | 7471 } |
| 7444 | 7472 |
| 7473 if (!EnsureGPUMemoryAvailable(image_size)) { |
| 7474 SetGLError(GL_OUT_OF_MEMORY, "glCompressedTexImage2D", "out of memory"); |
| 7475 return error::kNoError; |
| 7476 } |
| 7477 |
| 7445 if (info->IsAttachedToFramebuffer()) { | 7478 if (info->IsAttachedToFramebuffer()) { |
| 7446 clear_state_dirty_ = true; | 7479 clear_state_dirty_ = true; |
| 7447 // TODO(gman): If textures tracked which framebuffers they were attached to | 7480 // TODO(gman): If textures tracked which framebuffers they were attached to |
| 7448 // we could just mark those framebuffers as not complete. | 7481 // we could just mark those framebuffers as not complete. |
| 7449 framebuffer_manager()->IncFramebufferStateChangeCount(); | 7482 framebuffer_manager()->IncFramebufferStateChangeCount(); |
| 7450 } | 7483 } |
| 7451 | 7484 |
| 7452 scoped_array<int8> zero; | 7485 scoped_array<int8> zero; |
| 7453 if (!data) { | 7486 if (!data) { |
| 7454 zero.reset(new int8[image_size]); | 7487 zero.reset(new int8[image_size]); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7669 GLsizei height, | 7702 GLsizei height, |
| 7670 GLint border, | 7703 GLint border, |
| 7671 GLenum format, | 7704 GLenum format, |
| 7672 GLenum type, | 7705 GLenum type, |
| 7673 const void* pixels, | 7706 const void* pixels, |
| 7674 uint32 pixels_size) { | 7707 uint32 pixels_size) { |
| 7675 if (!ValidateTexImage2D("glTexImage2D", target, level, internal_format, | 7708 if (!ValidateTexImage2D("glTexImage2D", target, level, internal_format, |
| 7676 width, height, border, format, type, pixels, pixels_size)) { | 7709 width, height, border, format, type, pixels, pixels_size)) { |
| 7677 return; | 7710 return; |
| 7678 } | 7711 } |
| 7712 |
| 7713 if (!EnsureGPUMemoryAvailable(pixels_size)) { |
| 7714 SetGLError(GL_OUT_OF_MEMORY, "glTexImage2D", "out of memory"); |
| 7715 return; |
| 7716 } |
| 7717 |
| 7679 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); | 7718 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 7680 GLsizei tex_width = 0; | 7719 GLsizei tex_width = 0; |
| 7681 GLsizei tex_height = 0; | 7720 GLsizei tex_height = 0; |
| 7682 GLenum tex_type = 0; | 7721 GLenum tex_type = 0; |
| 7683 GLenum tex_format = 0; | 7722 GLenum tex_format = 0; |
| 7684 bool level_is_same = | 7723 bool level_is_same = |
| 7685 info->GetLevelSize(target, level, &tex_width, &tex_height) && | 7724 info->GetLevelSize(target, level, &tex_width, &tex_height) && |
| 7686 info->GetLevelType(target, level, &tex_type, &tex_format) && | 7725 info->GetLevelType(target, level, &tex_type, &tex_format) && |
| 7687 width == tex_width && height == tex_height && | 7726 width == tex_width && height == tex_height && |
| 7688 type == tex_type && format == tex_format; | 7727 type == tex_type && format == tex_format; |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7895 uint32 channels_needed = GLES2Util::GetChannelsForFormat(internal_format); | 7934 uint32 channels_needed = GLES2Util::GetChannelsForFormat(internal_format); |
| 7896 | 7935 |
| 7897 if ((channels_needed & channels_exist) != channels_needed) { | 7936 if ((channels_needed & channels_exist) != channels_needed) { |
| 7898 SetGLError(GL_INVALID_OPERATION, "glCopyTexImage2D", "incompatible format"); | 7937 SetGLError(GL_INVALID_OPERATION, "glCopyTexImage2D", "incompatible format"); |
| 7899 return; | 7938 return; |
| 7900 } | 7939 } |
| 7901 | 7940 |
| 7902 if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { | 7941 if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
| 7903 SetGLError( | 7942 SetGLError( |
| 7904 GL_INVALID_OPERATION, | 7943 GL_INVALID_OPERATION, |
| 7905 "glCopyImage2D", "can not be used with depth or stencil textures"); | 7944 "glCopyTexImage2D", "can not be used with depth or stencil textures"); |
| 7906 return; | 7945 return; |
| 7907 } | 7946 } |
| 7908 | 7947 |
| 7948 uint32 estimated_size = 0; |
| 7949 if (!GLES2Util::ComputeImageDataSizes( |
| 7950 width, height, internal_format, GL_UNSIGNED_BYTE, state_.unpack_alignment, |
| 7951 &estimated_size, NULL, NULL)) { |
| 7952 SetGLError(GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too large"); |
| 7953 return; |
| 7954 } |
| 7955 |
| 7956 if (!EnsureGPUMemoryAvailable(estimated_size)) { |
| 7957 SetGLError(GL_OUT_OF_MEMORY, "glCopyTexImage2D", "out of memory"); |
| 7958 return; |
| 7959 } |
| 7960 |
| 7909 if (!CheckBoundFramebuffersValid("glCopyTexImage2D")) { | 7961 if (!CheckBoundFramebuffersValid("glCopyTexImage2D")) { |
| 7910 return; | 7962 return; |
| 7911 } | 7963 } |
| 7912 | 7964 |
| 7913 CopyRealGLErrorsToWrapper(); | 7965 CopyRealGLErrorsToWrapper(); |
| 7914 ScopedResolvedFrameBufferBinder binder(this, false, true); | 7966 ScopedResolvedFrameBufferBinder binder(this, false, true); |
| 7915 gfx::Size size = GetBoundReadFrameBufferSize(); | 7967 gfx::Size size = GetBoundReadFrameBufferSize(); |
| 7916 | 7968 |
| 7917 if (info->IsAttachedToFramebuffer()) { | 7969 if (info->IsAttachedToFramebuffer()) { |
| 7918 clear_state_dirty_ = true; | 7970 clear_state_dirty_ = true; |
| (...skipping 1649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9568 return; | 9620 return; |
| 9569 } | 9621 } |
| 9570 if (info->IsAttachedToFramebuffer()) { | 9622 if (info->IsAttachedToFramebuffer()) { |
| 9571 clear_state_dirty_ = true; | 9623 clear_state_dirty_ = true; |
| 9572 } | 9624 } |
| 9573 if (info->IsImmutable()) { | 9625 if (info->IsImmutable()) { |
| 9574 SetGLError(GL_INVALID_OPERATION, | 9626 SetGLError(GL_INVALID_OPERATION, |
| 9575 "glTexStorage2DEXT", "texture is immutable"); | 9627 "glTexStorage2DEXT", "texture is immutable"); |
| 9576 return; | 9628 return; |
| 9577 } | 9629 } |
| 9630 |
| 9631 GLenum format = ExtractFormatFromStorageFormat(internal_format); |
| 9632 GLenum type = ExtractTypeFromStorageFormat(internal_format); |
| 9633 |
| 9634 { |
| 9635 GLsizei level_width = width; |
| 9636 GLsizei level_height = height; |
| 9637 uint32 estimated_size = 0; |
| 9638 for (int ii = 0; ii < levels; ++ii) { |
| 9639 uint32 level_size = 0; |
| 9640 if (!GLES2Util::ComputeImageDataSizes( |
| 9641 level_width, level_height, format, type, state_.unpack_alignment, |
| 9642 &estimated_size, NULL, NULL) || |
| 9643 !SafeAddUint32(estimated_size, level_size, &estimated_size)) { |
| 9644 SetGLError(GL_OUT_OF_MEMORY, |
| 9645 "glTexStorage2DEXT", "dimensions too large"); |
| 9646 return; |
| 9647 } |
| 9648 level_width = std::max(1, level_width >> 1); |
| 9649 level_height = std::max(1, level_height >> 1); |
| 9650 } |
| 9651 if (!EnsureGPUMemoryAvailable(estimated_size)) { |
| 9652 SetGLError(GL_OUT_OF_MEMORY, "glTexStorage2DEXT", "out of memory"); |
| 9653 return; |
| 9654 } |
| 9655 } |
| 9656 |
| 9578 CopyRealGLErrorsToWrapper(); | 9657 CopyRealGLErrorsToWrapper(); |
| 9579 glTexStorage2DEXT(target, levels, GetTexInternalFormat(internal_format), | 9658 glTexStorage2DEXT(target, levels, GetTexInternalFormat(internal_format), |
| 9580 width, height); | 9659 width, height); |
| 9581 GLenum error = PeekGLError(); | 9660 GLenum error = PeekGLError(); |
| 9582 if (error == GL_NO_ERROR) { | 9661 if (error == GL_NO_ERROR) { |
| 9583 GLenum format = ExtractFormatFromStorageFormat(internal_format); | |
| 9584 GLenum type = ExtractTypeFromStorageFormat(internal_format); | |
| 9585 GLsizei level_width = width; | 9662 GLsizei level_width = width; |
| 9586 GLsizei level_height = height; | 9663 GLsizei level_height = height; |
| 9587 for (int ii = 0; ii < levels; ++ii) { | 9664 for (int ii = 0; ii < levels; ++ii) { |
| 9588 texture_manager()->SetLevelInfo( | 9665 texture_manager()->SetLevelInfo( |
| 9589 info, target, ii, format, level_width, level_height, 1, 0, format, | 9666 info, target, ii, format, level_width, level_height, 1, 0, format, |
| 9590 type, false); | 9667 type, false); |
| 9591 level_width = std::max(1, level_width >> 1); | 9668 level_width = std::max(1, level_width >> 1); |
| 9592 level_height = std::max(1, level_height >> 1); | 9669 level_height = std::max(1, level_height >> 1); |
| 9593 } | 9670 } |
| 9594 info->SetImmutable(true); | 9671 info->SetImmutable(true); |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9876 "glAsyncTexImage2DCHROMIUM", info, target, level, pixels)) | 9953 "glAsyncTexImage2DCHROMIUM", info, target, level, pixels)) |
| 9877 return error::kNoError; | 9954 return error::kNoError; |
| 9878 | 9955 |
| 9879 // Don't allow async redefinition of a textures. | 9956 // Don't allow async redefinition of a textures. |
| 9880 if (info->IsDefined()) { | 9957 if (info->IsDefined()) { |
| 9881 SetGLError(GL_INVALID_OPERATION, | 9958 SetGLError(GL_INVALID_OPERATION, |
| 9882 "glAsyncTexImage2DCHROMIUM", "already defined"); | 9959 "glAsyncTexImage2DCHROMIUM", "already defined"); |
| 9883 return error::kNoError; | 9960 return error::kNoError; |
| 9884 } | 9961 } |
| 9885 | 9962 |
| 9963 if (!EnsureGPUMemoryAvailable(pixels_size)) { |
| 9964 SetGLError(GL_OUT_OF_MEMORY, "glAsyncTexImage2DCHROMIUM", "out of memory"); |
| 9965 return error::kNoError; |
| 9966 } |
| 9967 |
| 9886 // We know the memory/size is safe, so get the real shared memory since | 9968 // We know the memory/size is safe, so get the real shared memory since |
| 9887 // it might need to be duped to prevent use-after-free of the memory. | 9969 // it might need to be duped to prevent use-after-free of the memory. |
| 9888 Buffer buffer = GetSharedMemoryBuffer(c.pixels_shm_id); | 9970 Buffer buffer = GetSharedMemoryBuffer(c.pixels_shm_id); |
| 9889 base::SharedMemory* shared_memory = buffer.shared_memory; | 9971 base::SharedMemory* shared_memory = buffer.shared_memory; |
| 9890 uint32 shm_size = buffer.size; | 9972 uint32 shm_size = buffer.size; |
| 9891 uint32 shm_data_offset = c.pixels_shm_offset; | 9973 uint32 shm_data_offset = c.pixels_shm_offset; |
| 9892 uint32 shm_data_size = pixels_size; | 9974 uint32 shm_data_size = pixels_size; |
| 9893 | 9975 |
| 9894 // Set up the async state if needed, and make the texture | 9976 // Set up the async state if needed, and make the texture |
| 9895 // immutable so the async state stays valid. The level info | 9977 // immutable so the async state stays valid. The level info |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9995 return error::kNoError; | 10077 return error::kNoError; |
| 9996 } | 10078 } |
| 9997 | 10079 |
| 9998 // Include the auto-generated part of this file. We split this because it means | 10080 // Include the auto-generated part of this file. We split this because it means |
| 9999 // we can easily edit the non-auto generated parts right here in this file | 10081 // we can easily edit the non-auto generated parts right here in this file |
| 10000 // instead of having to edit some template or the code generator. | 10082 // instead of having to edit some template or the code generator. |
| 10001 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 10083 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 10002 | 10084 |
| 10003 } // namespace gles2 | 10085 } // namespace gles2 |
| 10004 } // namespace gpu | 10086 } // namespace gpu |
| OLD | NEW |