| 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 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 // resource limits. So we need to keep the number of texture resources | 811 // resource limits. So we need to keep the number of texture resources |
| 812 // under tight control | 812 // under tight control |
| 813 if (ImageBuffer::getGlobalAcceleratedImageBufferCount() >= MaxGlobalAccelera
tedImageBufferCount) | 813 if (ImageBuffer::getGlobalAcceleratedImageBufferCount() >= MaxGlobalAccelera
tedImageBufferCount) |
| 814 return false; | 814 return false; |
| 815 | 815 |
| 816 return true; | 816 return true; |
| 817 } | 817 } |
| 818 | 818 |
| 819 class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa
ctory { | 819 class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa
ctory { |
| 820 public: | 820 public: |
| 821 virtual std::unique_ptr<ImageBufferSurface> createSurface(const IntSize& siz
e, OpacityMode opacityMode) | 821 virtual std::unique_ptr<ImageBufferSurface> createSurface(const IntSize& siz
e, OpacityMode opacityMode, sk_sp<SkColorSpace> colorSpace) |
| 822 { | 822 { |
| 823 return wrapUnique(new UnacceleratedImageBufferSurface(size, opacityMode)
); | 823 return wrapUnique(new UnacceleratedImageBufferSurface(size, opacityMode,
InitializeImagePixels, colorSpace)); |
| 824 } | 824 } |
| 825 | 825 |
| 826 virtual ~UnacceleratedSurfaceFactory() { } | 826 virtual ~UnacceleratedSurfaceFactory() { } |
| 827 }; | 827 }; |
| 828 | 828 |
| 829 bool HTMLCanvasElement::shouldUseDisplayList(const IntSize& deviceSize) | 829 bool HTMLCanvasElement::shouldUseDisplayList(const IntSize& deviceSize) |
| 830 { | 830 { |
| 831 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) | 831 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) |
| 832 return true; | 832 return true; |
| 833 | 833 |
| 834 if (!RuntimeEnabledFeatures::displayList2dCanvasEnabled()) | 834 if (!RuntimeEnabledFeatures::displayList2dCanvasEnabled()) |
| 835 return false; | 835 return false; |
| 836 | 836 |
| 837 return true; | 837 return true; |
| 838 } | 838 } |
| 839 | 839 |
| 840 std::unique_ptr<ImageBufferSurface> HTMLCanvasElement::createImageBufferSurface(
const IntSize& deviceSize, int* msaaSampleCount) | 840 std::unique_ptr<ImageBufferSurface> HTMLCanvasElement::createImageBufferSurface(
const IntSize& deviceSize, int* msaaSampleCount, sk_sp<SkColorSpace> colorSpace) |
| 841 { | 841 { |
| 842 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque :
Opaque; | 842 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque :
Opaque; |
| 843 | 843 |
| 844 *msaaSampleCount = 0; | 844 *msaaSampleCount = 0; |
| 845 if (is3D()) { | 845 if (is3D()) { |
| 846 // If 3d, but the use of the canvas will be for non-accelerated content | 846 // If 3d, but the use of the canvas will be for non-accelerated content |
| 847 // then make a non-accelerated ImageBuffer. This means copying the inter
nal | 847 // then make a non-accelerated ImageBuffer. This means copying the inter
nal |
| 848 // Image will require a pixel readback, but that is unavoidable in this
case. | 848 // Image will require a pixel readback, but that is unavoidable in this
case. |
| 849 return wrapUnique(new AcceleratedImageBufferSurface(deviceSize, opacityM
ode)); | 849 return wrapUnique(new AcceleratedImageBufferSurface(deviceSize, opacityM
ode, colorSpace)); |
| 850 } | 850 } |
| 851 | 851 |
| 852 if (shouldAccelerate(deviceSize)) { | 852 if (shouldAccelerate(deviceSize)) { |
| 853 if (document().settings()) | 853 if (document().settings()) |
| 854 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASam
pleCount(); | 854 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASam
pleCount(); |
| 855 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new Canvas2DIma
geBufferSurface(deviceSize, *msaaSampleCount, opacityMode, Canvas2DLayerBridge::
EnableAcceleration)); | 855 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new Canvas2DIma
geBufferSurface(deviceSize, *msaaSampleCount, opacityMode, Canvas2DLayerBridge::
EnableAcceleration, colorSpace)); |
| 856 if (surface->isValid()) { | 856 if (surface->isValid()) { |
| 857 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated
2DCanvasImageBufferCreated); | 857 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated
2DCanvasImageBufferCreated); |
| 858 return surface; | 858 return surface; |
| 859 } | 859 } |
| 860 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated2DCa
nvasImageBufferCreationFailed); | 860 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated2DCa
nvasImageBufferCreationFailed); |
| 861 } | 861 } |
| 862 | 862 |
| 863 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory =
wrapUnique(new UnacceleratedSurfaceFactory()); | 863 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory =
wrapUnique(new UnacceleratedSurfaceFactory()); |
| 864 | 864 |
| 865 if (shouldUseDisplayList(deviceSize)) { | 865 if (shouldUseDisplayList(deviceSize)) { |
| 866 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new RecordingIm
ageBufferSurface(deviceSize, std::move(surfaceFactory), opacityMode)); | 866 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new RecordingIm
ageBufferSurface(deviceSize, std::move(surfaceFactory), opacityMode, colorSpace)
); |
| 867 if (surface->isValid()) { | 867 if (surface->isValid()) { |
| 868 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::DisplayList2DC
anvasImageBufferCreated); | 868 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::DisplayList2DC
anvasImageBufferCreated); |
| 869 return surface; | 869 return surface; |
| 870 } | 870 } |
| 871 surfaceFactory = wrapUnique(new UnacceleratedSurfaceFactory()); // recre
ate because previous one was released | 871 surfaceFactory = wrapUnique(new UnacceleratedSurfaceFactory()); // recre
ate because previous one was released |
| 872 } | 872 } |
| 873 auto surface = surfaceFactory->createSurface(deviceSize, opacityMode); | 873 auto surface = surfaceFactory->createSurface(deviceSize, opacityMode, colorS
pace); |
| 874 if (!surface->isValid()) { | 874 if (!surface->isValid()) { |
| 875 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Unaccelerated2DCan
vasImageBufferCreationFailed); | 875 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Unaccelerated2DCan
vasImageBufferCreationFailed); |
| 876 } else { | 876 } else { |
| 877 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Unaccelerated2DCan
vasImageBufferCreated); | 877 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Unaccelerated2DCan
vasImageBufferCreated); |
| 878 } | 878 } |
| 879 return surface; | 879 return surface; |
| 880 } | 880 } |
| 881 | 881 |
| 882 void HTMLCanvasElement::createImageBuffer() | 882 void HTMLCanvasElement::createImageBuffer() |
| 883 { | 883 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 894 m_imageBufferIsClear = true; | 894 m_imageBufferIsClear = true; |
| 895 | 895 |
| 896 if (!canCreateImageBuffer(size())) | 896 if (!canCreateImageBuffer(size())) |
| 897 return; | 897 return; |
| 898 | 898 |
| 899 int msaaSampleCount = 0; | 899 int msaaSampleCount = 0; |
| 900 std::unique_ptr<ImageBufferSurface> surface; | 900 std::unique_ptr<ImageBufferSurface> surface; |
| 901 if (externalSurface) { | 901 if (externalSurface) { |
| 902 surface = std::move(externalSurface); | 902 surface = std::move(externalSurface); |
| 903 } else { | 903 } else { |
| 904 surface = createImageBufferSurface(size(), &msaaSampleCount); | 904 surface = createImageBufferSurface(size(), &msaaSampleCount, m_context->
skColorSpace()); |
| 905 } | 905 } |
| 906 m_imageBuffer = ImageBuffer::create(std::move(surface)); | 906 m_imageBuffer = ImageBuffer::create(std::move(surface)); |
| 907 if (!m_imageBuffer) | 907 if (!m_imageBuffer) |
| 908 return; | 908 return; |
| 909 m_imageBuffer->setClient(this); | 909 m_imageBuffer->setClient(this); |
| 910 | 910 |
| 911 m_didFailToCreateImageBuffer = false; | 911 m_didFailToCreateImageBuffer = false; |
| 912 | 912 |
| 913 updateExternallyAllocatedMemory(); | 913 updateExternallyAllocatedMemory(); |
| 914 | 914 |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 | 1234 |
| 1235 bool HTMLCanvasElement::createSurfaceLayer() | 1235 bool HTMLCanvasElement::createSurfaceLayer() |
| 1236 { | 1236 { |
| 1237 DCHECK(!m_surfaceLayerBridge); | 1237 DCHECK(!m_surfaceLayerBridge); |
| 1238 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne
w CanvasSurfaceLayerBridgeClientImpl()); | 1238 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne
w CanvasSurfaceLayerBridgeClientImpl()); |
| 1239 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri
dgeClient))); | 1239 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri
dgeClient))); |
| 1240 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height(
)); | 1240 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height(
)); |
| 1241 } | 1241 } |
| 1242 | 1242 |
| 1243 } // namespace blink | 1243 } // namespace blink |
| OLD | NEW |