transparent background on body ? (linux/chromeos)

1,610 views
Skip to first unread message

oshima

unread,
Sep 10, 2010, 8:57:16 PM9/10/10
to chromium-dev
[from right address this time...]

Hi,

I'd like to use transparent body background so that I can compose domui and a window behind it (for chromeos),
and looking for a help to find out where to look at/start. Is this something possible with current webkit/renderer
design or it requires a lot work on both side? Any help would be appreciated.

Thanks!
- oshima

Brett Wilson

unread,
Sep 10, 2010, 9:47:55 PM9/10/10
to osh...@chromium.org, chromium-dev

You won't be able to get text subpixel antialiasing if you do this. It
will require some changes inside our WebKit port to be able to disable
subpixel AA in this case. Extensions wanted something similar, and
they ended up drawing "what would be behind the extension" (i.e. the
toolbar background) below the page so it's always drawing to an opaque
surface to get full rendering fidelity.

Brett

Patrick Horn

unread,
Sep 11, 2010, 4:09:51 AM9/11/10
to chromi...@chromium.org
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
I've done this, and it works on Linux--though as Brett notes, the text quality won't be as good.

void setTransparent(bool enable) {
  SkBitmap bg;
  int bitmap = 0; // transparent pixel to reference.
  if (enable) {
    bg.setConfig(SkBitmap::kA1_Config, 1, 1); // 1x1 alpha bitmap.
    bg.setPixels(&bitmap); // only one pixel
  }
  render_widget_host_->Send(new ViewMsg_SetBackground(
      render_widget_host_->routing_id(),
      bg));
}

Normally, the renderer does not clear its internal paint buffer, but in this case, you also need to clear the canvas in RenderWidget::DoDeferredUpdate.
On render_widget.cpp line 504, right after getting the canvas, you need to add:
  if (!background_.empty() && !background_.isOpaque()) {
    // If the background contains any transparency, we must clear the output
    // buffer, or we will end up with garbage from the last render.
    canvas->drawARGB(0,0,0,0,SkXfermode::kClear_Mode);
  }

Also, note that skia uses pre-multiplied alpha, so if you send this directly to the X backing store, partially-transparent parts may look darker than normal, which makes anti-aliased text look ugly. If you use skia for blending, it should be fine.

-Patrick

oshima

unread,
Sep 13, 2010, 4:04:40 AM9/13/10
to patric...@gmail.com, chromi...@chromium.org
Brett, Patrick, thank you for the info!

Does this mean if the background is fully opaque, antialias should work?

By the way, I found the thread that may be related.


It sounds like subpixel rendering does not work if RenderLayer needs to use rgba background?
am i wrong?

- oshima
 

-Patrick

Brett Wilson

unread,
Sep 13, 2010, 11:42:12 AM9/13/10
to osh...@chromium.org, patric...@gmail.com, chromi...@chromium.org

Yes.

> By the way, I found the thread that may be related.
> http://code.google.com/p/chromium/issues/detail?id=27806
> It sounds like subpixel rendering does not work if RenderLayer needs to use
> rgba background?

That bug was marked invalid and I don't see it mention RenderLayer, so
I'm not sure if there's anything to be learned from it.

Brett

Evan Martin

unread,
Sep 13, 2010, 12:28:23 PM9/13/10
to osh...@chromium.org, Daniel Erat, chromium-dev
On Fri, Sep 10, 2010 at 5:57 PM, oshima <osh...@chromium.org> wrote:

The rest of the thread discusses layering web page contents with
transparency, but your mention of "window" makes me wonder if you're
talking about top-level window. In that case, transparency is managed
a few layers out -- the transparency information needs to be
communicated to the window manager. I'm sure CrOS already does this
in some places.

oshima

unread,
Sep 13, 2010, 12:55:27 PM9/13/10
to Evan Martin, Daniel Erat, chromium-dev
Yes, ChromeOS WM does composition. What I'd like to do is basically same as
what we're already doing with login screen and panel, make the window transparent,
use (partly) transparent background and compose with a window behind it using
WM, but with DOMUI instead of gtk/views.

- oshima

Reply all
Reply to author
Forward
0 new messages