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

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

Powered by Google App Engine
This is Rietveld 408576698