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

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

Issue 2171513003: Re-enable canvas optimization for getImageData with new codepath (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix tests 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 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 { 454 {
455 if (!m_surfaceCreationFailedAtLeastOnce) { 455 if (!m_surfaceCreationFailedAtLeastOnce) {
456 // Only count the failure once per instance so that the histogram may 456 // Only count the failure once per instance so that the histogram may
457 // reflect the proportion of Canvas2DLayerBridge instances with surface 457 // reflect the proportion of Canvas2DLayerBridge instances with surface
458 // allocation failures. 458 // allocation failures.
459 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated2DCa nvasSurfaceCreationFailed); 459 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated2DCa nvasSurfaceCreationFailed);
460 m_surfaceCreationFailedAtLeastOnce = true; 460 m_surfaceCreationFailedAtLeastOnce = true;
461 } 461 }
462 } 462 }
463 463
464 void Canvas2DLayerBridge::disableAcceleration()
465 {
466 DCHECK(isAccelerated());
467 bool surfaceIsAccelerated;
468 RefPtr<SkSurface> newSurface = createSkSurface(nullptr, m_size, m_msaaSample Count, m_opacityMode, &surfaceIsAccelerated);
469 if (newSurface) {
470 DCHECK(!surfaceIsAccelerated);
471 flush();
472 SkPaint copyPaint;
473 copyPaint.setXfermodeMode(SkXfermode::kSrc_Mode);
474 m_surface->draw(newSurface->getCanvas(), 0, 0, &copyPaint); // GPU readb ack here
475 m_accelerationMode = DisableAcceleration; // Acceleration gets permanent ly disabled
476 GraphicsLayer::unregisterContentsLayer(m_layer->layer());
477 m_layer->clearTexture();
478 m_layer->layer()->removeFromParent();
479 m_surface = newSurface;
480 if (m_imageBuffer)
481 m_imageBuffer->didDisableAcceleration();
482 }
483 }
484
485 SkSurface* Canvas2DLayerBridge::getOrCreateSurface(AccelerationHint hint) 464 SkSurface* Canvas2DLayerBridge::getOrCreateSurface(AccelerationHint hint)
486 { 465 {
487 if (m_surface) { 466 if (m_surface)
488 // Note: in layout tests, canvas2dFixedRenderingMode is set to true to i nhibit
489 // mode switching so that we continue to get test coverage for GPU accel eration
490 // despite the use of getImageData in tests
491 if (hint == ForceNoAcceleration && isAccelerated() && !RuntimeEnabledFea tures::canvas2dFixedRenderingModeEnabled())
492 disableAcceleration();
493 return m_surface.get(); 467 return m_surface.get();
494 }
495 468
496 if (m_layer && !isHibernating() && hint == PreferAcceleration && m_accelerat ionMode != DisableAcceleration) { 469 if (m_layer && !isHibernating() && hint == PreferAcceleration && m_accelerat ionMode != DisableAcceleration) {
497 return nullptr; // re-creation will happen through restore() 470 return nullptr; // re-creation will happen through restore()
498 } 471 }
499 472
500 bool wantAcceleration = shouldAccelerate(hint); 473 bool wantAcceleration = shouldAccelerate(hint);
501 if (CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU && isHidden() && wantAccelerati on) { 474 if (CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU && isHidden() && wantAccelerati on) {
502 wantAcceleration = false; 475 wantAcceleration = false;
503 m_softwareRenderingWhileHidden = true; 476 m_softwareRenderingWhileHidden = true;
504 } 477 }
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 #endif // USE_IOSURFACE_FOR_2D_CANVAS 992 #endif // USE_IOSURFACE_FOR_2D_CANVAS
1020 } 993 }
1021 994
1022 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) 995 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event)
1023 { 996 {
1024 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib ernationEvents", HibernationEventCount)); 997 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib ernationEvents", HibernationEventCount));
1025 hibernationHistogram.count(event); 998 hibernationHistogram.count(event);
1026 } 999 }
1027 1000
1028 } // namespace blink 1001 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698