Commit 9286a11b authored by penghuang's avatar penghuang Committed by Commit bot

services/ui: Use the correct offset and stride in MojoGpuMemoryBuffer.

BUG=None

Review-Url: https://codereview.chromium.org/2277293002
Cr-Commit-Position: refs/heads/master@{#414494}
parent 7be93abd
...@@ -17,13 +17,6 @@ ...@@ -17,13 +17,6 @@
namespace ui { namespace ui {
MojoGpuMemoryBufferImpl::MojoGpuMemoryBufferImpl(
const gfx::Size& size,
gfx::BufferFormat format,
std::unique_ptr<base::SharedMemory> shared_memory)
: GpuMemoryBufferImpl(gfx::GenericSharedMemoryId(0), size, format),
shared_memory_(std::move(shared_memory)) {}
// TODO(rjkroege): Support running a destructor callback as necessary. // TODO(rjkroege): Support running a destructor callback as necessary.
MojoGpuMemoryBufferImpl::~MojoGpuMemoryBufferImpl() {} MojoGpuMemoryBufferImpl::~MojoGpuMemoryBufferImpl() {}
...@@ -50,8 +43,10 @@ std::unique_ptr<gfx::GpuMemoryBuffer> MojoGpuMemoryBufferImpl::Create( ...@@ -50,8 +43,10 @@ std::unique_ptr<gfx::GpuMemoryBuffer> MojoGpuMemoryBufferImpl::Create(
auto shared_memory = auto shared_memory =
base::MakeUnique<base::SharedMemory>(platform_handle, readonly); base::MakeUnique<base::SharedMemory>(platform_handle, readonly);
return base::MakeUnique<MojoGpuMemoryBufferImpl>( const int stride = base::checked_cast<int>(
size, format, std::move(shared_memory)); gfx::RowSizeForBufferFormat(size.width(), format, 0));
return base::WrapUnique(new MojoGpuMemoryBufferImpl(
size, format, std::move(shared_memory), 0, stride));
} }
// static // static
...@@ -65,8 +60,8 @@ std::unique_ptr<gfx::GpuMemoryBuffer> MojoGpuMemoryBufferImpl::CreateFromHandle( ...@@ -65,8 +60,8 @@ std::unique_ptr<gfx::GpuMemoryBuffer> MojoGpuMemoryBufferImpl::CreateFromHandle(
const bool readonly = false; const bool readonly = false;
auto shared_memory = auto shared_memory =
base::MakeUnique<base::SharedMemory>(handle.handle, readonly); base::MakeUnique<base::SharedMemory>(handle.handle, readonly);
return base::MakeUnique<MojoGpuMemoryBufferImpl>( return base::WrapUnique(new MojoGpuMemoryBufferImpl(
size, format, std::move(shared_memory)); size, format, std::move(shared_memory), handle.offset, handle.stride));
} }
MojoGpuMemoryBufferImpl* MojoGpuMemoryBufferImpl::FromClientBuffer( MojoGpuMemoryBufferImpl* MojoGpuMemoryBufferImpl::FromClientBuffer(
...@@ -80,7 +75,11 @@ const unsigned char* MojoGpuMemoryBufferImpl::GetMemory() const { ...@@ -80,7 +75,11 @@ const unsigned char* MojoGpuMemoryBufferImpl::GetMemory() const {
bool MojoGpuMemoryBufferImpl::Map() { bool MojoGpuMemoryBufferImpl::Map() {
DCHECK(!mapped_); 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; return false;
mapped_ = true; mapped_ = true;
return true; return true;
...@@ -89,7 +88,7 @@ bool MojoGpuMemoryBufferImpl::Map() { ...@@ -89,7 +88,7 @@ bool MojoGpuMemoryBufferImpl::Map() {
void* MojoGpuMemoryBufferImpl::memory(size_t plane) { void* MojoGpuMemoryBufferImpl::memory(size_t plane) {
DCHECK(mapped_); DCHECK(mapped_);
DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); 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); gfx::BufferOffsetForBufferFormat(size_, format_, plane);
} }
...@@ -109,9 +108,8 @@ gfx::GpuMemoryBufferHandle MojoGpuMemoryBufferImpl::GetHandle() const { ...@@ -109,9 +108,8 @@ gfx::GpuMemoryBufferHandle MojoGpuMemoryBufferImpl::GetHandle() const {
gfx::GpuMemoryBufferHandle handle; gfx::GpuMemoryBufferHandle handle;
handle.type = gfx::SHARED_MEMORY_BUFFER; handle.type = gfx::SHARED_MEMORY_BUFFER;
handle.handle = shared_memory_->handle(); handle.handle = shared_memory_->handle();
handle.offset = 0; handle.offset = offset_;
handle.stride = static_cast<int32_t>( handle.stride = stride_;
gfx::RowSizeForBufferFormat(size_.width(), format_, 0));
return handle; return handle;
} }
...@@ -120,4 +118,15 @@ gfx::GpuMemoryBufferType MojoGpuMemoryBufferImpl::GetBufferType() const { ...@@ -120,4 +118,15 @@ gfx::GpuMemoryBufferType MojoGpuMemoryBufferImpl::GetBufferType() const {
return gfx::SHARED_MEMORY_BUFFER; return gfx::SHARED_MEMORY_BUFFER;
} }
MojoGpuMemoryBufferImpl::MojoGpuMemoryBufferImpl(
const gfx::Size& size,
gfx::BufferFormat format,
std::unique_ptr<base::SharedMemory> shared_memory,
uint32_t offset,
int32_t stride)
: GpuMemoryBufferImpl(gfx::GenericSharedMemoryId(0), size, format),
shared_memory_(std::move(shared_memory)),
offset_(offset),
stride_(stride) {}
} // namespace ui } // namespace ui
...@@ -18,9 +18,6 @@ namespace ui { ...@@ -18,9 +18,6 @@ namespace ui {
class MojoGpuMemoryBufferImpl : public ui::GpuMemoryBufferImpl { class MojoGpuMemoryBufferImpl : public ui::GpuMemoryBufferImpl {
public: public:
MojoGpuMemoryBufferImpl(const gfx::Size& size,
gfx::BufferFormat format,
std::unique_ptr<base::SharedMemory> shared_memory);
~MojoGpuMemoryBufferImpl() override; ~MojoGpuMemoryBufferImpl() override;
static std::unique_ptr<gfx::GpuMemoryBuffer> Create(const gfx::Size& size, static std::unique_ptr<gfx::GpuMemoryBuffer> Create(const gfx::Size& size,
...@@ -46,7 +43,15 @@ class MojoGpuMemoryBufferImpl : public ui::GpuMemoryBufferImpl { ...@@ -46,7 +43,15 @@ class MojoGpuMemoryBufferImpl : public ui::GpuMemoryBufferImpl {
gfx::GpuMemoryBufferType GetBufferType() const override; gfx::GpuMemoryBufferType GetBufferType() const override;
private: private:
MojoGpuMemoryBufferImpl(const gfx::Size& size,
gfx::BufferFormat format,
std::unique_ptr<base::SharedMemory> shared_memory,
uint32_t offset,
int32_t stride);
std::unique_ptr<base::SharedMemory> shared_memory_; std::unique_ptr<base::SharedMemory> shared_memory_;
const uint32_t offset_;
const int32_t stride_;
DISALLOW_COPY_AND_ASSIGN(MojoGpuMemoryBufferImpl); DISALLOW_COPY_AND_ASSIGN(MojoGpuMemoryBufferImpl);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment