Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(579)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp

Issue 2101823002: Revert of Make 2D canvas disable gpu acceleration when getImageData is called (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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, &copyPaint); // 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
489 SkSurface* Canvas2DLayerBridge::getOrCreateSurface(AccelerationHint hint) 467 SkSurface* Canvas2DLayerBridge::getOrCreateSurface(AccelerationHint hint)
490 { 468 {
491 if (m_surface) { 469 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();
497 return m_surface.get(); 470 return m_surface.get();
498 }
499 471
500 if (m_layer && !isHibernating() && hint == PreferAcceleration) { 472 if (m_layer && !isHibernating() && hint == PreferAcceleration) {
501 return nullptr; // re-creation will happen through restore() 473 return nullptr; // re-creation will happen through restore()
502 } 474 }
503 475
504 bool wantAcceleration = shouldAccelerate(hint); 476 bool wantAcceleration = shouldAccelerate(hint);
477 bool surfaceIsAccelerated;
505 if (CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU && isHidden() && wantAccelerati on) { 478 if (CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU && isHidden() && wantAccelerati on) {
506 wantAcceleration = false; 479 wantAcceleration = false;
507 m_softwareRenderingWhileHidden = true; 480 m_softwareRenderingWhileHidden = true;
508 } 481 }
509 482
510 bool surfaceIsAccelerated;
511 m_surface = createSkSurface(wantAcceleration ? m_contextProvider->grContext( ) : nullptr, m_size, m_msaaSampleCount, m_opacityMode, &surfaceIsAccelerated); 483 m_surface = createSkSurface(wantAcceleration ? m_contextProvider->grContext( ) : nullptr, m_size, m_msaaSampleCount, m_opacityMode, &surfaceIsAccelerated);
512 484
513 if (!m_surface) 485 if (!m_surface)
514 reportSurfaceCreationFailure(); 486 reportSurfaceCreationFailure();
515 487
516 if (m_surface && surfaceIsAccelerated && !m_layer) { 488 if (m_surface && surfaceIsAccelerated && !m_layer) {
517 m_layer = wrapUnique(Platform::current()->compositorSupport()->createExt ernalTextureLayer(this)); 489 m_layer = wrapUnique(Platform::current()->compositorSupport()->createExt ernalTextureLayer(this));
518 m_layer->setOpaque(m_opacityMode == Opaque); 490 m_layer->setOpaque(m_opacityMode == Opaque);
519 m_layer->setBlendBackgroundColor(m_opacityMode != Opaque); 491 m_layer->setBlendBackgroundColor(m_opacityMode != Opaque);
520 GraphicsLayer::registerContentsLayer(m_layer->layer()); 492 GraphicsLayer::registerContentsLayer(m_layer->layer());
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 #endif // USE_IOSURFACE_FOR_2D_CANVAS 996 #endif // USE_IOSURFACE_FOR_2D_CANVAS
1025 } 997 }
1026 998
1027 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) 999 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event)
1028 { 1000 {
1029 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib ernationEvents", HibernationEventCount)); 1001 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib ernationEvents", HibernationEventCount));
1030 hibernationHistogram.count(event); 1002 hibernationHistogram.count(event);
1031 } 1003 }
1032 1004
1033 } // namespace blink 1005 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698