| 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 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 { | 815 { |
| 816 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) | 816 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) |
| 817 return true; | 817 return true; |
| 818 | 818 |
| 819 if (!RuntimeEnabledFeatures::displayList2dCanvasEnabled()) | 819 if (!RuntimeEnabledFeatures::displayList2dCanvasEnabled()) |
| 820 return false; | 820 return false; |
| 821 | 821 |
| 822 return true; | 822 return true; |
| 823 } | 823 } |
| 824 | 824 |
| 825 std::unique_ptr<ImageBufferSurface> HTMLCanvasElement::createWebGLImageBufferSur
face(const IntSize& deviceSize, OpacityMode opacityMode, sk_sp<SkColorSpace> col
orSpace) |
| 826 { |
| 827 DCHECK(is3D()); |
| 828 // If 3d, but the use of the canvas will be for non-accelerated content |
| 829 // then make a non-accelerated ImageBuffer. This means copying the internal |
| 830 // Image will require a pixel readback, but that is unavoidable in this case
. |
| 831 auto surface = wrapUnique(new AcceleratedImageBufferSurface(deviceSize, opac
ityMode, std::move(colorSpace))); |
| 832 if (surface->isValid()) |
| 833 return std::move(surface); |
| 834 return nullptr; |
| 835 } |
| 836 |
| 825 std::unique_ptr<ImageBufferSurface> HTMLCanvasElement::createAcceleratedImageBuf
ferSurface(const IntSize& deviceSize, OpacityMode opacityMode, sk_sp<SkColorSpac
e> colorSpace, int* msaaSampleCount) | 837 std::unique_ptr<ImageBufferSurface> HTMLCanvasElement::createAcceleratedImageBuf
ferSurface(const IntSize& deviceSize, OpacityMode opacityMode, sk_sp<SkColorSpac
e> colorSpace, int* msaaSampleCount) |
| 826 { | 838 { |
| 827 if (is3D()) { | |
| 828 // If 3d, but the use of the canvas will be for non-accelerated content | |
| 829 // then make a non-accelerated ImageBuffer. This means copying the inter
nal | |
| 830 // Image will require a pixel readback, but that is unavoidable in this
case. | |
| 831 return wrapUnique(new AcceleratedImageBufferSurface(deviceSize, opacityM
ode, colorSpace)); | |
| 832 } | |
| 833 | |
| 834 if (!shouldAccelerate(deviceSize)) | 839 if (!shouldAccelerate(deviceSize)) |
| 835 return nullptr; | 840 return nullptr; |
| 836 | 841 |
| 837 if (document().settings()) | 842 if (document().settings()) |
| 838 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASampleC
ount(); | 843 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASampleC
ount(); |
| 839 | 844 |
| 840 // Avoid creating |contextProvider| until we're sure we want to try use it, | 845 // Avoid creating |contextProvider| until we're sure we want to try use it, |
| 841 // since it costs us GPU memory. | 846 // since it costs us GPU memory. |
| 842 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider(Platform::curr
ent()->createSharedOffscreenGraphicsContext3DProvider()); | 847 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider(Platform::curr
ent()->createSharedOffscreenGraphicsContext3DProvider()); |
| 843 if (!contextProvider) { | 848 if (!contextProvider) { |
| 844 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Accelerated2DCanva
sGPUContextLost); | 849 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Accelerated2DCanva
sGPUContextLost); |
| 845 return nullptr; | 850 return nullptr; |
| 846 } | 851 } |
| 847 | 852 |
| 848 if (contextProvider->isSoftwareRendering()) | 853 if (contextProvider->isSoftwareRendering()) |
| 849 return nullptr; // Don't use accelerated canvas with swiftshader. | 854 return nullptr; // Don't use accelerated canvas with swiftshader. |
| 850 | 855 |
| 851 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new Canvas2DImageBu
fferSurface(std::move(contextProvider), deviceSize, *msaaSampleCount, opacityMod
e, Canvas2DLayerBridge::EnableAcceleration, std::move(colorSpace))); | 856 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new Canvas2DImageBu
fferSurface(std::move(contextProvider), deviceSize, *msaaSampleCount, opacityMod
e, Canvas2DLayerBridge::EnableAcceleration, std::move(colorSpace))); |
| 852 if (surface->isValid()) { | 857 if (!surface->isValid()) { |
| 853 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated2DCa
nvasImageBufferCreated); | 858 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated2DCa
nvasImageBufferCreationFailed); |
| 854 return surface; | 859 return nullptr; |
| 855 } | 860 } |
| 856 | 861 |
| 857 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated2DCanvas
ImageBufferCreationFailed); | 862 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated2DCanvas
ImageBufferCreated); |
| 858 return nullptr; | 863 return surface; |
| 859 } | 864 } |
| 860 | 865 |
| 861 std::unique_ptr<ImageBufferSurface> HTMLCanvasElement::createUnacceleratedImageB
ufferSurface(const IntSize& deviceSize, OpacityMode opacityMode, sk_sp<SkColorSp
ace> colorSpace) | 866 std::unique_ptr<ImageBufferSurface> HTMLCanvasElement::createUnacceleratedImageB
ufferSurface(const IntSize& deviceSize, OpacityMode opacityMode, sk_sp<SkColorSp
ace> colorSpace) |
| 862 { | 867 { |
| 863 if (shouldUseDisplayList(deviceSize)) { | 868 if (shouldUseDisplayList(deviceSize)) { |
| 864 auto surface = wrapUnique(new RecordingImageBufferSurface(deviceSize, wr
apUnique(new UnacceleratedSurfaceFactory), opacityMode, colorSpace)); | 869 auto surface = wrapUnique(new RecordingImageBufferSurface(deviceSize, wr
apUnique(new UnacceleratedSurfaceFactory), opacityMode, colorSpace)); |
| 865 if (surface->isValid()) { | 870 if (surface->isValid()) { |
| 866 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::DisplayList2DC
anvasImageBufferCreated); | 871 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::DisplayList2DC
anvasImageBufferCreated); |
| 867 return std::move(surface); | 872 return std::move(surface); |
| 868 } | 873 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 892 DCHECK(!m_imageBuffer); | 897 DCHECK(!m_imageBuffer); |
| 893 | 898 |
| 894 m_didFailToCreateImageBuffer = true; | 899 m_didFailToCreateImageBuffer = true; |
| 895 m_imageBufferIsClear = true; | 900 m_imageBufferIsClear = true; |
| 896 | 901 |
| 897 if (!ImageBuffer::canCreateImageBuffer(size())) | 902 if (!ImageBuffer::canCreateImageBuffer(size())) |
| 898 return; | 903 return; |
| 899 | 904 |
| 900 OpacityMode opacityMode = !m_context || m_context->creationAttributes().alph
a() ? NonOpaque : Opaque; | 905 OpacityMode opacityMode = !m_context || m_context->creationAttributes().alph
a() ? NonOpaque : Opaque; |
| 901 int msaaSampleCount = 0; | 906 int msaaSampleCount = 0; |
| 902 std::unique_ptr<ImageBufferSurface> surface = std::move(externalSurface); | 907 std::unique_ptr<ImageBufferSurface> surface; |
| 903 if (!surface) | 908 if (externalSurface) { |
| 909 if (externalSurface->isValid()) |
| 910 surface = std::move(externalSurface); |
| 911 } else if (is3D()) { |
| 912 surface = createWebGLImageBufferSurface(size(), opacityMode, m_context->
skColorSpace()); |
| 913 } else { |
| 904 surface = createAcceleratedImageBufferSurface(size(), opacityMode, m_con
text->skColorSpace(), &msaaSampleCount); | 914 surface = createAcceleratedImageBufferSurface(size(), opacityMode, m_con
text->skColorSpace(), &msaaSampleCount); |
| 905 if (!surface) | 915 if (!surface) |
| 906 surface = createUnacceleratedImageBufferSurface(size(), opacityMode, m_c
ontext->skColorSpace()); | 916 surface = createUnacceleratedImageBufferSurface(size(), opacityMode,
m_context->skColorSpace()); |
| 917 } |
| 907 if (!surface) | 918 if (!surface) |
| 908 return; | 919 return; |
| 909 DCHECK(surface->isValid()); | 920 DCHECK(surface->isValid()); |
| 910 m_imageBuffer = ImageBuffer::create(std::move(surface)); | 921 m_imageBuffer = ImageBuffer::create(std::move(surface)); |
| 911 DCHECK(m_imageBuffer); | 922 DCHECK(m_imageBuffer); |
| 912 m_imageBuffer->setClient(this); | 923 m_imageBuffer->setClient(this); |
| 913 | 924 |
| 914 m_didFailToCreateImageBuffer = false; | 925 m_didFailToCreateImageBuffer = false; |
| 915 | 926 |
| 916 updateExternallyAllocatedMemory(); | 927 updateExternallyAllocatedMemory(); |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 | 1256 |
| 1246 bool HTMLCanvasElement::createSurfaceLayer() | 1257 bool HTMLCanvasElement::createSurfaceLayer() |
| 1247 { | 1258 { |
| 1248 DCHECK(!m_surfaceLayerBridge); | 1259 DCHECK(!m_surfaceLayerBridge); |
| 1249 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne
w CanvasSurfaceLayerBridgeClientImpl()); | 1260 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne
w CanvasSurfaceLayerBridgeClientImpl()); |
| 1250 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri
dgeClient))); | 1261 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri
dgeClient))); |
| 1251 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height(
)); | 1262 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height(
)); |
| 1252 } | 1263 } |
| 1253 | 1264 |
| 1254 } // namespace blink | 1265 } // namespace blink |
| OLD | NEW |