Commit 7e961a4b authored by Miguel Casas's avatar Miguel Casas Committed by Commit Bot

canvas 2D lowLatency ️: correct CreateSkSurface() orientation

This CL does two things to support the correct SkSurface
orientation for low latency canvas 2D contexts to get promoted
to overlay:

1. CanvasRenderingContext::IsOriginTopLeft() is extended in 2D
canvases to return false if IsAccelerated() (because those refer
to the bottom left) -- but true if it IsSingleBuffered(). This
is needed to support overlays on Intel, which can only be top
left (and other platforms/archs like ARM RockChip are OK with it
anyway).

2. CanvasResourceProvider::Create() gets a new parameter, namely
|is_origin_top_left|, which is by default true (since that's how
Canvases work by default). The callsites where true is not the
right thing are corrected.

Bug: 869161
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_layout_tests_slimming_paint_v2;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ia798bd674b3f9e42063e5ae8b4017bfdd9e60d48
Reviewed-on: https://chromium-review.googlesource.com/1160774Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581294}
parent 356557dd
...@@ -77,10 +77,13 @@ CanvasRenderingContextHost::GetOrCreateCanvasResourceProvider( ...@@ -77,10 +77,13 @@ CanvasRenderingContextHost::GetOrCreateCanvasResourceProvider(
? CanvasResourceProvider::kAllowImageChromiumPresentationMode ? CanvasResourceProvider::kAllowImageChromiumPresentationMode
: CanvasResourceProvider::kDefaultPresentationMode; : CanvasResourceProvider::kDefaultPresentationMode;
const bool is_origin_top_left =
!SharedGpuContext::IsGpuCompositingEnabled();
ReplaceResourceProvider(CanvasResourceProvider::Create( ReplaceResourceProvider(CanvasResourceProvider::Create(
Size(), usage, SharedGpuContext::ContextProviderWrapper(), Size(), usage, SharedGpuContext::ContextProviderWrapper(),
0 /* msaa_sample_count */, ColorParams(), presentation_mode, 0 /* msaa_sample_count */, ColorParams(), presentation_mode,
std::move(dispatcher))); std::move(dispatcher), is_origin_top_left));
} else { } else {
DCHECK(Is2d()); DCHECK(Is2d());
const bool want_acceleration = const bool want_acceleration =
...@@ -96,10 +99,13 @@ CanvasRenderingContextHost::GetOrCreateCanvasResourceProvider( ...@@ -96,10 +99,13 @@ CanvasRenderingContextHost::GetOrCreateCanvasResourceProvider(
? CanvasResourceProvider::kAllowImageChromiumPresentationMode ? CanvasResourceProvider::kAllowImageChromiumPresentationMode
: CanvasResourceProvider::kDefaultPresentationMode; : CanvasResourceProvider::kDefaultPresentationMode;
const bool is_origin_top_left =
!want_acceleration || LowLatencyEnabled();
ReplaceResourceProvider(CanvasResourceProvider::Create( ReplaceResourceProvider(CanvasResourceProvider::Create(
Size(), usage, SharedGpuContext::ContextProviderWrapper(), Size(), usage, SharedGpuContext::ContextProviderWrapper(),
GetMSAASampleCountFor2dContext(), ColorParams(), presentation_mode, GetMSAASampleCountFor2dContext(), ColorParams(), presentation_mode,
std::move(dispatcher))); std::move(dispatcher), is_origin_top_left));
if (ResourceProvider()) { if (ResourceProvider()) {
// Always save an initial frame, to support resetting the top level // Always save an initial frame, to support resetting the top level
......
...@@ -623,7 +623,8 @@ ImageBitmap::ImageBitmap(HTMLVideoElement* video, ...@@ -623,7 +623,8 @@ ImageBitmap::ImageBitmap(HTMLVideoElement* video,
0, // msaa_sample_count 0, // msaa_sample_count
CanvasColorParams(), // TODO: set color space here to avoid clamping CanvasColorParams(), // TODO: set color space here to avoid clamping
CanvasResourceProvider::kDefaultPresentationMode, CanvasResourceProvider::kDefaultPresentationMode,
nullptr); // canvas_resource_dispatcher nullptr, // canvas_resource_dispatcher
IsAccelerated()); // is_origin_top_left
if (!resource_provider) if (!resource_provider)
return; return;
......
...@@ -322,7 +322,7 @@ CanvasResourceProvider* OffscreenCanvas::GetOrCreateResourceProvider() { ...@@ -322,7 +322,7 @@ CanvasResourceProvider* OffscreenCanvas::GetOrCreateResourceProvider() {
ReplaceResourceProvider(CanvasResourceProvider::Create( ReplaceResourceProvider(CanvasResourceProvider::Create(
surface_size, usage, SharedGpuContext::ContextProviderWrapper(), 0, surface_size, usage, SharedGpuContext::ContextProviderWrapper(), 0,
context_->ColorParams(), presentation_mode, context_->ColorParams(), presentation_mode,
std::move(dispatcher_weakptr))); std::move(dispatcher_weakptr), false /* is_origin_top_left */));
// The fallback chain for k*CompositedResourceUsage should never fall // The fallback chain for k*CompositedResourceUsage should never fall
// all the way through to BitmapResourceProvider, except in unit tests. // all the way through to BitmapResourceProvider, except in unit tests.
......
...@@ -168,6 +168,12 @@ bool CanvasRenderingContext2D::IsAccelerated() const { ...@@ -168,6 +168,12 @@ bool CanvasRenderingContext2D::IsAccelerated() const {
return layer_bridge->IsAccelerated(); return layer_bridge->IsAccelerated();
} }
bool CanvasRenderingContext2D::IsOriginTopLeft() const {
// Accelerated 2D contexts have the origin of coordinates on the bottom left,
// except if they are single buffered (needed for front buffer rendering).
return !IsAccelerated() || canvas()->ResourceProvider()->IsSingleBuffered();
}
bool CanvasRenderingContext2D::IsComposited() const { bool CanvasRenderingContext2D::IsComposited() const {
return IsAccelerated(); return IsAccelerated();
} }
......
...@@ -244,6 +244,7 @@ class MODULES_EXPORT CanvasRenderingContext2D final ...@@ -244,6 +244,7 @@ class MODULES_EXPORT CanvasRenderingContext2D final
bool Is2d() const override { return true; } bool Is2d() const override { return true; }
bool IsComposited() const override; bool IsComposited() const override;
bool IsAccelerated() const override; bool IsAccelerated() const override;
bool IsOriginTopLeft() const override;
bool HasAlpha() const override { return CreationAttributes().alpha; } bool HasAlpha() const override { return CreationAttributes().alpha; }
void SetIsHidden(bool) override; void SetIsHidden(bool) override;
void Stop() final; void Stop() final;
......
...@@ -797,7 +797,7 @@ scoped_refptr<StaticBitmapImage> WebGLRenderingContextBase::GetImage( ...@@ -797,7 +797,7 @@ scoped_refptr<StaticBitmapImage> WebGLRenderingContextBase::GetImage(
size, CanvasResourceProvider::kAcceleratedResourceUsage, size, CanvasResourceProvider::kAcceleratedResourceUsage,
SharedGpuContext::ContextProviderWrapper(), 0, ColorParams(), SharedGpuContext::ContextProviderWrapper(), 0, ColorParams(),
CanvasResourceProvider::kDefaultPresentationMode, CanvasResourceProvider::kDefaultPresentationMode,
nullptr); // canvas_resource_dispatcher nullptr /* canvas_resource_dispatcher */, is_origin_top_left_);
if (!resource_provider || !resource_provider->IsValid()) if (!resource_provider || !resource_provider->IsValid())
return nullptr; return nullptr;
if (!CopyRenderingResultsFromDrawingBuffer(resource_provider.get(), if (!CopyRenderingResultsFromDrawingBuffer(resource_provider.get(),
...@@ -5467,10 +5467,9 @@ void WebGLRenderingContextBase::TexImageHelperHTMLVideoElement( ...@@ -5467,10 +5467,9 @@ void WebGLRenderingContextBase::TexImageHelperHTMLVideoElement(
IntSize(video->videoWidth(), video->videoHeight()), IntSize(video->videoWidth(), video->videoHeight()),
CanvasResourceProvider::kAcceleratedResourceUsage, CanvasResourceProvider::kAcceleratedResourceUsage,
SharedGpuContext::ContextProviderWrapper(), SharedGpuContext::ContextProviderWrapper(),
0, // msaa_sample_count 0 /* msaa_sample_count */, CanvasColorParams(),
CanvasColorParams(),
CanvasResourceProvider::kDefaultPresentationMode, CanvasResourceProvider::kDefaultPresentationMode,
nullptr); // canvas_resource_dispatcher nullptr /* canvas_resource_dispatcher */, is_origin_top_left_);
if (resource_provider && resource_provider->IsValid()) { if (resource_provider && resource_provider->IsValid()) {
// The video element paints an RGBA frame into our surface here. By // The video element paints an RGBA frame into our surface here. By
// using an AcceleratedImageBufferSurface, we enable the WebMediaPlayer // using an AcceleratedImageBufferSurface, we enable the WebMediaPlayer
......
...@@ -41,12 +41,14 @@ class CanvasResourceProviderTexture : public CanvasResourceProvider { ...@@ -41,12 +41,14 @@ class CanvasResourceProviderTexture : public CanvasResourceProvider {
const CanvasColorParams color_params, const CanvasColorParams color_params,
base::WeakPtr<WebGraphicsContext3DProviderWrapper> base::WeakPtr<WebGraphicsContext3DProviderWrapper>
context_provider_wrapper, context_provider_wrapper,
base::WeakPtr<CanvasResourceDispatcher> resource_dispatcher) base::WeakPtr<CanvasResourceDispatcher> resource_dispatcher,
bool is_origin_top_left)
: CanvasResourceProvider(size, : CanvasResourceProvider(size,
color_params, color_params,
std::move(context_provider_wrapper), std::move(context_provider_wrapper),
std::move(resource_dispatcher)), std::move(resource_dispatcher)),
msaa_sample_count_(msaa_sample_count) {} msaa_sample_count_(msaa_sample_count),
is_origin_top_left_(is_origin_top_left) {}
~CanvasResourceProviderTexture() override = default; ~CanvasResourceProviderTexture() override = default;
...@@ -116,15 +118,21 @@ class CanvasResourceProviderTexture : public CanvasResourceProvider { ...@@ -116,15 +118,21 @@ class CanvasResourceProviderTexture : public CanvasResourceProvider {
auto* gr = GetGrContext(); auto* gr = GetGrContext();
DCHECK(gr); DCHECK(gr);
SkImageInfo info = SkImageInfo::Make( const SkImageInfo info = SkImageInfo::Make(
Size().Width(), Size().Height(), ColorParams().GetSkColorType(), Size().Width(), Size().Height(), ColorParams().GetSkColorType(),
kPremul_SkAlphaType, ColorParams().GetSkColorSpaceForSkSurfaces()); kPremul_SkAlphaType, ColorParams().GetSkColorSpaceForSkSurfaces());
const enum GrSurfaceOrigin surface_origin =
is_origin_top_left_ ? kTopLeft_GrSurfaceOrigin
: kBottomLeft_GrSurfaceOrigin;
return SkSurface::MakeRenderTarget(gr, SkBudgeted::kNo, info, return SkSurface::MakeRenderTarget(gr, SkBudgeted::kNo, info,
msaa_sample_count_, msaa_sample_count_, surface_origin,
ColorParams().GetSkSurfaceProps()); ColorParams().GetSkSurfaceProps());
} }
const unsigned msaa_sample_count_; const unsigned msaa_sample_count_;
const bool is_origin_top_left_;
}; };
// CanvasResourceProviderTextureGpuMemoryBuffer // CanvasResourceProviderTextureGpuMemoryBuffer
...@@ -143,12 +151,14 @@ class CanvasResourceProviderTextureGpuMemoryBuffer final ...@@ -143,12 +151,14 @@ class CanvasResourceProviderTextureGpuMemoryBuffer final
const CanvasColorParams color_params, const CanvasColorParams color_params,
base::WeakPtr<WebGraphicsContext3DProviderWrapper> base::WeakPtr<WebGraphicsContext3DProviderWrapper>
context_provider_wrapper, context_provider_wrapper,
base::WeakPtr<CanvasResourceDispatcher> resource_dispatcher) base::WeakPtr<CanvasResourceDispatcher> resource_dispatcher,
bool is_origin_top_left)
: CanvasResourceProviderTexture(size, : CanvasResourceProviderTexture(size,
msaa_sample_count, msaa_sample_count,
color_params, color_params,
std::move(context_provider_wrapper), std::move(context_provider_wrapper),
std::move(resource_dispatcher)) {} std::move(resource_dispatcher),
is_origin_top_left) {}
~CanvasResourceProviderTextureGpuMemoryBuffer() override = default; ~CanvasResourceProviderTextureGpuMemoryBuffer() override = default;
bool SupportsDirectCompositing() const override { return true; } bool SupportsDirectCompositing() const override { return true; }
...@@ -396,7 +406,8 @@ std::unique_ptr<CanvasResourceProvider> CanvasResourceProvider::Create( ...@@ -396,7 +406,8 @@ std::unique_ptr<CanvasResourceProvider> CanvasResourceProvider::Create(
unsigned msaa_sample_count, unsigned msaa_sample_count,
const CanvasColorParams& color_params, const CanvasColorParams& color_params,
PresentationMode presentation_mode, PresentationMode presentation_mode,
base::WeakPtr<CanvasResourceDispatcher> resource_dispatcher) { base::WeakPtr<CanvasResourceDispatcher> resource_dispatcher,
bool is_origin_top_left) {
const ResourceType* resource_type_fallback_list = nullptr; const ResourceType* resource_type_fallback_list = nullptr;
size_t list_length = 0; size_t list_length = 0;
...@@ -449,7 +460,7 @@ std::unique_ptr<CanvasResourceProvider> CanvasResourceProvider::Create( ...@@ -449,7 +460,7 @@ std::unique_ptr<CanvasResourceProvider> CanvasResourceProvider::Create(
provider = provider =
std::make_unique<CanvasResourceProviderTextureGpuMemoryBuffer>( std::make_unique<CanvasResourceProviderTextureGpuMemoryBuffer>(
size, msaa_sample_count, color_params, context_provider_wrapper, size, msaa_sample_count, color_params, context_provider_wrapper,
resource_dispatcher); resource_dispatcher, is_origin_top_left);
break; break;
case kRamGpuMemoryBufferResourceType: case kRamGpuMemoryBufferResourceType:
if (!SharedGpuContext::IsGpuCompositingEnabled()) if (!SharedGpuContext::IsGpuCompositingEnabled())
...@@ -478,7 +489,7 @@ std::unique_ptr<CanvasResourceProvider> CanvasResourceProvider::Create( ...@@ -478,7 +489,7 @@ std::unique_ptr<CanvasResourceProvider> CanvasResourceProvider::Create(
continue; continue;
provider = std::make_unique<CanvasResourceProviderTexture>( provider = std::make_unique<CanvasResourceProviderTexture>(
size, msaa_sample_count, color_params, context_provider_wrapper, size, msaa_sample_count, color_params, context_provider_wrapper,
resource_dispatcher); resource_dispatcher, is_origin_top_left);
break; break;
case kBitmapResourceType: case kBitmapResourceType:
provider = std::make_unique<CanvasResourceProviderBitmap>( provider = std::make_unique<CanvasResourceProviderBitmap>(
......
...@@ -80,7 +80,8 @@ class PLATFORM_EXPORT CanvasResourceProvider ...@@ -80,7 +80,8 @@ class PLATFORM_EXPORT CanvasResourceProvider
unsigned msaa_sample_count, unsigned msaa_sample_count,
const CanvasColorParams&, const CanvasColorParams&,
PresentationMode, PresentationMode,
base::WeakPtr<CanvasResourceDispatcher>); base::WeakPtr<CanvasResourceDispatcher>,
bool is_origin_top_left = true);
// Use this method for capturing a frame that is intended to be displayed via // Use this method for capturing a frame that is intended to be displayed via
// the compositor. Cases that need to acquire a snaptshot that is not destined // the compositor. Cases that need to acquire a snaptshot that is not destined
......
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