summaryrefslogtreecommitdiffstats
path: root/cc/test/test_gpu_memory_buffer_manager.cc
diff options
context:
space:
mode:
authorandresantoso <andresantoso@chromium.org>2015-08-27 18:27:10 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-28 01:27:50 +0000
commit16218d0ac0920a68b05a3c57b7569d74adb79fff (patch)
treeccb0a31cdd0876b719f5f40abee7e61f728020a5 /cc/test/test_gpu_memory_buffer_manager.cc
parent85c8178bab8d45602c5f0476a61d23b330833323 (diff)
downloadchromium_src-16218d0ac0920a68b05a3c57b7569d74adb79fff.zip
chromium_src-16218d0ac0920a68b05a3c57b7569d74adb79fff.tar.gz
chromium_src-16218d0ac0920a68b05a3c57b7569d74adb79fff.tar.bz2
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}
Diffstat (limited to 'cc/test/test_gpu_memory_buffer_manager.cc')
-rw-r--r--cc/test/test_gpu_memory_buffer_manager.cc78
1 files changed, 8 insertions, 70 deletions
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<size_t>(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<int>(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<int>(gfx::NumberOfPlanesForBufferFormat(format_));
for (int i = 0; i < num_planes; ++i) {
data[i] = reinterpret_cast<uint8*>(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<int>(gfx::NumberOfPlanesForBufferFormat(format_));
for (int i = 0; i < num_planes; ++i)
- stride[i] =
- base::checked_cast<int>(StrideInBytes(size_.width(), format_, i));
+ stride[i] = base::checked_cast<int>(
+ 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<base::SharedMemory> 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<gfx::GpuMemoryBuffer>(
new GpuMemoryBufferImpl(size, format, shared_memory.Pass()));