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

Unified Diff: content/common/gpu/client/gpu_memory_buffer_impl.cc

Issue 806653006: Update GPU memory buffers to use StrideInBytes internally. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use CheckedNumeric Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/client/gpu_memory_buffer_impl.cc
diff --git a/content/common/gpu/client/gpu_memory_buffer_impl.cc b/content/common/gpu/client/gpu_memory_buffer_impl.cc
index d3c08bdb1a09b0d1256c297148cd190d2fae5690..befde5e6837d402ccfc75337a6e0822131b0b401 100644
--- a/content/common/gpu/client/gpu_memory_buffer_impl.cc
+++ b/content/common/gpu/client/gpu_memory_buffer_impl.cc
@@ -5,6 +5,7 @@
#include "content/common/gpu/client/gpu_memory_buffer_impl.h"
#include "base/logging.h"
+#include "base/numerics/safe_math.h"
#include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h"
#include "ui/gl/gl_bindings.h"
@@ -76,16 +77,26 @@ GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer(
}
// static
-size_t GpuMemoryBufferImpl::BytesPerPixel(Format format) {
+bool GpuMemoryBufferImpl::StrideInBytes(size_t width,
+ Format format,
+ size_t* stride_in_bytes) {
+ base::CheckedNumeric<size_t> w = width;
reveman 2015/01/13 16:04:40 nit: maybe s/w/s/ for stride
switch (format) {
case RGBA_8888:
case RGBX_8888:
case BGRA_8888:
- return 4;
+ w *= 4;
+ break;
+ default:
reveman 2015/01/13 16:04:40 nit: please avoid having a default case as that al
+ NOTREACHED();
+ return false;
}
- NOTREACHED();
- return 0;
+ if (!w.IsValid())
+ return false;
+
+ *stride_in_bytes = w.ValueOrDie();
+ return true;
}
gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const {

Powered by Google App Engine
This is Rietveld 408576698