From 16218d0ac0920a68b05a3c57b7569d74adb79fff Mon Sep 17 00:00:00 2001 From: andresantoso Date: Thu, 27 Aug 2015 18:27:10 -0700 Subject: Move BufferFormat utility functions to gfx. There were multiple copies of these utility functions. Move them to gfx and remove the duplicate copies. CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel Review URL: https://codereview.chromium.org/1308393006 Cr-Commit-Position: refs/heads/master@{#346045} --- cc/test/test_gpu_memory_buffer_manager.cc | 78 ++++--------------------------- 1 file changed, 8 insertions(+), 70 deletions(-) (limited to 'cc/test/test_gpu_memory_buffer_manager.cc') diff --git a/cc/test/test_gpu_memory_buffer_manager.cc b/cc/test/test_gpu_memory_buffer_manager.cc index f8bec8e..0192b40 100644 --- a/cc/test/test_gpu_memory_buffer_manager.cc +++ b/cc/test/test_gpu_memory_buffer_manager.cc @@ -12,70 +12,6 @@ namespace cc { namespace { -size_t SubsamplingFactor(gfx::BufferFormat format, int plane) { - switch (format) { - case gfx::BufferFormat::ATC: - case gfx::BufferFormat::ATCIA: - case gfx::BufferFormat::DXT1: - case gfx::BufferFormat::DXT5: - case gfx::BufferFormat::ETC1: - case gfx::BufferFormat::R_8: - case gfx::BufferFormat::RGBA_4444: - case gfx::BufferFormat::RGBA_8888: - case gfx::BufferFormat::BGRX_8888: - case gfx::BufferFormat::BGRA_8888: - case gfx::BufferFormat::UYVY_422: - return 1; - case gfx::BufferFormat::YUV_420: { - static size_t factor[] = {1, 2, 2}; - DCHECK_LT(static_cast(plane), arraysize(factor)); - return factor[plane]; - } - } - NOTREACHED(); - return 0; -} - -size_t StrideInBytes(size_t width, gfx::BufferFormat format, int plane) { - switch (format) { - case gfx::BufferFormat::ATCIA: - case gfx::BufferFormat::DXT5: - DCHECK_EQ(plane, 0); - return width; - case gfx::BufferFormat::ATC: - case gfx::BufferFormat::DXT1: - case gfx::BufferFormat::ETC1: - DCHECK_EQ(plane, 0); - DCHECK_EQ(width % 2, 0u); - return width / 2; - case gfx::BufferFormat::R_8: - return (width + 3) & ~0x3; - case gfx::BufferFormat::RGBA_4444: - case gfx::BufferFormat::UYVY_422: - DCHECK_EQ(plane, 0); - return width * 2; - case gfx::BufferFormat::RGBA_8888: - case gfx::BufferFormat::BGRX_8888: - case gfx::BufferFormat::BGRA_8888: - DCHECK_EQ(plane, 0); - return width * 4; - case gfx::BufferFormat::YUV_420: - return width / SubsamplingFactor(format, plane); - } - NOTREACHED(); - return 0; -} - -size_t BufferSizeInBytes(const gfx::Size& size, gfx::BufferFormat format) { - size_t size_in_bytes = 0; - int num_planes = static_cast(gfx::NumberOfPlanesForBufferFormat(format)); - for (int i = 0; i < num_planes; ++i) { - size_in_bytes += StrideInBytes(size.width(), format, i) * - (size.height() / SubsamplingFactor(format, i)); - } - return size_in_bytes; -} - class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { public: GpuMemoryBufferImpl(const gfx::Size& size, @@ -89,7 +25,7 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { // Overridden from gfx::GpuMemoryBuffer: bool Map(void** data) override { DCHECK(!mapped_); - if (!shared_memory_->Map(BufferSizeInBytes(size_, format_))) + if (!shared_memory_->Map(gfx::BufferSizeForBufferFormat(size_, format_))) return false; mapped_ = true; size_t offset = 0; @@ -97,8 +33,9 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { static_cast(gfx::NumberOfPlanesForBufferFormat(format_)); for (int i = 0; i < num_planes; ++i) { data[i] = reinterpret_cast(shared_memory_->memory()) + offset; - offset += StrideInBytes(size_.width(), format_, i) * - (size_.height() / SubsamplingFactor(format_, i)); + offset += + gfx::RowSizeForBufferFormat(size_.width(), format_, i) * + (size_.height() / gfx::SubsamplingFactorForBufferFormat(format_, i)); } return true; } @@ -113,8 +50,8 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { int num_planes = static_cast(gfx::NumberOfPlanesForBufferFormat(format_)); for (int i = 0; i < num_planes; ++i) - stride[i] = - base::checked_cast(StrideInBytes(size_.width(), format_, i)); + stride[i] = base::checked_cast( + gfx::RowSizeForBufferFormat(size_.width(), format_, i)); } gfx::GpuMemoryBufferId GetId() const override { NOTREACHED(); @@ -150,7 +87,8 @@ TestGpuMemoryBufferManager::AllocateGpuMemoryBuffer(const gfx::Size& size, gfx::BufferFormat format, gfx::BufferUsage usage) { scoped_ptr shared_memory(new base::SharedMemory); - if (!shared_memory->CreateAnonymous(BufferSizeInBytes(size, format))) + const size_t buffer_size = gfx::BufferSizeForBufferFormat(size, format); + if (!shared_memory->CreateAnonymous(buffer_size)) return nullptr; return make_scoped_ptr( new GpuMemoryBufferImpl(size, format, shared_memory.Pass())); -- cgit v1.1