Fix for bug 762654 (Switch the Azure 2d canvas context to new DOM bindings). r=bz.

This commit is contained in:
Peter Van der Beken 2012-05-21 23:30:07 +02:00
Родитель b0344cefa6
Коммит ad2c6d7b5a
6 изменённых файлов: 72 добавлений и 15 удалений

Просмотреть файл

@ -129,6 +129,14 @@ protected:
nsRefPtr<nsHTMLCanvasElement> mCanvasElement;
};
namespace mozilla {
namespace dom {
extern bool AzureCanvasEnabled();
}
}
NS_DEFINE_STATIC_IID_ACCESSOR(nsICanvasRenderingContextInternal,
NS_ICANVASRENDERINGCONTEXTINTERNAL_IID)

Просмотреть файл

@ -95,6 +95,7 @@
#include "mozilla/dom/BindingUtils.h"
#include "nsHTMLImageElement.h"
#include "nsHTMLVideoElement.h"
#include "mozilla/dom/CanvasRenderingContext2DBinding.h"
#ifdef XP_WIN
#include "gfxWindowsPlatform.h"
@ -545,19 +546,51 @@ PRUint32 nsCanvasRenderingContext2DAzure::sNumLivingContexts = 0;
PRUint8 (*nsCanvasRenderingContext2DAzure::sUnpremultiplyTable)[256] = nsnull;
PRUint8 (*nsCanvasRenderingContext2DAzure::sPremultiplyTable)[256] = nsnull;
namespace mozilla {
namespace dom {
static bool
AzureCanvasEnabledOnPlatform()
{
#ifdef XP_WIN
if (gfxWindowsPlatform::GetPlatform()->GetRenderMode() !=
gfxWindowsPlatform::RENDER_DIRECT2D ||
!gfxWindowsPlatform::GetPlatform()->DWriteEnabled()) {
static bool checkedPref = false;
static bool preferSkia;
if (!checkedPref) {
preferSkia = Preferences::GetBool("gfx.canvas.azure.prefer-skia", false);
checkedPref = true;
}
return preferSkia;
}
#elif !defined(XP_MACOSX) && !defined(ANDROID) && !defined(LINUX)
return false;
#endif
return true;
}
bool
AzureCanvasEnabled()
{
static bool checkedPref = false;
static bool azureEnabled;
if (!checkedPref) {
azureEnabled = Preferences::GetBool("gfx.canvas.azure.enabled", false);
checkedPref = true;
}
return azureEnabled && AzureCanvasEnabledOnPlatform();
}
}
}
nsresult
NS_NewCanvasRenderingContext2DAzure(nsIDOMCanvasRenderingContext2D** aResult)
{
#ifdef XP_WIN
if ((gfxWindowsPlatform::GetPlatform()->GetRenderMode() !=
gfxWindowsPlatform::RENDER_DIRECT2D ||
!gfxWindowsPlatform::GetPlatform()->DWriteEnabled()) &&
!Preferences::GetBool("gfx.canvas.azure.prefer-skia", false)) {
if (!AzureCanvasEnabledOnPlatform()) {
return NS_ERROR_NOT_AVAILABLE;
}
#elif !defined(XP_MACOSX) && !defined(ANDROID) && !defined(LINUX)
return NS_ERROR_NOT_AVAILABLE;
#endif
nsRefPtr<nsIDOMCanvasRenderingContext2D> ctx = new nsCanvasRenderingContext2DAzure();
if (!ctx)
@ -575,6 +608,7 @@ nsCanvasRenderingContext2DAzure::nsCanvasRenderingContext2DAzure()
, mInvalidateCount(0)
{
sNumLivingContexts++;
SetIsDOMBinding();
}
nsCanvasRenderingContext2DAzure::~nsCanvasRenderingContext2DAzure()
@ -593,6 +627,13 @@ nsCanvasRenderingContext2DAzure::~nsCanvasRenderingContext2DAzure()
}
}
JSObject*
nsCanvasRenderingContext2DAzure::WrapObject(JSContext *cx, JSObject *scope,
bool *triedToWrap)
{
return CanvasRenderingContext2DBinding::Wrap(cx, scope, this, triedToWrap);
}
bool
nsCanvasRenderingContext2DAzure::ParseColor(const nsAString& aString,
nscolor* aColor)

Просмотреть файл

@ -138,6 +138,9 @@ public:
nsCanvasRenderingContext2DAzure();
virtual ~nsCanvasRenderingContext2DAzure();
virtual JSObject* WrapObject(JSContext *cx, JSObject *scope,
bool *triedToWrap);
nsHTMLCanvasElement* GetCanvas() const
{
return mCanvasElement;

Просмотреть файл

@ -19548,7 +19548,11 @@ ok(window.CanvasRenderingContext2D.prototype, "window.CanvasRenderingContext2D.p
window.CanvasRenderingContext2D.prototype.fill = 1;
ok(window.CanvasRenderingContext2D.prototype.fill === 1, "window.CanvasRenderingContext2D.prototype.fill === 1");
delete window.CanvasRenderingContext2D.prototype.fill;
todo(window.CanvasRenderingContext2D.prototype.fill === undefined, "window.CanvasRenderingContext2D.prototype.fill === undefined");
if (IsAzureEnabled()) {
ok(window.CanvasRenderingContext2D.prototype.fill === undefined, "window.CanvasRenderingContext2D.prototype.fill === undefined");
} else {
todo(window.CanvasRenderingContext2D.prototype.fill === undefined, "window.CanvasRenderingContext2D.prototype.fill === undefined");
}
//restore the original method to ensure that other tests can run successfully
window.CanvasRenderingContext2D.prototype.fill = fill;

Просмотреть файл

@ -768,12 +768,8 @@ nsresult
NS_NewCanvasRenderingContext2D(nsIDOMCanvasRenderingContext2D** aResult)
{
Telemetry::Accumulate(Telemetry::CANVAS_2D_USED, 1);
if (Preferences::GetBool("gfx.canvas.azure.enabled", false)) {
nsresult rv = NS_NewCanvasRenderingContext2DAzure(aResult);
// If Azure fails, fall back to a classic canvas.
if (NS_SUCCEEDED(rv)) {
return rv;
}
if (AzureCanvasEnabled()) {
return NS_NewCanvasRenderingContext2DAzure(aResult);
}
return NS_NewCanvasRenderingContext2DThebes(aResult);

Просмотреть файл

@ -534,6 +534,7 @@ using mozilla::dom::indexedDB::IDBWrapperCache;
#undef None // something included above defines this preprocessor symbol, maybe Xlib headers
#include "WebGLContext.h"
#include "nsICanvasRenderingContextInternal.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -4590,6 +4591,10 @@ nsDOMClassInfo::Init()
// Non-proxy bindings
mozilla::dom::Register(nameSpaceManager);
if (!AzureCanvasEnabled()) {
nameSpaceManager->RegisterDefineDOMInterface(NS_LITERAL_STRING("CanvasRenderingContext2D"), NULL);
}
sIsInitialized = true;
return NS_OK;