Hello everybody,
I managed to get to the pixels. Here cometh the snippet. DISCLAIMER:
this works for me, and it's probably still buggy. I still have to
understand if and where I have to use smart pointers, and I know never
free memory, and a lot of other stuff that must be fixed. All I know
is that "textureBuffer" points to a memory zone that I can
subsequently render in a OpenGL texture, so I can tell it works.
Ciao,
Aaron/Babele
void EmbeddedBrowser::GrabWindow()
{
nsCOMPtr<nsIDOMWindow> domWindow;
nsresult rv = mWebBrowser-
>GetContentDOMWindow(getter_AddRefs(domWindow));
assert(NS_SUCCEEDED(rv) && domWindow);
nsCOMPtr<nsICanvasRenderingContextInternal> context;
context = do_CreateInstance("@mozilla.org/content/canvas-rendering-
context;1?id=2d", &rv);
assert(NS_SUCCEEDED(rv) && context);
context->SetDimensions(512, 512);
context->SetCanvasElement(nsnull);
nsCOMPtr<nsIDOMCanvasRenderingContext2D> domCanvas;
domCanvas = do_QueryInterface(context, &rv);
assert(NS_SUCCEEDED(rv) && domCanvas);
rv = domCanvas->DrawWindow(domWindow, 0, 0, 512, 512,
NS_LITERAL_STRING("rgb(0,0,0)"));
assert (NS_SUCCEEDED(rv));
gfxASurface* DOMRenderedSurface = NULL;
rv = context->GetThebesSurface(&DOMRenderedSurface);
assert (NS_SUCCEEDED(rv) && DOMRenderedSurface);
assert(DOMRenderedSurface->GetType() ==
gfxASurface::SurfaceTypeWin32);
assert(DOMRenderedSurface->GetContentType() ==
gfxASurface::CONTENT_COLOR_ALPHA);
nsRefPtr<gfxImageSurface> imgSurface = new
gfxImageSurface(gfxIntSize(512,
512),gfxImageSurface::ImageFormatARGB32);
assert(imgSurface);
gfxContext* dcontext = new gfxContext(imgSurface);
assert(dcontext);
dcontext->SetOperator(gfxContext::OPERATOR_SOURCE);
dcontext->SetSource(DOMRenderedSurface);
dcontext->Paint();
PRUint32* imageData = (PRUint32*)imgSurface->Data();
textureBuffer = (char*) imageData;
}
_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding