| 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 1365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1792 } | 1794 } |
| 1793 | 1795 |
| 1794 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { | 1796 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { |
| 1795 decoder_->texture_upload_count_++; | 1797 decoder_->texture_upload_count_++; |
| 1796 decoder_->total_texture_upload_time_ += | 1798 decoder_->total_texture_upload_time_ += |
| 1797 base::TimeTicks::HighResNow() - begin_time_; | 1799 base::TimeTicks::HighResNow() - begin_time_; |
| 1798 } | 1800 } |
| 1799 | 1801 |
| 1800 Texture::Texture(GLES2DecoderImpl* decoder) | 1802 Texture::Texture(GLES2DecoderImpl* decoder) |
| 1801 : decoder_(decoder), | 1803 : decoder_(decoder), |
| 1802 memory_tracker_(decoder->GetContextGroup()->memory_tracker()), | 1804 memory_tracker_(decoder->GetContextGroup()->memory_tracker(), |
| 1805 MemoryTracker::kUnmanaged), |
| 1806 bytes_allocated_(0), |
| 1803 id_(0) { | 1807 id_(0) { |
| 1804 } | 1808 } |
| 1805 | 1809 |
| 1806 Texture::~Texture() { | 1810 Texture::~Texture() { |
| 1807 // This does not destroy the render texture because that would require that | 1811 // This does not destroy the render texture because that would require that |
| 1808 // the associated GL context was current. Just check that it was explicitly | 1812 // the associated GL context was current. Just check that it was explicitly |
| 1809 // destroyed. | 1813 // destroyed. |
| 1810 DCHECK_EQ(id_, 0u); | 1814 DCHECK_EQ(id_, 0u); |
| 1811 } | 1815 } |
| 1812 | 1816 |
| 1813 void Texture::Create() { | 1817 void Texture::Create() { |
| 1814 ScopedGLErrorSuppressor suppressor(decoder_); | 1818 ScopedGLErrorSuppressor suppressor(decoder_); |
| 1815 Destroy(); | 1819 Destroy(); |
| 1816 glGenTextures(1, &id_); | 1820 glGenTextures(1, &id_); |
| 1817 ScopedTexture2DBinder binder(decoder_, id_); | 1821 ScopedTexture2DBinder binder(decoder_, id_); |
| 1818 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 1822 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1819 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 1823 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1820 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 1824 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1821 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 1825 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 1822 | 1826 |
| 1823 // TODO(apatrick): Attempt to diagnose crbug.com/97775. If SwapBuffers is | 1827 // TODO(apatrick): Attempt to diagnose crbug.com/97775. If SwapBuffers is |
| 1824 // never called on an offscreen context, no data will ever be uploaded to the | 1828 // never called on an offscreen context, no data will ever be uploaded to the |
| 1825 // saved offscreen color texture (it is deferred until to when SwapBuffers | 1829 // saved offscreen color texture (it is deferred until to when SwapBuffers |
| 1826 // is called). My idea is that some nvidia drivers might have a bug where | 1830 // is called). My idea is that some nvidia drivers might have a bug where |
| 1827 // deleting a texture that has never been populated might cause a | 1831 // deleting a texture that has never been populated might cause a |
| 1828 // crash. | 1832 // crash. |
| 1829 glTexImage2D( | 1833 glTexImage2D( |
| 1830 GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 1834 GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 1831 memory_tracker_.UpdateMemRepresented(16u * 16u * 4u); | 1835 |
| 1836 bytes_allocated_ = 16u * 16u * 4u; |
| 1837 memory_tracker_.TrackMemAlloc(bytes_allocated_); |
| 1832 } | 1838 } |
| 1833 | 1839 |
| 1834 bool Texture::AllocateStorage(const gfx::Size& size, GLenum format) { | 1840 bool Texture::AllocateStorage(const gfx::Size& size, GLenum format) { |
| 1835 DCHECK_NE(id_, 0u); | 1841 DCHECK_NE(id_, 0u); |
| 1836 ScopedGLErrorSuppressor suppressor(decoder_); | 1842 ScopedGLErrorSuppressor suppressor(decoder_); |
| 1837 ScopedTexture2DBinder binder(decoder_, id_); | 1843 ScopedTexture2DBinder binder(decoder_, id_); |
| 1838 | 1844 |
| 1839 WrappedTexImage2D(GL_TEXTURE_2D, | 1845 WrappedTexImage2D(GL_TEXTURE_2D, |
| 1840 0, // mip level | 1846 0, // mip level |
| 1841 format, | 1847 format, |
| 1842 size.width(), | 1848 size.width(), |
| 1843 size.height(), | 1849 size.height(), |
| 1844 0, // border | 1850 0, // border |
| 1845 format, | 1851 format, |
| 1846 GL_UNSIGNED_BYTE, | 1852 GL_UNSIGNED_BYTE, |
| 1847 NULL); | 1853 NULL); |
| 1848 | 1854 |
| 1849 size_ = size; | 1855 size_ = size; |
| 1850 | 1856 |
| 1851 bool success = glGetError() == GL_NO_ERROR; | 1857 bool success = glGetError() == GL_NO_ERROR; |
| 1852 if (success) { | 1858 if (success) { |
| 1853 uint32 image_size = 0; | 1859 uint32 image_size = 0; |
| 1854 GLES2Util::ComputeImageDataSizes( | 1860 GLES2Util::ComputeImageDataSizes( |
| 1855 size.width(), size.height(), format, GL_UNSIGNED_BYTE, 4, &image_size, | 1861 size.width(), size.height(), format, GL_UNSIGNED_BYTE, 4, &image_size, |
| 1856 NULL, NULL); | 1862 NULL, NULL); |
| 1857 memory_tracker_.UpdateMemRepresented(image_size); | 1863 memory_tracker_.TrackMemFree(bytes_allocated_); |
| 1864 bytes_allocated_ = image_size; |
| 1865 memory_tracker_.TrackMemAlloc(bytes_allocated_); |
| 1858 } | 1866 } |
| 1859 return success; | 1867 return success; |
| 1860 } | 1868 } |
| 1861 | 1869 |
| 1862 void Texture::Copy(const gfx::Size& size, GLenum format) { | 1870 void Texture::Copy(const gfx::Size& size, GLenum format) { |
| 1863 DCHECK_NE(id_, 0u); | 1871 DCHECK_NE(id_, 0u); |
| 1864 ScopedGLErrorSuppressor suppressor(decoder_); | 1872 ScopedGLErrorSuppressor suppressor(decoder_); |
| 1865 ScopedTexture2DBinder binder(decoder_, id_); | 1873 ScopedTexture2DBinder binder(decoder_, id_); |
| 1866 glCopyTexImage2D(GL_TEXTURE_2D, | 1874 glCopyTexImage2D(GL_TEXTURE_2D, |
| 1867 0, // level | 1875 0, // level |
| 1868 format, | 1876 format, |
| 1869 0, 0, | 1877 0, 0, |
| 1870 size.width(), | 1878 size.width(), |
| 1871 size.height(), | 1879 size.height(), |
| 1872 0); // border | 1880 0); // border |
| 1873 } | 1881 } |
| 1874 | 1882 |
| 1875 void Texture::Destroy() { | 1883 void Texture::Destroy() { |
| 1876 if (id_ != 0) { | 1884 if (id_ != 0) { |
| 1877 ScopedGLErrorSuppressor suppressor(decoder_); | 1885 ScopedGLErrorSuppressor suppressor(decoder_); |
| 1878 glDeleteTextures(1, &id_); | 1886 glDeleteTextures(1, &id_); |
| 1879 id_ = 0; | 1887 id_ = 0; |
| 1880 memory_tracker_.UpdateMemRepresented(0); | |
| 1881 } | 1888 } |
| 1889 memory_tracker_.TrackMemFree(bytes_allocated_); |
| 1890 bytes_allocated_ = 0; |
| 1882 } | 1891 } |
| 1883 | 1892 |
| 1884 void Texture::Invalidate() { | 1893 void Texture::Invalidate() { |
| 1885 id_ = 0; | 1894 id_ = 0; |
| 1886 } | 1895 } |
| 1887 | 1896 |
| 1888 RenderBuffer::RenderBuffer(GLES2DecoderImpl* decoder) | 1897 RenderBuffer::RenderBuffer(GLES2DecoderImpl* decoder) |
| 1889 : decoder_(decoder), | 1898 : decoder_(decoder), |
| 1890 memory_tracker_(decoder->GetContextGroup()->memory_tracker()), | 1899 memory_tracker_(decoder->GetContextGroup()->memory_tracker(), |
| 1900 MemoryTracker::kUnmanaged), |
| 1901 bytes_allocated_(0), |
| 1891 id_(0) { | 1902 id_(0) { |
| 1892 } | 1903 } |
| 1893 | 1904 |
| 1894 RenderBuffer::~RenderBuffer() { | 1905 RenderBuffer::~RenderBuffer() { |
| 1895 // This does not destroy the render buffer because that would require that | 1906 // This does not destroy the render buffer because that would require that |
| 1896 // the associated GL context was current. Just check that it was explicitly | 1907 // the associated GL context was current. Just check that it was explicitly |
| 1897 // destroyed. | 1908 // destroyed. |
| 1898 DCHECK_EQ(id_, 0u); | 1909 DCHECK_EQ(id_, 0u); |
| 1899 } | 1910 } |
| 1900 | 1911 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1923 } else { | 1934 } else { |
| 1924 glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, | 1935 glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, |
| 1925 samples, | 1936 samples, |
| 1926 format, | 1937 format, |
| 1927 size.width(), | 1938 size.width(), |
| 1928 size.height()); | 1939 size.height()); |
| 1929 } | 1940 } |
| 1930 } | 1941 } |
| 1931 bool success = glGetError() == GL_NO_ERROR; | 1942 bool success = glGetError() == GL_NO_ERROR; |
| 1932 if (success) { | 1943 if (success) { |
| 1933 memory_tracker_.UpdateMemRepresented( | 1944 memory_tracker_.TrackMemFree(bytes_allocated_); |
| 1945 bytes_allocated_ = |
| 1934 size.width() * size.height() * samples * | 1946 size.width() * size.height() * samples * |
| 1935 GLES2Util::RenderbufferBytesPerPixel(format)); | 1947 GLES2Util::RenderbufferBytesPerPixel(format); |
| 1948 memory_tracker_.TrackMemAlloc(bytes_allocated_); |
| 1936 } | 1949 } |
| 1937 return success; | 1950 return success; |
| 1938 } | 1951 } |
| 1939 | 1952 |
| 1940 void RenderBuffer::Destroy() { | 1953 void RenderBuffer::Destroy() { |
| 1941 if (id_ != 0) { | 1954 if (id_ != 0) { |
| 1942 ScopedGLErrorSuppressor suppressor(decoder_); | 1955 ScopedGLErrorSuppressor suppressor(decoder_); |
| 1943 glDeleteRenderbuffersEXT(1, &id_); | 1956 glDeleteRenderbuffersEXT(1, &id_); |
| 1944 id_ = 0; | 1957 id_ = 0; |
| 1945 memory_tracker_.UpdateMemRepresented(0); | |
| 1946 } | 1958 } |
| 1959 memory_tracker_.TrackMemFree(bytes_allocated_); |
| 1960 bytes_allocated_ = 0; |
| 1947 } | 1961 } |
| 1948 | 1962 |
| 1949 void RenderBuffer::Invalidate() { | 1963 void RenderBuffer::Invalidate() { |
| 1950 id_ = 0; | 1964 id_ = 0; |
| 1951 } | 1965 } |
| 1952 | 1966 |
| 1953 FrameBuffer::FrameBuffer(GLES2DecoderImpl* decoder) | 1967 FrameBuffer::FrameBuffer(GLES2DecoderImpl* decoder) |
| 1954 : decoder_(decoder), | 1968 : decoder_(decoder), |
| 1955 id_(0) { | 1969 id_(0) { |
| 1956 } | 1970 } |
| (...skipping 7765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9722 target, level, xoffset, yoffset, width, height, format, type, pixels); | 9736 target, level, xoffset, yoffset, width, height, format, type, pixels); |
| 9723 } | 9737 } |
| 9724 | 9738 |
| 9725 // Include the auto-generated part of this file. We split this because it means | 9739 // Include the auto-generated part of this file. We split this because it means |
| 9726 // we can easily edit the non-auto generated parts right here in this file | 9740 // we can easily edit the non-auto generated parts right here in this file |
| 9727 // instead of having to edit some template or the code generator. | 9741 // instead of having to edit some template or the code generator. |
| 9728 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 9742 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 9729 | 9743 |
| 9730 } // namespace gles2 | 9744 } // namespace gles2 |
| 9731 } // namespace gpu | 9745 } // namespace gpu |
| OLD | NEW |