| 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 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 void HTMLCanvasElement::removeListener(CanvasDrawListener* listener) { | 775 void HTMLCanvasElement::removeListener(CanvasDrawListener* listener) { |
| 776 m_listeners.remove(listener); | 776 m_listeners.remove(listener); |
| 777 } | 777 } |
| 778 | 778 |
| 779 SecurityOrigin* HTMLCanvasElement::getSecurityOrigin() const { | 779 SecurityOrigin* HTMLCanvasElement::getSecurityOrigin() const { |
| 780 return document().getSecurityOrigin(); | 780 return document().getSecurityOrigin(); |
| 781 } | 781 } |
| 782 | 782 |
| 783 bool HTMLCanvasElement::originClean() const { | 783 bool HTMLCanvasElement::originClean() const { |
| 784 if (document().settings() && | 784 if (document().settings() && |
| 785 document().settings()->disableReadingFromCanvas()) | 785 document().settings()->GetDisableReadingFromCanvas()) |
| 786 return false; | 786 return false; |
| 787 if (placeholderFrame()) | 787 if (placeholderFrame()) |
| 788 return placeholderFrame()->originClean(); | 788 return placeholderFrame()->originClean(); |
| 789 return m_originClean; | 789 return m_originClean; |
| 790 } | 790 } |
| 791 | 791 |
| 792 bool HTMLCanvasElement::shouldAccelerate(const IntSize& size) const { | 792 bool HTMLCanvasElement::shouldAccelerate(const IntSize& size) const { |
| 793 if (m_context && !m_context->is2d()) | 793 if (m_context && !m_context->is2d()) |
| 794 return false; | 794 return false; |
| 795 | 795 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 823 #endif | 823 #endif |
| 824 // If the GPU resources would be very expensive, prefer a display list. | 824 // If the GPU resources would be very expensive, prefer a display list. |
| 825 if (canvasPixelCount > ExpensiveCanvasHeuristicParameters:: | 825 if (canvasPixelCount > ExpensiveCanvasHeuristicParameters:: |
| 826 PreferDisplayListOverGpuSizeThreshold) | 826 PreferDisplayListOverGpuSizeThreshold) |
| 827 return false; | 827 return false; |
| 828 } | 828 } |
| 829 | 829 |
| 830 // Do not use acceleration for small canvas. | 830 // Do not use acceleration for small canvas. |
| 831 Settings* settings = document().settings(); | 831 Settings* settings = document().settings(); |
| 832 if (!settings || | 832 if (!settings || |
| 833 canvasPixelCount < settings->minimumAccelerated2dCanvasSize()) | 833 canvasPixelCount < settings->GetMinimumAccelerated2dCanvasSize()) |
| 834 return false; | 834 return false; |
| 835 | 835 |
| 836 // When GPU allocated memory runs low (due to having created too many | 836 // When GPU allocated memory runs low (due to having created too many |
| 837 // accelerated canvases), the compositor starves and browser becomes laggy. | 837 // accelerated canvases), the compositor starves and browser becomes laggy. |
| 838 // Thus, we should stop allocating more GPU memory to new canvases created | 838 // Thus, we should stop allocating more GPU memory to new canvases created |
| 839 // when the current memory usage exceeds the threshold. | 839 // when the current memory usage exceeds the threshold. |
| 840 if (ImageBuffer::getGlobalGPUMemoryUsage() >= MaxGlobalGPUMemoryUsage) | 840 if (ImageBuffer::getGlobalGPUMemoryUsage() >= MaxGlobalGPUMemoryUsage) |
| 841 return false; | 841 return false; |
| 842 | 842 |
| 843 // Allocating too many GPU resources can makes us run into the driver's | 843 // Allocating too many GPU resources can makes us run into the driver's |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 } | 898 } |
| 899 | 899 |
| 900 std::unique_ptr<ImageBufferSurface> | 900 std::unique_ptr<ImageBufferSurface> |
| 901 HTMLCanvasElement::createAcceleratedImageBufferSurface( | 901 HTMLCanvasElement::createAcceleratedImageBufferSurface( |
| 902 const IntSize& deviceSize, | 902 const IntSize& deviceSize, |
| 903 OpacityMode opacityMode, | 903 OpacityMode opacityMode, |
| 904 int* msaaSampleCount) { | 904 int* msaaSampleCount) { |
| 905 if (!shouldAccelerate(deviceSize)) | 905 if (!shouldAccelerate(deviceSize)) |
| 906 return nullptr; | 906 return nullptr; |
| 907 | 907 |
| 908 if (document().settings()) | 908 if (document().settings()) { |
| 909 *msaaSampleCount = | 909 *msaaSampleCount = |
| 910 document().settings()->accelerated2dCanvasMSAASampleCount(); | 910 document().settings()->GetAccelerated2dCanvasMSAASampleCount(); |
| 911 } |
| 911 | 912 |
| 912 // Avoid creating |contextProvider| until we're sure we want to try use it, | 913 // Avoid creating |contextProvider| until we're sure we want to try use it, |
| 913 // since it costs us GPU memory. | 914 // since it costs us GPU memory. |
| 914 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider( | 915 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider( |
| 915 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); | 916 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); |
| 916 if (!contextProvider) { | 917 if (!contextProvider) { |
| 917 CanvasMetrics::countCanvasContextUsage( | 918 CanvasMetrics::countCanvasContextUsage( |
| 918 CanvasMetrics::Accelerated2DCanvasGPUContextLost); | 919 CanvasMetrics::Accelerated2DCanvasGPUContextLost); |
| 919 return nullptr; | 920 return nullptr; |
| 920 } | 921 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 // Early out for WebGL canvases | 1019 // Early out for WebGL canvases |
| 1019 return; | 1020 return; |
| 1020 } | 1021 } |
| 1021 | 1022 |
| 1022 m_imageBuffer->setClient(this); | 1023 m_imageBuffer->setClient(this); |
| 1023 // Enabling MSAA overrides a request to disable antialiasing. This is true | 1024 // Enabling MSAA overrides a request to disable antialiasing. This is true |
| 1024 // regardless of whether the rendering mode is accelerated or not. For | 1025 // regardless of whether the rendering mode is accelerated or not. For |
| 1025 // consistency, we don't want to apply AA in accelerated canvases but not in | 1026 // consistency, we don't want to apply AA in accelerated canvases but not in |
| 1026 // unaccelerated canvases. | 1027 // unaccelerated canvases. |
| 1027 if (!msaaSampleCount && document().settings() && | 1028 if (!msaaSampleCount && document().settings() && |
| 1028 !document().settings()->antialiased2dCanvasEnabled()) | 1029 !document().settings()->GetAntialiased2dCanvasEnabled()) |
| 1029 m_context->setShouldAntialias(false); | 1030 m_context->setShouldAntialias(false); |
| 1030 | 1031 |
| 1031 if (m_context) | 1032 if (m_context) |
| 1032 setNeedsCompositingUpdate(); | 1033 setNeedsCompositingUpdate(); |
| 1033 } | 1034 } |
| 1034 | 1035 |
| 1035 void HTMLCanvasElement::notifySurfaceInvalid() { | 1036 void HTMLCanvasElement::notifySurfaceInvalid() { |
| 1036 if (m_context && m_context->is2d()) | 1037 if (m_context && m_context->is2d()) |
| 1037 m_context->loseContext(CanvasRenderingContext::RealLostContext); | 1038 m_context->loseContext(CanvasRenderingContext::RealLostContext); |
| 1038 } | 1039 } |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1406 m_surfaceLayerBridge = WTF::wrapUnique(new CanvasSurfaceLayerBridge(this)); | 1407 m_surfaceLayerBridge = WTF::wrapUnique(new CanvasSurfaceLayerBridge(this)); |
| 1407 // Creates a placeholder layer first before Surface is created. | 1408 // Creates a placeholder layer first before Surface is created. |
| 1408 m_surfaceLayerBridge->createSolidColorLayer(); | 1409 m_surfaceLayerBridge->createSolidColorLayer(); |
| 1409 } | 1410 } |
| 1410 | 1411 |
| 1411 void HTMLCanvasElement::OnWebLayerReplaced() { | 1412 void HTMLCanvasElement::OnWebLayerReplaced() { |
| 1412 setNeedsCompositingUpdate(); | 1413 setNeedsCompositingUpdate(); |
| 1413 } | 1414 } |
| 1414 | 1415 |
| 1415 } // namespace blink | 1416 } // namespace blink |
| OLD | NEW |