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 "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 return renderer.Pass(); | 68 return renderer.Pass(); |
69 } | 69 } |
70 | 70 |
71 GLRenderer::GLRenderer(RendererClient* client, ResourceProvider* resourceProvide
r) | 71 GLRenderer::GLRenderer(RendererClient* client, ResourceProvider* resourceProvide
r) |
72 : DirectRenderer(client, resourceProvider) | 72 : DirectRenderer(client, resourceProvider) |
73 , m_offscreenFramebufferId(0) | 73 , m_offscreenFramebufferId(0) |
74 , m_sharedGeometryQuad(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f)) | 74 , m_sharedGeometryQuad(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f)) |
75 , m_context(resourceProvider->graphicsContext3D()) | 75 , m_context(resourceProvider->graphicsContext3D()) |
76 , m_isViewportChanged(false) | 76 , m_isViewportChanged(false) |
77 , m_isFramebufferDiscarded(false) | 77 , m_isBackbufferDiscarded(false) |
78 , m_discardFramebufferWhenNotVisible(false) | 78 , m_discardBackbufferWhenNotVisible(false) |
79 , m_isUsingBindUniform(false) | 79 , m_isUsingBindUniform(false) |
80 , m_visible(true) | 80 , m_visible(true) |
81 , m_isScissorEnabled(false) | 81 , m_isScissorEnabled(false) |
82 { | 82 { |
83 DCHECK(m_context); | 83 DCHECK(m_context); |
84 } | 84 } |
85 | 85 |
86 bool GLRenderer::initialize() | 86 bool GLRenderer::initialize() |
87 { | 87 { |
88 if (!m_context->makeContextCurrent()) | 88 if (!m_context->makeContextCurrent()) |
(...skipping 23 matching lines...) Expand all Loading... |
112 | 112 |
113 m_capabilities.usingSetVisibility = extensions.count("GL_CHROMIUM_set_visibi
lity"); | 113 m_capabilities.usingSetVisibility = extensions.count("GL_CHROMIUM_set_visibi
lity"); |
114 | 114 |
115 if (extensions.count("GL_CHROMIUM_iosurface")) | 115 if (extensions.count("GL_CHROMIUM_iosurface")) |
116 DCHECK(extensions.count("GL_ARB_texture_rectangle")); | 116 DCHECK(extensions.count("GL_ARB_texture_rectangle")); |
117 | 117 |
118 m_capabilities.usingGpuMemoryManager = extensions.count("GL_CHROMIUM_gpu_mem
ory_manager"); | 118 m_capabilities.usingGpuMemoryManager = extensions.count("GL_CHROMIUM_gpu_mem
ory_manager"); |
119 if (m_capabilities.usingGpuMemoryManager) | 119 if (m_capabilities.usingGpuMemoryManager) |
120 m_context->setMemoryAllocationChangedCallbackCHROMIUM(this); | 120 m_context->setMemoryAllocationChangedCallbackCHROMIUM(this); |
121 | 121 |
122 m_capabilities.usingDiscardFramebuffer = extensions.count("GL_CHROMIUM_disca
rd_framebuffer"); | 122 m_capabilities.usingDiscardBackbuffer = extensions.count("GL_CHROMIUM_discar
d_backbuffer"); |
123 | 123 |
124 m_capabilities.usingEglImage = extensions.count("GL_OES_EGL_image_external")
; | 124 m_capabilities.usingEglImage = extensions.count("GL_OES_EGL_image_external")
; |
125 | 125 |
126 GLC(m_context, m_context->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_capabilities.m
axTextureSize)); | 126 GLC(m_context, m_context->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_capabilities.m
axTextureSize)); |
127 m_capabilities.bestTextureFormat = PlatformColor::bestTextureFormat(m_contex
t, extensions.count("GL_EXT_texture_format_BGRA8888")); | 127 m_capabilities.bestTextureFormat = PlatformColor::bestTextureFormat(m_contex
t, extensions.count("GL_EXT_texture_format_BGRA8888")); |
128 | 128 |
129 // The updater can access textures while the GLRenderer is using them. | 129 // The updater can access textures while the GLRenderer is using them. |
130 m_capabilities.allowPartialTextureUpdates = true; | 130 m_capabilities.allowPartialTextureUpdates = true; |
131 | 131 |
132 m_isUsingBindUniform = extensions.count("GL_CHROMIUM_bind_uniform_location")
; | 132 m_isUsingBindUniform = extensions.count("GL_CHROMIUM_bind_uniform_location")
; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 if (m_capabilities.usingSetVisibility) | 181 if (m_capabilities.usingSetVisibility) |
182 m_context->setVisibilityCHROMIUM(visible); | 182 m_context->setVisibilityCHROMIUM(visible); |
183 } | 183 } |
184 | 184 |
185 void GLRenderer::sendManagedMemoryStats(size_t bytesVisible, size_t bytesVisible
AndNearby, size_t bytesAllocated) | 185 void GLRenderer::sendManagedMemoryStats(size_t bytesVisible, size_t bytesVisible
AndNearby, size_t bytesAllocated) |
186 { | 186 { |
187 WebKit::WebGraphicsManagedMemoryStats stats; | 187 WebKit::WebGraphicsManagedMemoryStats stats; |
188 stats.bytesVisible = bytesVisible; | 188 stats.bytesVisible = bytesVisible; |
189 stats.bytesVisibleAndNearby = bytesVisibleAndNearby; | 189 stats.bytesVisibleAndNearby = bytesVisibleAndNearby; |
190 stats.bytesAllocated = bytesAllocated; | 190 stats.bytesAllocated = bytesAllocated; |
191 stats.backbufferRequested = !m_isFramebufferDiscarded; | 191 stats.backbufferRequested = !m_isBackbufferDiscarded; |
192 m_context->sendManagedMemoryStatsCHROMIUM(&stats); | 192 m_context->sendManagedMemoryStatsCHROMIUM(&stats); |
193 } | 193 } |
194 | 194 |
195 void GLRenderer::releaseRenderPassTextures() | 195 void GLRenderer::releaseRenderPassTextures() |
196 { | 196 { |
197 m_renderPassTextures.clear(); | 197 m_renderPassTextures.clear(); |
198 } | 198 } |
199 | 199 |
200 void GLRenderer::viewportChanged() | 200 void GLRenderer::viewportChanged() |
201 { | 201 { |
202 m_isViewportChanged = true; | 202 m_isViewportChanged = true; |
203 } | 203 } |
204 | 204 |
205 void GLRenderer::clearFramebuffer(DrawingFrame& frame) | 205 void GLRenderer::clearFramebuffer(DrawingFrame& frame) |
206 { | 206 { |
207 // On DEBUG builds, opaque render passes are cleared to blue to easily see r
egions that were not drawn on the screen. | 207 // On DEBUG builds, opaque render passes are cleared to blue to easily see r
egions that were not drawn on the screen. |
208 if (frame.currentRenderPass->has_transparent_background) | 208 if (frame.currentRenderPass->has_transparent_background) |
209 GLC(m_context, m_context->clearColor(0, 0, 0, 0)); | 209 GLC(m_context, m_context->clearColor(0, 0, 0, 0)); |
210 else | 210 else |
211 GLC(m_context, m_context->clearColor(0, 0, 1, 1)); | 211 GLC(m_context, m_context->clearColor(0, 0, 1, 1)); |
212 | 212 |
213 #ifdef NDEBUG | 213 #ifdef NDEBUG |
214 if (frame.currentRenderPass->has_transparent_background) | 214 if (frame.currentRenderPass->has_transparent_background) |
215 #endif | 215 #endif |
216 m_context->clear(GL_COLOR_BUFFER_BIT); | 216 m_context->clear(GL_COLOR_BUFFER_BIT); |
217 } | 217 } |
218 | 218 |
219 void GLRenderer::beginDrawingFrame(DrawingFrame& frame) | 219 void GLRenderer::beginDrawingFrame(DrawingFrame& frame) |
220 { | 220 { |
221 // FIXME: Remove this once framebuffer is automatically recreated on first u
se | 221 // FIXME: Remove this once backbuffer is automatically recreated on first us
e |
222 ensureFramebuffer(); | 222 ensureBackbuffer(); |
223 | 223 |
224 if (viewportSize().IsEmpty()) | 224 if (viewportSize().IsEmpty()) |
225 return; | 225 return; |
226 | 226 |
227 TRACE_EVENT0("cc", "GLRenderer::drawLayers"); | 227 TRACE_EVENT0("cc", "GLRenderer::drawLayers"); |
228 if (m_isViewportChanged) { | 228 if (m_isViewportChanged) { |
229 // Only reshape when we know we are going to draw. Otherwise, the reshap
e | 229 // Only reshape when we know we are going to draw. Otherwise, the reshap
e |
230 // can leave the window at the wrong size if we never draw and the prope
r | 230 // can leave the window at the wrong size if we never draw and the prope
r |
231 // viewport size is never set. | 231 // viewport size is never set. |
232 m_isViewportChanged = false; | 232 m_isViewportChanged = false; |
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1235 | 1235 |
1236 void GLRenderer::finish() | 1236 void GLRenderer::finish() |
1237 { | 1237 { |
1238 TRACE_EVENT0("cc", "GLRenderer::finish"); | 1238 TRACE_EVENT0("cc", "GLRenderer::finish"); |
1239 m_context->finish(); | 1239 m_context->finish(); |
1240 } | 1240 } |
1241 | 1241 |
1242 bool GLRenderer::swapBuffers() | 1242 bool GLRenderer::swapBuffers() |
1243 { | 1243 { |
1244 DCHECK(m_visible); | 1244 DCHECK(m_visible); |
1245 DCHECK(!m_isFramebufferDiscarded); | 1245 DCHECK(!m_isBackbufferDiscarded); |
1246 | 1246 |
1247 TRACE_EVENT0("cc", "GLRenderer::swapBuffers"); | 1247 TRACE_EVENT0("cc", "GLRenderer::swapBuffers"); |
1248 // We're done! Time to swapbuffers! | 1248 // We're done! Time to swapbuffers! |
1249 | 1249 |
1250 if (m_capabilities.usingPartialSwap) { | 1250 if (m_capabilities.usingPartialSwap) { |
1251 // If supported, we can save significant bandwidth by only swapping the
damaged/scissored region (clamped to the viewport) | 1251 // If supported, we can save significant bandwidth by only swapping the
damaged/scissored region (clamped to the viewport) |
1252 m_swapBufferRect.Intersect(gfx::Rect(gfx::Point(), viewportSize())); | 1252 m_swapBufferRect.Intersect(gfx::Rect(gfx::Point(), viewportSize())); |
1253 int flippedYPosOfRectBottom = viewportHeight() - m_swapBufferRect.y() -
m_swapBufferRect.height(); | 1253 int flippedYPosOfRectBottom = viewportHeight() - m_swapBufferRect.y() -
m_swapBufferRect.height(); |
1254 m_context->postSubBufferCHROMIUM(m_swapBufferRect.x(), flippedYPosOfRect
Bottom, m_swapBufferRect.width(), m_swapBufferRect.height()); | 1254 m_context->postSubBufferCHROMIUM(m_swapBufferRect.x(), flippedYPosOfRect
Bottom, m_swapBufferRect.width(), m_swapBufferRect.height()); |
1255 } else { | 1255 } else { |
(...skipping 23 matching lines...) Expand all Loading... |
1279 priorityCutoffValue(allocation.priorityCutoffWhenVisible), | 1279 priorityCutoffValue(allocation.priorityCutoffWhenVisible), |
1280 allocation.bytesLimitWhenNotVisible, | 1280 allocation.bytesLimitWhenNotVisible, |
1281 priorityCutoffValue(allocation.priorityCutoffWhenNotVisible)); | 1281 priorityCutoffValue(allocation.priorityCutoffWhenNotVisible)); |
1282 | 1282 |
1283 if (allocation.enforceButDoNotKeepAsPolicy) | 1283 if (allocation.enforceButDoNotKeepAsPolicy) |
1284 m_client->enforceManagedMemoryPolicy(policy); | 1284 m_client->enforceManagedMemoryPolicy(policy); |
1285 else | 1285 else |
1286 m_client->setManagedMemoryPolicy(policy); | 1286 m_client->setManagedMemoryPolicy(policy); |
1287 } | 1287 } |
1288 | 1288 |
1289 bool oldDiscardFramebufferWhenNotVisible = m_discardFramebufferWhenNotVisibl
e; | 1289 bool oldDiscardBackbufferWhenNotVisible = m_discardBackbufferWhenNotVisible; |
1290 m_discardFramebufferWhenNotVisible = !allocation.suggestHaveBackbuffer; | 1290 m_discardBackbufferWhenNotVisible = !allocation.suggestHaveBackbuffer; |
1291 enforceMemoryPolicy(); | 1291 enforceMemoryPolicy(); |
1292 if (allocation.enforceButDoNotKeepAsPolicy) | 1292 if (allocation.enforceButDoNotKeepAsPolicy) |
1293 m_discardFramebufferWhenNotVisible = oldDiscardFramebufferWhenNotVisible
; | 1293 m_discardBackbufferWhenNotVisible = oldDiscardBackbufferWhenNotVisible; |
1294 } | 1294 } |
1295 | 1295 |
1296 int GLRenderer::priorityCutoffValue(WebKit::WebGraphicsMemoryAllocation::Priorit
yCutoff priorityCutoff) | 1296 int GLRenderer::priorityCutoffValue(WebKit::WebGraphicsMemoryAllocation::Priorit
yCutoff priorityCutoff) |
1297 { | 1297 { |
1298 switch (priorityCutoff) { | 1298 switch (priorityCutoff) { |
1299 case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowNothing: | 1299 case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowNothing: |
1300 return PriorityCalculator::allowNothingCutoff(); | 1300 return PriorityCalculator::allowNothingCutoff(); |
1301 case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleOnly: | 1301 case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleOnly: |
1302 return PriorityCalculator::allowVisibleOnlyCutoff(); | 1302 return PriorityCalculator::allowVisibleOnlyCutoff(); |
1303 case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleAndNearb
y: | 1303 case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleAndNearb
y: |
1304 return PriorityCalculator::allowVisibleAndNearbyCutoff(); | 1304 return PriorityCalculator::allowVisibleAndNearbyCutoff(); |
1305 case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowEverything: | 1305 case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowEverything: |
1306 return PriorityCalculator::allowEverythingCutoff(); | 1306 return PriorityCalculator::allowEverythingCutoff(); |
1307 } | 1307 } |
1308 NOTREACHED(); | 1308 NOTREACHED(); |
1309 return 0; | 1309 return 0; |
1310 } | 1310 } |
1311 | 1311 |
1312 void GLRenderer::enforceMemoryPolicy() | 1312 void GLRenderer::enforceMemoryPolicy() |
1313 { | 1313 { |
1314 if (!m_visible) { | 1314 if (!m_visible) { |
1315 TRACE_EVENT0("cc", "GLRenderer::enforceMemoryPolicy dropping resources")
; | 1315 TRACE_EVENT0("cc", "GLRenderer::enforceMemoryPolicy dropping resources")
; |
1316 releaseRenderPassTextures(); | 1316 releaseRenderPassTextures(); |
1317 if (m_discardFramebufferWhenNotVisible) | 1317 if (m_discardBackbufferWhenNotVisible) |
1318 discardFramebuffer(); | 1318 discardBackbuffer(); |
1319 GLC(m_context, m_context->flush()); | 1319 GLC(m_context, m_context->flush()); |
1320 } | 1320 } |
1321 } | 1321 } |
1322 | 1322 |
1323 void GLRenderer::discardFramebuffer() | 1323 void GLRenderer::discardBackbuffer() |
1324 { | 1324 { |
1325 if (m_isFramebufferDiscarded) | 1325 if (m_isBackbufferDiscarded) |
1326 return; | 1326 return; |
1327 | 1327 |
1328 if (!m_capabilities.usingDiscardFramebuffer) | 1328 if (!m_capabilities.usingDiscardBackbuffer) |
1329 return; | 1329 return; |
1330 | 1330 |
1331 // FIXME: Update attachments argument to appropriate values once they are no
longer ignored. | 1331 m_context->discardBackbufferCHROMIUM(); |
1332 m_context->discardFramebufferEXT(GL_TEXTURE_2D, 0, 0); | 1332 m_isBackbufferDiscarded = true; |
1333 m_isFramebufferDiscarded = true; | |
1334 | 1333 |
1335 // Damage tracker needs a full reset every time framebuffer is discarded. | 1334 // Damage tracker needs a full reset every time framebuffer is discarded. |
1336 m_client->setFullRootLayerDamage(); | 1335 m_client->setFullRootLayerDamage(); |
1337 } | 1336 } |
1338 | 1337 |
1339 void GLRenderer::ensureFramebuffer() | 1338 void GLRenderer::ensureBackbuffer() |
1340 { | 1339 { |
1341 if (!m_isFramebufferDiscarded) | 1340 if (!m_isBackbufferDiscarded) |
1342 return; | 1341 return; |
1343 | 1342 |
1344 if (!m_capabilities.usingDiscardFramebuffer) | 1343 if (!m_capabilities.usingDiscardBackbuffer) |
1345 return; | 1344 return; |
1346 | 1345 |
1347 m_context->ensureFramebufferCHROMIUM(); | 1346 m_context->ensureBackbufferCHROMIUM(); |
1348 m_isFramebufferDiscarded = false; | 1347 m_isBackbufferDiscarded = false; |
1349 } | 1348 } |
1350 | 1349 |
1351 void GLRenderer::onContextLost() | 1350 void GLRenderer::onContextLost() |
1352 { | 1351 { |
1353 m_client->didLoseOutputSurface(); | 1352 m_client->didLoseOutputSurface(); |
1354 } | 1353 } |
1355 | 1354 |
1356 | 1355 |
1357 void GLRenderer::getFramebufferPixels(void *pixels, const gfx::Rect& rect) | 1356 void GLRenderer::getFramebufferPixels(void *pixels, const gfx::Rect& rect) |
1358 { | 1357 { |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1748 | 1747 |
1749 releaseRenderPassTextures(); | 1748 releaseRenderPassTextures(); |
1750 } | 1749 } |
1751 | 1750 |
1752 bool GLRenderer::isContextLost() | 1751 bool GLRenderer::isContextLost() |
1753 { | 1752 { |
1754 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); | 1753 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); |
1755 } | 1754 } |
1756 | 1755 |
1757 } // namespace cc | 1756 } // namespace cc |
OLD | NEW |