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 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 | 785 |
786 bool HTMLCanvasElement::originClean() const { | 786 bool HTMLCanvasElement::originClean() const { |
787 if (document().settings() && | 787 if (document().settings() && |
788 document().settings()->getDisableReadingFromCanvas()) | 788 document().settings()->getDisableReadingFromCanvas()) |
789 return false; | 789 return false; |
790 if (placeholderFrame()) | 790 if (placeholderFrame()) |
791 return placeholderFrame()->originClean(); | 791 return placeholderFrame()->originClean(); |
792 return m_originClean; | 792 return m_originClean; |
793 } | 793 } |
794 | 794 |
795 bool HTMLCanvasElement::shouldAccelerate(const IntSize& size) const { | 795 bool HTMLCanvasElement::shouldAccelerate(AccelerationCriteria criteria) const { |
796 if (m_context && !m_context->is2d()) | 796 if (m_context && !m_context->is2d()) |
797 return false; | 797 return false; |
798 | 798 |
799 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) | 799 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) |
800 return false; | 800 return false; |
801 | 801 |
802 if (!RuntimeEnabledFeatures::accelerated2dCanvasEnabled()) | 802 if (!RuntimeEnabledFeatures::accelerated2dCanvasEnabled()) |
803 return false; | 803 return false; |
804 | 804 |
805 // The following is necessary for handling the special case of canvases in the | 805 // The following is necessary for handling the special case of canvases in the |
806 // dev tools overlay, which run in a process that supports accelerated 2d | 806 // dev tools overlay, which run in a process that supports accelerated 2d |
807 // canvas but in a special compositing context that does not. | 807 // canvas but in a special compositing context that does not. |
808 if (layoutBox() && !layoutBox()->hasAcceleratedCompositing()) | 808 if (layoutBox() && !layoutBox()->hasAcceleratedCompositing()) |
809 return false; | 809 return false; |
810 | 810 |
811 CheckedNumeric<int> checkedCanvasPixelCount = size.width(); | 811 CheckedNumeric<int> checkedCanvasPixelCount = size().width(); |
812 checkedCanvasPixelCount *= size.height(); | 812 checkedCanvasPixelCount *= size().height(); |
813 if (!checkedCanvasPixelCount.IsValid()) | 813 if (!checkedCanvasPixelCount.IsValid()) |
814 return false; | 814 return false; |
815 int canvasPixelCount = checkedCanvasPixelCount.ValueOrDie(); | 815 int canvasPixelCount = checkedCanvasPixelCount.ValueOrDie(); |
816 | 816 |
817 if (RuntimeEnabledFeatures::displayList2dCanvasEnabled()) { | 817 if (RuntimeEnabledFeatures::displayList2dCanvasEnabled()) { |
818 #if 0 | 818 #if 0 |
819 // TODO(junov): re-enable this code once we solve the problem of recordi
ng | 819 // TODO(junov): re-enable this code once we solve the problem of recordi
ng |
820 // GPU-backed images to an SkPicture for cross-context rendering crbug.c
om/490328 | 820 // GPU-backed images to an SkPicture for cross-context rendering crbug.c
om/490328 |
821 | 821 |
822 // If the compositor provides GPU acceleration to display list canvases,
we | 822 // If the compositor provides GPU acceleration to display list canvases,
we |
823 // prefer that over direct acceleration. | 823 // prefer that over direct acceleration. |
824 if (document().viewportDescription().matchesHeuristicsForGpuRasterizatio
n()) | 824 if (document().viewportDescription().matchesHeuristicsForGpuRasterizatio
n()) |
825 return false; | 825 return false; |
826 #endif | 826 #endif |
827 // If the GPU resources would be very expensive, prefer a display list. | 827 // If the GPU resources would be very expensive, prefer a display list. |
828 if (canvasPixelCount > ExpensiveCanvasHeuristicParameters:: | 828 if (canvasPixelCount > ExpensiveCanvasHeuristicParameters:: |
829 PreferDisplayListOverGpuSizeThreshold) | 829 PreferDisplayListOverGpuSizeThreshold) |
830 return false; | 830 return false; |
831 } | 831 } |
832 | 832 |
833 // Do not use acceleration for small canvas. | 833 // Do not use acceleration for small canvas. |
834 Settings* settings = document().settings(); | 834 if (criteria != IgnoreCanvasSizeAccelerationCriteria) { |
835 if (!settings || | 835 Settings* settings = document().settings(); |
836 canvasPixelCount < settings->getMinimumAccelerated2dCanvasSize()) | 836 if (!settings || |
837 return false; | 837 canvasPixelCount < settings->getMinimumAccelerated2dCanvasSize()) |
| 838 return false; |
| 839 } |
838 | 840 |
839 // When GPU allocated memory runs low (due to having created too many | 841 // When GPU allocated memory runs low (due to having created too many |
840 // accelerated canvases), the compositor starves and browser becomes laggy. | 842 // accelerated canvases), the compositor starves and browser becomes laggy. |
841 // Thus, we should stop allocating more GPU memory to new canvases created | 843 // Thus, we should stop allocating more GPU memory to new canvases created |
842 // when the current memory usage exceeds the threshold. | 844 // when the current memory usage exceeds the threshold. |
843 if (ImageBuffer::getGlobalGPUMemoryUsage() >= MaxGlobalGPUMemoryUsage) | 845 if (ImageBuffer::getGlobalGPUMemoryUsage() >= MaxGlobalGPUMemoryUsage) |
844 return false; | 846 return false; |
845 | 847 |
846 // Allocating too many GPU resources can makes us run into the driver's | 848 // Allocating too many GPU resources can makes us run into the driver's |
847 // resource limits. So we need to keep the number of texture resources | 849 // resource limits. So we need to keep the number of texture resources |
(...skipping 17 matching lines...) Expand all Loading... |
865 SkColorType colorType) { | 867 SkColorType colorType) { |
866 return WTF::wrapUnique(new UnacceleratedImageBufferSurface( | 868 return WTF::wrapUnique(new UnacceleratedImageBufferSurface( |
867 size, opacityMode, InitializeImagePixels, colorSpace, colorType)); | 869 size, opacityMode, InitializeImagePixels, colorSpace, colorType)); |
868 } | 870 } |
869 | 871 |
870 virtual ~UnacceleratedSurfaceFactory() {} | 872 virtual ~UnacceleratedSurfaceFactory() {} |
871 }; | 873 }; |
872 | 874 |
873 } // namespace | 875 } // namespace |
874 | 876 |
875 bool HTMLCanvasElement::shouldUseDisplayList(const IntSize& deviceSize) { | 877 bool HTMLCanvasElement::shouldUseDisplayList() { |
876 if (m_context->colorSpace() != kLegacyCanvasColorSpace) | 878 if (m_context->colorSpace() != kLegacyCanvasColorSpace) |
877 return false; | 879 return false; |
878 | 880 |
879 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) | 881 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) |
880 return true; | 882 return true; |
881 | 883 |
882 if (!RuntimeEnabledFeatures::displayList2dCanvasEnabled()) | 884 if (!RuntimeEnabledFeatures::displayList2dCanvasEnabled()) |
883 return false; | 885 return false; |
884 | 886 |
885 return true; | 887 return true; |
886 } | 888 } |
887 | 889 |
888 std::unique_ptr<ImageBufferSurface> | 890 std::unique_ptr<ImageBufferSurface> |
889 HTMLCanvasElement::createWebGLImageBufferSurface(const IntSize& deviceSize, | 891 HTMLCanvasElement::createWebGLImageBufferSurface(OpacityMode opacityMode) { |
890 OpacityMode opacityMode) { | |
891 DCHECK(is3D()); | 892 DCHECK(is3D()); |
892 // If 3d, but the use of the canvas will be for non-accelerated content | 893 // If 3d, but the use of the canvas will be for non-accelerated content |
893 // then make a non-accelerated ImageBuffer. This means copying the internal | 894 // then make a non-accelerated ImageBuffer. This means copying the internal |
894 // Image will require a pixel readback, but that is unavoidable in this case. | 895 // Image will require a pixel readback, but that is unavoidable in this case. |
895 auto surface = WTF::wrapUnique(new AcceleratedImageBufferSurface( | 896 auto surface = WTF::wrapUnique(new AcceleratedImageBufferSurface( |
896 deviceSize, opacityMode, m_context->skColorSpace(), | 897 size(), opacityMode, m_context->skColorSpace(), m_context->colorType())); |
897 m_context->colorType())); | |
898 if (surface->isValid()) | 898 if (surface->isValid()) |
899 return std::move(surface); | 899 return std::move(surface); |
900 return nullptr; | 900 return nullptr; |
901 } | 901 } |
902 | 902 |
903 std::unique_ptr<ImageBufferSurface> | 903 std::unique_ptr<ImageBufferSurface> |
904 HTMLCanvasElement::createAcceleratedImageBufferSurface( | 904 HTMLCanvasElement::createAcceleratedImageBufferSurface( |
905 const IntSize& deviceSize, | |
906 OpacityMode opacityMode, | 905 OpacityMode opacityMode, |
907 int* msaaSampleCount) { | 906 int* msaaSampleCount) { |
908 if (!shouldAccelerate(deviceSize)) | |
909 return nullptr; | |
910 | |
911 if (document().settings()) { | 907 if (document().settings()) { |
912 *msaaSampleCount = | 908 *msaaSampleCount = |
913 document().settings()->getAccelerated2dCanvasMSAASampleCount(); | 909 document().settings()->getAccelerated2dCanvasMSAASampleCount(); |
914 } | 910 } |
915 | 911 |
916 // Avoid creating |contextProvider| until we're sure we want to try use it, | 912 // Avoid creating |contextProvider| until we're sure we want to try use it, |
917 // since it costs us GPU memory. | 913 // since it costs us GPU memory. |
918 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider( | 914 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider( |
919 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); | 915 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); |
920 if (!contextProvider) { | 916 if (!contextProvider) { |
921 CanvasMetrics::countCanvasContextUsage( | 917 CanvasMetrics::countCanvasContextUsage( |
922 CanvasMetrics::Accelerated2DCanvasGPUContextLost); | 918 CanvasMetrics::Accelerated2DCanvasGPUContextLost); |
923 return nullptr; | 919 return nullptr; |
924 } | 920 } |
925 | 921 |
926 if (contextProvider->isSoftwareRendering()) | 922 if (contextProvider->isSoftwareRendering()) |
927 return nullptr; // Don't use accelerated canvas with swiftshader. | 923 return nullptr; // Don't use accelerated canvas with swiftshader. |
928 | 924 |
929 std::unique_ptr<ImageBufferSurface> surface = | 925 std::unique_ptr<ImageBufferSurface> surface = |
930 WTF::wrapUnique(new Canvas2DImageBufferSurface( | 926 WTF::wrapUnique(new Canvas2DImageBufferSurface( |
931 std::move(contextProvider), deviceSize, *msaaSampleCount, opacityMode, | 927 std::move(contextProvider), size(), *msaaSampleCount, opacityMode, |
932 Canvas2DLayerBridge::EnableAcceleration, m_context->skColorSpace(), | 928 Canvas2DLayerBridge::EnableAcceleration, m_context->skColorSpace(), |
933 m_context->colorType())); | 929 m_context->colorType())); |
934 if (!surface->isValid()) { | 930 if (!surface->isValid()) { |
935 CanvasMetrics::countCanvasContextUsage( | 931 CanvasMetrics::countCanvasContextUsage( |
936 CanvasMetrics::GPUAccelerated2DCanvasImageBufferCreationFailed); | 932 CanvasMetrics::GPUAccelerated2DCanvasImageBufferCreationFailed); |
937 return nullptr; | 933 return nullptr; |
938 } | 934 } |
939 | 935 |
940 CanvasMetrics::countCanvasContextUsage( | 936 CanvasMetrics::countCanvasContextUsage( |
941 CanvasMetrics::GPUAccelerated2DCanvasImageBufferCreated); | 937 CanvasMetrics::GPUAccelerated2DCanvasImageBufferCreated); |
942 return surface; | 938 return surface; |
943 } | 939 } |
944 | 940 |
945 std::unique_ptr<ImageBufferSurface> | 941 std::unique_ptr<ImageBufferSurface> |
946 HTMLCanvasElement::createUnacceleratedImageBufferSurface( | 942 HTMLCanvasElement::createUnacceleratedImageBufferSurface( |
947 const IntSize& deviceSize, | |
948 OpacityMode opacityMode) { | 943 OpacityMode opacityMode) { |
949 if (shouldUseDisplayList(deviceSize)) { | 944 if (shouldUseDisplayList()) { |
950 auto surface = WTF::wrapUnique(new RecordingImageBufferSurface( | 945 auto surface = WTF::wrapUnique(new RecordingImageBufferSurface( |
951 deviceSize, WTF::wrapUnique(new UnacceleratedSurfaceFactory), | 946 size(), WTF::wrapUnique(new UnacceleratedSurfaceFactory), opacityMode, |
952 opacityMode, m_context->skColorSpace(), m_context->colorType())); | 947 m_context->skColorSpace(), m_context->colorType())); |
953 if (surface->isValid()) { | 948 if (surface->isValid()) { |
954 CanvasMetrics::countCanvasContextUsage( | 949 CanvasMetrics::countCanvasContextUsage( |
955 CanvasMetrics::DisplayList2DCanvasImageBufferCreated); | 950 CanvasMetrics::DisplayList2DCanvasImageBufferCreated); |
956 return std::move(surface); | 951 return std::move(surface); |
957 } | 952 } |
958 // We fallback to a non-display-list surface without recording a metric | 953 // We fallback to a non-display-list surface without recording a metric |
959 // here. | 954 // here. |
960 } | 955 } |
961 | 956 |
962 auto surfaceFactory = WTF::makeUnique<UnacceleratedSurfaceFactory>(); | 957 auto surfaceFactory = WTF::makeUnique<UnacceleratedSurfaceFactory>(); |
963 auto surface = surfaceFactory->createSurface(deviceSize, opacityMode, | 958 auto surface = surfaceFactory->createSurface( |
964 m_context->skColorSpace(), | 959 size(), opacityMode, m_context->skColorSpace(), m_context->colorType()); |
965 m_context->colorType()); | |
966 if (surface->isValid()) { | 960 if (surface->isValid()) { |
967 CanvasMetrics::countCanvasContextUsage( | 961 CanvasMetrics::countCanvasContextUsage( |
968 CanvasMetrics::Unaccelerated2DCanvasImageBufferCreated); | 962 CanvasMetrics::Unaccelerated2DCanvasImageBufferCreated); |
969 return surface; | 963 return surface; |
970 } | 964 } |
971 | 965 |
972 CanvasMetrics::countCanvasContextUsage( | 966 CanvasMetrics::countCanvasContextUsage( |
973 CanvasMetrics::Unaccelerated2DCanvasImageBufferCreationFailed); | 967 CanvasMetrics::Unaccelerated2DCanvasImageBufferCreationFailed); |
974 return nullptr; | 968 return nullptr; |
975 } | 969 } |
(...skipping 16 matching lines...) Expand all Loading... |
992 | 986 |
993 OpacityMode opacityMode = | 987 OpacityMode opacityMode = |
994 !m_context || m_context->creationAttributes().alpha() ? NonOpaque | 988 !m_context || m_context->creationAttributes().alpha() ? NonOpaque |
995 : Opaque; | 989 : Opaque; |
996 int msaaSampleCount = 0; | 990 int msaaSampleCount = 0; |
997 std::unique_ptr<ImageBufferSurface> surface; | 991 std::unique_ptr<ImageBufferSurface> surface; |
998 if (externalSurface) { | 992 if (externalSurface) { |
999 if (externalSurface->isValid()) | 993 if (externalSurface->isValid()) |
1000 surface = std::move(externalSurface); | 994 surface = std::move(externalSurface); |
1001 } else if (is3D()) { | 995 } else if (is3D()) { |
1002 surface = createWebGLImageBufferSurface(size(), opacityMode); | 996 surface = createWebGLImageBufferSurface(opacityMode); |
1003 } else { | 997 } else { |
1004 surface = createAcceleratedImageBufferSurface(size(), opacityMode, | 998 if (shouldAccelerate(NormalAccelerationCriteria)) { |
1005 &msaaSampleCount); | 999 surface = |
| 1000 createAcceleratedImageBufferSurface(opacityMode, &msaaSampleCount); |
| 1001 } |
1006 if (!surface) { | 1002 if (!surface) { |
1007 surface = createUnacceleratedImageBufferSurface(size(), opacityMode); | 1003 surface = createUnacceleratedImageBufferSurface(opacityMode); |
1008 } | 1004 } |
1009 } | 1005 } |
1010 if (!surface) | 1006 if (!surface) |
1011 return; | 1007 return; |
1012 DCHECK(surface->isValid()); | 1008 DCHECK(surface->isValid()); |
1013 m_imageBuffer = ImageBuffer::create(std::move(surface)); | 1009 m_imageBuffer = ImageBuffer::create(std::move(surface)); |
1014 DCHECK(m_imageBuffer); | 1010 DCHECK(m_imageBuffer); |
1015 m_imageBuffer->setClient(this); | 1011 m_imageBuffer->setClient(this); |
1016 | 1012 |
1017 m_didFailToCreateImageBuffer = false; | 1013 m_didFailToCreateImageBuffer = false; |
1018 | 1014 |
1019 updateExternallyAllocatedMemory(); | 1015 updateExternallyAllocatedMemory(); |
1020 | 1016 |
1021 if (is3D()) { | 1017 if (is3D()) { |
1022 // Early out for WebGL canvases | 1018 // Early out for WebGL canvases |
1023 return; | 1019 return; |
1024 } | 1020 } |
1025 | 1021 |
1026 m_imageBuffer->setClient(this); | |
1027 // Enabling MSAA overrides a request to disable antialiasing. This is true | 1022 // Enabling MSAA overrides a request to disable antialiasing. This is true |
1028 // regardless of whether the rendering mode is accelerated or not. For | 1023 // regardless of whether the rendering mode is accelerated or not. For |
1029 // consistency, we don't want to apply AA in accelerated canvases but not in | 1024 // consistency, we don't want to apply AA in accelerated canvases but not in |
1030 // unaccelerated canvases. | 1025 // unaccelerated canvases. |
1031 if (!msaaSampleCount && document().settings() && | 1026 if (!msaaSampleCount && document().settings() && |
1032 !document().settings()->getAntialiased2dCanvasEnabled()) | 1027 !document().settings()->getAntialiased2dCanvasEnabled()) |
1033 m_context->setShouldAntialias(false); | 1028 m_context->setShouldAntialias(false); |
1034 | 1029 |
1035 if (m_context) | 1030 if (m_context) |
1036 setNeedsCompositingUpdate(); | 1031 setNeedsCompositingUpdate(); |
(...skipping 27 matching lines...) Expand all Loading... |
1064 // Adding 2 is a pessimistic but relevant estimate. | 1059 // Adding 2 is a pessimistic but relevant estimate. |
1065 // Note: These buffers might be allocated in GPU memory. | 1060 // Note: These buffers might be allocated in GPU memory. |
1066 bufferCount += 2; | 1061 bufferCount += 2; |
1067 } | 1062 } |
1068 } | 1063 } |
1069 if (m_copiedImage) | 1064 if (m_copiedImage) |
1070 bufferCount++; | 1065 bufferCount++; |
1071 | 1066 |
1072 // Four bytes per pixel per buffer. | 1067 // Four bytes per pixel per buffer. |
1073 CheckedNumeric<intptr_t> checkedExternallyAllocatedMemory = 4 * bufferCount; | 1068 CheckedNumeric<intptr_t> checkedExternallyAllocatedMemory = 4 * bufferCount; |
1074 if (is3D()) | 1069 if (is3D()) { |
1075 checkedExternallyAllocatedMemory += | 1070 checkedExternallyAllocatedMemory += |
1076 m_context->externallyAllocatedBytesPerPixel(); | 1071 m_context->externallyAllocatedBytesPerPixel(); |
| 1072 } |
1077 | 1073 |
1078 checkedExternallyAllocatedMemory *= width(); | 1074 checkedExternallyAllocatedMemory *= width(); |
1079 checkedExternallyAllocatedMemory *= height(); | 1075 checkedExternallyAllocatedMemory *= height(); |
1080 intptr_t externallyAllocatedMemory = | 1076 intptr_t externallyAllocatedMemory = |
1081 checkedExternallyAllocatedMemory.ValueOrDefault( | 1077 checkedExternallyAllocatedMemory.ValueOrDefault( |
1082 std::numeric_limits<intptr_t>::max()); | 1078 std::numeric_limits<intptr_t>::max()); |
1083 | 1079 |
1084 // Subtracting two intptr_t that are known to be positive will never | 1080 // Subtracting two intptr_t that are known to be positive will never |
1085 // underflow. | 1081 // underflow. |
1086 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( | 1082 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1206 if (m_context) | 1202 if (m_context) |
1207 m_context->styleDidChange(oldStyle, newStyle); | 1203 m_context->styleDidChange(oldStyle, newStyle); |
1208 } | 1204 } |
1209 | 1205 |
1210 void HTMLCanvasElement::didMoveToNewDocument(Document& oldDocument) { | 1206 void HTMLCanvasElement::didMoveToNewDocument(Document& oldDocument) { |
1211 ContextLifecycleObserver::setContext(&document()); | 1207 ContextLifecycleObserver::setContext(&document()); |
1212 PageVisibilityObserver::setContext(document().page()); | 1208 PageVisibilityObserver::setContext(document().page()); |
1213 HTMLElement::didMoveToNewDocument(oldDocument); | 1209 HTMLElement::didMoveToNewDocument(oldDocument); |
1214 } | 1210 } |
1215 | 1211 |
| 1212 void HTMLCanvasElement::willDrawImageTo2DContext(CanvasImageSource* source) { |
| 1213 if (ExpensiveCanvasHeuristicParameters::EnableAccelerationToAvoidReadbacks && |
| 1214 source->isAccelerated() && !buffer()->isAccelerated() && |
| 1215 shouldAccelerate(IgnoreCanvasSizeAccelerationCriteria)) { |
| 1216 OpacityMode opacityMode = |
| 1217 m_context->creationAttributes().alpha() ? NonOpaque : Opaque; |
| 1218 int msaaSampleCount = 0; |
| 1219 std::unique_ptr<ImageBufferSurface> surface = |
| 1220 createAcceleratedImageBufferSurface(opacityMode, &msaaSampleCount); |
| 1221 if (surface) { |
| 1222 buffer()->setSurface(std::move(surface)); |
| 1223 } |
| 1224 } |
| 1225 } |
| 1226 |
1216 PassRefPtr<Image> HTMLCanvasElement::getSourceImageForCanvas( | 1227 PassRefPtr<Image> HTMLCanvasElement::getSourceImageForCanvas( |
1217 SourceImageStatus* status, | 1228 SourceImageStatus* status, |
1218 AccelerationHint hint, | 1229 AccelerationHint hint, |
1219 SnapshotReason reason, | 1230 SnapshotReason reason, |
1220 const FloatSize&) const { | 1231 const FloatSize&) const { |
1221 if (!width() || !height()) { | 1232 if (!width() || !height()) { |
1222 *status = ZeroSizeCanvasSourceImageStatus; | 1233 *status = ZeroSizeCanvasSourceImageStatus; |
1223 return nullptr; | 1234 return nullptr; |
1224 } | 1235 } |
1225 | 1236 |
(...skipping 27 matching lines...) Expand all Loading... |
1253 if (hasImageBuffer()) { | 1264 if (hasImageBuffer()) { |
1254 skImage = buffer()->newSkImageSnapshot(hint, reason); | 1265 skImage = buffer()->newSkImageSnapshot(hint, reason); |
1255 } else { | 1266 } else { |
1256 skImage = createTransparentSkImage(size()); | 1267 skImage = createTransparentSkImage(size()); |
1257 } | 1268 } |
1258 } else { | 1269 } else { |
1259 if (ExpensiveCanvasHeuristicParameters:: | 1270 if (ExpensiveCanvasHeuristicParameters:: |
1260 DisableAccelerationToAvoidReadbacks && | 1271 DisableAccelerationToAvoidReadbacks && |
1261 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled() && | 1272 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled() && |
1262 hint == PreferNoAcceleration && m_context->isAccelerated() && | 1273 hint == PreferNoAcceleration && m_context->isAccelerated() && |
1263 hasImageBuffer()) | 1274 hasImageBuffer()) { |
1264 buffer()->disableAcceleration(); | 1275 buffer()->disableAcceleration(); |
| 1276 } |
1265 RefPtr<Image> image = renderingContext()->getImage(hint, reason); | 1277 RefPtr<Image> image = renderingContext()->getImage(hint, reason); |
1266 if (image) { | 1278 if (image) { |
1267 skImage = | 1279 skImage = |
1268 image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget()); | 1280 image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget()); |
1269 } else { | 1281 } else { |
1270 skImage = createTransparentSkImage(size()); | 1282 skImage = createTransparentSkImage(size()); |
1271 } | 1283 } |
1272 } | 1284 } |
1273 | 1285 |
1274 if (skImage) { | 1286 if (skImage) { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1413 m_surfaceLayerBridge = WTF::wrapUnique(new CanvasSurfaceLayerBridge(this)); | 1425 m_surfaceLayerBridge = WTF::wrapUnique(new CanvasSurfaceLayerBridge(this)); |
1414 // Creates a placeholder layer first before Surface is created. | 1426 // Creates a placeholder layer first before Surface is created. |
1415 m_surfaceLayerBridge->createSolidColorLayer(); | 1427 m_surfaceLayerBridge->createSolidColorLayer(); |
1416 } | 1428 } |
1417 | 1429 |
1418 void HTMLCanvasElement::OnWebLayerReplaced() { | 1430 void HTMLCanvasElement::OnWebLayerReplaced() { |
1419 setNeedsCompositingUpdate(); | 1431 setNeedsCompositingUpdate(); |
1420 } | 1432 } |
1421 | 1433 |
1422 } // namespace blink | 1434 } // namespace blink |
OLD | NEW |