diff options
author | vasilii <vasilii@chromium.org> | 2015-10-22 01:30:06 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-22 08:31:02 +0000 |
commit | 5f26dd6169a6b113ddfb66f6c1c8ed74a259e269 (patch) | |
tree | c4435914cc8566c52de2527e400bc1a08f1e041d /ui | |
parent | 576f61470f508980a3cb769f6a2a45371ea19cd5 (diff) | |
download | chromium_src-5f26dd6169a6b113ddfb66f6c1c8ed74a259e269.zip chromium_src-5f26dd6169a6b113ddfb66f6c1c8ed74a259e269.tar.gz chromium_src-5f26dd6169a6b113ddfb66f6c1c8ed74a259e269.tar.bz2 |
Revert of GpuMemoryBuffer interface change: Map(**) to Map() and memory(plane); stride(plane) (patchset #5 id:610001 of https://codereview.chromium.org/1401183003/ )
Reason for revert:
Broke Win x64 GN compilation:
e:\b\build\slave\win_x64_gn\build\src\components\mus\gles2\mojo_gpu_memory_buffer.cc(78) :error C2220: warning treated as error - no 'object' file generated
e:\b\build\slave\win_x64_gn\build\src\components\mus\gles2\mojo_gpu_memory_buffer.cc(78) : warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
Original issue's description:
> 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
>
> Committed: https://crrev.com/a11ca23b4ae411b4dc6cd8ff755e366680e80776
> Cr-Commit-Position: refs/heads/master@{#355396}
TBR=reveman@chromium.org,avi@chromium.org,bajones@chromium.org,dalecurtis@chromium.org,fsamuel@chromium.org,miu@chromium.org,mcasas@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=542225
Review URL: https://codereview.chromium.org/1409163003
Cr-Commit-Position: refs/heads/master@{#355511}
Diffstat (limited to 'ui')
-rw-r--r-- | ui/gfx/buffer_format_util.cc | 147 | ||||
-rw-r--r-- | ui/gfx/buffer_format_util.h | 15 | ||||
-rw-r--r-- | ui/gfx/gpu_memory_buffer.h | 25 |
3 files changed, 75 insertions, 112 deletions
diff --git a/ui/gfx/buffer_format_util.cc b/ui/gfx/buffer_format_util.cc index 704b680..33bf627 100644 --- a/ui/gfx/buffer_format_util.cc +++ b/ui/gfx/buffer_format_util.cc @@ -23,60 +23,9 @@ 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> GetBufferFormatsForTesting() { +std::vector<BufferFormat> GetBufferFormats() { return std::vector<BufferFormat>(kBufferFormats, kBufferFormats + arraysize(kBufferFormats)); } @@ -123,7 +72,7 @@ size_t SubsamplingFactorForBufferFormat(BufferFormat format, int plane) { DCHECK_LT(static_cast<size_t>(plane), arraysize(factor)); return factor[plane]; } - case BufferFormat::YUV_420_BIPLANAR: { + case gfx::BufferFormat::YUV_420_BIPLANAR: { static size_t factor[] = {1, 2}; DCHECK_LT(static_cast<size_t>(plane), arraysize(factor)); return factor[plane]; @@ -140,16 +89,66 @@ size_t RowSizeForBufferFormat(size_t width, BufferFormat format, int plane) { return row_size; } -size_t BufferSizeForBufferFormat(const Size& size, BufferFormat format) { +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 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) { @@ -169,38 +168,4 @@ bool BufferSizeForBufferFormatChecked(const Size& size, 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 4e42039..f656f4a 100644 --- a/ui/gfx/buffer_format_util.h +++ b/ui/gfx/buffer_format_util.h @@ -15,21 +15,26 @@ namespace gfx { // Returns a vector containing all buffer formats. -GFX_EXPORT std::vector<BufferFormat> GetBufferFormatsForTesting(); +GFX_EXPORT std::vector<BufferFormat> GetBufferFormats(); // 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, @@ -39,10 +44,6 @@ 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 72ff1d2..629dabc 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 = GenericSharedMemoryId; +using GpuMemoryBufferId = gfx::GenericSharedMemoryId; struct GFX_EXPORT GpuMemoryBufferHandle { GpuMemoryBufferHandle(); @@ -55,28 +55,25 @@ 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. 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. + // 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. virtual void Unmap() = 0; // Returns the size for the buffer. - virtual Size GetSize() const = 0; + virtual gfx::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 int stride(size_t plane) const = 0; + virtual void GetStride(int* stride) const = 0; // Returns a unique identifier associated with buffer. virtual GpuMemoryBufferId GetId() const = 0; |