2009-09-02 17:47:49 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
#include "WebGLContext.h"
|
2013-07-16 07:32:24 -07:00
|
|
|
#include "WebGL1Context.h"
|
2012-11-20 13:38:20 -08:00
|
|
|
#include "WebGLObjectModel.h"
|
2011-09-30 21:45:50 -07:00
|
|
|
#include "WebGLExtensions.h"
|
2012-10-04 13:35:54 -07:00
|
|
|
#include "WebGLContextUtils.h"
|
2013-06-10 13:00:35 -07:00
|
|
|
#include "WebGLBuffer.h"
|
|
|
|
#include "WebGLVertexAttribData.h"
|
2013-11-25 16:03:38 -08:00
|
|
|
#include "WebGLMemoryTracker.h"
|
2013-06-10 13:00:35 -07:00
|
|
|
#include "WebGLFramebuffer.h"
|
2013-06-27 14:07:21 -07:00
|
|
|
#include "WebGLVertexArray.h"
|
2013-08-06 14:23:46 -07:00
|
|
|
#include "WebGLQuery.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-10-17 12:11:51 -07:00
|
|
|
#include "AccessCheck.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsIClassInfoImpl.h"
|
|
|
|
#include "nsContentUtils.h"
|
2009-11-01 16:33:39 -08:00
|
|
|
#include "nsIXPConnect.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2010-09-16 09:45:23 -07:00
|
|
|
#include "nsIGfxInfo.h"
|
2013-05-27 07:12:13 -07:00
|
|
|
#include "nsIWidget.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-11-16 20:33:03 -08:00
|
|
|
#include "nsIVariant.h"
|
|
|
|
|
2013-10-16 19:55:08 -07:00
|
|
|
#include "ImageEncoder.h"
|
2010-11-16 20:33:03 -08:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxPattern.h"
|
2010-07-01 09:43:33 -07:00
|
|
|
#include "gfxUtils.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2009-11-01 16:33:39 -08:00
|
|
|
#include "CanvasUtils.h"
|
2011-03-27 16:59:47 -07:00
|
|
|
#include "nsDisplayList.h"
|
2009-11-01 16:33:39 -08:00
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
#include "GLContextProvider.h"
|
2013-09-04 05:14:52 -07:00
|
|
|
#include "GLContext.h"
|
2013-11-25 19:25:25 -08:00
|
|
|
#include "ScopedGLHelpers.h"
|
2014-01-02 07:17:29 -08:00
|
|
|
#include "GLReadTexImageHelper.h"
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2011-03-02 12:50:36 -08:00
|
|
|
#include "gfxCrashReporterUtils.h"
|
|
|
|
|
2010-08-13 06:36:13 -07:00
|
|
|
#include "nsSVGEffects.h"
|
|
|
|
|
2010-08-06 22:09:18 -07:00
|
|
|
#include "prenv.h"
|
|
|
|
|
2011-07-06 19:00:02 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-06-06 00:40:02 -07:00
|
|
|
#include "mozilla/Services.h"
|
2011-09-19 13:08:56 -07:00
|
|
|
#include "mozilla/Telemetry.h"
|
2011-07-06 19:00:02 -07:00
|
|
|
|
2012-04-21 13:48:22 -07:00
|
|
|
#include "nsIObserverService.h"
|
2012-07-01 16:45:59 -07:00
|
|
|
#include "mozilla/Services.h"
|
2012-05-31 11:16:48 -07:00
|
|
|
#include "mozilla/dom/WebGLRenderingContextBinding.h"
|
2012-10-03 14:13:05 -07:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2013-08-22 22:17:11 -07:00
|
|
|
#include "mozilla/dom/ImageData.h"
|
2013-04-25 17:53:26 -07:00
|
|
|
#include "mozilla/ProcessPriorityManager.h"
|
2014-04-25 19:34:07 -07:00
|
|
|
#include "mozilla/EnumeratedArrayCycleCollection.h"
|
2012-04-21 13:48:22 -07:00
|
|
|
|
2012-08-20 21:06:46 -07:00
|
|
|
#include "Layers.h"
|
|
|
|
|
2013-05-27 07:12:13 -07:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
#include "mozilla/layers/ShadowLayers.h"
|
|
|
|
#endif
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
using namespace mozilla;
|
2012-10-03 14:13:05 -07:00
|
|
|
using namespace mozilla::dom;
|
2013-02-13 15:26:24 -08:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using namespace mozilla::gl;
|
2010-09-02 02:18:40 -07:00
|
|
|
using namespace mozilla::layers;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-04-21 13:48:22 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLMemoryPressureObserver::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* aSomeData)
|
2012-04-21 13:48:22 -07:00
|
|
|
{
|
2012-12-07 18:00:42 -08:00
|
|
|
if (strcmp(aTopic, "memory-pressure"))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
bool wantToLoseContext = true;
|
|
|
|
|
2013-04-25 17:53:26 -07:00
|
|
|
if (!mContext->mCanLoseContextInForeground &&
|
|
|
|
ProcessPriorityManager::CurrentProcessIsForeground())
|
2013-01-03 15:39:25 -08:00
|
|
|
wantToLoseContext = false;
|
2014-05-12 19:11:08 -07:00
|
|
|
else if (!nsCRT::strcmp(aSomeData,
|
|
|
|
MOZ_UTF16("heap-minimize")))
|
2012-12-07 18:00:42 -08:00
|
|
|
wantToLoseContext = mContext->mLoseContextOnHeapMinimize;
|
|
|
|
|
2014-05-12 19:11:08 -07:00
|
|
|
if (wantToLoseContext)
|
2012-12-07 18:00:42 -08:00
|
|
|
mContext->ForceLoseContext();
|
|
|
|
|
|
|
|
return NS_OK;
|
2012-04-21 13:48:22 -07:00
|
|
|
}
|
|
|
|
|
2014-05-12 19:11:08 -07:00
|
|
|
|
2012-08-01 11:58:44 -07:00
|
|
|
WebGLContextOptions::WebGLContextOptions()
|
2012-08-01 15:13:49 -07:00
|
|
|
: alpha(true), depth(true), stencil(false),
|
2012-08-01 11:58:44 -07:00
|
|
|
premultipliedAlpha(true), antialias(true),
|
|
|
|
preserveDrawingBuffer(false)
|
|
|
|
{
|
|
|
|
// Set default alpha state based on preference.
|
2012-08-01 15:13:49 -07:00
|
|
|
if (Preferences::GetBool("webgl.default-no-alpha", false))
|
2012-08-01 15:40:24 -07:00
|
|
|
alpha = false;
|
2012-08-01 11:58:44 -07:00
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
WebGLContext::WebGLContext()
|
2012-07-30 07:20:58 -07:00
|
|
|
: gl(nullptr)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-05-31 11:16:48 -07:00
|
|
|
SetIsDOMBinding();
|
2012-03-26 11:59:04 -07:00
|
|
|
|
2010-07-14 20:52:34 -07:00
|
|
|
mGeneration = 0;
|
2011-10-17 07:59:28 -07:00
|
|
|
mInvalidated = false;
|
2013-02-13 15:26:24 -08:00
|
|
|
mShouldPresent = true;
|
2011-10-17 07:59:28 -07:00
|
|
|
mResetLayer = true;
|
|
|
|
mOptionsFrozen = false;
|
2010-07-14 20:52:34 -07:00
|
|
|
|
|
|
|
mActiveTexture = 0;
|
2011-10-17 07:59:28 -07:00
|
|
|
mPixelStoreFlipY = false;
|
|
|
|
mPixelStorePremultiplyAlpha = false;
|
2010-12-06 03:34:35 -08:00
|
|
|
mPixelStoreColorspaceConversion = BROWSER_DEFAULT_WEBGL;
|
2010-07-14 20:52:34 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mShaderValidation = true;
|
2010-07-14 20:52:34 -07:00
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
mFakeBlackStatus = WebGLContextFakeBlackStatus::NotNeeded;
|
2010-09-02 07:34:08 -07:00
|
|
|
|
|
|
|
mVertexAttrib0Vector[0] = 0;
|
|
|
|
mVertexAttrib0Vector[1] = 0;
|
|
|
|
mVertexAttrib0Vector[2] = 0;
|
|
|
|
mVertexAttrib0Vector[3] = 1;
|
2011-02-24 14:17:34 -08:00
|
|
|
mFakeVertexAttrib0BufferObjectVector[0] = 0;
|
|
|
|
mFakeVertexAttrib0BufferObjectVector[1] = 0;
|
|
|
|
mFakeVertexAttrib0BufferObjectVector[2] = 0;
|
|
|
|
mFakeVertexAttrib0BufferObjectVector[3] = 1;
|
|
|
|
mFakeVertexAttrib0BufferObjectSize = 0;
|
|
|
|
mFakeVertexAttrib0BufferObject = 0;
|
2013-10-11 06:16:43 -07:00
|
|
|
mFakeVertexAttrib0BufferStatus = WebGLVertexAttrib0Status::Default;
|
2011-05-20 12:53:53 -07:00
|
|
|
|
2014-01-10 05:41:04 -08:00
|
|
|
mViewportX = 0;
|
|
|
|
mViewportY = 0;
|
|
|
|
mViewportWidth = 0;
|
|
|
|
mViewportHeight = 0;
|
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
mScissorTestEnabled = 0;
|
|
|
|
mDitherEnabled = 1;
|
2013-08-22 17:11:40 -07:00
|
|
|
mRasterizerDiscardEnabled = 0; // OpenGL ES 3.0 spec p244
|
2013-05-22 00:05:38 -07:00
|
|
|
|
2011-06-27 10:27:04 -07:00
|
|
|
// initialize some GL values: we're going to get them from the GL and use them as the sizes of arrays,
|
|
|
|
// so in case glGetIntegerv leaves them uninitialized because of a GL bug, we would have very weird crashes.
|
|
|
|
mGLMaxVertexAttribs = 0;
|
|
|
|
mGLMaxTextureUnits = 0;
|
|
|
|
mGLMaxTextureSize = 0;
|
|
|
|
mGLMaxCubeMapTextureSize = 0;
|
2012-12-11 13:57:30 -08:00
|
|
|
mGLMaxRenderbufferSize = 0;
|
2011-06-27 10:27:04 -07:00
|
|
|
mGLMaxTextureImageUnits = 0;
|
|
|
|
mGLMaxVertexTextureImageUnits = 0;
|
|
|
|
mGLMaxVaryingVectors = 0;
|
|
|
|
mGLMaxFragmentUniformVectors = 0;
|
|
|
|
mGLMaxVertexUniformVectors = 0;
|
2013-06-21 16:44:17 -07:00
|
|
|
mGLMaxColorAttachments = 1;
|
|
|
|
mGLMaxDrawBuffers = 1;
|
2013-08-20 08:36:20 -07:00
|
|
|
mGLMaxTransformFeedbackSeparateAttribs = 0;
|
2012-08-02 14:28:02 -07:00
|
|
|
|
2011-06-27 10:27:04 -07:00
|
|
|
// See OpenGL ES 2.0.25 spec, 6.2 State Tables, table 6.13
|
|
|
|
mPixelStorePackAlignment = 4;
|
|
|
|
mPixelStoreUnpackAlignment = 4;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2013-11-25 16:03:38 -08:00
|
|
|
WebGLMemoryTracker::AddWebGLContext(this);
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2014-05-12 19:11:08 -07:00
|
|
|
mAllowRestore = true;
|
2012-04-21 13:48:22 -07:00
|
|
|
mContextLossTimerRunning = false;
|
2014-05-12 19:11:08 -07:00
|
|
|
mDrawSinceContextLossTimerSet = false;
|
2011-11-18 19:57:29 -08:00
|
|
|
mContextRestorer = do_CreateInstance("@mozilla.org/timer;1");
|
2013-09-04 05:14:44 -07:00
|
|
|
mContextStatus = ContextNotLost;
|
2014-05-12 19:11:08 -07:00
|
|
|
mContextLostErrorSet = false;
|
2012-12-07 18:00:42 -08:00
|
|
|
mLoseContextOnHeapMinimize = false;
|
2013-01-03 15:39:25 -08:00
|
|
|
mCanLoseContextInForeground = true;
|
2012-05-23 09:07:10 -07:00
|
|
|
|
2012-05-29 11:44:31 -07:00
|
|
|
mAlreadyGeneratedWarnings = 0;
|
2012-07-25 09:13:45 -07:00
|
|
|
mAlreadyWarnedAboutFakeVertexAttrib0 = false;
|
2014-01-10 05:41:04 -08:00
|
|
|
mAlreadyWarnedAboutViewportLargerThanDest = false;
|
2013-06-04 12:44:08 -07:00
|
|
|
mMaxWarnings = Preferences::GetInt("webgl.max-warnings-per-context", 32);
|
|
|
|
if (mMaxWarnings < -1)
|
|
|
|
{
|
|
|
|
GenerateWarning("webgl.max-warnings-per-context size is too large (seems like a negative value wrapped)");
|
|
|
|
mMaxWarnings = 0;
|
|
|
|
}
|
2012-08-02 14:28:02 -07:00
|
|
|
|
|
|
|
mLastUseIndex = 0;
|
2012-11-19 07:49:51 -08:00
|
|
|
|
2013-08-13 15:11:01 -07:00
|
|
|
InvalidateBufferFetching();
|
2013-02-13 15:26:24 -08:00
|
|
|
|
2014-04-17 13:15:41 -07:00
|
|
|
mBackbufferNeedsClear = true;
|
2013-05-15 14:50:52 -07:00
|
|
|
|
|
|
|
mDisableFragHighP = false;
|
2013-05-22 00:05:38 -07:00
|
|
|
|
|
|
|
mDrawCallsSinceLastFlush = 0;
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
WebGLContext::~WebGLContext()
|
|
|
|
{
|
2010-07-18 22:01:14 -07:00
|
|
|
DestroyResourcesAndContext();
|
2013-11-25 16:03:38 -08:00
|
|
|
WebGLMemoryTracker::RemoveWebGLContext(this);
|
2012-04-21 13:48:22 -07:00
|
|
|
TerminateContextLossTimer();
|
2012-07-30 07:20:58 -07:00
|
|
|
mContextRestorer = nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::DestroyResourcesAndContext()
|
|
|
|
{
|
2012-04-21 13:48:22 -07:00
|
|
|
if (mMemoryPressureObserver) {
|
|
|
|
nsCOMPtr<nsIObserverService> observerService
|
|
|
|
= mozilla::services::GetObserverService();
|
|
|
|
if (observerService) {
|
|
|
|
observerService->RemoveObserver(mMemoryPressureObserver,
|
|
|
|
"memory-pressure");
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
mMemoryPressureObserver = nullptr;
|
2012-04-21 13:48:22 -07:00
|
|
|
}
|
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gl->MakeCurrent();
|
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
mBound2DTextures.Clear();
|
|
|
|
mBoundCubeMapTextures.Clear();
|
2012-07-30 07:20:58 -07:00
|
|
|
mBoundArrayBuffer = nullptr;
|
2013-08-20 08:36:20 -07:00
|
|
|
mBoundTransformFeedbackBuffer = nullptr;
|
2012-07-30 07:20:58 -07:00
|
|
|
mCurrentProgram = nullptr;
|
|
|
|
mBoundFramebuffer = nullptr;
|
2013-08-06 14:23:46 -07:00
|
|
|
mActiveOcclusionQuery = nullptr;
|
2012-07-30 07:20:58 -07:00
|
|
|
mBoundRenderbuffer = nullptr;
|
2013-06-27 14:07:21 -07:00
|
|
|
mBoundVertexArray = nullptr;
|
|
|
|
mDefaultVertexArray = nullptr;
|
2011-12-04 11:15:42 -08:00
|
|
|
|
2012-05-29 11:44:31 -07:00
|
|
|
while (!mTextures.isEmpty())
|
|
|
|
mTextures.getLast()->DeleteOnce();
|
2013-06-27 14:07:21 -07:00
|
|
|
while (!mVertexArrays.isEmpty())
|
|
|
|
mVertexArrays.getLast()->DeleteOnce();
|
2012-05-29 11:44:31 -07:00
|
|
|
while (!mBuffers.isEmpty())
|
|
|
|
mBuffers.getLast()->DeleteOnce();
|
|
|
|
while (!mRenderbuffers.isEmpty())
|
|
|
|
mRenderbuffers.getLast()->DeleteOnce();
|
|
|
|
while (!mFramebuffers.isEmpty())
|
|
|
|
mFramebuffers.getLast()->DeleteOnce();
|
|
|
|
while (!mShaders.isEmpty())
|
|
|
|
mShaders.getLast()->DeleteOnce();
|
|
|
|
while (!mPrograms.isEmpty())
|
|
|
|
mPrograms.getLast()->DeleteOnce();
|
2013-08-06 14:23:46 -07:00
|
|
|
while (!mQueries.isEmpty())
|
|
|
|
mQueries.getLast()->DeleteOnce();
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
mBlackOpaqueTexture2D = nullptr;
|
|
|
|
mBlackOpaqueTextureCubeMap = nullptr;
|
|
|
|
mBlackTransparentTexture2D = nullptr;
|
|
|
|
mBlackTransparentTextureCubeMap = nullptr;
|
2010-08-23 14:03:53 -07:00
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
if (mFakeVertexAttrib0BufferObject) {
|
|
|
|
gl->fDeleteBuffers(1, &mFakeVertexAttrib0BufferObject);
|
|
|
|
}
|
|
|
|
|
2013-11-05 01:35:50 -08:00
|
|
|
// disable all extensions except "WEBGL_lose_context". see bug #927969
|
|
|
|
// spec: http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
|
2014-04-25 19:34:07 -07:00
|
|
|
for (size_t i = 0; i < size_t(WebGLExtensionID::Max); ++i) {
|
2013-11-05 01:35:50 -08:00
|
|
|
WebGLExtensionID extension = WebGLExtensionID(i);
|
|
|
|
|
2014-04-25 19:34:07 -07:00
|
|
|
if (!IsExtensionEnabled(extension) || (extension == WebGLExtensionID::WEBGL_lose_context))
|
2013-11-05 01:35:50 -08:00
|
|
|
continue;
|
|
|
|
|
2014-03-11 19:51:39 -07:00
|
|
|
mExtensions[extension]->MarkLost();
|
2013-11-05 01:35:50 -08:00
|
|
|
mExtensions[extension] = nullptr;
|
|
|
|
}
|
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
// We just got rid of everything, so the context had better
|
|
|
|
// have been going away.
|
2010-09-13 08:40:01 -07:00
|
|
|
#ifdef DEBUG
|
2012-06-11 08:25:06 -07:00
|
|
|
if (gl->DebugMode()) {
|
|
|
|
printf_stderr("--- WebGL context destroyed: %p\n", gl.get());
|
|
|
|
}
|
2010-09-13 08:40:01 -07:00
|
|
|
#endif
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
gl = nullptr;
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::Invalidate()
|
|
|
|
{
|
2011-03-27 16:59:47 -07:00
|
|
|
if (mInvalidated)
|
|
|
|
return;
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
if (!mCanvasElement)
|
|
|
|
return;
|
|
|
|
|
2012-06-06 00:42:47 -07:00
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(mCanvasElement);
|
2010-08-13 06:36:13 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mInvalidated = true;
|
2012-07-30 07:20:58 -07:00
|
|
|
mCanvasElement->InvalidateCanvasContent(nullptr);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsICanvasRenderingContextInternal
|
|
|
|
//
|
|
|
|
|
2010-11-16 20:33:03 -08:00
|
|
|
NS_IMETHODIMP
|
2013-06-07 11:42:12 -07:00
|
|
|
WebGLContext::SetContextOptions(JSContext* aCx, JS::Handle<JS::Value> aOptions)
|
2010-11-16 20:33:03 -08:00
|
|
|
{
|
2013-06-12 11:42:27 -07:00
|
|
|
if (aOptions.isNullOrUndefined() && mOptionsFrozen) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-06-12 13:04:18 -07:00
|
|
|
|
2013-06-07 11:42:12 -07:00
|
|
|
WebGLContextAttributes attributes;
|
2013-06-12 13:04:18 -07:00
|
|
|
NS_ENSURE_TRUE(attributes.Init(aCx, aOptions), NS_ERROR_UNEXPECTED);
|
2010-11-16 20:33:03 -08:00
|
|
|
|
|
|
|
WebGLContextOptions newOpts;
|
|
|
|
|
2013-06-07 11:42:12 -07:00
|
|
|
newOpts.stencil = attributes.mStencil;
|
|
|
|
newOpts.depth = attributes.mDepth;
|
|
|
|
newOpts.premultipliedAlpha = attributes.mPremultipliedAlpha;
|
|
|
|
newOpts.antialias = attributes.mAntialias;
|
|
|
|
newOpts.preserveDrawingBuffer = attributes.mPreserveDrawingBuffer;
|
|
|
|
if (attributes.mAlpha.WasPassed()) {
|
|
|
|
newOpts.alpha = attributes.mAlpha.Value();
|
|
|
|
}
|
2012-07-06 06:19:27 -07:00
|
|
|
|
2010-11-16 20:33:03 -08:00
|
|
|
// enforce that if stencil is specified, we also give back depth
|
|
|
|
newOpts.depth |= newOpts.stencil;
|
|
|
|
|
2010-12-03 14:44:01 -08:00
|
|
|
#if 0
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning("aaHint: %d stencil: %d depth: %d alpha: %d premult: %d preserve: %d\n",
|
2011-05-20 12:53:53 -07:00
|
|
|
newOpts.antialias ? 1 : 0,
|
2010-11-16 20:33:03 -08:00
|
|
|
newOpts.stencil ? 1 : 0,
|
|
|
|
newOpts.depth ? 1 : 0,
|
|
|
|
newOpts.alpha ? 1 : 0,
|
2011-05-20 12:53:53 -07:00
|
|
|
newOpts.premultipliedAlpha ? 1 : 0,
|
|
|
|
newOpts.preserveDrawingBuffer ? 1 : 0);
|
2010-12-03 14:44:01 -08:00
|
|
|
#endif
|
2010-11-16 20:33:03 -08:00
|
|
|
|
|
|
|
if (mOptionsFrozen && newOpts != mOptions) {
|
|
|
|
// Error if the options are already frozen, and the ones that were asked for
|
|
|
|
// aren't the same as what they were originally.
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mOptions = newOpts;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-30 14:02:40 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
int32_t
|
|
|
|
WebGLContext::GetWidth() const
|
|
|
|
{
|
|
|
|
return mWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
WebGLContext::GetHeight() const
|
|
|
|
{
|
|
|
|
return mHeight;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
WebGLContext::SetDimensions(int32_t width, int32_t height)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-09-27 07:13:45 -07:00
|
|
|
// Early error return cases
|
|
|
|
|
|
|
|
if (width < 0 || height < 0) {
|
|
|
|
GenerateWarning("Canvas size is too large (seems like a negative value wrapped)");
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2012-08-02 14:28:02 -07:00
|
|
|
|
2012-09-27 07:13:44 -07:00
|
|
|
if (!GetCanvas())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-09-27 07:13:45 -07:00
|
|
|
// Early success return cases
|
|
|
|
|
2012-09-27 07:13:44 -07:00
|
|
|
GetCanvas()->InvalidateCanvas();
|
2011-03-27 16:59:47 -07:00
|
|
|
|
2011-05-06 11:44:26 -07:00
|
|
|
if (gl && mWidth == width && mHeight == height)
|
2009-09-02 17:47:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2011-05-19 03:49:18 -07:00
|
|
|
// Zero-sized surfaces can cause problems.
|
2013-10-09 14:22:11 -07:00
|
|
|
if (width == 0) {
|
2011-05-19 03:49:18 -07:00
|
|
|
width = 1;
|
2013-10-09 14:22:11 -07:00
|
|
|
}
|
|
|
|
if (height == 0) {
|
2011-05-19 03:49:18 -07:00
|
|
|
height = 1;
|
|
|
|
}
|
|
|
|
|
2011-10-19 12:09:57 -07:00
|
|
|
// If we already have a gl context, then we just need to resize it
|
|
|
|
if (gl) {
|
2011-12-19 15:47:54 -08:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2013-10-31 06:52:24 -07:00
|
|
|
// If we've already drawn, we should commit the current buffer.
|
|
|
|
PresentScreenBuffer();
|
|
|
|
|
|
|
|
// ResizeOffscreen scraps the current prod buffer before making a new one.
|
2014-01-01 11:47:19 -08:00
|
|
|
gl->ResizeOffscreen(gfx::IntSize(width, height)); // Doesn't matter if it succeeds (soft-fail)
|
2011-10-19 12:09:57 -07:00
|
|
|
// It's unlikely that we'll get a proper-sized context if we recreate if we didn't on resize
|
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
// everything's good, we're done here
|
2013-02-13 15:26:24 -08:00
|
|
|
mWidth = gl->OffscreenSize().width;
|
|
|
|
mHeight = gl->OffscreenSize().height;
|
2011-10-17 07:59:28 -07:00
|
|
|
mResetLayer = true;
|
2011-12-19 15:47:54 -08:00
|
|
|
|
2014-04-17 13:15:41 -07:00
|
|
|
mBackbufferNeedsClear = true;
|
2011-12-19 15:47:54 -08:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-06-09 15:07:12 -07:00
|
|
|
|
2012-09-27 07:13:45 -07:00
|
|
|
// End of early return cases.
|
|
|
|
// At this point we know that we're not just resizing an existing context,
|
|
|
|
// we are initializing a new context.
|
2011-06-10 12:02:06 -07:00
|
|
|
|
2012-08-02 14:28:02 -07:00
|
|
|
// if we exceeded either the global or the per-principal limit for WebGL contexts,
|
|
|
|
// lose the oldest-used context now to free resources. Note that we can't do that
|
|
|
|
// in the WebGLContext constructor as we don't have a canvas element yet there.
|
|
|
|
// Here is the right place to do so, as we are about to create the OpenGL context
|
|
|
|
// and that is what can fail if we already have too many.
|
|
|
|
LoseOldestWebGLContextIfLimitExceeded();
|
2011-06-10 12:02:06 -07:00
|
|
|
|
|
|
|
// Get some prefs for some preferred/overriden things
|
2011-07-06 19:00:02 -07:00
|
|
|
NS_ENSURE_TRUE(Preferences::GetRootBranch(), NS_ERROR_FAILURE);
|
|
|
|
|
2012-01-16 14:07:18 -08:00
|
|
|
#ifdef XP_WIN
|
2011-09-28 23:19:26 -07:00
|
|
|
bool preferEGL =
|
|
|
|
Preferences::GetBool("webgl.prefer-egl", false);
|
|
|
|
bool preferOpenGL =
|
|
|
|
Preferences::GetBool("webgl.prefer-native-gl", false);
|
2011-12-17 22:00:42 -08:00
|
|
|
#endif
|
2011-09-28 23:19:26 -07:00
|
|
|
bool forceEnabled =
|
|
|
|
Preferences::GetBool("webgl.force-enabled", false);
|
|
|
|
bool disabled =
|
|
|
|
Preferences::GetBool("webgl.disabled", false);
|
2012-07-06 06:19:27 -07:00
|
|
|
bool prefer16bit =
|
|
|
|
Preferences::GetBool("webgl.prefer-16bpp", false);
|
2011-06-10 12:02:06 -07:00
|
|
|
|
2012-02-27 13:33:19 -08:00
|
|
|
ScopedGfxFeatureReporter reporter("WebGL", forceEnabled);
|
|
|
|
|
2011-06-10 12:02:06 -07:00
|
|
|
if (disabled)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
// We're going to create an entirely new context. If our
|
|
|
|
// generation is not 0 right now (that is, if this isn't the first
|
|
|
|
// context we're creating), we may have to dispatch a context lost
|
|
|
|
// event.
|
2010-06-09 15:07:12 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
// If incrementing the generation would cause overflow,
|
|
|
|
// don't allow it. Allowing this would allow us to use
|
|
|
|
// resource handles created from older context generations.
|
2012-05-14 12:50:20 -07:00
|
|
|
if (!(mGeneration + 1).isValid())
|
2010-07-18 22:01:14 -07:00
|
|
|
return NS_ERROR_FAILURE; // exit without changing the value of mGeneration
|
2010-06-09 15:07:12 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
SurfaceCaps caps;
|
2010-11-16 20:33:03 -08:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
caps.color = true;
|
|
|
|
caps.alpha = mOptions.alpha;
|
|
|
|
caps.depth = mOptions.depth;
|
|
|
|
caps.stencil = mOptions.stencil;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-07-06 06:19:27 -07:00
|
|
|
// we should really have this behind a
|
|
|
|
// |gfxPlatform::GetPlatform()->GetScreenDepth() == 16| check, but
|
|
|
|
// for now it's just behind a pref for testing/evaluation.
|
2013-02-13 15:26:24 -08:00
|
|
|
caps.bpp16 = prefer16bit;
|
|
|
|
|
|
|
|
caps.preserve = mOptions.preserveDrawingBuffer;
|
2012-07-06 06:19:27 -07:00
|
|
|
|
2013-05-27 07:12:13 -07:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
nsIWidget *docWidget = nsContentUtils::WidgetForDocument(mCanvasElement->OwnerDoc());
|
|
|
|
if (docWidget) {
|
|
|
|
layers::LayerManager *layerManager = docWidget->GetLayerManager();
|
|
|
|
if (layerManager) {
|
|
|
|
// XXX we really want "AsSurfaceAllocator" here for generality
|
|
|
|
layers::ShadowLayerForwarder *forwarder = layerManager->AsShadowForwarder();
|
|
|
|
if (forwarder) {
|
|
|
|
caps.surfaceAllocator = static_cast<layers::ISurfaceAllocator*>(forwarder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-11-03 07:50:40 -07:00
|
|
|
bool forceMSAA =
|
|
|
|
Preferences::GetBool("webgl.msaa-force", false);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t status;
|
2011-11-03 07:50:40 -07:00
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
|
2011-11-22 11:51:51 -08:00
|
|
|
if (mOptions.antialias &&
|
|
|
|
gfxInfo &&
|
2011-11-03 07:50:40 -07:00
|
|
|
NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_WEBGL_MSAA, &status))) {
|
2011-11-03 07:50:40 -07:00
|
|
|
if (status == nsIGfxInfo::FEATURE_NO_INFO || forceMSAA) {
|
2013-02-13 15:26:24 -08:00
|
|
|
caps.antialias = true;
|
2011-11-03 07:50:40 -07:00
|
|
|
}
|
2011-10-19 12:09:57 -07:00
|
|
|
}
|
|
|
|
|
2012-01-16 14:07:18 -08:00
|
|
|
#ifdef XP_WIN
|
2010-12-03 14:44:01 -08:00
|
|
|
if (PR_GetEnv("MOZ_WEBGL_PREFER_EGL")) {
|
2011-10-17 07:59:28 -07:00
|
|
|
preferEGL = true;
|
2010-12-03 14:44:01 -08:00
|
|
|
}
|
2012-01-16 14:07:18 -08:00
|
|
|
#endif
|
2010-08-25 05:14:12 -07:00
|
|
|
|
2010-09-13 08:53:52 -07:00
|
|
|
// Ask GfxInfo about what we should use
|
2011-09-28 23:19:26 -07:00
|
|
|
bool useOpenGL = true;
|
2012-01-16 14:07:18 -08:00
|
|
|
|
|
|
|
#ifdef XP_WIN
|
2011-09-28 23:19:26 -07:00
|
|
|
bool useANGLE = true;
|
2012-01-16 14:07:18 -08:00
|
|
|
#endif
|
2010-09-16 09:45:23 -07:00
|
|
|
|
2011-01-28 18:12:24 -08:00
|
|
|
if (gfxInfo && !forceEnabled) {
|
2010-09-20 10:20:45 -07:00
|
|
|
if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_WEBGL_OPENGL, &status))) {
|
2011-01-25 19:21:45 -08:00
|
|
|
if (status != nsIGfxInfo::FEATURE_NO_INFO) {
|
2011-10-17 07:59:28 -07:00
|
|
|
useOpenGL = false;
|
2010-09-20 10:20:45 -07:00
|
|
|
}
|
|
|
|
}
|
2012-01-16 14:07:18 -08:00
|
|
|
#ifdef XP_WIN
|
2010-09-20 10:20:45 -07:00
|
|
|
if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_WEBGL_ANGLE, &status))) {
|
2011-01-25 19:21:45 -08:00
|
|
|
if (status != nsIGfxInfo::FEATURE_NO_INFO) {
|
2011-10-17 07:59:28 -07:00
|
|
|
useANGLE = false;
|
2010-09-20 10:20:45 -07:00
|
|
|
}
|
|
|
|
}
|
2012-01-16 14:07:18 -08:00
|
|
|
#endif
|
2010-09-16 09:45:23 -07:00
|
|
|
}
|
|
|
|
|
2012-01-16 14:07:18 -08:00
|
|
|
#ifdef XP_WIN
|
2010-12-03 14:44:01 -08:00
|
|
|
// allow forcing GL and not EGL/ANGLE
|
2014-01-10 10:55:23 -08:00
|
|
|
if (PR_GetEnv("MOZ_WEBGL_FORCE_OPENGL")) {
|
2011-10-17 07:59:28 -07:00
|
|
|
preferEGL = false;
|
|
|
|
useANGLE = false;
|
|
|
|
useOpenGL = true;
|
2010-12-03 14:44:01 -08:00
|
|
|
}
|
2012-01-16 14:07:18 -08:00
|
|
|
#endif
|
2010-12-03 14:44:01 -08:00
|
|
|
|
2013-03-06 21:26:15 -08:00
|
|
|
gfxIntSize size(width, height);
|
|
|
|
|
2010-09-13 08:53:52 -07:00
|
|
|
#ifdef XP_WIN
|
2010-12-03 14:44:01 -08:00
|
|
|
// if we want EGL, try it now
|
|
|
|
if (!gl && (preferEGL || useANGLE) && !preferOpenGL) {
|
2013-03-06 21:26:15 -08:00
|
|
|
gl = gl::GLContextProviderEGL::CreateOffscreen(size, caps);
|
2012-03-26 12:20:35 -07:00
|
|
|
if (!gl || !InitAndValidateGL()) {
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning("Error during ANGLE OpenGL ES initialization");
|
2012-02-24 15:10:18 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-08-06 22:09:18 -07:00
|
|
|
}
|
2010-09-13 08:53:52 -07:00
|
|
|
}
|
2012-01-16 14:07:18 -08:00
|
|
|
#endif
|
2010-09-13 08:53:52 -07:00
|
|
|
|
2012-01-16 14:07:18 -08:00
|
|
|
// try the default provider, whatever that is
|
2012-06-06 00:40:02 -07:00
|
|
|
if (!gl && useOpenGL) {
|
2014-01-10 10:55:23 -08:00
|
|
|
gl = gl::GLContextProvider::CreateOffscreen(size, caps);
|
2010-09-13 08:53:52 -07:00
|
|
|
if (gl && !InitAndValidateGL()) {
|
2014-01-10 10:55:23 -08:00
|
|
|
GenerateWarning("Error during OpenGL initialization");
|
2012-01-16 14:07:18 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-05-19 13:46:08 -07:00
|
|
|
}
|
2010-08-06 22:09:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gl) {
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning("Can't get a usable WebGL context");
|
2010-08-06 22:09:18 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2010-09-13 08:40:01 -07:00
|
|
|
#ifdef DEBUG
|
2012-06-11 08:25:06 -07:00
|
|
|
if (gl->DebugMode()) {
|
|
|
|
printf_stderr("--- WebGL context created: %p\n", gl.get());
|
|
|
|
}
|
2010-09-13 08:40:01 -07:00
|
|
|
#endif
|
2010-08-06 22:09:18 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
mWidth = width;
|
|
|
|
mHeight = height;
|
2014-01-10 05:41:04 -08:00
|
|
|
mViewportWidth = width;
|
|
|
|
mViewportHeight = height;
|
2011-10-17 07:59:28 -07:00
|
|
|
mResetLayer = true;
|
|
|
|
mOptionsFrozen = true;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2014-05-12 19:11:08 -07:00
|
|
|
mHasRobustness = gl->HasRobustness();
|
|
|
|
|
2010-06-04 12:03:37 -07:00
|
|
|
// increment the generation number
|
2010-07-03 15:32:19 -07:00
|
|
|
++mGeneration;
|
2014-05-12 19:11:08 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
#if 0
|
|
|
|
if (mGeneration > 0) {
|
|
|
|
// XXX dispatch context lost event
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
2010-06-04 12:03:37 -07:00
|
|
|
|
|
|
|
// Make sure that we clear this out, otherwise
|
|
|
|
// we'll end up displaying random memory
|
2013-02-13 15:26:24 -08:00
|
|
|
gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, 0);
|
2011-12-19 15:47:54 -08:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
gl->fClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
2010-07-21 12:34:26 -07:00
|
|
|
gl->fClearDepth(1.0f);
|
2010-07-18 22:01:14 -07:00
|
|
|
gl->fClearStencil(0);
|
2011-12-19 15:47:54 -08:00
|
|
|
|
2014-04-17 13:15:41 -07:00
|
|
|
mBackbufferNeedsClear = true;
|
|
|
|
|
|
|
|
// Clear immediately, because we need to present the cleared initial
|
|
|
|
// buffer.
|
|
|
|
ClearBackbufferIfNeeded();
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
mShouldPresent = true;
|
|
|
|
|
|
|
|
MOZ_ASSERT(gl->Caps().color == caps.color);
|
|
|
|
MOZ_ASSERT(gl->Caps().alpha == caps.alpha);
|
|
|
|
MOZ_ASSERT(gl->Caps().depth == caps.depth || !gl->Caps().depth);
|
|
|
|
MOZ_ASSERT(gl->Caps().stencil == caps.stencil || !gl->Caps().stencil);
|
|
|
|
MOZ_ASSERT(gl->Caps().antialias == caps.antialias || !gl->Caps().antialias);
|
|
|
|
MOZ_ASSERT(gl->Caps().preserve == caps.preserve);
|
|
|
|
|
2011-03-02 12:50:36 -08:00
|
|
|
reporter.SetSuccessful();
|
2009-09-02 17:47:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-17 13:15:41 -07:00
|
|
|
void
|
|
|
|
WebGLContext::ClearBackbufferIfNeeded()
|
|
|
|
{
|
|
|
|
if (!mBackbufferNeedsClear)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
gl->MakeCurrent();
|
|
|
|
|
|
|
|
GLuint fb = 0;
|
|
|
|
gl->GetUIntegerv(LOCAL_GL_FRAMEBUFFER_BINDING, &fb);
|
|
|
|
MOZ_ASSERT(fb == 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ClearScreen();
|
|
|
|
|
|
|
|
mBackbufferNeedsClear = false;
|
|
|
|
}
|
|
|
|
|
2012-08-02 14:28:02 -07:00
|
|
|
void WebGLContext::LoseOldestWebGLContextIfLimitExceeded()
|
|
|
|
{
|
|
|
|
#ifdef MOZ_GFX_OPTIMIZE_MOBILE
|
|
|
|
// some mobile devices can't have more than 8 GL contexts overall
|
|
|
|
const size_t kMaxWebGLContextsPerPrincipal = 2;
|
|
|
|
const size_t kMaxWebGLContexts = 4;
|
|
|
|
#else
|
2012-09-21 10:44:35 -07:00
|
|
|
const size_t kMaxWebGLContextsPerPrincipal = 16;
|
|
|
|
const size_t kMaxWebGLContexts = 32;
|
2012-08-02 14:28:02 -07:00
|
|
|
#endif
|
|
|
|
MOZ_ASSERT(kMaxWebGLContextsPerPrincipal < kMaxWebGLContexts);
|
|
|
|
|
|
|
|
// it's important to update the index on a new context before losing old contexts,
|
|
|
|
// otherwise new unused contexts would all have index 0 and we couldn't distinguish older ones
|
|
|
|
// when choosing which one to lose first.
|
|
|
|
UpdateLastUseIndex();
|
|
|
|
|
2013-11-25 16:03:38 -08:00
|
|
|
WebGLMemoryTracker::ContextsArrayType &contexts
|
|
|
|
= WebGLMemoryTracker::Contexts();
|
2012-08-02 14:28:02 -07:00
|
|
|
|
|
|
|
// quick exit path, should cover a majority of cases
|
|
|
|
if (contexts.Length() <= kMaxWebGLContextsPerPrincipal) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// note that here by "context" we mean "non-lost context". See the check for
|
|
|
|
// IsContextLost() below. Indeed, the point of this function is to maybe lose
|
|
|
|
// some currently non-lost context.
|
|
|
|
|
|
|
|
uint64_t oldestIndex = UINT64_MAX;
|
|
|
|
uint64_t oldestIndexThisPrincipal = UINT64_MAX;
|
2012-08-12 03:43:47 -07:00
|
|
|
const WebGLContext *oldestContext = nullptr;
|
|
|
|
const WebGLContext *oldestContextThisPrincipal = nullptr;
|
2012-08-02 14:28:02 -07:00
|
|
|
size_t numContexts = 0;
|
|
|
|
size_t numContextsThisPrincipal = 0;
|
|
|
|
|
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i) {
|
|
|
|
|
|
|
|
// don't want to lose ourselves.
|
|
|
|
if (contexts[i] == this)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (contexts[i]->IsContextLost())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!contexts[i]->GetCanvas()) {
|
|
|
|
// Zombie context: the canvas is already destroyed, but something else
|
|
|
|
// (typically the compositor) is still holding on to the context.
|
|
|
|
// Killing zombies is a no-brainer.
|
|
|
|
const_cast<WebGLContext*>(contexts[i])->LoseContext();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
numContexts++;
|
|
|
|
if (contexts[i]->mLastUseIndex < oldestIndex) {
|
|
|
|
oldestIndex = contexts[i]->mLastUseIndex;
|
|
|
|
oldestContext = contexts[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPrincipal *ourPrincipal = GetCanvas()->NodePrincipal();
|
|
|
|
nsIPrincipal *theirPrincipal = contexts[i]->GetCanvas()->NodePrincipal();
|
|
|
|
bool samePrincipal;
|
|
|
|
nsresult rv = ourPrincipal->Equals(theirPrincipal, &samePrincipal);
|
|
|
|
if (NS_SUCCEEDED(rv) && samePrincipal) {
|
|
|
|
numContextsThisPrincipal++;
|
|
|
|
if (contexts[i]->mLastUseIndex < oldestIndexThisPrincipal) {
|
|
|
|
oldestIndexThisPrincipal = contexts[i]->mLastUseIndex;
|
|
|
|
oldestContextThisPrincipal = contexts[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numContextsThisPrincipal > kMaxWebGLContextsPerPrincipal) {
|
|
|
|
GenerateWarning("Exceeded %d live WebGL contexts for this principal, losing the "
|
|
|
|
"least recently used one.", kMaxWebGLContextsPerPrincipal);
|
|
|
|
MOZ_ASSERT(oldestContextThisPrincipal); // if we reach this point, this can't be null
|
|
|
|
const_cast<WebGLContext*>(oldestContextThisPrincipal)->LoseContext();
|
|
|
|
} else if (numContexts > kMaxWebGLContexts) {
|
|
|
|
GenerateWarning("Exceeded %d live WebGL contexts, losing the least recently used one.",
|
|
|
|
kMaxWebGLContexts);
|
|
|
|
MOZ_ASSERT(oldestContext); // if we reach this point, this can't be null
|
|
|
|
const_cast<WebGLContext*>(oldestContext)->LoseContext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-16 19:55:08 -07:00
|
|
|
void
|
|
|
|
WebGLContext::GetImageBuffer(uint8_t** aImageBuffer, int32_t* aFormat)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-10-16 19:55:08 -07:00
|
|
|
*aImageBuffer = nullptr;
|
|
|
|
*aFormat = 0;
|
2013-09-09 07:56:00 -07:00
|
|
|
|
2014-04-16 22:31:44 -07:00
|
|
|
// Use GetSurfaceSnapshot() to make sure that appropriate y-flip gets applied
|
|
|
|
bool premult;
|
|
|
|
RefPtr<SourceSurface> snapshot =
|
|
|
|
GetSurfaceSnapshot(mOptions.premultipliedAlpha ? nullptr : &premult);
|
|
|
|
if (!snapshot) {
|
2013-10-16 19:55:08 -07:00
|
|
|
return;
|
|
|
|
}
|
2014-04-16 22:31:44 -07:00
|
|
|
MOZ_ASSERT(mOptions.premultipliedAlpha || !premult, "We must get unpremult when we ask for it!");
|
2013-10-08 12:00:17 -07:00
|
|
|
|
2014-04-16 22:31:44 -07:00
|
|
|
RefPtr<DataSourceSurface> dataSurface = snapshot->GetDataSurface();
|
|
|
|
|
|
|
|
DataSourceSurface::MappedSurface map;
|
|
|
|
if (!dataSurface->Map(DataSourceSurface::MapType::READ, &map)) {
|
2013-10-16 19:55:08 -07:00
|
|
|
return;
|
|
|
|
}
|
2013-09-13 11:14:36 -07:00
|
|
|
|
2014-04-16 22:31:44 -07:00
|
|
|
static const fallible_t fallible = fallible_t();
|
|
|
|
uint8_t* imageBuffer = new (fallible) uint8_t[mWidth * mHeight * 4];
|
|
|
|
if (!imageBuffer) {
|
|
|
|
dataSurface->Unmap();
|
2013-10-16 19:55:08 -07:00
|
|
|
return;
|
|
|
|
}
|
2014-04-16 22:31:44 -07:00
|
|
|
memcpy(imageBuffer, map.mData, mWidth * mHeight * 4);
|
|
|
|
|
|
|
|
dataSurface->Unmap();
|
2013-10-08 12:00:17 -07:00
|
|
|
|
2013-10-16 19:55:08 -07:00
|
|
|
int32_t format = imgIEncoder::INPUT_FORMAT_HOSTARGB;
|
2012-03-23 15:10:50 -07:00
|
|
|
if (!mOptions.premultipliedAlpha) {
|
|
|
|
// We need to convert to INPUT_FORMAT_RGBA, otherwise
|
|
|
|
// we are automatically considered premult, and unpremult'd.
|
|
|
|
// Yes, it is THAT silly.
|
|
|
|
// Except for different lossy conversions by color,
|
|
|
|
// we could probably just change the label, and not change the data.
|
2014-04-16 22:31:44 -07:00
|
|
|
gfxUtils::ConvertBGRAtoRGBA(imageBuffer, mWidth * mHeight * 4);
|
2012-03-23 15:10:50 -07:00
|
|
|
format = imgIEncoder::INPUT_FORMAT_RGBA;
|
|
|
|
}
|
|
|
|
|
2013-10-16 19:55:08 -07:00
|
|
|
*aImageBuffer = imageBuffer;
|
|
|
|
*aFormat = format;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::GetInputStream(const char* aMimeType,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* aEncoderOptions,
|
2013-10-16 19:55:08 -07:00
|
|
|
nsIInputStream **aStream)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(gl, "GetInputStream on invalid context?");
|
|
|
|
if (!gl)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCString enccid("@mozilla.org/image/encoder;2?type=");
|
|
|
|
enccid += aMimeType;
|
|
|
|
nsCOMPtr<imgIEncoder> encoder = do_CreateInstance(enccid.get());
|
|
|
|
if (!encoder) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2013-11-20 16:55:53 -08:00
|
|
|
nsAutoArrayPtr<uint8_t> imageBuffer;
|
|
|
|
int32_t format = 0;
|
|
|
|
GetImageBuffer(getter_Transfers(imageBuffer), &format);
|
|
|
|
if (!imageBuffer) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-10-16 19:55:08 -07:00
|
|
|
return ImageEncoder::GetInputStream(mWidth, mHeight, imageBuffer, format,
|
|
|
|
encoder, aEncoderOptions, aStream);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-08-02 14:28:02 -07:00
|
|
|
void WebGLContext::UpdateLastUseIndex()
|
|
|
|
{
|
|
|
|
static CheckedInt<uint64_t> sIndex = 0;
|
|
|
|
|
|
|
|
sIndex++;
|
|
|
|
|
|
|
|
// should never happen with 64-bit; trying to handle this would be riskier than
|
|
|
|
// not handling it as the handler code would never get exercised.
|
|
|
|
if (!sIndex.isValid()) {
|
|
|
|
NS_RUNTIMEABORT("Can't believe it's been 2^64 transactions already!");
|
|
|
|
}
|
|
|
|
|
|
|
|
mLastUseIndex = sIndex.value();
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint8_t gWebGLLayerUserData;
|
2010-07-15 14:07:46 -07:00
|
|
|
|
2011-10-31 14:14:12 -07:00
|
|
|
namespace mozilla {
|
|
|
|
|
2011-03-27 16:59:47 -07:00
|
|
|
class WebGLContextUserData : public LayerUserData {
|
|
|
|
public:
|
2013-01-03 21:16:14 -08:00
|
|
|
WebGLContextUserData(HTMLCanvasElement *aContent)
|
2013-02-13 15:26:24 -08:00
|
|
|
: mContent(aContent)
|
|
|
|
{}
|
2011-10-31 14:14:12 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
/* PreTransactionCallback gets called by the Layers code every time the
|
|
|
|
* WebGL canvas is going to be composited.
|
|
|
|
*/
|
|
|
|
static void PreTransactionCallback(void* data)
|
|
|
|
{
|
|
|
|
WebGLContextUserData* userdata = static_cast<WebGLContextUserData*>(data);
|
|
|
|
HTMLCanvasElement* canvas = userdata->mContent;
|
|
|
|
WebGLContext* context = static_cast<WebGLContext*>(canvas->GetContextAtIndex(0));
|
|
|
|
|
|
|
|
// Present our screenbuffer, if needed.
|
|
|
|
context->PresentScreenBuffer();
|
2013-05-22 00:05:38 -07:00
|
|
|
context->mDrawCallsSinceLastFlush = 0;
|
2013-02-13 15:26:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** DidTransactionCallback gets called by the Layers code everytime the WebGL canvas gets composite,
|
|
|
|
* so it really is the right place to put actions that have to be performed upon compositing
|
|
|
|
*/
|
|
|
|
static void DidTransactionCallback(void* aData)
|
|
|
|
{
|
|
|
|
WebGLContextUserData *userdata = static_cast<WebGLContextUserData*>(aData);
|
|
|
|
HTMLCanvasElement *canvas = userdata->mContent;
|
|
|
|
WebGLContext *context = static_cast<WebGLContext*>(canvas->GetContextAtIndex(0));
|
2011-10-31 14:14:12 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
// Mark ourselves as no longer invalidated.
|
|
|
|
context->MarkContextClean();
|
2012-08-02 14:28:02 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
context->UpdateLastUseIndex();
|
|
|
|
}
|
2011-03-27 16:59:47 -07:00
|
|
|
|
|
|
|
private:
|
2013-02-13 15:26:24 -08:00
|
|
|
nsRefPtr<HTMLCanvasElement> mContent;
|
2011-03-27 16:59:47 -07:00
|
|
|
};
|
|
|
|
|
2011-10-31 14:14:12 -07:00
|
|
|
} // end namespace mozilla
|
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
already_AddRefed<layers::CanvasLayer>
|
2011-03-27 16:59:47 -07:00
|
|
|
WebGLContext::GetCanvasLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
CanvasLayer *aOldLayer,
|
2010-07-15 14:07:46 -07:00
|
|
|
LayerManager *aManager)
|
2010-05-17 21:04:22 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-07-15 14:07:46 -07:00
|
|
|
if (!mResetLayer && aOldLayer &&
|
2010-09-02 02:18:39 -07:00
|
|
|
aOldLayer->HasUserData(&gWebGLLayerUserData)) {
|
2013-04-22 04:15:59 -07:00
|
|
|
nsRefPtr<layers::CanvasLayer> ret = aOldLayer;
|
|
|
|
return ret.forget();
|
2010-07-15 14:07:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<CanvasLayer> canvasLayer = aManager->CreateCanvasLayer();
|
2010-05-17 21:04:22 -07:00
|
|
|
if (!canvasLayer) {
|
|
|
|
NS_WARNING("CreateCanvasLayer returned null!");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
WebGLContextUserData *userData = nullptr;
|
2011-03-27 16:59:47 -07:00
|
|
|
if (aBuilder->IsPaintingToWindow()) {
|
|
|
|
// Make the layer tell us whenever a transaction finishes (including
|
|
|
|
// the current transaction), so we can clear our invalidation state and
|
|
|
|
// start invalidating again. We need to do this for the layer that is
|
|
|
|
// being painted to a window (there shouldn't be more than one at a time,
|
|
|
|
// and if there is, flushing the invalidation state more often than
|
|
|
|
// necessary is harmless).
|
|
|
|
|
|
|
|
// The layer will be destroyed when we tear down the presentation
|
|
|
|
// (at the latest), at which time this userData will be destroyed,
|
|
|
|
// releasing the reference to the element.
|
|
|
|
// The userData will receive DidTransactionCallbacks, which flush the
|
|
|
|
// the invalidation state to indicate that the canvas is up to date.
|
2012-06-06 00:42:47 -07:00
|
|
|
userData = new WebGLContextUserData(mCanvasElement);
|
2011-03-27 16:59:47 -07:00
|
|
|
canvasLayer->SetDidTransactionCallback(
|
|
|
|
WebGLContextUserData::DidTransactionCallback, userData);
|
2013-02-13 15:26:24 -08:00
|
|
|
canvasLayer->SetPreTransactionCallback(
|
|
|
|
WebGLContextUserData::PreTransactionCallback, userData);
|
2011-03-27 16:59:47 -07:00
|
|
|
}
|
|
|
|
canvasLayer->SetUserData(&gWebGLLayerUserData, userData);
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
CanvasLayer::Data data;
|
2013-02-13 15:26:24 -08:00
|
|
|
data.mGLContext = gl;
|
2010-05-17 21:04:22 -07:00
|
|
|
data.mSize = nsIntSize(mWidth, mHeight);
|
2014-05-14 09:26:13 -07:00
|
|
|
data.mHasAlpha = gl->Caps().alpha;
|
2013-02-13 15:26:24 -08:00
|
|
|
data.mIsGLAlphaPremult = IsPremultAlpha();
|
2010-05-17 21:04:22 -07:00
|
|
|
|
|
|
|
canvasLayer->Initialize(data);
|
2013-02-13 15:26:24 -08:00
|
|
|
uint32_t flags = gl->Caps().alpha ? 0 : Layer::CONTENT_OPAQUE;
|
2010-09-02 02:18:40 -07:00
|
|
|
canvasLayer->SetContentFlags(flags);
|
2011-03-27 16:59:46 -07:00
|
|
|
canvasLayer->Updated();
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mResetLayer = false;
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2013-04-22 04:15:59 -07:00
|
|
|
return canvasLayer.forget();
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-10-22 10:08:52 -07:00
|
|
|
void
|
2013-10-09 09:05:22 -07:00
|
|
|
WebGLContext::GetContextAttributes(Nullable<dom::WebGLContextAttributes> &retval)
|
2010-11-16 20:33:03 -08:00
|
|
|
{
|
2012-11-30 15:30:05 -08:00
|
|
|
retval.SetNull();
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-10-22 10:08:52 -07:00
|
|
|
return;
|
2012-11-30 15:30:05 -08:00
|
|
|
|
|
|
|
dom::WebGLContextAttributes& result = retval.SetValue();
|
2010-11-16 20:33:03 -08:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
const PixelBufferFormat& format = gl->GetPixelFormat();
|
|
|
|
|
2013-06-07 11:42:12 -07:00
|
|
|
result.mAlpha.Construct(format.alpha > 0);
|
2013-02-13 15:26:24 -08:00
|
|
|
result.mDepth = format.depth > 0;
|
|
|
|
result.mStencil = format.stencil > 0;
|
|
|
|
result.mAntialias = format.samples > 1;
|
2012-12-17 13:44:04 -08:00
|
|
|
result.mPremultipliedAlpha = mOptions.premultipliedAlpha;
|
|
|
|
result.mPreserveDrawingBuffer = mOptions.preserveDrawingBuffer;
|
2010-11-16 20:33:03 -08:00
|
|
|
}
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
/* [noscript] DOMString mozGetUnderlyingParamString(in GLenum pname); */
|
2010-12-16 12:49:54 -08:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
WebGLContext::MozGetUnderlyingParamString(uint32_t pname, nsAString& retval)
|
2010-12-16 12:49:54 -08:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2011-10-26 13:00:44 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
retval.SetIsVoid(true);
|
2010-12-16 12:49:54 -08:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
switch (pname) {
|
|
|
|
case LOCAL_GL_VENDOR:
|
|
|
|
case LOCAL_GL_RENDERER:
|
|
|
|
case LOCAL_GL_VERSION:
|
|
|
|
case LOCAL_GL_SHADING_LANGUAGE_VERSION:
|
|
|
|
case LOCAL_GL_EXTENSIONS: {
|
|
|
|
const char *s = (const char *) gl->fGetString(pname);
|
|
|
|
retval.Assign(NS_ConvertASCIItoUTF16(nsDependentCString(s)));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
void
|
2013-02-13 15:26:24 -08:00
|
|
|
WebGLContext::ClearScreen()
|
|
|
|
{
|
2014-04-30 14:30:23 -07:00
|
|
|
bool colorAttachmentsMask[WebGLContext::kMaxColorAttachments] = {false};
|
2013-06-21 16:44:17 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
MakeContextCurrent();
|
|
|
|
ScopedBindFramebuffer autoFB(gl, 0);
|
|
|
|
|
|
|
|
GLbitfield clearMask = LOCAL_GL_COLOR_BUFFER_BIT;
|
|
|
|
if (mOptions.depth)
|
|
|
|
clearMask |= LOCAL_GL_DEPTH_BUFFER_BIT;
|
|
|
|
if (mOptions.stencil)
|
|
|
|
clearMask |= LOCAL_GL_STENCIL_BUFFER_BIT;
|
|
|
|
|
2013-06-21 16:44:17 -07:00
|
|
|
colorAttachmentsMask[0] = true;
|
|
|
|
|
|
|
|
ForceClearFramebufferWithDefaultValues(clearMask, colorAttachmentsMask);
|
2013-02-13 15:26:24 -08:00
|
|
|
}
|
|
|
|
|
2014-05-12 19:11:40 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
// For NaNs, etc.
|
|
|
|
static bool IsShadowCorrect(float shadow, float actual) {
|
|
|
|
if (IsNaN(shadow)) {
|
|
|
|
// GL is allowed to do anything it wants for NaNs, so if we're shadowing
|
|
|
|
// a NaN, then whatever `actual` is might be correct.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return shadow == actual;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
void
|
2014-04-30 14:30:23 -07:00
|
|
|
WebGLContext::ForceClearFramebufferWithDefaultValues(GLbitfield mask, const bool colorAttachmentsMask[kMaxColorAttachments])
|
2011-05-20 12:53:53 -07:00
|
|
|
{
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool initializeColorBuffer = 0 != (mask & LOCAL_GL_COLOR_BUFFER_BIT);
|
|
|
|
bool initializeDepthBuffer = 0 != (mask & LOCAL_GL_DEPTH_BUFFER_BIT);
|
|
|
|
bool initializeStencilBuffer = 0 != (mask & LOCAL_GL_STENCIL_BUFFER_BIT);
|
2014-04-25 19:34:07 -07:00
|
|
|
bool drawBuffersIsEnabled = IsExtensionEnabled(WebGLExtensionID::WEBGL_draw_buffers);
|
2013-06-21 16:44:17 -07:00
|
|
|
|
2014-04-30 14:30:23 -07:00
|
|
|
GLenum currentDrawBuffers[WebGLContext::kMaxColorAttachments];
|
2011-05-20 12:53:53 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
// Fun GL fact: No need to worry about the viewport here, glViewport is just
|
|
|
|
// setting up a coordinates transformation, it doesn't affect glClear at all.
|
2014-05-12 19:11:40 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Scope to hide our variables.
|
|
|
|
{
|
|
|
|
// Sanity-check that all our state is set properly. Otherwise, when we
|
|
|
|
// reset out state to what we *think* it is, we'll get it wrong.
|
|
|
|
|
|
|
|
// Dither shouldn't matter when we're clearing to {0,0,0,0}.
|
|
|
|
MOZ_ASSERT(gl->fIsEnabled(LOCAL_GL_SCISSOR_TEST) == mScissorTestEnabled);
|
|
|
|
|
|
|
|
if (initializeColorBuffer) {
|
|
|
|
realGLboolean colorWriteMask[4] = {2, 2, 2, 2};
|
|
|
|
GLfloat colorClearValue[4] = {-1.0f, -1.0f, -1.0f, -1.0f};
|
|
|
|
|
|
|
|
gl->fGetBooleanv(LOCAL_GL_COLOR_WRITEMASK, colorWriteMask);
|
|
|
|
gl->fGetFloatv(LOCAL_GL_COLOR_CLEAR_VALUE, colorClearValue);
|
|
|
|
|
|
|
|
MOZ_ASSERT(colorWriteMask[0] == mColorWriteMask[0] &&
|
|
|
|
colorWriteMask[1] == mColorWriteMask[1] &&
|
|
|
|
colorWriteMask[2] == mColorWriteMask[2] &&
|
|
|
|
colorWriteMask[3] == mColorWriteMask[3]);
|
|
|
|
MOZ_ASSERT(IsShadowCorrect(mColorClearValue[0], colorClearValue[0]) &&
|
|
|
|
IsShadowCorrect(mColorClearValue[1], colorClearValue[1]) &&
|
|
|
|
IsShadowCorrect(mColorClearValue[2], colorClearValue[2]) &&
|
|
|
|
IsShadowCorrect(mColorClearValue[3], colorClearValue[3]));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initializeDepthBuffer) {
|
|
|
|
realGLboolean depthWriteMask = 2;
|
|
|
|
GLfloat depthClearValue = -1.0f;
|
|
|
|
|
|
|
|
|
|
|
|
gl->fGetBooleanv(LOCAL_GL_DEPTH_WRITEMASK, &depthWriteMask);
|
|
|
|
gl->fGetFloatv(LOCAL_GL_DEPTH_CLEAR_VALUE, &depthClearValue);
|
|
|
|
|
|
|
|
MOZ_ASSERT(depthWriteMask == mDepthWriteMask);
|
|
|
|
MOZ_ASSERT(IsShadowCorrect(mDepthClearValue, depthClearValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initializeStencilBuffer) {
|
|
|
|
GLuint stencilWriteMaskFront = 0xdeadbad1;
|
|
|
|
GLuint stencilWriteMaskBack = 0xdeadbad1;
|
|
|
|
GLuint stencilClearValue = 0xdeadbad1;
|
|
|
|
|
|
|
|
gl->GetUIntegerv(LOCAL_GL_STENCIL_WRITEMASK, &stencilWriteMaskFront);
|
|
|
|
gl->GetUIntegerv(LOCAL_GL_STENCIL_BACK_WRITEMASK, &stencilWriteMaskBack);
|
|
|
|
gl->GetUIntegerv(LOCAL_GL_STENCIL_CLEAR_VALUE, &stencilClearValue);
|
|
|
|
|
|
|
|
GLuint stencilBits = 0;
|
|
|
|
gl->GetUIntegerv(LOCAL_GL_STENCIL_BITS, &stencilBits);
|
|
|
|
GLuint stencilMask = (GLuint(1) << stencilBits) - 1;
|
|
|
|
|
|
|
|
MOZ_ASSERT( ( stencilWriteMaskFront & stencilMask) ==
|
|
|
|
(mStencilWriteMaskFront & stencilMask) );
|
|
|
|
MOZ_ASSERT( ( stencilWriteMaskBack & stencilMask) ==
|
|
|
|
(mStencilWriteMaskBack & stencilMask) );
|
|
|
|
MOZ_ASSERT( ( stencilClearValue & stencilMask) ==
|
|
|
|
(mStencilClearValue & stencilMask) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2013-02-13 15:26:24 -08:00
|
|
|
|
|
|
|
// Prepare GL state for clearing.
|
2011-05-20 12:53:53 -07:00
|
|
|
gl->fDisable(LOCAL_GL_SCISSOR_TEST);
|
|
|
|
|
|
|
|
if (initializeColorBuffer) {
|
2013-06-21 16:44:17 -07:00
|
|
|
|
|
|
|
if (drawBuffersIsEnabled) {
|
|
|
|
|
2014-04-30 14:30:23 -07:00
|
|
|
GLenum drawBuffersCommand[WebGLContext::kMaxColorAttachments] = { LOCAL_GL_NONE };
|
2013-06-21 16:44:17 -07:00
|
|
|
|
|
|
|
for(int32_t i = 0; i < mGLMaxDrawBuffers; i++) {
|
|
|
|
GLint temp;
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_DRAW_BUFFER0 + i, &temp);
|
|
|
|
currentDrawBuffers[i] = temp;
|
|
|
|
|
|
|
|
if (colorAttachmentsMask[i]) {
|
|
|
|
drawBuffersCommand[i] = LOCAL_GL_COLOR_ATTACHMENT0 + i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gl->fDrawBuffers(mGLMaxDrawBuffers, drawBuffersCommand);
|
|
|
|
}
|
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
gl->fColorMask(1, 1, 1, 1);
|
2013-02-13 15:26:24 -08:00
|
|
|
gl->fClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
2011-05-20 12:53:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (initializeDepthBuffer) {
|
|
|
|
gl->fDepthMask(1);
|
|
|
|
gl->fClearDepth(1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initializeStencilBuffer) {
|
2013-02-13 15:26:24 -08:00
|
|
|
// "The clear operation always uses the front stencil write mask
|
|
|
|
// when clearing the stencil buffer."
|
|
|
|
gl->fStencilMaskSeparate(LOCAL_GL_FRONT, 0xffffffff);
|
|
|
|
gl->fStencilMaskSeparate(LOCAL_GL_BACK, 0xffffffff);
|
2011-05-20 12:53:53 -07:00
|
|
|
gl->fClearStencil(0);
|
|
|
|
}
|
|
|
|
|
2013-08-22 17:11:40 -07:00
|
|
|
if (mRasterizerDiscardEnabled) {
|
|
|
|
gl->fDisable(LOCAL_GL_RASTERIZER_DISCARD);
|
|
|
|
}
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
// Do the clear!
|
2011-05-20 12:53:53 -07:00
|
|
|
gl->fClear(mask);
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
// And reset!
|
|
|
|
if (mScissorTestEnabled)
|
|
|
|
gl->fEnable(LOCAL_GL_SCISSOR_TEST);
|
|
|
|
|
2013-08-22 17:11:40 -07:00
|
|
|
if (mRasterizerDiscardEnabled) {
|
|
|
|
gl->fEnable(LOCAL_GL_RASTERIZER_DISCARD);
|
|
|
|
}
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
// Restore GL state after clearing.
|
2011-05-20 12:53:53 -07:00
|
|
|
if (initializeColorBuffer) {
|
2013-06-21 16:44:17 -07:00
|
|
|
if (drawBuffersIsEnabled) {
|
|
|
|
gl->fDrawBuffers(mGLMaxDrawBuffers, currentDrawBuffers);
|
|
|
|
}
|
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
gl->fColorMask(mColorWriteMask[0],
|
|
|
|
mColorWriteMask[1],
|
|
|
|
mColorWriteMask[2],
|
|
|
|
mColorWriteMask[3]);
|
|
|
|
gl->fClearColor(mColorClearValue[0],
|
|
|
|
mColorClearValue[1],
|
|
|
|
mColorClearValue[2],
|
|
|
|
mColorClearValue[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initializeDepthBuffer) {
|
|
|
|
gl->fDepthMask(mDepthWriteMask);
|
|
|
|
gl->fClearDepth(mDepthClearValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initializeStencilBuffer) {
|
2011-05-20 12:53:53 -07:00
|
|
|
gl->fStencilMaskSeparate(LOCAL_GL_FRONT, mStencilWriteMaskFront);
|
2013-02-13 15:26:24 -08:00
|
|
|
gl->fStencilMaskSeparate(LOCAL_GL_BACK, mStencilWriteMaskBack);
|
2011-05-20 12:53:53 -07:00
|
|
|
gl->fClearStencil(mStencilClearValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
// For an overview of how WebGL compositing works, see:
|
|
|
|
// https://wiki.mozilla.org/Platform/GFX/WebGL/Compositing
|
|
|
|
bool
|
|
|
|
WebGLContext::PresentScreenBuffer()
|
2011-05-20 12:53:53 -07:00
|
|
|
{
|
2013-11-23 18:21:45 -08:00
|
|
|
if (IsContextLost()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
if (!mShouldPresent) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-05-20 12:53:53 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
gl->MakeCurrent();
|
2014-04-17 13:15:41 -07:00
|
|
|
MOZ_ASSERT(!mBackbufferNeedsClear);
|
2013-02-13 15:26:24 -08:00
|
|
|
if (!gl->PublishFrame()) {
|
|
|
|
this->ForceLoseContext();
|
|
|
|
return false;
|
|
|
|
}
|
2011-05-20 12:53:53 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
if (!mOptions.preserveDrawingBuffer) {
|
2014-04-17 13:15:41 -07:00
|
|
|
mBackbufferNeedsClear = true;
|
2013-02-13 15:26:24 -08:00
|
|
|
}
|
2013-02-20 07:01:20 -08:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
mShouldPresent = false;
|
2013-02-21 11:54:25 -08:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
return true;
|
2011-05-20 12:53:53 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2012-01-24 13:12:31 -08:00
|
|
|
WebGLContext::DummyFramebufferOperation(const char *info)
|
|
|
|
{
|
2013-09-04 05:14:43 -07:00
|
|
|
GLenum status = CheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
|
2014-02-20 17:20:28 -08:00
|
|
|
if (status != LOCAL_GL_FRAMEBUFFER_COMPLETE)
|
|
|
|
ErrorInvalidFramebufferOperation("%s: incomplete framebuffer", info);
|
2012-01-24 13:12:31 -08:00
|
|
|
}
|
|
|
|
|
2012-01-04 13:12:03 -08:00
|
|
|
// We use this timer for many things. Here are the things that it is activated for:
|
|
|
|
// 1) If a script is using the MOZ_WEBGL_lose_context extension.
|
|
|
|
// 2) If we are using EGL and _NOT ANGLE_, we query periodically to see if the
|
|
|
|
// CONTEXT_LOST_WEBGL error has been triggered.
|
|
|
|
// 3) If we are using ANGLE, or anything that supports ARB_robustness, query the
|
|
|
|
// GPU periodically to see if the reset status bit has been set.
|
|
|
|
// In all of these situations, we use this timer to send the script context lost
|
|
|
|
// and restored events asynchronously. For example, if it triggers a context loss,
|
|
|
|
// the webglcontextlost event will be sent to it the next time the robustness timer
|
|
|
|
// fires.
|
|
|
|
// Note that this timer mechanism is not used unless one of these 3 criteria
|
|
|
|
// are met.
|
|
|
|
// At a bare minimum, from context lost to context restores, it would take 3
|
|
|
|
// full timer iterations: detection, webglcontextlost, webglcontextrestored.
|
2012-10-23 09:21:23 -07:00
|
|
|
void
|
2014-05-12 19:11:08 -07:00
|
|
|
WebGLContext::RobustnessTimerCallback(nsITimer* timer)
|
2011-10-26 13:00:44 -07:00
|
|
|
{
|
2014-05-12 19:11:08 -07:00
|
|
|
TerminateContextLossTimer();
|
|
|
|
|
2012-06-06 00:42:47 -07:00
|
|
|
if (!mCanvasElement) {
|
2012-04-21 13:48:22 -07:00
|
|
|
// the canvas is gone. That happens when the page was closed before we got
|
|
|
|
// this timer event. In this case, there's nothing to do here, just don't crash.
|
2012-10-23 09:21:23 -07:00
|
|
|
return;
|
2012-04-21 13:48:22 -07:00
|
|
|
}
|
|
|
|
|
2014-05-12 19:11:08 -07:00
|
|
|
// If the context has been lost and we're waiting for it to be restored, do
|
|
|
|
// that now.
|
2012-01-04 13:12:03 -08:00
|
|
|
if (mContextStatus == ContextLostAwaitingEvent) {
|
2014-05-12 19:11:08 -07:00
|
|
|
bool defaultAction;
|
2012-06-06 00:42:47 -07:00
|
|
|
nsContentUtils::DispatchTrustedEvent(mCanvasElement->OwnerDoc(),
|
|
|
|
static_cast<nsIDOMHTMLCanvasElement*>(mCanvasElement),
|
2012-01-04 13:12:03 -08:00
|
|
|
NS_LITERAL_STRING("webglcontextlost"),
|
2012-02-14 08:17:19 -08:00
|
|
|
true,
|
|
|
|
true,
|
2014-05-12 19:11:08 -07:00
|
|
|
&defaultAction);
|
|
|
|
|
|
|
|
// If the script didn't handle the event, we don't allow restores.
|
|
|
|
if (defaultAction)
|
|
|
|
mAllowRestore = false;
|
|
|
|
|
|
|
|
// If the script handled the event and we are allowing restores, then
|
|
|
|
// mark it to be restored. Otherwise, leave it as context lost
|
|
|
|
// (unusable).
|
|
|
|
if (!defaultAction && mAllowRestore) {
|
|
|
|
ForceRestoreContext();
|
|
|
|
// Restart the timer so that it will be restored on the next
|
|
|
|
// callback.
|
|
|
|
SetupContextLossTimer();
|
|
|
|
} else {
|
2012-01-04 13:12:03 -08:00
|
|
|
mContextStatus = ContextLost;
|
|
|
|
}
|
2014-05-12 19:11:08 -07:00
|
|
|
} else if (mContextStatus == ContextLostAwaitingRestore) {
|
|
|
|
// Try to restore the context. If it fails, try again later.
|
|
|
|
if (NS_FAILED(SetDimensions(mWidth, mHeight))) {
|
|
|
|
SetupContextLossTimer();
|
2012-10-23 09:21:23 -07:00
|
|
|
return;
|
2012-01-04 13:12:03 -08:00
|
|
|
}
|
2013-09-04 05:14:44 -07:00
|
|
|
mContextStatus = ContextNotLost;
|
2012-06-06 00:42:47 -07:00
|
|
|
nsContentUtils::DispatchTrustedEvent(mCanvasElement->OwnerDoc(),
|
|
|
|
static_cast<nsIDOMHTMLCanvasElement*>(mCanvasElement),
|
2012-01-04 13:12:03 -08:00
|
|
|
NS_LITERAL_STRING("webglcontextrestored"),
|
2012-02-14 08:17:19 -08:00
|
|
|
true,
|
|
|
|
true);
|
2014-05-12 19:11:08 -07:00
|
|
|
// Set all flags back to the state they were in before the context was
|
|
|
|
// lost.
|
2014-03-07 13:16:34 -08:00
|
|
|
mEmitContextLostErrorOnce = true;
|
2014-05-12 19:11:08 -07:00
|
|
|
mAllowRestore = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
MaybeRestoreContext();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::MaybeRestoreContext()
|
|
|
|
{
|
|
|
|
// Don't try to handle it if we already know it's busted.
|
|
|
|
if (mContextStatus != ContextNotLost || gl == nullptr)
|
2011-10-26 13:00:44 -07:00
|
|
|
return;
|
2014-05-12 19:11:08 -07:00
|
|
|
|
|
|
|
bool isEGL = gl->GetContextType() == gl::GLContextType::EGL,
|
|
|
|
isANGLE = gl->IsANGLE();
|
|
|
|
|
|
|
|
GLContext::ContextResetARB resetStatus = GLContext::CONTEXT_NO_ERROR;
|
|
|
|
if (mHasRobustness) {
|
|
|
|
gl->MakeCurrent();
|
|
|
|
resetStatus = (GLContext::ContextResetARB) gl->fGetGraphicsResetStatus();
|
|
|
|
} else if (isEGL) {
|
|
|
|
// Simulate a ARB_robustness guilty context loss for when we
|
|
|
|
// get an EGL_CONTEXT_LOST error. It may not actually be guilty,
|
|
|
|
// but we can't make any distinction, so we must assume the worst
|
|
|
|
// case.
|
|
|
|
if (!gl->MakeCurrent(true) && gl->IsContextLost()) {
|
|
|
|
resetStatus = GLContext::CONTEXT_GUILTY_CONTEXT_RESET_ARB;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resetStatus != GLContext::CONTEXT_NO_ERROR) {
|
|
|
|
// It's already lost, but clean up after it and signal to JS that it is
|
|
|
|
// lost.
|
|
|
|
ForceLoseContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (resetStatus) {
|
|
|
|
case GLContext::CONTEXT_NO_ERROR:
|
|
|
|
// If there has been activity since the timer was set, it's possible
|
|
|
|
// that we did or are going to miss something, so clear this flag and
|
|
|
|
// run it again some time later.
|
|
|
|
if (mDrawSinceContextLossTimerSet)
|
|
|
|
SetupContextLossTimer();
|
|
|
|
break;
|
|
|
|
case GLContext::CONTEXT_GUILTY_CONTEXT_RESET_ARB:
|
|
|
|
NS_WARNING("WebGL content on the page caused the graphics card to reset; not restoring the context");
|
|
|
|
mAllowRestore = false;
|
|
|
|
break;
|
|
|
|
case GLContext::CONTEXT_INNOCENT_CONTEXT_RESET_ARB:
|
|
|
|
break;
|
|
|
|
case GLContext::CONTEXT_UNKNOWN_CONTEXT_RESET_ARB:
|
|
|
|
NS_WARNING("WebGL content on the page might have caused the graphics card to reset");
|
|
|
|
if (isEGL && isANGLE) {
|
|
|
|
// If we're using ANGLE, we ONLY get back UNKNOWN context resets, including for guilty contexts.
|
|
|
|
// This means that we can't restore it or risk restoring a guilty context. Should this ever change,
|
|
|
|
// we can get rid of the whole IsANGLE() junk from GLContext.h since, as of writing, this is the
|
|
|
|
// only use for it. See ANGLE issue 261.
|
|
|
|
mAllowRestore = false;
|
|
|
|
}
|
|
|
|
break;
|
2011-10-26 13:00:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::ForceLoseContext()
|
|
|
|
{
|
2014-05-12 19:11:08 -07:00
|
|
|
if (mContextStatus == ContextLostAwaitingEvent)
|
|
|
|
return;
|
2014-05-12 17:56:31 -07:00
|
|
|
|
2014-05-12 19:11:08 -07:00
|
|
|
mContextStatus = ContextLostAwaitingEvent;
|
|
|
|
// Queue up a task to restore the event.
|
|
|
|
SetupContextLossTimer();
|
2011-10-26 13:00:44 -07:00
|
|
|
DestroyResourcesAndContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::ForceRestoreContext()
|
|
|
|
{
|
2012-01-04 13:12:03 -08:00
|
|
|
mContextStatus = ContextLostAwaitingRestore;
|
2011-10-26 13:00:44 -07:00
|
|
|
}
|
|
|
|
|
2013-09-04 05:14:52 -07:00
|
|
|
void
|
|
|
|
WebGLContext::MakeContextCurrent() const { gl->MakeCurrent(); }
|
|
|
|
|
2013-10-01 14:01:19 -07:00
|
|
|
mozilla::TemporaryRef<mozilla::gfx::SourceSurface>
|
2014-04-16 22:28:17 -07:00
|
|
|
WebGLContext::GetSurfaceSnapshot(bool* aPremultAlpha)
|
2013-10-01 14:01:19 -07:00
|
|
|
{
|
2014-04-16 22:28:17 -07:00
|
|
|
if (!gl)
|
|
|
|
return nullptr;
|
|
|
|
|
2014-05-12 19:20:26 -07:00
|
|
|
RefPtr<DataSourceSurface> surf = Factory::CreateDataSourceSurfaceWithStride(IntSize(mWidth, mHeight),
|
|
|
|
SurfaceFormat::B8G8R8A8,
|
|
|
|
mWidth * 4);
|
|
|
|
if (!surf) {
|
2014-04-16 22:28:17 -07:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl->MakeCurrent();
|
2014-04-17 13:15:41 -07:00
|
|
|
{
|
|
|
|
ScopedBindFramebuffer autoFB(gl, 0);
|
|
|
|
ClearBackbufferIfNeeded();
|
2014-05-12 19:20:26 -07:00
|
|
|
ReadPixelsIntoDataSurface(gl, surf);
|
2014-04-17 13:15:41 -07:00
|
|
|
}
|
2014-04-16 22:28:17 -07:00
|
|
|
|
|
|
|
if (aPremultAlpha) {
|
|
|
|
*aPremultAlpha = true;
|
|
|
|
}
|
|
|
|
bool srcPremultAlpha = mOptions.premultipliedAlpha;
|
|
|
|
if (!srcPremultAlpha) {
|
|
|
|
if (aPremultAlpha) {
|
|
|
|
*aPremultAlpha = false;
|
|
|
|
} else {
|
2014-05-12 19:20:26 -07:00
|
|
|
gfxUtils::PremultiplyDataSurface(surf);
|
2014-04-16 22:28:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<DrawTarget> dt =
|
|
|
|
Factory::CreateDrawTarget(BackendType::CAIRO,
|
|
|
|
IntSize(mWidth, mHeight),
|
|
|
|
SurfaceFormat::B8G8R8A8);
|
|
|
|
|
|
|
|
if (!dt) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Matrix m;
|
|
|
|
m.Translate(0.0, mHeight);
|
|
|
|
m.Scale(1.0, -1.0);
|
|
|
|
dt->SetTransform(m);
|
|
|
|
|
2014-05-12 19:20:26 -07:00
|
|
|
dt->DrawSurface(surf,
|
2014-04-16 22:28:17 -07:00
|
|
|
Rect(0, 0, mWidth, mHeight),
|
|
|
|
Rect(0, 0, mWidth, mHeight),
|
|
|
|
DrawSurfaceOptions(),
|
|
|
|
DrawOptions(1.0f, CompositionOp::OP_SOURCE));
|
|
|
|
|
|
|
|
return dt->Snapshot();
|
2013-10-01 14:01:19 -07:00
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
//
|
|
|
|
// XPCOM goop
|
|
|
|
//
|
|
|
|
|
2011-03-06 03:11:31 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(WebGLContext)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(WebGLContext)
|
2010-06-15 14:38:05 -07:00
|
|
|
|
2014-04-29 01:57:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WebGLContext,
|
2012-11-14 23:32:39 -08:00
|
|
|
mCanvasElement,
|
|
|
|
mExtensions,
|
|
|
|
mBound2DTextures,
|
|
|
|
mBoundCubeMapTextures,
|
|
|
|
mBoundArrayBuffer,
|
2013-08-21 18:11:03 -07:00
|
|
|
mBoundTransformFeedbackBuffer,
|
2012-11-14 23:32:39 -08:00
|
|
|
mCurrentProgram,
|
|
|
|
mBoundFramebuffer,
|
|
|
|
mBoundRenderbuffer,
|
2013-08-06 14:23:46 -07:00
|
|
|
mBoundVertexArray,
|
2013-09-04 08:29:36 -07:00
|
|
|
mDefaultVertexArray,
|
2013-08-21 18:11:03 -07:00
|
|
|
mActiveOcclusionQuery,
|
|
|
|
mActiveTransformFeedbackQuery)
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-15 14:38:05 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebGLContext)
|
2012-05-04 09:36:40 -07:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2010-11-16 20:33:04 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMWebGLRenderingContext)
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICanvasRenderingContextInternal)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
2012-05-04 09:36:40 -07:00
|
|
|
// If the exact way we cast to nsISupports here ever changes, fix our
|
2013-04-09 09:26:36 -07:00
|
|
|
// ToSupports() method.
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMWebGLRenderingContext)
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_INTERFACE_MAP_END
|