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 20 matching lines...) Expand all Loading... |
31 #include "gpu/command_buffer/service/buffer_manager.h" | 31 #include "gpu/command_buffer/service/buffer_manager.h" |
32 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 32 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
33 #include "gpu/command_buffer/service/context_group.h" | 33 #include "gpu/command_buffer/service/context_group.h" |
34 #include "gpu/command_buffer/service/feature_info.h" | 34 #include "gpu/command_buffer/service/feature_info.h" |
35 #include "gpu/command_buffer/service/framebuffer_manager.h" | 35 #include "gpu/command_buffer/service/framebuffer_manager.h" |
36 #include "gpu/command_buffer/service/gl_utils.h" | 36 #include "gpu/command_buffer/service/gl_utils.h" |
37 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" | 37 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" |
38 #include "gpu/command_buffer/service/gles2_cmd_validation.h" | 38 #include "gpu/command_buffer/service/gles2_cmd_validation.h" |
39 #include "gpu/command_buffer/service/gpu_switches.h" | 39 #include "gpu/command_buffer/service/gpu_switches.h" |
40 #include "gpu/command_buffer/service/mailbox_manager.h" | 40 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 41 #include "gpu/command_buffer/service/memory_tracking.h" |
41 #include "gpu/command_buffer/service/program_manager.h" | 42 #include "gpu/command_buffer/service/program_manager.h" |
42 #include "gpu/command_buffer/service/query_manager.h" | 43 #include "gpu/command_buffer/service/query_manager.h" |
43 #include "gpu/command_buffer/service/renderbuffer_manager.h" | 44 #include "gpu/command_buffer/service/renderbuffer_manager.h" |
44 #include "gpu/command_buffer/service/shader_manager.h" | 45 #include "gpu/command_buffer/service/shader_manager.h" |
45 #include "gpu/command_buffer/service/shader_translator.h" | 46 #include "gpu/command_buffer/service/shader_translator.h" |
46 #include "gpu/command_buffer/service/shader_translator_cache.h" | 47 #include "gpu/command_buffer/service/shader_translator_cache.h" |
47 #include "gpu/command_buffer/service/stream_texture.h" | 48 #include "gpu/command_buffer/service/stream_texture.h" |
48 #include "gpu/command_buffer/service/stream_texture_manager.h" | 49 #include "gpu/command_buffer/service/stream_texture_manager.h" |
49 #include "gpu/command_buffer/service/texture_definition.h" | 50 #include "gpu/command_buffer/service/texture_definition.h" |
50 #include "gpu/command_buffer/service/texture_manager.h" | 51 #include "gpu/command_buffer/service/texture_manager.h" |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 | 342 |
342 GLuint id() const { | 343 GLuint id() const { |
343 return id_; | 344 return id_; |
344 } | 345 } |
345 | 346 |
346 gfx::Size size() const { | 347 gfx::Size size() const { |
347 return size_; | 348 return size_; |
348 } | 349 } |
349 | 350 |
350 size_t estimated_size() const { | 351 size_t estimated_size() const { |
351 return estimated_size_; | 352 return memory_tracker_.GetMemRepresented(); |
352 } | 353 } |
353 | 354 |
354 private: | 355 private: |
355 GLES2DecoderImpl* decoder_; | 356 GLES2DecoderImpl* decoder_; |
| 357 MemoryTypeTracker memory_tracker_; |
356 GLuint id_; | 358 GLuint id_; |
357 gfx::Size size_; | 359 gfx::Size size_; |
358 size_t estimated_size_; | |
359 DISALLOW_COPY_AND_ASSIGN(Texture); | 360 DISALLOW_COPY_AND_ASSIGN(Texture); |
360 }; | 361 }; |
361 | 362 |
362 // Encapsulates an OpenGL render buffer of any format. | 363 // Encapsulates an OpenGL render buffer of any format. |
363 class RenderBuffer { | 364 class RenderBuffer { |
364 public: | 365 public: |
365 explicit RenderBuffer(GLES2DecoderImpl* decoder); | 366 explicit RenderBuffer(GLES2DecoderImpl* decoder); |
366 ~RenderBuffer(); | 367 ~RenderBuffer(); |
367 | 368 |
368 // Create a new render buffer. | 369 // Create a new render buffer. |
369 void Create(); | 370 void Create(); |
370 | 371 |
371 // Set the initial size and format of a render buffer or resize it. | 372 // Set the initial size and format of a render buffer or resize it. |
372 bool AllocateStorage(const gfx::Size& size, GLenum format, GLsizei samples); | 373 bool AllocateStorage(const gfx::Size& size, GLenum format, GLsizei samples); |
373 | 374 |
374 // Destroy the render buffer. This must be explicitly called before destroying | 375 // Destroy the render buffer. This must be explicitly called before destroying |
375 // this object. | 376 // this object. |
376 void Destroy(); | 377 void Destroy(); |
377 | 378 |
378 // Invalidate the render buffer. This can be used when a context is lost and | 379 // Invalidate the render buffer. This can be used when a context is lost and |
379 // it is not possible to make it current in order to free the resource. | 380 // it is not possible to make it current in order to free the resource. |
380 void Invalidate(); | 381 void Invalidate(); |
381 | 382 |
382 GLuint id() const { | 383 GLuint id() const { |
383 return id_; | 384 return id_; |
384 } | 385 } |
385 | 386 |
386 size_t estimated_size() const { | 387 size_t estimated_size() const { |
387 return estimated_size_; | 388 return memory_tracker_.GetMemRepresented(); |
388 } | 389 } |
389 | 390 |
390 private: | 391 private: |
391 GLES2DecoderImpl* decoder_; | 392 GLES2DecoderImpl* decoder_; |
| 393 MemoryTypeTracker memory_tracker_; |
392 GLuint id_; | 394 GLuint id_; |
393 size_t estimated_size_; | |
394 DISALLOW_COPY_AND_ASSIGN(RenderBuffer); | 395 DISALLOW_COPY_AND_ASSIGN(RenderBuffer); |
395 }; | 396 }; |
396 | 397 |
397 // Encapsulates an OpenGL frame buffer. | 398 // Encapsulates an OpenGL frame buffer. |
398 class FrameBuffer { | 399 class FrameBuffer { |
399 public: | 400 public: |
400 explicit FrameBuffer(GLES2DecoderImpl* decoder); | 401 explicit FrameBuffer(GLES2DecoderImpl* decoder); |
401 ~FrameBuffer(); | 402 ~FrameBuffer(); |
402 | 403 |
403 // Create a new frame buffer. | 404 // Create a new frame buffer. |
(...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1683 | 1684 |
1684 ScopedGLErrorSuppressor suppressor(decoder_); | 1685 ScopedGLErrorSuppressor suppressor(decoder_); |
1685 decoder_->RestoreCurrentFramebufferBindings(); | 1686 decoder_->RestoreCurrentFramebufferBindings(); |
1686 if (decoder_->enable_scissor_test_) { | 1687 if (decoder_->enable_scissor_test_) { |
1687 glEnable(GL_SCISSOR_TEST); | 1688 glEnable(GL_SCISSOR_TEST); |
1688 } | 1689 } |
1689 } | 1690 } |
1690 | 1691 |
1691 Texture::Texture(GLES2DecoderImpl* decoder) | 1692 Texture::Texture(GLES2DecoderImpl* decoder) |
1692 : decoder_(decoder), | 1693 : decoder_(decoder), |
1693 id_(0), | 1694 memory_tracker_(decoder->GetContextGroup()->memory_tracker(), |
1694 estimated_size_(0) { | 1695 NULL, NULL), |
| 1696 id_(0) { |
1695 } | 1697 } |
1696 | 1698 |
1697 Texture::~Texture() { | 1699 Texture::~Texture() { |
1698 // This does not destroy the render texture because that would require that | 1700 // This does not destroy the render texture because that would require that |
1699 // the associated GL context was current. Just check that it was explicitly | 1701 // the associated GL context was current. Just check that it was explicitly |
1700 // destroyed. | 1702 // destroyed. |
1701 DCHECK_EQ(id_, 0u); | 1703 DCHECK_EQ(id_, 0u); |
1702 } | 1704 } |
1703 | 1705 |
1704 void Texture::Create() { | 1706 void Texture::Create() { |
1705 ScopedGLErrorSuppressor suppressor(decoder_); | 1707 ScopedGLErrorSuppressor suppressor(decoder_); |
1706 Destroy(); | 1708 Destroy(); |
1707 glGenTextures(1, &id_); | 1709 glGenTextures(1, &id_); |
1708 ScopedTexture2DBinder binder(decoder_, id_); | 1710 ScopedTexture2DBinder binder(decoder_, id_); |
1709 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 1711 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1710 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 1712 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
1711 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 1713 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
1712 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 1714 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
1713 | 1715 |
1714 // TODO(apatrick): Attempt to diagnose crbug.com/97775. If SwapBuffers is | 1716 // TODO(apatrick): Attempt to diagnose crbug.com/97775. If SwapBuffers is |
1715 // never called on an offscreen context, no data will ever be uploaded to the | 1717 // never called on an offscreen context, no data will ever be uploaded to the |
1716 // saved offscreen color texture (it is deferred until to when SwapBuffers | 1718 // saved offscreen color texture (it is deferred until to when SwapBuffers |
1717 // is called). My idea is that some nvidia drivers might have a bug where | 1719 // is called). My idea is that some nvidia drivers might have a bug where |
1718 // deleting a texture that has never been populated might cause a | 1720 // deleting a texture that has never been populated might cause a |
1719 // crash. | 1721 // crash. |
1720 glTexImage2D( | 1722 glTexImage2D( |
1721 GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 1723 GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
1722 estimated_size_ = 16u * 16u * 4u; | 1724 memory_tracker_.UpdateMemRepresented(16u * 16u * 4u); |
1723 TRACE_BACKBUFFER_MEMORY_TOTAL(decoder_); | 1725 TRACE_BACKBUFFER_MEMORY_TOTAL(decoder_); |
1724 } | 1726 } |
1725 | 1727 |
1726 bool Texture::AllocateStorage(const gfx::Size& size, GLenum format) { | 1728 bool Texture::AllocateStorage(const gfx::Size& size, GLenum format) { |
1727 DCHECK_NE(id_, 0u); | 1729 DCHECK_NE(id_, 0u); |
1728 ScopedGLErrorSuppressor suppressor(decoder_); | 1730 ScopedGLErrorSuppressor suppressor(decoder_); |
1729 ScopedTexture2DBinder binder(decoder_, id_); | 1731 ScopedTexture2DBinder binder(decoder_, id_); |
1730 | 1732 |
1731 WrappedTexImage2D(GL_TEXTURE_2D, | 1733 WrappedTexImage2D(GL_TEXTURE_2D, |
1732 0, // mip level | 1734 0, // mip level |
1733 format, | 1735 format, |
1734 size.width(), | 1736 size.width(), |
1735 size.height(), | 1737 size.height(), |
1736 0, // border | 1738 0, // border |
1737 format, | 1739 format, |
1738 GL_UNSIGNED_BYTE, | 1740 GL_UNSIGNED_BYTE, |
1739 NULL); | 1741 NULL); |
1740 | 1742 |
1741 size_ = size; | 1743 size_ = size; |
1742 | 1744 |
1743 bool success = glGetError() == GL_NO_ERROR; | 1745 bool success = glGetError() == GL_NO_ERROR; |
1744 if (success) { | 1746 if (success) { |
1745 uint32 image_size = 0; | 1747 uint32 image_size = 0; |
1746 GLES2Util::ComputeImageDataSizes( | 1748 GLES2Util::ComputeImageDataSizes( |
1747 size.width(), size.height(), format, GL_UNSIGNED_BYTE, 4, &image_size, | 1749 size.width(), size.height(), format, GL_UNSIGNED_BYTE, 4, &image_size, |
1748 NULL, NULL); | 1750 NULL, NULL); |
1749 estimated_size_ = image_size; | 1751 memory_tracker_.UpdateMemRepresented(image_size); |
1750 TRACE_BACKBUFFER_MEMORY_TOTAL(decoder_); | 1752 TRACE_BACKBUFFER_MEMORY_TOTAL(decoder_); |
1751 } | 1753 } |
1752 return success; | 1754 return success; |
1753 } | 1755 } |
1754 | 1756 |
1755 void Texture::Copy(const gfx::Size& size, GLenum format) { | 1757 void Texture::Copy(const gfx::Size& size, GLenum format) { |
1756 DCHECK_NE(id_, 0u); | 1758 DCHECK_NE(id_, 0u); |
1757 ScopedGLErrorSuppressor suppressor(decoder_); | 1759 ScopedGLErrorSuppressor suppressor(decoder_); |
1758 ScopedTexture2DBinder binder(decoder_, id_); | 1760 ScopedTexture2DBinder binder(decoder_, id_); |
1759 glCopyTexImage2D(GL_TEXTURE_2D, | 1761 glCopyTexImage2D(GL_TEXTURE_2D, |
1760 0, // level | 1762 0, // level |
1761 format, | 1763 format, |
1762 0, 0, | 1764 0, 0, |
1763 size.width(), | 1765 size.width(), |
1764 size.height(), | 1766 size.height(), |
1765 0); // border | 1767 0); // border |
1766 } | 1768 } |
1767 | 1769 |
1768 void Texture::Destroy() { | 1770 void Texture::Destroy() { |
1769 if (id_ != 0) { | 1771 if (id_ != 0) { |
1770 ScopedGLErrorSuppressor suppressor(decoder_); | 1772 ScopedGLErrorSuppressor suppressor(decoder_); |
1771 glDeleteTextures(1, &id_); | 1773 glDeleteTextures(1, &id_); |
1772 id_ = 0; | 1774 id_ = 0; |
1773 estimated_size_ = 0; | 1775 memory_tracker_.UpdateMemRepresented(0); |
1774 TRACE_BACKBUFFER_MEMORY_TOTAL(decoder_); | 1776 TRACE_BACKBUFFER_MEMORY_TOTAL(decoder_); |
1775 } | 1777 } |
1776 } | 1778 } |
1777 | 1779 |
1778 void Texture::Invalidate() { | 1780 void Texture::Invalidate() { |
1779 id_ = 0; | 1781 id_ = 0; |
1780 } | 1782 } |
1781 | 1783 |
1782 RenderBuffer::RenderBuffer(GLES2DecoderImpl* decoder) | 1784 RenderBuffer::RenderBuffer(GLES2DecoderImpl* decoder) |
1783 : decoder_(decoder), | 1785 : decoder_(decoder), |
1784 id_(0), | 1786 memory_tracker_(decoder->GetContextGroup()->memory_tracker(), |
1785 estimated_size_(0) { | 1787 NULL, NULL), |
| 1788 id_(0) { |
1786 } | 1789 } |
1787 | 1790 |
1788 RenderBuffer::~RenderBuffer() { | 1791 RenderBuffer::~RenderBuffer() { |
1789 // This does not destroy the render buffer because that would require that | 1792 // This does not destroy the render buffer because that would require that |
1790 // the associated GL context was current. Just check that it was explicitly | 1793 // the associated GL context was current. Just check that it was explicitly |
1791 // destroyed. | 1794 // destroyed. |
1792 DCHECK_EQ(id_, 0u); | 1795 DCHECK_EQ(id_, 0u); |
1793 } | 1796 } |
1794 | 1797 |
1795 void RenderBuffer::Create() { | 1798 void RenderBuffer::Create() { |
(...skipping 21 matching lines...) Expand all Loading... |
1817 } else { | 1820 } else { |
1818 glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, | 1821 glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, |
1819 samples, | 1822 samples, |
1820 format, | 1823 format, |
1821 size.width(), | 1824 size.width(), |
1822 size.height()); | 1825 size.height()); |
1823 } | 1826 } |
1824 } | 1827 } |
1825 bool success = glGetError() == GL_NO_ERROR; | 1828 bool success = glGetError() == GL_NO_ERROR; |
1826 if (success) { | 1829 if (success) { |
1827 estimated_size_ = size.width() * size.height() * samples * | 1830 memory_tracker_.UpdateMemRepresented( |
1828 GLES2Util::RenderbufferBytesPerPixel(format); | 1831 size.width() * size.height() * samples * |
| 1832 GLES2Util::RenderbufferBytesPerPixel(format)); |
1829 TRACE_BACKBUFFER_MEMORY_TOTAL(decoder_); | 1833 TRACE_BACKBUFFER_MEMORY_TOTAL(decoder_); |
1830 } | 1834 } |
1831 return success; | 1835 return success; |
1832 } | 1836 } |
1833 | 1837 |
1834 void RenderBuffer::Destroy() { | 1838 void RenderBuffer::Destroy() { |
1835 if (id_ != 0) { | 1839 if (id_ != 0) { |
1836 ScopedGLErrorSuppressor suppressor(decoder_); | 1840 ScopedGLErrorSuppressor suppressor(decoder_); |
1837 glDeleteRenderbuffersEXT(1, &id_); | 1841 glDeleteRenderbuffersEXT(1, &id_); |
1838 id_ = 0; | 1842 id_ = 0; |
1839 estimated_size_ = 0; | 1843 memory_tracker_.UpdateMemRepresented(0); |
1840 TRACE_BACKBUFFER_MEMORY_TOTAL(decoder_); | 1844 TRACE_BACKBUFFER_MEMORY_TOTAL(decoder_); |
1841 } | 1845 } |
1842 } | 1846 } |
1843 | 1847 |
1844 void RenderBuffer::Invalidate() { | 1848 void RenderBuffer::Invalidate() { |
1845 id_ = 0; | 1849 id_ = 0; |
1846 } | 1850 } |
1847 | 1851 |
1848 FrameBuffer::FrameBuffer(GLES2DecoderImpl* decoder) | 1852 FrameBuffer::FrameBuffer(GLES2DecoderImpl* decoder) |
1849 : decoder_(decoder), | 1853 : decoder_(decoder), |
(...skipping 7338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9188 BindAndApplyTextureParameters(info); | 9192 BindAndApplyTextureParameters(info); |
9189 } | 9193 } |
9190 | 9194 |
9191 // Include the auto-generated part of this file. We split this because it means | 9195 // Include the auto-generated part of this file. We split this because it means |
9192 // we can easily edit the non-auto generated parts right here in this file | 9196 // we can easily edit the non-auto generated parts right here in this file |
9193 // instead of having to edit some template or the code generator. | 9197 // instead of having to edit some template or the code generator. |
9194 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 9198 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
9195 | 9199 |
9196 } // namespace gles2 | 9200 } // namespace gles2 |
9197 } // namespace gpu | 9201 } // namespace gpu |
OLD | NEW |