Support for off-screen rendering

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Re: Support for off-screen rendering

Postby cgravill » Wed Mar 17, 2010 8:07 am

I can outline what I did.

Create a separate window offscreen somewhere.
Fetch the hwnd via the handler instance (make sure it's the one Webkit is actually rendering to).
Create a target, you should be able to use an in memory bitmap, we use another toolkit.
Copy the area of the hwnd you want into the hdc of your target using e.g. PrintWindow or BitBlt.

I haven't figured out a way to get notifications of needing to redraw yet so if you find a way it would be nice to hear.
cgravill
Newbie
 
Posts: 2
Joined: Tue Feb 23, 2010 11:09 am

Re: Support for off-screen rendering

Postby jerryprez » Sat Mar 27, 2010 6:30 am

cgravill wrote:I can outline what I did.

Create a separate window offscreen somewhere.
Fetch the hwnd via the handler instance (make sure it's the one Webkit is actually rendering to).
Create a target, you should be able to use an in memory bitmap, we use another toolkit.
Copy the area of the hwnd you want into the hdc of your target using e.g. PrintWindow or BitBlt.

I haven't figured out a way to get notifications of needing to redraw yet so if you find a way it would be nice to hear.


Thanks for your information!
I've decided to add a render method of CefBrowserImpl that calls the WebKit::WebView's paint method to paint directly onto a skia canvas and then copy the pixel bits to a memory buffer.

About your concern of getting notifications of needing to redraw, I think you might be interested in WebWidgetHost::DidScrollRect and WebWidgetHost::DidInvalidateRect to monitor and maintain a "dirty" area (rect) and a flag to indicate whether it needs to repaint or not.
Hope this helps.

Regards.
jerryprez
Newbie
 
Posts: 7
Joined: Thu Feb 25, 2010 6:04 am

Re: Support for off-screen rendering

Postby emerick » Tue Mar 30, 2010 9:33 am

Jerry,

If you can/would share your code, I'd love to take a look. I'm working on something quite similar and will need to support off-screen rendering as well.

It's starting to sound like direct CEF support for this feature would be helpful. :-)

Thanks,

Emerick
emerick
Expert
 
Posts: 154
Joined: Sun Feb 21, 2010 7:57 pm
Location: Belmont, MA

Re: Support for off-screen rendering

Postby jerryprez » Wed Mar 31, 2010 3:42 am

Hi Emerick,
Below is the code that I use in my render routine.
To render Flash content, you also need to implement a Windowless Plugin Delegate and replace it with the default plugin in
BrowserWebViewDelegate::CreatePluginDelegate()


Code: Select all

WebKit::WebSize WebWidgetHost::GetSize()
{
   return webwidget_->size();
}

void CefBrowserImpl::UIT_Render( CefFrame* frame )
{
   REQUIRE_UIT();
   if (renderbuffer_)
   {
      free(renderbuffer_);
      renderwidth_ = renderheight_ = 0;
      renderbuffer_ = NULL;
   }
   WebFrame* webframe = GetWebFrame(frame);
   if (!webframe)
      return;
   WebView* webview = webframe->view();
   if (!webview)
      return;
   WebSize websize = webviewhost_->GetSize();
   if ( (canvas_->getTopPlatformDevice().width() != websize.width)
      || (canvas_->getTopPlatformDevice().height() != websize.height) )
   {
      delete canvas_;
      canvas_ = new skia::PlatformCanvas(websize.width, websize.height, true);
   }
   webview->layout();
   webview->paint(canvas_, gfx::Rect(0, 0, websize.width, websize.height));

   renderwidth_ = canvas_->getTopPlatformDevice().width();
   renderheight_ = canvas_->getTopPlatformDevice().height();
   const SkBitmap& sourceBitmap = canvas_->getTopPlatformDevice().accessBitmap(false);
   SkAutoLockPixels sourceBitmapLock(sourceBitmap);

   int nBytes = sourceBitmap.getSize();
   renderbuffer_ = malloc(nBytes);
   if (renderbuffer_)
      memcpy(renderbuffer_, sourceBitmap.getPixels(), nBytes);
}
Last edited by jerryprez on Wed Mar 31, 2010 9:47 pm, edited 1 time in total.
jerryprez
Newbie
 
Posts: 7
Joined: Thu Feb 25, 2010 6:04 am

Re: Support for off-screen rendering

Postby emerick » Wed Mar 31, 2010 8:15 am

Jerry,

Thanks for sharing your code. That looks like exactly what I need and it's always helpful to see someone else's approach.

Cheers,

Emerick
emerick
Expert
 
Posts: 154
Joined: Sun Feb 21, 2010 7:57 pm
Location: Belmont, MA

Re: Support for off-screen rendering

Postby emerick » Thu Apr 01, 2010 10:47 am

Does anyone have any experience rendering a scaled image? In my application, I'm trying to render a webpage thumbnail, which will be about half the size of the actual webpage. In my naive attempt, I was doing this:

Code: Select all
canvas.scale(SkScalar(0.50), SkScalar(0.50));
webview->layout();
webview->paint(canvas, ...);


This does indeed scale the image down, but the quality of the scaled image is really low. I expect a small amount of blurriness, but my resulting image is absolutely terrible.

Am I just going about this the wrong way? Should I be trying to reduce the size of the webview itself before rendering? Just curious if anyone here had any experience with this.

Thanks,

Emerick
emerick
Expert
 
Posts: 154
Joined: Sun Feb 21, 2010 7:57 pm
Location: Belmont, MA

Previous

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 62 guests