Closed Bug 1168189 Opened 5 years ago Closed 4 years ago

PDF file not displayed correctly in Firefox (when Hardware Acceleration is enabled)

Categories

(Core :: Canvas: 2D, defect, P3)

38 Branch
x86_64
Windows 7
defect

Tracking

()

RESOLVED FIXED
mozilla42
Tracking Status
firefox38 --- wontfix
firefox38.0.5 --- wontfix
firefox39 --- wontfix
firefox40 + verified
firefox41 + fixed
firefox42 + fixed
firefox-esr38 - wontfix

People

(Reporter: pioruns, Assigned: kyle_fung)

References

Details

(Whiteboard: [pdfjs-c-rendering][pdfjs-d-hwa-on][gfx-noted])

Attachments

(9 files, 2 obsolete files)

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Build ID: 20150513174244

Steps to reproduce:

Open attached PDF file with Firefox 38.0.1 on Windows.

PDF file can be also opened straight from the Internet, link: http://ieee-security.org/TC/SPW2015/W2SP/papers/W2SP_2015_submission_32.pdf

Go to 2 page.


Actual results:

On top of page, you see white background with some random shapes and lines here and there.


Expected results:

You supposed to see 2 images (screenshots) on top of the page.
I tried Adobe Acrobat XI (version 11.0.10, english), and SumatraPDF (version 3.0), both displaying document correctly.
Screenshot from Adobe Reader displaying file correctly.
Attached image screenshot from Firefox
Screenshot from Firefox, displaying file incorrectly.
I tried it on new Firefox 38.0.1 profile, without any plugins and addons, with all settings on default, same issue.
I disabled hardware acceleration in Firefox... and I got it.
Looks like it's related to video hardware acceleration. I am using AMD Catalyst 15.4 Beta video driver, for my graphics card AMD Radeon HD 7950.

Here's Troubleshooting Information page:

Application Basics
------------------

Name: Firefox
Version: 38.0.1
Build ID: 20150513174244
Update Channel: release
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Multiprocess Windows: 0/1 (default: false)

Crash Reports for the Last 3 Days
---------------------------------

All Crash Reports

Extensions
----------

Graphics
--------

Adapter Description: AMD Radeon HD 7900 Series
Adapter Drivers: aticfx64 aticfx64 aticfx64 aticfx32 aticfx32 aticfx32 atiumd64 atidxx64 atidxx64 atiumdag atidxx32 atidxx32 atiumdva atiumd6a atitmm64
Adapter RAM: 3072
Device ID: 0x6798
Direct2D Enabled: true
DirectWrite Enabled: true (6.2.9200.17292)
Driver Date: 3-31-2015
Driver Version: 14.502.1014.0
GPU #2 Active: false
GPU Accelerated Windows: 1/1 Direct3D 11 (OMTC)
Subsys ID: 3000174b
Vendor ID: 0x1002
WebGL Renderer: Google Inc. -- ANGLE (AMD Radeon HD 7900 Series Direct3D11 vs_5_0 ps_5_0)
windowLayerManagerRemote: true
AzureCanvasBackend: direct2d 1.1
AzureContentBackend: direct2d 1.1
AzureFallbackCanvasBackend: cairo
AzureSkiaAccelerated: 0

Important Modified Preferences
------------------------------

browser.cache.disk.capacity: 358400
browser.cache.disk.smart_size.first_run: false
browser.cache.frecency_experiment: 1
browser.download.importedFromSqlite: true
browser.places.smartBookmarksVersion: 7
browser.sessionstore.upgradeBackup.latestBuildID: 20150513174244
browser.startup.homepage_override.buildID: 20150513174244
browser.startup.homepage_override.mstone: 38.0.1
dom.mozApps.used: true
extensions.lastAppVersion: 38.0.1
gfx.direct3d.last_used_feature_level_idx: 0
network.cookie.prefsMigrated: true
places.history.expiration.transient_current_max_pages: 104858
plugin.disable_full_page_plugin_for_types: application/pdf
privacy.sanitize.migrateFx3Prefs: true

Important Locked Preferences
----------------------------

JavaScript
----------

Incremental GC: true

Accessibility
-------------

Activated: true
Prevent Accessibility: 0

Library Versions
----------------

NSPR
Expected minimum version: 4.10.8
Version in use: 4.10.8

NSS
Expected minimum version: 3.18.1 Basic ECC
Version in use: 3.18.1 Basic ECC

NSSSMIME
Expected minimum version: 3.18.1 Basic ECC
Version in use: 3.18.1 Basic ECC

NSSSSL
Expected minimum version: 3.18.1 Basic ECC
Version in use: 3.18.1 Basic ECC

NSSUTIL
Expected minimum version: 3.18.1
Version in use: 3.18.1

Experimental Features
---------------------
Component: Untriaged → PDF Viewer
Attachment #8610213 - Attachment mime type: application/force-download → application/pdf
WFM with FF38 on Win 7, I see both images.
I am now uninstalling AMD Catalyst beta drivers, I will see how it goes without drivers and with stable driver.
I just installed stable AMD Catalyst driver 14.12, same issue.
When I disable Hardware Acceleration in Firefox images are displaying fine.
Summary: PDF file not displayed correctly in Firefox → PDF file not displayed correctly in Firefox (when Hardware Acceleration is enabled)
WFM on NVIDIA
OS: Unspecified → Windows 7
Hardware: Unspecified → x86_64
Whiteboard: [pdfjs-c-rendering][pdfjs-d-hwa-on]
Priority: -- → P3
I installed Firefox from Beta Channel, currently it's presenting itself as Firefox 39 Beta 3:
Build identifier: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:39.0) Gecko/20100101 Firefox/39.0

In Firefox 39 (Beta) and stable AMD Catalyst drivers issue is still existing.
I am attaching screenshot showing PDF displayed incorrectly, AMD Catalyst opened with version information, and Firefox about:support page with Hardware Acceleration details.
Firefox 39 Beta 3
AMD Catalyst Omega 14.12
Hardware acceleration in Firefox enabled
I don't have AMD hardware available, but can you try http://jsbin.com/gufozi/1/ to see if you can reproduce it there (I extracted code that drawing pictures)?
Flags: needinfo?(pioruns)
(In reply to Yury Delendik (:yury) from comment #10)
> I don't have AMD hardware available, but can you try
> http://jsbin.com/gufozi/1/ to see if you can reproduce it there (I extracted
> code that drawing pictures)?

Yes, I can reproduce problem on that page. Screenshot attached below.
Flags: needinfo?(pioruns)
Attached image 2015-06-09 19.37.30.png
Screenshot of http://output.jsbin.com/gufozi/1/ webpage opened
The test case above demonstrates issue with canvas 2d for some AMD hardware on windows and that is not only PDF viewer issue.
Component: PDF Viewer → Canvas: 2D
Product: Firefox → Core
Duplicate of this bug: 1170739
If you are interested, I reduce the test case at http://jsbin.com/fugewiquwa/1/.
It should display a black rectangle, but not on my computer.

The main problem is 'putImageData'. It fails to render image when the image source size is different or offset parameter are not 0.
But strange behaviour: when context has been previously manipulated with other methods (in my example I use 'fillRect' for just making a dot), 'putImageData' renders the black rectangle correctly.
better test case: http://jsbin.com/fiwimimidi/1/
(In reply to samycookie from comment #17)
> better test case: http://jsbin.com/fiwimimidi/1/

I just checked that on my machine, with Hardware Acceleration enabled I see 3 black squares, with Acceleration disabled I see 5 black squares.
Whiteboard: [pdfjs-c-rendering][pdfjs-d-hwa-on] → [pdfjs-c-rendering][pdfjs-d-hwa-on][gfx-noted]
Tried to reproduce this on a variety of drivers on an R7 240. The drivers can be taken from here: (http://support.amd.com/en-us/download/desktop/previous?os=Windows%207%20-%2064). I am unable to reproduce using driver 14.4 and previous versions. Pioruns, can you try to reproduce using 14.4?
Flags: needinfo?(pioruns)
I will test this tomorrow, I am downloading driver now. Can you reproduce this on current driver 14.12?
I meant that all versions after 14.4 do exhibit the problem. I've seen it reproduce on 14.9 and up.
Cannot reproduce this on an R9 290 driver version 14.502.1014.1001.
I just uninstalled AMD Catalyst driver (14.12). Rebooted, I am on default Windows driver (14.502.1014.0).
I still can reproduce this problem. Screenshot attached, you can see 3 black squares, driver version and info from about:support.
Flags: needinfo?(pioruns)
Just to confirm, with Hardware Acceleration disabled in Firefox I can see again 5 black squares. Default Windows driver (14.502.1014.0).
I got a clue now.

I just taken out my discrete graphics card - Sapphire Radeon HD 7970. I connected monitor to APU (processor is AMD A10-5700 APU). And with hardware acceleration enabled I can see 5 black squares. Still using 14.502.1014.0 driver.
> Pioruns, can you try to reproduce using 14.4?

I installed 14.4 driver. Tried it both on APU and on discrete Radeon HD 7970. In both cases I cannot reproduce problem, I can see 5 black squares nicely.
Flags: needinfo?(kfung)
But there is one more thing worth to mention about 14.4 - Firefox detects that driver is old and disable some acceleration as I understand it. Here's paste from about:support:

Graphics
Adapter Description	AMD Radeon HD 7900 Series
Adapter Drivers	aticfx64 aticfx64 aticfx64 aticfx32 aticfx32 aticfx32 atiumd64 atidxx64 atidxx64 atiumdag atidxx32 atidxx32 atiumdva atiumd6a atitmm64
Adapter RAM	3072
Asynchronous Pan/Zoom	none
Device ID	0x6798
Direct2D Enabled	Blocked for your graphics driver version. Try updating your graphics driver to version ATI Catalyst 14.6+ or newer.
DirectWrite Enabled	false (6.2.9200.17292)
Driver Date	4-17-2014
Driver Version	14.100.0.0
GPU #2 Active	false
GPU Accelerated Windows	1/1 Direct3D 11 (OMTC)
Subsys ID	3000174b
Vendor ID	0x1002
WebGL Renderer	Google Inc. -- ANGLE (AMD Radeon HD 7900 Series Direct3D11 vs_5_0 ps_5_0)
windowLayerManagerRemote	true
AzureCanvasBackend	skia
AzureContentBackend	cairo
AzureFallbackCanvasBackend	cairo
AzureSkiaAccelerated	0
And latest result:
AMD driver 14.12. APU A10-5700 graphics card is working fine, cannot reproduce issue. After plugging back my discrete HD 7970, again I can reproduce issue.

Quick summary:
14.502.1014.0 driver: APU works fine, HD 7970 bugged

14.4 driver: APU works fine, HD 7970 works fine (because Direct2D and DirectWrite is disabled, driver is blacklisted by Firefox)

14.12 driver : APU works fine, HD 7970 bugged

In all cases problem seems to be in HD 7970, when APU is used to display graphics problem does not occur.
The problem seems to go away when settings gfx.direct2d.use1_1 to false in about:config. It looks like a driver issue for Direct 2D 1.1 on cards with GCN 1.0 architecture.
Flags: needinfo?(kfung)
So where it can be reported?
Attached patch copy-surface-force-bitmap.patch (obsolete) — Splinter Review
This seems to work around it by making CopySurface in the D2D1 backend use the same functions as the D2D backend whenever it can, similar to the work around from Bug 1160070.
Attachment #8624883 - Flags: review?(bas)
Also, we've sent a bug report to AMD about this issue; just waiting for response.
Comment on attachment 8624883 [details] [diff] [review]
copy-surface-force-bitmap.patch

Review of attachment 8624883 [details] [diff] [review]:
-----------------------------------------------------------------

::: gfx/2d/DrawTargetD2D1.cpp
@@ +345,5 @@
> +  //Draw using image if it's not possible to draw with bitmap
> +  if (!bitmap && mFormat != SurfaceFormat::A8) {
> +      mDC->DrawImage(image, D2D1::Point2F(Float(aDestination.x), Float(aDestination.y)),
> +                     D2DRect(srcRect), D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
> +                     D2D1_COMPOSITE_MODE_BOUNDED_SOURCE_COPY);

You need a return here.

@@ +348,5 @@
> +                     D2DRect(srcRect), D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
> +                     D2D1_COMPOSITE_MODE_BOUNDED_SOURCE_COPY);
> +  }
> +
> +  mDC->PushAxisAlignedClip(D2DRect(dstRect), D2D1_ANTIALIAS_MODE_ALIASED);

This is way more expensive than the approach the code currently takes. Can we somehow only do this on affected hardware or something, or is there some other way we can detect when this is needed.
Replaced the push clip, clear, pop clip stuff by setting the primitive blend mode to copy. Seems to work fine on my machine.
Attachment #8624883 - Attachment is obsolete: true
Attachment #8624883 - Flags: review?(bas)
Attachment #8627430 - Flags: review?(bas)
I would like to test it, can someone compile a webpage with visual test of this patch?
Forgot to reset the blend state

Try:
https://treeherder.mozilla.org/#/jobs?repo=try&revision=cf919b41cd5f
Attachment #8627430 - Attachment is obsolete: true
Attachment #8627430 - Flags: review?(bas)
Attachment #8627748 - Flags: review?(bas)
Pioruns, you can get a Windows binary from the try build after it's done. It should be done within a few hours. Test it out and see if it works.
Attachment #8627748 - Flags: review?(bas) → review+
It is done yet? I look at Try webpage not it mostly shows 0% progress.
Pioruns, the binaries are available at http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/kfung@mozilla.com-cf919b41cd5f/try-win32/ (can be found via clicking "B" near "Windows XP opt", then navigating to "Build: x86 windowsxp win" link shown at the bottom left panel)
Keywords: checkin-needed
I tried patch on Nightly version from test build you provided

Name 	Firefox
Version 	41.0a1
Build ID 	20150630092626

It works! 5 squares on website http://jsbin.com/fiwimimidi/1/
with Hardware Acceleration enabled.
I restarted to Firefox Beta 64, problem reoccured. Version of Nightly with patches definitely fixes the problem.
[Tracking Requested - why for this release]: This seems like the kind of thing we'd want to backport anywhere and everywhere.
Assignee: nobody → kfung
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
https://hg.mozilla.org/mozilla-central/rev/8d86b5dc1577
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla42
Comment on attachment 8627748 [details] [diff] [review]
copy-surface-force-bitmap-v3.patch

[Approval Request Comment]
If this is not a sec:{high,crit} bug, please state case for ESR consideration: Improper rendering on some cards
User impact if declined: Improper rendering on some cards
Fix Landed on Version:
Risk to taking this patch (and alternatives if risky): Not much, unless it exposes another driver bug previously not seen
String or UUID changes made by this patch: 

See https://wiki.mozilla.org/Release_Management/ESR_Landing_Process for more info.

Approval Request Comment
[Feature/regressing bug #]: Bug 1168189
[User impact if declined]: Incorrect rendering
[Describe test coverage new/current, TreeHerder]: Manually test correctness
[Risks and why]: We want things to render properly
[String/UUID change made/needed]:
Attachment #8627748 - Flags: approval-mozilla-release?
Attachment #8627748 - Flags: approval-mozilla-esr38?
Attachment #8627748 - Flags: approval-mozilla-beta?
Attachment #8627748 - Flags: approval-mozilla-aurora?
Tracking as we'll want this fix everywhere. I have left ESR38 as a ? for now as we don't yet have a 40+ option.
Comment on attachment 8627748 [details] [diff] [review]
copy-surface-force-bitmap-v3.patch

Functional correctness PDF fix verified by the submitter. Beta+ Aurora+

For ESR38, do we know when this issue was introduced?

For release, this is not a driver for a point release but can be considered for a ride-along.
Attachment #8627748 - Flags: approval-mozilla-beta?
Attachment #8627748 - Flags: approval-mozilla-beta+
Attachment #8627748 - Flags: approval-mozilla-aurora?
Attachment #8627748 - Flags: approval-mozilla-aurora+
I can check ESR on my machine, which versions of Firefox should I download to test it? I will be happy to find this regression and identify where it has been introduced.
Setting for QA verification. This should be in Firefox 40 Beta 2 (ftp://ftp.mozilla.org/pub/mozilla.org/firefox/candidates/40.0b2-candidates/).

Reporter and people who reproduced this are welcome to give it a spin and confirm the fix (we may not have the Hardware needed to reproduce the original issue).
Flags: qe-verify+
Screenshot of my desktop running Firefox 40 Beta 2 - bug is fixed. I have opened test case with squares, and original PDF file which discovered this regression, along with about:support tab showing Hardware Acceleration enabled. Big thanks for everyone involved for fixing this issue!
amazing thanks
(In reply to pioruns from comment #51)
> Screenshot of my desktop running Firefox 40 Beta 2 - bug is fixed. I have
> opened test case with squares, and original PDF file which discovered this
> regression, along with about:support tab showing Hardware Acceleration
> enabled. Big thanks for everyone involved for fixing this issue!

Thank you for verifying this so quickly! Marking as verified for Firefox 40 Beta.
I confirmed this is fixed for me in v40b2 equally.
cf. https://github.com/mozilla/pdf.js/issues/5986

Thanks all !
Comment on attachment 8627748 [details] [diff] [review]
copy-surface-force-bitmap-v3.patch

We shipped 38 with this bug. I think this can ride the train with 40...
Not sure it is critical enough for esr and it can carry some additional risk to the release.
Attachment #8627748 - Flags: approval-mozilla-release?
Attachment #8627748 - Flags: approval-mozilla-release-
Attachment #8627748 - Flags: approval-mozilla-esr38?
Attachment #8627748 - Flags: approval-mozilla-esr38-
Removing the qe-verify+ flag since it was already verified fixed on Firefox 40 and we can't reproduce the initial issue.
Flags: qe-verify+
You need to log in before you can comment on or make changes to this bug.