Commit 611e49df authored by Khushal Sagar's avatar Khushal Sagar Committed by Commit Bot

canvas2d: Fix readback for canvas frames on mac.

GLHelper assumes that the texture used in readback with it is always
GL_TEXTURE_2D which is not the case for resources creates for canvas2d
elements on mac using GL_TEXTURE_RECTANGLE_ARB.

R=ericrk@chromium.org, guidou@chromium.org

Bug: 1020796
Change-Id: Ic5a4b8e0ba5a0d61a8af43251438f5323b911fd5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1902506
Commit-Queue: Khushal <khushalsagar@chromium.org>
Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713649}
parent 4e807bc9
...@@ -95,9 +95,9 @@ class I420ConverterImpl : public I420Converter { ...@@ -95,9 +95,9 @@ class I420ConverterImpl : public I420Converter {
GLenum GetReadbackFormat() const override; GLenum GetReadbackFormat() const override;
protected: protected:
// Returns true if the planerizer should use the faster, two-pass shaders to // Returns true if the planerizer should use the faster, two-pass shaders
// generate the YUV planar outputs. If false, the source will be scanned three // to generate the YUV planar outputs. If false, the source will be
// times, once for each Y/U/V plane. // scanned three times, once for each Y/U/V plane.
bool use_mrt() const { return !v_planerizer_; } bool use_mrt() const { return !v_planerizer_; }
// Reallocates the intermediate and plane textures, if needed. // Reallocates the intermediate and plane textures, if needed.
...@@ -112,9 +112,9 @@ class I420ConverterImpl : public I420Converter { ...@@ -112,9 +112,9 @@ class I420ConverterImpl : public I420Converter {
private: private:
// These generate the Y/U/V planes. If MRT is being used, |y_planerizer_| // These generate the Y/U/V planes. If MRT is being used, |y_planerizer_|
// generates the Y and interim UV plane, |u_planerizer_| generates the final U // generates the Y and interim UV plane, |u_planerizer_| generates the
// and V planes, and |v_planerizer_| is unused. If MRT is not being used, each // final U and V planes, and |v_planerizer_| is unused. If MRT is not
// of these generates only one of the Y/U/V planes. // being used, each of these generates only one of the Y/U/V planes.
const std::unique_ptr<GLHelper::ScalerInterface> y_planerizer_; const std::unique_ptr<GLHelper::ScalerInterface> y_planerizer_;
const std::unique_ptr<GLHelper::ScalerInterface> u_planerizer_; const std::unique_ptr<GLHelper::ScalerInterface> u_planerizer_;
const std::unique_ptr<GLHelper::ScalerInterface> v_planerizer_; const std::unique_ptr<GLHelper::ScalerInterface> v_planerizer_;
...@@ -122,8 +122,8 @@ class I420ConverterImpl : public I420Converter { ...@@ -122,8 +122,8 @@ class I420ConverterImpl : public I420Converter {
// Intermediate texture, holding the scaler's output. // Intermediate texture, holding the scaler's output.
base::Optional<TextureHolder> intermediate_; base::Optional<TextureHolder> intermediate_;
// Intermediate texture, holding the UV interim output (if the MRT shader is // Intermediate texture, holding the UV interim output (if the MRT shader
// being used). // is being used).
base::Optional<ScopedTexture> uv_; base::Optional<ScopedTexture> uv_;
DISALLOW_COPY_AND_ASSIGN(I420ConverterImpl); DISALLOW_COPY_AND_ASSIGN(I420ConverterImpl);
...@@ -146,6 +146,7 @@ class GLHelper::CopyTextureToImpl ...@@ -146,6 +146,7 @@ class GLHelper::CopyTextureToImpl
~CopyTextureToImpl() { CancelRequests(); } ~CopyTextureToImpl() { CancelRequests(); }
void ReadbackTextureAsync(GLuint texture, void ReadbackTextureAsync(GLuint texture,
GLenum texture_target,
const gfx::Size& dst_size, const gfx::Size& dst_size,
unsigned char* out, unsigned char* out,
SkColorType color_type, SkColorType color_type,
...@@ -267,8 +268,8 @@ class GLHelper::CopyTextureToImpl ...@@ -267,8 +268,8 @@ class GLHelper::CopyTextureToImpl
CopyTextureToImpl* copy_impl_; CopyTextureToImpl* copy_impl_;
ReadbackSwizzle swizzle_; ReadbackSwizzle swizzle_;
// May be null if no scaling is required. This can be changed between calls // May be null if no scaling is required. This can be changed between
// to ReadbackYUV(). // calls to ReadbackYUV().
std::unique_ptr<GLHelper::ScalerInterface> scaler_; std::unique_ptr<GLHelper::ScalerInterface> scaler_;
// These are the output textures for each Y/U/V plane. // These are the output textures for each Y/U/V plane.
...@@ -366,6 +367,7 @@ void GLHelper::CopyTextureToImpl::ReadbackAsync( ...@@ -366,6 +367,7 @@ void GLHelper::CopyTextureToImpl::ReadbackAsync(
void GLHelper::CopyTextureToImpl::ReadbackTextureAsync( void GLHelper::CopyTextureToImpl::ReadbackTextureAsync(
GLuint texture, GLuint texture,
GLenum texture_target,
const gfx::Size& dst_size, const gfx::Size& dst_size,
unsigned char* out, unsigned char* out,
SkColorType color_type, SkColorType color_type,
...@@ -379,9 +381,10 @@ void GLHelper::CopyTextureToImpl::ReadbackTextureAsync( ...@@ -379,9 +381,10 @@ void GLHelper::CopyTextureToImpl::ReadbackTextureAsync(
IsBGRAReadbackSupported()) { IsBGRAReadbackSupported()) {
format = GL_BGRA_EXT; format = GL_BGRA_EXT;
} else { } else {
// Note: It's possible the GL implementation supports other readback types. // Note: It's possible the GL implementation supports other readback
// However, as of this writing, no caller of this method will request a // types. However, as of this writing, no caller of this method will
// different |color_type| (i.e., requiring using some other GL format). // request a different |color_type| (i.e., requiring using some other GL
// format).
std::move(callback).Run(false); std::move(callback).Run(false);
return; return;
} }
...@@ -389,12 +392,13 @@ void GLHelper::CopyTextureToImpl::ReadbackTextureAsync( ...@@ -389,12 +392,13 @@ void GLHelper::CopyTextureToImpl::ReadbackTextureAsync(
ScopedFramebuffer dst_framebuffer(gl_); ScopedFramebuffer dst_framebuffer(gl_);
ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_,
dst_framebuffer); dst_framebuffer);
ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); gl_->BindTexture(texture_target, texture);
gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
texture, 0); texture_target, texture, 0);
ReadbackAsync(dst_size, dst_size.width() * kBytesPerPixel, ReadbackAsync(dst_size, dst_size.width() * kBytesPerPixel,
dst_size.width() * kBytesPerPixel, out, format, dst_size.width() * kBytesPerPixel, out, format,
GL_UNSIGNED_BYTE, kBytesPerPixel, std::move(callback)); GL_UNSIGNED_BYTE, kBytesPerPixel, std::move(callback));
gl_->BindTexture(texture_target, 0);
} }
void GLHelper::CopyTextureToImpl::ReadbackDone(Request* finished_request, void GLHelper::CopyTextureToImpl::ReadbackDone(Request* finished_request,
...@@ -490,13 +494,14 @@ GLHelper::GLHelper(GLES2Interface* gl, gpu::ContextSupport* context_support) ...@@ -490,13 +494,14 @@ GLHelper::GLHelper(GLES2Interface* gl, gpu::ContextSupport* context_support)
GLHelper::~GLHelper() {} GLHelper::~GLHelper() {}
void GLHelper::ReadbackTextureAsync(GLuint texture, void GLHelper::ReadbackTextureAsync(GLuint texture,
GLenum texture_target,
const gfx::Size& dst_size, const gfx::Size& dst_size,
unsigned char* out, unsigned char* out,
SkColorType color_type, SkColorType color_type,
base::OnceCallback<void(bool)> callback) { base::OnceCallback<void(bool)> callback) {
InitCopyTextToImpl(); InitCopyTextToImpl();
copy_texture_to_impl_->ReadbackTextureAsync(texture, dst_size, out, copy_texture_to_impl_->ReadbackTextureAsync(
color_type, std::move(callback)); texture, texture_target, dst_size, out, color_type, std::move(callback));
} }
void GLHelper::InitCopyTextToImpl() { void GLHelper::InitCopyTextToImpl() {
...@@ -744,8 +749,8 @@ void GLHelper::CopyTextureToImpl::ReadbackYUVImpl::ReadbackYUV( ...@@ -744,8 +749,8 @@ void GLHelper::CopyTextureToImpl::ReadbackYUVImpl::ReadbackYUV(
I420ConverterImpl::Convert(texture, src_texture_size, gfx::Vector2dF(), I420ConverterImpl::Convert(texture, src_texture_size, gfx::Vector2dF(),
scaler_.get(), output_rect, y_, u_, v_); scaler_.get(), output_rect, y_, u_, v_);
// Read back planes, one at a time. Keep the video frame alive while doing the // Read back planes, one at a time. Keep the video frame alive while doing
// readback. // the readback.
const gfx::Rect paste_rect(paste_location, output_rect.size()); const gfx::Rect paste_rect(paste_location, output_rect.size());
const auto SetUpAndBindFramebuffer = [this](GLuint framebuffer, const auto SetUpAndBindFramebuffer = [this](GLuint framebuffer,
GLuint texture) { GLuint texture) {
......
...@@ -164,6 +164,7 @@ class VIZ_COMMON_EXPORT GLHelper { ...@@ -164,6 +164,7 @@ class VIZ_COMMON_EXPORT GLHelper {
// TODO(crbug.com/870036): DEPRECATED. This will be moved to be closer to its // TODO(crbug.com/870036): DEPRECATED. This will be moved to be closer to its
// one caller soon. // one caller soon.
void ReadbackTextureAsync(GLuint texture, void ReadbackTextureAsync(GLuint texture,
GLenum texture_target,
const gfx::Size& dst_size, const gfx::Size& dst_size,
unsigned char* out, unsigned char* out,
SkColorType color_type, SkColorType color_type,
......
...@@ -1009,7 +1009,7 @@ class GLHelperTest : public testing::Test { ...@@ -1009,7 +1009,7 @@ class GLHelperTest : public testing::Test {
base::RunLoop run_loop; base::RunLoop run_loop;
bool success = false; bool success = false;
helper_->ReadbackTextureAsync( helper_->ReadbackTextureAsync(
src_texture, src_size, pixels, color_type, src_texture, GL_TEXTURE_2D, src_size, pixels, color_type,
base::BindOnce( base::BindOnce(
[](bool* success, base::OnceClosure callback, bool result) { [](bool* success, base::OnceClosure callback, bool result) {
*success = result; *success = result;
......
...@@ -308,7 +308,7 @@ void CanvasCaptureHandler::ReadARGBPixelsAsync( ...@@ -308,7 +308,7 @@ void CanvasCaptureHandler::ReadARGBPixelsAsync(
DCHECK(result); DCHECK(result);
DCHECK(context_provider->GetGLHelper()); DCHECK(context_provider->GetGLHelper());
context_provider->GetGLHelper()->ReadbackTextureAsync( context_provider->GetGLHelper()->ReadbackTextureAsync(
texture_info.fID, image_size, texture_info.fID, texture_info.fTarget, image_size,
temp_argb_frame->visible_data(VideoFrame::kARGBPlane), kN32_SkColorType, temp_argb_frame->visible_data(VideoFrame::kARGBPlane), kN32_SkColorType,
WTF::Bind(&CanvasCaptureHandler::OnARGBPixelsReadAsync, WTF::Bind(&CanvasCaptureHandler::OnARGBPixelsReadAsync,
weak_ptr_factory_.GetWeakPtr(), image, temp_argb_frame, weak_ptr_factory_.GetWeakPtr(), image, temp_argb_frame,
......
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