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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp

Issue 1414553002: Fix out-of-memory crashes related to ArrayBuffer allocation Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase+more tweaks Created 5 years, 1 month 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) 2008, Google Inc. All rights reserved. 2 * Copyright (c) 2008, Google Inc. All rights reserved.
3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
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 are 7 * modification, are permitted provided that the following conditions are
8 * met: 8 * met:
9 * 9 *
10 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "platform/image-encoders/skia/JPEGImageEncoder.h" 47 #include "platform/image-encoders/skia/JPEGImageEncoder.h"
48 #include "platform/image-encoders/skia/PNGImageEncoder.h" 48 #include "platform/image-encoders/skia/PNGImageEncoder.h"
49 #include "platform/image-encoders/skia/WEBPImageEncoder.h" 49 #include "platform/image-encoders/skia/WEBPImageEncoder.h"
50 #include "public/platform/Platform.h" 50 #include "public/platform/Platform.h"
51 #include "public/platform/WebExternalTextureMailbox.h" 51 #include "public/platform/WebExternalTextureMailbox.h"
52 #include "public/platform/WebGraphicsContext3D.h" 52 #include "public/platform/WebGraphicsContext3D.h"
53 #include "public/platform/WebGraphicsContext3DProvider.h" 53 #include "public/platform/WebGraphicsContext3DProvider.h"
54 #include "third_party/skia/include/core/SkPicture.h" 54 #include "third_party/skia/include/core/SkPicture.h"
55 #include "wtf/ArrayBufferContents.h" 55 #include "wtf/ArrayBufferContents.h"
56 #include "wtf/MathExtras.h" 56 #include "wtf/MathExtras.h"
57 #include "wtf/PartitionAlloc.h"
57 #include "wtf/Vector.h" 58 #include "wtf/Vector.h"
58 #include "wtf/text/Base64.h" 59 #include "wtf/text/Base64.h"
59 #include "wtf/text/WTFString.h" 60 #include "wtf/text/WTFString.h"
60 61
61 namespace blink { 62 namespace blink {
62 63
63 PassOwnPtr<ImageBuffer> ImageBuffer::create(PassOwnPtr<ImageBufferSurface> surfa ce) 64 PassOwnPtr<ImageBuffer> ImageBuffer::create(PassOwnPtr<ImageBufferSurface> surfa ce)
64 { 65 {
65 if (!surface->isValid()) 66 if (!surface->isValid())
66 return nullptr; 67 return nullptr;
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 284
284 bool ImageBuffer::getImageData(Multiply multiplied, const IntRect& rect, WTF::Ar rayBufferContents& contents) const 285 bool ImageBuffer::getImageData(Multiply multiplied, const IntRect& rect, WTF::Ar rayBufferContents& contents) const
285 { 286 {
286 Checked<int, RecordOverflow> dataSize = 4; 287 Checked<int, RecordOverflow> dataSize = 4;
287 dataSize *= rect.width(); 288 dataSize *= rect.width();
288 dataSize *= rect.height(); 289 dataSize *= rect.height();
289 if (dataSize.hasOverflowed()) 290 if (dataSize.hasOverflowed())
290 return false; 291 return false;
291 292
292 if (!isSurfaceValid()) { 293 if (!isSurfaceValid()) {
293 WTF::ArrayBufferContents result(rect.width() * rect.height(), 4, WTF::Ar rayBufferContents::NotShared, WTF::ArrayBufferContents::ZeroInitialize); 294 WTF::ArrayBufferContents result(rect.width() * rect.height(), 4, WTF::Ar rayBufferContents::NotShared, WTF::ArrayBufferContents::ZeroInitialize, WTF::Arr ayBufferContents::NullDataIfOutOfMemory);
295 if (!result.data())
296 return false;
294 result.transfer(contents); 297 result.transfer(contents);
295 return true; 298 return true;
296 } 299 }
297 300
298 ASSERT(canvas()); 301 ASSERT(canvas());
299 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot(PreferNoAcceleration) ; 302 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot(PreferNoAcceleration) ;
300 if (!snapshot) 303 if (!snapshot)
301 return false; 304 return false;
302 305
303 const bool mayHaveStrayArea = 306 const bool mayHaveStrayArea =
304 m_surface->isAccelerated() // GPU readback may fail silently 307 m_surface->isAccelerated() // GPU readback may fail silently
305 || rect.x() < 0 308 || rect.x() < 0
306 || rect.y() < 0 309 || rect.y() < 0
307 || rect.maxX() > m_surface->size().width() 310 || rect.maxX() > m_surface->size().width()
308 || rect.maxY() > m_surface->size().height(); 311 || rect.maxY() > m_surface->size().height();
309 WTF::ArrayBufferContents result( 312 WTF::ArrayBufferContents result(
310 rect.width() * rect.height(), 4, 313 rect.width() * rect.height(), 4,
311 WTF::ArrayBufferContents::NotShared, 314 WTF::ArrayBufferContents::NotShared,
312 mayHaveStrayArea 315 mayHaveStrayArea
313 ? WTF::ArrayBufferContents::ZeroInitialize 316 ? WTF::ArrayBufferContents::ZeroInitialize
314 : WTF::ArrayBufferContents::DontInitialize); 317 : WTF::ArrayBufferContents::DontInitialize,
318 WTF::ArrayBufferContents::NullDataIfOutOfMemory);
319
320 if (!result.data())
321 return false;
315 322
316 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; 323 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
317 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888 _SkColorType, alphaType); 324 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888 _SkColorType, alphaType);
318 325
319 snapshot->readPixels(info, result.data(), 4 * rect.width(), rect.x(), rect.y ()); 326 snapshot->readPixels(info, result.data(), 4 * rect.width(), rect.x(), rect.y ());
320 result.transfer(contents); 327 result.transfer(contents);
321 return true; 328 return true;
322 } 329 }
323 330
324 void ImageBuffer::putByteArray(Multiply multiplied, const unsigned char* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint ) 331 void ImageBuffer::putByteArray(Multiply multiplied, const unsigned char* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint )
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 385 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
379 386
380 Vector<unsigned char> result; 387 Vector<unsigned char> result;
381 if (!encodeImage(mimeType, quality, &result)) 388 if (!encodeImage(mimeType, quality, &result))
382 return "data:,"; 389 return "data:,";
383 390
384 return "data:" + mimeType + ";base64," + base64Encode(result); 391 return "data:" + mimeType + ";base64," + base64Encode(result);
385 } 392 }
386 393
387 } // namespace blink 394 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698