Commit 9392e786 authored by Michael Ludwig's avatar Michael Ludwig Committed by Commit Bot

SkiaRenderer: Update texture draw quads to new API

Change-Id: Icc26306afd6c8ba25d81c96162ee4f3af671d936
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1521276
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: default avatarweiliangc <weiliangc@chromium.org>
Reviewed-by: default avatarJonathan Backer <backer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644894}
parent 9bebc67b
......@@ -552,6 +552,7 @@ ResourceMetadata DisplayResourceProvider::LockForExternalUse(ResourceId id) {
metadata.resource_format = resource->transferable.format;
metadata.mailbox_holder.sync_token = resource->sync_token();
metadata.color_space = resource->transferable.color_space;
metadata.origin = kTopLeft_GrSurfaceOrigin;
resource->locked_for_external_use = true;
return metadata;
......@@ -879,7 +880,8 @@ DisplayResourceProvider::ScopedSamplerGL::~ScopedSamplerGL() = default;
DisplayResourceProvider::ScopedReadLockSkImage::ScopedReadLockSkImage(
DisplayResourceProvider* resource_provider,
ResourceId resource_id,
SkAlphaType alpha_type)
SkAlphaType alpha_type,
GrSurfaceOrigin origin)
: resource_provider_(resource_provider), resource_id_(resource_id) {
const ChildResource* resource = resource_provider->LockForRead(resource_id);
DCHECK(resource);
......@@ -902,7 +904,7 @@ DisplayResourceProvider::ScopedReadLockSkImage::ScopedReadLockSkImage(
GrMipMapped::kNo, texture_info);
sk_image_ = SkImage::MakeFromTexture(
resource_provider->compositor_context_provider_->GrContext(),
backend_texture, kTopLeft_GrSurfaceOrigin,
backend_texture, origin,
ResourceFormatToClosestSkColorType(!resource_provider->IsSoftware(),
resource->transferable.format),
alpha_type, resource->transferable.color_space.ToSkColorSpace());
......@@ -921,6 +923,7 @@ DisplayResourceProvider::ScopedReadLockSkImage::ScopedReadLockSkImage(
return;
}
DCHECK(origin == kTopLeft_GrSurfaceOrigin);
SkBitmap sk_bitmap;
resource_provider->PopulateSkBitmapWithResource(&sk_bitmap, resource);
sk_bitmap.setImmutable();
......@@ -954,9 +957,11 @@ ResourceMetadata DisplayResourceProvider::LockSetForExternalUse::LockResource(
sk_sp<SkImage>
DisplayResourceProvider::LockSetForExternalUse::LockResourceAndCreateSkImage(
ResourceId id,
SkAlphaType alpha_type) {
SkAlphaType alpha_type,
GrSurfaceOrigin origin) {
auto metadata = LockResource(id);
metadata.alpha_type = alpha_type;
metadata.origin = origin;
auto& resource_sk_image = resource_provider_->resource_sk_images_[id];
if (!resource_sk_image) {
resource_sk_image =
......
......@@ -176,7 +176,8 @@ class VIZ_SERVICE_EXPORT DisplayResourceProvider
public:
ScopedReadLockSkImage(DisplayResourceProvider* resource_provider,
ResourceId resource_id,
SkAlphaType alpha_type = kPremul_SkAlphaType);
SkAlphaType alpha_type = kPremul_SkAlphaType,
GrSurfaceOrigin origin = kTopLeft_GrSurfaceOrigin);
~ScopedReadLockSkImage();
const SkImage* sk_image() const { return sk_image_.get(); }
......@@ -207,7 +208,8 @@ class VIZ_SERVICE_EXPORT DisplayResourceProvider
// Lock a resource and create a SkImage from it by using
// Client::CreateImage.
sk_sp<SkImage> LockResourceAndCreateSkImage(ResourceId resource_id,
SkAlphaType alpha_type);
SkAlphaType alpha_type,
GrSurfaceOrigin origin);
// Unlock all locked resources with a |sync_token|.
// See UnlockForExternalUse for the detail. All resources must be unlocked
......
......@@ -5,6 +5,7 @@
#ifndef COMPONENTS_VIZ_SERVICE_DISPLAY_RESOURCE_METADATA_H_
#define COMPONENTS_VIZ_SERVICE_DISPLAY_RESOURCE_METADATA_H_
#include "GrTypes.h"
#include "components/viz/common/resources/resource_format.h"
#include "components/viz/service/viz_service_export.h"
#include "gpu/command_buffer/common/mailbox_holder.h"
......@@ -36,6 +37,9 @@ struct VIZ_SERVICE_EXPORT ResourceMetadata {
// Whether resource is premultiplied.
SkAlphaType alpha_type;
// If the SkImage should use top-left or bottom-left for (0,0) uv
GrSurfaceOrigin origin;
};
} // namespace viz
......
......@@ -115,13 +115,11 @@ class VIZ_SERVICE_EXPORT SkiaRenderer : public DirectRenderer {
DrawQuadParams CalculateDrawQuadParams(const DrawQuad* quad,
const gfx::QuadF* draw_region);
// In most cases alpha should be params.opacity, but some quad types apply
// transparency at a different point in the rendering.
SkCanvas::ImageSetEntry MakeEntry(const DrawQuadParams& params,
const SkImage* image,
const gfx::RectF& src,
int matrix_index,
float alpha);
bool use_opacity = true);
bool MustFlushBatchedQuads(const DrawQuad* new_quad,
const DrawQuadParams& params);
......@@ -130,6 +128,13 @@ class VIZ_SERVICE_EXPORT SkiaRenderer : public DirectRenderer {
const gfx::RectF& tex_coords);
void FlushBatchedQuads();
// Utility to make a single ImageSetEntry and draw it with the complex paint.
// Assumes the paint applies the param's opacity.
void DrawSingleImage(const DrawQuadParams& params,
const SkImage* image,
const gfx::RectF& src,
const SkPaint* paint);
// DebugBorder, Picture, RPDQ, and SolidColor quads cannot be batched. They
// either are not textures (debug, picture, solid color), or it's very likely
// the texture will have advanced paint effects (rpdq)
......@@ -141,9 +146,10 @@ class VIZ_SERVICE_EXPORT SkiaRenderer : public DirectRenderer {
SkPaint* paint);
void DrawSolidColorQuad(const SolidColorDrawQuad* quad, SkPaint* paint);
void DrawTextureQuad(const TextureDrawQuad* quad, SkPaint* paint);
void DrawStreamVideoQuad(const StreamVideoDrawQuad* quad,
const DrawQuadParams& params);
void DrawTextureQuad(const TextureDrawQuad* quad,
const DrawQuadParams& params);
void DrawTileDrawQuad(const TileDrawQuad* quad, const DrawQuadParams& params);
void DrawYUVVideoQuad(const YUVVideoDrawQuad* quad,
const DrawQuadParams& params);
......
......@@ -66,7 +66,7 @@ class SkiaOutputSurfaceImpl::PromiseTextureHelper {
auto* helper = new PromiseTextureHelper(
impl->impl_on_gpu_->weak_ptr(), metadata.size, metadata.resource_format,
metadata.mailbox_holder, metadata.color_space.ToSkColorSpace(),
metadata.alpha_type);
metadata.alpha_type, metadata.origin);
return helper->MakePromiseSkImage(impl);
}
......@@ -108,14 +108,16 @@ class SkiaOutputSurfaceImpl::PromiseTextureHelper {
ResourceFormat resource_format,
const gpu::MailboxHolder& mailbox_holder,
sk_sp<SkColorSpace> color_space,
SkAlphaType alpha_type)
SkAlphaType alpha_type,
GrSurfaceOrigin origin)
: impl_on_gpu_(impl_on_gpu),
size_(size),
resource_format_(resource_format),
render_pass_id_(0u),
mailbox_holder_(mailbox_holder),
color_space_(std::move(color_space)),
alpha_type_(alpha_type) {}
alpha_type_(alpha_type),
origin_(origin) {}
~PromiseTextureHelper() = default;
sk_sp<SkImage> MakePromiseSkImage(SkiaOutputSurfaceImpl* impl) {
......@@ -125,9 +127,8 @@ class SkiaOutputSurfaceImpl::PromiseTextureHelper {
resource_format_,
render_pass_id_ ? GL_TEXTURE_2D : mailbox_holder_.texture_target);
return impl->recorder_->makePromiseTexture(
backend_format, size_.width(), size_.height(), mipmap_,
kTopLeft_GrSurfaceOrigin /* origin */, color_type, alpha_type_,
color_space_, PromiseTextureHelper::Fulfill,
backend_format, size_.width(), size_.height(), mipmap_, origin_,
color_type, alpha_type_, color_space_, PromiseTextureHelper::Fulfill,
PromiseTextureHelper::Release, PromiseTextureHelper::Done, this);
}
......@@ -174,6 +175,7 @@ class SkiaOutputSurfaceImpl::PromiseTextureHelper {
const GrMipMapped mipmap_ = GrMipMapped::kNo;
const sk_sp<SkColorSpace> color_space_;
const SkAlphaType alpha_type_ = kPremul_SkAlphaType;
const GrSurfaceOrigin origin_ = kTopLeft_GrSurfaceOrigin;
// If non-null, an outstanding SharedImageRepresentation that must be freed on
// Release. Only written / read from GPU thread.
......@@ -212,6 +214,7 @@ class SkiaOutputSurfaceImpl::YUVAPromiseTextureHelper {
// called. It will delete contexts.
const auto process_planar = [&](size_t i, ResourceFormat resource_format) {
auto& metadata = metadatas[i];
DCHECK(metadata.origin == kTopLeft_GrSurfaceOrigin);
metadata.resource_format = resource_format;
formats[i] = impl->GetGrBackendFormatForTexture(
resource_format, metadata.mailbox_holder.texture_target);
......@@ -219,7 +222,8 @@ class SkiaOutputSurfaceImpl::YUVAPromiseTextureHelper {
contexts[i] = new PromiseTextureHelper(
impl->impl_on_gpu_->weak_ptr(), metadata.size,
metadata.resource_format, metadata.mailbox_holder,
nullptr /* color_space */, metadata.alpha_type);
nullptr /* color_space */, metadata.alpha_type,
kTopLeft_GrSurfaceOrigin);
};
if (is_i420) {
......
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