| OLD | NEW |
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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 "cc/output/gl_renderer.h" | 5 #include "cc/output/gl_renderer.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 is_using_bind_uniform_(false), | 105 is_using_bind_uniform_(false), |
| 106 visible_(true), | 106 visible_(true), |
| 107 is_scissor_enabled_(false) { | 107 is_scissor_enabled_(false) { |
| 108 DCHECK(context_); | 108 DCHECK(context_); |
| 109 } | 109 } |
| 110 | 110 |
| 111 bool GLRenderer::Initialize() { | 111 bool GLRenderer::Initialize() { |
| 112 if (!context_->makeContextCurrent()) | 112 if (!context_->makeContextCurrent()) |
| 113 return false; | 113 return false; |
| 114 | 114 |
| 115 context_->setContextLostCallback(this); | |
| 116 context_->pushGroupMarkerEXT("CompositorContext"); | 115 context_->pushGroupMarkerEXT("CompositorContext"); |
| 117 | 116 |
| 118 std::string extensions_string = | 117 std::string extensions_string = |
| 119 UTF16ToASCII(context_->getString(GL_EXTENSIONS)); | 118 UTF16ToASCII(context_->getString(GL_EXTENSIONS)); |
| 120 std::vector<std::string> extensions_list; | 119 std::vector<std::string> extensions_list; |
| 121 base::SplitString(extensions_string, ' ', &extensions_list); | 120 base::SplitString(extensions_string, ' ', &extensions_list); |
| 122 std::set<std::string> extensions(extensions_list.begin(), | 121 std::set<std::string> extensions(extensions_list.begin(), |
| 123 extensions_list.end()); | 122 extensions_list.end()); |
| 124 | 123 |
| 125 if (Settings().accelerate_painting && | 124 if (Settings().accelerate_painting && |
| 126 extensions.count("GL_EXT_texture_format_BGRA8888") && | 125 extensions.count("GL_EXT_texture_format_BGRA8888") && |
| 127 extensions.count("GL_EXT_read_format_bgra")) | 126 extensions.count("GL_EXT_read_format_bgra")) |
| 128 capabilities_.using_accelerated_painting = true; | 127 capabilities_.using_accelerated_painting = true; |
| 129 else | 128 else |
| 130 capabilities_.using_accelerated_painting = false; | 129 capabilities_.using_accelerated_painting = false; |
| 131 | 130 |
| 132 capabilities_.using_partial_swap = | 131 capabilities_.using_partial_swap = |
| 133 Settings().partial_swap_enabled && | 132 Settings().partial_swap_enabled && |
| 134 extensions.count("GL_CHROMIUM_post_sub_buffer"); | 133 extensions.count("GL_CHROMIUM_post_sub_buffer"); |
| 135 | 134 |
| 136 // Use the SwapBuffers callback only with the threaded proxy. | 135 // Use the SwapBuffers callback only with the threaded proxy. |
| 137 if (client_->HasImplThread()) | 136 if (client_->HasImplThread()) |
| 138 capabilities_.using_swap_complete_callback = | 137 capabilities_.using_swap_complete_callback = |
| 139 extensions.count("GL_CHROMIUM_swapbuffers_complete_callback"); | 138 extensions.count("GL_CHROMIUM_swapbuffers_complete_callback"); |
| 140 if (capabilities_.using_swap_complete_callback) | |
| 141 context_->setSwapBuffersCompleteCallbackCHROMIUM(this); | |
| 142 | 139 |
| 143 capabilities_.using_set_visibility = | 140 capabilities_.using_set_visibility = |
| 144 extensions.count("GL_CHROMIUM_set_visibility"); | 141 extensions.count("GL_CHROMIUM_set_visibility"); |
| 145 | 142 |
| 146 if (extensions.count("GL_CHROMIUM_iosurface")) | 143 if (extensions.count("GL_CHROMIUM_iosurface")) |
| 147 DCHECK(extensions.count("GL_ARB_texture_rectangle")); | 144 DCHECK(extensions.count("GL_ARB_texture_rectangle")); |
| 148 | 145 |
| 149 capabilities_.using_gpu_memory_manager = | 146 capabilities_.using_gpu_memory_manager = |
| 150 extensions.count("GL_CHROMIUM_gpu_memory_manager") && | 147 extensions.count("GL_CHROMIUM_gpu_memory_manager") && |
| 151 Settings().use_memory_management; | 148 Settings().use_memory_management; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 176 | 173 |
| 177 if (!InitializeSharedObjects()) | 174 if (!InitializeSharedObjects()) |
| 178 return false; | 175 return false; |
| 179 | 176 |
| 180 // Make sure the viewport and context gets initialized, even if it is to zero. | 177 // Make sure the viewport and context gets initialized, even if it is to zero. |
| 181 ViewportChanged(); | 178 ViewportChanged(); |
| 182 return true; | 179 return true; |
| 183 } | 180 } |
| 184 | 181 |
| 185 GLRenderer::~GLRenderer() { | 182 GLRenderer::~GLRenderer() { |
| 186 context_->setSwapBuffersCompleteCallbackCHROMIUM(NULL); | |
| 187 context_->setMemoryAllocationChangedCallbackCHROMIUM(NULL); | 183 context_->setMemoryAllocationChangedCallbackCHROMIUM(NULL); |
| 188 context_->setContextLostCallback(NULL); | |
| 189 CleanupSharedObjects(); | 184 CleanupSharedObjects(); |
| 190 } | 185 } |
| 191 | 186 |
| 192 const RendererCapabilities& GLRenderer::Capabilities() const { | 187 const RendererCapabilities& GLRenderer::Capabilities() const { |
| 193 return capabilities_; | 188 return capabilities_; |
| 194 } | 189 } |
| 195 | 190 |
| 196 WebGraphicsContext3D* GLRenderer::Context() { return context_; } | 191 WebGraphicsContext3D* GLRenderer::Context() { return context_; } |
| 197 | 192 |
| 198 void GLRenderer::DebugGLCall(WebGraphicsContext3D* context, | 193 void GLRenderer::DebugGLCall(WebGraphicsContext3D* context, |
| (...skipping 1474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1673 // assuming a double-buffered GPU pipeline. A texture can be | 1668 // assuming a double-buffered GPU pipeline. A texture can be |
| 1674 // written to after one full frame has past since it was last read. | 1669 // written to after one full frame has past since it was last read. |
| 1675 if (last_swap_fence_) | 1670 if (last_swap_fence_) |
| 1676 static_cast<SimpleSwapFence*>(last_swap_fence_.get())->SetHasPassed(); | 1671 static_cast<SimpleSwapFence*>(last_swap_fence_.get())->SetHasPassed(); |
| 1677 last_swap_fence_ = resource_provider_->GetReadLockFence(); | 1672 last_swap_fence_ = resource_provider_->GetReadLockFence(); |
| 1678 resource_provider_->SetReadLockFence(new SimpleSwapFence()); | 1673 resource_provider_->SetReadLockFence(new SimpleSwapFence()); |
| 1679 | 1674 |
| 1680 return true; | 1675 return true; |
| 1681 } | 1676 } |
| 1682 | 1677 |
| 1683 void GLRenderer::ReceiveCompositorFrameAck(const CompositorFrameAck& ack) { | |
| 1684 onSwapBuffersComplete(); | |
| 1685 } | |
| 1686 | |
| 1687 void GLRenderer::onSwapBuffersComplete() { client_->OnSwapBuffersComplete(); } | |
| 1688 | |
| 1689 void GLRenderer::onMemoryAllocationChanged( | 1678 void GLRenderer::onMemoryAllocationChanged( |
| 1690 WebGraphicsMemoryAllocation allocation) { | 1679 WebGraphicsMemoryAllocation allocation) { |
| 1691 // Just ignore the memory manager when it says to set the limit to zero | 1680 // Just ignore the memory manager when it says to set the limit to zero |
| 1692 // bytes. This will happen when the memory manager thinks that the renderer | 1681 // bytes. This will happen when the memory manager thinks that the renderer |
| 1693 // is not visible (which the renderer knows better). | 1682 // is not visible (which the renderer knows better). |
| 1694 if (allocation.bytesLimitWhenVisible) { | 1683 if (allocation.bytesLimitWhenVisible) { |
| 1695 ManagedMemoryPolicy policy( | 1684 ManagedMemoryPolicy policy( |
| 1696 allocation.bytesLimitWhenVisible, | 1685 allocation.bytesLimitWhenVisible, |
| 1697 PriorityCutoff(allocation.priorityCutoffWhenVisible), | 1686 PriorityCutoff(allocation.priorityCutoffWhenVisible), |
| 1698 allocation.bytesLimitWhenNotVisible, | 1687 allocation.bytesLimitWhenNotVisible, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1756 } | 1745 } |
| 1757 | 1746 |
| 1758 void GLRenderer::EnsureBackbuffer() { | 1747 void GLRenderer::EnsureBackbuffer() { |
| 1759 if (!is_backbuffer_discarded_) | 1748 if (!is_backbuffer_discarded_) |
| 1760 return; | 1749 return; |
| 1761 | 1750 |
| 1762 output_surface_->EnsureBackbuffer(); | 1751 output_surface_->EnsureBackbuffer(); |
| 1763 is_backbuffer_discarded_ = false; | 1752 is_backbuffer_discarded_ = false; |
| 1764 } | 1753 } |
| 1765 | 1754 |
| 1766 void GLRenderer::onContextLost() { client_->DidLoseOutputSurface(); } | |
| 1767 | |
| 1768 void GLRenderer::GetFramebufferPixels(void* pixels, gfx::Rect rect) { | 1755 void GLRenderer::GetFramebufferPixels(void* pixels, gfx::Rect rect) { |
| 1769 DCHECK(rect.right() <= ViewportWidth()); | 1756 DCHECK(rect.right() <= ViewportWidth()); |
| 1770 DCHECK(rect.bottom() <= ViewportHeight()); | 1757 DCHECK(rect.bottom() <= ViewportHeight()); |
| 1771 | 1758 |
| 1772 if (!pixels) | 1759 if (!pixels) |
| 1773 return; | 1760 return; |
| 1774 | 1761 |
| 1775 MakeContextCurrent(); | 1762 MakeContextCurrent(); |
| 1776 | 1763 |
| 1777 bool do_workaround = NeedsIOSurfaceReadbackWorkaround(); | 1764 bool do_workaround = NeedsIOSurfaceReadbackWorkaround(); |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2229 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); | 2216 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); |
| 2230 | 2217 |
| 2231 ReleaseRenderPassTextures(); | 2218 ReleaseRenderPassTextures(); |
| 2232 } | 2219 } |
| 2233 | 2220 |
| 2234 bool GLRenderer::IsContextLost() { | 2221 bool GLRenderer::IsContextLost() { |
| 2235 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); | 2222 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); |
| 2236 } | 2223 } |
| 2237 | 2224 |
| 2238 } // namespace cc | 2225 } // namespace cc |
| OLD | NEW |