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