Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix transparency #12561

Merged
merged 2 commits into from Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions atom/browser/api/atom_api_web_contents.cc
Expand Up @@ -276,6 +276,9 @@ content::ServiceWorkerContext* GetServiceWorkerContext(
void OnCapturePageDone(const base::Callback<void(const gfx::Image&)>& callback,
const SkBitmap& bitmap,
content::ReadbackResponse response) {
// Hack to enable transparency in captured image
// TODO(nitsakh) Remove hack once fixed in chromium
const_cast<SkBitmap&>(bitmap).setAlphaType(kPremul_SkAlphaType);
callback.Run(gfx::Image::CreateFrom1xBitmap(bitmap));
}

Expand Down
23 changes: 23 additions & 0 deletions spec/api-browser-window-spec.js
Expand Up @@ -442,6 +442,29 @@ describe('BrowserWindow module', () => {
done()
})
})

it('preserves transparency', (done) => {
w.close()
const width = 400
const height = 400
w = new BrowserWindow({
show: false,
width: width,
height: height,
transparent: true
})
w.loadURL('data:text/html,<html><body background-color: rgba(255,255,255,0)></body></html>')
w.once('ready-to-show', () => {
w.show()
w.capturePage((image) => {
let imgBuffer = image.toPNG()
// Check 25th byte in the PNG
// Values can be 0,2,3,4, or 6. We want 6, which is RGB + Alpha
assert.equal(imgBuffer[25], 6)
done()
})
})
})
})

describe('BrowserWindow.setSize(width, height)', () => {
Expand Down