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