Commit 7c859919 authored by Chih-Yu Huang's avatar Chih-Yu Huang Committed by Commit Bot

media/gpu/chromeos: Add GpuBufferLayout class.

Currently, we use VideoFrameLayout to store the physical layout of
video frame buffers. VideoFrameLayout uses VideoFrameLayout to
indicate the buffer format. However in GPU buffer usage, we have to
handle proprietary format, which is not listed in VideoPixelFormat.

This CL introduces a new class "GpuBufferLayout", which is planned to
replace VideoFrameLayout inside media/gpu/chromeos.

Bug: 1004727
Test: ninja media/gpu/chromeos:common

Change-Id: Iaac1b1c76ac6b9dace7e4b790a9161de17e3342a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1899228
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
Reviewed-by: default avatarHirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715615}
parent 3e92d52f
...@@ -48,6 +48,8 @@ source_set("common") { ...@@ -48,6 +48,8 @@ source_set("common") {
sources = [ sources = [
"dmabuf_video_frame_pool.cc", "dmabuf_video_frame_pool.cc",
"dmabuf_video_frame_pool.h", "dmabuf_video_frame_pool.h",
"gpu_buffer_layout.cc",
"gpu_buffer_layout.h",
"image_processor.cc", "image_processor.cc",
"image_processor.h", "image_processor.h",
"image_processor_factory.h", "image_processor_factory.h",
......
...@@ -20,6 +20,7 @@ namespace media { ...@@ -20,6 +20,7 @@ namespace media {
Fourcc::Fourcc() : value_(Fourcc::INVALID) {} Fourcc::Fourcc() : value_(Fourcc::INVALID) {}
Fourcc::Fourcc(Fourcc::Value fourcc) : value_(fourcc) {} Fourcc::Fourcc(Fourcc::Value fourcc) : value_(fourcc) {}
Fourcc::~Fourcc() = default; Fourcc::~Fourcc() = default;
Fourcc& Fourcc::operator=(const Fourcc& other) = default;
// static // static
Fourcc Fourcc::FromVideoPixelFormat(VideoPixelFormat pixel_format, Fourcc Fourcc::FromVideoPixelFormat(VideoPixelFormat pixel_format,
......
...@@ -115,6 +115,7 @@ class MEDIA_GPU_EXPORT Fourcc { ...@@ -115,6 +115,7 @@ class MEDIA_GPU_EXPORT Fourcc {
// Constructor for invalid Fourcc. // Constructor for invalid Fourcc.
Fourcc(); Fourcc();
explicit Fourcc(Fourcc::Value fourcc); explicit Fourcc(Fourcc::Value fourcc);
Fourcc& operator=(const Fourcc& fourcc);
~Fourcc(); ~Fourcc();
bool operator==(const Fourcc& rhs) const { return value_ == rhs.value_; } bool operator==(const Fourcc& rhs) const { return value_ == rhs.value_; }
...@@ -163,7 +164,7 @@ class MEDIA_GPU_EXPORT Fourcc { ...@@ -163,7 +164,7 @@ class MEDIA_GPU_EXPORT Fourcc {
std::string ToString() const; std::string ToString() const;
private: private:
const Value value_; Value value_;
}; };
MEDIA_GPU_EXPORT bool operator==(uint32_t lhs, const Fourcc& rhs); MEDIA_GPU_EXPORT bool operator==(uint32_t lhs, const Fourcc& rhs);
......
// Copyright 2019 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 "media/gpu/chromeos/gpu_buffer_layout.h"
#include <sstream>
#include "media/gpu/macros.h"
namespace media {
namespace {
template <class T>
std::string VectorToString(const std::vector<T>& vec) {
std::ostringstream result;
std::string delim;
result << "[";
for (auto& v : vec) {
result << delim << v;
if (delim.size() == 0)
delim = ", ";
}
result << "]";
return result.str();
}
} // namespace
// static
base::Optional<GpuBufferLayout> GpuBufferLayout::Create(
const Fourcc& fourcc,
const gfx::Size& size,
const std::vector<ColorPlaneLayout>& planes) {
// TODO(akahuang): Check planes.size() is equal to the expected value
// according to |fourcc|.
if (!fourcc || size.IsEmpty() || planes.size() == 0) {
VLOGF(1) << "Invalid parameters. fourcc: " << fourcc.ToString()
<< ", size: " << size.ToString()
<< ", planes: " << VectorToString(planes);
return base::nullopt;
}
return GpuBufferLayout(fourcc, size, planes);
}
GpuBufferLayout::GpuBufferLayout(const Fourcc& fourcc,
const gfx::Size& size,
const std::vector<ColorPlaneLayout>& planes)
: fourcc_(fourcc), size_(size), planes_(planes) {}
GpuBufferLayout::~GpuBufferLayout() = default;
GpuBufferLayout::GpuBufferLayout(const GpuBufferLayout&) = default;
GpuBufferLayout::GpuBufferLayout(GpuBufferLayout&&) = default;
GpuBufferLayout& GpuBufferLayout::operator=(const GpuBufferLayout& other) =
default;
bool GpuBufferLayout::operator==(const GpuBufferLayout& rhs) const {
return fourcc_ == rhs.fourcc_ && size_ == rhs.size_ && planes_ == rhs.planes_;
}
bool GpuBufferLayout::operator!=(const GpuBufferLayout& rhs) const {
return !(*this == rhs);
}
std::ostream& operator<<(std::ostream& ostream, const GpuBufferLayout& layout) {
ostream << "GpuBufferLayout(fourcc: " << layout.fourcc().ToString()
<< ", size: " << layout.size().ToString()
<< ", planes (stride, offset, size): "
<< VectorToString(layout.planes());
return ostream;
}
} // namespace media
// Copyright 2019 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 MEDIA_GPU_CHROMEOS_GPU_BUFFER_LAYOUT_H_
#define MEDIA_GPU_CHROMEOS_GPU_BUFFER_LAYOUT_H_
#include <ostream>
#include <string>
#include <vector>
#include "base/optional.h"
#include "media/base/color_plane_layout.h"
#include "media/gpu/chromeos/fourcc.h"
#include "media/gpu/media_gpu_export.h"
#include "ui/gfx/geometry/size.h"
namespace media {
class MEDIA_GPU_EXPORT GpuBufferLayout {
public:
static base::Optional<GpuBufferLayout> Create(
const Fourcc& fourcc,
const gfx::Size& size,
const std::vector<ColorPlaneLayout>& planes);
GpuBufferLayout() = delete;
GpuBufferLayout(const GpuBufferLayout&);
GpuBufferLayout(GpuBufferLayout&&);
GpuBufferLayout& operator=(const GpuBufferLayout&);
~GpuBufferLayout();
bool operator==(const GpuBufferLayout& rhs) const;
bool operator!=(const GpuBufferLayout& rhs) const;
const Fourcc& fourcc() const { return fourcc_; }
const gfx::Size& size() const { return size_; }
const std::vector<ColorPlaneLayout>& planes() const { return planes_; }
private:
GpuBufferLayout(const Fourcc& fourcc,
const gfx::Size& size,
const std::vector<ColorPlaneLayout>& planes);
// Fourcc format of the buffer.
Fourcc fourcc_;
// Width and height of the buffer in pixels. This must include pixel
// data for the whole image; i.e. for YUV formats with subsampled chroma
// planes, in the case that the visible portion of the image does not line up
// on a sample boundary, |size_| must be rounded up appropriately and
// the pixel data provided for the odd pixels.
gfx::Size size_;
// Layout property for each color planes, e.g. stride and buffer offset.
std::vector<ColorPlaneLayout> planes_;
};
// Outputs GpuBufferLayout to stream.
MEDIA_GPU_EXPORT std::ostream& operator<<(std::ostream& ostream,
const GpuBufferLayout& layout);
} // namespace media
#endif // MEDIA_GPU_CHROMEOS_GPU_BUFFER_LAYOUT_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment