Back out bug 760342 for Windows build error, bug 755070 for Android crashes, and bug 760458 because it depends on 755070

This commit is contained in:
Matt Brubeck
2012-06-01 17:45:02 -07:00
parent d203db5424
commit 3024f60165
17 changed files with 138 additions and 338 deletions

View File

@@ -29,8 +29,6 @@
#include "nsIDocShell.h"
#include "nsPIDOMWindow.h"
#include "mozilla/dom/ScreenOrientation.h"
#include "nsIDOMWindowUtils.h"
#include "nsIDOMClientRect.h"
#ifdef DEBUG
#define ALOG_BRIDGE(args...) ALOG(args)
@@ -2350,33 +2348,36 @@ jobject JNICALL
Java_org_mozilla_gecko_GeckoAppShell_allocateDirectBuffer(JNIEnv *env, jclass, jlong size);
nsresult AndroidBridge::TakeScreenshot(nsIDOMWindow *window, PRInt32 srcX, PRInt32 srcY, PRInt32 srcW, PRInt32 srcH, PRInt32 dstX, PRInt32 dstY, PRInt32 dstW, PRInt32 dstH, PRInt32 bufW, PRInt32 bufH, PRInt32 tabId, PRInt32 token, jobject buffer)
nsresult AndroidBridge::TakeScreenshot(nsIDOMWindow *window, PRInt32 srcX, PRInt32 srcY, PRInt32 srcW, PRInt32 srcH, PRInt32 dstW, PRInt32 dstH, PRInt32 tabId, float scale, PRInt32 token)
{
nsresult rv;
float scale = 1.0;
if (!buffer)
return NS_OK;
// take a screenshot, as wide as possible, proportional to the destination size
if (!srcW && !srcH) {
nsCOMPtr<nsIDOMWindowUtils> utils = do_GetInterface(window);
if (!utils)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMClientRect> rect;
rv = utils->GetRootBounds(getter_AddRefs(rect));
nsCOMPtr<nsIDOMDocument> doc;
rv = window->GetDocument(getter_AddRefs(doc));
NS_ENSURE_SUCCESS(rv, rv);
if (!rect)
if (!doc)
return NS_ERROR_FAILURE;
float left, top, width, height;
rect->GetLeft(&left);
rect->GetTop(&top);
rect->GetWidth(&width);
rect->GetHeight(&height);
nsCOMPtr<nsIDOMElement> docElement;
rv = doc->GetDocumentElement(getter_AddRefs(docElement));
NS_ENSURE_SUCCESS(rv, rv);
if (!docElement)
return NS_ERROR_FAILURE;
if (width == 0 || height == 0)
PRInt32 viewportHeight;
PRInt32 pageWidth;
PRInt32 pageHeight;
window->GetInnerHeight(&viewportHeight);
docElement->GetScrollWidth(&pageWidth);
docElement->GetScrollHeight(&pageHeight);
// use the page or viewport dimensions, whichever is larger
PRInt32 width = pageWidth;
PRInt32 height = viewportHeight > pageHeight ? viewportHeight : pageHeight;
if (!width || !height)
return NS_ERROR_FAILURE;
float aspectRatio = ((float) dstW) / dstH;
@@ -2387,9 +2388,6 @@ nsresult AndroidBridge::TakeScreenshot(nsIDOMWindow *window, PRInt32 srcX, PRInt
srcW = height * aspectRatio;
srcH = height;
}
srcX = left;
srcY = top;
}
JNIEnv* env = GetJNIEnv();
@@ -2417,17 +2415,21 @@ nsresult AndroidBridge::TakeScreenshot(nsIDOMWindow *window, PRInt32 srcX, PRInt
nsPresContext::CSSPixelsToAppUnits(srcW / scale),
nsPresContext::CSSPixelsToAppUnits(srcH / scale));
PRUint32 stride = bufW * 2 /* 16 bpp */;
PRUint32 stride = dstW * 2;
PRUint32 bufferSize = dstH * stride;
jobject buffer = Java_org_mozilla_gecko_GeckoAppShell_allocateDirectBuffer(env, NULL, bufferSize);
if (!buffer)
return NS_OK;
void* data = env->GetDirectBufferAddress(buffer);
nsRefPtr<gfxImageSurface> surf = new gfxImageSurface(static_cast<unsigned char*>(data), nsIntSize(bufW, bufH), stride, gfxASurface::ImageFormatRGB16_565);
memset(data, 0, bufferSize);
nsRefPtr<gfxImageSurface> surf = new gfxImageSurface(static_cast<unsigned char*>(data), nsIntSize(dstW, dstH), stride, gfxASurface::ImageFormatRGB16_565);
nsRefPtr<gfxContext> context = new gfxContext(surf);
gfxPoint pt(dstX, dstY);
context->Translate(pt);
context->Scale(scale * dstW / srcW, scale * dstH / srcH);
rv = presShell->RenderDocument(r, renderDocFlags, bgColor, context);
NS_ENSURE_SUCCESS(rv, rv);
env->CallStaticVoidMethod(AndroidBridge::Bridge()->mGeckoAppShellClass, AndroidBridge::Bridge()->jNotifyScreenShot, buffer, tabId, srcX * dstW / srcW , srcY * dstH / srcH, bufW, bufH, token);
env->CallStaticVoidMethod(AndroidBridge::Bridge()->mGeckoAppShellClass, AndroidBridge::Bridge()->jNotifyScreenShot, buffer, tabId, srcX * dstW / srcW , srcY * dstH / srcH, dstW, dstH, token);
return NS_OK;
}