OLD | NEW |
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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 285 |
286 bool ImageBuffer::getImageData(Multiply multiplied, const IntRect& rect, WTF::Ar
rayBufferContents& contents) const | 286 bool ImageBuffer::getImageData(Multiply multiplied, const IntRect& rect, WTF::Ar
rayBufferContents& contents) const |
287 { | 287 { |
288 Checked<int, RecordOverflow> dataSize = 4; | 288 Checked<int, RecordOverflow> dataSize = 4; |
289 dataSize *= rect.width(); | 289 dataSize *= rect.width(); |
290 dataSize *= rect.height(); | 290 dataSize *= rect.height(); |
291 if (dataSize.hasOverflowed()) | 291 if (dataSize.hasOverflowed()) |
292 return false; | 292 return false; |
293 | 293 |
294 if (!isSurfaceValid()) { | 294 if (!isSurfaceValid()) { |
295 WTF::ArrayBufferContents result(rect.width() * rect.height(), 4, WTF::Ar
rayBufferContents::NotShared, WTF::ArrayBufferContents::ZeroInitialize); | 295 size_t allocSizeInBytes = rect.width() * rect.height() * 4; |
| 296 void* data; |
| 297 WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes, WTF::Ar
rayBufferContents::ZeroInitialize, data); |
| 298 if (!data) |
| 299 return false; |
| 300 WTF::ArrayBufferContents result(data, allocSizeInBytes, WTF::ArrayBuffer
Contents::NotShared); |
296 result.transfer(contents); | 301 result.transfer(contents); |
297 return true; | 302 return true; |
298 } | 303 } |
299 | 304 |
300 ASSERT(canvas()); | 305 ASSERT(canvas()); |
301 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot(PreferNoAcceleration,
SnapshotReasonGetImageData); | 306 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot(PreferNoAcceleration,
SnapshotReasonGetImageData); |
302 if (!snapshot) | 307 if (!snapshot) |
303 return false; | 308 return false; |
304 | 309 |
305 const bool mayHaveStrayArea = | 310 const bool mayHaveStrayArea = |
306 m_surface->isAccelerated() // GPU readback may fail silently | 311 m_surface->isAccelerated() // GPU readback may fail silently |
307 || rect.x() < 0 | 312 || rect.x() < 0 |
308 || rect.y() < 0 | 313 || rect.y() < 0 |
309 || rect.maxX() > m_surface->size().width() | 314 || rect.maxX() > m_surface->size().width() |
310 || rect.maxY() > m_surface->size().height(); | 315 || rect.maxY() > m_surface->size().height(); |
311 WTF::ArrayBufferContents result( | 316 size_t allocSizeInBytes = rect.width() * rect.height() * 4; |
312 rect.width() * rect.height(), 4, | 317 void* data; |
313 WTF::ArrayBufferContents::NotShared, | 318 WTF::ArrayBufferContents::InitializationPolicy initializationPolicy = mayHav
eStrayArea ? WTF::ArrayBufferContents::ZeroInitialize : WTF::ArrayBufferContents
::DontInitialize; |
314 mayHaveStrayArea | 319 WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes, initializat
ionPolicy, data); |
315 ? WTF::ArrayBufferContents::ZeroInitialize | 320 if (!data) |
316 : WTF::ArrayBufferContents::DontInitialize); | 321 return false; |
| 322 WTF::ArrayBufferContents result(data, allocSizeInBytes, WTF::ArrayBufferCont
ents::NotShared); |
317 | 323 |
318 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType
: kUnpremul_SkAlphaType; | 324 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType
: kUnpremul_SkAlphaType; |
319 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888
_SkColorType, alphaType); | 325 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888
_SkColorType, alphaType); |
320 | 326 |
321 snapshot->readPixels(info, result.data(), 4 * rect.width(), rect.x(), rect.y
()); | 327 snapshot->readPixels(info, result.data(), 4 * rect.width(), rect.x(), rect.y
()); |
322 result.transfer(contents); | 328 result.transfer(contents); |
323 return true; | 329 return true; |
324 } | 330 } |
325 | 331 |
326 void ImageBuffer::putByteArray(Multiply multiplied, const unsigned char* source,
const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint
) | 332 void ImageBuffer::putByteArray(Multiply multiplied, const unsigned char* source,
const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint
) |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 405 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
400 | 406 |
401 Vector<unsigned char> result; | 407 Vector<unsigned char> result; |
402 if (!encodeImage(mimeType, quality, &result)) | 408 if (!encodeImage(mimeType, quality, &result)) |
403 return "data:,"; | 409 return "data:,"; |
404 | 410 |
405 return "data:" + mimeType + ";base64," + base64Encode(result); | 411 return "data:" + mimeType + ";base64," + base64Encode(result); |
406 } | 412 } |
407 | 413 |
408 } // namespace blink | 414 } // namespace blink |
OLD | NEW |