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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp

Issue 2192493003: Enable GPU acceleration in 2D OffscreenCanvases on main thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix layout test failures Created 4 years, 4 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) 2004, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 } 759 }
760 760
761 bool HTMLCanvasElement::shouldAccelerate(const IntSize& size) const 761 bool HTMLCanvasElement::shouldAccelerate(const IntSize& size) const
762 { 762 {
763 if (m_context && !m_context->is2d()) 763 if (m_context && !m_context->is2d())
764 return false; 764 return false;
765 765
766 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) 766 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled())
767 return false; 767 return false;
768 768
769 Settings* settings = document().settings(); 769 if (!RuntimeEnabledFeatures::accelerated2dCanvasEnabled())
770 if (!settings || !settings->accelerated2dCanvasEnabled())
771 return false; 770 return false;
772 771
773 int canvasPixelCount = size.width() * size.height(); 772 int canvasPixelCount = size.width() * size.height();
774 773
775 if (RuntimeEnabledFeatures::displayList2dCanvasEnabled()) { 774 if (RuntimeEnabledFeatures::displayList2dCanvasEnabled()) {
776 #if 0 775 #if 0
777 // TODO(junov): re-enable this code once we solve the problem of recordi ng 776 // TODO(junov): re-enable this code once we solve the problem of recordi ng
778 // GPU-backed images to an SkPicture for cross-context rendering crbug.c om/490328 777 // GPU-backed images to an SkPicture for cross-context rendering crbug.c om/490328
779 778
780 // If the compositor provides GPU acceleration to display list canvases, we 779 // If the compositor provides GPU acceleration to display list canvases, we
781 // prefer that over direct acceleration. 780 // prefer that over direct acceleration.
782 if (document().viewportDescription().matchesHeuristicsForGpuRasterizatio n()) 781 if (document().viewportDescription().matchesHeuristicsForGpuRasterizatio n())
783 return false; 782 return false;
784 #endif 783 #endif
785 // If the GPU resources would be very expensive, prefer a display list. 784 // If the GPU resources would be very expensive, prefer a display list.
786 if (canvasPixelCount > ExpensiveCanvasHeuristicParameters::PreferDisplay ListOverGpuSizeThreshold) 785 if (canvasPixelCount > ExpensiveCanvasHeuristicParameters::PreferDisplay ListOverGpuSizeThreshold)
787 return false; 786 return false;
788 } 787 }
789 788
790 // Do not use acceleration for small canvas. 789 // Do not use acceleration for small canvas.
791 if (canvasPixelCount < settings->minimumAccelerated2dCanvasSize()) 790 Settings* settings = document().settings();
791 if (!settings || canvasPixelCount < settings->minimumAccelerated2dCanvasSize ())
792 return false; 792 return false;
793 793
794 if (!Platform::current()->canAccelerate2dCanvas()) 794 if (!Platform::current()->canAccelerate2dCanvas())
795 return false; 795 return false;
796 796
797 // When GPU allocated memory runs low (due to having created too many 797 // When GPU allocated memory runs low (due to having created too many
798 // accelerated canvases), the compositor starves and browser becomes laggy. 798 // accelerated canvases), the compositor starves and browser becomes laggy.
799 // Thus, we should stop allocating more GPU memory to new canvases created 799 // Thus, we should stop allocating more GPU memory to new canvases created
800 // when the current memory usage exceeds the threshold. 800 // when the current memory usage exceeds the threshold.
801 if (ImageBuffer::getGlobalGPUMemoryUsage() >= MaxGlobalGPUMemoryUsage) 801 if (ImageBuffer::getGlobalGPUMemoryUsage() >= MaxGlobalGPUMemoryUsage)
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
1228 1228
1229 bool HTMLCanvasElement::createSurfaceLayer() 1229 bool HTMLCanvasElement::createSurfaceLayer()
1230 { 1230 {
1231 DCHECK(!m_surfaceLayerBridge); 1231 DCHECK(!m_surfaceLayerBridge);
1232 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne w CanvasSurfaceLayerBridgeClientImpl()); 1232 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne w CanvasSurfaceLayerBridgeClientImpl());
1233 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri dgeClient))); 1233 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri dgeClient)));
1234 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height( )); 1234 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height( ));
1235 } 1235 }
1236 1236
1237 } // namespace blink 1237 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698