diff options
-rw-r--r-- | cc/test/test_gpu_memory_buffer_manager.cc | 29 | ||||
-rw-r--r-- | components/view_manager/gles2/mojo_gpu_memory_buffer.cc | 29 | ||||
-rw-r--r-- | content/browser/renderer_host/media/video_capture_buffer_pool.cc | 7 | ||||
-rw-r--r-- | content/child/child_thread_impl_browsertest.cc | 4 | ||||
-rw-r--r-- | content/common/gpu/client/gpu_memory_buffer_impl.cc | 25 | ||||
-rw-r--r-- | content/common/gpu/client/gpu_memory_buffer_impl.h | 4 | ||||
-rw-r--r-- | content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc | 7 | ||||
-rw-r--r-- | content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc | 7 | ||||
-rw-r--r-- | gpu/command_buffer/tests/gl_manager.cc | 27 | ||||
-rw-r--r-- | ui/gfx/BUILD.gn | 2 | ||||
-rw-r--r-- | ui/gfx/buffer_format_util.cc | 31 | ||||
-rw-r--r-- | ui/gfx/buffer_format_util.h | 19 | ||||
-rw-r--r-- | ui/gfx/gfx.gyp | 2 |
13 files changed, 84 insertions, 109 deletions
diff --git a/cc/test/test_gpu_memory_buffer_manager.cc b/cc/test/test_gpu_memory_buffer_manager.cc index d70b740..dbc9077 100644 --- a/cc/test/test_gpu_memory_buffer_manager.cc +++ b/cc/test/test_gpu_memory_buffer_manager.cc @@ -6,31 +6,12 @@ #include "base/logging.h" #include "base/numerics/safe_conversions.h" +#include "ui/gfx/buffer_format_util.h" #include "ui/gfx/gpu_memory_buffer.h" namespace cc { namespace { -int NumberOfPlanesForGpuMemoryBufferFormat(gfx::BufferFormat format) { - 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::RGBX_8888: - case gfx::BufferFormat::BGRA_8888: - return 1; - case gfx::BufferFormat::YUV_420: - return 3; - } - NOTREACHED(); - return 0; -} - size_t SubsamplingFactor(gfx::BufferFormat format, int plane) { switch (format) { case gfx::BufferFormat::ATC: @@ -85,7 +66,7 @@ size_t StrideInBytes(size_t width, gfx::BufferFormat format, int plane) { size_t BufferSizeInBytes(const gfx::Size& size, gfx::BufferFormat format) { size_t size_in_bytes = 0; - int num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format); + 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)); @@ -110,7 +91,8 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { return false; mapped_ = true; size_t offset = 0; - int num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format_); + int num_planes = + 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) * @@ -126,7 +108,8 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { bool IsMapped() const override { return mapped_; } gfx::BufferFormat GetFormat() const override { return format_; } void GetStride(int* stride) const override { - int num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format_); + 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)); diff --git a/components/view_manager/gles2/mojo_gpu_memory_buffer.cc b/components/view_manager/gles2/mojo_gpu_memory_buffer.cc index 4545050..254c358 100644 --- a/components/view_manager/gles2/mojo_gpu_memory_buffer.cc +++ b/components/view_manager/gles2/mojo_gpu_memory_buffer.cc @@ -7,31 +7,12 @@ #include "base/logging.h" #include "base/memory/shared_memory.h" #include "base/numerics/safe_conversions.h" +#include "ui/gfx/buffer_format_util.h" namespace gles2 { namespace { -int NumberOfPlanesForGpuMemoryBufferFormat(gfx::BufferFormat format) { - 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::RGBX_8888: - case gfx::BufferFormat::BGRA_8888: - return 1; - case gfx::BufferFormat::YUV_420: - return 3; - } - NOTREACHED(); - return 0; -} - size_t SubsamplingFactor(gfx::BufferFormat format, int plane) { switch (format) { case gfx::BufferFormat::ATC: @@ -86,7 +67,7 @@ size_t StrideInBytes(size_t width, gfx::BufferFormat format, int plane) { size_t BufferSizeInBytes(const gfx::Size& size, gfx::BufferFormat format) { size_t size_in_bytes = 0; - int num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format); + 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)); @@ -131,7 +112,8 @@ bool MojoGpuMemoryBufferImpl::Map(void** data) { return false; mapped_ = true; size_t offset = 0; - int num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format_); + int num_planes = 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) * @@ -155,7 +137,8 @@ gfx::BufferFormat MojoGpuMemoryBufferImpl::GetFormat() const { } void MojoGpuMemoryBufferImpl::GetStride(int* stride) const { - int num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format_); + 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)); diff --git a/content/browser/renderer_host/media/video_capture_buffer_pool.cc b/content/browser/renderer_host/media/video_capture_buffer_pool.cc index 4d3e9a1..ea8ff20 100644 --- a/content/browser/renderer_host/media/video_capture_buffer_pool.cc +++ b/content/browser/renderer_host/media/video_capture_buffer_pool.cc @@ -8,8 +8,9 @@ #include "base/memory/scoped_ptr.h" #include "base/stl_util.h" #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" -#include "content/common/gpu/client/gpu_memory_buffer_impl.h" #include "content/public/browser/browser_thread.h" +#include "ui/gfx/buffer_format_util.h" +#include "ui/gfx/gpu_memory_buffer.h" namespace content { @@ -57,9 +58,7 @@ class GpuMemoryBufferBufferHandle public: GpuMemoryBufferBufferHandle(gfx::GpuMemoryBuffer* gmb, size_t size) : gmb_(gmb), - data_(new void* [GpuMemoryBufferImpl:: - NumberOfPlanesForGpuMemoryBufferFormat( - gmb_->GetFormat())]), + data_(new void*[gfx::NumberOfPlanesForBufferFormat(gmb_->GetFormat())]), size_(size) { DCHECK(gmb && !gmb_->IsMapped()); gmb_->Map(data_.get()); diff --git a/content/child/child_thread_impl_browsertest.cc b/content/child/child_thread_impl_browsertest.cc index d6b82a8..add820c 100644 --- a/content/child/child_thread_impl_browsertest.cc +++ b/content/child/child_thread_impl_browsertest.cc @@ -16,6 +16,7 @@ #include "content/public/test/content_browser_test.h" #include "content/public/test/content_browser_test_utils.h" #include "content/shell/browser/shell.h" +#include "ui/gfx/buffer_format_util.h" #include "url/gurl.h" namespace content { @@ -157,8 +158,7 @@ IN_PROC_BROWSER_TEST_P(ChildThreadImplGpuMemoryBufferBrowserTest, ASSERT_TRUE(buffer); EXPECT_EQ(format, buffer->GetFormat()); - size_t num_planes = - GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat(format); + size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); // Map buffer planes. scoped_ptr<void* []> planes(new void* [num_planes]); diff --git a/content/common/gpu/client/gpu_memory_buffer_impl.cc b/content/common/gpu/client/gpu_memory_buffer_impl.cc index 928faa9..81af399 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl.cc +++ b/content/common/gpu/client/gpu_memory_buffer_impl.cc @@ -7,6 +7,7 @@ #include "base/logging.h" #include "base/numerics/safe_math.h" #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" +#include "ui/gfx/buffer_format_util.h" #include "ui/gl/gl_bindings.h" #if defined(OS_MACOSX) @@ -78,28 +79,6 @@ GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer( } // static -size_t GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat( - gfx::BufferFormat format) { - 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::RGBX_8888: - case gfx::BufferFormat::BGRA_8888: - return 1; - case gfx::BufferFormat::YUV_420: - return 3; - } - NOTREACHED(); - return 0; -} - -// static size_t GpuMemoryBufferImpl::SubsamplingFactor(gfx::BufferFormat format, int plane) { switch (format) { @@ -176,7 +155,7 @@ bool GpuMemoryBufferImpl::BufferSizeInBytes(const gfx::Size& size, gfx::BufferFormat format, size_t* size_in_bytes) { base::CheckedNumeric<size_t> checked_size = 0; - size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format); + size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); for (size_t i = 0; i < num_planes; ++i) { size_t row_size_in_bytes = 0; if (!RowSizeInBytes(size.width(), format, i, &row_size_in_bytes)) diff --git a/content/common/gpu/client/gpu_memory_buffer_impl.h b/content/common/gpu/client/gpu_memory_buffer_impl.h index 9e5c7da..4ef4637 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl.h +++ b/content/common/gpu/client/gpu_memory_buffer_impl.h @@ -34,10 +34,6 @@ class CONTENT_EXPORT GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { // Type-checking upcast routine. Returns an NULL on failure. static GpuMemoryBufferImpl* FromClientBuffer(ClientBuffer buffer); - // Returns the number of planes based on the format of the buffer. - static size_t NumberOfPlanesForGpuMemoryBufferFormat( - gfx::BufferFormat format); - // Returns the subsampling factor applied to the given zero-indexed |plane| of // the |format| both horizontally and vertically. static size_t SubsamplingFactor(gfx::BufferFormat format, int plane); diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc b/content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc index 9db3696..d869ef0 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc +++ b/content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc @@ -6,6 +6,7 @@ #include "base/bind.h" #include "base/numerics/safe_math.h" +#include "ui/gfx/buffer_format_util.h" #include "ui/gl/gl_bindings.h" namespace content { @@ -149,7 +150,7 @@ bool GpuMemoryBufferImplSharedMemory::IsSizeValidForFormat( case gfx::BufferFormat::RGBX_8888: return true; case gfx::BufferFormat::YUV_420: { - size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format); + size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); for (size_t i = 0; i < num_planes; ++i) { size_t factor = SubsamplingFactor(format, i); if (size.width() % factor || size.height() % factor) @@ -166,7 +167,7 @@ bool GpuMemoryBufferImplSharedMemory::IsSizeValidForFormat( bool GpuMemoryBufferImplSharedMemory::Map(void** data) { DCHECK(!mapped_); size_t offset = 0; - size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format_); + size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format_); for (size_t i = 0; i < num_planes; ++i) { data[i] = reinterpret_cast<uint8*>(shared_memory_->memory()) + offset; size_t row_size_in_bytes = 0; @@ -186,7 +187,7 @@ void GpuMemoryBufferImplSharedMemory::Unmap() { } void GpuMemoryBufferImplSharedMemory::GetStride(int* stride) const { - size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format_); + size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format_); for (size_t i = 0; i < num_planes; ++i) { size_t row_size_in_bytes = 0; bool valid_row_size = diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc b/content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc index d96c7f4..1ab1d99 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc +++ b/content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc @@ -7,6 +7,7 @@ #include "base/bind.h" #include "content/common/gpu/gpu_memory_buffer_factory.h" #include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/buffer_format_util.h" namespace content { namespace { @@ -92,8 +93,7 @@ TEST_P(GpuMemoryBufferImplTest, Map) { EXPECT_FALSE(buffer->IsMapped()); size_t num_planes = - GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat( - configuration.format); + gfx::NumberOfPlanesForBufferFormat(configuration.format); // Map buffer into user space. scoped_ptr<void*[]> mapped_buffers(new void*[num_planes]); @@ -155,8 +155,7 @@ TEST_P(GpuMemoryBufferImplTest, PersistentMap) { EXPECT_FALSE(buffer->IsMapped()); size_t num_planes = - GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat( - configuration.format); + gfx::NumberOfPlanesForBufferFormat(configuration.format); // Map buffer into user space. scoped_ptr<void* []> mapped_buffers(new void* [num_planes]); diff --git a/gpu/command_buffer/tests/gl_manager.cc b/gpu/command_buffer/tests/gl_manager.cc index 3b9e170..5489358 100644 --- a/gpu/command_buffer/tests/gl_manager.cc +++ b/gpu/command_buffer/tests/gl_manager.cc @@ -30,6 +30,7 @@ #include "gpu/command_buffer/service/memory_tracking.h" #include "gpu/command_buffer/service/valuebuffer_manager.h" #include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/buffer_format_util.h" #include "ui/gfx/gpu_memory_buffer.h" #include "ui/gl/gl_context.h" #include "ui/gl/gl_image_ref_counted_memory.h" @@ -39,26 +40,6 @@ namespace gpu { namespace { -size_t NumberOfPlanesForGpuMemoryBufferFormat(gfx::BufferFormat format) { - 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::RGBX_8888: - case gfx::BufferFormat::BGRA_8888: - return 1; - case gfx::BufferFormat::YUV_420: - return 3; - } - NOTREACHED(); - return 0; -} - size_t SubsamplingFactor(gfx::BufferFormat format, int plane) { switch (format) { case gfx::BufferFormat::ATC: @@ -116,7 +97,7 @@ size_t StrideInBytes(size_t width, gfx::BufferFormat format, int plane) { size_t BufferSizeInBytes(const gfx::Size& size, gfx::BufferFormat format) { size_t size_in_bytes = 0; - size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format); + size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); for (size_t i = 0; i < num_planes; ++i) { size_in_bytes += StrideInBytes(size.width(), format, i) * (size.height() / SubsamplingFactor(format, i)); @@ -138,7 +119,7 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { // Overridden from gfx::GpuMemoryBuffer: bool Map(void** data) override { size_t offset = 0; - size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format_); + 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 += StrideInBytes(size_.width(), format_, i) * @@ -151,7 +132,7 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { bool IsMapped() const override { return mapped_; } gfx::BufferFormat GetFormat() const override { return format_; } void GetStride(int* stride) const override { - size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format_); + size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format_); for (size_t i = 0; i < num_planes; ++i) stride[i] = StrideInBytes(size_.width(), format_, i); } diff --git a/ui/gfx/BUILD.gn b/ui/gfx/BUILD.gn index 58b493f..ec0743e 100644 --- a/ui/gfx/BUILD.gn +++ b/ui/gfx/BUILD.gn @@ -55,6 +55,8 @@ component("gfx") { "blit.cc", "blit.h", "break_list.h", + "buffer_format_util.cc", + "buffer_format_util.h", "canvas.cc", "canvas.h", "canvas_notimplemented.cc", diff --git a/ui/gfx/buffer_format_util.cc b/ui/gfx/buffer_format_util.cc new file mode 100644 index 0000000..61cf260 --- /dev/null +++ b/ui/gfx/buffer_format_util.cc @@ -0,0 +1,31 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/gfx/buffer_format_util.h" + +#include "base/logging.h" + +namespace gfx { + +size_t NumberOfPlanesForBufferFormat(BufferFormat format) { + switch (format) { + case BufferFormat::ATC: + case BufferFormat::ATCIA: + case BufferFormat::DXT1: + case BufferFormat::DXT5: + case BufferFormat::ETC1: + case BufferFormat::R_8: + case BufferFormat::RGBA_4444: + case BufferFormat::RGBA_8888: + case BufferFormat::RGBX_8888: + case BufferFormat::BGRA_8888: + return 1; + case BufferFormat::YUV_420: + return 3; + } + NOTREACHED(); + return 0; +} + +} // namespace gfx diff --git a/ui/gfx/buffer_format_util.h b/ui/gfx/buffer_format_util.h new file mode 100644 index 0000000..96b1859 --- /dev/null +++ b/ui/gfx/buffer_format_util.h @@ -0,0 +1,19 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_BUFFER_FORMAT_UTIL_H_ +#define UI_GFX_BUFFER_FORMAT_UTIL_H_ + +#include "base/basictypes.h" +#include "ui/gfx/buffer_types.h" +#include "ui/gfx/gfx_export.h" + +namespace gfx { + +// Returns the number of planes for |format|. +GFX_EXPORT size_t NumberOfPlanesForBufferFormat(BufferFormat format); + +} // namespace gfx + +#endif // UI_GFX_BUFFER_FORMAT_UTIL_H_ diff --git a/ui/gfx/gfx.gyp b/ui/gfx/gfx.gyp index a92eca1..d741b0e 100644 --- a/ui/gfx/gfx.gyp +++ b/ui/gfx/gfx.gyp @@ -127,6 +127,8 @@ 'blit.cc', 'blit.h', 'break_list.h', + 'buffer_format_util.cc', + 'buffer_format_util.h', 'canvas.cc', 'canvas.h', 'canvas_notimplemented.cc', |