Bug 167968 - Disallow accelerated rendering for ginormous 2D canvases.
Summary: Disallow accelerated rendering for ginormous 2D canvases.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Canvas (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Andreas Kling
URL:
Keywords: InRadar, Performance
Depends on:
Blocks:
 
Reported: 2017-02-07 16:52 PST by Andreas Kling
Modified: 2022-02-05 19:04 PST (History)
10 users (show)

See Also:


Attachments
Proposed patch (6.50 KB, patch)
2017-02-07 17:22 PST, Andreas Kling
buildbot: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews101 for mac-elcapitan (963.11 KB, application/zip)
2017-02-07 18:29 PST, Build Bot
no flags Details
Archive of layout-test-results from ews104 for mac-elcapitan-wk2 (899.50 KB, application/zip)
2017-02-07 18:33 PST, Build Bot
no flags Details
Archive of layout-test-results from ews114 for mac-elcapitan (1.68 MB, application/zip)
2017-02-07 18:37 PST, Build Bot
no flags Details
Archive of layout-test-results from ews122 for ios-simulator-wk2 (788.52 KB, application/zip)
2017-02-07 18:54 PST, Build Bot
no flags Details
Proposed patch (7.03 KB, patch)
2017-02-07 19:59 PST, Andreas Kling
no flags Details | Formatted Diff | Diff
Proposed patch (11.50 KB, patch)
2017-02-08 07:19 PST, Andreas Kling
buildbot: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews122 for ios-simulator-wk2 (785.48 KB, application/zip)
2017-02-08 08:54 PST, Build Bot
no flags Details
Proposed patch (12.81 KB, patch)
2017-02-08 11:17 PST, Andreas Kling
buildbot: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews123 for ios-simulator-wk2 (874.64 KB, application/zip)
2017-02-08 12:41 PST, Build Bot
no flags Details
Proposed patch (12.82 KB, patch)
2017-02-08 12:49 PST, Andreas Kling
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Kling 2017-02-07 16:52:33 PST
Allowing gargantuan canvases to have accelerated backing stores creates an opportunity for some lame pathologies.

<rdar://problem/30119483>
Comment 1 Andreas Kling 2017-02-07 17:22:20 PST
Created attachment 300864 [details]
Proposed patch
Comment 2 Simon Fraser (smfr) 2017-02-07 17:48:56 PST
Please split this into 2 patches.
Comment 3 Alex Christensen 2017-02-07 18:05:28 PST
Comment on attachment 300864 [details]
Proposed patch

View in context: https://bugs.webkit.org/attachment.cgi?id=300864&action=review

> Source/WebCore/page/Settings.in:28
>  minimumAccelerated2dCanvasSize type=int, initial=257*256
>  
> +maximumAccelerated2dCanvasSize type=unsigned, initial=5120*2880

Why are these different types?
Comment 4 Build Bot 2017-02-07 18:29:45 PST
Comment on attachment 300864 [details]
Proposed patch

Attachment 300864 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/3022503

New failing tests:
inspector/layers/layers-compositing-reasons.html
Comment 5 Build Bot 2017-02-07 18:29:50 PST
Created attachment 300873 [details]
Archive of layout-test-results from ews101 for mac-elcapitan

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews101  Port: mac-elcapitan  Platform: Mac OS X 10.11.6
Comment 6 Build Bot 2017-02-07 18:33:00 PST
Comment on attachment 300864 [details]
Proposed patch

Attachment 300864 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/3022510

New failing tests:
inspector/layers/layers-compositing-reasons.html
Comment 7 Build Bot 2017-02-07 18:33:05 PST
Created attachment 300874 [details]
Archive of layout-test-results from ews104 for mac-elcapitan-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-elcapitan-wk2  Platform: Mac OS X 10.11.6
Comment 8 Build Bot 2017-02-07 18:36:57 PST
Comment on attachment 300864 [details]
Proposed patch

Attachment 300864 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/3022506

New failing tests:
inspector/layers/layers-compositing-reasons.html
Comment 9 Build Bot 2017-02-07 18:37:01 PST
Created attachment 300875 [details]
Archive of layout-test-results from ews114 for mac-elcapitan

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews114  Port: mac-elcapitan  Platform: Mac OS X 10.11.6
Comment 10 Build Bot 2017-02-07 18:54:04 PST
Comment on attachment 300864 [details]
Proposed patch

Attachment 300864 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/3022524

New failing tests:
compositing/canvas/accelerated-canvas-compositing-size-limit.html
Comment 11 Build Bot 2017-02-07 18:54:09 PST
Created attachment 300876 [details]
Archive of layout-test-results from ews122 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews122  Port: ios-simulator-wk2  Platform: Mac OS X 10.11.6
Comment 12 Andreas Kling 2017-02-07 19:59:57 PST
Created attachment 300879 [details]
Proposed patch
Comment 13 Andreas Kling 2017-02-07 20:00:47 PST
(In reply to comment #2)
> Please split this into 2 patches.

k!

(In reply to comment #3)
> Comment on attachment 300864 [details]
> Proposed patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=300864&action=review
> 
> > Source/WebCore/page/Settings.in:28
> >  minimumAccelerated2dCanvasSize type=int, initial=257*256
> >  
> > +maximumAccelerated2dCanvasSize type=unsigned, initial=5120*2880
> 
> Why are these different types?

They should both be unsigned. I'm trying to keep this change minimal, so didn't touch it now.
Comment 14 Simon Fraser (smfr) 2017-02-07 20:28:45 PST
Comment on attachment 300879 [details]
Proposed patch

View in context: https://bugs.webkit.org/attachment.cgi?id=300879&action=review

> LayoutTests/compositing/canvas/accelerated-canvas-compositing-size-limit.html:27
> +<p>Verifies that 2D canvases with higher than 5120x2880 resolution don't create accelerated backing stores.</p>

So this test is actually detecting whether we create compositing layers for big canvases, not whether we're accelerating the canvas backing store. This are correlated (but you may break this correlation in your next patch).

> LayoutTests/platform/ios-simulator/TestExpectations:2855
> +compositing/canvas/accelerated-canvas-compositing-size-limit.html [ Failure ]

I think this is the wrong way to handle this. Why not just land iOS-specific results, so we can tell if we broke the limits in future?
Comment 15 Andreas Kling 2017-02-08 06:38:34 PST
(In reply to comment #14)
> Comment on attachment 300879 [details]
> Proposed patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=300879&action=review
> 
> > LayoutTests/compositing/canvas/accelerated-canvas-compositing-size-limit.html:27
> > +<p>Verifies that 2D canvases with higher than 5120x2880 resolution don't create accelerated backing stores.</p>
> 
> So this test is actually detecting whether we create compositing layers for
> big canvases, not whether we're accelerating the canvas backing store. This
> are correlated (but you may break this correlation in your next patch).

Duh. Let me add a way to include the accelerates drawing flag in layer tree dumps..

> > LayoutTests/platform/ios-simulator/TestExpectations:2855
> > +compositing/canvas/accelerated-canvas-compositing-size-limit.html [ Failure ]
> 
> I think this is the wrong way to handle this. Why not just land iOS-specific
> results, so we can tell if we broke the limits in future?

That would be better, let's do that.
Comment 16 Andreas Kling 2017-02-08 07:19:19 PST
Created attachment 300895 [details]
Proposed patch

With "acceleratesDrawing" in layer tree dumps (optional). I don't have a test baseline for iOS at the moment, but I'm sure EWS is gonna give me one.
Comment 17 WebKit Commit Bot 2017-02-08 07:21:25 PST
Attachment 300895 [details] did not pass style-queue:


ERROR: Source/WebCore/testing/Internals.h:263:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
ERROR: Source/WebCore/testing/Internals.h:264:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
Total errors found: 2 in 13 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 18 Build Bot 2017-02-08 08:54:37 PST
Comment on attachment 300895 [details]
Proposed patch

Attachment 300895 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/3025466

New failing tests:
compositing/canvas/accelerated-canvas-compositing-size-limit.html
Comment 19 Build Bot 2017-02-08 08:54:43 PST
Created attachment 300904 [details]
Archive of layout-test-results from ews122 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews122  Port: ios-simulator-wk2  Platform: Mac OS X 10.11.6
Comment 20 Andreas Kling 2017-02-08 11:17:48 PST
Created attachment 300926 [details]
Proposed patch

My machine doesn't seem to care about the maxActivePixelMemory change I wanted to make anymore.
This one is still very relevant though.
Comment 21 WebKit Commit Bot 2017-02-08 11:20:50 PST
Attachment 300926 [details] did not pass style-queue:


ERROR: Source/WebCore/testing/Internals.h:263:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
ERROR: Source/WebCore/testing/Internals.h:264:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
Total errors found: 2 in 14 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 22 Build Bot 2017-02-08 12:41:24 PST
Comment on attachment 300926 [details]
Proposed patch

Attachment 300926 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/3026595

New failing tests:
compositing/canvas/accelerated-canvas-compositing-size-limit.html
Comment 23 Build Bot 2017-02-08 12:41:29 PST
Created attachment 300936 [details]
Archive of layout-test-results from ews123 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews123  Port: ios-simulator-wk2  Platform: Mac OS X 10.11.6
Comment 24 Andreas Kling 2017-02-08 12:49:46 PST
Created attachment 300939 [details]
Proposed patch
Comment 25 WebKit Commit Bot 2017-02-08 12:51:47 PST
Attachment 300939 [details] did not pass style-queue:


ERROR: Source/WebCore/testing/Internals.h:263:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
ERROR: Source/WebCore/testing/Internals.h:264:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
Total errors found: 2 in 14 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 26 WebKit Commit Bot 2017-02-09 05:57:14 PST
Comment on attachment 300939 [details]
Proposed patch

Clearing flags on attachment: 300939

Committed r211949: <http://trac.webkit.org/changeset/211949>
Comment 27 WebKit Commit Bot 2017-02-09 05:57:22 PST
All reviewed patches have been landed.  Closing bug.
Comment 28 Simon Fraser (smfr) 2017-02-09 08:44:42 PST
Comment on attachment 300939 [details]
Proposed patch

View in context: https://bugs.webkit.org/attachment.cgi?id=300939&action=review

> Source/WebCore/platform/graphics/GraphicsLayer.cpp:789
> +    if (behavior & LayerTreeAsTextIncludeAcceleratesDrawing && m_acceleratesDrawing) {
> +        writeIndent(ts, indent + 1);
> +        ts << "(acceleratesDrawing " << m_acceleratesDrawing << ")\n";
> +    }

This has no relation to whether the canvas itself is using accelerated drawing. This is just about the compositing layers, and will always be 1 on Mac, and 0 in the iOS simulator. So I don't think this is giving you accurate information about the behavior of HTMLCanvasElement::shouldAccelerate().
Comment 29 Andreas Kling 2017-02-09 08:50:38 PST
(In reply to comment #28)
> Comment on attachment 300939 [details]
> Proposed patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=300939&action=review
> 
> > Source/WebCore/platform/graphics/GraphicsLayer.cpp:789
> > +    if (behavior & LayerTreeAsTextIncludeAcceleratesDrawing && m_acceleratesDrawing) {
> > +        writeIndent(ts, indent + 1);
> > +        ts << "(acceleratesDrawing " << m_acceleratesDrawing << ")\n";
> > +    }
> 
> This has no relation to whether the canvas itself is using accelerated
> drawing. This is just about the compositing layers, and will always be 1 on
> Mac, and 0 in the iOS simulator. So I don't think this is giving you
> accurate information about the behavior of
> HTMLCanvasElement::shouldAccelerate().

Are you sure? The only thing we do with the return value from shouldAccelerate() is call GraphicsLayer::setAcceleratesDrawing() if it's true.
Comment 30 Andreas Kling 2017-02-09 08:55:46 PST
iOS simulator doesn't enable USE_IOSURFACE_CANVAS_BACKING_STORE so I think shouldAccelerate() will always return false there, unless we're building with ENABLE(ACCELERATED_2D_CANVAS)?

If you look at the expected results from my new test, you'll see that acceleratesDrawing is not present for the over-5K canvas's layer.
Comment 31 Simon Fraser (smfr) 2017-02-09 10:58:20 PST
(In reply to comment #29)
> (In reply to comment #28)
> > Comment on attachment 300939 [details]
> > Proposed patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=300939&action=review
> > 
> > > Source/WebCore/platform/graphics/GraphicsLayer.cpp:789
> > > +    if (behavior & LayerTreeAsTextIncludeAcceleratesDrawing && m_acceleratesDrawing) {
> > > +        writeIndent(ts, indent + 1);
> > > +        ts << "(acceleratesDrawing " << m_acceleratesDrawing << ")\n";
> > > +    }
> > 
> > This has no relation to whether the canvas itself is using accelerated
> > drawing. This is just about the compositing layers, and will always be 1 on
> > Mac, and 0 in the iOS simulator. So I don't think this is giving you
> > accurate information about the behavior of
> > HTMLCanvasElement::shouldAccelerate().
> 
> Are you sure? The only thing we do with the return value from
> shouldAccelerate() is call GraphicsLayer::setAcceleratesDrawing() if it's
> true.

GraphicsLayer::acceleratesDrawing() is true by default on Mac and iOS device, so this line is mostly a no-op. I'm actually not sure why it was added (maybe before we turned on accel. drawing by default?).

What really matters for canvas backing store is the code in HTMLCanvasElement::createImageBuffer().