Commit 0c93bcb5 authored by Jonah Chin's avatar Jonah Chin Committed by Commit Bot

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/+/2419653Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Commit-Queue: Jonah Chin <jochin@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#826449}
parent e18cee67
......@@ -298,11 +298,6 @@ void PaintImage::FlushPendingSkiaOps() {
texture_backing_->FlushPendingSkiaOps();
}
bool PaintImage::HasExclusiveTextureAccess() const {
DCHECK(IsTextureBacked());
return texture_backing_->unique();
}
int PaintImage::width() const {
return paint_worklet_input_
? static_cast<int>(paint_worklet_input_->GetSize().width())
......
......@@ -235,11 +235,12 @@ class CC_PAINT_EXPORT PaintImage {
int src_x,
int src_y) const;
SkImageInfo GetSkImageInfo() const;
// Returned mailbox must not outlive this PaintImage.
gpu::Mailbox GetMailbox() const;
Id stable_id() const { return id_; }
const sk_sp<SkImage>& GetSkImage() const;
gpu::Mailbox GetMailbox() const;
SkImageInfo GetSkImageInfo() const;
AnimationType animation_type() const { return animation_type_; }
CompletionState completion_state() const { return completion_state_; }
bool is_multipart() const { return is_multipart_; }
......@@ -262,7 +263,6 @@ class CC_PAINT_EXPORT PaintImage {
// Skia internally buffers commands and flushes them as necessary but there
// are some cases where we need to force a flush.
void FlushPendingSkiaOps();
bool HasExclusiveTextureAccess() const;
int width() const;
int height() const;
SkColorSpace* color_space() const {
......
......@@ -1431,9 +1431,14 @@ void DrawImageOp::RasterWithFlags(const DrawImageOp* op,
canvas->scale(1.f / op->scale_adjustment.width(),
1.f / op->scale_adjustment.height());
}
auto sk_image = op->image.IsTextureBacked()
? op->image.GetAcceleratedSkImage()
: op->image.GetSwSkImage();
sk_sp<SkImage> sk_image;
if (op->image.IsTextureBacked()) {
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);
return;
}
......@@ -1505,9 +1510,13 @@ void DrawImageRectOp::RasterWithFlags(const DrawImageRectOp* op,
if (!params.image_provider) {
SkRect adjusted_src = AdjustSrcRectForScale(op->src, op->scale_adjustment);
flags->DrawToSk(canvas, [op, adjusted_src](SkCanvas* c, const SkPaint& p) {
auto sk_image = op->image.IsTextureBacked()
? op->image.GetAcceleratedSkImage()
: op->image.GetSwSkImage();
sk_sp<SkImage> sk_image;
if (op->image.IsTextureBacked()) {
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,
op->constraint);
});
......
......@@ -1347,8 +1347,9 @@ void WebMediaPlayerImpl::Paint(cc::PaintCanvas* canvas,
if (video_frame && video_frame->HasTextures()) {
if (!raster_context_provider_)
return; // Unable to get/create a shared main thread context.
if (!raster_context_provider_->GrContext())
return; // The context has been lost since and can't setup a GrContext.
DCHECK(
raster_context_provider_->ContextCapabilities().supports_oop_raster ||
raster_context_provider_->GrContext());
}
if (out_metadata && video_frame) {
// WebGL last-uploaded-frame-metadata API enabled. https://crbug.com/639174
......
......@@ -41,6 +41,7 @@ class RasterContextProvider;
}
namespace media {
class VideoTextureBacking;
// Handles rendering of VideoFrames to PaintCanvases.
class MEDIA_EXPORT PaintCanvasVideoRenderer {
......@@ -211,22 +212,15 @@ class MEDIA_EXPORT PaintCanvasVideoRenderer {
// to the visible size of the VideoFrame. Its contents are generated lazily.
cc::PaintImage paint_image;
// The context provider used to generate |source_mailbox| and
// |source_texture|. This is only set if the VideoFrame was texture-backed.
scoped_refptr<viz::RasterContextProvider> raster_context_provider;
// 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 backing for the source texture. This is also responsible for managing
// the lifetime of the texture.
sk_sp<VideoTextureBacking> texture_backing;
// 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.
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.
gfx::Size coded_size;
......@@ -235,10 +229,6 @@ class MEDIA_EXPORT PaintCanvasVideoRenderer {
// This is only set if the VideoFrame was texture-backed.
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
// no external users have access to this resource via SkImage. Returns true
// if the existing resource can be recycled.
......@@ -266,6 +256,8 @@ class MEDIA_EXPORT PaintCanvasVideoRenderer {
unsigned int type,
bool flip_y);
bool CacheBackingWrapsTexture() const;
base::Optional<Cache> cache_;
// If |cache_| is not used for a while, it's deleted to save memory.
......
......@@ -377,8 +377,8 @@ gpu::ContextSupport* ContextProviderCommandBuffer::ContextSupport() {
class GrDirectContext* ContextProviderCommandBuffer::GrContext() {
DCHECK(bind_tried_);
DCHECK_EQ(bind_result_, gpu::ContextResult::kSuccess);
DCHECK(support_grcontext_);
DCHECK(ContextSupport()->HasGrContextSupport());
if (!support_grcontext_ || !ContextSupport()->HasGrContextSupport())
return nullptr;
CheckValidThreadOrLockAcquired();
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