| 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/gl_renderer.h" | 5 #include "cc/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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 is_using_bind_uniform_(false), | 103 is_using_bind_uniform_(false), |
| 104 visible_(true), | 104 visible_(true), |
| 105 is_scissor_enabled_(false) { | 105 is_scissor_enabled_(false) { |
| 106 DCHECK(context_); | 106 DCHECK(context_); |
| 107 } | 107 } |
| 108 | 108 |
| 109 bool GLRenderer::Initialize() { | 109 bool GLRenderer::Initialize() { |
| 110 if (!context_->makeContextCurrent()) | 110 if (!context_->makeContextCurrent()) |
| 111 return false; | 111 return false; |
| 112 | 112 |
| 113 context_->setContextLostCallback(this); | |
| 114 context_->pushGroupMarkerEXT("CompositorContext"); | 113 context_->pushGroupMarkerEXT("CompositorContext"); |
| 115 | 114 |
| 116 std::string extensions_string = | 115 std::string extensions_string = |
| 117 UTF16ToASCII(context_->getString(GL_EXTENSIONS)); | 116 UTF16ToASCII(context_->getString(GL_EXTENSIONS)); |
| 118 std::vector<std::string> extensions_list; | 117 std::vector<std::string> extensions_list; |
| 119 base::SplitString(extensions_string, ' ', &extensions_list); | 118 base::SplitString(extensions_string, ' ', &extensions_list); |
| 120 std::set<std::string> extensions(extensions_list.begin(), | 119 std::set<std::string> extensions(extensions_list.begin(), |
| 121 extensions_list.end()); | 120 extensions_list.end()); |
| 122 | 121 |
| 123 if (Settings().acceleratePainting && | 122 if (Settings().acceleratePainting && |
| 124 extensions.count("GL_EXT_texture_format_BGRA8888") && | 123 extensions.count("GL_EXT_texture_format_BGRA8888") && |
| 125 extensions.count("GL_EXT_read_format_bgra")) | 124 extensions.count("GL_EXT_read_format_bgra")) |
| 126 capabilities_.using_accelerated_painting = true; | 125 capabilities_.using_accelerated_painting = true; |
| 127 else | 126 else |
| 128 capabilities_.using_accelerated_painting = false; | 127 capabilities_.using_accelerated_painting = false; |
| 129 | 128 |
| 130 capabilities_.using_partial_swap = | 129 capabilities_.using_partial_swap = |
| 131 Settings().partialSwapEnabled && | 130 Settings().partialSwapEnabled && |
| 132 extensions.count("GL_CHROMIUM_post_sub_buffer"); | 131 extensions.count("GL_CHROMIUM_post_sub_buffer"); |
| 133 | 132 |
| 134 // Use the swapBuffers callback only with the threaded proxy. | 133 // Use the swapBuffers callback only with the threaded proxy. |
| 135 if (client_->HasImplThread()) | 134 if (client_->HasImplThread()) |
| 136 capabilities_.using_swap_complete_callback = | 135 capabilities_.using_swap_complete_callback = |
| 137 extensions.count("GL_CHROMIUM_swapbuffers_complete_callback"); | 136 extensions.count("GL_CHROMIUM_swapbuffers_complete_callback"); |
| 138 if (capabilities_.using_swap_complete_callback) | |
| 139 context_->setSwapBuffersCompleteCallbackCHROMIUM(this); | |
| 140 | 137 |
| 141 capabilities_.using_set_visibility = | 138 capabilities_.using_set_visibility = |
| 142 extensions.count("GL_CHROMIUM_set_visibility"); | 139 extensions.count("GL_CHROMIUM_set_visibility"); |
| 143 | 140 |
| 144 if (extensions.count("GL_CHROMIUM_iosurface")) | 141 if (extensions.count("GL_CHROMIUM_iosurface")) |
| 145 DCHECK(extensions.count("GL_ARB_texture_rectangle")); | 142 DCHECK(extensions.count("GL_ARB_texture_rectangle")); |
| 146 | 143 |
| 147 capabilities_.using_gpu_memory_manager = | 144 capabilities_.using_gpu_memory_manager = |
| 148 extensions.count("GL_CHROMIUM_gpu_memory_manager") && | 145 extensions.count("GL_CHROMIUM_gpu_memory_manager") && |
| 149 Settings().useMemoryManagement; | 146 Settings().useMemoryManagement; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 174 | 171 |
| 175 if (!InitializeSharedObjects()) | 172 if (!InitializeSharedObjects()) |
| 176 return false; | 173 return false; |
| 177 | 174 |
| 178 // Make sure the viewport and context gets initialized, even if it is to zero. | 175 // Make sure the viewport and context gets initialized, even if it is to zero. |
| 179 ViewportChanged(); | 176 ViewportChanged(); |
| 180 return true; | 177 return true; |
| 181 } | 178 } |
| 182 | 179 |
| 183 GLRenderer::~GLRenderer() { | 180 GLRenderer::~GLRenderer() { |
| 184 context_->setSwapBuffersCompleteCallbackCHROMIUM(NULL); | |
| 185 context_->setMemoryAllocationChangedCallbackCHROMIUM(NULL); | 181 context_->setMemoryAllocationChangedCallbackCHROMIUM(NULL); |
| 186 context_->setContextLostCallback(NULL); | |
| 187 CleanupSharedObjects(); | 182 CleanupSharedObjects(); |
| 188 } | 183 } |
| 189 | 184 |
| 190 const RendererCapabilities& GLRenderer::Capabilities() const { | 185 const RendererCapabilities& GLRenderer::Capabilities() const { |
| 191 return capabilities_; | 186 return capabilities_; |
| 192 } | 187 } |
| 193 | 188 |
| 194 WebGraphicsContext3D* GLRenderer::Context() { return context_; } | 189 WebGraphicsContext3D* GLRenderer::Context() { return context_; } |
| 195 | 190 |
| 196 void GLRenderer::DebugGLCall(WebGraphicsContext3D* context, | 191 void GLRenderer::DebugGLCall(WebGraphicsContext3D* context, |
| (...skipping 1405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1602 // assuming a double-buffered GPU pipeline. A texture can be | 1597 // assuming a double-buffered GPU pipeline. A texture can be |
| 1603 // written to after one full frame has past since it was last read. | 1598 // written to after one full frame has past since it was last read. |
| 1604 if (last_swap_fence_) | 1599 if (last_swap_fence_) |
| 1605 static_cast<SimpleSwapFence*>(last_swap_fence_.get())->SetHasPassed(); | 1600 static_cast<SimpleSwapFence*>(last_swap_fence_.get())->SetHasPassed(); |
| 1606 last_swap_fence_ = resource_provider_->GetReadLockFence(); | 1601 last_swap_fence_ = resource_provider_->GetReadLockFence(); |
| 1607 resource_provider_->SetReadLockFence(new SimpleSwapFence()); | 1602 resource_provider_->SetReadLockFence(new SimpleSwapFence()); |
| 1608 | 1603 |
| 1609 return true; | 1604 return true; |
| 1610 } | 1605 } |
| 1611 | 1606 |
| 1612 void GLRenderer::ReceiveCompositorFrameAck(const CompositorFrameAck& ack) { | |
| 1613 onSwapBuffersComplete(); | |
| 1614 } | |
| 1615 | |
| 1616 void GLRenderer::onSwapBuffersComplete() { client_->OnSwapBuffersComplete(); } | |
| 1617 | |
| 1618 void GLRenderer::onMemoryAllocationChanged( | 1607 void GLRenderer::onMemoryAllocationChanged( |
| 1619 WebGraphicsMemoryAllocation allocation) { | 1608 WebGraphicsMemoryAllocation allocation) { |
| 1620 // Just ignore the memory manager when it says to set the limit to zero | 1609 // Just ignore the memory manager when it says to set the limit to zero |
| 1621 // bytes. This will happen when the memory manager thinks that the renderer | 1610 // bytes. This will happen when the memory manager thinks that the renderer |
| 1622 // is not visible (which the renderer knows better). | 1611 // is not visible (which the renderer knows better). |
| 1623 if (allocation.bytesLimitWhenVisible) { | 1612 if (allocation.bytesLimitWhenVisible) { |
| 1624 ManagedMemoryPolicy policy( | 1613 ManagedMemoryPolicy policy( |
| 1625 allocation.bytesLimitWhenVisible, | 1614 allocation.bytesLimitWhenVisible, |
| 1626 PriorityCutoff(allocation.priorityCutoffWhenVisible), | 1615 PriorityCutoff(allocation.priorityCutoffWhenVisible), |
| 1627 allocation.bytesLimitWhenNotVisible, | 1616 allocation.bytesLimitWhenNotVisible, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1685 } | 1674 } |
| 1686 | 1675 |
| 1687 void GLRenderer::EnsureBackbuffer() { | 1676 void GLRenderer::EnsureBackbuffer() { |
| 1688 if (!is_backbuffer_discarded_) | 1677 if (!is_backbuffer_discarded_) |
| 1689 return; | 1678 return; |
| 1690 | 1679 |
| 1691 output_surface_->EnsureBackbuffer(); | 1680 output_surface_->EnsureBackbuffer(); |
| 1692 is_backbuffer_discarded_ = false; | 1681 is_backbuffer_discarded_ = false; |
| 1693 } | 1682 } |
| 1694 | 1683 |
| 1695 void GLRenderer::onContextLost() { client_->DidLoseOutputSurface(); } | |
| 1696 | |
| 1697 void GLRenderer::GetFramebufferPixels(void* pixels, gfx::Rect rect) { | 1684 void GLRenderer::GetFramebufferPixels(void* pixels, gfx::Rect rect) { |
| 1698 DCHECK(rect.right() <= ViewportWidth()); | 1685 DCHECK(rect.right() <= ViewportWidth()); |
| 1699 DCHECK(rect.bottom() <= ViewportHeight()); | 1686 DCHECK(rect.bottom() <= ViewportHeight()); |
| 1700 | 1687 |
| 1701 if (!pixels) | 1688 if (!pixels) |
| 1702 return; | 1689 return; |
| 1703 | 1690 |
| 1704 MakeContextCurrent(); | 1691 MakeContextCurrent(); |
| 1705 | 1692 |
| 1706 bool do_workaround = NeedsIOSurfaceReadbackWorkaround(); | 1693 bool do_workaround = NeedsIOSurfaceReadbackWorkaround(); |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2129 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); | 2116 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); |
| 2130 | 2117 |
| 2131 ReleaseRenderPassTextures(); | 2118 ReleaseRenderPassTextures(); |
| 2132 } | 2119 } |
| 2133 | 2120 |
| 2134 bool GLRenderer::IsContextLost() { | 2121 bool GLRenderer::IsContextLost() { |
| 2135 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); | 2122 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); |
| 2136 } | 2123 } |
| 2137 | 2124 |
| 2138 } // namespace cc | 2125 } // namespace cc |
| OLD | NEW |