diff options
author | mcasas <mcasas@chromium.org> | 2015-10-21 14:05:27 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-21 21:06:27 +0000 |
commit | a11ca23b4ae411b4dc6cd8ff755e366680e80776 (patch) | |
tree | 88ec297d5e74aa06ccd5a6042168442859de2760 /gpu | |
parent | 83469713c2eac58b5ef66cf8831eefc0a33e4e66 (diff) | |
download | chromium_src-a11ca23b4ae411b4dc6cd8ff755e366680e80776.zip chromium_src-a11ca23b4ae411b4dc6cd8ff755e366680e80776.tar.gz chromium_src-a11ca23b4ae411b4dc6cd8ff755e366680e80776.tar.bz2 |
GpuMemoryBuffer interface change: Map(**) --> Map() + memory(plane); GetStride(*) --> stride(plane)
And at the same time clean up/simplify/homogeneise
uses of those APIs.
buffer_format_util.cc:RowSizeForBufferFormatChecked()
is only used in unittests and internally to the file, this CL
restricts it to the .cc file. Also a function there is only
used in test --> added ForTesting() suffix.
BUG=542225
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
Review URL: https://codereview.chromium.org/1401183003
Cr-Commit-Position: refs/heads/master@{#355396}
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/command_buffer/tests/gl_gpu_memory_buffer_unittest.cc | 21 | ||||
-rw-r--r-- | gpu/command_buffer/tests/gl_manager.cc | 33 |
2 files changed, 26 insertions, 28 deletions
diff --git a/gpu/command_buffer/tests/gl_gpu_memory_buffer_unittest.cc b/gpu/command_buffer/tests/gl_gpu_memory_buffer_unittest.cc index 23fc468..280de5f 100644 --- a/gpu/command_buffer/tests/gl_gpu_memory_buffer_unittest.cc +++ b/gpu/command_buffer/tests/gl_gpu_memory_buffer_unittest.cc @@ -170,22 +170,17 @@ TEST_P(GpuMemoryBufferTest, Lifecycle) { gfx::Size(kImageWidth, kImageHeight), GetParam())); // Map buffer for writing. - void* data; - bool rv = buffer->Map(&data); - DCHECK(rv); - - uint8_t* mapped_buffer = static_cast<uint8_t*>(data); - ASSERT_TRUE(mapped_buffer != NULL); - + ASSERT_TRUE(buffer->Map()); + ASSERT_NE(nullptr, buffer->memory(0)); + ASSERT_NE(0, buffer->stride(0)); uint8_t pixel[] = {255u, 0u, 0u, 255u}; // Assign a value to each pixel. - int stride = 0; - buffer->GetStride(&stride); - ASSERT_NE(stride, 0); - for (int y = 0; y < kImageHeight; ++y) - SetRow(GetParam(), mapped_buffer + y * stride, kImageWidth, pixel); - + for (int y = 0; y < kImageHeight; ++y) { + SetRow(GetParam(), + static_cast<uint8_t*>(buffer->memory(0)) + y * buffer->stride(0), + kImageWidth, pixel); + } // Unmap the buffer. buffer->Unmap(); diff --git a/gpu/command_buffer/tests/gl_manager.cc b/gpu/command_buffer/tests/gl_manager.cc index bb803bb..2dbcfb93 100644 --- a/gpu/command_buffer/tests/gl_manager.cc +++ b/gpu/command_buffer/tests/gl_manager.cc @@ -49,31 +49,33 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { GpuMemoryBufferImpl(base::RefCountedBytes* bytes, const gfx::Size& size, gfx::BufferFormat format) - : bytes_(bytes), size_(size), format_(format) {} + : mapped_(false), bytes_(bytes), size_(size), format_(format) {} static GpuMemoryBufferImpl* FromClientBuffer(ClientBuffer buffer) { return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); } // Overridden from gfx::GpuMemoryBuffer: - bool Map(void** data) override { - size_t offset = 0; - size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format_); - for (size_t i = 0; i < num_planes; ++i) { - data[i] = reinterpret_cast<uint8*>(&bytes_->data().front()) + offset; - offset += - gfx::RowSizeForBufferFormat(size_.width(), format_, i) * - (size_.height() / gfx::SubsamplingFactorForBufferFormat(format_, i)); - } + bool Map() override { + DCHECK(!mapped_); + mapped_ = true; return true; } - void Unmap() override {} + void* memory(size_t plane) override { + DCHECK(mapped_); + DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); + return reinterpret_cast<uint8*>(&bytes_->data().front()) + + gfx::BufferOffsetForBufferFormat(size_, format_, plane); + } + void Unmap() override { + DCHECK(mapped_); + mapped_ = false; + } gfx::Size GetSize() const override { return size_; } gfx::BufferFormat GetFormat() const override { return format_; } - void GetStride(int* stride) const override { - size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format_); - for (size_t i = 0; i < num_planes; ++i) - stride[i] = gfx::RowSizeForBufferFormat(size_.width(), format_, i); + int stride(size_t plane) const override { + DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); + return gfx::RowSizeForBufferFormat(size_.width(), format_, plane); } gfx::GpuMemoryBufferId GetId() const override { NOTREACHED(); @@ -90,6 +92,7 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { base::RefCountedBytes* bytes() { return bytes_.get(); } private: + bool mapped_; scoped_refptr<base::RefCountedBytes> bytes_; const gfx::Size size_; gfx::BufferFormat format_; |