| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/gl_renderer.h" | 7 #include "cc/gl_renderer.h" |
| 8 | 8 |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 m_capabilities.usingAcceleratedPainting = true; | 104 m_capabilities.usingAcceleratedPainting = true; |
| 105 else | 105 else |
| 106 m_capabilities.usingAcceleratedPainting = false; | 106 m_capabilities.usingAcceleratedPainting = false; |
| 107 | 107 |
| 108 | 108 |
| 109 m_capabilities.contextHasCachedFrontBuffer = extensions.count("GL_CHROMIUM_f
ront_buffer_cached"); | 109 m_capabilities.contextHasCachedFrontBuffer = extensions.count("GL_CHROMIUM_f
ront_buffer_cached"); |
| 110 | 110 |
| 111 m_capabilities.usingPartialSwap = Settings::partialSwapEnabled() && extensio
ns.count("GL_CHROMIUM_post_sub_buffer"); | 111 m_capabilities.usingPartialSwap = Settings::partialSwapEnabled() && extensio
ns.count("GL_CHROMIUM_post_sub_buffer"); |
| 112 | 112 |
| 113 // Use the swapBuffers callback only with the threaded proxy. | 113 // Use the swapBuffers callback only with the threaded proxy. |
| 114 if (m_client->hasImplThread()) | 114 if (Proxy::hasImplThread()) |
| 115 m_capabilities.usingSwapCompleteCallback = extensions.count("GL_CHROMIUM
_swapbuffers_complete_callback"); | 115 m_capabilities.usingSwapCompleteCallback = extensions.count("GL_CHROMIUM
_swapbuffers_complete_callback"); |
| 116 if (m_capabilities.usingSwapCompleteCallback) | 116 if (m_capabilities.usingSwapCompleteCallback) |
| 117 m_context->setSwapBuffersCompleteCallbackCHROMIUM(this); | 117 m_context->setSwapBuffersCompleteCallbackCHROMIUM(this); |
| 118 | 118 |
| 119 m_capabilities.usingSetVisibility = extensions.count("GL_CHROMIUM_set_visibi
lity"); | 119 m_capabilities.usingSetVisibility = extensions.count("GL_CHROMIUM_set_visibi
lity"); |
| 120 | 120 |
| 121 if (extensions.count("GL_CHROMIUM_iosurface")) | 121 if (extensions.count("GL_CHROMIUM_iosurface")) |
| 122 DCHECK(extensions.count("GL_ARB_texture_rectangle")); | 122 DCHECK(extensions.count("GL_ARB_texture_rectangle")); |
| 123 | 123 |
| 124 m_capabilities.usingGpuMemoryManager = extensions.count("GL_CHROMIUM_gpu_mem
ory_manager"); | 124 m_capabilities.usingGpuMemoryManager = extensions.count("GL_CHROMIUM_gpu_mem
ory_manager"); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 137 if (!initializeSharedObjects()) | 137 if (!initializeSharedObjects()) |
| 138 return false; | 138 return false; |
| 139 | 139 |
| 140 // Make sure the viewport and context gets initialized, even if it is to zer
o. | 140 // Make sure the viewport and context gets initialized, even if it is to zer
o. |
| 141 viewportChanged(); | 141 viewportChanged(); |
| 142 return true; | 142 return true; |
| 143 } | 143 } |
| 144 | 144 |
| 145 GLRenderer::~GLRenderer() | 145 GLRenderer::~GLRenderer() |
| 146 { | 146 { |
| 147 DCHECK(Proxy::isImplThread()); |
| 147 m_context->setSwapBuffersCompleteCallbackCHROMIUM(0); | 148 m_context->setSwapBuffersCompleteCallbackCHROMIUM(0); |
| 148 m_context->setMemoryAllocationChangedCallbackCHROMIUM(0); | 149 m_context->setMemoryAllocationChangedCallbackCHROMIUM(0); |
| 149 m_context->setContextLostCallback(0); | 150 m_context->setContextLostCallback(0); |
| 150 cleanupSharedObjects(); | 151 cleanupSharedObjects(); |
| 151 } | 152 } |
| 152 | 153 |
| 153 const RendererCapabilities& GLRenderer::capabilities() const | 154 const RendererCapabilities& GLRenderer::capabilities() const |
| 154 { | 155 { |
| 155 return m_capabilities; | 156 return m_capabilities; |
| 156 } | 157 } |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 float alpha = SkColorGetA(color) / 255.0; | 335 float alpha = SkColorGetA(color) / 255.0; |
| 335 | 336 |
| 336 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation(
), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, (
SkColorGetB(color) / 255.0) * alpha, alpha)); | 337 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation(
), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, (
SkColorGetB(color) / 255.0) * alpha, alpha)); |
| 337 | 338 |
| 338 GLC(context(), context()->lineWidth(quad->width())); | 339 GLC(context(), context()->lineWidth(quad->width())); |
| 339 | 340 |
| 340 // The indices for the line are stored in the same array as the triangle ind
ices. | 341 // The indices for the line are stored in the same array as the triangle ind
ices. |
| 341 GLC(context(), context()->drawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 6
* sizeof(unsigned short))); | 342 GLC(context(), context()->drawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 6
* sizeof(unsigned short))); |
| 342 } | 343 } |
| 343 | 344 |
| 344 static WebGraphicsContext3D* getFilterContext(bool hasImplThread) | 345 static WebGraphicsContext3D* getFilterContext() |
| 345 { | 346 { |
| 346 if (hasImplThread) | 347 if (Proxy::hasImplThread()) |
| 347 return WebSharedGraphicsContext3D::compositorThreadContext(); | 348 return WebSharedGraphicsContext3D::compositorThreadContext(); |
| 348 else | 349 else |
| 349 return WebSharedGraphicsContext3D::mainThreadContext(); | 350 return WebSharedGraphicsContext3D::mainThreadContext(); |
| 350 } | 351 } |
| 351 | 352 |
| 352 static GrContext* getFilterGrContext(bool hasImplThread) | 353 static GrContext* getFilterGrContext() |
| 353 { | 354 { |
| 354 if (hasImplThread) | 355 if (Proxy::hasImplThread()) |
| 355 return WebSharedGraphicsContext3D::compositorThreadGrContext(); | 356 return WebSharedGraphicsContext3D::compositorThreadGrContext(); |
| 356 else | 357 else |
| 357 return WebSharedGraphicsContext3D::mainThreadGrContext(); | 358 return WebSharedGraphicsContext3D::mainThreadGrContext(); |
| 358 } | 359 } |
| 359 | 360 |
| 360 static inline SkBitmap applyFilters(GLRenderer* renderer, const WebKit::WebFilte
rOperations& filters, ScopedTexture* sourceTexture, bool hasImplThread) | 361 static inline SkBitmap applyFilters(GLRenderer* renderer, const WebKit::WebFilte
rOperations& filters, ScopedTexture* sourceTexture) |
| 361 { | 362 { |
| 362 if (filters.isEmpty()) | 363 if (filters.isEmpty()) |
| 363 return SkBitmap(); | 364 return SkBitmap(); |
| 364 | 365 |
| 365 WebGraphicsContext3D* filterContext = getFilterContext(hasImplThread); | 366 WebGraphicsContext3D* filterContext = getFilterContext(); |
| 366 GrContext* filterGrContext = getFilterGrContext(hasImplThread); | 367 GrContext* filterGrContext = getFilterGrContext(); |
| 367 | 368 |
| 368 if (!filterContext || !filterGrContext) | 369 if (!filterContext || !filterGrContext) |
| 369 return SkBitmap(); | 370 return SkBitmap(); |
| 370 | 371 |
| 371 renderer->context()->flush(); | 372 renderer->context()->flush(); |
| 372 | 373 |
| 373 ResourceProvider::ScopedWriteLockGL lock(renderer->resourceProvider(), sourc
eTexture->id()); | 374 ResourceProvider::ScopedWriteLockGL lock(renderer->resourceProvider(), sourc
eTexture->id()); |
| 374 SkBitmap source = RenderSurfaceFilters::apply(filters, lock.textureId(), sou
rceTexture->size(), filterContext, filterGrContext); | 375 SkBitmap source = RenderSurfaceFilters::apply(filters, lock.textureId(), sou
rceTexture->size(), filterContext, filterGrContext); |
| 375 return source; | 376 return source; |
| 376 } | 377 } |
| 377 | 378 |
| 378 static SkBitmap applyImageFilter(GLRenderer* renderer, SkImageFilter* filter, Sc
opedTexture* sourceTexture, bool hasImplThread) | 379 static SkBitmap applyImageFilter(GLRenderer* renderer, SkImageFilter* filter, Sc
opedTexture* sourceTexture) |
| 379 { | 380 { |
| 380 if (!filter) | 381 if (!filter) |
| 381 return SkBitmap(); | 382 return SkBitmap(); |
| 382 | 383 |
| 383 WebGraphicsContext3D* context3d = getFilterContext(hasImplThread); | 384 WebGraphicsContext3D* context3d = getFilterContext(); |
| 384 GrContext* grContext = getFilterGrContext(hasImplThread); | 385 GrContext* grContext = getFilterGrContext(); |
| 385 | 386 |
| 386 if (!context3d || !grContext) | 387 if (!context3d || !grContext) |
| 387 return SkBitmap(); | 388 return SkBitmap(); |
| 388 | 389 |
| 389 renderer->context()->flush(); | 390 renderer->context()->flush(); |
| 390 | 391 |
| 391 ResourceProvider::ScopedWriteLockGL lock(renderer->resourceProvider(), sourc
eTexture->id()); | 392 ResourceProvider::ScopedWriteLockGL lock(renderer->resourceProvider(), sourc
eTexture->id()); |
| 392 | 393 |
| 393 // Wrap the source texture in a Ganesh platform texture. | 394 // Wrap the source texture in a Ganesh platform texture. |
| 394 GrPlatformTextureDesc platformTextureDescription; | 395 GrPlatformTextureDesc platformTextureDescription; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 int top, right, bottom, left; | 461 int top, right, bottom, left; |
| 461 filters.getOutsets(top, right, bottom, left); | 462 filters.getOutsets(top, right, bottom, left); |
| 462 deviceRect.Inset(-left, -top, -right, -bottom); | 463 deviceRect.Inset(-left, -top, -right, -bottom); |
| 463 | 464 |
| 464 deviceRect.Intersect(frame.currentRenderPass->outputRect()); | 465 deviceRect.Intersect(frame.currentRenderPass->outputRect()); |
| 465 | 466 |
| 466 scoped_ptr<ScopedTexture> deviceBackgroundTexture = ScopedTexture::create(m_
resourceProvider); | 467 scoped_ptr<ScopedTexture> deviceBackgroundTexture = ScopedTexture::create(m_
resourceProvider); |
| 467 if (!getFramebufferTexture(deviceBackgroundTexture.get(), deviceRect)) | 468 if (!getFramebufferTexture(deviceBackgroundTexture.get(), deviceRect)) |
| 468 return scoped_ptr<ScopedTexture>(); | 469 return scoped_ptr<ScopedTexture>(); |
| 469 | 470 |
| 470 SkBitmap filteredDeviceBackground = applyFilters(this, filters, deviceBackgr
oundTexture.get(), m_client->hasImplThread()); | 471 SkBitmap filteredDeviceBackground = applyFilters(this, filters, deviceBackgr
oundTexture.get()); |
| 471 if (!filteredDeviceBackground.getTexture()) | 472 if (!filteredDeviceBackground.getTexture()) |
| 472 return scoped_ptr<ScopedTexture>(); | 473 return scoped_ptr<ScopedTexture>(); |
| 473 | 474 |
| 474 GrTexture* texture = reinterpret_cast<GrTexture*>(filteredDeviceBackground.g
etTexture()); | 475 GrTexture* texture = reinterpret_cast<GrTexture*>(filteredDeviceBackground.g
etTexture()); |
| 475 int filteredDeviceBackgroundTextureId = texture->getTextureHandle(); | 476 int filteredDeviceBackgroundTextureId = texture->getTextureHandle(); |
| 476 | 477 |
| 477 scoped_ptr<ScopedTexture> backgroundTexture = ScopedTexture::create(m_resour
ceProvider); | 478 scoped_ptr<ScopedTexture> backgroundTexture = ScopedTexture::create(m_resour
ceProvider); |
| 478 if (!backgroundTexture->allocate(Renderer::ImplPool, quad->quadRect().size()
, GL_RGBA, ResourceProvider::TextureUsageFramebuffer)) | 479 if (!backgroundTexture->allocate(Renderer::ImplPool, quad->quadRect().size()
, GL_RGBA, ResourceProvider::TextureUsageFramebuffer)) |
| 479 return scoped_ptr<ScopedTexture>(); | 480 return scoped_ptr<ScopedTexture>(); |
| 480 | 481 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 // Can only draw surface if device matrix is invertible. | 516 // Can only draw surface if device matrix is invertible. |
| 516 if (!contentsDeviceTransform.isInvertible()) | 517 if (!contentsDeviceTransform.isInvertible()) |
| 517 return; | 518 return; |
| 518 | 519 |
| 519 scoped_ptr<ScopedTexture> backgroundTexture = drawBackgroundFilters(frame, q
uad, renderPass->backgroundFilters(), contentsDeviceTransform); | 520 scoped_ptr<ScopedTexture> backgroundTexture = drawBackgroundFilters(frame, q
uad, renderPass->backgroundFilters(), contentsDeviceTransform); |
| 520 | 521 |
| 521 // FIXME: Cache this value so that we don't have to do it for both the surfa
ce and its replica. | 522 // FIXME: Cache this value so that we don't have to do it for both the surfa
ce and its replica. |
| 522 // Apply filters to the contents texture. | 523 // Apply filters to the contents texture. |
| 523 SkBitmap filterBitmap; | 524 SkBitmap filterBitmap; |
| 524 if (renderPass->filter()) { | 525 if (renderPass->filter()) { |
| 525 filterBitmap = applyImageFilter(this, renderPass->filter(), contentsText
ure, m_client->hasImplThread()); | 526 filterBitmap = applyImageFilter(this, renderPass->filter(), contentsText
ure); |
| 526 } else { | 527 } else { |
| 527 filterBitmap = applyFilters(this, renderPass->filters(), contentsTexture
, m_client->hasImplThread()); | 528 filterBitmap = applyFilters(this, renderPass->filters(), contentsTexture
); |
| 528 } | 529 } |
| 529 scoped_ptr<ResourceProvider::ScopedReadLockGL> contentsResourceLock; | 530 scoped_ptr<ResourceProvider::ScopedReadLockGL> contentsResourceLock; |
| 530 unsigned contentsTextureId = 0; | 531 unsigned contentsTextureId = 0; |
| 531 if (filterBitmap.getTexture()) { | 532 if (filterBitmap.getTexture()) { |
| 532 GrTexture* texture = reinterpret_cast<GrTexture*>(filterBitmap.getTextur
e()); | 533 GrTexture* texture = reinterpret_cast<GrTexture*>(filterBitmap.getTextur
e()); |
| 533 contentsTextureId = texture->getTextureHandle(); | 534 contentsTextureId = texture->getTextureHandle(); |
| 534 } else { | 535 } else { |
| 535 contentsResourceLock = make_scoped_ptr(new ResourceProvider::ScopedReadL
ockGL(m_resourceProvider, contentsTexture->id())); | 536 contentsResourceLock = make_scoped_ptr(new ResourceProvider::ScopedReadL
ockGL(m_resourceProvider, contentsTexture->id())); |
| 536 contentsTextureId = contentsResourceLock->textureId(); | 537 contentsTextureId = contentsResourceLock->textureId(); |
| 537 } | 538 } |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 template<class Program> void set(Program* program) | 946 template<class Program> void set(Program* program) |
| 946 { | 947 { |
| 947 TextureProgramBinding::set(program); | 948 TextureProgramBinding::set(program); |
| 948 texTransformLocation = program->vertexShader().texTransformLocation(); | 949 texTransformLocation = program->vertexShader().texTransformLocation(); |
| 949 } | 950 } |
| 950 int texTransformLocation; | 951 int texTransformLocation; |
| 951 }; | 952 }; |
| 952 | 953 |
| 953 void GLRenderer::drawTextureQuad(const DrawingFrame& frame, const TextureDrawQua
d* quad) | 954 void GLRenderer::drawTextureQuad(const DrawingFrame& frame, const TextureDrawQua
d* quad) |
| 954 { | 955 { |
| 956 DCHECK(Proxy::isImplThread()); |
| 957 |
| 955 TexTransformTextureProgramBinding binding; | 958 TexTransformTextureProgramBinding binding; |
| 956 if (quad->flipped()) | 959 if (quad->flipped()) |
| 957 binding.set(textureProgramFlip()); | 960 binding.set(textureProgramFlip()); |
| 958 else | 961 else |
| 959 binding.set(textureProgram()); | 962 binding.set(textureProgram()); |
| 960 GLC(context(), context()->useProgram(binding.programId)); | 963 GLC(context(), context()->useProgram(binding.programId)); |
| 961 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); | 964 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); |
| 962 const gfx::RectF& uvRect = quad->uvRect(); | 965 const gfx::RectF& uvRect = quad->uvRect(); |
| 963 GLC(context(), context()->uniform4f(binding.texTransformLocation, uvRect.x()
, uvRect.y(), uvRect.width(), uvRect.height())); | 966 GLC(context(), context()->uniform4f(binding.texTransformLocation, uvRect.x()
, uvRect.y(), uvRect.width(), uvRect.height())); |
| 964 | 967 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 987 | 990 |
| 988 setShaderOpacity(quad->opacity(), binding.alphaLocation); | 991 setShaderOpacity(quad->opacity(), binding.alphaLocation); |
| 989 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), binding.mat
rixLocation); | 992 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), binding.mat
rixLocation); |
| 990 | 993 |
| 991 if (!quad->premultipliedAlpha()) | 994 if (!quad->premultipliedAlpha()) |
| 992 GLC(m_context, m_context->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | 995 GLC(m_context, m_context->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); |
| 993 } | 996 } |
| 994 | 997 |
| 995 void GLRenderer::drawIOSurfaceQuad(const DrawingFrame& frame, const IOSurfaceDra
wQuad* quad) | 998 void GLRenderer::drawIOSurfaceQuad(const DrawingFrame& frame, const IOSurfaceDra
wQuad* quad) |
| 996 { | 999 { |
| 1000 DCHECK(Proxy::isImplThread()); |
| 997 TexTransformTextureProgramBinding binding; | 1001 TexTransformTextureProgramBinding binding; |
| 998 binding.set(textureIOSurfaceProgram()); | 1002 binding.set(textureIOSurfaceProgram()); |
| 999 | 1003 |
| 1000 GLC(context(), context()->useProgram(binding.programId)); | 1004 GLC(context(), context()->useProgram(binding.programId)); |
| 1001 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); | 1005 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); |
| 1002 if (quad->orientation() == IOSurfaceDrawQuad::Flipped) | 1006 if (quad->orientation() == IOSurfaceDrawQuad::Flipped) |
| 1003 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, qua
d->ioSurfaceSize().height(), quad->ioSurfaceSize().width(), quad->ioSurfaceSize(
).height() * -1.0)); | 1007 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, qua
d->ioSurfaceSize().height(), quad->ioSurfaceSize().width(), quad->ioSurfaceSize(
).height() * -1.0)); |
| 1004 else | 1008 else |
| 1005 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, 0,
quad->ioSurfaceSize().width(), quad->ioSurfaceSize().height())); | 1009 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, 0,
quad->ioSurfaceSize().width(), quad->ioSurfaceSize().height())); |
| 1006 | 1010 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1128 return true; | 1132 return true; |
| 1129 } | 1133 } |
| 1130 | 1134 |
| 1131 void GLRenderer::onSwapBuffersComplete() | 1135 void GLRenderer::onSwapBuffersComplete() |
| 1132 { | 1136 { |
| 1133 m_client->onSwapBuffersComplete(); | 1137 m_client->onSwapBuffersComplete(); |
| 1134 } | 1138 } |
| 1135 | 1139 |
| 1136 void GLRenderer::onMemoryAllocationChanged(WebGraphicsMemoryAllocation allocatio
n) | 1140 void GLRenderer::onMemoryAllocationChanged(WebGraphicsMemoryAllocation allocatio
n) |
| 1137 { | 1141 { |
| 1142 // FIXME: This is called on the main thread in single threaded mode, but we
expect it on the impl thread. |
| 1143 if (!Proxy::hasImplThread()) { |
| 1144 DCHECK(Proxy::isMainThread()); |
| 1145 DebugScopedSetImplThread impl; |
| 1146 onMemoryAllocationChangedOnImplThread(allocation); |
| 1147 } else { |
| 1148 DCHECK(Proxy::isImplThread()); |
| 1149 onMemoryAllocationChangedOnImplThread(allocation); |
| 1150 } |
| 1151 } |
| 1152 |
| 1153 int GLRenderer::priorityCutoffValue(WebKit::WebGraphicsMemoryAllocation::Priorit
yCutoff priorityCutoff) |
| 1154 { |
| 1155 switch (priorityCutoff) { |
| 1156 case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowNothing: |
| 1157 return PriorityCalculator::allowNothingCutoff(); |
| 1158 case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleOnly: |
| 1159 return PriorityCalculator::allowVisibleOnlyCutoff(); |
| 1160 case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleAndNearb
y: |
| 1161 return PriorityCalculator::allowVisibleAndNearbyCutoff(); |
| 1162 case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowEverything: |
| 1163 return PriorityCalculator::allowEverythingCutoff(); |
| 1164 } |
| 1165 NOTREACHED(); |
| 1166 return 0; |
| 1167 } |
| 1168 |
| 1169 void GLRenderer::onMemoryAllocationChangedOnImplThread(WebKit::WebGraphicsMemory
Allocation allocation) |
| 1170 { |
| 1138 // Just ignore the memory manager when it says to set the limit to zero | 1171 // Just ignore the memory manager when it says to set the limit to zero |
| 1139 // bytes. This will happen when the memory manager thinks that the renderer | 1172 // bytes. This will happen when the memory manager thinks that the renderer |
| 1140 // is not visible (which the renderer knows better). | 1173 // is not visible (which the renderer knows better). |
| 1141 if (allocation.bytesLimitWhenVisible) { | 1174 if (allocation.bytesLimitWhenVisible) { |
| 1142 ManagedMemoryPolicy policy( | 1175 ManagedMemoryPolicy policy( |
| 1143 allocation.bytesLimitWhenVisible, | 1176 allocation.bytesLimitWhenVisible, |
| 1144 priorityCutoffValue(allocation.priorityCutoffWhenVisible), | 1177 priorityCutoffValue(allocation.priorityCutoffWhenVisible), |
| 1145 allocation.bytesLimitWhenNotVisible, | 1178 allocation.bytesLimitWhenNotVisible, |
| 1146 priorityCutoffValue(allocation.priorityCutoffWhenNotVisible)); | 1179 priorityCutoffValue(allocation.priorityCutoffWhenNotVisible)); |
| 1147 | 1180 |
| 1148 if (allocation.enforceButDoNotKeepAsPolicy) | 1181 if (allocation.enforceButDoNotKeepAsPolicy) |
| 1149 m_client->enforceManagedMemoryPolicy(policy); | 1182 m_client->enforceManagedMemoryPolicy(policy); |
| 1150 else | 1183 else |
| 1151 m_client->setManagedMemoryPolicy(policy); | 1184 m_client->setManagedMemoryPolicy(policy); |
| 1152 } | 1185 } |
| 1153 | 1186 |
| 1154 bool oldDiscardFramebufferWhenNotVisible = m_discardFramebufferWhenNotVisibl
e; | 1187 bool oldDiscardFramebufferWhenNotVisible = m_discardFramebufferWhenNotVisibl
e; |
| 1155 m_discardFramebufferWhenNotVisible = !allocation.suggestHaveBackbuffer; | 1188 m_discardFramebufferWhenNotVisible = !allocation.suggestHaveBackbuffer; |
| 1156 enforceMemoryPolicy(); | 1189 enforceMemoryPolicy(); |
| 1157 if (allocation.enforceButDoNotKeepAsPolicy) | 1190 if (allocation.enforceButDoNotKeepAsPolicy) |
| 1158 m_discardFramebufferWhenNotVisible = oldDiscardFramebufferWhenNotVisible
; | 1191 m_discardFramebufferWhenNotVisible = oldDiscardFramebufferWhenNotVisible
; |
| 1159 } | 1192 } |
| 1160 | 1193 |
| 1161 int GLRenderer::priorityCutoffValue(WebKit::WebGraphicsMemoryAllocation::Priorit
yCutoff priorityCutoff) | |
| 1162 { | |
| 1163 switch (priorityCutoff) { | |
| 1164 case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowNothing: | |
| 1165 return PriorityCalculator::allowNothingCutoff(); | |
| 1166 case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleOnly: | |
| 1167 return PriorityCalculator::allowVisibleOnlyCutoff(); | |
| 1168 case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleAndNearb
y: | |
| 1169 return PriorityCalculator::allowVisibleAndNearbyCutoff(); | |
| 1170 case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowEverything: | |
| 1171 return PriorityCalculator::allowEverythingCutoff(); | |
| 1172 } | |
| 1173 NOTREACHED(); | |
| 1174 return 0; | |
| 1175 } | |
| 1176 | |
| 1177 void GLRenderer::enforceMemoryPolicy() | 1194 void GLRenderer::enforceMemoryPolicy() |
| 1178 { | 1195 { |
| 1179 if (!m_visible) { | 1196 if (!m_visible) { |
| 1180 TRACE_EVENT0("cc", "GLRenderer::enforceMemoryPolicy dropping resources")
; | 1197 TRACE_EVENT0("cc", "GLRenderer::enforceMemoryPolicy dropping resources")
; |
| 1181 releaseRenderPassTextures(); | 1198 releaseRenderPassTextures(); |
| 1182 if (m_discardFramebufferWhenNotVisible) | 1199 if (m_discardFramebufferWhenNotVisible) |
| 1183 discardFramebuffer(); | 1200 discardFramebuffer(); |
| 1184 GLC(m_context, m_context->flush()); | 1201 GLC(m_context, m_context->flush()); |
| 1185 } | 1202 } |
| 1186 } | 1203 } |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1608 | 1625 |
| 1609 releaseRenderPassTextures(); | 1626 releaseRenderPassTextures(); |
| 1610 } | 1627 } |
| 1611 | 1628 |
| 1612 bool GLRenderer::isContextLost() | 1629 bool GLRenderer::isContextLost() |
| 1613 { | 1630 { |
| 1614 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); | 1631 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); |
| 1615 } | 1632 } |
| 1616 | 1633 |
| 1617 } // namespace cc | 1634 } // namespace cc |
| OLD | NEW |