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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp

Issue 1814563002: wtf/CheckedArithmetic.h delegates to base/numerics/safe_math.h. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 278
279 void ImageBuffer::flushGpu(FlushReason reason) 279 void ImageBuffer::flushGpu(FlushReason reason)
280 { 280 {
281 if (m_surface->canvas()) { 281 if (m_surface->canvas()) {
282 m_surface->flushGpu(reason); 282 m_surface->flushGpu(reason);
283 } 283 }
284 } 284 }
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 WTF::CheckedNumeric<int> 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.IsValid())
292 return false; 292 return false;
293 293
294 if (!isSurfaceValid()) { 294 if (!isSurfaceValid()) {
295 size_t allocSizeInBytes = rect.width() * rect.height() * 4; 295 size_t allocSizeInBytes = rect.width() * rect.height() * 4;
296 void* data; 296 void* data;
297 WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes, WTF::Ar rayBufferContents::ZeroInitialize, data); 297 WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes, WTF::Ar rayBufferContents::ZeroInitialize, data);
298 if (!data) 298 if (!data)
299 return false; 299 return false;
300 WTF::ArrayBufferContents result(data, allocSizeInBytes, WTF::ArrayBuffer Contents::NotShared); 300 WTF::ArrayBufferContents result(data, allocSizeInBytes, WTF::ArrayBuffer Contents::NotShared);
301 result.transfer(contents); 301 result.transfer(contents);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; 356 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
357 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);
358 m_surface->writePixels(info, srcAddr, srcBytesPerRow, destX, destY); 358 m_surface->writePixels(info, srcAddr, srcBytesPerRow, destX, destY);
359 } 359 }
360 360
361 void ImageBuffer::updateGPUMemoryUsage() const 361 void ImageBuffer::updateGPUMemoryUsage() const
362 { 362 {
363 if (this->isAccelerated()) { 363 if (this->isAccelerated()) {
364 // 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.
365 int gpuBufferCount = 2; 365 int gpuBufferCount = 2;
366 Checked<intptr_t, RecordOverflow> checkedGPUUsage = 4 * gpuBufferCount; 366 WTF::CheckedNumeric<intptr_t> checkedGPUUsage = 4 * gpuBufferCount;
367 checkedGPUUsage *= this->size().width(); 367 checkedGPUUsage *= this->size().width();
368 checkedGPUUsage *= this->size().height(); 368 checkedGPUUsage *= this->size().height();
369 intptr_t gpuMemoryUsage; 369 intptr_t gpuMemoryUsage = checkedGPUUsage.ValueOrDefault(std::numeric_li mits<intptr_t>::max());
370 if (checkedGPUUsage.safeGet(gpuMemoryUsage) == CheckedState::DidOverflow )
371 gpuMemoryUsage = std::numeric_limits<intptr_t>::max();
372 370
373 s_globalGPUMemoryUsage += (gpuMemoryUsage - m_gpuMemoryUsage); 371 s_globalGPUMemoryUsage += (gpuMemoryUsage - m_gpuMemoryUsage);
374 m_gpuMemoryUsage = gpuMemoryUsage; 372 m_gpuMemoryUsage = gpuMemoryUsage;
375 } else if (m_gpuMemoryUsage > 0) { 373 } else if (m_gpuMemoryUsage > 0) {
376 // In case of switching from accelerated to non-accelerated mode, 374 // In case of switching from accelerated to non-accelerated mode,
377 // the GPU memory usage needs to be updated too. 375 // the GPU memory usage needs to be updated too.
378 s_globalGPUMemoryUsage -= m_gpuMemoryUsage; 376 s_globalGPUMemoryUsage -= m_gpuMemoryUsage;
379 m_gpuMemoryUsage = 0; 377 m_gpuMemoryUsage = 0;
380 } 378 }
381 } 379 }
(...skipping 23 matching lines...) Expand all
405 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 403 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
406 404
407 Vector<unsigned char> result; 405 Vector<unsigned char> result;
408 if (!encodeImage(mimeType, quality, &result)) 406 if (!encodeImage(mimeType, quality, &result))
409 return "data:,"; 407 return "data:,";
410 408
411 return "data:" + mimeType + ";base64," + base64Encode(result); 409 return "data:" + mimeType + ";base64," + base64Encode(result);
412 } 410 }
413 411
414 } // namespace blink 412 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698