2009-09-03 04:47:49 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04: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-18 08:04:22 +04:00
|
|
|
|
2009-09-03 04:47:49 +04:00
|
|
|
#include "WebGLContext.h"
|
2014-08-22 20:55:00 +04:00
|
|
|
|
2017-11-30 14:40:57 +03:00
|
|
|
#include <algorithm>
|
2015-07-15 03:37:28 +03:00
|
|
|
#include <queue>
|
|
|
|
|
2012-10-17 23:11:51 +04:00
|
|
|
#include "AccessCheck.h"
|
2009-09-03 04:47:49 +04:00
|
|
|
#include "gfxContext.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "gfxCrashReporterUtils.h"
|
2009-09-03 04:47:49 +04:00
|
|
|
#include "gfxPattern.h"
|
2014-07-04 03:09:04 +04:00
|
|
|
#include "gfxPrefs.h"
|
2010-07-01 20:43:33 +04:00
|
|
|
#include "gfxUtils.h"
|
2018-01-07 20:35:00 +03:00
|
|
|
#include "MozFramebuffer.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "GLBlitHelper.h"
|
2013-09-04 16:14:52 +04:00
|
|
|
#include "GLContext.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "GLContextProvider.h"
|
2014-01-02 19:17:29 +04:00
|
|
|
#include "GLReadTexImageHelper.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
#include "GLScreenBuffer.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "ImageContainer.h"
|
|
|
|
#include "ImageEncoder.h"
|
|
|
|
#include "Layers.h"
|
2015-10-22 23:04:35 +03:00
|
|
|
#include "LayerUserData.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2015-10-12 06:21:03 +03:00
|
|
|
#include "mozilla/dom/Event.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "mozilla/dom/HTMLVideoElement.h"
|
|
|
|
#include "mozilla/dom/ImageData.h"
|
2016-05-12 02:45:43 +03:00
|
|
|
#include "mozilla/dom/WebGLContextEvent.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "mozilla/EnumeratedArrayCycleCollection.h"
|
2011-07-07 06:00:02 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "mozilla/ProcessPriorityManager.h"
|
2016-07-22 20:26:05 +03:00
|
|
|
#include "mozilla/ScopeExit.h"
|
2012-06-06 11:40:02 +04:00
|
|
|
#include "mozilla/Services.h"
|
2011-09-20 00:08:56 +04:00
|
|
|
#include "mozilla/Telemetry.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsIClassInfoImpl.h"
|
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsIGfxInfo.h"
|
2012-04-22 00:48:22 +04:00
|
|
|
#include "nsIObserverService.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "nsIVariant.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2017-08-30 16:14:46 +03:00
|
|
|
#include "SVGObserverUtils.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "prenv.h"
|
|
|
|
#include "ScopedGLHelpers.h"
|
2016-02-25 02:54:50 +03:00
|
|
|
#include "VRManagerChild.h"
|
2018-09-28 22:25:21 +03:00
|
|
|
#include "mozilla/layers/ImageBridgeChild.h"
|
2016-02-25 02:54:50 +03:00
|
|
|
#include "mozilla/layers/TextureClientSharedSurface.h"
|
2017-10-28 13:07:27 +03:00
|
|
|
#include "mozilla/layers/WebRenderUserData.h"
|
|
|
|
#include "mozilla/layers/WebRenderCanvasRenderer.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
|
|
|
|
// Local
|
|
|
|
#include "CanvasUtils.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "WebGL1Context.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
#include "WebGLActiveInfo.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "WebGLBuffer.h"
|
|
|
|
#include "WebGLContextLossHandler.h"
|
|
|
|
#include "WebGLContextUtils.h"
|
|
|
|
#include "WebGLExtensions.h"
|
2018-09-28 02:38:23 +03:00
|
|
|
#include "WebGLFormats.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "WebGLFramebuffer.h"
|
|
|
|
#include "WebGLMemoryTracker.h"
|
|
|
|
#include "WebGLObjectModel.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
#include "WebGLProgram.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "WebGLQuery.h"
|
|
|
|
#include "WebGLSampler.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
#include "WebGLShader.h"
|
2016-06-23 12:01:36 +03:00
|
|
|
#include "WebGLSync.h"
|
2014-11-26 05:00:06 +03:00
|
|
|
#include "WebGLTransformFeedback.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "WebGLVertexArray.h"
|
|
|
|
#include "WebGLVertexAttribData.h"
|
2012-08-21 08:06:46 +04:00
|
|
|
|
2016-02-19 04:59:24 +03:00
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
|
|
|
#include "nsCocoaFeatures.h"
|
|
|
|
#endif
|
|
|
|
|
2016-06-21 06:38:47 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "WGLLibrary.h"
|
|
|
|
#endif
|
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
// Generated
|
|
|
|
#include "mozilla/dom/WebGLRenderingContextBinding.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace mozilla {
|
2013-05-27 18:12:13 +04:00
|
|
|
|
2012-10-04 01:13:05 +04:00
|
|
|
using namespace mozilla::dom;
|
2013-02-14 03:26:24 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using namespace mozilla::gl;
|
2010-09-02 13:18:40 +04:00
|
|
|
using namespace mozilla::layers;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2012-08-01 22:58:44 +04:00
|
|
|
WebGLContextOptions::WebGLContextOptions()
|
|
|
|
{
|
|
|
|
// Set default alpha state based on preference.
|
2015-10-12 06:21:03 +03:00
|
|
|
if (gfxPrefs::WebGLDefaultNoAlpha())
|
2012-08-02 02:40:24 +04:00
|
|
|
alpha = false;
|
2012-08-01 22:58:44 +04:00
|
|
|
}
|
|
|
|
|
2018-06-23 02:47:02 +03:00
|
|
|
bool
|
|
|
|
WebGLContextOptions::operator==(const WebGLContextOptions& r) const
|
|
|
|
{
|
|
|
|
bool eq = true;
|
|
|
|
eq &= (alpha == r.alpha);
|
|
|
|
eq &= (depth == r.depth);
|
|
|
|
eq &= (stencil == r.stencil);
|
|
|
|
eq &= (premultipliedAlpha == r.premultipliedAlpha);
|
|
|
|
eq &= (antialias == r.antialias);
|
|
|
|
eq &= (preserveDrawingBuffer == r.preserveDrawingBuffer);
|
|
|
|
eq &= (failIfMajorPerformanceCaveat == r.failIfMajorPerformanceCaveat);
|
|
|
|
eq &= (powerPreference == r.powerPreference);
|
|
|
|
return eq;
|
|
|
|
}
|
|
|
|
|
2009-09-03 04:47:49 +04:00
|
|
|
WebGLContext::WebGLContext()
|
2018-04-13 16:01:28 +03:00
|
|
|
: WebGLContextUnchecked(nullptr)
|
|
|
|
, mMaxPerfWarnings(gfxPrefs::WebGLMaxPerfWarnings())
|
|
|
|
, mNumPerfWarnings(0)
|
|
|
|
, mMaxAcceptableFBStatusInvals(gfxPrefs::WebGLMaxAcceptableFBStatusInvals())
|
|
|
|
, mDataAllocGLCallCount(0)
|
|
|
|
, mBypassShaderValidation(false)
|
|
|
|
, mEmptyTFO(0)
|
|
|
|
, mContextLossHandler(this)
|
|
|
|
, mNeedsFakeNoAlpha(false)
|
|
|
|
, mNeedsFakeNoDepth(false)
|
|
|
|
, mNeedsFakeNoStencil(false)
|
|
|
|
, mAllowFBInvalidation(gfxPrefs::WebGLFBInvalidation())
|
|
|
|
, mMsaaSamples(gfxPrefs::WebGLMsaaSamples())
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2018-04-13 16:01:28 +03:00
|
|
|
mGeneration = 0;
|
|
|
|
mInvalidated = false;
|
|
|
|
mCapturedFrameInvalidated = false;
|
|
|
|
mShouldPresent = true;
|
|
|
|
mResetLayer = true;
|
|
|
|
mOptionsFrozen = false;
|
|
|
|
mDisableExtensions = false;
|
|
|
|
mIsMesa = false;
|
|
|
|
mEmitContextLostErrorOnce = false;
|
|
|
|
mWebGLError = 0;
|
|
|
|
mUnderlyingGLError = 0;
|
2018-09-28 22:25:21 +03:00
|
|
|
mVRReady = false;
|
2018-04-13 16:01:28 +03:00
|
|
|
|
|
|
|
mContextLostErrorSet = false;
|
|
|
|
|
|
|
|
mViewportX = 0;
|
|
|
|
mViewportY = 0;
|
|
|
|
mViewportWidth = 0;
|
|
|
|
mViewportHeight = 0;
|
|
|
|
|
|
|
|
mDitherEnabled = 1;
|
|
|
|
mRasterizerDiscardEnabled = 0; // OpenGL ES 3.0 spec p244
|
|
|
|
mScissorTestEnabled = 0;
|
|
|
|
mStencilTestEnabled = 0;
|
2013-05-22 11:05:38 +04:00
|
|
|
|
2018-04-13 16:01:28 +03:00
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
// XXX mtseng: bug 709490, not thread safe
|
|
|
|
WebGLMemoryTracker::AddWebGLContext(this);
|
|
|
|
}
|
2018-04-10 22:11:02 +03:00
|
|
|
|
2018-04-13 16:01:28 +03:00
|
|
|
mAllowContextRestore = true;
|
|
|
|
mLastLossWasSimulated = false;
|
|
|
|
mLoseContextOnMemoryPressure = false;
|
|
|
|
mCanLoseContextInForeground = true;
|
|
|
|
mRestoreWhenVisible = false;
|
|
|
|
|
|
|
|
mAlreadyGeneratedWarnings = 0;
|
|
|
|
mAlreadyWarnedAboutFakeVertexAttrib0 = false;
|
|
|
|
mAlreadyWarnedAboutViewportLargerThanDest = false;
|
|
|
|
|
|
|
|
mMaxWarnings = gfxPrefs::WebGLMaxWarningsPerContext();
|
|
|
|
if (mMaxWarnings < -1) {
|
|
|
|
GenerateWarning("webgl.max-warnings-per-context size is too large (seems like a negative value wrapped)");
|
|
|
|
mMaxWarnings = 0;
|
|
|
|
}
|
2012-08-03 01:28:02 +04:00
|
|
|
|
2018-04-13 16:01:28 +03:00
|
|
|
mLastUseIndex = 0;
|
2012-11-19 19:49:51 +04:00
|
|
|
|
2018-04-13 16:01:28 +03:00
|
|
|
mDisableFragHighP = false;
|
2013-05-22 11:05:38 +04:00
|
|
|
|
2018-04-13 16:01:28 +03:00
|
|
|
mDrawCallsSinceLastFlush = 0;
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
WebGLContext::~WebGLContext()
|
|
|
|
{
|
2014-09-10 05:40:51 +04:00
|
|
|
RemovePostRefreshObserver();
|
2014-06-23 03:16:00 +04:00
|
|
|
|
2010-07-19 09:01:14 +04:00
|
|
|
DestroyResourcesAndContext();
|
2015-10-12 06:21:03 +03:00
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
// XXX mtseng: bug 709490, not thread safe
|
|
|
|
WebGLMemoryTracker::RemoveWebGLContext(this);
|
|
|
|
}
|
2010-07-19 09:01:14 +04:00
|
|
|
}
|
|
|
|
|
2016-06-03 11:18:56 +03:00
|
|
|
template<typename T>
|
2016-11-30 05:30:28 +03:00
|
|
|
void
|
2016-06-03 11:18:56 +03:00
|
|
|
ClearLinkedList(LinkedList<T>& list)
|
|
|
|
{
|
|
|
|
while (!list.isEmpty()) {
|
|
|
|
list.getLast()->DeleteOnce();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-19 09:01:14 +04:00
|
|
|
void
|
|
|
|
WebGLContext::DestroyResourcesAndContext()
|
|
|
|
{
|
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
mDefaultFB = nullptr;
|
|
|
|
mResolvedDefaultFB = nullptr;
|
|
|
|
|
2011-12-04 23:15:42 +04:00
|
|
|
mBound2DTextures.Clear();
|
|
|
|
mBoundCubeMapTextures.Clear();
|
2014-10-14 03:42:20 +04:00
|
|
|
mBound3DTextures.Clear();
|
2015-11-25 07:15:29 +03:00
|
|
|
mBound2DArrayTextures.Clear();
|
2015-06-09 03:18:19 +03:00
|
|
|
mBoundSamplers.Clear();
|
2012-07-30 18:20:58 +04:00
|
|
|
mBoundArrayBuffer = nullptr;
|
2014-12-05 10:04:55 +03:00
|
|
|
mBoundCopyReadBuffer = nullptr;
|
|
|
|
mBoundCopyWriteBuffer = nullptr;
|
|
|
|
mBoundPixelPackBuffer = nullptr;
|
|
|
|
mBoundPixelUnpackBuffer = nullptr;
|
2018-03-30 02:43:58 +03:00
|
|
|
mBoundTransformFeedbackBuffer = nullptr;
|
2014-12-05 10:04:55 +03:00
|
|
|
mBoundUniformBuffer = nullptr;
|
2012-07-30 18:20:58 +04:00
|
|
|
mCurrentProgram = nullptr;
|
2015-01-16 02:40:39 +03:00
|
|
|
mActiveProgramLinkInfo = nullptr;
|
2015-01-13 02:05:21 +03:00
|
|
|
mBoundDrawFramebuffer = nullptr;
|
|
|
|
mBoundReadFramebuffer = nullptr;
|
2012-07-30 18:20:58 +04:00
|
|
|
mBoundRenderbuffer = nullptr;
|
2013-06-28 01:07:21 +04:00
|
|
|
mBoundVertexArray = nullptr;
|
|
|
|
mDefaultVertexArray = nullptr;
|
2014-11-26 05:00:06 +03:00
|
|
|
mBoundTransformFeedback = nullptr;
|
|
|
|
mDefaultTransformFeedback = nullptr;
|
2018-08-24 18:32:12 +03:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
mVRScreen = nullptr;
|
|
|
|
#endif
|
2014-11-26 05:00:06 +03:00
|
|
|
|
2016-10-04 04:33:52 +03:00
|
|
|
mQuerySlot_SamplesPassed = nullptr;
|
|
|
|
mQuerySlot_TFPrimsWritten = nullptr;
|
|
|
|
mQuerySlot_TimeElapsed = nullptr;
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
mIndexedUniformBufferBindings.clear();
|
2014-12-05 10:04:55 +03:00
|
|
|
|
2018-02-21 04:34:25 +03:00
|
|
|
if (mAvailabilityRunnable) {
|
|
|
|
mAvailabilityRunnable->Run();
|
|
|
|
}
|
|
|
|
|
2016-06-03 11:18:56 +03:00
|
|
|
//////
|
|
|
|
|
|
|
|
ClearLinkedList(mBuffers);
|
|
|
|
ClearLinkedList(mFramebuffers);
|
|
|
|
ClearLinkedList(mPrograms);
|
|
|
|
ClearLinkedList(mQueries);
|
|
|
|
ClearLinkedList(mRenderbuffers);
|
|
|
|
ClearLinkedList(mSamplers);
|
|
|
|
ClearLinkedList(mShaders);
|
2016-06-23 12:01:36 +03:00
|
|
|
ClearLinkedList(mSyncs);
|
2016-06-03 11:18:56 +03:00
|
|
|
ClearLinkedList(mTextures);
|
|
|
|
ClearLinkedList(mTransformFeedbacks);
|
|
|
|
ClearLinkedList(mVertexArrays);
|
|
|
|
|
|
|
|
//////
|
2010-07-19 09:01:14 +04:00
|
|
|
|
2016-12-29 11:08:39 +03:00
|
|
|
if (mEmptyTFO) {
|
|
|
|
gl->fDeleteTransformFeedbacks(1, &mEmptyTFO);
|
|
|
|
mEmptyTFO = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////
|
|
|
|
|
2016-07-21 11:12:15 +03:00
|
|
|
if (mFakeVertexAttrib0BufferObject) {
|
2011-02-25 01:17:34 +03:00
|
|
|
gl->fDeleteBuffers(1, &mFakeVertexAttrib0BufferObject);
|
2016-07-21 11:12:15 +03:00
|
|
|
mFakeVertexAttrib0BufferObject = 0;
|
|
|
|
}
|
2011-02-25 01:17:34 +03:00
|
|
|
|
2013-11-05 13:35:50 +04: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-26 06:34:07 +04:00
|
|
|
for (size_t i = 0; i < size_t(WebGLExtensionID::Max); ++i) {
|
2013-11-05 13:35:50 +04:00
|
|
|
WebGLExtensionID extension = WebGLExtensionID(i);
|
|
|
|
|
2014-04-26 06:34:07 +04:00
|
|
|
if (!IsExtensionEnabled(extension) || (extension == WebGLExtensionID::WEBGL_lose_context))
|
2013-11-05 13:35:50 +04:00
|
|
|
continue;
|
|
|
|
|
2014-03-12 06:51:39 +04:00
|
|
|
mExtensions[extension]->MarkLost();
|
2013-11-05 13:35:50 +04:00
|
|
|
mExtensions[extension] = nullptr;
|
|
|
|
}
|
|
|
|
|
2010-07-19 09:01:14 +04:00
|
|
|
// We just got rid of everything, so the context had better
|
|
|
|
// have been going away.
|
2016-06-07 02:29:08 +03:00
|
|
|
if (GLContext::ShouldSpew()) {
|
2012-06-11 19:25:06 +04:00
|
|
|
printf_stderr("--- WebGL context destroyed: %p\n", gl.get());
|
2016-06-07 02:29:08 +03:00
|
|
|
}
|
2010-07-19 09:01:14 +04:00
|
|
|
|
2016-07-21 11:12:15 +03:00
|
|
|
MOZ_ASSERT(gl);
|
2017-12-19 05:30:56 +03:00
|
|
|
gl->MarkDestroyed();
|
2016-07-21 11:12:15 +03:00
|
|
|
mGL_OnlyClearInDestroyResourcesAndContext = nullptr;
|
|
|
|
MOZ_ASSERT(!gl);
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::Invalidate()
|
|
|
|
{
|
2015-09-17 06:37:05 +03:00
|
|
|
if (!mCanvasElement)
|
2011-03-28 03:59:47 +04:00
|
|
|
return;
|
|
|
|
|
2015-09-17 06:37:05 +03:00
|
|
|
mCapturedFrameInvalidated = true;
|
|
|
|
|
|
|
|
if (mInvalidated)
|
2009-09-03 04:47:49 +04:00
|
|
|
return;
|
|
|
|
|
2017-08-30 17:58:31 +03:00
|
|
|
SVGObserverUtils::InvalidateDirectRenderingObservers(mCanvasElement);
|
2010-08-13 17:36:13 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mInvalidated = true;
|
2012-07-30 18:20:58 +04:00
|
|
|
mCanvasElement->InvalidateCanvasContent(nullptr);
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
void
|
|
|
|
WebGLContext::OnVisibilityChange()
|
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
if (gl) // Context not lost.
|
2015-10-12 06:21:03 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!mRestoreWhenVisible || mLastLossWasSimulated) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ForceRestoreContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::OnMemoryPressure()
|
|
|
|
{
|
|
|
|
bool shouldLoseContext = mLoseContextOnMemoryPressure;
|
|
|
|
|
|
|
|
if (!mCanLoseContextInForeground &&
|
|
|
|
ProcessPriorityManager::CurrentProcessIsForeground())
|
|
|
|
{
|
|
|
|
shouldLoseContext = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldLoseContext)
|
|
|
|
ForceLoseContext();
|
|
|
|
}
|
|
|
|
|
2009-09-03 04:47:49 +04:00
|
|
|
//
|
|
|
|
// nsICanvasRenderingContextInternal
|
|
|
|
//
|
|
|
|
|
2018-06-28 23:09:16 +03:00
|
|
|
static bool
|
|
|
|
IsFeatureInBlacklist(const nsCOMPtr<nsIGfxInfo>& gfxInfo, int32_t feature,
|
|
|
|
nsCString* const out_blacklistId)
|
|
|
|
{
|
|
|
|
int32_t status;
|
|
|
|
if (!NS_SUCCEEDED(gfxUtils::ThreadSafeGetFeatureStatus(gfxInfo, feature,
|
|
|
|
*out_blacklistId, &status)))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status != nsIGfxInfo::FEATURE_STATUS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-17 07:33:03 +03:00
|
|
|
NS_IMETHODIMP
|
2015-10-18 14:14:22 +03:00
|
|
|
WebGLContext::SetContextOptions(JSContext* cx, JS::Handle<JS::Value> options,
|
|
|
|
ErrorResult& aRvForDictionaryInit)
|
2010-11-17 07:33:03 +03:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "getContext");
|
|
|
|
(void)IsContextLost(); // Ignore this.
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
if (options.isNullOrUndefined() && mOptionsFrozen)
|
2013-06-12 22:42:27 +04:00
|
|
|
return NS_OK;
|
2013-06-13 00:04:18 +04:00
|
|
|
|
2013-06-07 22:42:12 +04:00
|
|
|
WebGLContextAttributes attributes;
|
2015-10-18 14:14:22 +03:00
|
|
|
if (!attributes.Init(cx, options)) {
|
|
|
|
aRvForDictionaryInit.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2010-11-17 07:33:03 +03:00
|
|
|
|
|
|
|
WebGLContextOptions newOpts;
|
|
|
|
|
2013-06-07 22:42:12 +04:00
|
|
|
newOpts.stencil = attributes.mStencil;
|
|
|
|
newOpts.depth = attributes.mDepth;
|
|
|
|
newOpts.premultipliedAlpha = attributes.mPremultipliedAlpha;
|
|
|
|
newOpts.antialias = attributes.mAntialias;
|
|
|
|
newOpts.preserveDrawingBuffer = attributes.mPreserveDrawingBuffer;
|
2015-05-21 18:51:49 +03:00
|
|
|
newOpts.failIfMajorPerformanceCaveat = attributes.mFailIfMajorPerformanceCaveat;
|
2018-06-23 02:47:02 +03:00
|
|
|
newOpts.powerPreference = attributes.mPowerPreference;
|
2014-08-28 03:16:22 +04:00
|
|
|
|
2018-06-28 23:09:16 +03:00
|
|
|
if (attributes.mAlpha.WasPassed()) {
|
2014-08-28 03:16:22 +04:00
|
|
|
newOpts.alpha = attributes.mAlpha.Value();
|
2018-06-28 23:09:16 +03:00
|
|
|
}
|
2012-07-06 17:19:27 +04:00
|
|
|
|
2014-07-04 03:09:04 +04:00
|
|
|
// Don't do antialiasing if we've disabled MSAA.
|
2018-06-28 23:09:16 +03:00
|
|
|
if (!gfxPrefs::MSAALevel()) {
|
|
|
|
newOpts.antialias = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gfxPrefs::WebGLForceMSAA()) {
|
|
|
|
const nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
|
|
|
|
|
|
|
|
nsCString blocklistId;
|
|
|
|
if (IsFeatureInBlacklist(gfxInfo, nsIGfxInfo::FEATURE_WEBGL_MSAA, &blocklistId)) {
|
|
|
|
GenerateWarning("Disallowing antialiased backbuffers due to blacklisting.");
|
2018-09-06 23:17:26 +03:00
|
|
|
newOpts.antialias = false;
|
2018-06-28 23:09:16 +03:00
|
|
|
}
|
|
|
|
}
|
2014-07-04 03:09:04 +04:00
|
|
|
|
2010-12-04 01:44:01 +03:00
|
|
|
#if 0
|
2012-05-23 20:07:29 +04:00
|
|
|
GenerateWarning("aaHint: %d stencil: %d depth: %d alpha: %d premult: %d preserve: %d\n",
|
2011-05-20 23:53:53 +04:00
|
|
|
newOpts.antialias ? 1 : 0,
|
2010-11-17 07:33:03 +03:00
|
|
|
newOpts.stencil ? 1 : 0,
|
|
|
|
newOpts.depth ? 1 : 0,
|
|
|
|
newOpts.alpha ? 1 : 0,
|
2011-05-20 23:53:53 +04:00
|
|
|
newOpts.premultipliedAlpha ? 1 : 0,
|
|
|
|
newOpts.preserveDrawingBuffer ? 1 : 0);
|
2010-12-04 01:44:01 +03:00
|
|
|
#endif
|
2010-11-17 07:33:03 +03:00
|
|
|
|
2018-06-23 02:47:02 +03:00
|
|
|
if (mOptionsFrozen && !(newOpts == mOptions)) {
|
2010-11-17 07:33:03 +03:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2015-05-21 18:51:49 +03:00
|
|
|
static bool
|
|
|
|
HasAcceleratedLayers(const nsCOMPtr<nsIGfxInfo>& gfxInfo)
|
|
|
|
{
|
|
|
|
int32_t status;
|
|
|
|
|
2016-04-14 00:12:47 +03:00
|
|
|
nsCString discardFailureId;
|
2015-10-12 06:21:03 +03:00
|
|
|
gfxUtils::ThreadSafeGetFeatureStatus(gfxInfo,
|
|
|
|
nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS,
|
2016-04-14 00:12:47 +03:00
|
|
|
discardFailureId,
|
2015-10-12 06:21:03 +03:00
|
|
|
&status);
|
2015-05-21 18:51:49 +03:00
|
|
|
if (status)
|
|
|
|
return true;
|
2015-10-12 06:21:03 +03:00
|
|
|
gfxUtils::ThreadSafeGetFeatureStatus(gfxInfo,
|
|
|
|
nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS,
|
2016-04-14 00:12:47 +03:00
|
|
|
discardFailureId,
|
2015-10-12 06:21:03 +03:00
|
|
|
&status);
|
2015-05-21 18:51:49 +03:00
|
|
|
if (status)
|
|
|
|
return true;
|
2015-10-12 06:21:03 +03:00
|
|
|
gfxUtils::ThreadSafeGetFeatureStatus(gfxInfo,
|
|
|
|
nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS,
|
2016-04-14 00:12:47 +03:00
|
|
|
discardFailureId,
|
2015-10-12 06:21:03 +03:00
|
|
|
&status);
|
2015-05-21 18:51:49 +03:00
|
|
|
if (status)
|
|
|
|
return true;
|
2015-10-12 06:21:03 +03:00
|
|
|
gfxUtils::ThreadSafeGetFeatureStatus(gfxInfo,
|
|
|
|
nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS,
|
2016-04-14 00:12:47 +03:00
|
|
|
discardFailureId,
|
2015-10-12 06:21:03 +03:00
|
|
|
&status);
|
2015-05-21 18:51:49 +03:00
|
|
|
if (status)
|
|
|
|
return true;
|
2015-10-12 06:21:03 +03:00
|
|
|
gfxUtils::ThreadSafeGetFeatureStatus(gfxInfo,
|
|
|
|
nsIGfxInfo::FEATURE_OPENGL_LAYERS,
|
2016-04-14 00:12:47 +03:00
|
|
|
discardFailureId,
|
2015-10-12 06:21:03 +03:00
|
|
|
&status);
|
2015-05-21 18:51:49 +03:00
|
|
|
if (status)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-28 23:09:16 +03:00
|
|
|
// --
|
2014-08-28 03:16:22 +04:00
|
|
|
|
|
|
|
bool
|
2016-06-21 06:28:57 +03:00
|
|
|
WebGLContext::CreateAndInitGL(bool forceEnabled,
|
|
|
|
std::vector<FailureReason>* const out_failReasons)
|
2014-08-28 03:16:22 +04:00
|
|
|
{
|
2017-06-22 20:13:12 +03:00
|
|
|
// Can't use WebGL in headless mode.
|
|
|
|
if (gfxPlatform::IsHeadless()) {
|
|
|
|
FailureReason reason;
|
|
|
|
reason.info = "Can't use WebGL in headless mode (https://bugzil.la/1375585).";
|
|
|
|
out_failReasons->push_back(reason);
|
|
|
|
GenerateWarning("%s", reason.info.BeginReading());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-02 23:48:12 +03:00
|
|
|
// WebGL2 is separately blocked:
|
|
|
|
if (IsWebGL2()) {
|
|
|
|
const nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
|
|
|
|
const auto feature = nsIGfxInfo::FEATURE_WEBGL2;
|
|
|
|
|
|
|
|
FailureReason reason;
|
|
|
|
if (IsFeatureInBlacklist(gfxInfo, feature, &reason.key)) {
|
|
|
|
reason.info = "Refused to create WebGL2 context because of blacklist"
|
|
|
|
" entry: ";
|
|
|
|
reason.info.Append(reason.key);
|
|
|
|
out_failReasons->push_back(reason);
|
|
|
|
GenerateWarning("%s", reason.info.BeginReading());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-09 23:30:01 +03:00
|
|
|
gl::CreateContextFlags flags = (gl::CreateContextFlags::NO_VALIDATION |
|
|
|
|
gl::CreateContextFlags::PREFER_ROBUSTNESS);
|
2016-06-22 22:47:03 +03:00
|
|
|
bool tryNativeGL = true;
|
|
|
|
bool tryANGLE = false;
|
|
|
|
|
2016-06-21 06:43:06 +03:00
|
|
|
if (forceEnabled) {
|
2016-06-22 22:47:03 +03:00
|
|
|
flags |= gl::CreateContextFlags::FORCE_ENABLE_HARDWARE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsWebGL2()) {
|
|
|
|
flags |= gl::CreateContextFlags::PREFER_ES3;
|
2017-08-08 22:42:35 +03:00
|
|
|
} else if (!gfxPrefs::WebGL1AllowCoreProfile()) {
|
2016-06-22 22:47:03 +03:00
|
|
|
flags |= gl::CreateContextFlags::REQUIRE_COMPAT_PROFILE;
|
|
|
|
}
|
|
|
|
|
2018-06-23 02:47:02 +03:00
|
|
|
switch (mOptions.powerPreference) {
|
|
|
|
case dom::WebGLPowerPreference::Low_power:
|
|
|
|
break;
|
2018-07-27 07:46:33 +03:00
|
|
|
|
2018-06-23 02:47:02 +03:00
|
|
|
// Eventually add a heuristic, but for now default to high-performance.
|
|
|
|
// We can even make it dynamic by holding on to a ForceDiscreteGPUHelperCGL iff
|
|
|
|
// we decide it's a high-performance application:
|
|
|
|
// - Non-trivial canvas size
|
|
|
|
// - Many draw calls
|
|
|
|
// - Same origin with root page (try to stem bleeding from WebGL ads/trackers)
|
|
|
|
case dom::WebGLPowerPreference::High_performance:
|
|
|
|
default:
|
|
|
|
flags |= gl::CreateContextFlags::HIGH_POWER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-11-24 11:51:37 +03:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
const nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
|
|
|
|
nsString vendorID, deviceID;
|
|
|
|
|
|
|
|
// Avoid crash for Intel HD Graphics 3000 on OSX. (Bug 1413269)
|
|
|
|
gfxInfo->GetAdapterVendorID(vendorID);
|
|
|
|
gfxInfo->GetAdapterDeviceID(deviceID);
|
|
|
|
if (vendorID.EqualsLiteral("0x8086") &&
|
|
|
|
(deviceID.EqualsLiteral("0x0116") || deviceID.EqualsLiteral("0x0126")))
|
|
|
|
{
|
|
|
|
flags |= gl::CreateContextFlags::REQUIRE_COMPAT_PROFILE;
|
|
|
|
}
|
|
|
|
#endif
|
2018-06-28 23:09:16 +03:00
|
|
|
|
|
|
|
// --
|
|
|
|
|
|
|
|
const auto surfaceCaps = [&]() {
|
|
|
|
auto ret = gl::SurfaceCaps::ForRGBA();
|
|
|
|
ret.premultAlpha = mOptions.premultipliedAlpha;
|
|
|
|
ret.preserve = mOptions.preserveDrawingBuffer;
|
|
|
|
|
|
|
|
if (!mOptions.alpha) {
|
|
|
|
ret.premultAlpha = true;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}();
|
|
|
|
|
|
|
|
// --
|
2016-06-22 22:47:03 +03:00
|
|
|
|
|
|
|
const bool useEGL = PR_GetEnv("MOZ_WEBGL_FORCE_EGL");
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
2016-09-12 12:39:54 +03:00
|
|
|
tryNativeGL = false;
|
|
|
|
tryANGLE = true;
|
2016-06-22 22:47:03 +03:00
|
|
|
|
|
|
|
if (gfxPrefs::WebGLDisableWGL()) {
|
|
|
|
tryNativeGL = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gfxPrefs::WebGLDisableANGLE() || PR_GetEnv("MOZ_WEBGL_FORCE_OPENGL") || useEGL) {
|
|
|
|
tryNativeGL = true;
|
|
|
|
tryANGLE = false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (tryNativeGL && !forceEnabled) {
|
2016-06-21 06:28:57 +03:00
|
|
|
const nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
|
2016-06-21 06:43:06 +03:00
|
|
|
const auto feature = nsIGfxInfo::FEATURE_WEBGL_OPENGL;
|
2016-06-21 06:28:57 +03:00
|
|
|
|
2016-06-21 06:28:57 +03:00
|
|
|
FailureReason reason;
|
2016-06-21 06:43:06 +03:00
|
|
|
if (IsFeatureInBlacklist(gfxInfo, feature, &reason.key)) {
|
2016-06-21 06:28:57 +03:00
|
|
|
reason.info = "Refused to create native OpenGL context because of blacklist"
|
|
|
|
" entry: ";
|
2016-06-21 06:42:10 +03:00
|
|
|
reason.info.Append(reason.key);
|
2016-06-21 06:28:57 +03:00
|
|
|
|
|
|
|
out_failReasons->push_back(reason);
|
|
|
|
|
2016-12-10 02:48:22 +03:00
|
|
|
GenerateWarning("%s", reason.info.BeginReading());
|
2016-06-22 22:47:03 +03:00
|
|
|
tryNativeGL = false;
|
2016-06-21 06:28:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-28 23:09:16 +03:00
|
|
|
// --
|
2014-08-28 03:16:22 +04:00
|
|
|
|
2018-06-28 23:09:16 +03:00
|
|
|
typedef decltype(gl::GLContextProviderEGL::CreateOffscreen) fnCreateOffscreenT;
|
|
|
|
const auto fnCreate = [&](fnCreateOffscreenT* const pfnCreateOffscreen,
|
|
|
|
const char* const info)
|
|
|
|
{
|
|
|
|
const gfx::IntSize dummySize(1, 1);
|
|
|
|
nsCString failureId;
|
2018-04-05 03:11:42 +03:00
|
|
|
RefPtr<GLContext> gl = pfnCreateOffscreen(dummySize, surfaceCaps, flags,
|
|
|
|
&failureId);
|
|
|
|
if (gl && gl->IsCoreProfile() &&
|
|
|
|
!(flags & gl::CreateContextFlags::REQUIRE_COMPAT_PROFILE) &&
|
|
|
|
!gl->IsSupported(gl::GLFeature::gpu_shader5))
|
|
|
|
{
|
|
|
|
// See comment on "constant-index-expression" in WebGLShaderValidator.cpp.
|
|
|
|
const auto compatFlags = flags | gl::CreateContextFlags::REQUIRE_COMPAT_PROFILE;
|
|
|
|
gl = pfnCreateOffscreen(dummySize, surfaceCaps, compatFlags, &failureId);
|
|
|
|
}
|
2018-06-28 23:09:16 +03:00
|
|
|
if (!gl) {
|
|
|
|
out_failReasons->push_back(WebGLContext::FailureReason(failureId, info));
|
|
|
|
}
|
|
|
|
return gl;
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto newGL = [&]() -> RefPtr<gl::GLContext> {
|
|
|
|
if (tryNativeGL) {
|
|
|
|
if (useEGL)
|
|
|
|
return fnCreate(&gl::GLContextProviderEGL::CreateOffscreen, "useEGL");
|
|
|
|
|
|
|
|
const auto ret = fnCreate(&gl::GLContextProvider::CreateOffscreen,
|
|
|
|
"tryNativeGL");
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2016-06-21 06:28:57 +03:00
|
|
|
|
2018-06-28 23:09:16 +03:00
|
|
|
if (tryANGLE) {
|
|
|
|
// Force enable alpha channel to make sure ANGLE use correct framebuffer format
|
|
|
|
MOZ_ASSERT(surfaceCaps.alpha);
|
|
|
|
return fnCreate(&gl::GLContextProviderEGL::CreateOffscreen, "tryANGLE");
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}();
|
|
|
|
|
|
|
|
if (!newGL) {
|
|
|
|
out_failReasons->push_back(FailureReason("FEATURE_FAILURE_WEBGL_EXHAUSTED_DRIVERS",
|
|
|
|
"Exhausted GL driver options."));
|
|
|
|
return false;
|
2016-06-21 06:28:57 +03:00
|
|
|
}
|
|
|
|
|
2018-06-28 23:09:16 +03:00
|
|
|
// --
|
2016-06-21 06:28:57 +03:00
|
|
|
|
2018-06-28 23:09:16 +03:00
|
|
|
FailureReason reason;
|
2016-06-21 06:28:57 +03:00
|
|
|
|
2018-06-28 23:09:16 +03:00
|
|
|
mGL_OnlyClearInDestroyResourcesAndContext = newGL;
|
|
|
|
MOZ_RELEASE_ASSERT(gl);
|
|
|
|
if (!InitAndValidateGL(&reason)) {
|
|
|
|
DestroyResourcesAndContext();
|
|
|
|
MOZ_RELEASE_ASSERT(!gl);
|
2016-06-21 06:28:57 +03:00
|
|
|
|
2018-06-28 23:09:16 +03:00
|
|
|
// The fail reason here should be specific enough for now.
|
|
|
|
out_failReasons->push_back(reason);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2014-08-28 03:16:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fallback for resizes:
|
2017-12-19 05:30:56 +03:00
|
|
|
|
2014-08-28 03:16:22 +04:00
|
|
|
bool
|
2018-07-27 07:46:33 +03:00
|
|
|
WebGLContext::EnsureDefaultFB()
|
2014-08-28 03:16:22 +04:00
|
|
|
{
|
2017-12-19 05:30:56 +03:00
|
|
|
if (mDefaultFB) {
|
|
|
|
MOZ_ASSERT(mDefaultFB->mSize == mRequestedSize);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool depthStencil = mOptions.depth || mOptions.stencil;
|
|
|
|
auto attemptSize = mRequestedSize;
|
2014-08-28 03:16:22 +04:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
while (attemptSize.width || attemptSize.height) {
|
|
|
|
attemptSize.width = std::max(attemptSize.width, 1);
|
|
|
|
attemptSize.height = std::max(attemptSize.height, 1);
|
|
|
|
|
|
|
|
[&]() {
|
|
|
|
if (mOptions.antialias) {
|
|
|
|
MOZ_ASSERT(!mDefaultFB);
|
|
|
|
mDefaultFB = MozFramebuffer::Create(gl, attemptSize, mMsaaSamples,
|
|
|
|
depthStencil);
|
|
|
|
if (mDefaultFB)
|
|
|
|
return;
|
|
|
|
if (mOptionsFrozen)
|
|
|
|
return;
|
|
|
|
}
|
2014-08-28 03:16:22 +04:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
MOZ_ASSERT(!mDefaultFB);
|
|
|
|
mDefaultFB = MozFramebuffer::Create(gl, attemptSize, 0, depthStencil);
|
|
|
|
}();
|
2014-08-28 03:16:22 +04:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
if (mDefaultFB)
|
|
|
|
break;
|
|
|
|
|
|
|
|
attemptSize.width /= 2;
|
|
|
|
attemptSize.height /= 2;
|
2014-08-28 03:16:22 +04:00
|
|
|
}
|
|
|
|
|
2017-12-22 04:14:54 +03:00
|
|
|
if (!mDefaultFB) {
|
2018-07-27 07:46:33 +03:00
|
|
|
GenerateWarning("Backbuffer resize failed. Losing context.");
|
2017-12-22 04:14:54 +03:00
|
|
|
ForceLoseContext();
|
2014-08-28 03:16:22 +04:00
|
|
|
return false;
|
2017-12-22 04:14:54 +03:00
|
|
|
}
|
2014-08-28 03:16:22 +04:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
mDefaultFB_IsInvalid = true;
|
2014-08-28 03:16:22 +04:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
if (mDefaultFB->mSize != mRequestedSize) {
|
2014-08-28 03:16:22 +04:00
|
|
|
GenerateWarning("Requested size %dx%d was too large, but resize"
|
|
|
|
" to %dx%d succeeded.",
|
2017-12-19 05:30:56 +03:00
|
|
|
mRequestedSize.width, mRequestedSize.height,
|
|
|
|
mDefaultFB->mSize.width, mDefaultFB->mSize.height);
|
2014-08-28 03:16:22 +04:00
|
|
|
}
|
2017-12-22 04:14:54 +03:00
|
|
|
mRequestedSize = mDefaultFB->mSize;
|
2014-08-28 03:16:22 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-12 02:45:43 +03:00
|
|
|
void
|
|
|
|
WebGLContext::ThrowEvent_WebGLContextCreationError(const nsACString& text)
|
|
|
|
{
|
|
|
|
RefPtr<EventTarget> target = mCanvasElement;
|
2016-09-30 10:29:34 +03:00
|
|
|
if (!target && mOffscreenCanvas) {
|
2016-05-12 02:45:43 +03:00
|
|
|
target = mOffscreenCanvas;
|
2016-09-30 10:29:34 +03:00
|
|
|
} else if (!target) {
|
|
|
|
GenerateWarning("Failed to create WebGL context: %s", text.BeginReading());
|
|
|
|
return;
|
2016-05-12 02:45:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto kEventName = NS_LITERAL_STRING("webglcontextcreationerror");
|
|
|
|
|
|
|
|
WebGLContextEventInit eventInit;
|
|
|
|
// eventInit.mCancelable = true; // The spec says this, but it's silly.
|
|
|
|
eventInit.mStatusMessage = NS_ConvertASCIItoUTF16(text);
|
|
|
|
|
|
|
|
const RefPtr<WebGLContextEvent> event = WebGLContextEvent::Constructor(target,
|
|
|
|
kEventName,
|
|
|
|
eventInit);
|
|
|
|
event->SetTrusted(true);
|
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
target->DispatchEvent(*event);
|
2016-05-12 02:45:43 +03:00
|
|
|
|
|
|
|
//////
|
|
|
|
|
|
|
|
GenerateWarning("Failed to create WebGL context: %s", text.BeginReading());
|
|
|
|
}
|
|
|
|
|
2009-09-03 04:47:49 +04:00
|
|
|
NS_IMETHODIMP
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::SetDimensions(int32_t signedWidth, int32_t signedHeight)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "<SetDimensions>");
|
|
|
|
(void)IsContextLost(); // We handle this ourselves.
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
if (signedWidth < 0 || signedHeight < 0) {
|
2016-07-22 20:26:05 +03:00
|
|
|
if (!gl) {
|
|
|
|
Telemetry::Accumulate(Telemetry::CANVAS_WEBGL_FAILURE_ID,
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_WEBGL_SIZE"));
|
|
|
|
}
|
2012-09-27 18:13:45 +04:00
|
|
|
GenerateWarning("Canvas size is too large (seems like a negative value wrapped)");
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2012-08-03 01:28:02 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
uint32_t width = signedWidth;
|
|
|
|
uint32_t height = signedHeight;
|
2012-09-27 18:13:44 +04:00
|
|
|
|
2015-07-02 02:19:09 +03:00
|
|
|
// Early success return cases
|
2015-10-12 06:21:03 +03:00
|
|
|
|
|
|
|
// May have a OffscreenCanvas instead of an HTMLCanvasElement
|
|
|
|
if (GetCanvas())
|
|
|
|
GetCanvas()->InvalidateCanvas();
|
2011-03-28 03:59:47 +04:00
|
|
|
|
2011-05-19 14:49:18 +04:00
|
|
|
// Zero-sized surfaces can cause problems.
|
2014-11-14 07:03:50 +03:00
|
|
|
if (width == 0)
|
2011-05-19 14:49:18 +04:00
|
|
|
width = 1;
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
if (height == 0)
|
2011-05-19 14:49:18 +04:00
|
|
|
height = 1;
|
|
|
|
|
2011-10-19 23:09:57 +04:00
|
|
|
// If we already have a gl context, then we just need to resize it
|
|
|
|
if (gl) {
|
2017-12-19 05:30:56 +03:00
|
|
|
if (uint32_t(mRequestedSize.width) == width &&
|
|
|
|
uint32_t(mRequestedSize.height) == height)
|
2014-08-28 03:16:22 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsContextLost())
|
|
|
|
return NS_OK;
|
|
|
|
|
2013-10-31 17:52:24 +04:00
|
|
|
// If we've already drawn, we should commit the current buffer.
|
2018-08-24 18:32:12 +03:00
|
|
|
PresentScreenBuffer(gl->Screen());
|
2013-10-31 17:52:24 +04:00
|
|
|
|
2015-03-19 05:55:44 +03:00
|
|
|
if (IsContextLost()) {
|
|
|
|
GenerateWarning("WebGL context was lost due to swap failure.");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
// Kill our current default fb(s), for later lazy allocation.
|
|
|
|
mRequestedSize = {width, height};
|
|
|
|
mDefaultFB = nullptr;
|
2011-10-19 23:09:57 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mResetLayer = true;
|
2010-07-19 09:01:14 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-06-10 02:07:12 +04:00
|
|
|
|
2016-07-22 20:26:05 +03:00
|
|
|
nsCString failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_WEBGL_UNKOWN");
|
|
|
|
auto autoTelemetry = mozilla::MakeScopeExit([&] {
|
|
|
|
Telemetry::Accumulate(Telemetry::CANVAS_WEBGL_FAILURE_ID,
|
|
|
|
failureId);
|
|
|
|
});
|
|
|
|
|
2012-09-27 18:13:45 +04: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 23:02:06 +04:00
|
|
|
|
2012-08-03 01:28:02 +04: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 23:02:06 +04:00
|
|
|
|
2010-07-19 09:01:14 +04: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-10 02:07:12 +04:00
|
|
|
|
2010-07-19 09:01:14 +04: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.
|
2014-08-28 03:16:22 +04:00
|
|
|
if (!(mGeneration + 1).isValid()) {
|
2016-05-12 02:45:43 +03:00
|
|
|
// exit without changing the value of mGeneration
|
2016-07-22 20:26:05 +03:00
|
|
|
failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_WEBGL_TOO_MANY");
|
2016-05-12 02:45:43 +03:00
|
|
|
const nsLiteralCString text("Too many WebGL contexts created this run.");
|
|
|
|
ThrowEvent_WebGLContextCreationError(text);
|
|
|
|
return NS_ERROR_FAILURE;
|
2013-05-27 18:12:13 +04:00
|
|
|
}
|
|
|
|
|
2015-07-21 07:38:52 +03:00
|
|
|
// increment the generation number - Do this early because later
|
|
|
|
// in CreateOffscreenGL(), "default" objects are created that will
|
|
|
|
// pick up the old generation.
|
|
|
|
++mGeneration;
|
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
bool disabled = gfxPrefs::WebGLDisabled();
|
2015-06-16 00:05:02 +03:00
|
|
|
|
|
|
|
// TODO: When we have software webgl support we should use that instead.
|
|
|
|
disabled |= gfxPlatform::InSafeMode();
|
|
|
|
|
2014-08-28 03:16:22 +04:00
|
|
|
if (disabled) {
|
2016-07-29 21:28:51 +03:00
|
|
|
if (gfxPlatform::InSafeMode()) {
|
|
|
|
failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_WEBGL_SAFEMODE");
|
|
|
|
} else {
|
|
|
|
failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_WEBGL_DISABLED");
|
|
|
|
}
|
2016-05-12 02:45:43 +03:00
|
|
|
const nsLiteralCString text("WebGL is currently disabled.");
|
|
|
|
ThrowEvent_WebGLContextCreationError(text);
|
2014-08-28 03:16:22 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2014-08-27 13:15:40 +04:00
|
|
|
}
|
|
|
|
|
2016-05-25 23:18:00 +03:00
|
|
|
if (gfxPrefs::WebGLDisableFailIfMajorPerformanceCaveat()) {
|
|
|
|
mOptions.failIfMajorPerformanceCaveat = false;
|
|
|
|
}
|
2016-05-12 02:45:43 +03:00
|
|
|
|
2016-05-25 23:18:00 +03:00
|
|
|
if (mOptions.failIfMajorPerformanceCaveat) {
|
2016-05-12 02:45:43 +03:00
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
|
|
|
|
if (!HasAcceleratedLayers(gfxInfo)) {
|
2016-07-22 20:26:05 +03:00
|
|
|
failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_WEBGL_PERF_CAVEAT");
|
2016-05-12 02:45:43 +03:00
|
|
|
const nsLiteralCString text("failIfMajorPerformanceCaveat: Compositor is not"
|
|
|
|
" hardware-accelerated.");
|
|
|
|
ThrowEvent_WebGLContextCreationError(text);
|
2015-05-21 18:51:49 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-28 03:16:22 +04:00
|
|
|
// Alright, now let's start trying.
|
2015-10-12 06:21:03 +03:00
|
|
|
bool forceEnabled = gfxPrefs::WebGLForceEnabled();
|
2014-08-28 03:16:22 +04:00
|
|
|
ScopedGfxFeatureReporter reporter("WebGL", forceEnabled);
|
2014-08-27 13:15:40 +04:00
|
|
|
|
2015-09-24 22:21:05 +03:00
|
|
|
MOZ_ASSERT(!gl);
|
2016-06-21 06:28:57 +03:00
|
|
|
std::vector<FailureReason> failReasons;
|
|
|
|
if (!CreateAndInitGL(forceEnabled, &failReasons)) {
|
|
|
|
nsCString text("WebGL creation failed: ");
|
|
|
|
for (const auto& cur : failReasons) {
|
2017-04-18 12:57:53 +03:00
|
|
|
// Don't try to accumulate using an empty key if |cur.key| is empty.
|
|
|
|
if (cur.key.IsEmpty()) {
|
|
|
|
Telemetry::Accumulate(Telemetry::CANVAS_WEBGL_FAILURE_ID,
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_REASON_UNKNOWN"));
|
|
|
|
} else {
|
|
|
|
Telemetry::Accumulate(Telemetry::CANVAS_WEBGL_FAILURE_ID, cur.key);
|
|
|
|
}
|
2016-06-21 06:28:57 +03:00
|
|
|
|
2018-09-08 01:12:04 +03:00
|
|
|
text.AppendLiteral("\n* ");
|
2016-06-21 06:28:57 +03:00
|
|
|
text.Append(cur.info);
|
|
|
|
}
|
2016-07-22 20:26:05 +03:00
|
|
|
failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_REASON");
|
2016-05-12 02:45:43 +03:00
|
|
|
ThrowEvent_WebGLContextCreationError(text);
|
2014-08-28 03:16:22 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2014-08-27 13:15:40 +04:00
|
|
|
}
|
2014-08-28 03:16:22 +04:00
|
|
|
MOZ_ASSERT(gl);
|
2015-09-24 22:21:05 +03:00
|
|
|
|
2016-05-25 23:18:00 +03:00
|
|
|
if (mOptions.failIfMajorPerformanceCaveat) {
|
|
|
|
if (gl->IsWARP()) {
|
2016-07-21 11:12:15 +03:00
|
|
|
DestroyResourcesAndContext();
|
|
|
|
MOZ_ASSERT(!gl);
|
2016-06-21 06:38:47 +03:00
|
|
|
|
2016-07-22 20:26:05 +03:00
|
|
|
failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_WEBGL_PERF_WARP");
|
2016-05-25 23:18:00 +03:00
|
|
|
const nsLiteralCString text("failIfMajorPerformanceCaveat: Driver is not"
|
|
|
|
" hardware-accelerated.");
|
|
|
|
ThrowEvent_WebGLContextCreationError(text);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2016-06-21 06:38:47 +03:00
|
|
|
|
2016-06-22 04:02:07 +03:00
|
|
|
#ifdef XP_WIN
|
2016-06-21 06:38:47 +03:00
|
|
|
if (gl->GetContextType() == gl::GLContextType::WGL &&
|
|
|
|
!gl::sWGLLib.HasDXInterop2())
|
|
|
|
{
|
2016-07-21 11:12:15 +03:00
|
|
|
DestroyResourcesAndContext();
|
|
|
|
MOZ_ASSERT(!gl);
|
2016-06-21 06:38:47 +03:00
|
|
|
|
2016-07-22 20:26:05 +03:00
|
|
|
failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_WEBGL_DXGL_INTEROP2");
|
2016-06-21 06:38:47 +03:00
|
|
|
const nsLiteralCString text("Caveat: WGL without DXGLInterop2.");
|
|
|
|
ThrowEvent_WebGLContextCreationError(text);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2016-06-22 04:02:07 +03:00
|
|
|
#endif
|
2016-05-25 23:18:00 +03:00
|
|
|
}
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
MOZ_ASSERT(!mDefaultFB);
|
|
|
|
mRequestedSize = {width, height};
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!EnsureDefaultFB()) {
|
2017-12-22 04:14:54 +03:00
|
|
|
MOZ_ASSERT(!gl);
|
|
|
|
|
2016-07-22 20:26:05 +03:00
|
|
|
failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_WEBGL_BACKBUFFER");
|
2016-05-12 02:45:43 +03:00
|
|
|
const nsLiteralCString text("Initializing WebGL backbuffer failed.");
|
|
|
|
ThrowEvent_WebGLContextCreationError(text);
|
2010-08-07 09:09:18 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-06-07 02:29:08 +03:00
|
|
|
if (GLContext::ShouldSpew()) {
|
2012-06-11 19:25:06 +04:00
|
|
|
printf_stderr("--- WebGL context created: %p\n", gl.get());
|
2016-06-07 02:29:08 +03:00
|
|
|
}
|
2010-08-07 09:09:18 +04:00
|
|
|
|
2014-10-09 03:37:30 +04:00
|
|
|
// Update our internal stuff:
|
2018-06-28 23:09:16 +03:00
|
|
|
|
|
|
|
mOptions.antialias &= bool(mDefaultFB->mSamples);
|
2015-03-12 04:23:56 +03:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
if (!mOptions.alpha) {
|
|
|
|
// We always have alpha.
|
|
|
|
mNeedsFakeNoAlpha = true;
|
|
|
|
}
|
2015-09-24 22:21:05 +03:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
if (mOptions.depth || mOptions.stencil) {
|
|
|
|
// We always have depth+stencil if we have either.
|
|
|
|
if (!mOptions.depth) {
|
|
|
|
mNeedsFakeNoDepth = true;
|
|
|
|
}
|
|
|
|
if (!mOptions.stencil) {
|
2015-03-12 04:23:56 +03:00
|
|
|
mNeedsFakeNoStencil = true;
|
2016-02-19 04:59:24 +03:00
|
|
|
}
|
2014-10-09 03:37:30 +04:00
|
|
|
}
|
2014-08-28 03:16:22 +04:00
|
|
|
|
2017-12-22 14:42:04 +03:00
|
|
|
mNeedsFakeNoStencil_UserFBs = false;
|
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
|
|
|
if (!nsCocoaFeatures::IsAtLeastVersion(10, 12) &&
|
|
|
|
gl->Vendor() == GLVendor::Intel)
|
|
|
|
{
|
|
|
|
mNeedsFakeNoStencil_UserFBs = true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
mResetLayer = true;
|
|
|
|
mOptionsFrozen = true;
|
2014-10-23 01:17:02 +04:00
|
|
|
|
2016-06-01 00:44:46 +03:00
|
|
|
//////
|
|
|
|
// Initial setup.
|
|
|
|
|
2017-08-11 04:01:04 +03:00
|
|
|
gl->mImplicitMakeCurrent = true;
|
2014-10-09 03:37:30 +04:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
const auto& size = mDefaultFB->mSize;
|
|
|
|
|
2017-01-10 22:15:00 +03:00
|
|
|
mViewportX = mViewportY = 0;
|
2017-12-19 05:30:56 +03:00
|
|
|
mViewportWidth = size.width;
|
|
|
|
mViewportHeight = size.height;
|
|
|
|
gl->fViewport(mViewportX, mViewportY, mViewportWidth, mViewportHeight);
|
2014-10-09 03:37:30 +04:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
gl->fScissor(0, 0, size.width, size.height);
|
2011-12-20 03:47:54 +04:00
|
|
|
|
2016-06-01 00:44:46 +03:00
|
|
|
//////
|
|
|
|
// Check everything
|
2015-07-02 02:19:09 +03:00
|
|
|
|
2016-06-01 00:44:46 +03:00
|
|
|
AssertCachedBindings();
|
|
|
|
AssertCachedGlobalState();
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2016-06-01 00:44:46 +03:00
|
|
|
mShouldPresent = true;
|
|
|
|
|
|
|
|
//////
|
2014-05-22 06:03:09 +04:00
|
|
|
|
2011-03-02 23:50:36 +03:00
|
|
|
reporter.SetSuccessful();
|
2016-05-20 20:14:15 +03:00
|
|
|
|
2016-07-22 20:26:05 +03:00
|
|
|
failureId = NS_LITERAL_CSTRING("SUCCESS");
|
2017-07-13 21:26:00 +03:00
|
|
|
|
|
|
|
gl->ResetSyncCallCount("WebGLContext Initialization");
|
2009-09-03 04:47:49 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
void
|
|
|
|
WebGLContext::LoseOldestWebGLContextIfLimitExceeded()
|
2012-08-03 01:28:02 +04:00
|
|
|
{
|
2018-01-03 14:12:29 +03:00
|
|
|
const auto maxWebGLContexts = gfxPrefs::WebGLMaxContexts();
|
|
|
|
auto maxWebGLContextsPerPrincipal = gfxPrefs::WebGLMaxContextsPerPrincipal();
|
2017-11-30 14:40:57 +03:00
|
|
|
|
|
|
|
// maxWebGLContextsPerPrincipal must be less than maxWebGLContexts
|
2018-01-03 14:12:29 +03:00
|
|
|
MOZ_ASSERT(maxWebGLContextsPerPrincipal <= maxWebGLContexts);
|
|
|
|
maxWebGLContextsPerPrincipal = std::min(maxWebGLContextsPerPrincipal, maxWebGLContexts);
|
2012-08-03 01:28:02 +04:00
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
// XXX mtseng: bug 709490, WebGLMemoryTracker is not thread safe.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-03 01:28:02 +04:00
|
|
|
// 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();
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLMemoryTracker::ContextsArrayType& contexts = WebGLMemoryTracker::Contexts();
|
2012-08-03 01:28:02 +04:00
|
|
|
|
|
|
|
// quick exit path, should cover a majority of cases
|
2017-11-30 14:40:57 +03:00
|
|
|
if (contexts.Length() <= maxWebGLContextsPerPrincipal)
|
2012-08-03 01:28:02 +04:00
|
|
|
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;
|
2014-11-14 07:03:50 +03:00
|
|
|
const WebGLContext* oldestContext = nullptr;
|
|
|
|
const WebGLContext* oldestContextThisPrincipal = nullptr;
|
2012-08-03 01:28:02 +04: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;
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!contexts[i]->gl)
|
2012-08-03 01:28:02 +04:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
nsIPrincipal* ourPrincipal = GetCanvas()->NodePrincipal();
|
|
|
|
nsIPrincipal* theirPrincipal = contexts[i]->GetCanvas()->NodePrincipal();
|
2012-08-03 01:28:02 +04:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-30 14:40:57 +03:00
|
|
|
if (numContextsThisPrincipal > maxWebGLContextsPerPrincipal) {
|
2018-01-03 14:12:29 +03:00
|
|
|
GenerateWarning("Exceeded %u live WebGL contexts for this principal, losing the "
|
2017-11-30 14:40:57 +03:00
|
|
|
"least recently used one.", maxWebGLContextsPerPrincipal);
|
2012-08-03 01:28:02 +04:00
|
|
|
MOZ_ASSERT(oldestContextThisPrincipal); // if we reach this point, this can't be null
|
|
|
|
const_cast<WebGLContext*>(oldestContextThisPrincipal)->LoseContext();
|
2017-11-30 14:40:57 +03:00
|
|
|
} else if (numContexts > maxWebGLContexts) {
|
2018-01-03 14:12:29 +03:00
|
|
|
GenerateWarning("Exceeded %u live WebGL contexts, losing the least "
|
2017-11-30 14:40:57 +03:00
|
|
|
"recently used one.", maxWebGLContexts);
|
2012-08-03 01:28:02 +04:00
|
|
|
MOZ_ASSERT(oldestContext); // if we reach this point, this can't be null
|
|
|
|
const_cast<WebGLContext*>(oldestContext)->LoseContext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-26 21:31:12 +03:00
|
|
|
UniquePtr<uint8_t[]>
|
|
|
|
WebGLContext::GetImageBuffer(int32_t* out_format)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2014-11-14 07:03:50 +03:00
|
|
|
*out_format = 0;
|
2013-09-09 18:56:00 +04:00
|
|
|
|
2014-04-17 09:31:44 +04:00
|
|
|
// Use GetSurfaceSnapshot() to make sure that appropriate y-flip gets applied
|
2017-04-12 12:55:23 +03:00
|
|
|
gfxAlphaType any;
|
|
|
|
RefPtr<SourceSurface> snapshot = GetSurfaceSnapshot(&any);
|
|
|
|
if (!snapshot)
|
2015-10-26 21:31:12 +03:00
|
|
|
return nullptr;
|
2013-10-08 23:00:17 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DataSourceSurface> dataSurface = snapshot->GetDataSurface();
|
2014-04-17 09:31:44 +04:00
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
return gfxUtils::GetImageBuffer(dataSurface, mOptions.premultipliedAlpha,
|
2015-10-26 21:31:12 +03:00
|
|
|
out_format);
|
2013-10-17 06:55:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::GetInputStream(const char* mimeType,
|
|
|
|
const char16_t* encoderOptions,
|
|
|
|
nsIInputStream** out_stream)
|
2013-10-17 06:55:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(gl, "GetInputStream on invalid context?");
|
|
|
|
if (!gl)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
// Use GetSurfaceSnapshot() to make sure that appropriate y-flip gets applied
|
2017-04-12 12:55:23 +03:00
|
|
|
gfxAlphaType any;
|
|
|
|
RefPtr<SourceSurface> snapshot = GetSurfaceSnapshot(&any);
|
2015-10-12 06:21:03 +03:00
|
|
|
if (!snapshot)
|
2013-10-17 06:55:08 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DataSourceSurface> dataSurface = snapshot->GetDataSurface();
|
2015-10-12 06:21:03 +03:00
|
|
|
return gfxUtils::GetInputStream(dataSurface, mOptions.premultipliedAlpha, mimeType,
|
|
|
|
encoderOptions, out_stream);
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
void
|
|
|
|
WebGLContext::UpdateLastUseIndex()
|
2012-08-03 01:28:02 +04:00
|
|
|
{
|
|
|
|
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.
|
2014-11-14 07:03:50 +03:00
|
|
|
if (!sIndex.isValid())
|
2016-12-03 00:46:53 +03:00
|
|
|
MOZ_CRASH("Can't believe it's been 2^64 transactions already!");
|
2012-08-03 01:28:02 +04:00
|
|
|
mLastUseIndex = sIndex.value();
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint8_t gWebGLLayerUserData;
|
2010-07-16 01:07:46 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
class WebGLContextUserData : public LayerUserData
|
|
|
|
{
|
2011-03-28 03:59:47 +04:00
|
|
|
public:
|
2014-11-14 07:03:50 +03:00
|
|
|
explicit WebGLContextUserData(HTMLCanvasElement* canvas)
|
|
|
|
: mCanvas(canvas)
|
2013-02-14 03:26:24 +04:00
|
|
|
{}
|
2011-11-01 01:14:12 +04:00
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
/* PreTransactionCallback gets called by the Layers code every time the
|
|
|
|
* WebGL canvas is going to be composited.
|
|
|
|
*/
|
2014-11-14 07:03:50 +03:00
|
|
|
static void PreTransactionCallback(void* data) {
|
2017-08-03 08:55:14 +03:00
|
|
|
WebGLContext* webgl = static_cast<WebGLContext*>(data);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2016-08-20 00:44:37 +03:00
|
|
|
// Prepare the context for composition
|
|
|
|
webgl->BeginComposition();
|
2013-02-14 03:26:24 +04: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
|
|
|
|
*/
|
2014-11-14 07:03:50 +03:00
|
|
|
static void DidTransactionCallback(void* data) {
|
2017-08-03 08:55:14 +03:00
|
|
|
WebGLContext* webgl = static_cast<WebGLContext*>(data);
|
2011-11-01 01:14:12 +04:00
|
|
|
|
2016-08-20 00:44:37 +03:00
|
|
|
// Clean up the context after composition
|
|
|
|
webgl->EndComposition();
|
2013-02-14 03:26:24 +04:00
|
|
|
}
|
2011-03-28 03:59:47 +04:00
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HTMLCanvasElement> mCanvas;
|
2011-03-28 03:59:47 +04:00
|
|
|
};
|
|
|
|
|
2015-12-18 09:52:17 +03:00
|
|
|
already_AddRefed<layers::Layer>
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::GetCanvasLayer(nsDisplayListBuilder* builder,
|
2015-12-18 09:52:17 +03:00
|
|
|
Layer* oldLayer,
|
2017-08-29 00:50:14 +03:00
|
|
|
LayerManager* manager)
|
2010-05-18 08:04:22 +04:00
|
|
|
{
|
2014-11-14 07:03:50 +03:00
|
|
|
if (!mResetLayer && oldLayer &&
|
2017-08-29 00:50:14 +03:00
|
|
|
oldLayer->HasUserData(&gWebGLLayerUserData))
|
|
|
|
{
|
2015-12-18 09:52:17 +03:00
|
|
|
RefPtr<layers::Layer> ret = oldLayer;
|
2013-04-22 15:15:59 +04:00
|
|
|
return ret.forget();
|
2010-07-16 01:07:46 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<CanvasLayer> canvasLayer = manager->CreateCanvasLayer();
|
2010-05-18 08:04:22 +04:00
|
|
|
if (!canvasLayer) {
|
|
|
|
NS_WARNING("CreateCanvasLayer returned null!");
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
WebGLContextUserData* userData = nullptr;
|
2017-08-29 00:50:14 +03:00
|
|
|
if (builder->IsPaintingToWindow() && mCanvasElement) {
|
2017-08-03 08:55:14 +03:00
|
|
|
userData = new WebGLContextUserData(mCanvasElement);
|
|
|
|
}
|
|
|
|
|
2017-08-29 00:50:14 +03:00
|
|
|
canvasLayer->SetUserData(&gWebGLLayerUserData, userData);
|
2017-08-03 08:55:14 +03:00
|
|
|
|
|
|
|
CanvasRenderer* canvasRenderer = canvasLayer->CreateOrGetCanvasRenderer();
|
2017-08-29 00:50:14 +03:00
|
|
|
if (!InitializeCanvasRenderer(builder, canvasRenderer))
|
2017-08-18 10:13:29 +03:00
|
|
|
return nullptr;
|
|
|
|
|
2017-08-03 08:55:14 +03:00
|
|
|
uint32_t flags = gl->Caps().alpha ? 0 : Layer::CONTENT_OPAQUE;
|
|
|
|
canvasLayer->SetContentFlags(flags);
|
|
|
|
|
|
|
|
mResetLayer = false;
|
|
|
|
|
|
|
|
return canvasLayer.forget();
|
|
|
|
}
|
|
|
|
|
2017-10-28 13:07:27 +03:00
|
|
|
bool
|
|
|
|
WebGLContext::UpdateWebRenderCanvasData(nsDisplayListBuilder* aBuilder,
|
|
|
|
WebRenderCanvasData* aCanvasData)
|
|
|
|
{
|
|
|
|
CanvasRenderer* renderer = aCanvasData->GetCanvasRenderer();
|
|
|
|
|
|
|
|
if(!mResetLayer && renderer) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderer = aCanvasData->CreateCanvasRenderer();
|
|
|
|
if (!InitializeCanvasRenderer(aBuilder, renderer)) {
|
|
|
|
// Clear CanvasRenderer of WebRenderCanvasData
|
|
|
|
aCanvasData->ClearCanvasRenderer();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(renderer);
|
|
|
|
mResetLayer = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-18 10:13:29 +03:00
|
|
|
bool
|
2017-08-03 08:55:14 +03:00
|
|
|
WebGLContext::InitializeCanvasRenderer(nsDisplayListBuilder* aBuilder,
|
2017-08-29 00:50:14 +03:00
|
|
|
CanvasRenderer* aRenderer)
|
2017-08-03 08:55:14 +03:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "<InitializeCanvasRenderer>");
|
2017-08-18 10:13:29 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return false;
|
|
|
|
|
2017-08-03 08:55:14 +03:00
|
|
|
CanvasInitializeData data;
|
2017-08-29 00:50:14 +03:00
|
|
|
if (aBuilder->IsPaintingToWindow() && mCanvasElement) {
|
2015-10-12 06:21:03 +03:00
|
|
|
// 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.
|
2017-08-03 08:55:14 +03:00
|
|
|
data.mPreTransCallback = WebGLContextUserData::PreTransactionCallback;
|
|
|
|
data.mPreTransCallbackData = this;
|
|
|
|
data.mDidTransCallback = WebGLContextUserData::DidTransactionCallback;
|
|
|
|
data.mDidTransCallbackData = this;
|
2011-03-28 03:59:47 +04:00
|
|
|
}
|
2015-10-12 06:21:03 +03:00
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
data.mGLContext = gl;
|
2018-07-27 07:46:33 +03:00
|
|
|
data.mSize = DrawingBufferSize();
|
2017-12-19 05:30:56 +03:00
|
|
|
data.mHasAlpha = mOptions.alpha;
|
2014-06-19 04:04:06 +04:00
|
|
|
data.mIsGLAlphaPremult = IsPremultAlpha() || !data.mHasAlpha;
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2017-08-03 08:55:14 +03:00
|
|
|
aRenderer->Initialize(data);
|
|
|
|
aRenderer->SetDirty();
|
2018-09-28 22:25:21 +03:00
|
|
|
mVRReady = true;
|
2017-08-18 10:13:29 +03:00
|
|
|
return true;
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2015-08-18 01:10:12 +03:00
|
|
|
layers::LayersBackend
|
|
|
|
WebGLContext::GetCompositorBackendType() const
|
|
|
|
{
|
2015-10-12 06:21:03 +03:00
|
|
|
if (mCanvasElement) {
|
|
|
|
return mCanvasElement->GetCompositorBackendType();
|
|
|
|
} else if (mOffscreenCanvas) {
|
|
|
|
return mOffscreenCanvas->GetCompositorBackendType();
|
2015-08-18 01:10:12 +03:00
|
|
|
}
|
2015-10-12 06:21:03 +03:00
|
|
|
|
2015-08-18 01:10:12 +03:00
|
|
|
return LayersBackend::LAYERS_NONE;
|
|
|
|
}
|
|
|
|
|
2017-08-23 17:39:40 +03:00
|
|
|
nsIDocument*
|
|
|
|
WebGLContext::GetOwnerDoc() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCanvasElement);
|
|
|
|
if (!mCanvasElement) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mCanvasElement->OwnerDoc();
|
|
|
|
}
|
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
void
|
|
|
|
WebGLContext::Commit()
|
|
|
|
{
|
|
|
|
if (mOffscreenCanvas) {
|
|
|
|
mOffscreenCanvas->CommitFrameToCompositor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::GetCanvas(Nullable<dom::OwningHTMLCanvasElementOrOffscreenCanvas>& retval)
|
|
|
|
{
|
|
|
|
if (mCanvasElement) {
|
2016-06-06 18:17:23 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!mOffscreenCanvas, "GFX: Canvas is offscreen.");
|
2015-11-15 16:48:32 +03:00
|
|
|
|
|
|
|
if (mCanvasElement->IsInNativeAnonymousSubtree()) {
|
|
|
|
retval.SetNull();
|
|
|
|
} else {
|
|
|
|
retval.SetValue().SetAsHTMLCanvasElement() = mCanvasElement;
|
|
|
|
}
|
2015-10-12 06:21:03 +03:00
|
|
|
} else if (mOffscreenCanvas) {
|
|
|
|
retval.SetValue().SetAsOffscreenCanvas() = mOffscreenCanvas;
|
|
|
|
} else {
|
|
|
|
retval.SetNull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-22 21:08:52 +04:00
|
|
|
void
|
2015-07-15 03:37:28 +03:00
|
|
|
WebGLContext::GetContextAttributes(dom::Nullable<dom::WebGLContextAttributes>& retval)
|
2010-11-17 07:33:03 +03:00
|
|
|
{
|
2012-12-01 03:30:05 +04:00
|
|
|
retval.SetNull();
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "getContextAttributes");
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-10-22 21:08:52 +04:00
|
|
|
return;
|
2012-12-01 03:30:05 +04:00
|
|
|
|
|
|
|
dom::WebGLContextAttributes& result = retval.SetValue();
|
2010-11-17 07:33:03 +03:00
|
|
|
|
2014-10-09 03:32:50 +04:00
|
|
|
result.mAlpha.Construct(mOptions.alpha);
|
|
|
|
result.mDepth = mOptions.depth;
|
|
|
|
result.mStencil = mOptions.stencil;
|
|
|
|
result.mAntialias = mOptions.antialias;
|
2012-12-18 01:44:04 +04:00
|
|
|
result.mPremultipliedAlpha = mOptions.premultipliedAlpha;
|
|
|
|
result.mPreserveDrawingBuffer = mOptions.preserveDrawingBuffer;
|
2015-05-21 18:51:49 +03:00
|
|
|
result.mFailIfMajorPerformanceCaveat = mOptions.failIfMajorPerformanceCaveat;
|
2018-06-23 02:47:02 +03:00
|
|
|
result.mPowerPreference = mOptions.powerPreference;
|
2010-11-17 07:33:03 +03:00
|
|
|
}
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
// -
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
namespace webgl {
|
2011-05-20 23:53:53 +04:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
ScopedPrepForResourceClear::ScopedPrepForResourceClear(const WebGLContext& webgl_)
|
|
|
|
: webgl(webgl_)
|
|
|
|
{
|
|
|
|
const auto& gl = webgl.gl;
|
2014-10-02 04:05:34 +04:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
if (webgl.mScissorTestEnabled) {
|
|
|
|
gl->fDisable(LOCAL_GL_SCISSOR_TEST);
|
2011-05-20 23:53:53 +04:00
|
|
|
}
|
2018-10-17 07:18:15 +03:00
|
|
|
if (webgl.mRasterizerDiscardEnabled) {
|
|
|
|
gl->fDisable(LOCAL_GL_RASTERIZER_DISCARD);
|
2011-05-20 23:53:53 +04:00
|
|
|
}
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
// "The clear operation always uses the front stencil write mask
|
|
|
|
// when clearing the stencil buffer."
|
|
|
|
webgl.DoColorMask(0x0f);
|
|
|
|
gl->fDepthMask(true);
|
|
|
|
gl->fStencilMaskSeparate(LOCAL_GL_FRONT, 0xffffffff);
|
2011-05-20 23:53:53 +04:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
gl->fClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
gl->fClearDepth(1.0f); // Depth formats are always cleared to 1.0f, not 0.0f.
|
|
|
|
gl->fClearStencil(0);
|
|
|
|
}
|
2013-08-23 04:11:40 +04:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
ScopedPrepForResourceClear::~ScopedPrepForResourceClear()
|
|
|
|
{
|
|
|
|
const auto& gl = webgl.gl;
|
2011-05-20 23:53:53 +04:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
if (webgl.mScissorTestEnabled) {
|
2013-02-14 03:26:24 +04:00
|
|
|
gl->fEnable(LOCAL_GL_SCISSOR_TEST);
|
2017-12-20 12:55:50 +03:00
|
|
|
}
|
2018-10-17 07:18:15 +03:00
|
|
|
if (webgl.mRasterizerDiscardEnabled) {
|
2013-08-23 04:11:40 +04:00
|
|
|
gl->fEnable(LOCAL_GL_RASTERIZER_DISCARD);
|
|
|
|
}
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
// DoColorMask() is lazy.
|
|
|
|
gl->fDepthMask(webgl.mDepthWriteMask);
|
|
|
|
gl->fStencilMaskSeparate(LOCAL_GL_FRONT, webgl.mStencilWriteMaskFront);
|
2011-05-20 23:53:53 +04:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
gl->fClearColor(webgl.mColorClearValue[0],
|
|
|
|
webgl.mColorClearValue[1],
|
|
|
|
webgl.mColorClearValue[2],
|
|
|
|
webgl.mColorClearValue[3]);
|
|
|
|
gl->fClearDepth(webgl.mDepthClearValue);
|
|
|
|
gl->fClearStencil(webgl.mStencilClearValue);
|
2011-05-20 23:53:53 +04:00
|
|
|
}
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
} // namespace webgl
|
|
|
|
|
|
|
|
// -
|
|
|
|
|
2017-06-22 21:32:00 +03:00
|
|
|
void
|
|
|
|
WebGLContext::OnEndOfFrame() const
|
|
|
|
{
|
|
|
|
if (gfxPrefs::WebGLSpewFrameAllocs()) {
|
|
|
|
GeneratePerfWarning("[webgl.perf.spew-frame-allocs] %" PRIu64 " data allocations this frame.",
|
|
|
|
mDataAllocGLCallCount);
|
|
|
|
}
|
|
|
|
mDataAllocGLCallCount = 0;
|
2017-07-13 21:26:00 +03:00
|
|
|
gl->ResetSyncCallCount("WebGLContext PresentScreenBuffer");
|
2017-06-22 21:32:00 +03:00
|
|
|
}
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
void
|
|
|
|
WebGLContext::BlitBackbufferToCurDriverFB() const
|
|
|
|
{
|
2017-12-20 12:55:50 +03:00
|
|
|
DoColorMask(0x0f);
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
if (mScissorTestEnabled) {
|
|
|
|
gl->fDisable(LOCAL_GL_SCISSOR_TEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
[&]() {
|
|
|
|
const auto& size = mDefaultFB->mSize;
|
|
|
|
|
|
|
|
if (gl->IsSupported(GLFeature::framebuffer_blit)) {
|
|
|
|
gl->fBindFramebuffer(LOCAL_GL_READ_FRAMEBUFFER, mDefaultFB->mFB);
|
|
|
|
gl->fBlitFramebuffer(0, 0, size.width, size.height,
|
|
|
|
0, 0, size.width, size.height,
|
|
|
|
LOCAL_GL_COLOR_BUFFER_BIT, LOCAL_GL_NEAREST);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (mDefaultFB->mSamples &&
|
|
|
|
gl->IsExtensionSupported(GLContext::APPLE_framebuffer_multisample))
|
|
|
|
{
|
|
|
|
gl->fBindFramebuffer(LOCAL_GL_READ_FRAMEBUFFER, mDefaultFB->mFB);
|
|
|
|
gl->fResolveMultisampleFramebufferAPPLE();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl->BlitHelper()->DrawBlitTextureToFramebuffer(mDefaultFB->ColorTex(), size,
|
|
|
|
size);
|
|
|
|
}();
|
|
|
|
|
|
|
|
if (mScissorTestEnabled) {
|
|
|
|
gl->fEnable(LOCAL_GL_SCISSOR_TEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
// For an overview of how WebGL compositing works, see:
|
|
|
|
// https://wiki.mozilla.org/Platform/GFX/WebGL/Compositing
|
|
|
|
bool
|
2018-08-24 18:32:12 +03:00
|
|
|
WebGLContext::PresentScreenBuffer(GLScreenBuffer* const targetScreen)
|
2011-05-20 23:53:53 +04:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "<PresentScreenBuffer>");
|
2017-12-19 05:30:56 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!mShouldPresent)
|
2013-11-24 06:21:45 +04:00
|
|
|
return false;
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateAndInitFB(nullptr))
|
2017-12-19 05:30:56 +03:00
|
|
|
return false;
|
|
|
|
|
2018-08-24 18:32:12 +03:00
|
|
|
const auto& screen = targetScreen ? targetScreen : gl->Screen();
|
|
|
|
if ((!screen->IsReadBufferReady() || screen->Size() != mDefaultFB->mSize) &&
|
2017-12-19 05:30:56 +03:00
|
|
|
!screen->Resize(mDefaultFB->mSize))
|
|
|
|
{
|
|
|
|
GenerateWarning("screen->Resize failed. Losing context.");
|
|
|
|
ForceLoseContext();
|
2013-02-14 03:26:24 +04:00
|
|
|
return false;
|
|
|
|
}
|
2011-05-20 23:53:53 +04:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, 0);
|
|
|
|
BlitBackbufferToCurDriverFB();
|
2014-10-08 08:11:54 +04:00
|
|
|
|
2017-12-22 04:42:52 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (!mOptions.alpha) {
|
|
|
|
gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, 0);
|
|
|
|
uint32_t pixel = 3;
|
|
|
|
gl->fReadPixels(0, 0, 1, 1, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, &pixel);
|
|
|
|
MOZ_ASSERT((pixel & 0xff000000) == 0xff000000);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-10-09 00:04:19 +04:00
|
|
|
if (!screen->PublishFrame(screen->Size())) {
|
2017-12-19 05:30:56 +03:00
|
|
|
GenerateWarning("PublishFrame failed. Losing context.");
|
2014-08-28 03:16:22 +04:00
|
|
|
ForceLoseContext();
|
2013-02-14 03:26:24 +04:00
|
|
|
return false;
|
|
|
|
}
|
2011-05-20 23:53:53 +04:00
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
if (!mOptions.preserveDrawingBuffer) {
|
2017-12-19 05:30:56 +03:00
|
|
|
if (gl->IsSupported(gl::GLFeature::invalidate_framebuffer)) {
|
|
|
|
gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mDefaultFB->mFB);
|
|
|
|
const GLenum attachments[] = { LOCAL_GL_COLOR_ATTACHMENT0 };
|
|
|
|
gl->fInvalidateFramebuffer(LOCAL_GL_FRAMEBUFFER, 1, attachments);
|
|
|
|
}
|
|
|
|
mDefaultFB_IsInvalid = true;
|
2013-02-14 03:26:24 +04:00
|
|
|
}
|
2017-12-19 05:30:56 +03:00
|
|
|
mResolvedDefaultFB = nullptr;
|
2013-02-20 19:01:20 +04:00
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
mShouldPresent = false;
|
2017-06-22 21:32:00 +03:00
|
|
|
OnEndOfFrame();
|
2013-02-21 23:54:25 +04:00
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
return true;
|
2011-05-20 23:53:53 +04:00
|
|
|
}
|
|
|
|
|
2016-08-20 00:44:37 +03:00
|
|
|
// Prepare the context for capture before compositing
|
|
|
|
void
|
2018-08-24 18:32:12 +03:00
|
|
|
WebGLContext::BeginComposition(GLScreenBuffer* const screen)
|
2016-08-20 00:44:37 +03:00
|
|
|
{
|
|
|
|
// Present our screenbuffer, if needed.
|
2018-08-24 18:32:12 +03:00
|
|
|
PresentScreenBuffer(screen);
|
2016-08-20 00:44:37 +03:00
|
|
|
mDrawCallsSinceLastFlush = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up the context after captured for compositing
|
|
|
|
void
|
|
|
|
WebGLContext::EndComposition()
|
|
|
|
{
|
|
|
|
// Mark ourselves as no longer invalidated.
|
|
|
|
MarkContextClean();
|
|
|
|
UpdateLastUseIndex();
|
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2018-07-27 07:46:33 +03:00
|
|
|
WebGLContext::DummyReadFramebufferOperation()
|
2012-01-25 01:12:31 +04:00
|
|
|
{
|
2015-12-15 03:11:59 +03:00
|
|
|
if (!mBoundReadFramebuffer)
|
|
|
|
return; // Infallible.
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
const auto status = mBoundReadFramebuffer->CheckFramebufferStatus();
|
2014-11-14 07:03:50 +03:00
|
|
|
if (status != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidFramebufferOperation("Framebuffer must be complete.");
|
2014-11-14 07:03:50 +03:00
|
|
|
}
|
2012-01-25 01:12:31 +04:00
|
|
|
}
|
|
|
|
|
2016-07-17 20:37:00 +03:00
|
|
|
bool
|
2016-10-04 04:33:52 +03:00
|
|
|
WebGLContext::Has64BitTimestamps() const
|
2016-07-17 20:37:00 +03:00
|
|
|
{
|
|
|
|
// 'sync' provides glGetInteger64v either by supporting ARB_sync, GL3+, or GLES3+.
|
|
|
|
return gl->IsSupported(GLFeature::sync);
|
|
|
|
}
|
|
|
|
|
2014-06-03 01:40:15 +04:00
|
|
|
static bool
|
2014-11-14 07:03:50 +03:00
|
|
|
CheckContextLost(GLContext* gl, bool* const out_isGuilty)
|
2014-06-03 01:40:15 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(gl);
|
|
|
|
MOZ_ASSERT(out_isGuilty);
|
|
|
|
|
|
|
|
bool isEGL = gl->GetContextType() == gl::GLContextType::EGL;
|
|
|
|
|
|
|
|
GLenum resetStatus = LOCAL_GL_NO_ERROR;
|
2016-04-22 02:32:18 +03:00
|
|
|
if (gl->IsSupported(GLFeature::robustness)) {
|
2014-06-03 01:40:15 +04:00
|
|
|
gl->MakeCurrent();
|
|
|
|
resetStatus = 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.
|
|
|
|
if (!gl->MakeCurrent(true) && gl->IsContextLost()) {
|
|
|
|
resetStatus = LOCAL_GL_UNKNOWN_CONTEXT_RESET_ARB;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resetStatus == LOCAL_GL_NO_ERROR) {
|
|
|
|
*out_isGuilty = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assume guilty unless we find otherwise!
|
|
|
|
bool isGuilty = true;
|
|
|
|
switch (resetStatus) {
|
|
|
|
case LOCAL_GL_INNOCENT_CONTEXT_RESET_ARB:
|
|
|
|
// Either nothing wrong, or not our fault.
|
|
|
|
isGuilty = false;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_GUILTY_CONTEXT_RESET_ARB:
|
|
|
|
NS_WARNING("WebGL content on the page definitely caused the graphics"
|
|
|
|
" card to reset.");
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_UNKNOWN_CONTEXT_RESET_ARB:
|
|
|
|
NS_WARNING("WebGL content on the page might have caused the graphics"
|
|
|
|
" card to reset");
|
|
|
|
// If we can't tell, assume guilty.
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "Unreachable.");
|
|
|
|
// If we do get here, let's pretend to be guilty as an escape plan.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isGuilty) {
|
|
|
|
NS_WARNING("WebGL context on this page is considered guilty, and will"
|
|
|
|
" not be restored.");
|
|
|
|
}
|
|
|
|
|
|
|
|
*out_isGuilty = isGuilty;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGLContext::TryToRestoreContext()
|
|
|
|
{
|
2017-12-19 05:30:56 +03:00
|
|
|
if (NS_FAILED(SetDimensions(mRequestedSize.width, mRequestedSize.height)))
|
2014-06-03 01:40:15 +04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-22 20:55:00 +04:00
|
|
|
void
|
|
|
|
WebGLContext::RunContextLossTimer()
|
|
|
|
{
|
2016-06-16 20:01:44 +03:00
|
|
|
mContextLossHandler.RunTimer();
|
2014-08-22 20:55:00 +04:00
|
|
|
}
|
|
|
|
|
2016-04-11 21:40:06 +03:00
|
|
|
class UpdateContextLossStatusTask : public CancelableRunnable
|
2014-06-03 01:40:15 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WebGLContext> mWebGL;
|
2014-06-03 01:40:15 +04:00
|
|
|
|
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
explicit UpdateContextLossStatusTask(WebGLContext* webgl)
|
|
|
|
: CancelableRunnable("UpdateContextLossStatusTask")
|
|
|
|
, mWebGL(webgl)
|
|
|
|
{
|
2014-06-03 01:40:15 +04:00
|
|
|
}
|
|
|
|
|
2016-04-11 21:40:06 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2015-10-12 06:21:03 +03:00
|
|
|
if (mWebGL)
|
|
|
|
mWebGL->UpdateContextLossStatus();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-10-05 05:50:16 +03:00
|
|
|
|
2016-04-11 21:40:06 +03:00
|
|
|
nsresult Cancel() override {
|
2015-10-12 06:21:03 +03:00
|
|
|
mWebGL = nullptr;
|
2015-10-05 05:50:16 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-06-03 01:40:15 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::EnqueueUpdateContextLossStatus()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRunnable> task = new UpdateContextLossStatusTask(this);
|
|
|
|
NS_DispatchToCurrentThread(task);
|
|
|
|
}
|
|
|
|
|
2012-01-05 01:12:03 +04: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 20:21:23 +04:00
|
|
|
void
|
2014-06-03 01:40:15 +04:00
|
|
|
WebGLContext::UpdateContextLossStatus()
|
2011-10-27 00:00:44 +04:00
|
|
|
{
|
2015-10-12 06:21:03 +03:00
|
|
|
if (!mCanvasElement && !mOffscreenCanvas) {
|
2012-04-22 00:48:22 +04: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 20:21:23 +04:00
|
|
|
return;
|
2012-04-22 00:48:22 +04:00
|
|
|
}
|
2018-07-27 07:46:33 +03:00
|
|
|
if (mContextStatus == ContextStatus::NotLost) {
|
2014-06-03 01:40:15 +04:00
|
|
|
// We don't know that we're lost, but we might be, so we need to
|
|
|
|
// check. If we're guilty, don't allow restores, though.
|
|
|
|
|
|
|
|
bool isGuilty = true;
|
2014-06-03 01:40:46 +04:00
|
|
|
MOZ_ASSERT(gl); // Shouldn't be missing gl if we're NotLost.
|
2014-06-03 01:40:15 +04:00
|
|
|
bool isContextLost = CheckContextLost(gl, &isGuilty);
|
|
|
|
|
|
|
|
if (isContextLost) {
|
|
|
|
if (isGuilty)
|
|
|
|
mAllowContextRestore = false;
|
|
|
|
|
|
|
|
ForceLoseContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fall through.
|
|
|
|
}
|
2012-04-22 00:48:22 +04:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (mContextStatus == ContextStatus::LostAwaitingEvent) {
|
2014-06-03 01:40:15 +04:00
|
|
|
// The context has been lost and we haven't yet triggered the
|
|
|
|
// callback, so do that now.
|
2016-05-12 02:45:43 +03:00
|
|
|
const auto kEventName = NS_LITERAL_STRING("webglcontextlost");
|
2018-06-25 19:23:50 +03:00
|
|
|
const auto kCanBubble = CanBubble::eYes;
|
|
|
|
const auto kIsCancelable = Cancelable::eYes;
|
2014-06-03 01:40:15 +04:00
|
|
|
bool useDefaultHandler;
|
2015-10-12 06:21:03 +03:00
|
|
|
|
|
|
|
if (mCanvasElement) {
|
|
|
|
nsContentUtils::DispatchTrustedEvent(
|
|
|
|
mCanvasElement->OwnerDoc(),
|
2017-09-28 22:17:07 +03:00
|
|
|
static_cast<nsIContent*>(mCanvasElement),
|
2016-05-12 02:45:43 +03:00
|
|
|
kEventName,
|
|
|
|
kCanBubble,
|
|
|
|
kIsCancelable,
|
2015-10-12 06:21:03 +03:00
|
|
|
&useDefaultHandler);
|
|
|
|
} else {
|
|
|
|
// OffscreenCanvas case
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Event> event = new Event(mOffscreenCanvas, nullptr, nullptr);
|
2016-05-12 02:45:43 +03:00
|
|
|
event->InitEvent(kEventName, kCanBubble, kIsCancelable);
|
2015-10-12 06:21:03 +03:00
|
|
|
event->SetTrusted(true);
|
2018-04-05 20:42:41 +03:00
|
|
|
useDefaultHandler =
|
|
|
|
mOffscreenCanvas->DispatchEvent(*event, CallerType::System,
|
|
|
|
IgnoreErrors());
|
2015-10-12 06:21:03 +03:00
|
|
|
}
|
|
|
|
|
2014-06-03 01:40:15 +04:00
|
|
|
// We sent the callback, so we're just 'regular lost' now.
|
2018-07-27 07:46:33 +03:00
|
|
|
mContextStatus = ContextStatus::Lost;
|
2014-06-03 01:40:15 +04:00
|
|
|
// If we're told to use the default handler, it means the script
|
|
|
|
// didn't bother to handle the event. In this case, we shouldn't
|
|
|
|
// auto-restore the context.
|
|
|
|
if (useDefaultHandler)
|
|
|
|
mAllowContextRestore = false;
|
|
|
|
|
|
|
|
// Fall through.
|
|
|
|
}
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (mContextStatus == ContextStatus::Lost) {
|
2014-06-03 01:40:15 +04:00
|
|
|
// Context is lost, and we've already sent the callback. We
|
|
|
|
// should try to restore the context if we're both allowed to,
|
|
|
|
// and supposed to.
|
|
|
|
|
|
|
|
// Are we allowed to restore the context?
|
|
|
|
if (!mAllowContextRestore)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If we're only simulated-lost, we shouldn't auto-restore, and
|
|
|
|
// instead we should wait for restoreContext() to be called.
|
|
|
|
if (mLastLossWasSimulated)
|
|
|
|
return;
|
|
|
|
|
2014-06-23 03:16:00 +04:00
|
|
|
// Restore when the app is visible
|
|
|
|
if (mRestoreWhenVisible)
|
|
|
|
return;
|
|
|
|
|
2014-06-03 01:40:15 +04:00
|
|
|
ForceRestoreContext();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (mContextStatus == ContextStatus::LostAwaitingRestore) {
|
2014-06-03 01:40:15 +04:00
|
|
|
// Context is lost, but we should try to restore it.
|
|
|
|
|
|
|
|
if (!mAllowContextRestore) {
|
|
|
|
// We might decide this after thinking we'd be OK restoring
|
|
|
|
// the context, so downgrade.
|
2018-07-27 07:46:33 +03:00
|
|
|
mContextStatus = ContextStatus::Lost;
|
2014-06-03 01:40:15 +04:00
|
|
|
return;
|
2012-01-05 01:12:03 +04:00
|
|
|
}
|
2014-06-03 01:40:15 +04:00
|
|
|
|
|
|
|
if (!TryToRestoreContext()) {
|
|
|
|
// Failed to restore. Try again later.
|
2016-06-16 20:01:44 +03:00
|
|
|
mContextLossHandler.RunTimer();
|
2012-10-23 20:21:23 +04:00
|
|
|
return;
|
2012-01-05 01:12:03 +04:00
|
|
|
}
|
2014-06-03 01:40:15 +04:00
|
|
|
|
|
|
|
// Revival!
|
2018-07-27 07:46:33 +03:00
|
|
|
mContextStatus = ContextStatus::NotLost;
|
2015-10-12 06:21:03 +03:00
|
|
|
|
|
|
|
if (mCanvasElement) {
|
|
|
|
nsContentUtils::DispatchTrustedEvent(
|
|
|
|
mCanvasElement->OwnerDoc(),
|
2017-09-28 22:17:07 +03:00
|
|
|
static_cast<nsIContent*>(mCanvasElement),
|
2015-10-12 06:21:03 +03:00
|
|
|
NS_LITERAL_STRING("webglcontextrestored"),
|
2018-06-25 19:23:50 +03:00
|
|
|
CanBubble::eYes,
|
|
|
|
Cancelable::eYes);
|
2015-10-12 06:21:03 +03:00
|
|
|
} else {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Event> event = new Event(mOffscreenCanvas, nullptr, nullptr);
|
2018-06-25 19:23:50 +03:00
|
|
|
event->InitEvent(NS_LITERAL_STRING("webglcontextrestored"),
|
|
|
|
CanBubble::eYes,
|
|
|
|
Cancelable::eYes);
|
2015-10-12 06:21:03 +03:00
|
|
|
event->SetTrusted(true);
|
2018-04-05 20:42:41 +03:00
|
|
|
mOffscreenCanvas->DispatchEvent(*event);
|
2015-10-12 06:21:03 +03:00
|
|
|
}
|
|
|
|
|
2014-03-08 01:16:34 +04:00
|
|
|
mEmitContextLostErrorOnce = true;
|
2011-10-27 00:00:44 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-23 03:16:00 +04:00
|
|
|
WebGLContext::ForceLoseContext(bool simulateLosing)
|
2011-10-27 00:00:44 +04:00
|
|
|
{
|
2014-06-03 01:40:15 +04:00
|
|
|
printf_stderr("WebGL(%p)::ForceLoseContext\n", this);
|
2018-07-27 07:46:33 +03:00
|
|
|
MOZ_ASSERT(gl);
|
|
|
|
mContextStatus = ContextStatus::LostAwaitingEvent;
|
2014-06-03 01:40:15 +04:00
|
|
|
mContextLostErrorSet = false;
|
|
|
|
|
|
|
|
// Burn it all!
|
2011-10-27 00:00:44 +04:00
|
|
|
DestroyResourcesAndContext();
|
2014-06-23 03:16:00 +04:00
|
|
|
mLastLossWasSimulated = simulateLosing;
|
|
|
|
|
2014-06-03 01:40:15 +04:00
|
|
|
// Queue up a task, since we know the status changed.
|
|
|
|
EnqueueUpdateContextLossStatus();
|
2011-10-27 00:00:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::ForceRestoreContext()
|
|
|
|
{
|
2014-06-03 01:40:15 +04:00
|
|
|
printf_stderr("WebGL(%p)::ForceRestoreContext\n", this);
|
2018-07-27 07:46:33 +03:00
|
|
|
mContextStatus = ContextStatus::LostAwaitingRestore;
|
2014-06-03 01:40:15 +04:00
|
|
|
mAllowContextRestore = true; // Hey, you did say 'force'.
|
|
|
|
|
|
|
|
// Queue up a task, since we know the status changed.
|
|
|
|
EnqueueUpdateContextLossStatus();
|
2011-10-27 00:00:44 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<mozilla::gfx::SourceSurface>
|
2017-04-12 12:55:23 +03:00
|
|
|
WebGLContext::GetSurfaceSnapshot(gfxAlphaType* const out_alphaType)
|
2013-10-02 01:01:19 +04:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "<GetSurfaceSnapshot>");
|
|
|
|
if (IsContextLost())
|
2014-04-17 09:28:17 +04:00
|
|
|
return nullptr;
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!BindDefaultFBForRead())
|
2017-12-19 05:30:56 +03:00
|
|
|
return nullptr;
|
|
|
|
|
2017-04-12 12:55:23 +03:00
|
|
|
const auto surfFormat = mOptions.alpha ? SurfaceFormat::B8G8R8A8
|
|
|
|
: SurfaceFormat::B8G8R8X8;
|
2017-12-19 05:30:56 +03:00
|
|
|
const auto& size = mDefaultFB->mSize;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DataSourceSurface> surf;
|
2017-12-19 05:30:56 +03:00
|
|
|
surf = Factory::CreateDataSourceSurfaceWithStride(size, surfFormat, size.width * 4);
|
2017-04-12 12:55:23 +03:00
|
|
|
if (NS_WARN_IF(!surf))
|
2014-04-17 09:28:17 +04:00
|
|
|
return nullptr;
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
ReadPixelsIntoDataSurface(gl, surf);
|
2014-04-17 09:28:17 +04:00
|
|
|
|
2017-04-12 12:55:23 +03:00
|
|
|
gfxAlphaType alphaType;
|
|
|
|
if (!mOptions.alpha) {
|
|
|
|
alphaType = gfxAlphaType::Opaque;
|
|
|
|
} else if (mOptions.premultipliedAlpha) {
|
|
|
|
alphaType = gfxAlphaType::Premult;
|
|
|
|
} else {
|
|
|
|
alphaType = gfxAlphaType::NonPremult;
|
2014-04-17 09:28:17 +04:00
|
|
|
}
|
2017-04-12 12:55:23 +03:00
|
|
|
|
|
|
|
if (out_alphaType) {
|
|
|
|
*out_alphaType = alphaType;
|
|
|
|
} else {
|
|
|
|
// Expects Opaque or Premult
|
|
|
|
if (alphaType == gfxAlphaType::NonPremult) {
|
2014-06-19 04:04:05 +04:00
|
|
|
gfxUtils::PremultiplyDataSurface(surf, surf);
|
2014-04-17 09:28:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawTarget> dt =
|
2017-02-26 22:38:24 +03:00
|
|
|
Factory::CreateDrawTarget(gfxPlatform::GetPlatform()->GetSoftwareBackend(),
|
2017-12-19 05:30:56 +03:00
|
|
|
size, SurfaceFormat::B8G8R8A8);
|
2017-04-12 12:55:23 +03:00
|
|
|
if (!dt)
|
2014-04-17 09:28:17 +04:00
|
|
|
return nullptr;
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
dt->SetTransform(Matrix::Translation(0.0, size.height).PreScale(1.0, -1.0));
|
2014-04-17 09:28:17 +04:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
const gfx::Rect rect{0, 0, float(size.width), float(size.height)};
|
|
|
|
dt->DrawSurface(surf, rect, rect, DrawSurfaceOptions(),
|
2014-04-17 09:28:17 +04:00
|
|
|
DrawOptions(1.0f, CompositionOp::OP_SOURCE));
|
|
|
|
|
|
|
|
return dt->Snapshot();
|
2013-10-02 01:01:19 +04:00
|
|
|
}
|
|
|
|
|
2014-09-10 05:40:51 +04:00
|
|
|
void
|
|
|
|
WebGLContext::DidRefresh()
|
|
|
|
{
|
|
|
|
if (gl) {
|
|
|
|
gl->FlushIfHeavyGLCallsSinceLastFlush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
gfx::IntSize
|
2018-07-27 07:46:33 +03:00
|
|
|
WebGLContext::DrawingBufferSize()
|
2015-02-25 01:09:09 +03:00
|
|
|
{
|
2017-12-19 05:30:56 +03:00
|
|
|
const gfx::IntSize zeros{0, 0};
|
|
|
|
if (IsContextLost())
|
|
|
|
return zeros;
|
2016-05-27 04:07:52 +03:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!EnsureDefaultFB())
|
2017-12-19 05:30:56 +03:00
|
|
|
return zeros;
|
2015-11-24 06:27:13 +03:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
return mDefaultFB->mSize;
|
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
bool
|
2018-07-27 07:46:33 +03:00
|
|
|
WebGLContext::ValidateAndInitFB(const WebGLFramebuffer* const fb)
|
2017-12-19 05:30:56 +03:00
|
|
|
{
|
|
|
|
if (fb)
|
2018-07-27 07:46:33 +03:00
|
|
|
return fb->ValidateAndInitAttachments();
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!EnsureDefaultFB())
|
2017-12-19 05:30:56 +03:00
|
|
|
return false;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
if (mDefaultFB_IsInvalid) {
|
2018-10-17 07:18:15 +03:00
|
|
|
// Clear it!
|
2017-12-19 05:30:56 +03:00
|
|
|
gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mDefaultFB->mFB);
|
2018-10-17 07:18:15 +03:00
|
|
|
const webgl::ScopedPrepForResourceClear scopedPrep(*this);
|
|
|
|
if (!mOptions.alpha) {
|
|
|
|
gl->fClearColor(0, 0, 0, 1);
|
|
|
|
}
|
2017-12-19 05:30:56 +03:00
|
|
|
const GLbitfield bits = LOCAL_GL_COLOR_BUFFER_BIT |
|
|
|
|
LOCAL_GL_DEPTH_BUFFER_BIT |
|
|
|
|
LOCAL_GL_STENCIL_BUFFER_BIT;
|
2018-10-17 07:18:15 +03:00
|
|
|
gl->fClear(bits);
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
mDefaultFB_IsInvalid = false;
|
|
|
|
}
|
|
|
|
return true;
|
2015-08-04 00:34:46 +03:00
|
|
|
}
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
void
|
|
|
|
WebGLContext::DoBindFB(const WebGLFramebuffer* const fb, const GLenum target) const
|
|
|
|
{
|
|
|
|
const GLenum driverFB = fb ? fb->mGLName : mDefaultFB->mFB;
|
|
|
|
gl->fBindFramebuffer(target, driverFB);
|
|
|
|
}
|
2014-10-02 04:05:34 +04:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
bool
|
2018-07-27 07:46:33 +03:00
|
|
|
WebGLContext::BindCurFBForDraw()
|
2014-10-02 04:05:34 +04:00
|
|
|
{
|
2017-12-19 05:30:56 +03:00
|
|
|
const auto& fb = mBoundDrawFramebuffer;
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateAndInitFB(fb))
|
2017-12-19 05:30:56 +03:00
|
|
|
return false;
|
2016-12-21 10:31:22 +03:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
DoBindFB(fb);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-07-27 07:46:33 +03:00
|
|
|
WebGLContext::BindCurFBForColorRead(const webgl::FormatUsageInfo** const out_format,
|
2017-12-19 05:30:56 +03:00
|
|
|
uint32_t* const out_width,
|
|
|
|
uint32_t* const out_height)
|
|
|
|
{
|
|
|
|
const auto& fb = mBoundReadFramebuffer;
|
|
|
|
|
|
|
|
if (fb) {
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateAndInitFB(fb))
|
2017-12-19 05:30:56 +03:00
|
|
|
return false;
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!fb->ValidateForColorRead(out_format, out_width, out_height))
|
2017-12-19 05:30:56 +03:00
|
|
|
return false;
|
|
|
|
|
|
|
|
gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, fb->mGLName);
|
|
|
|
return true;
|
2015-09-24 22:21:05 +03:00
|
|
|
}
|
2017-12-19 05:30:56 +03:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!BindDefaultFBForRead())
|
2017-12-19 05:30:56 +03:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (mDefaultFB_ReadBuffer == LOCAL_GL_NONE) {
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidOperation("Can't read from backbuffer when readBuffer mode is NONE.");
|
2017-12-19 05:30:56 +03:00
|
|
|
return false;
|
2015-03-12 04:23:56 +03:00
|
|
|
}
|
2017-12-19 05:30:56 +03:00
|
|
|
|
|
|
|
auto effFormat = mOptions.alpha ? webgl::EffectiveFormat::RGBA8
|
|
|
|
: webgl::EffectiveFormat::RGB8;
|
|
|
|
|
|
|
|
*out_format = mFormatUsage->GetUsage(effFormat);
|
|
|
|
MOZ_ASSERT(*out_format);
|
|
|
|
|
|
|
|
*out_width = mDefaultFB->mSize.width;
|
|
|
|
*out_height = mDefaultFB->mSize.height;
|
|
|
|
return true;
|
2014-10-02 04:05:34 +04:00
|
|
|
}
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
bool
|
2018-07-27 07:46:33 +03:00
|
|
|
WebGLContext::BindDefaultFBForRead()
|
2014-10-02 04:05:34 +04:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateAndInitFB(nullptr))
|
2017-12-19 05:30:56 +03:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!mDefaultFB->mSamples) {
|
|
|
|
gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mDefaultFB->mFB);
|
|
|
|
return true;
|
2015-09-24 22:21:05 +03:00
|
|
|
}
|
2017-12-19 05:30:56 +03:00
|
|
|
|
|
|
|
if (!mResolvedDefaultFB) {
|
|
|
|
mResolvedDefaultFB = MozFramebuffer::Create(gl, mDefaultFB->mSize, 0, false);
|
|
|
|
if (!mResolvedDefaultFB) {
|
2018-07-27 07:46:33 +03:00
|
|
|
gfxCriticalNote << FuncName() << ": Failed to create mResolvedDefaultFB.";
|
2017-12-19 05:30:56 +03:00
|
|
|
return false;
|
|
|
|
}
|
2015-03-12 04:23:56 +03:00
|
|
|
}
|
2016-12-21 10:31:22 +03:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mResolvedDefaultFB->mFB);
|
|
|
|
BlitBackbufferToCurDriverFB();
|
|
|
|
|
|
|
|
gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mResolvedDefaultFB->mFB);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-20 12:55:50 +03:00
|
|
|
void
|
|
|
|
WebGLContext::DoColorMask(const uint8_t bitmask) const
|
|
|
|
{
|
|
|
|
if (mDriverColorMask != bitmask) {
|
|
|
|
mDriverColorMask = bitmask;
|
|
|
|
gl->fColorMask(bool(mDriverColorMask & (1 << 0)),
|
|
|
|
bool(mDriverColorMask & (1 << 1)),
|
|
|
|
bool(mDriverColorMask & (1 << 2)),
|
|
|
|
bool(mDriverColorMask & (1 << 3)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
ScopedDrawCallWrapper::ScopedDrawCallWrapper(WebGLContext& webgl)
|
|
|
|
: mWebGL(webgl)
|
|
|
|
{
|
|
|
|
uint8_t driverColorMask = mWebGL.mColorWriteMask;
|
|
|
|
bool driverDepthTest = mWebGL.mDepthTestEnabled;
|
|
|
|
bool driverStencilTest = mWebGL.mStencilTestEnabled;
|
2017-12-22 14:42:04 +03:00
|
|
|
const auto& fb = mWebGL.mBoundDrawFramebuffer;
|
|
|
|
if (!fb) {
|
2017-12-19 05:30:56 +03:00
|
|
|
if (mWebGL.mDefaultFB_DrawBuffer0 == LOCAL_GL_NONE) {
|
|
|
|
driverColorMask = 0; // Is this well-optimized enough for depth-first
|
|
|
|
// rendering?
|
|
|
|
} else {
|
|
|
|
driverColorMask &= ~(uint8_t(mWebGL.mNeedsFakeNoAlpha) << 3);
|
|
|
|
}
|
|
|
|
driverDepthTest &= !mWebGL.mNeedsFakeNoDepth;
|
|
|
|
driverStencilTest &= !mWebGL.mNeedsFakeNoStencil;
|
2017-12-22 14:42:04 +03:00
|
|
|
} else {
|
|
|
|
if (mWebGL.mNeedsFakeNoStencil_UserFBs &&
|
2018-10-17 07:18:15 +03:00
|
|
|
fb->DepthAttachment().HasAttachment() &&
|
|
|
|
!fb->StencilAttachment().HasAttachment())
|
2017-12-22 14:42:04 +03:00
|
|
|
{
|
|
|
|
driverStencilTest = false;
|
|
|
|
}
|
2017-12-19 05:30:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto& gl = mWebGL.gl;
|
2017-12-20 12:55:50 +03:00
|
|
|
mWebGL.DoColorMask(driverColorMask);
|
2017-12-19 05:30:56 +03:00
|
|
|
if (mWebGL.mDriverDepthTest != driverDepthTest) {
|
|
|
|
// "When disabled, the depth comparison and subsequent possible updates to the
|
|
|
|
// depth buffer value are bypassed and the fragment is passed to the next
|
|
|
|
// operation." [GLES 3.0.5, p177]
|
|
|
|
mWebGL.mDriverDepthTest = driverDepthTest;
|
|
|
|
gl->SetEnabled(LOCAL_GL_DEPTH_TEST, mWebGL.mDriverDepthTest);
|
|
|
|
}
|
|
|
|
if (mWebGL.mDriverStencilTest != driverStencilTest) {
|
|
|
|
// "When disabled, the stencil test and associated modifications are not made, and
|
|
|
|
// the fragment is always passed." [GLES 3.0.5, p175]
|
|
|
|
mWebGL.mDriverStencilTest = driverStencilTest;
|
|
|
|
gl->SetEnabled(LOCAL_GL_STENCIL_TEST, mWebGL.mDriverStencilTest);
|
2016-12-21 10:31:22 +03:00
|
|
|
}
|
2014-10-02 04:05:34 +04:00
|
|
|
}
|
2015-02-25 01:09:09 +03:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
ScopedDrawCallWrapper::~ScopedDrawCallWrapper()
|
2016-02-19 04:59:24 +03:00
|
|
|
{
|
2017-12-19 05:30:56 +03:00
|
|
|
if (mWebGL.mBoundDrawFramebuffer)
|
|
|
|
return;
|
2016-02-19 04:59:24 +03:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
mWebGL.mResolvedDefaultFB = nullptr;
|
2016-12-24 05:54:04 +03:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
mWebGL.Invalidate();
|
|
|
|
mWebGL.mShouldPresent = true;
|
2016-12-24 05:54:04 +03:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
////////////////////////////////////////
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
IndexedBufferBinding::IndexedBufferBinding()
|
|
|
|
: mRangeStart(0)
|
|
|
|
, mRangeSize(0)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
IndexedBufferBinding::ByteCount() const
|
|
|
|
{
|
|
|
|
if (!mBufferBinding)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
uint64_t bufferSize = mBufferBinding->ByteLength();
|
|
|
|
if (!mRangeSize) // BindBufferBase
|
|
|
|
return bufferSize;
|
|
|
|
|
|
|
|
if (mRangeStart >= bufferSize)
|
|
|
|
return 0;
|
|
|
|
bufferSize -= mRangeStart;
|
|
|
|
|
|
|
|
return std::min(bufferSize, mRangeSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
ScopedUnpackReset::ScopedUnpackReset(const WebGLContext* const webgl)
|
2015-11-25 07:15:29 +03:00
|
|
|
: ScopedGLWrapper<ScopedUnpackReset>(webgl->gl)
|
|
|
|
, mWebGL(webgl)
|
|
|
|
{
|
|
|
|
if (mWebGL->mPixelStore_UnpackAlignment != 4) mGL->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
|
|
|
|
|
|
|
|
if (mWebGL->IsWebGL2()) {
|
|
|
|
if (mWebGL->mPixelStore_UnpackRowLength != 0) mGL->fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH , 0);
|
|
|
|
if (mWebGL->mPixelStore_UnpackImageHeight != 0) mGL->fPixelStorei(LOCAL_GL_UNPACK_IMAGE_HEIGHT, 0);
|
|
|
|
if (mWebGL->mPixelStore_UnpackSkipPixels != 0) mGL->fPixelStorei(LOCAL_GL_UNPACK_SKIP_PIXELS , 0);
|
|
|
|
if (mWebGL->mPixelStore_UnpackSkipRows != 0) mGL->fPixelStorei(LOCAL_GL_UNPACK_SKIP_ROWS , 0);
|
|
|
|
if (mWebGL->mPixelStore_UnpackSkipImages != 0) mGL->fPixelStorei(LOCAL_GL_UNPACK_SKIP_IMAGES , 0);
|
|
|
|
|
|
|
|
if (mWebGL->mBoundPixelUnpackBuffer) mGL->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ScopedUnpackReset::UnwrapImpl()
|
|
|
|
{
|
|
|
|
mGL->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, mWebGL->mPixelStore_UnpackAlignment);
|
|
|
|
|
|
|
|
if (mWebGL->IsWebGL2()) {
|
|
|
|
mGL->fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH , mWebGL->mPixelStore_UnpackRowLength );
|
|
|
|
mGL->fPixelStorei(LOCAL_GL_UNPACK_IMAGE_HEIGHT, mWebGL->mPixelStore_UnpackImageHeight);
|
|
|
|
mGL->fPixelStorei(LOCAL_GL_UNPACK_SKIP_PIXELS , mWebGL->mPixelStore_UnpackSkipPixels );
|
|
|
|
mGL->fPixelStorei(LOCAL_GL_UNPACK_SKIP_ROWS , mWebGL->mPixelStore_UnpackSkipRows );
|
|
|
|
mGL->fPixelStorei(LOCAL_GL_UNPACK_SKIP_IMAGES , mWebGL->mPixelStore_UnpackSkipImages );
|
|
|
|
|
|
|
|
GLuint pbo = 0;
|
|
|
|
if (mWebGL->mBoundPixelUnpackBuffer) {
|
|
|
|
pbo = mWebGL->mBoundPixelUnpackBuffer->mGLName;
|
|
|
|
}
|
|
|
|
|
|
|
|
mGL->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, pbo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
////////////////////
|
|
|
|
|
|
|
|
void
|
|
|
|
ScopedFBRebinder::UnwrapImpl()
|
|
|
|
{
|
|
|
|
const auto fnName = [&](WebGLFramebuffer* fb) {
|
|
|
|
return fb ? fb->mGLName : 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (mWebGL->IsWebGL2()) {
|
|
|
|
mGL->fBindFramebuffer(LOCAL_GL_DRAW_FRAMEBUFFER, fnName(mWebGL->mBoundDrawFramebuffer));
|
|
|
|
mGL->fBindFramebuffer(LOCAL_GL_READ_FRAMEBUFFER, fnName(mWebGL->mBoundReadFramebuffer));
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(mWebGL->mBoundDrawFramebuffer == mWebGL->mBoundReadFramebuffer);
|
|
|
|
mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, fnName(mWebGL->mBoundDrawFramebuffer));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-26 23:38:56 +03:00
|
|
|
////////////////////
|
|
|
|
|
|
|
|
static GLenum
|
|
|
|
TargetIfLazy(GLenum target)
|
|
|
|
{
|
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_PIXEL_PACK_BUFFER:
|
|
|
|
case LOCAL_GL_PIXEL_UNPACK_BUFFER:
|
|
|
|
return target;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopedLazyBind::ScopedLazyBind(gl::GLContext* gl, GLenum target, const WebGLBuffer* buf)
|
|
|
|
: ScopedGLWrapper<ScopedLazyBind>(gl)
|
|
|
|
, mTarget(buf ? TargetIfLazy(target) : 0)
|
|
|
|
, mBuf(buf)
|
|
|
|
{
|
|
|
|
if (mTarget) {
|
|
|
|
mGL->fBindBuffer(mTarget, mBuf->mGLName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ScopedLazyBind::UnwrapImpl()
|
|
|
|
{
|
|
|
|
if (mTarget) {
|
|
|
|
mGL->fBindBuffer(mTarget, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
////////////////////////////////////////
|
|
|
|
|
2017-02-28 02:24:14 +03:00
|
|
|
bool
|
|
|
|
Intersect(const int32_t srcSize, const int32_t read0, const int32_t readSize,
|
|
|
|
int32_t* const out_intRead0, int32_t* const out_intWrite0,
|
|
|
|
int32_t* const out_intSize)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(srcSize >= 0);
|
|
|
|
MOZ_ASSERT(readSize >= 0);
|
|
|
|
const auto read1 = int64_t(read0) + readSize;
|
|
|
|
|
|
|
|
int32_t intRead0 = read0; // Clearly doesn't need validation.
|
|
|
|
int64_t intWrite0 = 0;
|
|
|
|
int64_t intSize = readSize;
|
|
|
|
|
|
|
|
if (read1 <= 0 || read0 >= srcSize) {
|
|
|
|
// Disjoint ranges.
|
|
|
|
intSize = 0;
|
|
|
|
} else {
|
|
|
|
if (read0 < 0) {
|
|
|
|
const auto diff = int64_t(0) - read0;
|
|
|
|
MOZ_ASSERT(diff >= 0);
|
|
|
|
intRead0 = 0;
|
|
|
|
intWrite0 = diff;
|
|
|
|
intSize -= diff;
|
|
|
|
}
|
|
|
|
if (read1 > srcSize) {
|
|
|
|
const auto diff = int64_t(read1) - srcSize;
|
|
|
|
MOZ_ASSERT(diff >= 0);
|
|
|
|
intSize -= diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CheckedInt<int32_t>(intWrite0).isValid() ||
|
|
|
|
!CheckedInt<int32_t>(intSize).isValid())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*out_intRead0 = intRead0;
|
|
|
|
*out_intWrite0 = intWrite0;
|
|
|
|
*out_intSize = intSize;
|
|
|
|
return true;
|
2015-11-25 07:15:29 +03:00
|
|
|
}
|
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
// --
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
AvailGroups(const uint64_t totalAvailItems, const uint64_t firstItemOffset,
|
|
|
|
const uint32_t groupSize, const uint32_t groupStride)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(groupSize && groupStride);
|
|
|
|
MOZ_ASSERT(groupSize <= groupStride);
|
|
|
|
|
|
|
|
if (totalAvailItems <= firstItemOffset)
|
|
|
|
return 0;
|
|
|
|
const size_t availItems = totalAvailItems - firstItemOffset;
|
|
|
|
|
|
|
|
size_t availGroups = availItems / groupStride;
|
|
|
|
const size_t tailItems = availItems % groupStride;
|
|
|
|
if (tailItems >= groupSize) {
|
|
|
|
availGroups += 1;
|
|
|
|
}
|
|
|
|
return availGroups;
|
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
CheckedUint32
|
|
|
|
WebGLContext::GetUnpackSize(bool isFunc3D, uint32_t width, uint32_t height,
|
|
|
|
uint32_t depth, uint8_t bytesPerPixel)
|
|
|
|
{
|
|
|
|
if (!width || !height || !depth)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
|
|
|
|
const auto& maybeRowLength = mPixelStore_UnpackRowLength;
|
|
|
|
const auto& maybeImageHeight = mPixelStore_UnpackImageHeight;
|
|
|
|
|
|
|
|
const auto usedPixelsPerRow = CheckedUint32(mPixelStore_UnpackSkipPixels) + width;
|
|
|
|
const auto stridePixelsPerRow = (maybeRowLength ? CheckedUint32(maybeRowLength)
|
|
|
|
: usedPixelsPerRow);
|
|
|
|
|
|
|
|
const auto usedRowsPerImage = CheckedUint32(mPixelStore_UnpackSkipRows) + height;
|
|
|
|
const auto strideRowsPerImage = (maybeImageHeight ? CheckedUint32(maybeImageHeight)
|
|
|
|
: usedRowsPerImage);
|
|
|
|
|
|
|
|
const uint32_t skipImages = (isFunc3D ? mPixelStore_UnpackSkipImages
|
|
|
|
: 0);
|
|
|
|
const CheckedUint32 usedImages = CheckedUint32(skipImages) + depth;
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
|
|
|
|
CheckedUint32 strideBytesPerRow = bytesPerPixel * stridePixelsPerRow;
|
|
|
|
strideBytesPerRow = RoundUpToMultipleOf(strideBytesPerRow,
|
|
|
|
mPixelStore_UnpackAlignment);
|
|
|
|
|
|
|
|
const CheckedUint32 strideBytesPerImage = strideBytesPerRow * strideRowsPerImage;
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
|
|
|
|
CheckedUint32 usedBytesPerRow = bytesPerPixel * usedPixelsPerRow;
|
|
|
|
// Don't round this to the alignment, since alignment here is really just used for
|
|
|
|
// establishing stride, particularly in WebGL 1, where you can't set ROW_LENGTH.
|
|
|
|
|
|
|
|
CheckedUint32 totalBytes = strideBytesPerImage * (usedImages - 1);
|
|
|
|
totalBytes += strideBytesPerRow * (usedRowsPerImage - 1);
|
|
|
|
totalBytes += usedBytesPerRow;
|
|
|
|
|
|
|
|
return totalBytes;
|
|
|
|
}
|
|
|
|
|
2018-07-11 03:41:58 +03:00
|
|
|
|
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
already_AddRefed<layers::SharedSurfaceTextureClient>
|
|
|
|
WebGLContext::GetVRFrame()
|
|
|
|
{
|
2018-08-24 18:32:12 +03:00
|
|
|
if (!gl)
|
|
|
|
return nullptr;
|
2018-09-07 17:47:51 +03:00
|
|
|
|
2018-09-28 22:25:21 +03:00
|
|
|
EnsureVRReady();
|
|
|
|
|
2018-08-24 18:32:12 +03:00
|
|
|
// Create a custom GLScreenBuffer for VR.
|
|
|
|
if (!mVRScreen) {
|
|
|
|
auto caps = gl->Screen()->mCaps;
|
|
|
|
mVRScreen = GLScreenBuffer::Create(gl, gfx::IntSize(1, 1), caps);
|
|
|
|
|
|
|
|
RefPtr<ImageBridgeChild> imageBridge = ImageBridgeChild::GetSingleton();
|
|
|
|
if (imageBridge) {
|
|
|
|
TextureFlags flags = TextureFlags::ORIGIN_BOTTOM_LEFT;
|
|
|
|
UniquePtr<gl::SurfaceFactory> factory = gl::GLScreenBuffer::CreateFactory(gl, caps, imageBridge.get(), flags);
|
|
|
|
mVRScreen->Morph(std::move(factory));
|
|
|
|
}
|
|
|
|
}
|
2018-07-11 03:41:58 +03:00
|
|
|
|
2018-08-24 18:32:12 +03:00
|
|
|
// Swap buffers as though composition has occurred.
|
|
|
|
// We will then share the resulting front buffer to be submitted to the VR compositor.
|
|
|
|
BeginComposition(mVRScreen.get());
|
|
|
|
EndComposition();
|
2018-07-11 03:41:58 +03:00
|
|
|
|
2018-08-24 18:32:12 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return nullptr;
|
2018-07-11 03:41:58 +03:00
|
|
|
|
2018-08-24 18:32:12 +03:00
|
|
|
RefPtr<SharedSurfaceTextureClient> sharedSurface = mVRScreen->Front();
|
|
|
|
if (!sharedSurface || !sharedSurface->Surf())
|
|
|
|
return nullptr;
|
2018-08-24 00:10:57 +03:00
|
|
|
|
2018-08-24 18:32:12 +03:00
|
|
|
// Make sure that the WebGL buffer is committed to the attached SurfaceTexture on Android.
|
2018-07-11 03:41:58 +03:00
|
|
|
sharedSurface->Surf()->ProducerAcquire();
|
|
|
|
sharedSurface->Surf()->Commit();
|
|
|
|
sharedSurface->Surf()->ProducerRelease();
|
|
|
|
|
2018-08-24 18:32:12 +03:00
|
|
|
return sharedSurface.forget();
|
2018-07-11 03:41:58 +03:00
|
|
|
}
|
|
|
|
#else
|
2016-02-25 02:54:50 +03:00
|
|
|
already_AddRefed<layers::SharedSurfaceTextureClient>
|
|
|
|
WebGLContext::GetVRFrame()
|
|
|
|
{
|
2018-09-28 22:25:21 +03:00
|
|
|
EnsureVRReady();
|
2017-07-22 03:30:34 +03:00
|
|
|
/**
|
|
|
|
* Swap buffers as though composition has occurred.
|
|
|
|
* We will then share the resulting front buffer to be submitted to the VR
|
|
|
|
* compositor.
|
|
|
|
*/
|
|
|
|
BeginComposition();
|
|
|
|
EndComposition();
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!gl)
|
2018-05-26 00:10:47 +03:00
|
|
|
return nullptr;
|
|
|
|
|
2017-07-22 03:30:34 +03:00
|
|
|
gl::GLScreenBuffer* screen = gl->Screen();
|
2018-05-26 00:10:47 +03:00
|
|
|
if (!screen)
|
2017-07-22 03:30:34 +03:00
|
|
|
return nullptr;
|
2016-02-25 02:54:50 +03:00
|
|
|
|
2017-07-22 03:30:34 +03:00
|
|
|
RefPtr<SharedSurfaceTextureClient> sharedSurface = screen->Front();
|
2018-05-26 00:10:47 +03:00
|
|
|
if (!sharedSurface)
|
2017-07-22 03:30:34 +03:00
|
|
|
return nullptr;
|
2016-02-25 02:54:50 +03:00
|
|
|
|
2018-05-26 00:10:47 +03:00
|
|
|
return sharedSurface.forget();
|
2016-02-25 02:54:50 +03:00
|
|
|
}
|
|
|
|
|
2018-07-11 03:41:58 +03:00
|
|
|
#endif // ifdefined(MOZ_WIDGET_ANDROID)
|
|
|
|
|
2018-09-28 22:25:21 +03:00
|
|
|
void
|
|
|
|
WebGLContext::EnsureVRReady()
|
|
|
|
{
|
|
|
|
if (mVRReady) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make not composited canvases work with WebVR. See bug #1492554
|
|
|
|
// WebGLContext::InitializeCanvasRenderer is only called when the 2D compositor renders a WebGL canvas
|
|
|
|
// for the first time. This causes canvases not added to the DOM not to work properly with WebVR.
|
|
|
|
// Here we mimic what InitializeCanvasRenderer does internally as a workaround.
|
|
|
|
const auto imageBridge = ImageBridgeChild::GetSingleton();
|
|
|
|
if (imageBridge) {
|
|
|
|
const auto caps = gl->Screen()->mCaps;
|
|
|
|
auto flags = TextureFlags::ORIGIN_BOTTOM_LEFT;
|
|
|
|
if (!IsPremultAlpha() && mOptions.alpha) {
|
|
|
|
flags |= TextureFlags::NON_PREMULTIPLIED;
|
|
|
|
}
|
|
|
|
auto factory = gl::GLScreenBuffer::CreateFactory(gl, caps, imageBridge.get(), flags);
|
|
|
|
gl->Screen()->Morph(std::move(factory));
|
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2018-10-17 07:18:15 +03:00
|
|
|
// On Android we are using a different GLScreenBuffer for WebVR, so we need a resize here because
|
2018-09-28 22:25:21 +03:00
|
|
|
// PresentScreenBuffer() may not be called for the gl->Screen() after we set the new factory.
|
|
|
|
gl->Screen()->Resize(DrawingBufferSize());
|
|
|
|
#endif
|
|
|
|
mVRReady = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-12 01:39:23 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-11-12 04:43:53 +03:00
|
|
|
static inline size_t
|
|
|
|
SizeOfViewElem(const dom::ArrayBufferView& view)
|
|
|
|
{
|
|
|
|
const auto& elemType = view.Type();
|
|
|
|
if (elemType == js::Scalar::MaxTypedArrayViewType) // DataViews.
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return js::Scalar::byteSize(elemType);
|
|
|
|
}
|
|
|
|
|
2016-10-12 01:39:23 +03:00
|
|
|
bool
|
2018-07-27 07:46:33 +03:00
|
|
|
WebGLContext::ValidateArrayBufferView(const dom::ArrayBufferView& view, GLuint elemOffset,
|
2016-10-12 01:39:23 +03:00
|
|
|
GLuint elemCountOverride, uint8_t** const out_bytes,
|
|
|
|
size_t* const out_byteLen)
|
|
|
|
{
|
|
|
|
view.ComputeLengthAndData();
|
|
|
|
uint8_t* const bytes = view.DataAllowShared();
|
|
|
|
const size_t byteLen = view.LengthAllowShared();
|
|
|
|
|
2016-11-12 04:43:53 +03:00
|
|
|
const auto& elemSize = SizeOfViewElem(view);
|
2016-10-12 01:39:23 +03:00
|
|
|
|
|
|
|
size_t elemCount = byteLen / elemSize;
|
|
|
|
if (elemOffset > elemCount) {
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidValue("Invalid offset into ArrayBufferView.");
|
2016-10-12 01:39:23 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
elemCount -= elemOffset;
|
|
|
|
|
|
|
|
if (elemCountOverride) {
|
|
|
|
if (elemCountOverride > elemCount) {
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidValue("Invalid sub-length for ArrayBufferView.");
|
2016-10-12 01:39:23 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
elemCount = elemCountOverride;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out_bytes = bytes + (elemOffset * elemSize);
|
|
|
|
*out_byteLen = elemCount * elemSize;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
////
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2017-07-27 10:48:58 +03:00
|
|
|
void
|
|
|
|
WebGLContext::UpdateMaxDrawBuffers()
|
|
|
|
{
|
|
|
|
mGLMaxColorAttachments = gl->GetIntAs<uint32_t>(LOCAL_GL_MAX_COLOR_ATTACHMENTS);
|
|
|
|
mGLMaxDrawBuffers = gl->GetIntAs<uint32_t>(LOCAL_GL_MAX_DRAW_BUFFERS);
|
|
|
|
|
|
|
|
// WEBGL_draw_buffers:
|
|
|
|
// "The value of the MAX_COLOR_ATTACHMENTS_WEBGL parameter must be greater than or
|
|
|
|
// equal to that of the MAX_DRAW_BUFFERS_WEBGL parameter."
|
|
|
|
mGLMaxDrawBuffers = std::min(mGLMaxDrawBuffers, mGLMaxColorAttachments);
|
|
|
|
}
|
|
|
|
|
2018-02-21 04:34:25 +03:00
|
|
|
// --
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
const char*
|
|
|
|
WebGLContext::FuncName() const
|
|
|
|
{
|
|
|
|
const char* ret;
|
|
|
|
if (MOZ_LIKELY( mFuncScope )) {
|
|
|
|
ret = mFuncScope->mFuncName;
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
ret = "<funcName unknown>";
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -
|
|
|
|
|
|
|
|
WebGLContext::FuncScope::FuncScope(const WebGLContext& webgl, const char* const funcName)
|
|
|
|
: mWebGL(webgl)
|
|
|
|
, mFuncName(bool(mWebGL.mFuncScope) ? nullptr : funcName)
|
|
|
|
{
|
|
|
|
if (MOZ_UNLIKELY( !mFuncName )) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
mStillNeedsToCheckContextLost = false;
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mWebGL.mFuncScope = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLContext::FuncScope::~FuncScope()
|
|
|
|
{
|
|
|
|
if (MOZ_UNLIKELY( !mFuncName ))
|
|
|
|
return;
|
|
|
|
|
|
|
|
MOZ_ASSERT(!mStillNeedsToCheckContextLost);
|
|
|
|
mWebGL.mFuncScope = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGLContext::IsContextLost() const
|
|
|
|
{
|
|
|
|
if (MOZ_LIKELY( mFuncScope )) {
|
|
|
|
mFuncScope->OnCheckContextLost();
|
|
|
|
}
|
|
|
|
return mContextStatus != ContextStatus::NotLost;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGLContext::ValidateIsObject(const WebGLDeletableObject* const object) const
|
|
|
|
{
|
|
|
|
if (IsContextLost())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!object)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!object->IsCompatibleWithContext(this))
|
|
|
|
return false;
|
|
|
|
|
2018-10-17 09:54:28 +03:00
|
|
|
if (object->IsDeleted())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2018-07-27 07:46:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGLContext::ValidateDeleteObject(const WebGLDeletableObject* const object)
|
|
|
|
{
|
|
|
|
if (IsContextLost())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!object)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!ValidateObjectAllowDeleted("obj", *object))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (object->IsDeleteRequested())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --
|
|
|
|
|
2018-02-21 04:34:25 +03:00
|
|
|
webgl::AvailabilityRunnable*
|
|
|
|
WebGLContext::EnsureAvailabilityRunnable()
|
|
|
|
{
|
|
|
|
if (!mAvailabilityRunnable) {
|
|
|
|
RefPtr<webgl::AvailabilityRunnable> runnable = new webgl::AvailabilityRunnable(this);
|
|
|
|
|
|
|
|
nsIDocument* document = GetOwnerDoc();
|
|
|
|
if (document) {
|
|
|
|
document->Dispatch(TaskCategory::Other, runnable.forget());
|
|
|
|
} else {
|
|
|
|
NS_DispatchToCurrentThread(runnable.forget());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mAvailabilityRunnable;
|
|
|
|
}
|
|
|
|
|
|
|
|
webgl::AvailabilityRunnable::AvailabilityRunnable(WebGLContext* const webgl)
|
|
|
|
: Runnable("webgl::AvailabilityRunnable")
|
|
|
|
, mWebGL(webgl)
|
|
|
|
{
|
|
|
|
mWebGL->mAvailabilityRunnable = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
webgl::AvailabilityRunnable::~AvailabilityRunnable()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mQueries.empty());
|
|
|
|
MOZ_ASSERT(mSyncs.empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
webgl::AvailabilityRunnable::Run()
|
|
|
|
{
|
|
|
|
for (const auto& cur : mQueries) {
|
|
|
|
cur->mCanBeAvailable = true;
|
|
|
|
}
|
|
|
|
mQueries.clear();
|
|
|
|
|
|
|
|
for (const auto& cur : mSyncs) {
|
|
|
|
cur->mCanBeAvailable = true;
|
|
|
|
}
|
|
|
|
mSyncs.clear();
|
|
|
|
|
|
|
|
mWebGL->mAvailabilityRunnable = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// XPCOM goop
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
void
|
|
|
|
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& callback,
|
|
|
|
const std::vector<IndexedBufferBinding>& field,
|
|
|
|
const char* name, uint32_t flags)
|
|
|
|
{
|
|
|
|
for (const auto& cur : field) {
|
|
|
|
ImplCycleCollectionTraverse(callback, cur.mBufferBinding, name, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ImplCycleCollectionUnlink(std::vector<IndexedBufferBinding>& field)
|
|
|
|
{
|
|
|
|
field.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
////
|
|
|
|
|
2011-03-06 14:11:31 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(WebGLContext)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(WebGLContext)
|
2010-06-16 01:38:05 +04:00
|
|
|
|
2014-04-29 12:57:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WebGLContext,
|
2014-12-05 10:04:55 +03:00
|
|
|
mCanvasElement,
|
2015-10-12 06:21:03 +03:00
|
|
|
mOffscreenCanvas,
|
2014-12-05 10:04:55 +03:00
|
|
|
mExtensions,
|
|
|
|
mBound2DTextures,
|
|
|
|
mBoundCubeMapTextures,
|
|
|
|
mBound3DTextures,
|
2015-11-25 07:15:29 +03:00
|
|
|
mBound2DArrayTextures,
|
2015-06-09 03:18:19 +03:00
|
|
|
mBoundSamplers,
|
2014-12-05 10:04:55 +03:00
|
|
|
mBoundArrayBuffer,
|
|
|
|
mBoundCopyReadBuffer,
|
|
|
|
mBoundCopyWriteBuffer,
|
|
|
|
mBoundPixelPackBuffer,
|
|
|
|
mBoundPixelUnpackBuffer,
|
2016-09-10 07:02:54 +03:00
|
|
|
mBoundTransformFeedback,
|
2018-03-30 02:43:58 +03:00
|
|
|
mBoundTransformFeedbackBuffer,
|
2014-12-05 10:04:55 +03:00
|
|
|
mBoundUniformBuffer,
|
|
|
|
mCurrentProgram,
|
2015-01-13 02:05:21 +03:00
|
|
|
mBoundDrawFramebuffer,
|
|
|
|
mBoundReadFramebuffer,
|
2014-12-05 10:04:55 +03:00
|
|
|
mBoundRenderbuffer,
|
|
|
|
mBoundVertexArray,
|
|
|
|
mDefaultVertexArray,
|
2016-10-04 04:33:52 +03:00
|
|
|
mQuerySlot_SamplesPassed,
|
|
|
|
mQuerySlot_TFPrimsWritten,
|
|
|
|
mQuerySlot_TimeElapsed)
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2010-06-16 01:38:05 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebGLContext)
|
2014-11-14 07:03:50 +03:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICanvasRenderingContextInternal)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
// If the exact way we cast to nsISupports here ever changes, fix our
|
|
|
|
// ToSupports() method.
|
2018-02-26 22:36:04 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICanvasRenderingContextInternal)
|
2009-09-03 04:47:49 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
2015-07-15 03:37:28 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|