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

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

Issue 2050123002: Remove OwnPtr from Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments from Kent; merge. 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"
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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 DEFINE_STATIC_LOCAL(ContextFactoryVector, s_contextFactories, (CanvasRenderi ngContext::ContextTypeCount)); 201 DEFINE_STATIC_LOCAL(ContextFactoryVector, s_contextFactories, (CanvasRenderi ngContext::ContextTypeCount));
200 return s_contextFactories; 202 return s_contextFactories;
201 } 203 }
202 204
203 CanvasRenderingContextFactory* HTMLCanvasElement::getRenderingContextFactory(int type) 205 CanvasRenderingContextFactory* HTMLCanvasElement::getRenderingContextFactory(int type)
204 { 206 {
205 DCHECK(type < CanvasRenderingContext::ContextTypeCount); 207 DCHECK(type < CanvasRenderingContext::ContextTypeCount);
206 return renderingContextFactories()[type].get(); 208 return renderingContextFactories()[type].get();
207 } 209 }
208 210
209 void HTMLCanvasElement::registerRenderingContextFactory(PassOwnPtr<CanvasRenderi ngContextFactory> renderingContextFactory) 211 void HTMLCanvasElement::registerRenderingContextFactory(std::unique_ptr<CanvasRe nderingContextFactory> renderingContextFactory)
210 { 212 {
211 CanvasRenderingContext::ContextType type = renderingContextFactory->getConte xtType(); 213 CanvasRenderingContext::ContextType type = renderingContextFactory->getConte xtType();
212 DCHECK(type < CanvasRenderingContext::ContextTypeCount); 214 DCHECK(type < CanvasRenderingContext::ContextTypeCount);
213 DCHECK(!renderingContextFactories()[type]); 215 DCHECK(!renderingContextFactories()[type]);
214 renderingContextFactories()[type] = std::move(renderingContextFactory); 216 renderingContextFactories()[type] = std::move(renderingContextFactory);
215 } 217 }
216 218
217 CanvasRenderingContext* HTMLCanvasElement::getCanvasRenderingContext(const Strin g& type, const CanvasContextCreationAttributes& attributes) 219 CanvasRenderingContext* HTMLCanvasElement::getCanvasRenderingContext(const Strin g& type, const CanvasContextCreationAttributes& attributes)
218 { 220 {
219 CanvasRenderingContext::ContextType contextType = CanvasRenderingContext::co ntextTypeFromId(type); 221 CanvasRenderingContext::ContextType contextType = CanvasRenderingContext::co ntextTypeFromId(type);
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 // Thus, we should stop allocating more GPU memory to new canvases created 756 // Thus, we should stop allocating more GPU memory to new canvases created
755 // when the current memory usage exceeds the threshold. 757 // when the current memory usage exceeds the threshold.
756 if (ImageBuffer::getGlobalGPUMemoryUsage() >= MaxGlobalGPUMemoryUsage) 758 if (ImageBuffer::getGlobalGPUMemoryUsage() >= MaxGlobalGPUMemoryUsage)
757 return false; 759 return false;
758 760
759 return true; 761 return true;
760 } 762 }
761 763
762 class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa ctory { 764 class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa ctory {
763 public: 765 public:
764 virtual PassOwnPtr<ImageBufferSurface> createSurface(const IntSize& size, Op acityMode opacityMode) 766 virtual std::unique_ptr<ImageBufferSurface> createSurface(const IntSize& siz e, OpacityMode opacityMode)
765 { 767 {
766 return adoptPtr(new UnacceleratedImageBufferSurface(size, opacityMode)); 768 return wrapUnique(new UnacceleratedImageBufferSurface(size, opacityMode) );
767 } 769 }
768 770
769 virtual ~UnacceleratedSurfaceFactory() { } 771 virtual ~UnacceleratedSurfaceFactory() { }
770 }; 772 };
771 773
772 bool HTMLCanvasElement::shouldUseDisplayList(const IntSize& deviceSize) 774 bool HTMLCanvasElement::shouldUseDisplayList(const IntSize& deviceSize)
773 { 775 {
774 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) 776 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled())
775 return true; 777 return true;
776 778
777 if (!RuntimeEnabledFeatures::displayList2dCanvasEnabled()) 779 if (!RuntimeEnabledFeatures::displayList2dCanvasEnabled())
778 return false; 780 return false;
779 781
780 return true; 782 return true;
781 } 783 }
782 784
783 PassOwnPtr<ImageBufferSurface> HTMLCanvasElement::createImageBufferSurface(const IntSize& deviceSize, int* msaaSampleCount) 785 std::unique_ptr<ImageBufferSurface> HTMLCanvasElement::createImageBufferSurface( const IntSize& deviceSize, int* msaaSampleCount)
784 { 786 {
785 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque : Opaque; 787 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque : Opaque;
786 788
787 *msaaSampleCount = 0; 789 *msaaSampleCount = 0;
788 if (is3D()) { 790 if (is3D()) {
789 // If 3d, but the use of the canvas will be for non-accelerated content 791 // If 3d, but the use of the canvas will be for non-accelerated content
790 // then make a non-accelerated ImageBuffer. This means copying the inter nal 792 // then make a non-accelerated ImageBuffer. This means copying the inter nal
791 // Image will require a pixel readback, but that is unavoidable in this case. 793 // Image will require a pixel readback, but that is unavoidable in this case.
792 return adoptPtr(new AcceleratedImageBufferSurface(deviceSize, opacityMod e)); 794 return wrapUnique(new AcceleratedImageBufferSurface(deviceSize, opacityM ode));
793 } 795 }
794 796
795 if (shouldAccelerate(deviceSize)) { 797 if (shouldAccelerate(deviceSize)) {
796 if (document().settings()) 798 if (document().settings())
797 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASam pleCount(); 799 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASam pleCount();
798 OwnPtr<ImageBufferSurface> surface = adoptPtr(new Canvas2DImageBufferSur face(deviceSize, *msaaSampleCount, opacityMode, Canvas2DLayerBridge::EnableAccel eration)); 800 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new Canvas2DIma geBufferSurface(deviceSize, *msaaSampleCount, opacityMode, Canvas2DLayerBridge:: EnableAcceleration));
799 if (surface->isValid()) { 801 if (surface->isValid()) {
800 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated 2DCanvasImageBufferCreated); 802 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated 2DCanvasImageBufferCreated);
801 return surface; 803 return surface;
802 } 804 }
803 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated2DCa nvasImageBufferCreationFailed); 805 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated2DCa nvasImageBufferCreationFailed);
804 } 806 }
805 807
806 OwnPtr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = adoptPtr (new UnacceleratedSurfaceFactory()); 808 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = wrapUnique(new UnacceleratedSurfaceFactory());
807 809
808 if (shouldUseDisplayList(deviceSize)) { 810 if (shouldUseDisplayList(deviceSize)) {
809 OwnPtr<ImageBufferSurface> surface = adoptPtr(new RecordingImageBufferSu rface(deviceSize, std::move(surfaceFactory), opacityMode)); 811 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new RecordingIm ageBufferSurface(deviceSize, std::move(surfaceFactory), opacityMode));
810 if (surface->isValid()) { 812 if (surface->isValid()) {
811 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::DisplayList2DC anvasImageBufferCreated); 813 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::DisplayList2DC anvasImageBufferCreated);
812 return surface; 814 return surface;
813 } 815 }
814 surfaceFactory = adoptPtr(new UnacceleratedSurfaceFactory()); // recreat e because previous one was released 816 surfaceFactory = wrapUnique(new UnacceleratedSurfaceFactory()); // recre ate because previous one was released
815 } 817 }
816 auto surface = surfaceFactory->createSurface(deviceSize, opacityMode); 818 auto surface = surfaceFactory->createSurface(deviceSize, opacityMode);
817 if (!surface->isValid()) { 819 if (!surface->isValid()) {
818 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Unaccelerated2DCan vasImageBufferCreationFailed); 820 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Unaccelerated2DCan vasImageBufferCreationFailed);
819 } else { 821 } else {
820 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Unaccelerated2DCan vasImageBufferCreated); 822 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Unaccelerated2DCan vasImageBufferCreated);
821 } 823 }
822 return surface; 824 return surface;
823 } 825 }
824 826
825 void HTMLCanvasElement::createImageBuffer() 827 void HTMLCanvasElement::createImageBuffer()
826 { 828 {
827 createImageBufferInternal(nullptr); 829 createImageBufferInternal(nullptr);
828 if (m_didFailToCreateImageBuffer && m_context->is2d() && !size().isEmpty()) 830 if (m_didFailToCreateImageBuffer && m_context->is2d() && !size().isEmpty())
829 m_context->loseContext(CanvasRenderingContext::SyntheticLostContext); 831 m_context->loseContext(CanvasRenderingContext::SyntheticLostContext);
830 } 832 }
831 833
832 void HTMLCanvasElement::createImageBufferInternal(PassOwnPtr<ImageBufferSurface> externalSurface) 834 void HTMLCanvasElement::createImageBufferInternal(std::unique_ptr<ImageBufferSur face> externalSurface)
833 { 835 {
834 DCHECK(!m_imageBuffer); 836 DCHECK(!m_imageBuffer);
835 837
836 m_didFailToCreateImageBuffer = true; 838 m_didFailToCreateImageBuffer = true;
837 m_imageBufferIsClear = true; 839 m_imageBufferIsClear = true;
838 840
839 if (!canCreateImageBuffer(size())) 841 if (!canCreateImageBuffer(size()))
840 return; 842 return;
841 843
842 int msaaSampleCount = 0; 844 int msaaSampleCount = 0;
843 OwnPtr<ImageBufferSurface> surface; 845 std::unique_ptr<ImageBufferSurface> surface;
844 if (externalSurface) { 846 if (externalSurface) {
845 surface = std::move(externalSurface); 847 surface = std::move(externalSurface);
846 } else { 848 } else {
847 surface = createImageBufferSurface(size(), &msaaSampleCount); 849 surface = createImageBufferSurface(size(), &msaaSampleCount);
848 } 850 }
849 m_imageBuffer = ImageBuffer::create(std::move(surface)); 851 m_imageBuffer = ImageBuffer::create(std::move(surface));
850 if (!m_imageBuffer) 852 if (!m_imageBuffer)
851 return; 853 return;
852 m_imageBuffer->setClient(this); 854 m_imageBuffer->setClient(this);
853 855
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 } 944 }
943 945
944 ImageBuffer* HTMLCanvasElement::buffer() const 946 ImageBuffer* HTMLCanvasElement::buffer() const
945 { 947 {
946 DCHECK(m_context); 948 DCHECK(m_context);
947 if (!hasImageBuffer() && !m_didFailToCreateImageBuffer) 949 if (!hasImageBuffer() && !m_didFailToCreateImageBuffer)
948 const_cast<HTMLCanvasElement*>(this)->createImageBuffer(); 950 const_cast<HTMLCanvasElement*>(this)->createImageBuffer();
949 return m_imageBuffer.get(); 951 return m_imageBuffer.get();
950 } 952 }
951 953
952 void HTMLCanvasElement::createImageBufferUsingSurfaceForTesting(PassOwnPtr<Image BufferSurface> surface) 954 void HTMLCanvasElement::createImageBufferUsingSurfaceForTesting(std::unique_ptr< ImageBufferSurface> surface)
953 { 955 {
954 discardImageBuffer(); 956 discardImageBuffer();
955 setWidth(surface->size().width()); 957 setWidth(surface->size().width());
956 setHeight(surface->size().height()); 958 setHeight(surface->size().height());
957 createImageBufferInternal(std::move(surface)); 959 createImageBufferInternal(std::move(surface));
958 } 960 }
959 961
960 void HTMLCanvasElement::ensureUnacceleratedImageBuffer() 962 void HTMLCanvasElement::ensureUnacceleratedImageBuffer()
961 { 963 {
962 DCHECK(m_context); 964 DCHECK(m_context);
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 1171
1170 String HTMLCanvasElement::getIdFromControl(const Element* element) 1172 String HTMLCanvasElement::getIdFromControl(const Element* element)
1171 { 1173 {
1172 if (m_context) 1174 if (m_context)
1173 return m_context->getIdFromControl(element); 1175 return m_context->getIdFromControl(element);
1174 return String(); 1176 return String();
1175 } 1177 }
1176 1178
1177 void HTMLCanvasElement::createSurfaceLayerBridge() 1179 void HTMLCanvasElement::createSurfaceLayerBridge()
1178 { 1180 {
1179 m_surfaceLayerBridge = adoptPtr(new CanvasSurfaceLayerBridge()); 1181 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge());
1180 } 1182 }
1181 1183
1182 } // namespace blink 1184 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698