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

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: 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 269
270 bool ImageBuffer::getImageData(Multiply multiplied, const IntRect& rect, WTF::Ar rayBufferContents& contents) const 270 bool ImageBuffer::getImageData(Multiply multiplied, const IntRect& rect, WTF::Ar rayBufferContents& contents) const
271 { 271 {
272 Checked<int, RecordOverflow> dataSize = 4; 272 Checked<int, RecordOverflow> dataSize = 4;
273 dataSize *= rect.width(); 273 dataSize *= rect.width();
274 dataSize *= rect.height(); 274 dataSize *= rect.height();
275 if (dataSize.hasOverflowed()) 275 if (dataSize.hasOverflowed())
276 return false; 276 return false;
277 277
278 if (!isSurfaceValid()) { 278 if (!isSurfaceValid()) {
279 WTF::ArrayBufferContents result(rect.width() * rect.height(), 4, WTF::Ar rayBufferContents::ZeroInitialize); 279 WTF::ArrayBufferContents result(rect.width() * rect.height(), 4, WTF::Ar rayBufferContents::NotShared, WTF::ArrayBufferContents::ZeroInitialize);
280 result.transfer(contents); 280 result.transfer(contents);
281 return true; 281 return true;
282 } 282 }
283 283
284 const bool hasStrayArea = 284 const bool hasStrayArea =
285 rect.x() < 0 285 rect.x() < 0
286 || rect.y() < 0 286 || rect.y() < 0
287 || rect.maxX() > m_surface->size().width() 287 || rect.maxX() > m_surface->size().width()
288 || rect.maxY() > m_surface->size().height(); 288 || rect.maxY() > m_surface->size().height();
289 WTF::ArrayBufferContents result( 289 WTF::ArrayBufferContents result(
290 rect.width() * rect.height(), 4, 290 rect.width() * rect.height(), 4,
291 WTF::ArrayBufferContents::NotShared,
291 hasStrayArea 292 hasStrayArea
292 ? WTF::ArrayBufferContents::ZeroInitialize 293 ? WTF::ArrayBufferContents::ZeroInitialize
293 : WTF::ArrayBufferContents::DontInitialize); 294 : WTF::ArrayBufferContents::DontInitialize);
294 295
295 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; 296 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
296 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888 _SkColorType, alphaType); 297 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888 _SkColorType, alphaType);
297 298
298 m_surface->willAccessPixels(); 299 m_surface->willAccessPixels();
299 ASSERT(canvas()); 300 ASSERT(canvas());
300 canvas()->readPixels(info, result.data(), 4 * rect.width(), rect.x(), rect.y ()); 301 canvas()->readPixels(info, result.data(), 4 * rect.width(), rect.x(), rect.y ());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 377 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
377 378
378 Vector<char> encodedImage; 379 Vector<char> encodedImage;
379 if (!encodeImage(*this, mimeType, quality, &encodedImage)) 380 if (!encodeImage(*this, mimeType, quality, &encodedImage))
380 return "data:,"; 381 return "data:,";
381 382
382 return "data:" + mimeType + ";base64," + base64Encode(encodedImage); 383 return "data:" + mimeType + ";base64," + base64Encode(encodedImage);
383 } 384 }
384 385
385 } // namespace blink 386 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698