summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authormcasas <mcasas@chromium.org>2015-10-21 14:05:27 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-21 21:06:27 +0000
commita11ca23b4ae411b4dc6cd8ff755e366680e80776 (patch)
tree88ec297d5e74aa06ccd5a6042168442859de2760 /ui
parent83469713c2eac58b5ef66cf8831eefc0a33e4e66 (diff)
downloadchromium_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 'ui')
-rw-r--r--ui/gfx/buffer_format_util.cc147
-rw-r--r--ui/gfx/buffer_format_util.h15
-rw-r--r--ui/gfx/gpu_memory_buffer.h25
3 files changed, 112 insertions, 75 deletions
diff --git a/ui/gfx/buffer_format_util.cc b/ui/gfx/buffer_format_util.cc
index 33bf627..704b680 100644
--- a/ui/gfx/buffer_format_util.cc
+++ b/ui/gfx/buffer_format_util.cc
@@ -23,9 +23,60 @@ static_assert(arraysize(kBufferFormats) ==
(static_cast<int>(BufferFormat::LAST) + 1),
"BufferFormat::LAST must be last value of kBufferFormats");
+
+bool RowSizeForBufferFormatChecked(
+ size_t width, BufferFormat format, int plane, size_t* size_in_bytes) {
+ base::CheckedNumeric<size_t> checked_size = width;
+ switch (format) {
+ case BufferFormat::ATCIA:
+ case BufferFormat::DXT5:
+ DCHECK_EQ(0, plane);
+ *size_in_bytes = width;
+ return true;
+ case BufferFormat::ATC:
+ case BufferFormat::DXT1:
+ case BufferFormat::ETC1:
+ DCHECK_EQ(0, plane);
+ DCHECK_EQ(0u, width % 2);
+ *size_in_bytes = width / 2;
+ return true;
+ case BufferFormat::R_8:
+ checked_size += 3;
+ if (!checked_size.IsValid())
+ return false;
+ *size_in_bytes = checked_size.ValueOrDie() & ~0x3;
+ return true;
+ case BufferFormat::RGBA_4444:
+ case BufferFormat::UYVY_422:
+ checked_size *= 2;
+ if (!checked_size.IsValid())
+ return false;
+ *size_in_bytes = checked_size.ValueOrDie();
+ return true;
+ case BufferFormat::BGRX_8888:
+ case BufferFormat::RGBA_8888:
+ case BufferFormat::BGRA_8888:
+ checked_size *= 4;
+ if (!checked_size.IsValid())
+ return false;
+ *size_in_bytes = checked_size.ValueOrDie();
+ return true;
+ case BufferFormat::YUV_420:
+ DCHECK_EQ(0u, width % 2);
+ *size_in_bytes = width / SubsamplingFactorForBufferFormat(format, plane);
+ return true;
+ case BufferFormat::YUV_420_BIPLANAR:
+ DCHECK_EQ(width % 2, 0u);
+ *size_in_bytes = width;
+ return true;
+ }
+ NOTREACHED();
+ return false;
+}
+
} // namespace
-std::vector<BufferFormat> GetBufferFormats() {
+std::vector<BufferFormat> GetBufferFormatsForTesting() {
return std::vector<BufferFormat>(kBufferFormats,
kBufferFormats + arraysize(kBufferFormats));
}
@@ -72,7 +123,7 @@ size_t SubsamplingFactorForBufferFormat(BufferFormat format, int plane) {
DCHECK_LT(static_cast<size_t>(plane), arraysize(factor));
return factor[plane];
}
- case gfx::BufferFormat::YUV_420_BIPLANAR: {
+ case BufferFormat::YUV_420_BIPLANAR: {
static size_t factor[] = {1, 2};
DCHECK_LT(static_cast<size_t>(plane), arraysize(factor));
return factor[plane];
@@ -89,66 +140,16 @@ size_t RowSizeForBufferFormat(size_t width, BufferFormat format, int plane) {
return row_size;
}
-bool RowSizeForBufferFormatChecked(
- size_t width, BufferFormat format, int plane, size_t* size_in_bytes) {
- base::CheckedNumeric<size_t> checked_size = width;
- switch (format) {
- case BufferFormat::ATCIA:
- case BufferFormat::DXT5:
- DCHECK_EQ(0, plane);
- *size_in_bytes = width;
- return true;
- case BufferFormat::ATC:
- case BufferFormat::DXT1:
- case BufferFormat::ETC1:
- DCHECK_EQ(0, plane);
- DCHECK_EQ(0u, width % 2);
- *size_in_bytes = width / 2;
- return true;
- case BufferFormat::R_8:
- checked_size += 3;
- if (!checked_size.IsValid())
- return false;
- *size_in_bytes = checked_size.ValueOrDie() & ~0x3;
- return true;
- case BufferFormat::RGBA_4444:
- case BufferFormat::UYVY_422:
- checked_size *= 2;
- if (!checked_size.IsValid())
- return false;
- *size_in_bytes = checked_size.ValueOrDie();
- return true;
- case BufferFormat::BGRX_8888:
- case BufferFormat::RGBA_8888:
- case BufferFormat::BGRA_8888:
- checked_size *= 4;
- if (!checked_size.IsValid())
- return false;
- *size_in_bytes = checked_size.ValueOrDie();
- return true;
- case BufferFormat::YUV_420:
- DCHECK_EQ(0u, width % 2);
- *size_in_bytes = width / SubsamplingFactorForBufferFormat(format, plane);
- return true;
- case gfx::BufferFormat::YUV_420_BIPLANAR:
- DCHECK_EQ(width % 2, 0u);
- *size_in_bytes = width;
- return true;
- }
- NOTREACHED();
- return false;
-}
-
-size_t BufferSizeForBufferFormat(
- const Size& size, BufferFormat format) {
+size_t BufferSizeForBufferFormat(const Size& size, BufferFormat format) {
size_t buffer_size = 0;
bool valid = BufferSizeForBufferFormatChecked(size, format, &buffer_size);
DCHECK(valid);
return buffer_size;
}
-bool BufferSizeForBufferFormatChecked(
- const Size& size, BufferFormat format, size_t* size_in_bytes) {
+bool BufferSizeForBufferFormatChecked(const Size& size,
+ BufferFormat format,
+ size_t* size_in_bytes) {
base::CheckedNumeric<size_t> checked_size = 0;
size_t num_planes = NumberOfPlanesForBufferFormat(format);
for (size_t i = 0; i < num_planes; ++i) {
@@ -168,4 +169,38 @@ bool BufferSizeForBufferFormatChecked(
return true;
}
+int BufferOffsetForBufferFormat(const Size& size,
+ BufferFormat format,
+ size_t plane) {
+ DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(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::BGRX_8888:
+ case BufferFormat::BGRA_8888:
+ case BufferFormat::UYVY_422:
+ return 0;
+ case BufferFormat::YUV_420: {
+ static size_t offset_in_2x2_sub_sampling_sizes[] = {0, 4, 5};
+ DCHECK_LT(plane, arraysize(offset_in_2x2_sub_sampling_sizes));
+ return offset_in_2x2_sub_sampling_sizes[plane] *
+ (size.width() / 2 + size.height() / 2);
+ }
+ case gfx::BufferFormat::YUV_420_BIPLANAR: {
+ static size_t offset_in_2x2_sub_sampling_sizes[] = {0, 4};
+ DCHECK_LT(plane, arraysize(offset_in_2x2_sub_sampling_sizes));
+ return offset_in_2x2_sub_sampling_sizes[plane] *
+ (size.width() / 2 + size.height() / 2);
+ }
+ }
+ NOTREACHED();
+ return 0;
+}
+
} // namespace gfx
diff --git a/ui/gfx/buffer_format_util.h b/ui/gfx/buffer_format_util.h
index f656f4a..4e42039 100644
--- a/ui/gfx/buffer_format_util.h
+++ b/ui/gfx/buffer_format_util.h
@@ -15,26 +15,21 @@
namespace gfx {
// Returns a vector containing all buffer formats.
-GFX_EXPORT std::vector<BufferFormat> GetBufferFormats();
+GFX_EXPORT std::vector<BufferFormat> GetBufferFormatsForTesting();
// Returns the number of planes for |format|.
GFX_EXPORT size_t NumberOfPlanesForBufferFormat(BufferFormat format);
// Returns the subsampling factor applied to the given zero-indexed |plane| of
// |format| both horizontally and vertically.
-GFX_EXPORT size_t SubsamplingFactorForBufferFormat(
- BufferFormat format, int plane);
+GFX_EXPORT size_t SubsamplingFactorForBufferFormat(BufferFormat format,
+ int plane);
// Returns the number of bytes used to store a row of the given zero-indexed
// |plane| of |format|.
GFX_EXPORT size_t RowSizeForBufferFormat(size_t width,
BufferFormat format,
int plane);
-GFX_EXPORT bool RowSizeForBufferFormatChecked(size_t width,
- BufferFormat format,
- int plane,
- size_t* size_in_bytes)
- WARN_UNUSED_RESULT;
// Returns the number of bytes used to store all the planes of a given |format|.
GFX_EXPORT size_t BufferSizeForBufferFormat(const Size& size,
@@ -44,6 +39,10 @@ GFX_EXPORT bool BufferSizeForBufferFormatChecked(const Size& size,
size_t* size_in_bytes)
WARN_UNUSED_RESULT;
+GFX_EXPORT int BufferOffsetForBufferFormat(const Size& size,
+ BufferFormat format,
+ size_t plane);
+
} // namespace gfx
#endif // UI_GFX_BUFFER_FORMAT_UTIL_H_
diff --git a/ui/gfx/gpu_memory_buffer.h b/ui/gfx/gpu_memory_buffer.h
index 629dabc..72ff1d2 100644
--- a/ui/gfx/gpu_memory_buffer.h
+++ b/ui/gfx/gpu_memory_buffer.h
@@ -30,7 +30,7 @@ enum GpuMemoryBufferType {
GPU_MEMORY_BUFFER_TYPE_LAST = OZONE_NATIVE_PIXMAP
};
-using GpuMemoryBufferId = gfx::GenericSharedMemoryId;
+using GpuMemoryBufferId = GenericSharedMemoryId;
struct GFX_EXPORT GpuMemoryBufferHandle {
GpuMemoryBufferHandle();
@@ -55,25 +55,28 @@ class GFX_EXPORT GpuMemoryBuffer {
virtual ~GpuMemoryBuffer() {}
// Maps each plane of the buffer into the client's address space so it can be
- // written to by the CPU. A pointer to plane K is stored at index K-1 of the
- // |data| array. This call may block, for instance if the GPU needs to finish
- // accessing the buffer or if CPU caches need to be synchronized. Returns
- // false on failure.
- virtual bool Map(void** data) = 0;
-
- // Unmaps the buffer. It's illegal to use the pointer returned by Map() after
- // this has been called.
+ // written to by the CPU. This call may block, for instance if the GPU needs
+ // to finish accessing the buffer or if CPU caches need to be synchronized.
+ // Returns false on failure.
+ virtual bool Map() = 0;
+
+ // Returns a pointer to the memory address of a plane. Buffer must have been
+ // successfully mapped using a call to Map() before calling this function.
+ virtual void* memory(size_t plane) = 0;
+
+ // Unmaps the buffer. It's illegal to use any pointer returned by memory()
+ // after this has been called.
virtual void Unmap() = 0;
// Returns the size for the buffer.
- virtual gfx::Size GetSize() const = 0;
+ virtual Size GetSize() const = 0;
// Returns the format for the buffer.
virtual BufferFormat GetFormat() const = 0;
// Fills the stride in bytes for each plane of the buffer. The stride of
// plane K is stored at index K-1 of the |stride| array.
- virtual void GetStride(int* stride) const = 0;
+ virtual int stride(size_t plane) const = 0;
// Returns a unique identifier associated with buffer.
virtual GpuMemoryBufferId GetId() const = 0;