| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 280 |
| 280 bool ImageBuffer::getImageData(Multiply multiplied, const IntRect& rect, WTF::Ar
rayBufferContents& contents) const | 281 bool ImageBuffer::getImageData(Multiply multiplied, const IntRect& rect, WTF::Ar
rayBufferContents& contents) const |
| 281 { | 282 { |
| 282 Checked<int, RecordOverflow> dataSize = 4; | 283 Checked<int, RecordOverflow> dataSize = 4; |
| 283 dataSize *= rect.width(); | 284 dataSize *= rect.width(); |
| 284 dataSize *= rect.height(); | 285 dataSize *= rect.height(); |
| 285 if (dataSize.hasOverflowed()) | 286 if (dataSize.hasOverflowed()) |
| 286 return false; | 287 return false; |
| 287 | 288 |
| 288 if (!isSurfaceValid()) { | 289 if (!isSurfaceValid()) { |
| 289 WTF::ArrayBufferContents result(rect.width() * rect.height(), 4, WTF::Ar
rayBufferContents::NotShared, WTF::ArrayBufferContents::ZeroInitialize); | 290 WTF::ArrayBufferContents result(rect.width() * rect.height(), 4, WTF::Ar
rayBufferContents::NotShared, WTF::ArrayBufferContents::ZeroInitialize, WTF::Arr
ayBufferContents::NullDataIfOutOfMemory); |
| 291 if (!result.data()) |
| 292 return false; |
| 290 result.transfer(contents); | 293 result.transfer(contents); |
| 291 return true; | 294 return true; |
| 292 } | 295 } |
| 293 | 296 |
| 294 ASSERT(canvas()); | 297 ASSERT(canvas()); |
| 295 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot(PreferNoAcceleration)
; | 298 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot(PreferNoAcceleration)
; |
| 296 if (!snapshot) | 299 if (!snapshot) |
| 297 return false; | 300 return false; |
| 298 | 301 |
| 299 const bool mayHaveStrayArea = | 302 const bool mayHaveStrayArea = |
| 300 m_surface->isAccelerated() // GPU readback may fail silently | 303 m_surface->isAccelerated() // GPU readback may fail silently |
| 301 || rect.x() < 0 | 304 || rect.x() < 0 |
| 302 || rect.y() < 0 | 305 || rect.y() < 0 |
| 303 || rect.maxX() > m_surface->size().width() | 306 || rect.maxX() > m_surface->size().width() |
| 304 || rect.maxY() > m_surface->size().height(); | 307 || rect.maxY() > m_surface->size().height(); |
| 305 WTF::ArrayBufferContents result( | 308 WTF::ArrayBufferContents result( |
| 306 rect.width() * rect.height(), 4, | 309 rect.width() * rect.height(), 4, |
| 307 WTF::ArrayBufferContents::NotShared, | 310 WTF::ArrayBufferContents::NotShared, |
| 308 mayHaveStrayArea | 311 mayHaveStrayArea |
| 309 ? WTF::ArrayBufferContents::ZeroInitialize | 312 ? WTF::ArrayBufferContents::ZeroInitialize |
| 310 : WTF::ArrayBufferContents::DontInitialize); | 313 : WTF::ArrayBufferContents::DontInitialize, |
| 314 WTF::ArrayBufferContents::NullDataIfOutOfMemory); |
| 315 |
| 316 if (!result.data()) |
| 317 return false; |
| 311 | 318 |
| 312 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType
: kUnpremul_SkAlphaType; | 319 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType
: kUnpremul_SkAlphaType; |
| 313 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888
_SkColorType, alphaType); | 320 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888
_SkColorType, alphaType); |
| 314 | 321 |
| 315 snapshot->readPixels(info, result.data(), 4 * rect.width(), rect.x(), rect.y
()); | 322 snapshot->readPixels(info, result.data(), 4 * rect.width(), rect.x(), rect.y
()); |
| 316 result.transfer(contents); | 323 result.transfer(contents); |
| 317 return true; | 324 return true; |
| 318 } | 325 } |
| 319 | 326 |
| 320 void ImageBuffer::putByteArray(Multiply multiplied, const unsigned char* source,
const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint
) | 327 void ImageBuffer::putByteArray(Multiply multiplied, const unsigned char* source,
const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint
) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 383 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
| 377 | 384 |
| 378 Vector<char> encodedImage; | 385 Vector<char> encodedImage; |
| 379 if (!encodeImage(mimeType, quality, &encodedImage)) | 386 if (!encodeImage(mimeType, quality, &encodedImage)) |
| 380 return "data:,"; | 387 return "data:,"; |
| 381 | 388 |
| 382 return "data:" + mimeType + ";base64," + base64Encode(encodedImage); | 389 return "data:" + mimeType + ";base64," + base64Encode(encodedImage); |
| 383 } | 390 } |
| 384 | 391 |
| 385 } // namespace blink | 392 } // namespace blink |
| OLD | NEW |