| 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 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 return size_; | 371 return size_; |
| 372 } | 372 } |
| 373 | 373 |
| 374 size_t estimated_size() const { | 374 size_t estimated_size() const { |
| 375 return memory_tracker_.GetMemRepresented(); | 375 return memory_tracker_.GetMemRepresented(); |
| 376 } | 376 } |
| 377 | 377 |
| 378 private: | 378 private: |
| 379 GLES2DecoderImpl* decoder_; | 379 GLES2DecoderImpl* decoder_; |
| 380 MemoryTypeTracker memory_tracker_; | 380 MemoryTypeTracker memory_tracker_; |
| 381 size_t bytes_allocated_; |
| 381 GLuint id_; | 382 GLuint id_; |
| 382 gfx::Size size_; | 383 gfx::Size size_; |
| 383 DISALLOW_COPY_AND_ASSIGN(Texture); | 384 DISALLOW_COPY_AND_ASSIGN(Texture); |
| 384 }; | 385 }; |
| 385 | 386 |
| 386 // Encapsulates an OpenGL render buffer of any format. | 387 // Encapsulates an OpenGL render buffer of any format. |
| 387 class RenderBuffer { | 388 class RenderBuffer { |
| 388 public: | 389 public: |
| 389 explicit RenderBuffer(GLES2DecoderImpl* decoder); | 390 explicit RenderBuffer(GLES2DecoderImpl* decoder); |
| 390 ~RenderBuffer(); | 391 ~RenderBuffer(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 407 return id_; | 408 return id_; |
| 408 } | 409 } |
| 409 | 410 |
| 410 size_t estimated_size() const { | 411 size_t estimated_size() const { |
| 411 return memory_tracker_.GetMemRepresented(); | 412 return memory_tracker_.GetMemRepresented(); |
| 412 } | 413 } |
| 413 | 414 |
| 414 private: | 415 private: |
| 415 GLES2DecoderImpl* decoder_; | 416 GLES2DecoderImpl* decoder_; |
| 416 MemoryTypeTracker memory_tracker_; | 417 MemoryTypeTracker memory_tracker_; |
| 418 size_t bytes_allocated_; |
| 417 GLuint id_; | 419 GLuint id_; |
| 418 DISALLOW_COPY_AND_ASSIGN(RenderBuffer); | 420 DISALLOW_COPY_AND_ASSIGN(RenderBuffer); |
| 419 }; | 421 }; |
| 420 | 422 |
| 421 // Encapsulates an OpenGL frame buffer. | 423 // Encapsulates an OpenGL frame buffer. |
| 422 class FrameBuffer { | 424 class FrameBuffer { |
| 423 public: | 425 public: |
| 424 explicit FrameBuffer(GLES2DecoderImpl* decoder); | 426 explicit FrameBuffer(GLES2DecoderImpl* decoder); |
| 425 ~FrameBuffer(); | 427 ~FrameBuffer(); |
| 426 | 428 |
| (...skipping 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1783 } | 1785 } |
| 1784 | 1786 |
| 1785 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { | 1787 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { |
| 1786 decoder_->texture_upload_count_++; | 1788 decoder_->texture_upload_count_++; |
| 1787 decoder_->total_texture_upload_time_ += | 1789 decoder_->total_texture_upload_time_ += |
| 1788 base::TimeTicks::HighResNow() - begin_time_; | 1790 base::TimeTicks::HighResNow() - begin_time_; |
| 1789 } | 1791 } |
| 1790 | 1792 |
| 1791 Texture::Texture(GLES2DecoderImpl* decoder) | 1793 Texture::Texture(GLES2DecoderImpl* decoder) |
| 1792 : decoder_(decoder), | 1794 : decoder_(decoder), |
| 1793 memory_tracker_(decoder->GetContextGroup()->memory_tracker()), | 1795 memory_tracker_(decoder->GetContextGroup()->memory_tracker(), |
| 1796 MemoryTracker::Unmanaged), |
| 1797 bytes_allocated_(0), |
| 1794 id_(0) { | 1798 id_(0) { |
| 1795 } | 1799 } |
| 1796 | 1800 |
| 1797 Texture::~Texture() { | 1801 Texture::~Texture() { |
| 1798 // This does not destroy the render texture because that would require that | 1802 // This does not destroy the render texture because that would require that |
| 1799 // the associated GL context was current. Just check that it was explicitly | 1803 // the associated GL context was current. Just check that it was explicitly |
| 1800 // destroyed. | 1804 // destroyed. |
| 1801 DCHECK_EQ(id_, 0u); | 1805 DCHECK_EQ(id_, 0u); |
| 1802 } | 1806 } |
| 1803 | 1807 |
| 1804 void Texture::Create() { | 1808 void Texture::Create() { |
| 1805 ScopedGLErrorSuppressor suppressor(decoder_); | 1809 ScopedGLErrorSuppressor suppressor(decoder_); |
| 1806 Destroy(); | 1810 Destroy(); |
| 1807 glGenTextures(1, &id_); | 1811 glGenTextures(1, &id_); |
| 1808 ScopedTexture2DBinder binder(decoder_, id_); | 1812 ScopedTexture2DBinder binder(decoder_, id_); |
| 1809 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 1813 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1810 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 1814 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1811 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 1815 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1812 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 1816 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 1813 | 1817 |
| 1814 // TODO(apatrick): Attempt to diagnose crbug.com/97775. If SwapBuffers is | 1818 // TODO(apatrick): Attempt to diagnose crbug.com/97775. If SwapBuffers is |
| 1815 // never called on an offscreen context, no data will ever be uploaded to the | 1819 // never called on an offscreen context, no data will ever be uploaded to the |
| 1816 // saved offscreen color texture (it is deferred until to when SwapBuffers | 1820 // saved offscreen color texture (it is deferred until to when SwapBuffers |
| 1817 // is called). My idea is that some nvidia drivers might have a bug where | 1821 // is called). My idea is that some nvidia drivers might have a bug where |
| 1818 // deleting a texture that has never been populated might cause a | 1822 // deleting a texture that has never been populated might cause a |
| 1819 // crash. | 1823 // crash. |
| 1820 glTexImage2D( | 1824 glTexImage2D( |
| 1821 GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 1825 GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 1822 memory_tracker_.UpdateMemRepresented(16u * 16u * 4u); | 1826 |
| 1827 bytes_allocated_ = 16u * 16u * 4u; |
| 1828 memory_tracker_.TrackMemAlloc(bytes_allocated_); |
| 1823 } | 1829 } |
| 1824 | 1830 |
| 1825 bool Texture::AllocateStorage(const gfx::Size& size, GLenum format) { | 1831 bool Texture::AllocateStorage(const gfx::Size& size, GLenum format) { |
| 1826 DCHECK_NE(id_, 0u); | 1832 DCHECK_NE(id_, 0u); |
| 1827 ScopedGLErrorSuppressor suppressor(decoder_); | 1833 ScopedGLErrorSuppressor suppressor(decoder_); |
| 1828 ScopedTexture2DBinder binder(decoder_, id_); | 1834 ScopedTexture2DBinder binder(decoder_, id_); |
| 1829 | 1835 |
| 1830 WrappedTexImage2D(GL_TEXTURE_2D, | 1836 WrappedTexImage2D(GL_TEXTURE_2D, |
| 1831 0, // mip level | 1837 0, // mip level |
| 1832 format, | 1838 format, |
| 1833 size.width(), | 1839 size.width(), |
| 1834 size.height(), | 1840 size.height(), |
| 1835 0, // border | 1841 0, // border |
| 1836 format, | 1842 format, |
| 1837 GL_UNSIGNED_BYTE, | 1843 GL_UNSIGNED_BYTE, |
| 1838 NULL); | 1844 NULL); |
| 1839 | 1845 |
| 1840 size_ = size; | 1846 size_ = size; |
| 1841 | 1847 |
| 1842 bool success = glGetError() == GL_NO_ERROR; | 1848 bool success = glGetError() == GL_NO_ERROR; |
| 1843 if (success) { | 1849 if (success) { |
| 1844 uint32 image_size = 0; | 1850 uint32 image_size = 0; |
| 1845 GLES2Util::ComputeImageDataSizes( | 1851 GLES2Util::ComputeImageDataSizes( |
| 1846 size.width(), size.height(), format, GL_UNSIGNED_BYTE, 4, &image_size, | 1852 size.width(), size.height(), format, GL_UNSIGNED_BYTE, 4, &image_size, |
| 1847 NULL, NULL); | 1853 NULL, NULL); |
| 1848 memory_tracker_.UpdateMemRepresented(image_size); | 1854 memory_tracker_.TrackMemFree(bytes_allocated_); |
| 1855 bytes_allocated_ = image_size; |
| 1856 memory_tracker_.TrackMemAlloc(bytes_allocated_); |
| 1849 } | 1857 } |
| 1850 return success; | 1858 return success; |
| 1851 } | 1859 } |
| 1852 | 1860 |
| 1853 void Texture::Copy(const gfx::Size& size, GLenum format) { | 1861 void Texture::Copy(const gfx::Size& size, GLenum format) { |
| 1854 DCHECK_NE(id_, 0u); | 1862 DCHECK_NE(id_, 0u); |
| 1855 ScopedGLErrorSuppressor suppressor(decoder_); | 1863 ScopedGLErrorSuppressor suppressor(decoder_); |
| 1856 ScopedTexture2DBinder binder(decoder_, id_); | 1864 ScopedTexture2DBinder binder(decoder_, id_); |
| 1857 glCopyTexImage2D(GL_TEXTURE_2D, | 1865 glCopyTexImage2D(GL_TEXTURE_2D, |
| 1858 0, // level | 1866 0, // level |
| 1859 format, | 1867 format, |
| 1860 0, 0, | 1868 0, 0, |
| 1861 size.width(), | 1869 size.width(), |
| 1862 size.height(), | 1870 size.height(), |
| 1863 0); // border | 1871 0); // border |
| 1864 } | 1872 } |
| 1865 | 1873 |
| 1866 void Texture::Destroy() { | 1874 void Texture::Destroy() { |
| 1867 if (id_ != 0) { | 1875 if (id_ != 0) { |
| 1868 ScopedGLErrorSuppressor suppressor(decoder_); | 1876 ScopedGLErrorSuppressor suppressor(decoder_); |
| 1869 glDeleteTextures(1, &id_); | 1877 glDeleteTextures(1, &id_); |
| 1870 id_ = 0; | 1878 id_ = 0; |
| 1871 memory_tracker_.UpdateMemRepresented(0); | |
| 1872 } | 1879 } |
| 1880 memory_tracker_.TrackMemFree(bytes_allocated_); |
| 1881 bytes_allocated_ = 0; |
| 1873 } | 1882 } |
| 1874 | 1883 |
| 1875 void Texture::Invalidate() { | 1884 void Texture::Invalidate() { |
| 1876 id_ = 0; | 1885 id_ = 0; |
| 1877 } | 1886 } |
| 1878 | 1887 |
| 1879 RenderBuffer::RenderBuffer(GLES2DecoderImpl* decoder) | 1888 RenderBuffer::RenderBuffer(GLES2DecoderImpl* decoder) |
| 1880 : decoder_(decoder), | 1889 : decoder_(decoder), |
| 1881 memory_tracker_(decoder->GetContextGroup()->memory_tracker()), | 1890 memory_tracker_(decoder->GetContextGroup()->memory_tracker(), |
| 1891 MemoryTracker::Unmanaged), |
| 1892 bytes_allocated_(0), |
| 1882 id_(0) { | 1893 id_(0) { |
| 1883 } | 1894 } |
| 1884 | 1895 |
| 1885 RenderBuffer::~RenderBuffer() { | 1896 RenderBuffer::~RenderBuffer() { |
| 1886 // This does not destroy the render buffer because that would require that | 1897 // This does not destroy the render buffer because that would require that |
| 1887 // 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 |
| 1888 // destroyed. | 1899 // destroyed. |
| 1889 DCHECK_EQ(id_, 0u); | 1900 DCHECK_EQ(id_, 0u); |
| 1890 } | 1901 } |
| 1891 | 1902 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1914 } else { | 1925 } else { |
| 1915 glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, | 1926 glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, |
| 1916 samples, | 1927 samples, |
| 1917 format, | 1928 format, |
| 1918 size.width(), | 1929 size.width(), |
| 1919 size.height()); | 1930 size.height()); |
| 1920 } | 1931 } |
| 1921 } | 1932 } |
| 1922 bool success = glGetError() == GL_NO_ERROR; | 1933 bool success = glGetError() == GL_NO_ERROR; |
| 1923 if (success) { | 1934 if (success) { |
| 1924 memory_tracker_.UpdateMemRepresented( | 1935 memory_tracker_.TrackMemFree(bytes_allocated_); |
| 1936 bytes_allocated_ = |
| 1925 size.width() * size.height() * samples * | 1937 size.width() * size.height() * samples * |
| 1926 GLES2Util::RenderbufferBytesPerPixel(format)); | 1938 GLES2Util::RenderbufferBytesPerPixel(format); |
| 1939 memory_tracker_.TrackMemAlloc(bytes_allocated_); |
| 1927 } | 1940 } |
| 1928 return success; | 1941 return success; |
| 1929 } | 1942 } |
| 1930 | 1943 |
| 1931 void RenderBuffer::Destroy() { | 1944 void RenderBuffer::Destroy() { |
| 1932 if (id_ != 0) { | 1945 if (id_ != 0) { |
| 1933 ScopedGLErrorSuppressor suppressor(decoder_); | 1946 ScopedGLErrorSuppressor suppressor(decoder_); |
| 1934 glDeleteRenderbuffersEXT(1, &id_); | 1947 glDeleteRenderbuffersEXT(1, &id_); |
| 1935 id_ = 0; | 1948 id_ = 0; |
| 1936 memory_tracker_.UpdateMemRepresented(0); | |
| 1937 } | 1949 } |
| 1950 memory_tracker_.TrackMemFree(bytes_allocated_); |
| 1951 bytes_allocated_ = 0; |
| 1938 } | 1952 } |
| 1939 | 1953 |
| 1940 void RenderBuffer::Invalidate() { | 1954 void RenderBuffer::Invalidate() { |
| 1941 id_ = 0; | 1955 id_ = 0; |
| 1942 } | 1956 } |
| 1943 | 1957 |
| 1944 FrameBuffer::FrameBuffer(GLES2DecoderImpl* decoder) | 1958 FrameBuffer::FrameBuffer(GLES2DecoderImpl* decoder) |
| 1945 : decoder_(decoder), | 1959 : decoder_(decoder), |
| 1946 id_(0) { | 1960 id_(0) { |
| 1947 } | 1961 } |
| (...skipping 7704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9652 target, level, xoffset, yoffset, width, height, format, type, pixels); | 9666 target, level, xoffset, yoffset, width, height, format, type, pixels); |
| 9653 } | 9667 } |
| 9654 | 9668 |
| 9655 // Include the auto-generated part of this file. We split this because it means | 9669 // Include the auto-generated part of this file. We split this because it means |
| 9656 // we can easily edit the non-auto generated parts right here in this file | 9670 // we can easily edit the non-auto generated parts right here in this file |
| 9657 // instead of having to edit some template or the code generator. | 9671 // instead of having to edit some template or the code generator. |
| 9658 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 9672 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 9659 | 9673 |
| 9660 } // namespace gles2 | 9674 } // namespace gles2 |
| 9661 } // namespace gpu | 9675 } // namespace gpu |
| OLD | NEW |