OLD | NEW |
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 Loading... |
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()) | 770 return false; |
| 771 |
| 772 // The following is necessary for handling the special case of canvases in t
he |
| 773 // dev tools overlay, which run in a process that supports accelerated 2d ca
nvas |
| 774 // but in a special compositing context that does not. |
| 775 if (layoutBox() && !layoutBox()->hasAcceleratedCompositing()) |
771 return false; | 776 return false; |
772 | 777 |
773 int canvasPixelCount = size.width() * size.height(); | 778 int canvasPixelCount = size.width() * size.height(); |
774 | 779 |
775 if (RuntimeEnabledFeatures::displayList2dCanvasEnabled()) { | 780 if (RuntimeEnabledFeatures::displayList2dCanvasEnabled()) { |
776 #if 0 | 781 #if 0 |
777 // TODO(junov): re-enable this code once we solve the problem of recordi
ng | 782 // 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 | 783 // GPU-backed images to an SkPicture for cross-context rendering crbug.c
om/490328 |
779 | 784 |
780 // If the compositor provides GPU acceleration to display list canvases,
we | 785 // If the compositor provides GPU acceleration to display list canvases,
we |
781 // prefer that over direct acceleration. | 786 // prefer that over direct acceleration. |
782 if (document().viewportDescription().matchesHeuristicsForGpuRasterizatio
n()) | 787 if (document().viewportDescription().matchesHeuristicsForGpuRasterizatio
n()) |
783 return false; | 788 return false; |
784 #endif | 789 #endif |
785 // If the GPU resources would be very expensive, prefer a display list. | 790 // If the GPU resources would be very expensive, prefer a display list. |
786 if (canvasPixelCount > ExpensiveCanvasHeuristicParameters::PreferDisplay
ListOverGpuSizeThreshold) | 791 if (canvasPixelCount > ExpensiveCanvasHeuristicParameters::PreferDisplay
ListOverGpuSizeThreshold) |
787 return false; | 792 return false; |
788 } | 793 } |
789 | 794 |
790 // Do not use acceleration for small canvas. | 795 // Do not use acceleration for small canvas. |
791 if (canvasPixelCount < settings->minimumAccelerated2dCanvasSize()) | 796 Settings* settings = document().settings(); |
| 797 if (!settings || canvasPixelCount < settings->minimumAccelerated2dCanvasSize
()) |
792 return false; | 798 return false; |
793 | 799 |
794 if (!Platform::current()->canAccelerate2dCanvas()) | 800 if (!Platform::current()->canAccelerate2dCanvas()) |
795 return false; | 801 return false; |
796 | 802 |
797 // When GPU allocated memory runs low (due to having created too many | 803 // When GPU allocated memory runs low (due to having created too many |
798 // accelerated canvases), the compositor starves and browser becomes laggy. | 804 // accelerated canvases), the compositor starves and browser becomes laggy. |
799 // Thus, we should stop allocating more GPU memory to new canvases created | 805 // Thus, we should stop allocating more GPU memory to new canvases created |
800 // when the current memory usage exceeds the threshold. | 806 // when the current memory usage exceeds the threshold. |
801 if (ImageBuffer::getGlobalGPUMemoryUsage() >= MaxGlobalGPUMemoryUsage) | 807 if (ImageBuffer::getGlobalGPUMemoryUsage() >= MaxGlobalGPUMemoryUsage) |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 | 1234 |
1229 bool HTMLCanvasElement::createSurfaceLayer() | 1235 bool HTMLCanvasElement::createSurfaceLayer() |
1230 { | 1236 { |
1231 DCHECK(!m_surfaceLayerBridge); | 1237 DCHECK(!m_surfaceLayerBridge); |
1232 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne
w CanvasSurfaceLayerBridgeClientImpl()); | 1238 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne
w CanvasSurfaceLayerBridgeClientImpl()); |
1233 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri
dgeClient))); | 1239 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri
dgeClient))); |
1234 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height(
)); | 1240 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height(
)); |
1235 } | 1241 } |
1236 | 1242 |
1237 } // namespace blink | 1243 } // namespace blink |
OLD | NEW |