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

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

Issue 2594093002: Re-arrange some null pointer checks in HTMLCanvasElement.cpp (Closed)
Patch Set: Created 3 years, 12 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // gpuBufferCount in ImageBuffer::updateGPUMemoryUsage() and 4 means four bytes 104 // gpuBufferCount in ImageBuffer::updateGPUMemoryUsage() and 4 means four bytes
105 // per pixel per buffer. 105 // per pixel per buffer.
106 const int MaxGlobalGPUMemoryUsage = 106 const int MaxGlobalGPUMemoryUsage =
107 4000000 * MaxGlobalAcceleratedImageBufferCount; 107 4000000 * MaxGlobalAcceleratedImageBufferCount;
108 108
109 // A default value of quality argument for toDataURL and toBlob 109 // A default value of quality argument for toDataURL and toBlob
110 // It is in an invalid range (outside 0.0 - 1.0) so that it will not be 110 // It is in an invalid range (outside 0.0 - 1.0) so that it will not be
111 // misinterpreted as a user-input value 111 // misinterpreted as a user-input value
112 const int UndefinedQualityValue = -1.0; 112 const int UndefinedQualityValue = -1.0;
113 113
114 PassRefPtr<Image> createTransparentImage(const IntSize& size) { 114 sk_sp<SkImage> createTransparentSkImage(const IntSize& size) {
115 DCHECK(ImageBuffer::canCreateImageBuffer(size)); 115 DCHECK(ImageBuffer::canCreateImageBuffer(size));
116 sk_sp<SkSurface> surface = 116 sk_sp<SkSurface> surface =
117 SkSurface::MakeRasterN32Premul(size.width(), size.height()); 117 SkSurface::MakeRasterN32Premul(size.width(), size.height());
118 return surface ? StaticBitmapImage::create(surface->makeImageSnapshot()) 118 return surface->makeImageSnapshot();
119 : nullptr; 119 }
120
121 PassRefPtr<Image> createTransparentImage(const IntSize& size) {
122 sk_sp<SkImage> image = createTransparentSkImage(size);
123 return image ? StaticBitmapImage::create(image) : nullptr;
120 } 124 }
121 125
122 } // namespace 126 } // namespace
123 127
124 inline HTMLCanvasElement::HTMLCanvasElement(Document& document) 128 inline HTMLCanvasElement::HTMLCanvasElement(Document& document)
125 : HTMLElement(canvasTag, document), 129 : HTMLElement(canvasTag, document),
126 ContextLifecycleObserver(&document), 130 ContextLifecycleObserver(&document),
127 PageVisibilityObserver(document.page()), 131 PageVisibilityObserver(document.page()),
128 m_size(DefaultWidth, DefaultHeight), 132 m_size(DefaultWidth, DefaultHeight),
129 m_context(this, nullptr), 133 m_context(this, nullptr),
(...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 *status = InvalidSourceImageStatus; 1227 *status = InvalidSourceImageStatus;
1224 return nullptr; 1228 return nullptr;
1225 } 1229 }
1226 1230
1227 if (placeholderFrame()) { 1231 if (placeholderFrame()) {
1228 *status = NormalSourceImageStatus; 1232 *status = NormalSourceImageStatus;
1229 return placeholderFrame(); 1233 return placeholderFrame();
1230 } 1234 }
1231 1235
1232 if (!m_context) { 1236 if (!m_context) {
1233 *status = NormalSourceImageStatus; 1237 RefPtr<Image> result = createTransparentImage(size());
1234 return createTransparentImage(size()); 1238 *status = result ? NormalSourceImageStatus : InvalidSourceImageStatus;
1239 return result;
1235 } 1240 }
1236 1241
1237 if (m_context->getContextType() == CanvasRenderingContext::ContextImageBitmap) 1242 if (m_context->getContextType() == CanvasRenderingContext::ContextImageBitmap)
1238 return m_context->getImage(hint, reason); 1243 return m_context->getImage(hint, reason);
1239 1244
1240 sk_sp<SkImage> skImage; 1245 sk_sp<SkImage> skImage;
1241 // TODO(ccameron): Canvas should produce sRGB images. 1246 // TODO(ccameron): Canvas should produce sRGB images.
1242 // https://crbug.com/672299 1247 // https://crbug.com/672299
1243 if (m_context->is3d()) { 1248 if (m_context->is3d()) {
1244 // Because WebGL sources always require making a copy of the back buffer, we 1249 // Because WebGL sources always require making a copy of the back buffer, we
1245 // use paintRenderingResultsToCanvas instead of getImage in order to keep a 1250 // use paintRenderingResultsToCanvas instead of getImage in order to keep a
1246 // cached copy of the backing in the canvas's ImageBuffer. 1251 // cached copy of the backing in the canvas's ImageBuffer.
1247 renderingContext()->paintRenderingResultsToCanvas(BackBuffer); 1252 renderingContext()->paintRenderingResultsToCanvas(BackBuffer);
1248 skImage = hasImageBuffer() 1253 if (hasImageBuffer()) {
1249 ? buffer()->newSkImageSnapshot(hint, reason) 1254 skImage = buffer()->newSkImageSnapshot(hint, reason);
1250 : createTransparentImage(size())->imageForCurrentFrame( 1255 } else {
1251 ColorBehavior::transformToGlobalTarget()); 1256 skImage = createTransparentSkImage(size());
1257 }
1252 } else { 1258 } else {
1253 if (ExpensiveCanvasHeuristicParameters:: 1259 if (ExpensiveCanvasHeuristicParameters::
1254 DisableAccelerationToAvoidReadbacks && 1260 DisableAccelerationToAvoidReadbacks &&
1255 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled() && 1261 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled() &&
1256 hint == PreferNoAcceleration && m_context->isAccelerated() && 1262 hint == PreferNoAcceleration && m_context->isAccelerated() &&
1257 hasImageBuffer()) 1263 hasImageBuffer())
1258 buffer()->disableAcceleration(); 1264 buffer()->disableAcceleration();
1259 RefPtr<blink::Image> image = renderingContext()->getImage(hint, reason); 1265 RefPtr<Image> image = renderingContext()->getImage(hint, reason);
1260 skImage = image 1266 if (image) {
1261 ? image->imageForCurrentFrame( 1267 skImage =
1262 ColorBehavior::transformToGlobalTarget()) 1268 image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget());
1263 : createTransparentImage(size())->imageForCurrentFrame( 1269 } else {
1264 ColorBehavior::transformToGlobalTarget()); 1270 skImage = createTransparentSkImage(size());
1271 }
1265 } 1272 }
1266 1273
1267 if (skImage) { 1274 if (skImage) {
1268 *status = NormalSourceImageStatus; 1275 *status = NormalSourceImageStatus;
1269 return StaticBitmapImage::create(std::move(skImage)); 1276 return StaticBitmapImage::create(std::move(skImage));
1270 } 1277 }
1271 1278
1272 *status = InvalidSourceImageStatus; 1279 *status = InvalidSourceImageStatus;
1273 return nullptr; 1280 return nullptr;
1274 } 1281 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 m_surfaceLayerBridge = WTF::wrapUnique(new CanvasSurfaceLayerBridge(this)); 1413 m_surfaceLayerBridge = WTF::wrapUnique(new CanvasSurfaceLayerBridge(this));
1407 // Creates a placeholder layer first before Surface is created. 1414 // Creates a placeholder layer first before Surface is created.
1408 m_surfaceLayerBridge->createSolidColorLayer(); 1415 m_surfaceLayerBridge->createSolidColorLayer();
1409 } 1416 }
1410 1417
1411 void HTMLCanvasElement::OnWebLayerReplaced() { 1418 void HTMLCanvasElement::OnWebLayerReplaced() {
1412 setNeedsCompositingUpdate(); 1419 setNeedsCompositingUpdate();
1413 } 1420 }
1414 1421
1415 } // namespace blink 1422 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698