Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp

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

Powered by Google App Engine
This is Rietveld 408576698