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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" | 61 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" |
62 #include "platform/graphics/ImageBuffer.h" | 62 #include "platform/graphics/ImageBuffer.h" |
63 #include "platform/graphics/RecordingImageBufferSurface.h" | 63 #include "platform/graphics/RecordingImageBufferSurface.h" |
64 #include "platform/graphics/StaticBitmapImage.h" | 64 #include "platform/graphics/StaticBitmapImage.h" |
65 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 65 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
66 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" | 66 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" |
67 #include "platform/transforms/AffineTransform.h" | 67 #include "platform/transforms/AffineTransform.h" |
68 #include "public/platform/Platform.h" | 68 #include "public/platform/Platform.h" |
69 #include "public/platform/WebTraceLocation.h" | 69 #include "public/platform/WebTraceLocation.h" |
70 #include "wtf/CheckedNumeric.h" | 70 #include "wtf/CheckedNumeric.h" |
| 71 #include "wtf/PtrUtil.h" |
71 #include <math.h> | 72 #include <math.h> |
| 73 #include <memory> |
72 #include <v8.h> | 74 #include <v8.h> |
73 | 75 |
74 namespace blink { | 76 namespace blink { |
75 | 77 |
76 using namespace HTMLNames; | 78 using namespace HTMLNames; |
77 | 79 |
78 namespace { | 80 namespace { |
79 | 81 |
80 // These values come from the WhatWG spec. | 82 // These values come from the WhatWG spec. |
81 const int DefaultWidth = 300; | 83 const int DefaultWidth = 300; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 DEFINE_STATIC_LOCAL(ContextFactoryVector, s_contextFactories, (CanvasRenderi
ngContext::ContextTypeCount)); | 203 DEFINE_STATIC_LOCAL(ContextFactoryVector, s_contextFactories, (CanvasRenderi
ngContext::ContextTypeCount)); |
202 return s_contextFactories; | 204 return s_contextFactories; |
203 } | 205 } |
204 | 206 |
205 CanvasRenderingContextFactory* HTMLCanvasElement::getRenderingContextFactory(int
type) | 207 CanvasRenderingContextFactory* HTMLCanvasElement::getRenderingContextFactory(int
type) |
206 { | 208 { |
207 DCHECK(type < CanvasRenderingContext::ContextTypeCount); | 209 DCHECK(type < CanvasRenderingContext::ContextTypeCount); |
208 return renderingContextFactories()[type].get(); | 210 return renderingContextFactories()[type].get(); |
209 } | 211 } |
210 | 212 |
211 void HTMLCanvasElement::registerRenderingContextFactory(PassOwnPtr<CanvasRenderi
ngContextFactory> renderingContextFactory) | 213 void HTMLCanvasElement::registerRenderingContextFactory(std::unique_ptr<CanvasRe
nderingContextFactory> renderingContextFactory) |
212 { | 214 { |
213 CanvasRenderingContext::ContextType type = renderingContextFactory->getConte
xtType(); | 215 CanvasRenderingContext::ContextType type = renderingContextFactory->getConte
xtType(); |
214 DCHECK(type < CanvasRenderingContext::ContextTypeCount); | 216 DCHECK(type < CanvasRenderingContext::ContextTypeCount); |
215 DCHECK(!renderingContextFactories()[type]); | 217 DCHECK(!renderingContextFactories()[type]); |
216 renderingContextFactories()[type] = std::move(renderingContextFactory); | 218 renderingContextFactories()[type] = std::move(renderingContextFactory); |
217 } | 219 } |
218 | 220 |
219 CanvasRenderingContext* HTMLCanvasElement::getCanvasRenderingContext(const Strin
g& type, const CanvasContextCreationAttributes& attributes) | 221 CanvasRenderingContext* HTMLCanvasElement::getCanvasRenderingContext(const Strin
g& type, const CanvasContextCreationAttributes& attributes) |
220 { | 222 { |
221 CanvasRenderingContext::ContextType contextType = CanvasRenderingContext::co
ntextTypeFromId(type); | 223 CanvasRenderingContext::ContextType contextType = CanvasRenderingContext::co
ntextTypeFromId(type); |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 // resource limits. So we need to keep the number of texture resources | 764 // resource limits. So we need to keep the number of texture resources |
763 // under tight control | 765 // under tight control |
764 if (ImageBuffer::getGlobalAcceleratedImageBufferCount() >= MaxGlobalAccelera
tedImageBufferCount) | 766 if (ImageBuffer::getGlobalAcceleratedImageBufferCount() >= MaxGlobalAccelera
tedImageBufferCount) |
765 return false; | 767 return false; |
766 | 768 |
767 return true; | 769 return true; |
768 } | 770 } |
769 | 771 |
770 class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa
ctory { | 772 class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa
ctory { |
771 public: | 773 public: |
772 virtual PassOwnPtr<ImageBufferSurface> createSurface(const IntSize& size, Op
acityMode opacityMode) | 774 virtual std::unique_ptr<ImageBufferSurface> createSurface(const IntSize& siz
e, OpacityMode opacityMode) |
773 { | 775 { |
774 return adoptPtr(new UnacceleratedImageBufferSurface(size, opacityMode)); | 776 return wrapUnique(new UnacceleratedImageBufferSurface(size, opacityMode)
); |
775 } | 777 } |
776 | 778 |
777 virtual ~UnacceleratedSurfaceFactory() { } | 779 virtual ~UnacceleratedSurfaceFactory() { } |
778 }; | 780 }; |
779 | 781 |
780 bool HTMLCanvasElement::shouldUseDisplayList(const IntSize& deviceSize) | 782 bool HTMLCanvasElement::shouldUseDisplayList(const IntSize& deviceSize) |
781 { | 783 { |
782 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) | 784 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) |
783 return true; | 785 return true; |
784 | 786 |
785 if (!RuntimeEnabledFeatures::displayList2dCanvasEnabled()) | 787 if (!RuntimeEnabledFeatures::displayList2dCanvasEnabled()) |
786 return false; | 788 return false; |
787 | 789 |
788 return true; | 790 return true; |
789 } | 791 } |
790 | 792 |
791 PassOwnPtr<ImageBufferSurface> HTMLCanvasElement::createImageBufferSurface(const
IntSize& deviceSize, int* msaaSampleCount) | 793 std::unique_ptr<ImageBufferSurface> HTMLCanvasElement::createImageBufferSurface(
const IntSize& deviceSize, int* msaaSampleCount) |
792 { | 794 { |
793 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque :
Opaque; | 795 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque :
Opaque; |
794 | 796 |
795 *msaaSampleCount = 0; | 797 *msaaSampleCount = 0; |
796 if (is3D()) { | 798 if (is3D()) { |
797 // If 3d, but the use of the canvas will be for non-accelerated content | 799 // If 3d, but the use of the canvas will be for non-accelerated content |
798 // then make a non-accelerated ImageBuffer. This means copying the inter
nal | 800 // then make a non-accelerated ImageBuffer. This means copying the inter
nal |
799 // Image will require a pixel readback, but that is unavoidable in this
case. | 801 // Image will require a pixel readback, but that is unavoidable in this
case. |
800 return adoptPtr(new AcceleratedImageBufferSurface(deviceSize, opacityMod
e)); | 802 return wrapUnique(new AcceleratedImageBufferSurface(deviceSize, opacityM
ode)); |
801 } | 803 } |
802 | 804 |
803 if (shouldAccelerate(deviceSize)) { | 805 if (shouldAccelerate(deviceSize)) { |
804 if (document().settings()) | 806 if (document().settings()) |
805 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASam
pleCount(); | 807 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASam
pleCount(); |
806 OwnPtr<ImageBufferSurface> surface = adoptPtr(new Canvas2DImageBufferSur
face(deviceSize, *msaaSampleCount, opacityMode, Canvas2DLayerBridge::EnableAccel
eration)); | 808 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new Canvas2DIma
geBufferSurface(deviceSize, *msaaSampleCount, opacityMode, Canvas2DLayerBridge::
EnableAcceleration)); |
807 if (surface->isValid()) { | 809 if (surface->isValid()) { |
808 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated
2DCanvasImageBufferCreated); | 810 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated
2DCanvasImageBufferCreated); |
809 return surface; | 811 return surface; |
810 } | 812 } |
811 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated2DCa
nvasImageBufferCreationFailed); | 813 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated2DCa
nvasImageBufferCreationFailed); |
812 } | 814 } |
813 | 815 |
814 OwnPtr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = adoptPtr
(new UnacceleratedSurfaceFactory()); | 816 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory =
wrapUnique(new UnacceleratedSurfaceFactory()); |
815 | 817 |
816 if (shouldUseDisplayList(deviceSize)) { | 818 if (shouldUseDisplayList(deviceSize)) { |
817 OwnPtr<ImageBufferSurface> surface = adoptPtr(new RecordingImageBufferSu
rface(deviceSize, std::move(surfaceFactory), opacityMode)); | 819 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new RecordingIm
ageBufferSurface(deviceSize, std::move(surfaceFactory), opacityMode)); |
818 if (surface->isValid()) { | 820 if (surface->isValid()) { |
819 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::DisplayList2DC
anvasImageBufferCreated); | 821 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::DisplayList2DC
anvasImageBufferCreated); |
820 return surface; | 822 return surface; |
821 } | 823 } |
822 surfaceFactory = adoptPtr(new UnacceleratedSurfaceFactory()); // recreat
e because previous one was released | 824 surfaceFactory = wrapUnique(new UnacceleratedSurfaceFactory()); // recre
ate because previous one was released |
823 } | 825 } |
824 auto surface = surfaceFactory->createSurface(deviceSize, opacityMode); | 826 auto surface = surfaceFactory->createSurface(deviceSize, opacityMode); |
825 if (!surface->isValid()) { | 827 if (!surface->isValid()) { |
826 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Unaccelerated2DCan
vasImageBufferCreationFailed); | 828 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Unaccelerated2DCan
vasImageBufferCreationFailed); |
827 } else { | 829 } else { |
828 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Unaccelerated2DCan
vasImageBufferCreated); | 830 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Unaccelerated2DCan
vasImageBufferCreated); |
829 } | 831 } |
830 return surface; | 832 return surface; |
831 } | 833 } |
832 | 834 |
833 void HTMLCanvasElement::createImageBuffer() | 835 void HTMLCanvasElement::createImageBuffer() |
834 { | 836 { |
835 createImageBufferInternal(nullptr); | 837 createImageBufferInternal(nullptr); |
836 if (m_didFailToCreateImageBuffer && m_context->is2d() && !size().isEmpty()) | 838 if (m_didFailToCreateImageBuffer && m_context->is2d() && !size().isEmpty()) |
837 m_context->loseContext(CanvasRenderingContext::SyntheticLostContext); | 839 m_context->loseContext(CanvasRenderingContext::SyntheticLostContext); |
838 } | 840 } |
839 | 841 |
840 void HTMLCanvasElement::createImageBufferInternal(PassOwnPtr<ImageBufferSurface>
externalSurface) | 842 void HTMLCanvasElement::createImageBufferInternal(std::unique_ptr<ImageBufferSur
face> externalSurface) |
841 { | 843 { |
842 DCHECK(!m_imageBuffer); | 844 DCHECK(!m_imageBuffer); |
843 | 845 |
844 m_didFailToCreateImageBuffer = true; | 846 m_didFailToCreateImageBuffer = true; |
845 m_imageBufferIsClear = true; | 847 m_imageBufferIsClear = true; |
846 | 848 |
847 if (!canCreateImageBuffer(size())) | 849 if (!canCreateImageBuffer(size())) |
848 return; | 850 return; |
849 | 851 |
850 int msaaSampleCount = 0; | 852 int msaaSampleCount = 0; |
851 OwnPtr<ImageBufferSurface> surface; | 853 std::unique_ptr<ImageBufferSurface> surface; |
852 if (externalSurface) { | 854 if (externalSurface) { |
853 surface = std::move(externalSurface); | 855 surface = std::move(externalSurface); |
854 } else { | 856 } else { |
855 surface = createImageBufferSurface(size(), &msaaSampleCount); | 857 surface = createImageBufferSurface(size(), &msaaSampleCount); |
856 } | 858 } |
857 m_imageBuffer = ImageBuffer::create(std::move(surface)); | 859 m_imageBuffer = ImageBuffer::create(std::move(surface)); |
858 if (!m_imageBuffer) | 860 if (!m_imageBuffer) |
859 return; | 861 return; |
860 m_imageBuffer->setClient(this); | 862 m_imageBuffer->setClient(this); |
861 | 863 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 } | 952 } |
951 | 953 |
952 ImageBuffer* HTMLCanvasElement::buffer() const | 954 ImageBuffer* HTMLCanvasElement::buffer() const |
953 { | 955 { |
954 DCHECK(m_context); | 956 DCHECK(m_context); |
955 if (!hasImageBuffer() && !m_didFailToCreateImageBuffer) | 957 if (!hasImageBuffer() && !m_didFailToCreateImageBuffer) |
956 const_cast<HTMLCanvasElement*>(this)->createImageBuffer(); | 958 const_cast<HTMLCanvasElement*>(this)->createImageBuffer(); |
957 return m_imageBuffer.get(); | 959 return m_imageBuffer.get(); |
958 } | 960 } |
959 | 961 |
960 void HTMLCanvasElement::createImageBufferUsingSurfaceForTesting(PassOwnPtr<Image
BufferSurface> surface) | 962 void HTMLCanvasElement::createImageBufferUsingSurfaceForTesting(std::unique_ptr<
ImageBufferSurface> surface) |
961 { | 963 { |
962 discardImageBuffer(); | 964 discardImageBuffer(); |
963 setWidth(surface->size().width()); | 965 setWidth(surface->size().width()); |
964 setHeight(surface->size().height()); | 966 setHeight(surface->size().height()); |
965 createImageBufferInternal(std::move(surface)); | 967 createImageBufferInternal(std::move(surface)); |
966 } | 968 } |
967 | 969 |
968 void HTMLCanvasElement::ensureUnacceleratedImageBuffer() | 970 void HTMLCanvasElement::ensureUnacceleratedImageBuffer() |
969 { | 971 { |
970 DCHECK(m_context); | 972 DCHECK(m_context); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 | 1179 |
1178 String HTMLCanvasElement::getIdFromControl(const Element* element) | 1180 String HTMLCanvasElement::getIdFromControl(const Element* element) |
1179 { | 1181 { |
1180 if (m_context) | 1182 if (m_context) |
1181 return m_context->getIdFromControl(element); | 1183 return m_context->getIdFromControl(element); |
1182 return String(); | 1184 return String(); |
1183 } | 1185 } |
1184 | 1186 |
1185 void HTMLCanvasElement::createSurfaceLayerBridge() | 1187 void HTMLCanvasElement::createSurfaceLayerBridge() |
1186 { | 1188 { |
1187 m_surfaceLayerBridge = adoptPtr(new CanvasSurfaceLayerBridge()); | 1189 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge()); |
1188 } | 1190 } |
1189 | 1191 |
1190 } // namespace blink | 1192 } // namespace blink |
OLD | NEW |