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

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

Issue 2719883004: Adds support for ArrayBufferContents with external buffer. (Closed)
Patch Set: passes unique_ptr Created 3 years, 9 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) 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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 if (m_surface->colorSpace()) 339 if (m_surface->colorSpace())
340 bytesPerPixel = SkColorTypeBytesPerPixel(m_surface->colorType()); 340 bytesPerPixel = SkColorTypeBytesPerPixel(m_surface->colorType());
341 CheckedNumeric<int> dataSize = bytesPerPixel; 341 CheckedNumeric<int> dataSize = bytesPerPixel;
342 dataSize *= rect.width(); 342 dataSize *= rect.width();
343 dataSize *= rect.height(); 343 dataSize *= rect.height();
344 if (!dataSize.IsValid()) 344 if (!dataSize.IsValid())
345 return false; 345 return false;
346 346
347 if (!isSurfaceValid()) { 347 if (!isSurfaceValid()) {
348 size_t allocSizeInBytes = rect.width() * rect.height() * bytesPerPixel; 348 size_t allocSizeInBytes = rect.width() * rect.height() * bytesPerPixel;
349 void* data; 349 WTF::ArrayBufferContents::ScopedData data(
350 WTF::ArrayBufferContents::allocateMemoryOrNull( 350 WTF::ArrayBufferContents::allocateMemoryOrNull(
351 allocSizeInBytes, WTF::ArrayBufferContents::ZeroInitialize, data); 351 allocSizeInBytes, WTF::ArrayBufferContents::ZeroInitialize),
352 WTF::ArrayBufferContents::freeMemory);
352 if (!data) 353 if (!data)
353 return false; 354 return false;
354 WTF::ArrayBufferContents result(data, allocSizeInBytes, 355 WTF::ArrayBufferContents result(std::move(data), allocSizeInBytes,
355 WTF::ArrayBufferContents::NotShared); 356 WTF::ArrayBufferContents::NotShared);
356 result.transfer(contents); 357 result.transfer(contents);
357 return true; 358 return true;
358 } 359 }
359 360
360 DCHECK(canvas()); 361 DCHECK(canvas());
361 362
362 if (ExpensiveCanvasHeuristicParameters::GetImageDataForcesNoAcceleration && 363 if (ExpensiveCanvasHeuristicParameters::GetImageDataForcesNoAcceleration &&
363 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled()) { 364 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled()) {
364 const_cast<ImageBuffer*>(this)->disableAcceleration(); 365 const_cast<ImageBuffer*>(this)->disableAcceleration();
365 } 366 }
366 367
367 sk_sp<SkImage> snapshot = m_surface->newImageSnapshot( 368 sk_sp<SkImage> snapshot = m_surface->newImageSnapshot(
368 PreferNoAcceleration, SnapshotReasonGetImageData); 369 PreferNoAcceleration, SnapshotReasonGetImageData);
369 if (!snapshot) 370 if (!snapshot)
370 return false; 371 return false;
371 372
372 const bool mayHaveStrayArea = 373 const bool mayHaveStrayArea =
373 m_surface->isAccelerated() // GPU readback may fail silently 374 m_surface->isAccelerated() // GPU readback may fail silently
374 || rect.x() < 0 || rect.y() < 0 || 375 || rect.x() < 0 || rect.y() < 0 ||
375 rect.maxX() > m_surface->size().width() || 376 rect.maxX() > m_surface->size().width() ||
376 rect.maxY() > m_surface->size().height(); 377 rect.maxY() > m_surface->size().height();
377 size_t allocSizeInBytes = rect.width() * rect.height() * bytesPerPixel; 378 size_t allocSizeInBytes = rect.width() * rect.height() * bytesPerPixel;
378 void* data;
379 WTF::ArrayBufferContents::InitializationPolicy initializationPolicy = 379 WTF::ArrayBufferContents::InitializationPolicy initializationPolicy =
380 mayHaveStrayArea ? WTF::ArrayBufferContents::ZeroInitialize 380 mayHaveStrayArea ? WTF::ArrayBufferContents::ZeroInitialize
381 : WTF::ArrayBufferContents::DontInitialize; 381 : WTF::ArrayBufferContents::DontInitialize;
382 WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes, 382 WTF::ArrayBufferContents::ScopedData data(
383 initializationPolicy, data); 383 WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes,
384 initializationPolicy),
385 WTF::ArrayBufferContents::freeMemory);
384 if (!data) 386 if (!data)
385 return false; 387 return false;
386 WTF::ArrayBufferContents result(data, allocSizeInBytes, 388 WTF::ArrayBufferContents result(std::move(data), allocSizeInBytes,
387 WTF::ArrayBufferContents::NotShared); 389 WTF::ArrayBufferContents::NotShared);
388 390
389 // Skia does not support unpremultiplied read with an F16 to 8888 conversion 391 // Skia does not support unpremultiplied read with an F16 to 8888 conversion
390 bool useF16Workaround = m_surface->colorType() == kRGBA_F16_SkColorType; 392 bool useF16Workaround = m_surface->colorType() == kRGBA_F16_SkColorType;
391 393
392 SkAlphaType alphaType = (multiplied == Premultiplied || useF16Workaround) 394 SkAlphaType alphaType = (multiplied == Premultiplied || useF16Workaround)
393 ? kPremul_SkAlphaType 395 ? kPremul_SkAlphaType
394 : kUnpremul_SkAlphaType; 396 : kUnpremul_SkAlphaType;
395 // The workaround path use a canvas draw under the hood, which can only 397 // The workaround path use a canvas draw under the hood, which can only
396 // use N32 at this time. 398 // use N32 at this time.
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 DCHECK(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 610 DCHECK(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
609 611
610 Vector<unsigned char> result; 612 Vector<unsigned char> result;
611 if (!encodeImage(mimeType, quality, &result)) 613 if (!encodeImage(mimeType, quality, &result))
612 return "data:,"; 614 return "data:,";
613 615
614 return "data:" + mimeType + ";base64," + base64Encode(result); 616 return "data:" + mimeType + ";base64," + base64Encode(result);
615 } 617 }
616 618
617 } // namespace blink 619 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698