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

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

Issue 2125853002: Replace RefPtrs with raw pointers (imageFromNode in Editor.cpp) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: impl Created 4 years, 5 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 { 121 {
122 if (size.isEmpty()) 122 if (size.isEmpty())
123 return false; 123 return false;
124 if (size.width() * size.height() > MaxCanvasArea) 124 if (size.width() * size.height() > MaxCanvasArea)
125 return false; 125 return false;
126 if (size.width() > MaxSkiaDim || size.height() > MaxSkiaDim) 126 if (size.width() > MaxSkiaDim || size.height() > MaxSkiaDim)
127 return false; 127 return false;
128 return true; 128 return true;
129 } 129 }
130 130
131 PassRefPtr<Image> createTransparentImage(const IntSize& size)
132 {
133 DCHECK(canCreateImageBuffer(size));
134 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(size.width(), size .height());
135 surface->getCanvas()->clear(SK_ColorTRANSPARENT);
136 return StaticBitmapImage::create(fromSkSp(surface->makeImageSnapshot()));
137 }
138
139 } // namespace 131 } // namespace
140 132
141 inline HTMLCanvasElement::HTMLCanvasElement(Document& document) 133 inline HTMLCanvasElement::HTMLCanvasElement(Document& document)
142 : HTMLElement(canvasTag, document) 134 : HTMLElement(canvasTag, document)
143 , ContextLifecycleObserver(&document) 135 , ContextLifecycleObserver(&document)
144 , PageLifecycleObserver(document.page()) 136 , PageLifecycleObserver(document.page())
145 , m_size(DefaultWidth, DefaultHeight) 137 , m_size(DefaultWidth, DefaultHeight)
146 , m_ignoreReset(false) 138 , m_ignoreReset(false)
147 , m_externallyAllocatedMemory(0) 139 , m_externallyAllocatedMemory(0)
148 , m_originClean(true) 140 , m_originClean(true)
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 { 965 {
974 DCHECK(m_context); 966 DCHECK(m_context);
975 if ((hasImageBuffer() && !m_imageBuffer->isAccelerated()) || m_didFailToCrea teImageBuffer) 967 if ((hasImageBuffer() && !m_imageBuffer->isAccelerated()) || m_didFailToCrea teImageBuffer)
976 return; 968 return;
977 discardImageBuffer(); 969 discardImageBuffer();
978 OpacityMode opacityMode = m_context->hasAlpha() ? NonOpaque : Opaque; 970 OpacityMode opacityMode = m_context->hasAlpha() ? NonOpaque : Opaque;
979 m_imageBuffer = ImageBuffer::create(size(), opacityMode); 971 m_imageBuffer = ImageBuffer::create(size(), opacityMode);
980 m_didFailToCreateImageBuffer = !m_imageBuffer; 972 m_didFailToCreateImageBuffer = !m_imageBuffer;
981 } 973 }
982 974
983 PassRefPtr<Image> HTMLCanvasElement::copiedImage(SourceDrawingBuffer sourceBuffe r, AccelerationHint hint) const 975 Image* HTMLCanvasElement::copiedImage(SourceDrawingBuffer sourceBuffer, Accelera tionHint hint) const
984 { 976 {
985 if (!isPaintable()) 977 if (!isPaintable())
986 return nullptr; 978 return nullptr;
987 if (!m_context) 979 if (!m_context)
988 return createTransparentImage(size()); 980 return ensureTransparentImage();
989 981
990 bool needToUpdate = !m_copiedImage; 982 bool needToUpdate = !m_copiedImage;
991 // The concept of SourceDrawingBuffer is valid on only WebGL. 983 // The concept of SourceDrawingBuffer is valid on only WebGL.
992 if (m_context->is3d()) 984 if (m_context->is3d())
993 needToUpdate |= m_context->paintRenderingResultsToCanvas(sourceBuffer); 985 needToUpdate |= m_context->paintRenderingResultsToCanvas(sourceBuffer);
994 if (needToUpdate && buffer()) { 986 if (needToUpdate && buffer()) {
995 m_copiedImage = buffer()->newImageSnapshot(hint, SnapshotReasonGetCopied Image); 987 m_copiedImage = buffer()->newImageSnapshot(hint, SnapshotReasonGetCopied Image);
996 updateExternallyAllocatedMemory(); 988 updateExternallyAllocatedMemory();
997 } 989 }
998 return m_copiedImage; 990 return m_copiedImage.get();
999 } 991 }
1000 992
1001 void HTMLCanvasElement::discardImageBuffer() 993 void HTMLCanvasElement::discardImageBuffer()
1002 { 994 {
1003 m_imageBuffer.reset(); 995 m_imageBuffer.reset();
1004 m_dirtyRect = FloatRect(); 996 m_dirtyRect = FloatRect();
1005 updateExternallyAllocatedMemory(); 997 updateExternallyAllocatedMemory();
1006 } 998 }
1007 999
1008 void HTMLCanvasElement::clearCopiedImage() 1000 void HTMLCanvasElement::clearCopiedImage()
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 return nullptr; 1052 return nullptr;
1061 } 1053 }
1062 1054
1063 if (!isPaintable()) { 1055 if (!isPaintable()) {
1064 *status = InvalidSourceImageStatus; 1056 *status = InvalidSourceImageStatus;
1065 return nullptr; 1057 return nullptr;
1066 } 1058 }
1067 1059
1068 if (!m_context) { 1060 if (!m_context) {
1069 *status = NormalSourceImageStatus; 1061 *status = NormalSourceImageStatus;
1070 return createTransparentImage(size()); 1062 return ensureTransparentImage();
1071 } 1063 }
1072 1064
1073 if (m_context->is3d()) { 1065 if (m_context->is3d()) {
1074 m_context->paintRenderingResultsToCanvas(BackBuffer); 1066 m_context->paintRenderingResultsToCanvas(BackBuffer);
1075 } 1067 }
1076 1068
1077 RefPtr<SkImage> image = buffer()->newSkImageSnapshot(hint, reason); 1069 RefPtr<SkImage> image = buffer()->newSkImageSnapshot(hint, reason);
1078 if (image) { 1070 if (image) {
1079 *status = NormalSourceImageStatus; 1071 *status = NormalSourceImageStatus;
1080 return StaticBitmapImage::create(image.release()); 1072 return StaticBitmapImage::create(image.release());
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 } 1179 }
1188 1180
1189 bool HTMLCanvasElement::createSurfaceLayer() 1181 bool HTMLCanvasElement::createSurfaceLayer()
1190 { 1182 {
1191 DCHECK(!m_surfaceLayerBridge); 1183 DCHECK(!m_surfaceLayerBridge);
1192 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne w CanvasSurfaceLayerBridgeClientImpl()); 1184 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne w CanvasSurfaceLayerBridgeClientImpl());
1193 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri dgeClient))); 1185 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri dgeClient)));
1194 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height( )); 1186 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height( ));
1195 } 1187 }
1196 1188
1189 Image* HTMLCanvasElement::ensureTransparentImage() const
1190 {
1191 if (m_transparentImage && m_transparentImage->size() == size())
1192 return m_transparentImage.get();
1193 DCHECK(canCreateImageBuffer(size()));
1194 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(size().width(), si ze().height());
1195 surface->getCanvas()->clear(SK_ColorTRANSPARENT);
1196 m_transparentImage = StaticBitmapImage::create(fromSkSp(surface->makeImageSn apshot()));
1197 return m_transparentImage.get();
Ken Russell (switch to Gerrit) 2016/07/06 21:37:04 This seems to introduce a bunch of caching problem
hajimehoshi 2016/07/07 10:53:06 Even when the content is changed, as long as the s
1198 }
1199
1197 } // namespace blink 1200 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698