| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #include "platform/image-encoders/skia/WEBPImageEncoder.h" | 48 #include "platform/image-encoders/skia/WEBPImageEncoder.h" |
| 49 #include "public/platform/Platform.h" | 49 #include "public/platform/Platform.h" |
| 50 #include "public/platform/WebExternalTextureMailbox.h" | 50 #include "public/platform/WebExternalTextureMailbox.h" |
| 51 #include "public/platform/WebGraphicsContext3D.h" | 51 #include "public/platform/WebGraphicsContext3D.h" |
| 52 #include "public/platform/WebGraphicsContext3DProvider.h" | 52 #include "public/platform/WebGraphicsContext3DProvider.h" |
| 53 #include "skia/ext/texture_handle.h" | 53 #include "skia/ext/texture_handle.h" |
| 54 #include "third_party/skia/include/core/SkPicture.h" | 54 #include "third_party/skia/include/core/SkPicture.h" |
| 55 #include "third_party/skia/include/gpu/GrContext.h" | 55 #include "third_party/skia/include/gpu/GrContext.h" |
| 56 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" | 56 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" |
| 57 #include "wtf/ArrayBufferContents.h" | 57 #include "wtf/ArrayBufferContents.h" |
| 58 #include "wtf/CheckedNumeric.h" | |
| 59 #include "wtf/MathExtras.h" | 58 #include "wtf/MathExtras.h" |
| 60 #include "wtf/Vector.h" | 59 #include "wtf/Vector.h" |
| 61 #include "wtf/text/Base64.h" | 60 #include "wtf/text/Base64.h" |
| 62 #include "wtf/text/WTFString.h" | 61 #include "wtf/text/WTFString.h" |
| 63 | 62 |
| 64 namespace blink { | 63 namespace blink { |
| 65 | 64 |
| 66 PassOwnPtr<ImageBuffer> ImageBuffer::create(PassOwnPtr<ImageBufferSurface> surfa
ce) | 65 PassOwnPtr<ImageBuffer> ImageBuffer::create(PassOwnPtr<ImageBufferSurface> surfa
ce) |
| 67 { | 66 { |
| 68 if (!surface->isValid()) | 67 if (!surface->isValid()) |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 277 |
| 279 void ImageBuffer::flushGpu(FlushReason reason) | 278 void ImageBuffer::flushGpu(FlushReason reason) |
| 280 { | 279 { |
| 281 if (m_surface->canvas()) { | 280 if (m_surface->canvas()) { |
| 282 m_surface->flushGpu(reason); | 281 m_surface->flushGpu(reason); |
| 283 } | 282 } |
| 284 } | 283 } |
| 285 | 284 |
| 286 bool ImageBuffer::getImageData(Multiply multiplied, const IntRect& rect, WTF::Ar
rayBufferContents& contents) const | 285 bool ImageBuffer::getImageData(Multiply multiplied, const IntRect& rect, WTF::Ar
rayBufferContents& contents) const |
| 287 { | 286 { |
| 288 CheckedNumeric<int> dataSize = 4; | 287 Checked<int, RecordOverflow> dataSize = 4; |
| 289 dataSize *= rect.width(); | 288 dataSize *= rect.width(); |
| 290 dataSize *= rect.height(); | 289 dataSize *= rect.height(); |
| 291 if (!dataSize.IsValid()) | 290 if (dataSize.hasOverflowed()) |
| 292 return false; | 291 return false; |
| 293 | 292 |
| 294 if (!isSurfaceValid()) { | 293 if (!isSurfaceValid()) { |
| 295 size_t allocSizeInBytes = rect.width() * rect.height() * 4; | 294 size_t allocSizeInBytes = rect.width() * rect.height() * 4; |
| 296 void* data; | 295 void* data; |
| 297 WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes, WTF::Ar
rayBufferContents::ZeroInitialize, data); | 296 WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes, WTF::Ar
rayBufferContents::ZeroInitialize, data); |
| 298 if (!data) | 297 if (!data) |
| 299 return false; | 298 return false; |
| 300 WTF::ArrayBufferContents result(data, allocSizeInBytes, WTF::ArrayBuffer
Contents::NotShared); | 299 WTF::ArrayBufferContents result(data, allocSizeInBytes, WTF::ArrayBuffer
Contents::NotShared); |
| 301 result.transfer(contents); | 300 result.transfer(contents); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType
: kUnpremul_SkAlphaType; | 355 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType
: kUnpremul_SkAlphaType; |
| 357 SkImageInfo info = SkImageInfo::Make(sourceRect.width(), sourceRect.height()
, kRGBA_8888_SkColorType, alphaType); | 356 SkImageInfo info = SkImageInfo::Make(sourceRect.width(), sourceRect.height()
, kRGBA_8888_SkColorType, alphaType); |
| 358 m_surface->writePixels(info, srcAddr, srcBytesPerRow, destX, destY); | 357 m_surface->writePixels(info, srcAddr, srcBytesPerRow, destX, destY); |
| 359 } | 358 } |
| 360 | 359 |
| 361 void ImageBuffer::updateGPUMemoryUsage() const | 360 void ImageBuffer::updateGPUMemoryUsage() const |
| 362 { | 361 { |
| 363 if (this->isAccelerated()) { | 362 if (this->isAccelerated()) { |
| 364 // If image buffer is accelerated, we should keep track of GPU memory us
age. | 363 // If image buffer is accelerated, we should keep track of GPU memory us
age. |
| 365 int gpuBufferCount = 2; | 364 int gpuBufferCount = 2; |
| 366 CheckedNumeric<intptr_t> checkedGPUUsage = 4 * gpuBufferCount; | 365 Checked<intptr_t, RecordOverflow> checkedGPUUsage = 4 * gpuBufferCount; |
| 367 checkedGPUUsage *= this->size().width(); | 366 checkedGPUUsage *= this->size().width(); |
| 368 checkedGPUUsage *= this->size().height(); | 367 checkedGPUUsage *= this->size().height(); |
| 369 intptr_t gpuMemoryUsage = checkedGPUUsage.ValueOrDefault(std::numeric_li
mits<intptr_t>::max()); | 368 intptr_t gpuMemoryUsage; |
| 369 if (checkedGPUUsage.safeGet(gpuMemoryUsage) == CheckedState::DidOverflow
) |
| 370 gpuMemoryUsage = std::numeric_limits<intptr_t>::max(); |
| 370 | 371 |
| 371 s_globalGPUMemoryUsage += (gpuMemoryUsage - m_gpuMemoryUsage); | 372 s_globalGPUMemoryUsage += (gpuMemoryUsage - m_gpuMemoryUsage); |
| 372 m_gpuMemoryUsage = gpuMemoryUsage; | 373 m_gpuMemoryUsage = gpuMemoryUsage; |
| 373 } else if (m_gpuMemoryUsage > 0) { | 374 } else if (m_gpuMemoryUsage > 0) { |
| 374 // In case of switching from accelerated to non-accelerated mode, | 375 // In case of switching from accelerated to non-accelerated mode, |
| 375 // the GPU memory usage needs to be updated too. | 376 // the GPU memory usage needs to be updated too. |
| 376 s_globalGPUMemoryUsage -= m_gpuMemoryUsage; | 377 s_globalGPUMemoryUsage -= m_gpuMemoryUsage; |
| 377 m_gpuMemoryUsage = 0; | 378 m_gpuMemoryUsage = 0; |
| 378 } | 379 } |
| 379 } | 380 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 403 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 404 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
| 404 | 405 |
| 405 Vector<unsigned char> result; | 406 Vector<unsigned char> result; |
| 406 if (!encodeImage(mimeType, quality, &result)) | 407 if (!encodeImage(mimeType, quality, &result)) |
| 407 return "data:,"; | 408 return "data:,"; |
| 408 | 409 |
| 409 return "data:" + mimeType + ";base64," + base64Encode(result); | 410 return "data:" + mimeType + ";base64," + base64Encode(result); |
| 410 } | 411 } |
| 411 | 412 |
| 412 } // namespace blink | 413 } // namespace blink |
| OLD | NEW |