Skip to content

Commit

Permalink
Removing kSoftwareCompositedUsage for CanvasRenderingContextHost in 3D
Browse files Browse the repository at this point in the history
It is not needed to try and use the SharedImageProvider as currently
the CanvasResourceProvider::Create method will instantly fall into the
SharedBitmapProvider fallback or BitmapProvider fallback.

This CL removes the SoftwareCompositedUsage and replaces it with both
fallbacks.

This CL also adds the CreateSharedBitmapProvider.

Bug: 1035589
Change-Id: I2cc0b23c1a40c15285ccdbba06840a0f98ff1b39
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2118573
Reviewed-by: Fernando Serboncini <fserb@chromium.org>
Commit-Queue: Juanmi Huertas <juanmihd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#766425}
  • Loading branch information
Juanmihd authored and Commit Bot committed May 7, 2020
1 parent 7f33d3e commit 788b2ea
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
Expand Up @@ -121,8 +121,9 @@ void CanvasRenderingContextHost::CreateCanvasResourceProvider3D(
CanvasResourceProvider::kAllowImageChromiumPresentationMode;
}

CanvasResourceProvider::ResourceUsage usage;
std::unique_ptr<CanvasResourceProvider> provider;
if (SharedGpuContext::IsGpuCompositingEnabled()) {
CanvasResourceProvider::ResourceUsage usage;
if (LowLatencyEnabled() && RenderingContext() &&
RenderingContext()->UsingSwapChain()) {
// Allow swap chain presentation only if 3d context is using a swap
Expand All @@ -135,17 +136,27 @@ void CanvasRenderingContextHost::CreateCanvasResourceProvider3D(
usage = CanvasResourceProvider::ResourceUsage::
kAcceleratedCompositedResourceUsage;
}
provider = CanvasResourceProvider::Create(
Size(), usage, SharedGpuContext::ContextProviderWrapper(),
0 /* msaa_sample_count */, FilterQuality(), ColorParams(),
presentation_mode, std::move(dispatcher),
RenderingContext()->IsOriginTopLeft());
} else {
usage =
CanvasResourceProvider::ResourceUsage::kSoftwareCompositedResourceUsage;
// Here it should try a SoftwareCompositedResourceUsage, but as
// SharedGpuCOntext::IsGpuCompositingEnabled() is false and that being true
// is a requirement to try and create a SharedImageProvider if
// SoftwareCompositeResourceUsage is used, it will go straight ahead to a
// fallback SharedBitmap and then to a Bitmap provider
provider = CanvasResourceProvider::CreateSharedBitmapProvider(
Size(), SharedGpuContext::ContextProviderWrapper(), FilterQuality(),
ColorParams(), std::move(dispatcher));
if (!provider) {
provider = CanvasResourceProvider::CreateBitmapProvider(
Size(), FilterQuality(), ColorParams());
}
}

base::UmaHistogramEnumeration("Blink.Canvas.ResourceProviderUsage", usage);
ReplaceResourceProvider(CanvasResourceProvider::Create(
Size(), usage, SharedGpuContext::ContextProviderWrapper(),
0 /* msaa_sample_count */, FilterQuality(), ColorParams(),
presentation_mode, std::move(dispatcher),
RenderingContext()->IsOriginTopLeft()));
ReplaceResourceProvider(std::move(provider));
if (ResourceProvider() && ResourceProvider()->IsValid()) {
base::UmaHistogramBoolean("Blink.Canvas.ResourceProviderIsAccelerated",
ResourceProvider()->IsAccelerated());
Expand Down
Expand Up @@ -1017,6 +1017,38 @@ CanvasResourceProvider::CreateSharedImageProvider(
return nullptr;
}

std::unique_ptr<CanvasResourceProvider>
CanvasResourceProvider::CreatePassThroughProvider(
const IntSize& size,
base::WeakPtr<WebGraphicsContext3DProviderWrapper> context_provider_wrapper,
SkFilterQuality filter_quality,
const CanvasColorParams& color_params,
bool is_origin_top_left,
base::WeakPtr<CanvasResourceDispatcher> resource_dispatcher) {
if (!SharedGpuContext::IsGpuCompositingEnabled() || !context_provider_wrapper)
return nullptr;

const auto& capabilities =
context_provider_wrapper->ContextProvider()->GetCapabilities();
if (size.Width() > capabilities.max_texture_size ||
size.Height() > capabilities.max_texture_size ||
!capabilities.shared_image_swap_chain) {
return nullptr;
}

if (!IsGMBAllowed(size, color_params, capabilities) ||
!Platform::Current()->GetGpuMemoryBufferManager())
return nullptr;

auto provider = std::make_unique<CanvasResourceProviderPassThrough>(
size, filter_quality, color_params, context_provider_wrapper,
resource_dispatcher, is_origin_top_left);
if (provider->IsValid())
return provider;

return nullptr;
}

CanvasResourceProvider::CanvasImageProvider::CanvasImageProvider(
cc::ImageDecodeCache* cache_n32,
cc::ImageDecodeCache* cache_f16,
Expand Down
Expand Up @@ -131,6 +131,14 @@ class PLATFORM_EXPORT CanvasResourceProvider
RasterMode raster_mode,
uint32_t shared_image_usage_flags);

static std::unique_ptr<CanvasResourceProvider> CreatePassThroughProvider(
const IntSize&,
base::WeakPtr<WebGraphicsContext3DProviderWrapper>,
SkFilterQuality,
const CanvasColorParams&,
bool is_origin_top_left,
base::WeakPtr<CanvasResourceDispatcher>);

// TODO(juanmihd): Clean up creation methods/usage. See crbug.com/1035589.
static std::unique_ptr<CanvasResourceProvider> Create(
const IntSize&,
Expand Down

0 comments on commit 788b2ea

Please sign in to comment.