Commit e8d10268 authored by Jonah Chin's avatar Jonah Chin Committed by Chromium LUCI CQ

Reland "Introduce mailbox-based version of VideoTextureBacking"

This is a reland of 0c93bcb5

This change depends on an earlier change that has been relanded.
https://chromium-review.googlesource.com/c/chromium/src/+/2634055
This one can now reland too.

Original change's description:
> Introduce mailbox-based version of VideoTextureBacking
>
> This CL introduces an OOPR compatible version of VideoTextureBacking and
> updates PaintCanvasVideoRenderer::UpdateLastImage() to use this new
> version in the OOPR codepath.
>
> More details about overall PaintImage effort: crbug.com/1023259
> Info about the OOPR-Canvas2D project: crbug.com/1018894
>
> Bug: 1115217
> Change-Id: I4590cf16d6faef0e5575b0b4006ea88de89aa13d
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2419653
> Reviewed-by: Khushal <khushalsagar@chromium.org>
> Reviewed-by: Dale Curtis <dalecurtis@chromium.org>
> Commit-Queue: Jonah Chin <jochin@microsoft.com>
> Cr-Commit-Position: refs/heads/master@{#826449}

Bug: 1115217
Change-Id: I7350332bad441440b69c7b472cbf08074a33304e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2640815Reviewed-by: default avatarVasiliy Telezhnikov <vasilyt@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarSunny Sachanandani <sunnyps@chromium.org>
Commit-Queue: Jonah Chin <jochin@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#845358}
parent 0fc3eb77
...@@ -298,11 +298,6 @@ void PaintImage::FlushPendingSkiaOps() { ...@@ -298,11 +298,6 @@ void PaintImage::FlushPendingSkiaOps() {
texture_backing_->FlushPendingSkiaOps(); texture_backing_->FlushPendingSkiaOps();
} }
bool PaintImage::HasExclusiveTextureAccess() const {
DCHECK(IsTextureBacked());
return texture_backing_->unique();
}
int PaintImage::width() const { int PaintImage::width() const {
return paint_worklet_input_ return paint_worklet_input_
? static_cast<int>(paint_worklet_input_->GetSize().width()) ? static_cast<int>(paint_worklet_input_->GetSize().width())
......
...@@ -239,10 +239,11 @@ class CC_PAINT_EXPORT PaintImage { ...@@ -239,10 +239,11 @@ class CC_PAINT_EXPORT PaintImage {
int src_x, int src_x,
int src_y) const; int src_y) const;
SkImageInfo GetSkImageInfo() const; // Returned mailbox must not outlive this PaintImage.
gpu::Mailbox GetMailbox() const;
Id stable_id() const { return id_; } Id stable_id() const { return id_; }
gpu::Mailbox GetMailbox() const; SkImageInfo GetSkImageInfo() const;
AnimationType animation_type() const { return animation_type_; } AnimationType animation_type() const { return animation_type_; }
CompletionState completion_state() const { return completion_state_; } CompletionState completion_state() const { return completion_state_; }
bool is_multipart() const { return is_multipart_; } bool is_multipart() const { return is_multipart_; }
...@@ -265,7 +266,6 @@ class CC_PAINT_EXPORT PaintImage { ...@@ -265,7 +266,6 @@ class CC_PAINT_EXPORT PaintImage {
// Skia internally buffers commands and flushes them as necessary but there // Skia internally buffers commands and flushes them as necessary but there
// are some cases where we need to force a flush. // are some cases where we need to force a flush.
void FlushPendingSkiaOps(); void FlushPendingSkiaOps();
bool HasExclusiveTextureAccess() const;
int width() const; int width() const;
int height() const; int height() const;
SkColorSpace* color_space() const { SkColorSpace* color_space() const {
......
...@@ -1475,9 +1475,14 @@ void DrawImageOp::RasterWithFlags(const DrawImageOp* op, ...@@ -1475,9 +1475,14 @@ void DrawImageOp::RasterWithFlags(const DrawImageOp* op,
canvas->scale(1.f / op->scale_adjustment.width(), canvas->scale(1.f / op->scale_adjustment.width(),
1.f / op->scale_adjustment.height()); 1.f / op->scale_adjustment.height());
} }
auto sk_image = op->image.IsTextureBacked() sk_sp<SkImage> sk_image;
? op->image.GetAcceleratedSkImage() if (op->image.IsTextureBacked()) {
: op->image.GetSwSkImage(); sk_image = op->image.GetAcceleratedSkImage();
DCHECK(sk_image || !canvas->recordingContext());
}
if (!sk_image)
sk_image = op->image.GetSwSkImage();
canvas->drawImage(sk_image.get(), op->left, op->top, &paint); canvas->drawImage(sk_image.get(), op->left, op->top, &paint);
return; return;
} }
...@@ -1548,9 +1553,13 @@ void DrawImageRectOp::RasterWithFlags(const DrawImageRectOp* op, ...@@ -1548,9 +1553,13 @@ void DrawImageRectOp::RasterWithFlags(const DrawImageRectOp* op,
if (!params.image_provider) { if (!params.image_provider) {
SkRect adjusted_src = AdjustSrcRectForScale(op->src, op->scale_adjustment); SkRect adjusted_src = AdjustSrcRectForScale(op->src, op->scale_adjustment);
flags->DrawToSk(canvas, [op, adjusted_src](SkCanvas* c, const SkPaint& p) { flags->DrawToSk(canvas, [op, adjusted_src](SkCanvas* c, const SkPaint& p) {
auto sk_image = op->image.IsTextureBacked() sk_sp<SkImage> sk_image;
? op->image.GetAcceleratedSkImage() if (op->image.IsTextureBacked()) {
: op->image.GetSwSkImage(); sk_image = op->image.GetAcceleratedSkImage();
DCHECK(sk_image || !c->recordingContext());
}
if (!sk_image)
sk_image = op->image.GetSwSkImage();
c->drawImageRect(sk_image.get(), adjusted_src, op->dst, &p, c->drawImageRect(sk_image.get(), adjusted_src, op->dst, &p,
op->constraint); op->constraint);
}); });
......
...@@ -1356,8 +1356,10 @@ void WebMediaPlayerImpl::Paint(cc::PaintCanvas* canvas, ...@@ -1356,8 +1356,10 @@ void WebMediaPlayerImpl::Paint(cc::PaintCanvas* canvas,
if (video_frame && video_frame->HasTextures()) { if (video_frame && video_frame->HasTextures()) {
if (!raster_context_provider_) if (!raster_context_provider_)
return; // Unable to get/create a shared main thread context. return; // Unable to get/create a shared main thread context.
if (!raster_context_provider_->GrContext()) if (!raster_context_provider_->GrContext() &&
return; // The context has been lost since and can't setup a GrContext. !raster_context_provider_->ContextCapabilities().supports_oop_raster) {
return; // The context has been lost.
}
} }
if (out_metadata && video_frame) { if (out_metadata && video_frame) {
// WebGL last-uploaded-frame-metadata API enabled. https://crbug.com/639174 // WebGL last-uploaded-frame-metadata API enabled. https://crbug.com/639174
......
...@@ -41,6 +41,7 @@ class RasterContextProvider; ...@@ -41,6 +41,7 @@ class RasterContextProvider;
} }
namespace media { namespace media {
class VideoTextureBacking;
// Handles rendering of VideoFrames to PaintCanvases. // Handles rendering of VideoFrames to PaintCanvases.
class MEDIA_EXPORT PaintCanvasVideoRenderer { class MEDIA_EXPORT PaintCanvasVideoRenderer {
...@@ -211,22 +212,15 @@ class MEDIA_EXPORT PaintCanvasVideoRenderer { ...@@ -211,22 +212,15 @@ class MEDIA_EXPORT PaintCanvasVideoRenderer {
// to the visible size of the VideoFrame. Its contents are generated lazily. // to the visible size of the VideoFrame. Its contents are generated lazily.
cc::PaintImage paint_image; cc::PaintImage paint_image;
// The context provider used to generate |source_mailbox| and // The backing for the source texture. This is also responsible for managing
// |source_texture|. This is only set if the VideoFrame was texture-backed. // the lifetime of the texture.
scoped_refptr<viz::RasterContextProvider> raster_context_provider; sk_sp<VideoTextureBacking> texture_backing;
// The mailbox for the source texture. This can be either the source
// VideoFrame's texture (if |wraps_video_frame_texture| is true) or a newly
// allocated shared image (if |wraps_video_frame_texture| is false) if a
// copy or conversion was necessary.
// This is only set if the VideoFrame was texture-backed.
gpu::Mailbox source_mailbox;
// The texture ID created when importing |source_mailbox|. // The GL texture ID used in non-OOP code path.
// This is only set if the VideoFrame was texture-backed. // This is only set if the VideoFrame was texture-backed.
uint32_t source_texture = 0; uint32_t source_texture = 0;
// The allocated size of |source_mailbox|. // The allocated size of VideoFrame texture.
// This is only set if the VideoFrame was texture-backed. // This is only set if the VideoFrame was texture-backed.
gfx::Size coded_size; gfx::Size coded_size;
...@@ -235,10 +229,6 @@ class MEDIA_EXPORT PaintCanvasVideoRenderer { ...@@ -235,10 +229,6 @@ class MEDIA_EXPORT PaintCanvasVideoRenderer {
// This is only set if the VideoFrame was texture-backed. // This is only set if the VideoFrame was texture-backed.
gfx::Rect visible_rect; gfx::Rect visible_rect;
// Whether |source_mailbox| directly points to a texture of the VideoFrame
// (if true), or to an allocated shared image (if false).
bool wraps_video_frame_texture = false;
// Used to allow recycling of the previous shared image. This requires that // Used to allow recycling of the previous shared image. This requires that
// no external users have access to this resource via SkImage. Returns true // no external users have access to this resource via SkImage. Returns true
// if the existing resource can be recycled. // if the existing resource can be recycled.
...@@ -266,6 +256,8 @@ class MEDIA_EXPORT PaintCanvasVideoRenderer { ...@@ -266,6 +256,8 @@ class MEDIA_EXPORT PaintCanvasVideoRenderer {
unsigned int type, unsigned int type,
bool flip_y); bool flip_y);
bool CacheBackingWrapsTexture() const;
base::Optional<Cache> cache_; base::Optional<Cache> cache_;
// If |cache_| is not used for a while, it's deleted to save memory. // If |cache_| is not used for a while, it's deleted to save memory.
......
...@@ -377,8 +377,8 @@ gpu::ContextSupport* ContextProviderCommandBuffer::ContextSupport() { ...@@ -377,8 +377,8 @@ gpu::ContextSupport* ContextProviderCommandBuffer::ContextSupport() {
class GrDirectContext* ContextProviderCommandBuffer::GrContext() { class GrDirectContext* ContextProviderCommandBuffer::GrContext() {
DCHECK(bind_tried_); DCHECK(bind_tried_);
DCHECK_EQ(bind_result_, gpu::ContextResult::kSuccess); DCHECK_EQ(bind_result_, gpu::ContextResult::kSuccess);
DCHECK(support_grcontext_); if (!support_grcontext_ || !ContextSupport()->HasGrContextSupport())
DCHECK(ContextSupport()->HasGrContextSupport()); return nullptr;
CheckValidThreadOrLockAcquired(); CheckValidThreadOrLockAcquired();
if (gr_context_) if (gr_context_)
......
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