Commit c5ed236a authored by Nathan Zabriskie's avatar Nathan Zabriskie Committed by Commit Bot

Use origin and alpha info stored on SharedImageBacking

Previous CL's have added information regarding an image's origin and
alpha type to SharedImageBacking. This CL uses that info in place of
assumed defaults when creating SkSurfaces for write access.

Bug: 1034086
Change-Id: I82f1a400acc09724b0667318a34208ebeb91d549
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2307533
Commit-Queue: Nathan Zabriskie <nazabris@microsoft.com>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790239}
parent e4644edd
......@@ -264,15 +264,8 @@ class SharedImageProviderImpl final : public cc::SharedImageProvider {
DCHECK(result);
}
// TODO(http://crbug.com/1034086): We should initialize alpha_type and
// origin using metadata stored with the shared image.
auto sk_image = SkImage::MakeFromTexture(
shared_context_state_->gr_context(),
scoped_read_access->promise_image_texture()->backendTexture(),
kTopLeft_GrSurfaceOrigin,
viz::ResourceFormatToClosestSkColorType(true,
shared_image_skia->format()),
kPremul_SkAlphaType, shared_image_skia->color_space().ToSkColorSpace());
auto sk_image =
scoped_read_access->CreateSkImage(shared_context_state_->gr_context());
if (!sk_image) {
ERRORSTATE_SET_GL_ERROR(error_state_, GL_INVALID_OPERATION,
"SharedImageProviderImpl::OpenSharedImageForRead",
......@@ -2308,15 +2301,16 @@ void RasterDecoderImpl::DoCopySubTextureINTERNALSkia(
auto color_type = viz::ResourceFormatToClosestSkColorType(
true /* gpu_compositing */, source_shared_image->format());
// TODO(http://crbug.com/1034086): We should initialize alpha_type and
// origin using metadata stored with the shared image.
SkAlphaType alpha_type = kPremul_SkAlphaType;
// TODO(nazabris): We should be able to pipe this information through from
// the client side when creating the shared image. Make that change in a
// follow up CL.
SkAlphaType alpha_type = source_shared_image->alpha_type();
if (unpack_premultiply_alpha)
alpha_type = kUnpremul_SkAlphaType;
auto source_image = SkImage::MakeFromTexture(
shared_context_state_->gr_context(),
source_scoped_access->promise_image_texture()->backendTexture(),
kTopLeft_GrSurfaceOrigin, color_type, alpha_type,
source_shared_image->surface_origin(), color_type, alpha_type,
nullptr /* colorSpace */);
auto* canvas = dest_scoped_access->surface()->getCanvas();
......@@ -2543,18 +2537,13 @@ void RasterDecoderImpl::DoReadbackImagePixelsINTERNAL(
return;
}
auto src_color_type = viz::ResourceFormatToClosestSkColorType(
true /* gpu_compositing */, source_shared_image->format());
// TODO(http://crbug.com/1034086): We should initialize alpha_type and
// origin using metadata stored with the shared image.
SkAlphaType src_alpha_type = kPremul_SkAlphaType;
auto src_color_space = source_shared_image->color_space().ToSkColorSpace();
auto sk_image = SkImage::MakeFromTexture(
shared_context_state_->gr_context(),
source_scoped_access->promise_image_texture()->backendTexture(),
kTopLeft_GrSurfaceOrigin, src_color_type, src_alpha_type,
src_color_space);
auto sk_image =
source_scoped_access->CreateSkImage(shared_context_state_->gr_context());
if (!sk_image) {
LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels",
"Couldn't create SkImage for reading.");
return;
}
void* shm_address = GetSharedMemoryAs<void*>(
shm_id, shm_offset + pixels_offset, dst_info.computeByteSize(row_bytes));
......
......@@ -467,7 +467,7 @@ sk_sp<SkSurface> SharedImageRepresentationSkiaImpl::BeginWriteAccess(
/*gpu_compositing=*/true, format());
auto surface = SkSurface::MakeFromBackendTexture(
context_state_->gr_context(), promise_texture_->backendTexture(),
backing()->surface_origin(), final_msaa_count, sk_color_type,
surface_origin(), final_msaa_count, sk_color_type,
backing()->color_space().ToSkColorSpace(), &surface_props);
write_surface_ = surface.get();
return surface;
......
......@@ -4,6 +4,7 @@
#include "gpu/command_buffer/service/shared_image_representation.h"
#include "components/viz/common/resources/resource_format_utils.h"
#include "gpu/command_buffer/service/texture_manager.h"
#include "third_party/skia/include/core/SkPromiseImageTexture.h"
......@@ -153,6 +154,18 @@ SharedImageRepresentationSkia::ScopedReadAccess::~ScopedReadAccess() {
representation()->EndReadAccess();
}
sk_sp<SkImage> SharedImageRepresentationSkia::ScopedReadAccess::CreateSkImage(
GrContext* context) const {
auto surface_origin = representation()->surface_origin();
auto color_type =
viz::ResourceFormatToClosestSkColorType(true, representation()->format());
auto alpha_type = representation()->alpha_type();
auto sk_color_space = representation()->color_space().ToSkColorSpace();
return SkImage::MakeFromTexture(
context, promise_image_texture_->backendTexture(), surface_origin,
color_type, alpha_type, sk_color_space);
}
std::unique_ptr<SharedImageRepresentationSkia::ScopedReadAccess>
SharedImageRepresentationSkia::BeginScopedReadAccess(
std::vector<GrBackendSemaphore>* begin_semaphores,
......
......@@ -109,6 +109,9 @@ class GPU_GLES2_EXPORT SharedImageRepresentation {
}
RepresentationClass* representation() { return representation_; }
const RepresentationClass* representation() const {
return representation_;
}
private:
RepresentationClass* const representation_;
......@@ -255,6 +258,7 @@ class GPU_GLES2_EXPORT SharedImageRepresentationSkia
SkPromiseImageTexture* promise_image_texture() const {
return promise_image_texture_.get();
}
sk_sp<SkImage> CreateSkImage(GrContext* context) const;
GrBackendSurfaceMutableState* end_state() const { return end_state_.get(); }
private:
......
......@@ -98,7 +98,7 @@ sk_sp<SkSurface> SharedImageRepresentationSkiaGL::BeginWriteAccess(
/*gpu_compositing=*/true, format());
auto surface = SkSurface::MakeFromBackendTexture(
context_state_->gr_context(), promise_texture_->backendTexture(),
kTopLeft_GrSurfaceOrigin, final_msaa_count, sk_color_type,
surface_origin(), final_msaa_count, sk_color_type,
backing()->color_space().ToSkColorSpace(), &surface_props);
surface_ = surface;
return surface;
......
......@@ -78,9 +78,9 @@ sk_sp<SkSurface> SharedImageRepresentationSkiaVkAndroid::BeginWriteAccess(
SkColorType sk_color_type = viz::ResourceFormatToClosestSkColorType(
/*gpu_compositing=*/true, format());
surface_ = SkSurface::MakeFromBackendTexture(
gr_context, promise_texture_->backendTexture(),
kTopLeft_GrSurfaceOrigin, final_msaa_count, sk_color_type,
color_space().ToSkColorSpace(), &surface_props);
gr_context, promise_texture_->backendTexture(), surface_origin(),
final_msaa_count, sk_color_type, color_space().ToSkColorSpace(),
&surface_props);
if (!surface_) {
LOG(ERROR) << "MakeFromBackendTexture() failed.";
return nullptr;
......
......@@ -118,9 +118,9 @@ class WrappedSkImage : public ClearTrackingSharedImageBacking {
if (!surface || final_msaa_count != surface_msaa_count_ ||
surface_props != surface->props()) {
surface = SkSurface::MakeFromBackendTexture(
context_state_->gr_context(), backend_texture_,
kTopLeft_GrSurfaceOrigin, final_msaa_count, GetSkColorType(),
color_space().ToSkColorSpace(), &surface_props);
context_state_->gr_context(), backend_texture_, surface_origin(),
final_msaa_count, GetSkColorType(), color_space().ToSkColorSpace(),
&surface_props);
if (!surface) {
LOG(ERROR) << "MakeFromBackendTexture() failed.";
context_state_->EraseCachedSkSurface(this);
......
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