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: Source/platform/graphics/ImageBuffer.cpp

Issue 1186863005: Add a ref-counted data holder to ArrayBufferContents (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: type in ArrayBuffer::shareContentsWith Created 5 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) 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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 274
275 bool ImageBuffer::getImageData(Multiply multiplied, const IntRect& rect, WTF::Ar rayBufferContents& contents) const 275 bool ImageBuffer::getImageData(Multiply multiplied, const IntRect& rect, WTF::Ar rayBufferContents& contents) const
276 { 276 {
277 Checked<int, RecordOverflow> dataSize = 4; 277 Checked<int, RecordOverflow> dataSize = 4;
278 dataSize *= rect.width(); 278 dataSize *= rect.width();
279 dataSize *= rect.height(); 279 dataSize *= rect.height();
280 if (dataSize.hasOverflowed()) 280 if (dataSize.hasOverflowed())
281 return false; 281 return false;
282 282
283 if (!isSurfaceValid()) { 283 if (!isSurfaceValid()) {
284 WTF::ArrayBufferContents result(rect.width() * rect.height(), 4, WTF::Ar rayBufferContents::ZeroInitialize); 284 WTF::ArrayBufferContents result(rect.width() * rect.height(), 4, WTF::Ar rayBufferContents::NotShared, WTF::ArrayBufferContents::ZeroInitialize);
285 result.transfer(contents); 285 result.transfer(contents);
286 return true; 286 return true;
287 } 287 }
288 288
289 const bool hasStrayArea = 289 const bool hasStrayArea =
290 rect.x() < 0 290 rect.x() < 0
291 || rect.y() < 0 291 || rect.y() < 0
292 || rect.maxX() > m_surface->size().width() 292 || rect.maxX() > m_surface->size().width()
293 || rect.maxY() > m_surface->size().height(); 293 || rect.maxY() > m_surface->size().height();
294 WTF::ArrayBufferContents result( 294 WTF::ArrayBufferContents result(
295 rect.width() * rect.height(), 4, 295 rect.width() * rect.height(), 4,
296 WTF::ArrayBufferContents::NotShared,
296 hasStrayArea 297 hasStrayArea
297 ? WTF::ArrayBufferContents::ZeroInitialize 298 ? WTF::ArrayBufferContents::ZeroInitialize
298 : WTF::ArrayBufferContents::DontInitialize); 299 : WTF::ArrayBufferContents::DontInitialize);
299 300
300 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; 301 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
301 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888 _SkColorType, alphaType); 302 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888 _SkColorType, alphaType);
302 303
303 m_surface->willAccessPixels(); 304 m_surface->willAccessPixels();
304 ASSERT(canvas()); 305 ASSERT(canvas());
305 canvas()->readPixels(info, result.data(), 4 * rect.width(), rect.x(), rect.y ()); 306 canvas()->readPixels(info, result.data(), 4 * rect.width(), rect.x(), rect.y ());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 382 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
382 383
383 Vector<char> encodedImage; 384 Vector<char> encodedImage;
384 if (!encodeImage(*this, mimeType, quality, &encodedImage)) 385 if (!encodeImage(*this, mimeType, quality, &encodedImage))
385 return "data:,"; 386 return "data:,";
386 387
387 return "data:" + mimeType + ";base64," + base64Encode(encodedImage); 388 return "data:" + mimeType + ";base64," + base64Encode(encodedImage);
388 } 389 }
389 390
390 } // namespace blink 391 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698