Skip to content

Commit

Permalink
Revert of Move NumberOfPlanesForGpuMemoryBufferFormat to gfx (patchset
Browse files Browse the repository at this point in the history
…chromium#4 id:120001 of https://codereview.chromium.org/1281043006/ )

Reason for revert:
This breaks Win 64 builds:

http://build.chromium.org/p/chromium.win/builders/Win%20x64%20GN

Original issue's description:
> Move NumberOfPlanesForGpuMemoryBufferFormat to gfx
>
> We will need to call it from media::GpuMemoryBufferVideoFramePool when we
> add support for YUV_420_BIPLANAR.
>
> BUG=510260
> TEST=No behavior change, only moving code.
> CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
>
> Committed: https://crrev.com/85f29861d095a7c5dcf318053e8349d1efaddbab
> Cr-Commit-Position: refs/heads/master@{#342942}

TBR=reveman@chromium.org,ccameron@chromium.org,msw@chromium.org,jbauman@chromium.org,avi@chromium.org,andresantoso@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=510260

Review URL: https://codereview.chromium.org/1291643002

Cr-Commit-Position: refs/heads/master@{#342948}
  • Loading branch information
krockot authored and Commit bot committed Aug 12, 2015
1 parent efecf8a commit ccc6103
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 82 deletions.
29 changes: 23 additions & 6 deletions cc/test/test_gpu_memory_buffer_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,31 @@

#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:
Expand Down Expand Up @@ -66,7 +85,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 = static_cast<int>(gfx::NumberOfPlanesForBufferFormat(format));
int num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format);
for (int i = 0; i < num_planes; ++i) {
size_in_bytes += StrideInBytes(size.width(), format, i) *
(size.height() / SubsamplingFactor(format, i));
Expand All @@ -91,8 +110,7 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
return false;
mapped_ = true;
size_t offset = 0;
int num_planes =
static_cast<int>(gfx::NumberOfPlanesForBufferFormat(format_));
int num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format_);
for (int i = 0; i < num_planes; ++i) {
data[i] = reinterpret_cast<uint8*>(shared_memory_->memory()) + offset;
offset += StrideInBytes(size_.width(), format_, i) *
Expand All @@ -108,8 +126,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 {
int num_planes =
static_cast<int>(gfx::NumberOfPlanesForBufferFormat(format_));
int num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format_);
for (int i = 0; i < num_planes; ++i)
stride[i] =
base::checked_cast<int>(StrideInBytes(size_.width(), format_, i));
Expand Down
27 changes: 23 additions & 4 deletions components/view_manager/gles2/mojo_gpu_memory_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,31 @@
#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:
Expand Down Expand Up @@ -67,7 +86,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 = gfx::NumberOfPlanesForBufferFormat(format);
int num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format);
for (int i = 0; i < num_planes; ++i) {
size_in_bytes += StrideInBytes(size.width(), format, i) *
(size.height() / SubsamplingFactor(format, i));
Expand Down Expand Up @@ -112,7 +131,7 @@ bool MojoGpuMemoryBufferImpl::Map(void** data) {
return false;
mapped_ = true;
size_t offset = 0;
int num_planes = gfx::NumberOfPlanesForBufferFormat(format_);
int num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format_);
for (int i = 0; i < num_planes; ++i) {
data[i] = reinterpret_cast<uint8*>(shared_memory_->memory()) + offset;
offset += StrideInBytes(size_.width(), format_, i) *
Expand All @@ -136,7 +155,7 @@ gfx::BufferFormat MojoGpuMemoryBufferImpl::GetFormat() const {
}

void MojoGpuMemoryBufferImpl::GetStride(int* stride) const {
int num_planes = gfx::NumberOfPlanesForBufferFormat(format_);
int num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format_);
for (int i = 0; i < num_planes; ++i)
stride[i] =
base::checked_cast<int>(StrideInBytes(size_.width(), format_, i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
#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 {

Expand Down Expand Up @@ -58,7 +57,9 @@ class GpuMemoryBufferBufferHandle
public:
GpuMemoryBufferBufferHandle(gfx::GpuMemoryBuffer* gmb, size_t size)
: gmb_(gmb),
data_(new void*[gfx::NumberOfPlanesForBufferFormat(gmb_->GetFormat())]),
data_(new void* [GpuMemoryBufferImpl::
NumberOfPlanesForGpuMemoryBufferFormat(
gmb_->GetFormat())]),
size_(size) {
DCHECK(gmb && !gmb_->IsMapped());
gmb_->Map(data_.get());
Expand Down
4 changes: 2 additions & 2 deletions content/child/child_thread_impl_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#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 {
Expand Down Expand Up @@ -158,7 +157,8 @@ IN_PROC_BROWSER_TEST_P(ChildThreadImplGpuMemoryBufferBrowserTest,
ASSERT_TRUE(buffer);
EXPECT_EQ(format, buffer->GetFormat());

size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format);
size_t num_planes =
GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat(format);

// Map buffer planes.
scoped_ptr<void* []> planes(new void* [num_planes]);
Expand Down
25 changes: 23 additions & 2 deletions content/common/gpu/client/gpu_memory_buffer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#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)
Expand Down Expand Up @@ -78,6 +77,28 @@ GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer(
return reinterpret_cast<GpuMemoryBufferImpl*>(buffer);
}

// 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) {
Expand Down Expand Up @@ -155,7 +176,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 = gfx::NumberOfPlanesForBufferFormat(format);
size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(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))
Expand Down
4 changes: 4 additions & 0 deletions content/common/gpu/client/gpu_memory_buffer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#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 {
Expand Down Expand Up @@ -150,7 +149,7 @@ bool GpuMemoryBufferImplSharedMemory::IsSizeValidForFormat(
case gfx::BufferFormat::RGBX_8888:
return true;
case gfx::BufferFormat::YUV_420: {
size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format);
size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format);
for (size_t i = 0; i < num_planes; ++i) {
size_t factor = SubsamplingFactor(format, i);
if (size.width() % factor || size.height() % factor)
Expand All @@ -167,7 +166,7 @@ bool GpuMemoryBufferImplSharedMemory::IsSizeValidForFormat(
bool GpuMemoryBufferImplSharedMemory::Map(void** data) {
DCHECK(!mapped_);
size_t offset = 0;
size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format_);
size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(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;
Expand All @@ -187,7 +186,7 @@ void GpuMemoryBufferImplSharedMemory::Unmap() {
}

void GpuMemoryBufferImplSharedMemory::GetStride(int* stride) const {
size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format_);
size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format_);
for (size_t i = 0; i < num_planes; ++i) {
size_t row_size_in_bytes = 0;
bool valid_row_size =
Expand Down
7 changes: 4 additions & 3 deletions content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#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 {
Expand Down Expand Up @@ -93,7 +92,8 @@ TEST_P(GpuMemoryBufferImplTest, Map) {
EXPECT_FALSE(buffer->IsMapped());

size_t num_planes =
gfx::NumberOfPlanesForBufferFormat(configuration.format);
GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat(
configuration.format);

// Map buffer into user space.
scoped_ptr<void*[]> mapped_buffers(new void*[num_planes]);
Expand Down Expand Up @@ -155,7 +155,8 @@ TEST_P(GpuMemoryBufferImplTest, PersistentMap) {
EXPECT_FALSE(buffer->IsMapped());

size_t num_planes =
gfx::NumberOfPlanesForBufferFormat(configuration.format);
GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat(
configuration.format);

// Map buffer into user space.
scoped_ptr<void* []> mapped_buffers(new void* [num_planes]);
Expand Down
27 changes: 23 additions & 4 deletions gpu/command_buffer/tests/gl_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#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"
Expand All @@ -40,6 +39,26 @@
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:
Expand Down Expand Up @@ -97,7 +116,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 = gfx::NumberOfPlanesForBufferFormat(format);
size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format);
for (size_t i = 0; i < num_planes; ++i) {
size_in_bytes += StrideInBytes(size.width(), format, i) *
(size.height() / SubsamplingFactor(format, i));
Expand All @@ -119,7 +138,7 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
// Overridden from gfx::GpuMemoryBuffer:
bool Map(void** data) override {
size_t offset = 0;
size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format_);
size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(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) *
Expand All @@ -132,7 +151,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 = gfx::NumberOfPlanesForBufferFormat(format_);
size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format_);
for (size_t i = 0; i < num_planes; ++i)
stride[i] = StrideInBytes(size_.width(), format_, i);
}
Expand Down
2 changes: 0 additions & 2 deletions ui/gfx/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ component("gfx") {
"blit.cc",
"blit.h",
"break_list.h",
"buffer_format_util.cc",
"buffer_format_util.h",
"canvas.cc",
"canvas.h",
"canvas_notimplemented.cc",
Expand Down
31 changes: 0 additions & 31 deletions ui/gfx/buffer_format_util.cc

This file was deleted.

Loading

0 comments on commit ccc6103

Please sign in to comment.