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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 bool enforce_internal_framebuffer, | 311 bool enforce_internal_framebuffer, |
312 bool internal); | 312 bool internal); |
313 ~ScopedResolvedFrameBufferBinder(); | 313 ~ScopedResolvedFrameBufferBinder(); |
314 | 314 |
315 private: | 315 private: |
316 GLES2DecoderImpl* decoder_; | 316 GLES2DecoderImpl* decoder_; |
317 bool resolve_and_bind_; | 317 bool resolve_and_bind_; |
318 DISALLOW_COPY_AND_ASSIGN(ScopedResolvedFrameBufferBinder); | 318 DISALLOW_COPY_AND_ASSIGN(ScopedResolvedFrameBufferBinder); |
319 }; | 319 }; |
320 | 320 |
321 // This class records texture upload time when in scope. | |
322 class ScopedTextureUploadTimer { | |
323 public: | |
324 explicit ScopedTextureUploadTimer(GLES2DecoderImpl* decoder); | |
325 ~ScopedTextureUploadTimer(); | |
326 | |
327 private: | |
328 GLES2DecoderImpl* decoder_; | |
329 base::TimeTicks begin_time_; | |
330 DISALLOW_COPY_AND_ASSIGN(ScopedTextureUploadTimer); | |
331 }; | |
332 | |
321 // Encapsulates an OpenGL texture. | 333 // Encapsulates an OpenGL texture. |
322 class Texture { | 334 class Texture { |
323 public: | 335 public: |
324 explicit Texture(GLES2DecoderImpl* decoder); | 336 explicit Texture(GLES2DecoderImpl* decoder); |
325 ~Texture(); | 337 ~Texture(); |
326 | 338 |
327 // Create a new render texture. | 339 // Create a new render texture. |
328 void Create(); | 340 void Create(); |
329 | 341 |
330 // Set the initial size and format of a render texture or resize it. | 342 // Set the initial size and format of a render texture or resize it. |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
511 const base::Callback<void(gfx::Size)>& callback); | 523 const base::Callback<void(gfx::Size)>& callback); |
512 | 524 |
513 virtual void SetMsgCallback(const MsgCallback& callback); | 525 virtual void SetMsgCallback(const MsgCallback& callback); |
514 | 526 |
515 virtual void SetStreamTextureManager(StreamTextureManager* manager); | 527 virtual void SetStreamTextureManager(StreamTextureManager* manager); |
516 virtual bool GetServiceTextureId(uint32 client_texture_id, | 528 virtual bool GetServiceTextureId(uint32 client_texture_id, |
517 uint32* service_texture_id); | 529 uint32* service_texture_id); |
518 | 530 |
519 virtual uint32 GetGLError() OVERRIDE; | 531 virtual uint32 GetGLError() OVERRIDE; |
520 | 532 |
533 virtual uint32 GetTextureUploadCount() OVERRIDE; | |
534 virtual double GetTotalTextureUploadTimeInSeconds() OVERRIDE; | |
535 | |
521 // Restores the current state to the user's settings. | 536 // Restores the current state to the user's settings. |
522 void RestoreCurrentFramebufferBindings(); | 537 void RestoreCurrentFramebufferBindings(); |
523 void RestoreCurrentRenderbufferBindings(); | 538 void RestoreCurrentRenderbufferBindings(); |
524 void RestoreCurrentTexture2DBindings(); | 539 void RestoreCurrentTexture2DBindings(); |
525 | 540 |
526 // Sets DEPTH_TEST, STENCIL_TEST and color mask for the current framebuffer. | 541 // Sets DEPTH_TEST, STENCIL_TEST and color mask for the current framebuffer. |
527 void ApplyDirtyState(); | 542 void ApplyDirtyState(); |
528 | 543 |
529 // Reapply the texture parameters to the given texture. | 544 // Reapply the texture parameters to the given texture. |
530 void BindAndApplyTextureParameters(TextureManager::TextureInfo* info); | 545 void BindAndApplyTextureParameters(TextureManager::TextureInfo* info); |
531 | 546 |
532 // These check the state of the currently bound framebuffer or the | 547 // These check the state of the currently bound framebuffer or the |
533 // backbuffer if no framebuffer is bound. | 548 // backbuffer if no framebuffer is bound. |
534 bool BoundFramebufferHasColorAttachmentWithAlpha(); | 549 bool BoundFramebufferHasColorAttachmentWithAlpha(); |
535 bool BoundFramebufferHasDepthAttachment(); | 550 bool BoundFramebufferHasDepthAttachment(); |
536 bool BoundFramebufferHasStencilAttachment(); | 551 bool BoundFramebufferHasStencilAttachment(); |
537 | 552 |
538 virtual error::ContextLostReason GetContextLostReason(); | 553 virtual error::ContextLostReason GetContextLostReason(); |
539 | 554 |
540 private: | 555 private: |
541 friend class ScopedGLErrorSuppressor; | 556 friend class ScopedGLErrorSuppressor; |
542 friend class ScopedResolvedFrameBufferBinder; | 557 friend class ScopedResolvedFrameBufferBinder; |
558 friend class ScopedTextureUploadTimer; | |
543 friend class Texture; | 559 friend class Texture; |
544 friend class RenderBuffer; | 560 friend class RenderBuffer; |
545 friend class FrameBuffer; | 561 friend class FrameBuffer; |
546 | 562 |
547 // State associated with each texture unit. | 563 // State associated with each texture unit. |
548 struct TextureUnit { | 564 struct TextureUnit { |
549 TextureUnit() : bind_target(GL_TEXTURE_2D) { } | 565 TextureUnit() : bind_target(GL_TEXTURE_2D) { } |
550 | 566 |
551 // The last target that was bound to this texture unit. | 567 // The last target that was bound to this texture unit. |
552 GLenum bind_target; | 568 GLenum bind_target; |
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1576 typedef std::vector<GLES2DecoderImpl*> ChildList; | 1592 typedef std::vector<GLES2DecoderImpl*> ChildList; |
1577 ChildList children_; | 1593 ChildList children_; |
1578 | 1594 |
1579 scoped_ptr<CopyTextureCHROMIUMResourceManager> copy_texture_CHROMIUM_; | 1595 scoped_ptr<CopyTextureCHROMIUMResourceManager> copy_texture_CHROMIUM_; |
1580 | 1596 |
1581 // Cached values of the currently assigned viewport dimensions. | 1597 // Cached values of the currently assigned viewport dimensions. |
1582 GLint viewport_x_, viewport_y_; | 1598 GLint viewport_x_, viewport_y_; |
1583 GLsizei viewport_width_, viewport_height_; | 1599 GLsizei viewport_width_, viewport_height_; |
1584 GLsizei viewport_max_width_, viewport_max_height_; | 1600 GLsizei viewport_max_width_, viewport_max_height_; |
1585 | 1601 |
1602 // Texture upload stats. | |
1603 int texture_upload_count_; | |
1604 base::TimeDelta total_texture_upload_time_; | |
1605 | |
1586 DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl); | 1606 DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl); |
1587 }; | 1607 }; |
1588 | 1608 |
1589 ScopedGLErrorSuppressor::ScopedGLErrorSuppressor(GLES2DecoderImpl* decoder) | 1609 ScopedGLErrorSuppressor::ScopedGLErrorSuppressor(GLES2DecoderImpl* decoder) |
1590 : decoder_(decoder) { | 1610 : decoder_(decoder) { |
1591 decoder_->CopyRealGLErrorsToWrapper(); | 1611 decoder_->CopyRealGLErrorsToWrapper(); |
1592 } | 1612 } |
1593 | 1613 |
1594 ScopedGLErrorSuppressor::~ScopedGLErrorSuppressor() { | 1614 ScopedGLErrorSuppressor::~ScopedGLErrorSuppressor() { |
1595 decoder_->ClearRealGLErrors(); | 1615 decoder_->ClearRealGLErrors(); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1691 if (!resolve_and_bind_) | 1711 if (!resolve_and_bind_) |
1692 return; | 1712 return; |
1693 | 1713 |
1694 ScopedGLErrorSuppressor suppressor(decoder_); | 1714 ScopedGLErrorSuppressor suppressor(decoder_); |
1695 decoder_->RestoreCurrentFramebufferBindings(); | 1715 decoder_->RestoreCurrentFramebufferBindings(); |
1696 if (decoder_->enable_scissor_test_) { | 1716 if (decoder_->enable_scissor_test_) { |
1697 glEnable(GL_SCISSOR_TEST); | 1717 glEnable(GL_SCISSOR_TEST); |
1698 } | 1718 } |
1699 } | 1719 } |
1700 | 1720 |
1721 ScopedTextureUploadTimer::ScopedTextureUploadTimer(GLES2DecoderImpl* decoder) | |
1722 : decoder_(decoder), | |
1723 begin_time_(base::TimeTicks::HighResNow()) { | |
1724 } | |
1725 | |
1726 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { | |
1727 decoder_->texture_upload_count_++; | |
1728 decoder_->total_texture_upload_time_ += | |
1729 base::TimeTicks::HighResNow() - begin_time_; | |
1730 } | |
1731 | |
1701 Texture::Texture(GLES2DecoderImpl* decoder) | 1732 Texture::Texture(GLES2DecoderImpl* decoder) |
1702 : decoder_(decoder), | 1733 : decoder_(decoder), |
1703 memory_tracker_(decoder->GetContextGroup()->memory_tracker(), | 1734 memory_tracker_(decoder->GetContextGroup()->memory_tracker(), |
1704 NULL, NULL), | 1735 NULL, NULL), |
1705 id_(0) { | 1736 id_(0) { |
1706 } | 1737 } |
1707 | 1738 |
1708 Texture::~Texture() { | 1739 Texture::~Texture() { |
1709 // This does not destroy the render texture because that would require that | 1740 // This does not destroy the render texture because that would require that |
1710 // the associated GL context was current. Just check that it was explicitly | 1741 // the associated GL context was current. Just check that it was explicitly |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1981 needs_mac_nvidia_driver_workaround_(false), | 2012 needs_mac_nvidia_driver_workaround_(false), |
1982 needs_glsl_built_in_function_emulation_(false), | 2013 needs_glsl_built_in_function_emulation_(false), |
1983 force_webgl_glsl_validation_(false), | 2014 force_webgl_glsl_validation_(false), |
1984 derivatives_explicitly_enabled_(false), | 2015 derivatives_explicitly_enabled_(false), |
1985 compile_shader_always_succeeds_(false), | 2016 compile_shader_always_succeeds_(false), |
1986 viewport_x_(0), | 2017 viewport_x_(0), |
1987 viewport_y_(0), | 2018 viewport_y_(0), |
1988 viewport_width_(0), | 2019 viewport_width_(0), |
1989 viewport_height_(0), | 2020 viewport_height_(0), |
1990 viewport_max_width_(0), | 2021 viewport_max_width_(0), |
1991 viewport_max_height_(0) { | 2022 viewport_max_height_(0), |
2023 texture_upload_count_(0) { | |
1992 DCHECK(group); | 2024 DCHECK(group); |
1993 | 2025 |
1994 GLES2DecoderImpl* this_temp = this; | 2026 GLES2DecoderImpl* this_temp = this; |
1995 this_in_hex_ = HexEncode(&this_temp, sizeof(this_temp)); | 2027 this_in_hex_ = HexEncode(&this_temp, sizeof(this_temp)); |
1996 | 2028 |
1997 attrib_0_value_.v[0] = 0.0f; | 2029 attrib_0_value_.v[0] = 0.0f; |
1998 attrib_0_value_.v[1] = 0.0f; | 2030 attrib_0_value_.v[1] = 0.0f; |
1999 attrib_0_value_.v[2] = 0.0f; | 2031 attrib_0_value_.v[2] = 0.0f; |
2000 attrib_0_value_.v[3] = 1.0f; | 2032 attrib_0_value_.v[3] = 1.0f; |
2001 | 2033 |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2827 uint32* service_texture_id) { | 2859 uint32* service_texture_id) { |
2828 TextureManager::TextureInfo* texture = | 2860 TextureManager::TextureInfo* texture = |
2829 texture_manager()->GetTextureInfo(client_texture_id); | 2861 texture_manager()->GetTextureInfo(client_texture_id); |
2830 if (texture) { | 2862 if (texture) { |
2831 *service_texture_id = texture->service_id(); | 2863 *service_texture_id = texture->service_id(); |
2832 return true; | 2864 return true; |
2833 } | 2865 } |
2834 return false; | 2866 return false; |
2835 } | 2867 } |
2836 | 2868 |
2869 uint32 GLES2DecoderImpl::GetTextureUploadCount() { | |
2870 return texture_upload_count_; | |
2871 } | |
2872 | |
2873 double GLES2DecoderImpl::GetTotalTextureUploadTimeInSeconds() { | |
2874 return total_texture_upload_time_.InSecondsF(); | |
2875 } | |
2876 | |
nduca
2012/08/28 19:45:10
while we're at it, can we add tracking for "time s
| |
2837 void GLES2DecoderImpl::Destroy(bool have_context) { | 2877 void GLES2DecoderImpl::Destroy(bool have_context) { |
2838 DCHECK(!have_context || context_->IsCurrent(NULL)); | 2878 DCHECK(!have_context || context_->IsCurrent(NULL)); |
2839 | 2879 |
2840 ChildList children = children_; | 2880 ChildList children = children_; |
2841 for (ChildList::iterator it = children.begin(); it != children.end(); ++it) | 2881 for (ChildList::iterator it = children.begin(); it != children.end(); ++it) |
2842 (*it)->SetParent(NULL, 0); | 2882 (*it)->SetParent(NULL, 0); |
2843 DCHECK(children_.empty()); | 2883 DCHECK(children_.empty()); |
2844 SetParent(NULL, 0); | 2884 SetParent(NULL, 0); |
2845 | 2885 |
2846 // Unbind everything. | 2886 // Unbind everything. |
(...skipping 4944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7791 GLsizei tex_width = 0; | 7831 GLsizei tex_width = 0; |
7792 GLsizei tex_height = 0; | 7832 GLsizei tex_height = 0; |
7793 bool ok = info->GetLevelSize(target, level, &tex_width, &tex_height); | 7833 bool ok = info->GetLevelSize(target, level, &tex_width, &tex_height); |
7794 DCHECK(ok); | 7834 DCHECK(ok); |
7795 if (xoffset != 0 || yoffset != 0 || | 7835 if (xoffset != 0 || yoffset != 0 || |
7796 width != tex_width || height != tex_height) { | 7836 width != tex_width || height != tex_height) { |
7797 if (!texture_manager()->ClearTextureLevel(this, info, target, level)) { | 7837 if (!texture_manager()->ClearTextureLevel(this, info, target, level)) { |
7798 SetGLError(GL_OUT_OF_MEMORY, "glTexSubImage2D", "dimensions too big"); | 7838 SetGLError(GL_OUT_OF_MEMORY, "glTexSubImage2D", "dimensions too big"); |
7799 return; | 7839 return; |
7800 } | 7840 } |
7841 ScopedTextureUploadTimer timer(this); | |
7801 glTexSubImage2D( | 7842 glTexSubImage2D( |
7802 target, level, xoffset, yoffset, width, height, format, type, data); | 7843 target, level, xoffset, yoffset, width, height, format, type, data); |
7803 return; | 7844 return; |
7804 } | 7845 } |
7805 | 7846 |
7806 if (teximage2d_faster_than_texsubimage2d_ && !info->IsImmutable()) { | 7847 if (teximage2d_faster_than_texsubimage2d_ && !info->IsImmutable()) { |
7848 ScopedTextureUploadTimer timer(this); | |
7807 // NOTE: In OpenGL ES 2.0 border is always zero and format is always the | 7849 // NOTE: In OpenGL ES 2.0 border is always zero and format is always the |
7808 // same as internal_foramt. If that changes we'll need to look them up. | 7850 // same as internal_foramt. If that changes we'll need to look them up. |
7809 WrappedTexImage2D( | 7851 WrappedTexImage2D( |
7810 target, level, format, width, height, 0, format, type, data); | 7852 target, level, format, width, height, 0, format, type, data); |
7811 } else { | 7853 } else { |
7854 ScopedTextureUploadTimer timer(this); | |
7812 glTexSubImage2D( | 7855 glTexSubImage2D( |
7813 target, level, xoffset, yoffset, width, height, format, type, data); | 7856 target, level, xoffset, yoffset, width, height, format, type, data); |
7814 } | 7857 } |
7815 texture_manager()->SetLevelCleared(info, target, level); | 7858 texture_manager()->SetLevelCleared(info, target, level); |
7816 } | 7859 } |
7817 | 7860 |
7818 error::Error GLES2DecoderImpl::HandleTexSubImage2D( | 7861 error::Error GLES2DecoderImpl::HandleTexSubImage2D( |
7819 uint32 immediate_data_size, const gles2::TexSubImage2D& c) { | 7862 uint32 immediate_data_size, const gles2::TexSubImage2D& c) { |
7820 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexSubImage2D"); | 7863 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexSubImage2D"); |
7821 GLboolean internal = static_cast<GLboolean>(c.internal); | 7864 GLboolean internal = static_cast<GLboolean>(c.internal); |
(...skipping 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9235 } | 9278 } |
9236 | 9279 |
9237 | 9280 |
9238 // Include the auto-generated part of this file. We split this because it means | 9281 // Include the auto-generated part of this file. We split this because it means |
9239 // we can easily edit the non-auto generated parts right here in this file | 9282 // we can easily edit the non-auto generated parts right here in this file |
9240 // instead of having to edit some template or the code generator. | 9283 // instead of having to edit some template or the code generator. |
9241 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 9284 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
9242 | 9285 |
9243 } // namespace gles2 | 9286 } // namespace gles2 |
9244 } // namespace gpu | 9287 } // namespace gpu |
OLD | NEW |