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

Unified Diff: services/ui/public/cpp/mojo_gpu_memory_buffer.cc

Issue 2277293002: services/ui: Use the correct offset and stride in MojoGpuMemoryBuffer. (Closed)
Patch Set: Fix build error. Created 4 years, 4 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: services/ui/public/cpp/mojo_gpu_memory_buffer.cc
diff --git a/services/ui/public/cpp/mojo_gpu_memory_buffer.cc b/services/ui/public/cpp/mojo_gpu_memory_buffer.cc
index 2b559a2d775d086cd27b82be37914427aa197f32..36b432711a6d2c8e0c15bbfbeeee243d1dee0ef0 100644
--- a/services/ui/public/cpp/mojo_gpu_memory_buffer.cc
+++ b/services/ui/public/cpp/mojo_gpu_memory_buffer.cc
@@ -20,9 +20,13 @@ namespace ui {
MojoGpuMemoryBufferImpl::MojoGpuMemoryBufferImpl(
const gfx::Size& size,
gfx::BufferFormat format,
- std::unique_ptr<base::SharedMemory> shared_memory)
+ std::unique_ptr<base::SharedMemory> shared_memory,
+ size_t offset,
+ int stride)
: GpuMemoryBufferImpl(gfx::GenericSharedMemoryId(0), size, format),
- shared_memory_(std::move(shared_memory)) {}
+ shared_memory_(std::move(shared_memory)),
+ offset_(offset),
+ stride_(stride) {}
// TODO(rjkroege): Support running a destructor callback as necessary.
MojoGpuMemoryBufferImpl::~MojoGpuMemoryBufferImpl() {}
@@ -50,8 +54,10 @@ std::unique_ptr<gfx::GpuMemoryBuffer> MojoGpuMemoryBufferImpl::Create(
auto shared_memory =
base::MakeUnique<base::SharedMemory>(platform_handle, readonly);
- return base::MakeUnique<MojoGpuMemoryBufferImpl>(
- size, format, std::move(shared_memory));
+ const int stride = base::checked_cast<int>(
+ gfx::RowSizeForBufferFormat(size.width(), format, 0));
+ return base::WrapUnique(new MojoGpuMemoryBufferImpl(
+ size, format, std::move(shared_memory), 0, stride));
}
// static
@@ -65,8 +71,8 @@ std::unique_ptr<gfx::GpuMemoryBuffer> MojoGpuMemoryBufferImpl::CreateFromHandle(
const bool readonly = false;
auto shared_memory =
base::MakeUnique<base::SharedMemory>(handle.handle, readonly);
- return base::MakeUnique<MojoGpuMemoryBufferImpl>(
- size, format, std::move(shared_memory));
+ return base::WrapUnique(new MojoGpuMemoryBufferImpl(
+ size, format, std::move(shared_memory), handle.offset, handle.stride));
}
MojoGpuMemoryBufferImpl* MojoGpuMemoryBufferImpl::FromClientBuffer(
@@ -80,7 +86,11 @@ const unsigned char* MojoGpuMemoryBufferImpl::GetMemory() const {
bool MojoGpuMemoryBufferImpl::Map() {
DCHECK(!mapped_);
- if (!shared_memory_->Map(gfx::BufferSizeForBufferFormat(size_, format_)))
+ DCHECK_EQ(static_cast<size_t>(stride_),
+ gfx::RowSizeForBufferFormat(size_.width(), format_, 0));
+ const size_t buffer_size = gfx::BufferSizeForBufferFormat(size_, format_);
+ const size_t map_size = offset_ + buffer_size;
+ if (!shared_memory_->Map(map_size))
return false;
mapped_ = true;
return true;
@@ -89,7 +99,7 @@ bool MojoGpuMemoryBufferImpl::Map() {
void* MojoGpuMemoryBufferImpl::memory(size_t plane) {
DCHECK(mapped_);
DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_));
- return reinterpret_cast<uint8_t*>(shared_memory_->memory()) +
+ return reinterpret_cast<uint8_t*>(shared_memory_->memory()) + offset_ +
gfx::BufferOffsetForBufferFormat(size_, format_, plane);
}
@@ -109,9 +119,8 @@ gfx::GpuMemoryBufferHandle MojoGpuMemoryBufferImpl::GetHandle() const {
gfx::GpuMemoryBufferHandle handle;
handle.type = gfx::SHARED_MEMORY_BUFFER;
handle.handle = shared_memory_->handle();
- handle.offset = 0;
- handle.stride = static_cast<int32_t>(
- gfx::RowSizeForBufferFormat(size_.width(), format_, 0));
+ handle.offset = offset_;
+ handle.stride = stride_;
return handle;
}

Powered by Google App Engine
This is Rietveld 408576698