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 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 } | 841 } |
842 | 842 |
843 class UnacceleratedSurfaceFactory | 843 class UnacceleratedSurfaceFactory |
844 : public RecordingImageBufferFallbackSurfaceFactory { | 844 : public RecordingImageBufferFallbackSurfaceFactory { |
845 public: | 845 public: |
846 virtual std::unique_ptr<ImageBufferSurface> createSurface( | 846 virtual std::unique_ptr<ImageBufferSurface> createSurface( |
847 const IntSize& size, | 847 const IntSize& size, |
848 OpacityMode opacityMode, | 848 OpacityMode opacityMode, |
849 sk_sp<SkColorSpace> colorSpace, | 849 sk_sp<SkColorSpace> colorSpace, |
850 SkColorType colorType) { | 850 SkColorType colorType) { |
851 return wrapUnique(new UnacceleratedImageBufferSurface( | 851 return WTF::wrapUnique(new UnacceleratedImageBufferSurface( |
852 size, opacityMode, InitializeImagePixels, colorSpace, colorType)); | 852 size, opacityMode, InitializeImagePixels, colorSpace, colorType)); |
853 } | 853 } |
854 | 854 |
855 virtual ~UnacceleratedSurfaceFactory() {} | 855 virtual ~UnacceleratedSurfaceFactory() {} |
856 }; | 856 }; |
857 | 857 |
858 bool HTMLCanvasElement::shouldUseDisplayList(const IntSize& deviceSize) { | 858 bool HTMLCanvasElement::shouldUseDisplayList(const IntSize& deviceSize) { |
859 if (m_context->colorSpace() != kLegacyCanvasColorSpace) | 859 if (m_context->colorSpace() != kLegacyCanvasColorSpace) |
860 return false; | 860 return false; |
861 | 861 |
862 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) | 862 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) |
863 return true; | 863 return true; |
864 | 864 |
865 if (!RuntimeEnabledFeatures::displayList2dCanvasEnabled()) | 865 if (!RuntimeEnabledFeatures::displayList2dCanvasEnabled()) |
866 return false; | 866 return false; |
867 | 867 |
868 return true; | 868 return true; |
869 } | 869 } |
870 | 870 |
871 std::unique_ptr<ImageBufferSurface> | 871 std::unique_ptr<ImageBufferSurface> |
872 HTMLCanvasElement::createWebGLImageBufferSurface(const IntSize& deviceSize, | 872 HTMLCanvasElement::createWebGLImageBufferSurface(const IntSize& deviceSize, |
873 OpacityMode opacityMode) { | 873 OpacityMode opacityMode) { |
874 DCHECK(is3D()); | 874 DCHECK(is3D()); |
875 // If 3d, but the use of the canvas will be for non-accelerated content | 875 // If 3d, but the use of the canvas will be for non-accelerated content |
876 // then make a non-accelerated ImageBuffer. This means copying the internal | 876 // then make a non-accelerated ImageBuffer. This means copying the internal |
877 // Image will require a pixel readback, but that is unavoidable in this case. | 877 // Image will require a pixel readback, but that is unavoidable in this case. |
878 auto surface = wrapUnique(new AcceleratedImageBufferSurface( | 878 auto surface = WTF::wrapUnique(new AcceleratedImageBufferSurface( |
879 deviceSize, opacityMode, m_context->skColorSpace(), | 879 deviceSize, opacityMode, m_context->skColorSpace(), |
880 m_context->colorType())); | 880 m_context->colorType())); |
881 if (surface->isValid()) | 881 if (surface->isValid()) |
882 return std::move(surface); | 882 return std::move(surface); |
883 return nullptr; | 883 return nullptr; |
884 } | 884 } |
885 | 885 |
886 std::unique_ptr<ImageBufferSurface> | 886 std::unique_ptr<ImageBufferSurface> |
887 HTMLCanvasElement::createAcceleratedImageBufferSurface( | 887 HTMLCanvasElement::createAcceleratedImageBufferSurface( |
888 const IntSize& deviceSize, | 888 const IntSize& deviceSize, |
(...skipping 13 matching lines...) Expand all Loading... |
902 if (!contextProvider) { | 902 if (!contextProvider) { |
903 CanvasMetrics::countCanvasContextUsage( | 903 CanvasMetrics::countCanvasContextUsage( |
904 CanvasMetrics::Accelerated2DCanvasGPUContextLost); | 904 CanvasMetrics::Accelerated2DCanvasGPUContextLost); |
905 return nullptr; | 905 return nullptr; |
906 } | 906 } |
907 | 907 |
908 if (contextProvider->isSoftwareRendering()) | 908 if (contextProvider->isSoftwareRendering()) |
909 return nullptr; // Don't use accelerated canvas with swiftshader. | 909 return nullptr; // Don't use accelerated canvas with swiftshader. |
910 | 910 |
911 std::unique_ptr<ImageBufferSurface> surface = | 911 std::unique_ptr<ImageBufferSurface> surface = |
912 wrapUnique(new Canvas2DImageBufferSurface( | 912 WTF::wrapUnique(new Canvas2DImageBufferSurface( |
913 std::move(contextProvider), deviceSize, *msaaSampleCount, opacityMode, | 913 std::move(contextProvider), deviceSize, *msaaSampleCount, opacityMode, |
914 Canvas2DLayerBridge::EnableAcceleration, m_context->skColorSpace(), | 914 Canvas2DLayerBridge::EnableAcceleration, m_context->skColorSpace(), |
915 m_context->colorType())); | 915 m_context->colorType())); |
916 if (!surface->isValid()) { | 916 if (!surface->isValid()) { |
917 CanvasMetrics::countCanvasContextUsage( | 917 CanvasMetrics::countCanvasContextUsage( |
918 CanvasMetrics::GPUAccelerated2DCanvasImageBufferCreationFailed); | 918 CanvasMetrics::GPUAccelerated2DCanvasImageBufferCreationFailed); |
919 return nullptr; | 919 return nullptr; |
920 } | 920 } |
921 | 921 |
922 CanvasMetrics::countCanvasContextUsage( | 922 CanvasMetrics::countCanvasContextUsage( |
923 CanvasMetrics::GPUAccelerated2DCanvasImageBufferCreated); | 923 CanvasMetrics::GPUAccelerated2DCanvasImageBufferCreated); |
924 return surface; | 924 return surface; |
925 } | 925 } |
926 | 926 |
927 std::unique_ptr<ImageBufferSurface> | 927 std::unique_ptr<ImageBufferSurface> |
928 HTMLCanvasElement::createUnacceleratedImageBufferSurface( | 928 HTMLCanvasElement::createUnacceleratedImageBufferSurface( |
929 const IntSize& deviceSize, | 929 const IntSize& deviceSize, |
930 OpacityMode opacityMode) { | 930 OpacityMode opacityMode) { |
931 if (shouldUseDisplayList(deviceSize)) { | 931 if (shouldUseDisplayList(deviceSize)) { |
932 auto surface = wrapUnique(new RecordingImageBufferSurface( | 932 auto surface = WTF::wrapUnique(new RecordingImageBufferSurface( |
933 deviceSize, wrapUnique(new UnacceleratedSurfaceFactory), opacityMode, | 933 deviceSize, WTF::wrapUnique(new UnacceleratedSurfaceFactory), |
934 m_context->skColorSpace(), m_context->colorType())); | 934 opacityMode, m_context->skColorSpace(), m_context->colorType())); |
935 if (surface->isValid()) { | 935 if (surface->isValid()) { |
936 CanvasMetrics::countCanvasContextUsage( | 936 CanvasMetrics::countCanvasContextUsage( |
937 CanvasMetrics::DisplayList2DCanvasImageBufferCreated); | 937 CanvasMetrics::DisplayList2DCanvasImageBufferCreated); |
938 return std::move(surface); | 938 return std::move(surface); |
939 } | 939 } |
940 // We fallback to a non-display-list surface without recording a metric | 940 // We fallback to a non-display-list surface without recording a metric |
941 // here. | 941 // here. |
942 } | 942 } |
943 | 943 |
944 auto surfaceFactory = makeUnique<UnacceleratedSurfaceFactory>(); | 944 auto surfaceFactory = WTF::makeUnique<UnacceleratedSurfaceFactory>(); |
945 auto surface = surfaceFactory->createSurface(deviceSize, opacityMode, | 945 auto surface = surfaceFactory->createSurface(deviceSize, opacityMode, |
946 m_context->skColorSpace(), | 946 m_context->skColorSpace(), |
947 m_context->colorType()); | 947 m_context->colorType()); |
948 if (surface->isValid()) { | 948 if (surface->isValid()) { |
949 CanvasMetrics::countCanvasContextUsage( | 949 CanvasMetrics::countCanvasContextUsage( |
950 CanvasMetrics::Unaccelerated2DCanvasImageBufferCreated); | 950 CanvasMetrics::Unaccelerated2DCanvasImageBufferCreated); |
951 return surface; | 951 return surface; |
952 } | 952 } |
953 | 953 |
954 CanvasMetrics::countCanvasContextUsage( | 954 CanvasMetrics::countCanvasContextUsage( |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 return m_context->getIdFromControl(element); | 1381 return m_context->getIdFromControl(element); |
1382 return String(); | 1382 return String(); |
1383 } | 1383 } |
1384 | 1384 |
1385 bool HTMLCanvasElement::createSurfaceLayer() { | 1385 bool HTMLCanvasElement::createSurfaceLayer() { |
1386 DCHECK(!m_surfaceLayerBridge); | 1386 DCHECK(!m_surfaceLayerBridge); |
1387 mojom::blink::OffscreenCanvasSurfacePtr service; | 1387 mojom::blink::OffscreenCanvasSurfacePtr service; |
1388 Platform::current()->interfaceProvider()->getInterface( | 1388 Platform::current()->interfaceProvider()->getInterface( |
1389 mojo::GetProxy(&service)); | 1389 mojo::GetProxy(&service)); |
1390 m_surfaceLayerBridge = | 1390 m_surfaceLayerBridge = |
1391 wrapUnique(new CanvasSurfaceLayerBridge(std::move(service))); | 1391 WTF::wrapUnique(new CanvasSurfaceLayerBridge(std::move(service))); |
1392 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), | 1392 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), |
1393 this->height()); | 1393 this->height()); |
1394 } | 1394 } |
1395 | 1395 |
1396 } // namespace blink | 1396 } // namespace blink |
OLD | NEW |