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 <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 is_scissor_enabled_(false), | 112 is_scissor_enabled_(false), |
113 highp_threshold_min_(highp_threshold_min), | 113 highp_threshold_min_(highp_threshold_min), |
114 on_demand_tile_raster_resource_id_(0) { | 114 on_demand_tile_raster_resource_id_(0) { |
115 DCHECK(context_); | 115 DCHECK(context_); |
116 } | 116 } |
117 | 117 |
118 bool GLRenderer::Initialize() { | 118 bool GLRenderer::Initialize() { |
119 if (!context_->makeContextCurrent()) | 119 if (!context_->makeContextCurrent()) |
120 return false; | 120 return false; |
121 | 121 |
122 context_->setContextLostCallback(this); | |
123 context_->pushGroupMarkerEXT("CompositorContext"); | 122 context_->pushGroupMarkerEXT("CompositorContext"); |
124 | 123 |
125 std::string extensions_string = | 124 std::string extensions_string = |
126 UTF16ToASCII(context_->getString(GL_EXTENSIONS)); | 125 UTF16ToASCII(context_->getString(GL_EXTENSIONS)); |
127 std::vector<std::string> extensions_list; | 126 std::vector<std::string> extensions_list; |
128 base::SplitString(extensions_string, ' ', &extensions_list); | 127 base::SplitString(extensions_string, ' ', &extensions_list); |
129 std::set<std::string> extensions(extensions_list.begin(), | 128 std::set<std::string> extensions(extensions_list.begin(), |
130 extensions_list.end()); | 129 extensions_list.end()); |
131 | 130 |
132 if (Settings().accelerate_painting && | 131 if (Settings().accelerate_painting && |
133 extensions.count("GL_EXT_texture_format_BGRA8888") && | 132 extensions.count("GL_EXT_texture_format_BGRA8888") && |
134 extensions.count("GL_EXT_read_format_bgra")) | 133 extensions.count("GL_EXT_read_format_bgra")) |
135 capabilities_.using_accelerated_painting = true; | 134 capabilities_.using_accelerated_painting = true; |
136 else | 135 else |
137 capabilities_.using_accelerated_painting = false; | 136 capabilities_.using_accelerated_painting = false; |
138 | 137 |
139 capabilities_.using_partial_swap = | 138 capabilities_.using_partial_swap = |
140 Settings().partial_swap_enabled && | 139 Settings().partial_swap_enabled && |
141 extensions.count("GL_CHROMIUM_post_sub_buffer"); | 140 extensions.count("GL_CHROMIUM_post_sub_buffer"); |
142 | 141 |
143 // Use the SwapBuffers callback only with the threaded proxy. | 142 // Use the SwapBuffers callback only with the threaded proxy. |
144 if (client_->HasImplThread()) | 143 if (client_->HasImplThread()) |
145 capabilities_.using_swap_complete_callback = | 144 capabilities_.using_swap_complete_callback = |
146 extensions.count("GL_CHROMIUM_swapbuffers_complete_callback") > 0; | 145 extensions.count("GL_CHROMIUM_swapbuffers_complete_callback") > 0; |
147 if (capabilities_.using_swap_complete_callback) | |
148 context_->setSwapBuffersCompleteCallbackCHROMIUM(this); | |
149 | 146 |
150 capabilities_.using_set_visibility = | 147 capabilities_.using_set_visibility = |
151 extensions.count("GL_CHROMIUM_set_visibility") > 0; | 148 extensions.count("GL_CHROMIUM_set_visibility") > 0; |
152 | 149 |
153 if (extensions.count("GL_CHROMIUM_iosurface") > 0) | 150 if (extensions.count("GL_CHROMIUM_iosurface") > 0) |
154 DCHECK(extensions.count("GL_ARB_texture_rectangle") > 0); | 151 DCHECK(extensions.count("GL_ARB_texture_rectangle") > 0); |
155 | 152 |
156 capabilities_.using_gpu_memory_manager = | 153 capabilities_.using_gpu_memory_manager = |
157 extensions.count("GL_CHROMIUM_gpu_memory_manager") > 0 && | 154 extensions.count("GL_CHROMIUM_gpu_memory_manager") > 0 && |
158 Settings().use_memory_management; | 155 Settings().use_memory_management; |
(...skipping 25 matching lines...) Expand all Loading... |
184 | 181 |
185 if (!InitializeSharedObjects()) | 182 if (!InitializeSharedObjects()) |
186 return false; | 183 return false; |
187 | 184 |
188 // Make sure the viewport and context gets initialized, even if it is to zero. | 185 // Make sure the viewport and context gets initialized, even if it is to zero. |
189 ViewportChanged(); | 186 ViewportChanged(); |
190 return true; | 187 return true; |
191 } | 188 } |
192 | 189 |
193 GLRenderer::~GLRenderer() { | 190 GLRenderer::~GLRenderer() { |
194 context_->setSwapBuffersCompleteCallbackCHROMIUM(NULL); | |
195 context_->setMemoryAllocationChangedCallbackCHROMIUM(NULL); | 191 context_->setMemoryAllocationChangedCallbackCHROMIUM(NULL); |
196 context_->setContextLostCallback(NULL); | |
197 CleanupSharedObjects(); | 192 CleanupSharedObjects(); |
198 } | 193 } |
199 | 194 |
200 const RendererCapabilities& GLRenderer::Capabilities() const { | 195 const RendererCapabilities& GLRenderer::Capabilities() const { |
201 return capabilities_; | 196 return capabilities_; |
202 } | 197 } |
203 | 198 |
204 WebGraphicsContext3D* GLRenderer::Context() { return context_; } | 199 WebGraphicsContext3D* GLRenderer::Context() { return context_; } |
205 | 200 |
206 void GLRenderer::DebugGLCall(WebGraphicsContext3D* context, | 201 void GLRenderer::DebugGLCall(WebGraphicsContext3D* context, |
(...skipping 1675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1882 // assuming a double-buffered GPU pipeline. A texture can be | 1877 // assuming a double-buffered GPU pipeline. A texture can be |
1883 // written to after one full frame has past since it was last read. | 1878 // written to after one full frame has past since it was last read. |
1884 if (last_swap_fence_) | 1879 if (last_swap_fence_) |
1885 static_cast<SimpleSwapFence*>(last_swap_fence_.get())->SetHasPassed(); | 1880 static_cast<SimpleSwapFence*>(last_swap_fence_.get())->SetHasPassed(); |
1886 last_swap_fence_ = resource_provider_->GetReadLockFence(); | 1881 last_swap_fence_ = resource_provider_->GetReadLockFence(); |
1887 resource_provider_->SetReadLockFence(new SimpleSwapFence()); | 1882 resource_provider_->SetReadLockFence(new SimpleSwapFence()); |
1888 | 1883 |
1889 return true; | 1884 return true; |
1890 } | 1885 } |
1891 | 1886 |
1892 void GLRenderer::ReceiveCompositorFrameAck(const CompositorFrameAck& ack) { | |
1893 onSwapBuffersComplete(); | |
1894 } | |
1895 | |
1896 void GLRenderer::onSwapBuffersComplete() { client_->OnSwapBuffersComplete(); } | |
1897 | |
1898 void GLRenderer::onMemoryAllocationChanged( | 1887 void GLRenderer::onMemoryAllocationChanged( |
1899 WebGraphicsMemoryAllocation allocation) { | 1888 WebGraphicsMemoryAllocation allocation) { |
1900 // Just ignore the memory manager when it says to set the limit to zero | 1889 // Just ignore the memory manager when it says to set the limit to zero |
1901 // bytes. This will happen when the memory manager thinks that the renderer | 1890 // bytes. This will happen when the memory manager thinks that the renderer |
1902 // is not visible (which the renderer knows better). | 1891 // is not visible (which the renderer knows better). |
1903 if (allocation.bytesLimitWhenVisible) { | 1892 if (allocation.bytesLimitWhenVisible) { |
1904 ManagedMemoryPolicy policy( | 1893 ManagedMemoryPolicy policy( |
1905 allocation.bytesLimitWhenVisible, | 1894 allocation.bytesLimitWhenVisible, |
1906 PriorityCutoff(allocation.priorityCutoffWhenVisible), | 1895 PriorityCutoff(allocation.priorityCutoffWhenVisible), |
1907 allocation.bytesLimitWhenNotVisible, | 1896 allocation.bytesLimitWhenNotVisible, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1965 } | 1954 } |
1966 | 1955 |
1967 void GLRenderer::EnsureBackbuffer() { | 1956 void GLRenderer::EnsureBackbuffer() { |
1968 if (!is_backbuffer_discarded_) | 1957 if (!is_backbuffer_discarded_) |
1969 return; | 1958 return; |
1970 | 1959 |
1971 output_surface_->EnsureBackbuffer(); | 1960 output_surface_->EnsureBackbuffer(); |
1972 is_backbuffer_discarded_ = false; | 1961 is_backbuffer_discarded_ = false; |
1973 } | 1962 } |
1974 | 1963 |
1975 void GLRenderer::onContextLost() { client_->DidLoseOutputSurface(); } | |
1976 | |
1977 void GLRenderer::GetFramebufferPixels(void* pixels, gfx::Rect rect) { | 1964 void GLRenderer::GetFramebufferPixels(void* pixels, gfx::Rect rect) { |
1978 DCHECK(rect.right() <= ViewportWidth()); | 1965 DCHECK(rect.right() <= ViewportWidth()); |
1979 DCHECK(rect.bottom() <= ViewportHeight()); | 1966 DCHECK(rect.bottom() <= ViewportHeight()); |
1980 | 1967 |
1981 if (!pixels) | 1968 if (!pixels) |
1982 return; | 1969 return; |
1983 | 1970 |
1984 MakeContextCurrent(); | 1971 MakeContextCurrent(); |
1985 | 1972 |
1986 bool do_workaround = NeedsIOSurfaceReadbackWorkaround(); | 1973 bool do_workaround = NeedsIOSurfaceReadbackWorkaround(); |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2584 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); | 2571 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); |
2585 | 2572 |
2586 ReleaseRenderPassTextures(); | 2573 ReleaseRenderPassTextures(); |
2587 } | 2574 } |
2588 | 2575 |
2589 bool GLRenderer::IsContextLost() { | 2576 bool GLRenderer::IsContextLost() { |
2590 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); | 2577 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); |
2591 } | 2578 } |
2592 | 2579 |
2593 } // namespace cc | 2580 } // namespace cc |
OLD | NEW |