| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 { | 457 { |
| 458 if (!m_surfaceCreationFailedAtLeastOnce) { | 458 if (!m_surfaceCreationFailedAtLeastOnce) { |
| 459 // Only count the failure once per instance so that the histogram may | 459 // Only count the failure once per instance so that the histogram may |
| 460 // reflect the proportion of Canvas2DLayerBridge instances with surface | 460 // reflect the proportion of Canvas2DLayerBridge instances with surface |
| 461 // allocation failures. | 461 // allocation failures. |
| 462 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated2DCa
nvasSurfaceCreationFailed); | 462 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated2DCa
nvasSurfaceCreationFailed); |
| 463 m_surfaceCreationFailedAtLeastOnce = true; | 463 m_surfaceCreationFailedAtLeastOnce = true; |
| 464 } | 464 } |
| 465 } | 465 } |
| 466 | 466 |
| 467 void Canvas2DLayerBridge::disableAcceleration() |
| 468 { |
| 469 DCHECK(m_layer); |
| 470 bool surfaceIsAccelerated; |
| 471 RefPtr<SkSurface> newSurface = createSkSurface(nullptr, m_size, m_msaaSample
Count, m_opacityMode, &surfaceIsAccelerated); |
| 472 if (newSurface) { |
| 473 DCHECK(!surfaceIsAccelerated); |
| 474 flush(); |
| 475 SkPaint copyPaint; |
| 476 copyPaint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 477 m_surface->draw(newSurface->getCanvas(), 0, 0, ©Paint); // GPU readb
ack here |
| 478 m_accelerationMode = DisableAcceleration; // Acceleration gets permanent
ly disabled |
| 479 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); |
| 480 m_layer->clearTexture(); |
| 481 m_layer->layer()->removeFromParent(); |
| 482 m_layer.reset(); |
| 483 m_surface = newSurface; |
| 484 if (m_imageBuffer) |
| 485 m_imageBuffer->didDisableAcceleration(); |
| 486 } |
| 487 } |
| 488 |
| 467 SkSurface* Canvas2DLayerBridge::getOrCreateSurface(AccelerationHint hint) | 489 SkSurface* Canvas2DLayerBridge::getOrCreateSurface(AccelerationHint hint) |
| 468 { | 490 { |
| 469 if (m_surface) | 491 if (m_surface) { |
| 492 // Note: in layout tests, canvas2dFixedRenderingMode is set to true to i
nhibit |
| 493 // mode switching so that we continue to get test coverage for GPU accel
eration |
| 494 // despite the use of getImageData in tests |
| 495 if (hint == ForceNoAcceleration && m_layer && !RuntimeEnabledFeatures::c
anvas2dFixedRenderingModeEnabled()) |
| 496 disableAcceleration(); |
| 470 return m_surface.get(); | 497 return m_surface.get(); |
| 498 } |
| 471 | 499 |
| 472 if (m_layer && !isHibernating() && hint == PreferAcceleration) { | 500 if (m_layer && !isHibernating() && hint == PreferAcceleration) { |
| 473 return nullptr; // re-creation will happen through restore() | 501 return nullptr; // re-creation will happen through restore() |
| 474 } | 502 } |
| 475 | 503 |
| 476 bool wantAcceleration = shouldAccelerate(hint); | 504 bool wantAcceleration = shouldAccelerate(hint); |
| 477 bool surfaceIsAccelerated; | |
| 478 if (CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU && isHidden() && wantAccelerati
on) { | 505 if (CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU && isHidden() && wantAccelerati
on) { |
| 479 wantAcceleration = false; | 506 wantAcceleration = false; |
| 480 m_softwareRenderingWhileHidden = true; | 507 m_softwareRenderingWhileHidden = true; |
| 481 } | 508 } |
| 482 | 509 |
| 510 bool surfaceIsAccelerated; |
| 483 m_surface = createSkSurface(wantAcceleration ? m_contextProvider->grContext(
) : nullptr, m_size, m_msaaSampleCount, m_opacityMode, &surfaceIsAccelerated); | 511 m_surface = createSkSurface(wantAcceleration ? m_contextProvider->grContext(
) : nullptr, m_size, m_msaaSampleCount, m_opacityMode, &surfaceIsAccelerated); |
| 484 | 512 |
| 485 if (!m_surface) | 513 if (!m_surface) |
| 486 reportSurfaceCreationFailure(); | 514 reportSurfaceCreationFailure(); |
| 487 | 515 |
| 488 if (m_surface && surfaceIsAccelerated && !m_layer) { | 516 if (m_surface && surfaceIsAccelerated && !m_layer) { |
| 489 m_layer = wrapUnique(Platform::current()->compositorSupport()->createExt
ernalTextureLayer(this)); | 517 m_layer = wrapUnique(Platform::current()->compositorSupport()->createExt
ernalTextureLayer(this)); |
| 490 m_layer->setOpaque(m_opacityMode == Opaque); | 518 m_layer->setOpaque(m_opacityMode == Opaque); |
| 491 m_layer->setBlendBackgroundColor(m_opacityMode != Opaque); | 519 m_layer->setBlendBackgroundColor(m_opacityMode != Opaque); |
| 492 GraphicsLayer::registerContentsLayer(m_layer->layer()); | 520 GraphicsLayer::registerContentsLayer(m_layer->layer()); |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 #endif // USE_IOSURFACE_FOR_2D_CANVAS | 1024 #endif // USE_IOSURFACE_FOR_2D_CANVAS |
| 997 } | 1025 } |
| 998 | 1026 |
| 999 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) | 1027 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) |
| 1000 { | 1028 { |
| 1001 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib
ernationEvents", HibernationEventCount)); | 1029 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib
ernationEvents", HibernationEventCount)); |
| 1002 hibernationHistogram.count(event); | 1030 hibernationHistogram.count(event); |
| 1003 } | 1031 } |
| 1004 | 1032 |
| 1005 } // namespace blink | 1033 } // namespace blink |
| OLD | NEW |