OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 17 matching lines...) Expand all Loading... |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 | 31 |
32 #include "config.h" | 32 #include "config.h" |
33 | 33 |
34 #if USE(ACCELERATED_COMPOSITING) | 34 #if USE(ACCELERATED_COMPOSITING) |
35 #include "LayerRendererChromium.h" | 35 #include "LayerRendererChromium.h" |
36 | 36 |
37 #include "Extensions3D.h" | 37 #include "Extensions3D.h" |
38 #include "Extensions3DChromium.h" | |
39 #include "FloatQuad.h" | 38 #include "FloatQuad.h" |
40 #include "GeometryBinding.h" | 39 #include "GeometryBinding.h" |
41 #include "GrTexture.h" | 40 #include "GrTexture.h" |
42 #include "GraphicsContext3D.h" | 41 #include "GraphicsContext3D.h" |
43 #include "ManagedTexture.h" | 42 #include "ManagedTexture.h" |
44 #include "NativeImageSkia.h" | 43 #include "NativeImageSkia.h" |
45 #include "NotImplemented.h" | 44 #include "NotImplemented.h" |
46 #include "PlatformColor.h" | 45 #include "PlatformColor.h" |
47 #include "PlatformContextSkia.h" | 46 #include "PlatformContextSkia.h" |
48 #include "SharedGraphicsContext3D.h" | 47 #include "SharedGraphicsContext3D.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 214 |
216 private: | 215 private: |
217 explicit LayerRendererGpuMemoryAllocationChangedCallbackAdapter(LayerRendere
rChromium* layerRenderer) | 216 explicit LayerRendererGpuMemoryAllocationChangedCallbackAdapter(LayerRendere
rChromium* layerRenderer) |
218 : m_layerRenderer(layerRenderer), m_bindToImplThread(!CCProxy::hasImplTh
read()) | 217 : m_layerRenderer(layerRenderer), m_bindToImplThread(!CCProxy::hasImplTh
read()) |
219 { | 218 { |
220 } | 219 } |
221 | 220 |
222 void onGpuMemoryAllocationChangedOnImpl(Extensions3DChromium::GpuMemoryAlloc
ationCHROMIUM allocation) | 221 void onGpuMemoryAllocationChangedOnImpl(Extensions3DChromium::GpuMemoryAlloc
ationCHROMIUM allocation) |
223 { | 222 { |
224 ASSERT(CCProxy::isImplThread()); | 223 ASSERT(CCProxy::isImplThread()); |
225 if (!allocation.suggestHaveBackbuffer) | 224 m_layerRenderer->setGpuMemoryAllocation(allocation); |
226 m_layerRenderer->discardFramebuffer(); | |
227 else | |
228 m_layerRenderer->ensureFramebuffer(); | |
229 m_layerRenderer->m_client->setContentsMemoryAllocationLimitBytes(allocat
ion.gpuResourceSizeInBytes); | |
230 } | 225 } |
231 | 226 |
232 LayerRendererChromium* m_layerRenderer; | 227 LayerRendererChromium* m_layerRenderer; |
233 bool m_bindToImplThread; | 228 bool m_bindToImplThread; |
234 }; | 229 }; |
235 | 230 |
236 PassOwnPtr<LayerRendererChromium> LayerRendererChromium::create(CCRendererClient
* client, PassRefPtr<GraphicsContext3D> context, TextureUploaderOption textureUp
loaderSetting) | 231 PassOwnPtr<LayerRendererChromium> LayerRendererChromium::create(CCRendererClient
* client, PassRefPtr<GraphicsContext3D> context, TextureUploaderOption textureUp
loaderSetting) |
237 { | 232 { |
238 OwnPtr<LayerRendererChromium> layerRenderer(adoptPtr(new LayerRendererChromi
um(client, context, textureUploaderSetting))); | 233 OwnPtr<LayerRendererChromium> layerRenderer(adoptPtr(new LayerRendererChromi
um(client, context, textureUploaderSetting))); |
239 if (!layerRenderer->initialize()) | 234 if (!layerRenderer->initialize()) |
240 return nullptr; | 235 return nullptr; |
241 | 236 |
242 return layerRenderer.release(); | 237 return layerRenderer.release(); |
243 } | 238 } |
244 | 239 |
245 LayerRendererChromium::LayerRendererChromium(CCRendererClient* client, | 240 LayerRendererChromium::LayerRendererChromium(CCRendererClient* client, |
246 PassRefPtr<GraphicsContext3D> conte
xt, | 241 PassRefPtr<GraphicsContext3D> conte
xt, |
247 TextureUploaderOption textureUpload
erSetting) | 242 TextureUploaderOption textureUpload
erSetting) |
248 : CCRenderer(client) | 243 : CCRenderer(client) |
249 , m_currentRenderPass(0) | 244 , m_currentRenderPass(0) |
250 , m_currentManagedTexture(0) | 245 , m_currentManagedTexture(0) |
251 , m_offscreenFramebufferId(0) | 246 , m_offscreenFramebufferId(0) |
252 , m_sharedGeometryQuad(FloatRect(-0.5f, -0.5f, 1.0f, 1.0f)) | 247 , m_sharedGeometryQuad(FloatRect(-0.5f, -0.5f, 1.0f, 1.0f)) |
253 , m_context(context) | 248 , m_context(context) |
254 , m_defaultRenderPass(0) | 249 , m_defaultRenderPass(0) |
255 , m_isViewportChanged(false) | 250 , m_isViewportChanged(false) |
256 , m_isFramebufferDiscarded(false) | 251 , m_isFramebufferDiscarded(false) |
| 252 , m_visible(true) |
257 , m_textureUploaderSetting(textureUploaderSetting) | 253 , m_textureUploaderSetting(textureUploaderSetting) |
258 { | 254 { |
259 ASSERT(m_context.get()); | 255 ASSERT(m_context.get()); |
260 } | 256 } |
261 | 257 |
262 class ContextLostCallbackAdapter : public GraphicsContext3D::ContextLostCallback
{ | 258 class ContextLostCallbackAdapter : public GraphicsContext3D::ContextLostCallback
{ |
263 public: | 259 public: |
264 static PassOwnPtr<ContextLostCallbackAdapter> create(CCRendererClient* clien
t) | 260 static PassOwnPtr<ContextLostCallbackAdapter> create(CCRendererClient* clien
t) |
265 { | 261 { |
266 return adoptPtr(new ContextLostCallbackAdapter(client)); | 262 return adoptPtr(new ContextLostCallbackAdapter(client)); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 m_capabilities.usingTextureStorageExtension = extensions->supports("GL_EXT_t
exture_storage"); | 326 m_capabilities.usingTextureStorageExtension = extensions->supports("GL_EXT_t
exture_storage"); |
331 if (m_capabilities.usingTextureStorageExtension) | 327 if (m_capabilities.usingTextureStorageExtension) |
332 extensions->ensureEnabled("GL_EXT_texture_storage"); | 328 extensions->ensureEnabled("GL_EXT_texture_storage"); |
333 | 329 |
334 m_capabilities.usingGpuMemoryManager = extensions->supports("GL_CHROMIUM_gpu
_memory_manager"); | 330 m_capabilities.usingGpuMemoryManager = extensions->supports("GL_CHROMIUM_gpu
_memory_manager"); |
335 if (m_capabilities.usingGpuMemoryManager) { | 331 if (m_capabilities.usingGpuMemoryManager) { |
336 extensions->ensureEnabled("GL_CHROMIUM_gpu_memory_manager"); | 332 extensions->ensureEnabled("GL_CHROMIUM_gpu_memory_manager"); |
337 Extensions3DChromium* extensions3DChromium = static_cast<Extensions3DChr
omium*>(extensions); | 333 Extensions3DChromium* extensions3DChromium = static_cast<Extensions3DChr
omium*>(extensions); |
338 extensions3DChromium->setGpuMemoryAllocationChangedCallbackCHROMIUM(Laye
rRendererGpuMemoryAllocationChangedCallbackAdapter::create(this)); | 334 extensions3DChromium->setGpuMemoryAllocationChangedCallbackCHROMIUM(Laye
rRendererGpuMemoryAllocationChangedCallbackAdapter::create(this)); |
339 } else { | 335 } else { |
340 m_client->setContentsMemoryAllocationLimitBytes(TextureManager::highLimi
tBytes(viewportSize())); | 336 m_client->setMemoryAllocationLimitBytes(TextureManager::highLimitBytes(v
iewportSize())); |
341 } | 337 } |
342 | 338 |
343 m_capabilities.usingDiscardFramebuffer = extensions->supports("GL_CHROMIUM_d
iscard_framebuffer"); | 339 m_capabilities.usingDiscardFramebuffer = extensions->supports("GL_CHROMIUM_d
iscard_framebuffer"); |
344 if (m_capabilities.usingDiscardFramebuffer) | 340 if (m_capabilities.usingDiscardFramebuffer) |
345 extensions->ensureEnabled("GL_CHROMIUM_discard_framebuffer"); | 341 extensions->ensureEnabled("GL_CHROMIUM_discard_framebuffer"); |
346 | 342 |
347 GLC(m_context, m_context->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &
m_capabilities.maxTextureSize)); | 343 GLC(m_context, m_context->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &
m_capabilities.maxTextureSize)); |
348 m_capabilities.bestTextureFormat = PlatformColor::bestTextureFormat(m_contex
t.get()); | 344 m_capabilities.bestTextureFormat = PlatformColor::bestTextureFormat(m_contex
t.get()); |
349 | 345 |
350 if (!initializeSharedObjects()) | 346 if (!initializeSharedObjects()) |
(...skipping 20 matching lines...) Expand all Loading... |
371 | 367 |
372 void LayerRendererChromium::debugGLCall(GraphicsContext3D* context, const char*
command, const char* file, int line) | 368 void LayerRendererChromium::debugGLCall(GraphicsContext3D* context, const char*
command, const char* file, int line) |
373 { | 369 { |
374 unsigned long error = context->getError(); | 370 unsigned long error = context->getError(); |
375 if (error != GraphicsContext3D::NO_ERROR) | 371 if (error != GraphicsContext3D::NO_ERROR) |
376 LOG_ERROR("GL command failed: File: %s\n\tLine %d\n\tcommand: %s, error
%x\n", file, line, command, static_cast<int>(error)); | 372 LOG_ERROR("GL command failed: File: %s\n\tLine %d\n\tcommand: %s, error
%x\n", file, line, command, static_cast<int>(error)); |
377 } | 373 } |
378 | 374 |
379 void LayerRendererChromium::setVisible(bool visible) | 375 void LayerRendererChromium::setVisible(bool visible) |
380 { | 376 { |
381 if (!visible) | 377 if (m_visible == visible) |
382 releaseRenderPassTextures(); | 378 return; |
| 379 m_visible = visible; |
383 | 380 |
384 // TODO: Replace setVisibilityCHROMIUM with an extension to explicitly manag
e front/backbuffers | 381 // TODO: Replace setVisibilityCHROMIUM with an extension to explicitly manag
e front/backbuffers |
385 // crbug.com/116049 | 382 // crbug.com/116049 |
386 if (m_capabilities.usingSetVisibility) { | 383 if (m_capabilities.usingSetVisibility) { |
387 Extensions3DChromium* extensions3DChromium = static_cast<Extensions3DChr
omium*>(m_context->getExtensions()); | 384 Extensions3DChromium* extensions3DChromium = static_cast<Extensions3DChr
omium*>(m_context->getExtensions()); |
388 extensions3DChromium->setVisibilityCHROMIUM(visible); | 385 extensions3DChromium->setVisibilityCHROMIUM(visible); |
389 } | 386 } |
390 } | 387 } |
391 | 388 |
392 void LayerRendererChromium::releaseRenderPassTextures() | 389 void LayerRendererChromium::releaseRenderPassTextures() |
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE)); | 1257 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE)); |
1261 | 1258 |
1262 GLC(context(), context()->useProgram(program->program())); | 1259 GLC(context(), context()->useProgram(program->program())); |
1263 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio
n(), 0)); | 1260 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio
n(), 0)); |
1264 drawTexturedQuad(drawMatrix, bounds.width(), bounds.height(), 1, sharedGeome
tryQuad(), | 1261 drawTexturedQuad(drawMatrix, bounds.width(), bounds.height(), 1, sharedGeome
tryQuad(), |
1265 program->vertexShader().matrixLocation(), | 1262 program->vertexShader().matrixLocation(), |
1266 program->fragmentShader().alphaLocation(), | 1263 program->fragmentShader().alphaLocation(), |
1267 -1); | 1264 -1); |
1268 } | 1265 } |
1269 | 1266 |
| 1267 void LayerRendererChromium::setGpuMemoryAllocation(Extensions3DChromium::GpuMemo
ryAllocationCHROMIUM allocation) |
| 1268 { |
| 1269 if (m_visible && !allocation.gpuResourceSizeInBytes) |
| 1270 return; |
| 1271 |
| 1272 if (!allocation.suggestHaveBackbuffer && !m_visible) |
| 1273 discardFramebuffer(); |
| 1274 |
| 1275 if (!allocation.gpuResourceSizeInBytes) { |
| 1276 releaseRenderPassTextures(); |
| 1277 m_client->releaseContentsTextures(); |
| 1278 GLC(m_context, m_context->flush()); |
| 1279 } else |
| 1280 m_client->setMemoryAllocationLimitBytes(allocation.gpuResourceSizeInByte
s); |
| 1281 } |
| 1282 |
1270 void LayerRendererChromium::finish() | 1283 void LayerRendererChromium::finish() |
1271 { | 1284 { |
1272 TRACE_EVENT("LayerRendererChromium::finish", this, 0); | 1285 TRACE_EVENT("LayerRendererChromium::finish", this, 0); |
1273 m_context->finish(); | 1286 m_context->finish(); |
1274 } | 1287 } |
1275 | 1288 |
1276 bool LayerRendererChromium::swapBuffers(const IntRect& subBuffer) | 1289 bool LayerRendererChromium::swapBuffers(const IntRect& subBuffer) |
1277 { | 1290 { |
1278 // FIXME: Remove this once gpu process supports ignoring swap buffers comman
d while framebuffer is discarded. | 1291 ASSERT(m_visible); |
1279 // Alternatively (preferably?), protect all cc code so as not to atte
mpt a swap after a framebuffer discard. | 1292 ASSERT(!m_isFramebufferDiscarded); |
1280 if (m_isFramebufferDiscarded) { | |
1281 m_client->setFullRootLayerDamage(); | |
1282 return false; | |
1283 } | |
1284 | 1293 |
1285 TRACE_EVENT("LayerRendererChromium::swapBuffers", this, 0); | 1294 TRACE_EVENT("LayerRendererChromium::swapBuffers", this, 0); |
1286 // We're done! Time to swapbuffers! | 1295 // We're done! Time to swapbuffers! |
1287 | 1296 |
1288 if (m_capabilities.usingPartialSwap) { | 1297 if (m_capabilities.usingPartialSwap) { |
1289 // If supported, we can save significant bandwidth by only swapping the
damaged/scissored region (clamped to the viewport) | 1298 // If supported, we can save significant bandwidth by only swapping the
damaged/scissored region (clamped to the viewport) |
1290 IntRect clippedSubBuffer = subBuffer; | 1299 IntRect clippedSubBuffer = subBuffer; |
1291 clippedSubBuffer.intersect(IntRect(IntPoint::zero(), viewportSize())); | 1300 clippedSubBuffer.intersect(IntRect(IntPoint::zero(), viewportSize())); |
1292 Extensions3DChromium* extensions3DChromium = static_cast<Extensions3DChr
omium*>(m_context->getExtensions()); | 1301 Extensions3DChromium* extensions3DChromium = static_cast<Extensions3DChr
omium*>(m_context->getExtensions()); |
1293 int flippedYPosOfRectBottom = viewportHeight() - clippedSubBuffer.y() -
clippedSubBuffer.height(); | 1302 int flippedYPosOfRectBottom = viewportHeight() - clippedSubBuffer.y() -
clippedSubBuffer.height(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 GLC(context, context->readPixels(rect.x(), rect.y(), rect.width(), rect.heig
ht(), | 1386 GLC(context, context->readPixels(rect.x(), rect.y(), rect.width(), rect.heig
ht(), |
1378 GraphicsContext3D::RGBA, GraphicsContext3D:
:UNSIGNED_BYTE, pixels)); | 1387 GraphicsContext3D::RGBA, GraphicsContext3D:
:UNSIGNED_BYTE, pixels)); |
1379 | 1388 |
1380 if (doWorkaround) { | 1389 if (doWorkaround) { |
1381 // Clean up. | 1390 // Clean up. |
1382 GLC(context, context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0)
); | 1391 GLC(context, context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0)
); |
1383 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0)); | 1392 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0)); |
1384 GLC(context, context->deleteFramebuffer(temporaryFBO)); | 1393 GLC(context, context->deleteFramebuffer(temporaryFBO)); |
1385 GLC(context, context->deleteTexture(temporaryTexture)); | 1394 GLC(context, context->deleteTexture(temporaryTexture)); |
1386 } | 1395 } |
| 1396 |
| 1397 if (!m_visible) { |
| 1398 TRACE_EVENT0("cc", "LayerRendererChromium::getFramebufferPixels dropping
resources after readback"); |
| 1399 discardFramebuffer(); |
| 1400 releaseRenderPassTextures(); |
| 1401 m_client->releaseContentsTextures(); |
| 1402 GLC(m_context, m_context->flush()); |
| 1403 } |
1387 } | 1404 } |
1388 | 1405 |
1389 bool LayerRendererChromium::getFramebufferTexture(ManagedTexture* texture, const
IntRect& deviceRect) | 1406 bool LayerRendererChromium::getFramebufferTexture(ManagedTexture* texture, const
IntRect& deviceRect) |
1390 { | 1407 { |
1391 if (!texture->reserve(deviceRect.size(), GraphicsContext3D::RGB)) | 1408 if (!texture->reserve(deviceRect.size(), GraphicsContext3D::RGB)) |
1392 return false; | 1409 return false; |
1393 | 1410 |
1394 RefPtr<CCGraphicsContext> ccContext = CCGraphicsContext::create3D(m_context)
; | 1411 RefPtr<CCGraphicsContext> ccContext = CCGraphicsContext::create3D(m_context)
; |
1395 texture->bindTexture(ccContext.get(), m_implTextureAllocator.get()); | 1412 texture->bindTexture(ccContext.get(), m_implTextureAllocator.get()); |
1396 GLC(m_context, m_context->copyTexImage2D(GraphicsContext3D::TEXTURE_2D, 0, t
exture->format(), | 1413 GLC(m_context, m_context->copyTexImage2D(GraphicsContext3D::TEXTURE_2D, 0, t
exture->format(), |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1778 } | 1795 } |
1779 | 1796 |
1780 bool LayerRendererChromium::isContextLost() | 1797 bool LayerRendererChromium::isContextLost() |
1781 { | 1798 { |
1782 return (m_context.get()->getExtensions()->getGraphicsResetStatusARB() != Gra
phicsContext3D::NO_ERROR); | 1799 return (m_context.get()->getExtensions()->getGraphicsResetStatusARB() != Gra
phicsContext3D::NO_ERROR); |
1783 } | 1800 } |
1784 | 1801 |
1785 } // namespace WebCore | 1802 } // namespace WebCore |
1786 | 1803 |
1787 #endif // USE(ACCELERATED_COMPOSITING) | 1804 #endif // USE(ACCELERATED_COMPOSITING) |
OLD | NEW |