| 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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 | 507 |
| 508 // TODO(junov): Paint is currently only implemented by ImageBitmap contexts. | 508 // TODO(junov): Paint is currently only implemented by ImageBitmap contexts. |
| 509 // We could improve the abstraction by making all context types paint | 509 // We could improve the abstraction by making all context types paint |
| 510 // themselves (implement paint()). | 510 // themselves (implement paint()). |
| 511 if (m_context->paint(context, pixelSnappedIntRect(r))) | 511 if (m_context->paint(context, pixelSnappedIntRect(r))) |
| 512 return; | 512 return; |
| 513 | 513 |
| 514 m_context->paintRenderingResultsToCanvas(FrontBuffer); | 514 m_context->paintRenderingResultsToCanvas(FrontBuffer); |
| 515 if (hasImageBuffer()) { | 515 if (hasImageBuffer()) { |
| 516 if (!context.contextDisabled()) { | 516 if (!context.contextDisabled()) { |
| 517 SkXfermode::Mode compositeOperator = !m_context || m_context->hasAlp
ha() ? SkXfermode::kSrcOver_Mode : SkXfermode::kSrc_Mode; | 517 SkXfermode::Mode compositeOperator = !m_context || m_context->creati
onAttributes().alpha() ? SkXfermode::kSrcOver_Mode : SkXfermode::kSrc_Mode; |
| 518 buffer()->draw(context, pixelSnappedIntRect(r), 0, compositeOperator
); | 518 buffer()->draw(context, pixelSnappedIntRect(r), 0, compositeOperator
); |
| 519 } | 519 } |
| 520 } else { | 520 } else { |
| 521 // When alpha is false, we should draw to opaque black. | 521 // When alpha is false, we should draw to opaque black. |
| 522 if (!m_context->hasAlpha()) | 522 if (!m_context->creationAttributes().alpha()) |
| 523 context.fillRect(FloatRect(r), Color(0, 0, 0)); | 523 context.fillRect(FloatRect(r), Color(0, 0, 0)); |
| 524 } | 524 } |
| 525 | 525 |
| 526 if (is3D() && paintsIntoCanvasBuffer()) | 526 if (is3D() && paintsIntoCanvasBuffer()) |
| 527 m_context->markLayerComposited(); | 527 m_context->markLayerComposited(); |
| 528 } | 528 } |
| 529 | 529 |
| 530 bool HTMLCanvasElement::is3D() const | 530 bool HTMLCanvasElement::is3D() const |
| 531 { | 531 { |
| 532 return m_context && m_context->is3d(); | 532 return m_context && m_context->is3d(); |
| (...skipping 278 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->creationAttributes().alph
a() ? 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 setHeight(surface->size().height()); | 1013 setHeight(surface->size().height()); |
| 1014 createImageBufferInternal(std::move(surface)); | 1014 createImageBufferInternal(std::move(surface)); |
| 1015 } | 1015 } |
| 1016 | 1016 |
| 1017 void HTMLCanvasElement::ensureUnacceleratedImageBuffer() | 1017 void HTMLCanvasElement::ensureUnacceleratedImageBuffer() |
| 1018 { | 1018 { |
| 1019 DCHECK(m_context); | 1019 DCHECK(m_context); |
| 1020 if ((hasImageBuffer() && !m_imageBuffer->isAccelerated()) || m_didFailToCrea
teImageBuffer) | 1020 if ((hasImageBuffer() && !m_imageBuffer->isAccelerated()) || m_didFailToCrea
teImageBuffer) |
| 1021 return; | 1021 return; |
| 1022 discardImageBuffer(); | 1022 discardImageBuffer(); |
| 1023 OpacityMode opacityMode = m_context->hasAlpha() ? NonOpaque : Opaque; | 1023 OpacityMode opacityMode = m_context->creationAttributes().alpha() ? NonOpaqu
e : Opaque; |
| 1024 m_imageBuffer = ImageBuffer::create(size(), opacityMode); | 1024 m_imageBuffer = ImageBuffer::create(size(), opacityMode); |
| 1025 m_didFailToCreateImageBuffer = !m_imageBuffer; | 1025 m_didFailToCreateImageBuffer = !m_imageBuffer; |
| 1026 } | 1026 } |
| 1027 | 1027 |
| 1028 PassRefPtr<Image> HTMLCanvasElement::copiedImage(SourceDrawingBuffer sourceBuffe
r, AccelerationHint hint) const | 1028 PassRefPtr<Image> HTMLCanvasElement::copiedImage(SourceDrawingBuffer sourceBuffe
r, AccelerationHint hint) const |
| 1029 { | 1029 { |
| 1030 if (!isPaintable()) | 1030 if (!isPaintable()) |
| 1031 return nullptr; | 1031 return nullptr; |
| 1032 if (!m_context) | 1032 if (!m_context) |
| 1033 return createTransparentImage(size()); | 1033 return createTransparentImage(size()); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1150 if ((cropRect && !ImageBitmap::isSourceSizeValid(cropRect->width(), cropRect
->height(), exceptionState)) | 1150 if ((cropRect && !ImageBitmap::isSourceSizeValid(cropRect->width(), cropRect
->height(), exceptionState)) |
| 1151 || !ImageBitmap::isSourceSizeValid(bitmapSourceSize().width(), bitmapSou
rceSize().height(), exceptionState)) | 1151 || !ImageBitmap::isSourceSizeValid(bitmapSourceSize().width(), bitmapSou
rceSize().height(), exceptionState)) |
| 1152 return ScriptPromise(); | 1152 return ScriptPromise(); |
| 1153 if (!ImageBitmap::isResizeOptionValid(options, exceptionState)) | 1153 if (!ImageBitmap::isResizeOptionValid(options, exceptionState)) |
| 1154 return ScriptPromise(); | 1154 return ScriptPromise(); |
| 1155 return ImageBitmapSource::fulfillImageBitmap(scriptState, isPaintable() ? Im
ageBitmap::create(this, cropRect, options) : nullptr); | 1155 return ImageBitmapSource::fulfillImageBitmap(scriptState, isPaintable() ? Im
ageBitmap::create(this, cropRect, options) : nullptr); |
| 1156 } | 1156 } |
| 1157 | 1157 |
| 1158 bool HTMLCanvasElement::isOpaque() const | 1158 bool HTMLCanvasElement::isOpaque() const |
| 1159 { | 1159 { |
| 1160 return m_context && !m_context->hasAlpha(); | 1160 return m_context && !m_context->creationAttributes().alpha(); |
| 1161 } | 1161 } |
| 1162 | 1162 |
| 1163 bool HTMLCanvasElement::isSupportedInteractiveCanvasFallback(const Element& elem
ent) | 1163 bool HTMLCanvasElement::isSupportedInteractiveCanvasFallback(const Element& elem
ent) |
| 1164 { | 1164 { |
| 1165 if (!element.isDescendantOf(this)) | 1165 if (!element.isDescendantOf(this)) |
| 1166 return false; | 1166 return false; |
| 1167 | 1167 |
| 1168 // An element is a supported interactive canvas fallback element if it is on
e of the following: | 1168 // An element is a supported interactive canvas fallback element if it is on
e of the following: |
| 1169 // https://html.spec.whatwg.org/multipage/scripting.html#supported-interacti
ve-canvas-fallback-element | 1169 // https://html.spec.whatwg.org/multipage/scripting.html#supported-interacti
ve-canvas-fallback-element |
| 1170 | 1170 |
| (...skipping 63 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 |