Skip to content

Commit

Permalink
GLImageIOSurface: GLImageIOSurface::CopyTexImage and entrails
Browse files Browse the repository at this point in the history
This should have effects (it is removing now-dead code).

Now that macOS can assume the presence of ES3 raster contexts, and
therefore the ability to bind R16 and RG16 textures, we no longer
need to support YUV->RGB conversion in GLImageIOSurface.

Remove GLImageIOSurface::CopyTexImage, because it only existed to
support this path. Remove gl::YUVToRGBConverter, because it was only
being used by this path. Remove gfx::ColorTransform::GetShaderSource,
which was only being used by this path (WEBGL_webcodecs_video_frame
prototype work also uses it, but is not functional).

Bug: 1233228, 1310033
Change-Id: I8d5a8f817174a3f9470eb5096c21728f5a43d532
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3930906
Reviewed-by: Brandon Jones <bajones@chromium.org>
Commit-Queue: ccameron chromium <ccameron@chromium.org>
Reviewed-by: Dan Sanders <sandersd@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1054922}
  • Loading branch information
ccameron-chromium authored and Chromium LUCI CQ committed Oct 4, 2022
1 parent 7e906f9 commit 31a3117
Show file tree
Hide file tree
Showing 24 changed files with 30 additions and 1,018 deletions.
5 changes: 0 additions & 5 deletions gpu/command_buffer/service/gl_context_virtual.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ void GLContextVirtual::SetUnbindFboOnMakeCurrent() {
shared_context_->SetUnbindFboOnMakeCurrent();
}

gl::YUVToRGBConverter* GLContextVirtual::GetYUVToRGBConverter(
const gfx::ColorSpace& color_space) {
return shared_context_->GetYUVToRGBConverter(color_space);
}

void GLContextVirtual::ForceReleaseVirtuallyCurrent() {
shared_context_->OnReleaseVirtuallyCurrent(this);
}
Expand Down
2 changes: 0 additions & 2 deletions gpu/command_buffer/service/gl_context_virtual.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class GPU_GLES2_EXPORT GLContextVirtual : public gl::GLContext {
void SetSafeToForceGpuSwitch() override;
unsigned int CheckStickyGraphicsResetStatusImpl() override;
void SetUnbindFboOnMakeCurrent() override;
gl::YUVToRGBConverter* GetYUVToRGBConverter(
const gfx::ColorSpace& color_space) override;
void ForceReleaseVirtuallyCurrent() override;
#if BUILDFLAG(IS_MAC)
uint64_t BackpressureFenceCreate() override;
Expand Down
8 changes: 0 additions & 8 deletions media/base/media_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -915,14 +915,6 @@ BASE_FEATURE(kUseAlternateVideoDecoderImplementation,
#endif // BUILDFLAG(IS_CHROMEOS)
#endif // BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)

#if BUILDFLAG(IS_MAC)
// Enable binding multiple shared images to a single GpuMemoryBuffer for
// accelerated video decode using VideoToolbox.
BASE_FEATURE(kMultiPlaneVideoToolboxSharedImages,
"MultiPlaneVideoToolboxSharedImages",
base::FEATURE_ENABLED_BY_DEFAULT);
#endif // BUILDFLAG(IS_MAC)

#if BUILDFLAG(IS_WIN)
// Does NV12->NV12 video copy on the main thread right before the texture's
// used by GL.
Expand Down
4 changes: 0 additions & 4 deletions media/base/media_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,6 @@ MEDIA_EXPORT BASE_DECLARE_FEATURE(kUseAlternateVideoDecoderImplementation);
#endif // BUILDFLAG(IS_CHROMEOS)
#endif // BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)

#if BUILDFLAG(IS_MAC)
MEDIA_EXPORT BASE_DECLARE_FEATURE(kMultiPlaneVideoToolboxSharedImages);
#endif // BUILDFLAG(IS_MAC)

#if BUILDFLAG(IS_WIN)
MEDIA_EXPORT BASE_DECLARE_FEATURE(kDelayCopyNV12Textures);
MEDIA_EXPORT BASE_DECLARE_FEATURE(kDirectShowGetPhotoState);
Expand Down
37 changes: 7 additions & 30 deletions media/gpu/mac/vt_video_decode_accelerator_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2127,19 +2127,15 @@ bool VTVideoDecodeAccelerator::ProcessFrame(const Frame& frame) {
// Request new pictures.
picture_size_ = frame.image_size;

picture_format_ = PIXEL_FORMAT_RGBAF16;
picture_format_ = PIXEL_FORMAT_UNKNOWN;
if (config_.profile == VP9PROFILE_PROFILE2 ||
config_.profile == HEVCPROFILE_MAIN10 ||
config_.profile == HEVCPROFILE_REXT) {
buffer_format_ = gfx::BufferFormat::P010;
if (base::FeatureList::IsEnabled(kMultiPlaneVideoToolboxSharedImages)) {
picture_format_ = PIXEL_FORMAT_P016LE;
}
picture_format_ = PIXEL_FORMAT_P016LE;
} else {
buffer_format_ = gfx::BufferFormat::YUV_420_BIPLANAR;
if (base::FeatureList::IsEnabled(kMultiPlaneVideoToolboxSharedImages)) {
picture_format_ = PIXEL_FORMAT_NV12;
}
picture_format_ = PIXEL_FORMAT_NV12;
}

DVLOG(3) << "ProvidePictureBuffers(" << kNumPictureBuffers
Expand Down Expand Up @@ -2169,46 +2165,27 @@ bool VTVideoDecodeAccelerator::SendFrame(const Frame& frame) {

const gfx::ColorSpace color_space = GetImageBufferColorSpace(frame.image);
std::vector<gfx::BufferPlane> planes;
switch (picture_format_) {
case PIXEL_FORMAT_NV12:
case PIXEL_FORMAT_P016LE:
planes.push_back(gfx::BufferPlane::Y);
planes.push_back(gfx::BufferPlane::UV);
break;
case PIXEL_FORMAT_RGBAF16:
planes.push_back(gfx::BufferPlane::DEFAULT);
break;
default:
NOTREACHED();
break;
}

planes.push_back(gfx::BufferPlane::Y);
planes.push_back(gfx::BufferPlane::UV);
for (size_t plane = 0; plane < planes.size(); ++plane) {
const gfx::Size plane_size(
CVPixelBufferGetWidthOfPlane(frame.image.get(), plane),
CVPixelBufferGetHeightOfPlane(frame.image.get(), plane));
gfx::BufferFormat plane_buffer_format =
gpu::GetPlaneBufferFormat(planes[plane], buffer_format_);
// TODO(https://crbug.com/1108909): BGRA is not an appropriate value for
// these parameters.
const viz::ResourceFormat viz_resource_format =
(picture_format_ == PIXEL_FORMAT_RGBAF16)
? viz::ResourceFormat::RGBA_F16
: viz::GetResourceFormat(plane_buffer_format);
viz::GetResourceFormat(plane_buffer_format);
const GLenum gl_format = viz::GLDataFormat(viz_resource_format);

scoped_refptr<gl::GLImageIOSurface> gl_image(
gl::GLImageIOSurface::Create(plane_size, gl_format));
if (!gl_image->InitializeWithCVPixelBuffer(
frame.image.get(), plane,
gfx::GenericSharedMemoryId(g_cv_pixel_buffer_ids.GetNext()),
plane_buffer_format)) {
plane_buffer_format, color_space)) {
NOTIFY_STATUS("Failed to initialize GLImageIOSurface", PLATFORM_FAILURE,
SFT_PLATFORM_ERROR);
}
gl_image->DisableInUseByWindowServer();
gl_image->SetColorSpaceForYUVToRGBConversion(color_space);
gl_image->SetColorSpaceShallow(color_space);

if (picture_info->uses_shared_images) {
gpu::SharedImageStub* shared_image_stub = client_->GetSharedImageStub();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/worker_pool.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "ui/gfx/color_transform.h"

namespace blink {

Expand Down Expand Up @@ -248,12 +247,6 @@ WebGLWebCodecsVideoFrameHandle* WebGLWebCodecsVideoFrame::importVideoFrame(
MakeGarbageCollected<VideoColorSpace>(src_color_space);
video_frame_handle->setColorSpace(video_frame_color_space);

gfx::ColorSpace dst_color_space = gfx::ColorSpace::CreateSRGB();
std::unique_ptr<gfx::ColorTransform> color_transform(
gfx::ColorTransform::NewColorTransform(src_color_space, dst_color_space));
video_frame_handle->setColorConversionShaderFunc(
color_transform->GetShaderSource().c_str());

// Bookkeeping of imported video frames.
GLuint tex0 = info_array[0]->texture()->Object();
tex0_to_video_frame_map_.insert(tex0, frame);
Expand Down
3 changes: 2 additions & 1 deletion ui/accelerated_widget_mac/ca_layer_tree_unittest_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ @interface CALayer (Private)
CVPixelBufferCreateWithIOSurface(nullptr, io_surface, nullptr,
cv_pixel_buffer.InitializeInto());
gl_image->InitializeWithCVPixelBuffer(cv_pixel_buffer, 0,
gfx::GenericSharedMemoryId(), format);
gfx::GenericSharedMemoryId(), format,
gfx::ColorSpace::CreateREC709());
} else {
gl_image->Initialize(io_surface, 0, gfx::GenericSharedMemoryId(), format);
}
Expand Down
129 changes: 0 additions & 129 deletions ui/gfx/color_transform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,6 @@ class ColorTransformStep {
// Return true if this is a null transform.
virtual bool IsNull() { return false; }
virtual void Transform(ColorTransform::TriStim* color, size_t num) const = 0;
// In the shader, |hdr| will appear before |src|, so any helper functions that
// are created should be put in |hdr|. Any helper functions should have
// |step_index| included in the function name, to ensure that there are no
// naming conflicts.
virtual void AppendShaderSource(std::stringstream* hdr,
std::stringstream* src,
size_t step_index) const = 0;
virtual void AppendSkShaderSource(std::stringstream* src) const = 0;
};

Expand All @@ -214,7 +207,6 @@ class ColorTransformInternal : public ColorTransform {
step->Transform(colors, num);
}
}
std::string GetShaderSource() const override;
std::string GetSkShaderSource() const override;
bool IsIdentity() const override { return steps_.empty(); }
size_t NumberOfStepsForTesting() const override { return steps_.size(); }
Expand All @@ -235,9 +227,6 @@ class ColorTransformNull : public ColorTransformStep {
ColorTransformNull* GetNull() override { return this; }
bool IsNull() override { return true; }
void Transform(ColorTransform::TriStim* color, size_t num) const override {}
void AppendShaderSource(std::stringstream* hdr,
std::stringstream* src,
size_t step_index) const override {}
void AppendSkShaderSource(std::stringstream* src) const override {}
};

Expand All @@ -263,32 +252,6 @@ class ColorTransformMatrix : public ColorTransformStep {
}
}

void AppendShaderSource(std::stringstream* hdr,
std::stringstream* src,
size_t step_index) const override {
*src << " color = mat3(";
*src << matrix_.rc(0, 0) << ", " << matrix_.rc(1, 0) << ", "
<< matrix_.rc(2, 0) << ",";
*src << endl;
*src << " ";
*src << matrix_.rc(0, 1) << ", " << matrix_.rc(1, 1) << ", "
<< matrix_.rc(2, 1) << ",";
*src << endl;
*src << " ";
*src << matrix_.rc(0, 2) << ", " << matrix_.rc(1, 2) << ", "
<< matrix_.rc(2, 2) << ")";
*src << " * color;" << endl;

// Only print the translational component if it isn't the identity.
if (matrix_.rc(0, 3) != 0.f || matrix_.rc(1, 3) != 0.f ||
matrix_.rc(2, 3) != 0.f) {
*src << " color += vec3(";
*src << matrix_.rc(0, 3) << ", " << matrix_.rc(1, 3) << ", "
<< matrix_.rc(2, 3);
*src << ");" << endl;
}
}

void AppendSkShaderSource(std::stringstream* src) const override {
*src << " color = half4x4(";
*src << matrix_.rc(0, 0) << ", " << matrix_.rc(1, 0) << ", "
Expand Down Expand Up @@ -339,27 +302,6 @@ class ColorTransformPerChannelTransferFn : public ColorTransformStep {
}
}

void AppendShaderSource(std::stringstream* hdr,
std::stringstream* src,
size_t step_index) const override {
*hdr << "float TransferFn" << step_index << "(float v) {" << endl;
AppendTransferShaderSource(hdr, true /* is_glsl */);
*hdr << " return v;" << endl;
*hdr << "}" << endl;
if (extended_) {
*src << " color.r = sign(color.r) * TransferFn" << step_index
<< "(abs(color.r));" << endl;
*src << " color.g = sign(color.g) * TransferFn" << step_index
<< "(abs(color.g));" << endl;
*src << " color.b = sign(color.b) * TransferFn" << step_index
<< "(abs(color.b));" << endl;
} else {
*src << " color.r = TransferFn" << step_index << "(color.r);" << endl;
*src << " color.g = TransferFn" << step_index << "(color.g);" << endl;
*src << " color.b = TransferFn" << step_index << "(color.b);" << endl;
}
}

void AppendSkShaderSource(std::stringstream* src) const override {
if (extended_) {
*src << "{ half v = abs(color.r);" << endl;
Expand Down Expand Up @@ -900,32 +842,6 @@ class ColorTransformFromBT2020CL : public ColorTransformStep {
YUV[i] = ColorTransform::TriStim(R_Y + Y, Y, B_Y + Y);
}
}
void AppendShaderSource(std::stringstream* hdr,
std::stringstream* src,
size_t step_index) const override {
*hdr << "vec3 BT2020_YUV_to_RYB_Step" << step_index << "(vec3 color) {"
<< endl;
*hdr << " float Y = color.x;" << endl;
*hdr << " float U = color.y - 0.5;" << endl;
*hdr << " float V = color.z - 0.5;" << endl;
*hdr << " float B_Y = 0.0;" << endl;
*hdr << " float R_Y = 0.0;" << endl;
*hdr << " if (U <= 0.0) {" << endl;
*hdr << " B_Y = U * (-2.0 * -0.9702);" << endl;
*hdr << " } else {" << endl;
*hdr << " B_Y = U * (2.0 * 0.7910);" << endl;
*hdr << " }" << endl;
*hdr << " if (V <= 0.0) {" << endl;
*hdr << " R_Y = V * (-2.0 * -0.8591);" << endl;
*hdr << " } else {" << endl;
*hdr << " R_Y = V * (2.0 * 0.4969);" << endl;
*hdr << " }" << endl;
*hdr << " return vec3(R_Y + Y, Y, B_Y + Y);" << endl;
*hdr << "}" << endl;

*src << " color.rgb = BT2020_YUV_to_RYB_Step" << step_index
<< "(color.rgb);" << endl;
}

void AppendSkShaderSource(std::stringstream* src) const override {
NOTREACHED();
Expand Down Expand Up @@ -953,21 +869,6 @@ class ColorTransformHLGOOTF : public ColorTransformStep {
color[i].Scale(powf(L, gamma_minus_one_));
}
}
void AppendShaderSource(std::stringstream* hdr,
std::stringstream* src,
size_t step_index) const override {
*hdr << "vec3 ToneMapStep" << step_index << "(vec3 color) {\n"
<< " vec3 result = color;\n"
<< " vec3 luma_vec = vec3(" << kLr << ", " << kLg << ", " << kLb
<< ");\n"
<< " float L = dot(color, luma_vec);\n"
<< " if (L > 0.0) {\n"
<< " result *= pow(L, " << gamma_minus_one_ << ");\n"
<< " }\n"
<< " return result;\n"
<< "}\n";
*src << " color.rgb = ToneMapStep" << step_index << "(color.rgb);\n";
}
void AppendSkShaderSource(std::stringstream* src) const override {
*src << "{\n"
<< " half4 luma_vec = half4(" << kLr << ", " << kLg << ", " << kLb
Expand Down Expand Up @@ -1006,22 +907,6 @@ class ColorTransformToneMapInRec2020Linear : public ColorTransformStep {
color[i].Scale((1.f + a_ * L) / (1.f + b_ * L));
}
}
void AppendShaderSource(std::stringstream* hdr,
std::stringstream* src,
size_t step_index) const override {
*hdr << "vec3 ToneMapStep" << step_index << "(vec3 color) {\n"
<< " vec3 result = color;\n"
<< " vec3 luma_vec = vec3(" << kLr << ", " << kLg << ", " << kLb
<< ");\n"
<< " float L = dot(color, luma_vec);\n"
<< " if (L > 0.0) {\n"
<< " result *= (1.0 + " << a_ << "*L) / \n"
<< " (1.0 + " << b_ << "*L);\n"
<< " }\n"
<< " return result;\n"
<< "}\n";
*src << " color.rgb = ToneMapStep" << step_index << "(color.rgb);\n";
}
void AppendSkShaderSource(std::stringstream* src) const override {
*src << "{\n"
<< " half4 luma_vec = half4(" << kLr << ", " << kLg << ", " << kLb
Expand Down Expand Up @@ -1232,20 +1117,6 @@ ColorTransformInternal::ColorTransformInternal(const ColorSpace& src,
Simplify();
}

std::string ColorTransformInternal::GetShaderSource() const {
std::stringstream hdr;
std::stringstream src;
InitStringStream(&hdr);
InitStringStream(&src);
src << "vec3 DoColorConversion(vec3 color) {" << endl;
size_t step_index = 0;
for (const auto& step : steps_)
step->AppendShaderSource(&hdr, &src, step_index++);
src << " return color;" << endl;
src << "}" << endl;
return hdr.str() + src.str();
}

std::string ColorTransformInternal::GetSkShaderSource() const {
std::stringstream src;
InitStringStream(&src);
Expand Down
4 changes: 0 additions & 4 deletions ui/gfx/color_transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ class COLOR_SPACE_EXPORT ColorTransform {
// Perform transformation of colors, |colors| is both input and output.
virtual void Transform(TriStim* colors, size_t num) const = 0;

// Return GLSL shader source that defines a function DoColorConversion that
// converts a vec3 according to this transform.
virtual std::string GetShaderSource() const = 0;

// Return SKSL shader sources that modifies an "inout half4 color" according
// to this transform. Input and output are non-premultiplied alpha.
virtual std::string GetSkShaderSource() const = 0;
Expand Down
Loading

0 comments on commit 31a3117

Please sign in to comment.