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

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

Issue 2267993002: Expose if we are using swiftshader via WebGraphicsContext3DProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: softwarerendering: . 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 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 return document().getSecurityOrigin(); 753 return document().getSecurityOrigin();
754 } 754 }
755 755
756 bool HTMLCanvasElement::originClean() const 756 bool HTMLCanvasElement::originClean() const
757 { 757 {
758 if (document().settings() && document().settings()->disableReadingFromCanvas ()) 758 if (document().settings() && document().settings()->disableReadingFromCanvas ())
759 return false; 759 return false;
760 return m_originClean; 760 return m_originClean;
761 } 761 }
762 762
763 bool HTMLCanvasElement::shouldAccelerate(const IntSize& size) const 763 bool HTMLCanvasElement::shouldAccelerate(const IntSize& size, const WebGraphicsC ontext3DProvider* sharedMainThreadContextProvider) const
764 { 764 {
765 if (m_context && !m_context->is2d()) 765 if (m_context && !m_context->is2d())
766 return false; 766 return false;
767 767
768 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) 768 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled())
769 return false; 769 return false;
770 770
771 if (!RuntimeEnabledFeatures::accelerated2dCanvasEnabled()) 771 if (!RuntimeEnabledFeatures::accelerated2dCanvasEnabled())
772 return false; 772 return false;
773 773
774 // The following is necessary for handling the special case of canvases in t he 774 // The following is necessary for handling the special case of canvases in t he
775 // dev tools overlay, which run in a process that supports accelerated 2d ca nvas 775 // dev tools overlay, which run in a process that supports accelerated 2d ca nvas
776 // but in a special compositing context that does not. 776 // but in a special compositing context that does not.
777 if (layoutBox() && !layoutBox()->hasAcceleratedCompositing()) 777 if (layoutBox() && !layoutBox()->hasAcceleratedCompositing())
778 return false; 778 return false;
779 779
780 int canvasPixelCount = size.width() * size.height(); 780 CheckedNumeric<int> checkedCanvasPixelCount = size.width();
781 checkedCanvasPixelCount *= size.height();
782 if (!checkedCanvasPixelCount.IsValid())
783 return false;
784 int canvasPixelCount = checkedCanvasPixelCount.ValueOrDie();
781 785
782 if (RuntimeEnabledFeatures::displayList2dCanvasEnabled()) { 786 if (RuntimeEnabledFeatures::displayList2dCanvasEnabled()) {
783 #if 0 787 #if 0
784 // TODO(junov): re-enable this code once we solve the problem of recordi ng 788 // TODO(junov): re-enable this code once we solve the problem of recordi ng
785 // GPU-backed images to an SkPicture for cross-context rendering crbug.c om/490328 789 // GPU-backed images to an SkPicture for cross-context rendering crbug.c om/490328
786 790
787 // If the compositor provides GPU acceleration to display list canvases, we 791 // If the compositor provides GPU acceleration to display list canvases, we
788 // prefer that over direct acceleration. 792 // prefer that over direct acceleration.
789 if (document().viewportDescription().matchesHeuristicsForGpuRasterizatio n()) 793 if (document().viewportDescription().matchesHeuristicsForGpuRasterizatio n())
790 return false; 794 return false;
791 #endif 795 #endif
792 // If the GPU resources would be very expensive, prefer a display list. 796 // If the GPU resources would be very expensive, prefer a display list.
793 if (canvasPixelCount > ExpensiveCanvasHeuristicParameters::PreferDisplay ListOverGpuSizeThreshold) 797 if (canvasPixelCount > ExpensiveCanvasHeuristicParameters::PreferDisplay ListOverGpuSizeThreshold)
794 return false; 798 return false;
795 } 799 }
796 800
797 // Do not use acceleration for small canvas. 801 // Do not use acceleration for small canvas.
798 Settings* settings = document().settings(); 802 Settings* settings = document().settings();
799 if (!settings || canvasPixelCount < settings->minimumAccelerated2dCanvasSize ()) 803 if (!settings || canvasPixelCount < settings->minimumAccelerated2dCanvasSize ())
800 return false; 804 return false;
801 805
802 if (!Platform::current()->canAccelerate2dCanvas()) 806 if (sharedMainThreadContextProvider->isSoftwareRendering())
803 return false; 807 return false;
804 808
805 // When GPU allocated memory runs low (due to having created too many 809 // When GPU allocated memory runs low (due to having created too many
806 // accelerated canvases), the compositor starves and browser becomes laggy. 810 // accelerated canvases), the compositor starves and browser becomes laggy.
807 // Thus, we should stop allocating more GPU memory to new canvases created 811 // Thus, we should stop allocating more GPU memory to new canvases created
808 // when the current memory usage exceeds the threshold. 812 // when the current memory usage exceeds the threshold.
809 if (ImageBuffer::getGlobalGPUMemoryUsage() >= MaxGlobalGPUMemoryUsage) 813 if (ImageBuffer::getGlobalGPUMemoryUsage() >= MaxGlobalGPUMemoryUsage)
810 return false; 814 return false;
811 815
812 // Allocating too many GPU resources can makes us run into the driver's 816 // Allocating too many GPU resources can makes us run into the driver's
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque : Opaque; 848 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque : Opaque;
845 849
846 *msaaSampleCount = 0; 850 *msaaSampleCount = 0;
847 if (is3D()) { 851 if (is3D()) {
848 // If 3d, but the use of the canvas will be for non-accelerated content 852 // If 3d, but the use of the canvas will be for non-accelerated content
849 // then make a non-accelerated ImageBuffer. This means copying the inter nal 853 // then make a non-accelerated ImageBuffer. This means copying the inter nal
850 // Image will require a pixel readback, but that is unavoidable in this case. 854 // Image will require a pixel readback, but that is unavoidable in this case.
851 return wrapUnique(new AcceleratedImageBufferSurface(deviceSize, opacityM ode)); 855 return wrapUnique(new AcceleratedImageBufferSurface(deviceSize, opacityM ode));
852 } 856 }
853 857
854 if (shouldAccelerate(deviceSize)) { 858 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider = wrapUnique(P latform::current()->createSharedOffscreenGraphicsContext3DProvider());
859 if (!contextProvider) {
860 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Accelerated2DCanva sGPUContextLost);
861 } else if (shouldAccelerate(deviceSize, contextProvider.get())) {
855 if (document().settings()) 862 if (document().settings())
856 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASam pleCount(); 863 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASam pleCount();
857 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new Canvas2DIma geBufferSurface(deviceSize, *msaaSampleCount, opacityMode, Canvas2DLayerBridge:: EnableAcceleration)); 864 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new Canvas2DIma geBufferSurface(std::move(contextProvider), deviceSize, *msaaSampleCount, opacit yMode, Canvas2DLayerBridge::EnableAcceleration));
858 if (surface->isValid()) { 865 if (surface->isValid()) {
859 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated 2DCanvasImageBufferCreated); 866 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated 2DCanvasImageBufferCreated);
860 return surface; 867 return surface;
861 } 868 }
862 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated2DCa nvasImageBufferCreationFailed); 869 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated2DCa nvasImageBufferCreationFailed);
863 } 870 }
864 871
865 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = wrapUnique(new UnacceleratedSurfaceFactory()); 872 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = wrapUnique(new UnacceleratedSurfaceFactory());
866 873
867 if (shouldUseDisplayList(deviceSize)) { 874 if (shouldUseDisplayList(deviceSize)) {
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 1243
1237 bool HTMLCanvasElement::createSurfaceLayer() 1244 bool HTMLCanvasElement::createSurfaceLayer()
1238 { 1245 {
1239 DCHECK(!m_surfaceLayerBridge); 1246 DCHECK(!m_surfaceLayerBridge);
1240 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne w CanvasSurfaceLayerBridgeClientImpl()); 1247 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne w CanvasSurfaceLayerBridgeClientImpl());
1241 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri dgeClient))); 1248 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri dgeClient)));
1242 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height( )); 1249 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height( ));
1243 } 1250 }
1244 1251
1245 } // namespace blink 1252 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698