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