diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index 37092d4e6028..eaf781e76df9 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -116,6 +116,7 @@ #include "nsDeviceContext.h" #include "nsFontMetrics.h" #include "Units.h" +#include "CanvasUtils.h" #undef free // apparently defined by some windows header, clashing with a free() // method in SkTypes.h @@ -5277,12 +5278,12 @@ CanvasRenderingContext2D::PutImageData_explicit(int32_t x, int32_t y, uint32_t w //uint8_t *src = aArray->Data(); uint8_t *dst = imgsurf->Data(); uint8_t* srcLine = aArray->Data() + copyY * (w * 4) + copyX * 4; -#if 0 +#if 0 printf("PutImageData_explicit: dirty x=%d y=%d w=%d h=%d copy x=%d y=%d w=%d h=%d ext x=%d y=%d w=%d h=%d\n", dirtyRect.x, dirtyRect.y, copyWidth, copyHeight, copyX, copyY, copyWidth, copyHeight, x, y, w, h); -#endif +#endif for (uint32_t j = 0; j < copyHeight; j++) { uint8_t *src = srcLine; for (uint32_t i = 0; i < copyWidth; i++) { diff --git a/dom/canvas/CanvasRenderingContext2D.h b/dom/canvas/CanvasRenderingContext2D.h index 4ba85197608a..8a6fbbe594c5 100644 --- a/dom/canvas/CanvasRenderingContext2D.h +++ b/dom/canvas/CanvasRenderingContext2D.h @@ -13,7 +13,6 @@ #include "nsColor.h" #include "mozilla/dom/HTMLCanvasElement.h" #include "mozilla/dom/HTMLVideoElement.h" -#include "CanvasUtils.h" #include "gfxTextRun.h" #include "mozilla/ErrorResult.h" #include "mozilla/dom/CanvasGradient.h" diff --git a/dom/canvas/WebGL1Context.cpp b/dom/canvas/WebGL1Context.cpp index f3f0bf5ac577..c8a8d684cddc 100644 --- a/dom/canvas/WebGL1Context.cpp +++ b/dom/canvas/WebGL1Context.cpp @@ -28,9 +28,9 @@ WebGL1Context::~WebGL1Context() } JSObject* -WebGL1Context::WrapObject(JSContext* cx, JS::Handle aGivenProto) +WebGL1Context::WrapObject(JSContext* cx, JS::Handle givenProto) { - return dom::WebGLRenderingContextBinding::Wrap(cx, this, aGivenProto); + return dom::WebGLRenderingContextBinding::Wrap(cx, this, givenProto); } bool diff --git a/dom/canvas/WebGL1Context.h b/dom/canvas/WebGL1Context.h index a47be758cc8e..1d55edce2068 100644 --- a/dom/canvas/WebGL1Context.h +++ b/dom/canvas/WebGL1Context.h @@ -27,7 +27,7 @@ public: } // nsWrapperCache - virtual JSObject* WrapObject(JSContext* cx, JS::Handle aGivenProto) override; + virtual JSObject* WrapObject(JSContext* cx, JS::Handle givenProto) override; private: virtual bool ValidateAttribPointerType(bool integerMode, GLenum type, GLsizei* alignment, const char* info) override; diff --git a/dom/canvas/WebGL1ContextBuffers.cpp b/dom/canvas/WebGL1ContextBuffers.cpp index c4449748ad27..51d3fb7557aa 100644 --- a/dom/canvas/WebGL1ContextBuffers.cpp +++ b/dom/canvas/WebGL1ContextBuffers.cpp @@ -4,11 +4,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "WebGL1Context.h" -#include "WebGLBuffer.h" -#include "GLContext.h" -using namespace mozilla; -using namespace mozilla::dom; +namespace mozilla { // ------------------------------------------------------------------------- // Buffer objects @@ -50,3 +47,5 @@ WebGL1Context::ValidateBufferUsageEnum(GLenum usage, const char* info) ErrorInvalidEnumInfo(info, usage); return false; } + +} // namespace mozilla diff --git a/dom/canvas/WebGL2Context.cpp b/dom/canvas/WebGL2Context.cpp index 41720dc3bf62..9e699bd3e0fa 100644 --- a/dom/canvas/WebGL2Context.cpp +++ b/dom/canvas/WebGL2Context.cpp @@ -43,9 +43,9 @@ WebGL2Context::Create() } JSObject* -WebGL2Context::WrapObject(JSContext* cx, JS::Handle aGivenProto) +WebGL2Context::WrapObject(JSContext* cx, JS::Handle givenProto) { - return dom::WebGL2RenderingContextBinding::Wrap(cx, this, aGivenProto); + return dom::WebGL2RenderingContextBinding::Wrap(cx, this, givenProto); } //////////////////////////////////////////////////////////////////////////////// diff --git a/dom/canvas/WebGL2Context.h b/dom/canvas/WebGL2Context.h index ec1f8e5ac48f..475ed67eca6f 100644 --- a/dom/canvas/WebGL2Context.h +++ b/dom/canvas/WebGL2Context.h @@ -38,7 +38,7 @@ public: // ------------------------------------------------------------------------- // IMPLEMENT nsWrapperCache - virtual JSObject* WrapObject(JSContext* cx, JS::Handle aGivenProto) override; + virtual JSObject* WrapObject(JSContext* cx, JS::Handle givenProto) override; // ------------------------------------------------------------------------- // Buffer objects - WebGL2ContextBuffers.cpp @@ -58,9 +58,9 @@ public: void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); void GetInternalformatParameter(JSContext*, GLenum target, GLenum internalformat, GLenum pname, JS::MutableHandleValue retval); void InvalidateFramebuffer(GLenum target, const dom::Sequence& attachments, - ErrorResult& aRv); + ErrorResult& rv); void InvalidateSubFramebuffer (GLenum target, const dom::Sequence& attachments, GLint x, GLint y, - GLsizei width, GLsizei height, ErrorResult& aRv); + GLsizei width, GLsizei height, ErrorResult& rv); void ReadBuffer(GLenum mode); void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); @@ -75,12 +75,12 @@ public: void TexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, - const Nullable &pixels, + const dom::Nullable& pixels, ErrorResult& rv); void TexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, const Nullable& pixels, + GLenum format, GLenum type, const dom::Nullable& pixels, ErrorResult& rv); void TexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, diff --git a/dom/canvas/WebGL2ContextBuffers.cpp b/dom/canvas/WebGL2ContextBuffers.cpp index 415021be7996..4446e9ad66cc 100644 --- a/dom/canvas/WebGL2ContextBuffers.cpp +++ b/dom/canvas/WebGL2ContextBuffers.cpp @@ -7,9 +7,9 @@ #include "GLContext.h" #include "WebGLBuffer.h" +#include "WebGLTransformFeedback.h" -using namespace mozilla; -using namespace mozilla::dom; +namespace mozilla { bool WebGL2Context::ValidateBufferTarget(GLenum target, const char* info) @@ -224,3 +224,5 @@ WebGL2Context::GetBufferSubData(GLenum target, GLintptr offset, BindTransformFeedback(LOCAL_GL_TRANSFORM_FEEDBACK, currentTF); } } + +} // namespace mozilla diff --git a/dom/canvas/WebGL2ContextDraw.cpp b/dom/canvas/WebGL2ContextDraw.cpp index ae09e4625a2f..517f3f06fb23 100644 --- a/dom/canvas/WebGL2ContextDraw.cpp +++ b/dom/canvas/WebGL2ContextDraw.cpp @@ -4,10 +4,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "WebGL2Context.h" -#include "GLContext.h" -using namespace mozilla; -using namespace mozilla::dom; +namespace mozilla { // ------------------------------------------------------------------------- // Writing to the drawing buffer @@ -17,3 +15,5 @@ WebGL2Context::DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei { MOZ_CRASH("Not Implemented."); } + +} // namespace mozilla diff --git a/dom/canvas/WebGL2ContextFramebuffers.cpp b/dom/canvas/WebGL2ContextFramebuffers.cpp index 45b94720ea67..eeb7cd5e28ff 100644 --- a/dom/canvas/WebGL2ContextFramebuffers.cpp +++ b/dom/canvas/WebGL2ContextFramebuffers.cpp @@ -6,10 +6,11 @@ #include "WebGL2Context.h" #include "GLContext.h" +#include "GLScreenBuffer.h" #include "WebGLContextUtils.h" +#include "WebGLFramebuffer.h" -using namespace mozilla; -using namespace mozilla::dom; +namespace mozilla { // Returns one of FLOAT, INT, UNSIGNED_INT. // Fixed-points (normalized ints) are considered FLOAT. @@ -374,7 +375,7 @@ TranslateDefaultAttachments(const dom::Sequence& in, dom::Sequence& attachments, - ErrorResult& aRv) + ErrorResult& rv) { if (IsContextLost()) return; @@ -420,7 +421,7 @@ WebGL2Context::InvalidateFramebuffer(GLenum target, if (!fb && !isDefaultFB) { dom::Sequence tmpAttachments; if (!TranslateDefaultAttachments(attachments, &tmpAttachments)) { - aRv.Throw(NS_ERROR_OUT_OF_MEMORY); + rv.Throw(NS_ERROR_OUT_OF_MEMORY); return; } @@ -433,7 +434,7 @@ WebGL2Context::InvalidateFramebuffer(GLenum target, void WebGL2Context::InvalidateSubFramebuffer(GLenum target, const dom::Sequence& attachments, GLint x, GLint y, GLsizei width, GLsizei height, - ErrorResult& aRv) + ErrorResult& rv) { if (IsContextLost()) return; @@ -479,7 +480,7 @@ WebGL2Context::InvalidateSubFramebuffer(GLenum target, const dom::Sequence tmpAttachments; if (!TranslateDefaultAttachments(attachments, &tmpAttachments)) { - aRv.Throw(NS_ERROR_OUT_OF_MEMORY); + rv.Throw(NS_ERROR_OUT_OF_MEMORY); return; } @@ -536,3 +537,5 @@ WebGL2Context::RenderbufferStorageMultisample(GLenum target, GLsizei samples, RenderbufferStorage_base("renderbufferStorageMultisample", target, samples, internalFormat, width, height); } + +} // namespace mozilla diff --git a/dom/canvas/WebGL2ContextMRTs.cpp b/dom/canvas/WebGL2ContextMRTs.cpp index 28494a2fdedc..f61cb5754969 100644 --- a/dom/canvas/WebGL2ContextMRTs.cpp +++ b/dom/canvas/WebGL2ContextMRTs.cpp @@ -6,8 +6,7 @@ #include "WebGL2Context.h" #include "GLContext.h" -using namespace mozilla; -using namespace mozilla::dom; +namespace mozilla { bool WebGL2Context::ValidateClearBuffer(const char* info, GLenum buffer, GLint drawbuffer, size_t elemCount) { @@ -140,3 +139,5 @@ WebGL2Context::ClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLi MakeContextCurrent(); gl->fClearBufferfi(buffer, drawbuffer, depth, stencil); } + +} // namespace mozilla diff --git a/dom/canvas/WebGL2ContextSamplers.cpp b/dom/canvas/WebGL2ContextSamplers.cpp index 3e2b31ebd36f..b29b58166f87 100644 --- a/dom/canvas/WebGL2ContextSamplers.cpp +++ b/dom/canvas/WebGL2ContextSamplers.cpp @@ -7,8 +7,7 @@ #include "WebGLSampler.h" #include "GLContext.h" -using namespace mozilla; -using namespace mozilla::dom; +namespace mozilla { already_AddRefed WebGL2Context::CreateSampler() @@ -225,3 +224,5 @@ WebGL2Context::GetSamplerParameter(JSContext*, WebGLSampler* sampler, GLenum pna return; } } + +} // namespace mozilla diff --git a/dom/canvas/WebGL2ContextState.cpp b/dom/canvas/WebGL2ContextState.cpp index 09a842730b05..e41b7009e189 100644 --- a/dom/canvas/WebGL2ContextState.cpp +++ b/dom/canvas/WebGL2ContextState.cpp @@ -5,7 +5,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "WebGL2Context.h" + +#include "GLContext.h" +#include "WebGLBuffer.h" #include "WebGLContextUtils.h" +#include "WebGLFramebuffer.h" +#include "WebGLSampler.h" +#include "WebGLTransformFeedback.h" +#include "WebGLVertexArray.h" namespace mozilla { diff --git a/dom/canvas/WebGL2ContextSync.cpp b/dom/canvas/WebGL2ContextSync.cpp index 960dc67b7cfc..0680a2834119 100644 --- a/dom/canvas/WebGL2ContextSync.cpp +++ b/dom/canvas/WebGL2ContextSync.cpp @@ -8,8 +8,7 @@ #include "GLContext.h" #include "WebGLSync.h" -using namespace mozilla; -using namespace mozilla::dom; +namespace mozilla { // ------------------------------------------------------------------------- // Sync objects @@ -131,3 +130,5 @@ WebGL2Context::GetSyncParameter(JSContext*, WebGLSync* sync, GLenum pname, JS::M ErrorInvalidEnum("getSyncParameter: Invalid pname 0x%04x", pname); } + +} // namespace mozilla diff --git a/dom/canvas/WebGL2ContextTextures.cpp b/dom/canvas/WebGL2ContextTextures.cpp index e7ae1cacf8e4..33938666ad58 100644 --- a/dom/canvas/WebGL2ContextTextures.cpp +++ b/dom/canvas/WebGL2ContextTextures.cpp @@ -3,12 +3,12 @@ * 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/. */ +#include "GLContext.h" #include "WebGL2Context.h" #include "WebGLContextUtils.h" -#include "GLContext.h" +#include "WebGLTexture.h" -using namespace mozilla; -using namespace mozilla::dom; +namespace mozilla { bool WebGL2Context::ValidateSizedInternalFormat(GLenum internalformat, const char* info) @@ -205,7 +205,7 @@ void WebGL2Context::TexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, - const Nullable &pixels, + const dom::Nullable &pixels, ErrorResult& rv) { if (IsContextLost()) @@ -219,7 +219,7 @@ WebGL2Context::TexImage3D(GLenum target, GLint level, GLenum internalformat, dataLength = 0; jsArrayType = js::Scalar::MaxTypedArrayViewType; } else { - const ArrayBufferView& view = pixels.Value(); + const dom::ArrayBufferView& view = pixels.Value(); view.ComputeLengthAndData(); data = view.Data(); @@ -318,7 +318,8 @@ void WebGL2Context::TexSubImage3D(GLenum rawTarget, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, const Nullable& pixels, + GLenum format, GLenum type, + const dom::Nullable& pixels, ErrorResult& rv) { if (IsContextLost()) @@ -327,7 +328,7 @@ WebGL2Context::TexSubImage3D(GLenum rawTarget, GLint level, if (pixels.IsNull()) return ErrorInvalidValue("texSubImage3D: pixels must not be null!"); - const ArrayBufferView& view = pixels.Value(); + const dom::ArrayBufferView& view = pixels.Value(); view.ComputeLengthAndData(); const WebGLTexImageFunc func = WebGLTexImageFunc::TexSubImage; @@ -489,3 +490,5 @@ WebGL2Context::GetTexParameterInternal(const TexTarget& target, GLenum pname) return WebGLContext::GetTexParameterInternal(target, pname); } + +} // namespace mozilla diff --git a/dom/canvas/WebGL2ContextTransformFeedback.cpp b/dom/canvas/WebGL2ContextTransformFeedback.cpp index a1db81b78c57..acaafd52a5a4 100644 --- a/dom/canvas/WebGL2ContextTransformFeedback.cpp +++ b/dom/canvas/WebGL2ContextTransformFeedback.cpp @@ -9,8 +9,7 @@ #include "WebGLTransformFeedback.h" #include "GLContext.h" -using namespace mozilla; -using namespace mozilla::dom; +namespace mozilla { // ------------------------------------------------------------------------- // Transform Feedback @@ -216,3 +215,5 @@ WebGL2Context::GetTransformFeedbackVarying(WebGLProgram* program, GLuint index) return program->GetTransformFeedbackVarying(index); } + +} // namespace mozilla diff --git a/dom/canvas/WebGL2ContextUniforms.cpp b/dom/canvas/WebGL2ContextUniforms.cpp index 7d356843542e..f891d089278c 100644 --- a/dom/canvas/WebGL2ContextUniforms.cpp +++ b/dom/canvas/WebGL2ContextUniforms.cpp @@ -4,12 +4,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "WebGL2Context.h" + #include "GLContext.h" +#include "mozilla/dom/WebGL2RenderingContextBinding.h" +#include "nsRefPtr.h" +#include "WebGLBuffer.h" #include "WebGLContext.h" #include "WebGLProgram.h" #include "WebGLVertexArray.h" #include "WebGLVertexAttribData.h" -#include "mozilla/dom/WebGL2RenderingContextBinding.h" namespace mozilla { @@ -543,7 +546,7 @@ WebGL2Context::GetUniformBlockIndex(WebGLProgram* program, void WebGL2Context::GetActiveUniformBlockParameter(JSContext* cx, WebGLProgram* program, GLuint uniformBlockIndex, GLenum pname, - Nullable& retval, + dom::Nullable& retval, ErrorResult& rv) { retval.SetNull(); diff --git a/dom/canvas/WebGLActiveInfo.cpp b/dom/canvas/WebGLActiveInfo.cpp index afa4569898e3..e8c78178c640 100644 --- a/dom/canvas/WebGLActiveInfo.cpp +++ b/dom/canvas/WebGLActiveInfo.cpp @@ -91,9 +91,9 @@ WebGLActiveInfo::WebGLActiveInfo(WebGLContext* webgl, GLint elemCount, GLenum el //////////////////////////////////////////////////////////////////////////////// JSObject* -WebGLActiveInfo::WrapObject(JSContext* js, JS::Handle aGivenProto) +WebGLActiveInfo::WrapObject(JSContext* js, JS::Handle givenProto) { - return dom::WebGLActiveInfoBinding::Wrap(js, this, aGivenProto); + return dom::WebGLActiveInfoBinding::Wrap(js, this, givenProto); } NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLActiveInfo) diff --git a/dom/canvas/WebGLActiveInfo.h b/dom/canvas/WebGLActiveInfo.h index fd1295f42c79..63cae0113045 100644 --- a/dom/canvas/WebGLActiveInfo.h +++ b/dom/canvas/WebGLActiveInfo.h @@ -7,7 +7,6 @@ #define WEBGL_ACTIVE_INFO_H_ #include "GLDefs.h" -#include "js/TypeDecls.h" #include "mozilla/Attributes.h" #include "nsCycleCollectionParticipant.h" // NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS #include "nsISupportsImpl.h" // NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING @@ -25,7 +24,7 @@ public: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLActiveInfo) NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLActiveInfo) - virtual JSObject* WrapObject(JSContext* js, JS::Handle aGivenProto) override; + virtual JSObject* WrapObject(JSContext* js, JS::Handle givenProto) override; WebGLContext* GetParentObject() const { return mWebGL; diff --git a/dom/canvas/WebGLBuffer.cpp b/dom/canvas/WebGLBuffer.cpp index cb28be5f6477..5cc5aebb20f0 100644 --- a/dom/canvas/WebGLBuffer.cpp +++ b/dom/canvas/WebGLBuffer.cpp @@ -104,9 +104,9 @@ WebGLBuffer::IsElementArrayUsedWithMultipleTypes() const } JSObject* -WebGLBuffer::WrapObject(JSContext* cx, JS::Handle aGivenProto) +WebGLBuffer::WrapObject(JSContext* cx, JS::Handle givenProto) { - return dom::WebGLBufferBinding::Wrap(cx, this, aGivenProto); + return dom::WebGLBufferBinding::Wrap(cx, this, givenProto); } NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLBuffer) diff --git a/dom/canvas/WebGLBuffer.h b/dom/canvas/WebGLBuffer.h index ef831fe5b244..87d8f98324f6 100644 --- a/dom/canvas/WebGLBuffer.h +++ b/dom/canvas/WebGLBuffer.h @@ -8,10 +8,10 @@ #include "GLDefs.h" #include "mozilla/LinkedList.h" -#include "mozilla/MemoryReporting.h" +#include "nsAutoPtr.h" #include "nsWrapperCache.h" + #include "WebGLObjectModel.h" -#include "WebGLStrongTypes.h" #include "WebGLTypes.h" namespace mozilla { @@ -58,7 +58,7 @@ public: return Context(); } - virtual JSObject* WrapObject(JSContext* cx, JS::Handle aGivenProto) override; + virtual JSObject* WrapObject(JSContext* cx, JS::Handle givenProto) override; const GLenum mGLName; diff --git a/dom/canvas/WebGLContext.cpp b/dom/canvas/WebGLContext.cpp index 04995f7ad87e..8521f741a985 100644 --- a/dom/canvas/WebGLContext.cpp +++ b/dom/canvas/WebGLContext.cpp @@ -5,8 +5,9 @@ #include "WebGLContext.h" +#include + #include "AccessCheck.h" -#include "CanvasUtils.h" #include "gfxContext.h" #include "gfxCrashReporterUtils.h" #include "gfxPattern.h" @@ -16,13 +17,13 @@ #include "GLContext.h" #include "GLContextProvider.h" #include "GLReadTexImageHelper.h" +#include "GLScreenBuffer.h" #include "ImageContainer.h" #include "ImageEncoder.h" #include "Layers.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/HTMLVideoElement.h" #include "mozilla/dom/ImageData.h" -#include "mozilla/dom/WebGLRenderingContextBinding.h" #include "mozilla/EnumeratedArrayCycleCollection.h" #include "mozilla/Preferences.h" #include "mozilla/ProcessPriorityManager.h" @@ -33,18 +34,25 @@ #include "nsError.h" #include "nsIClassInfoImpl.h" #include "nsIConsoleService.h" +#include "nsIDOMEvent.h" #include "nsIGfxInfo.h" #include "nsIObserverService.h" -#include "nsIDOMEvent.h" #include "nsIVariant.h" #include "nsIWidget.h" #include "nsIXPConnect.h" #include "nsServiceManagerUtils.h" #include "nsSVGEffects.h" #include "prenv.h" -#include #include "ScopedGLHelpers.h" + +#ifdef MOZ_WIDGET_GONK +#include "mozilla/layers/ShadowLayers.h" +#endif + +// Local +#include "CanvasUtils.h" #include "WebGL1Context.h" +#include "WebGLActiveInfo.h" #include "WebGLBuffer.h" #include "WebGLContextLossHandler.h" #include "WebGLContextUtils.h" @@ -52,17 +60,20 @@ #include "WebGLFramebuffer.h" #include "WebGLMemoryTracker.h" #include "WebGLObjectModel.h" +#include "WebGLProgram.h" #include "WebGLQuery.h" #include "WebGLSampler.h" +#include "WebGLShader.h" #include "WebGLTransformFeedback.h" #include "WebGLVertexArray.h" #include "WebGLVertexAttribData.h" -#ifdef MOZ_WIDGET_GONK -#include "mozilla/layers/ShadowLayers.h" -#endif +// Generated +#include "mozilla/dom/WebGLRenderingContextBinding.h" + + +namespace mozilla { -using namespace mozilla; using namespace mozilla::dom; using namespace mozilla::gfx; using namespace mozilla::gl; @@ -908,7 +919,7 @@ WebGLContext::SetDimensions(int32_t signedWidth, int32_t signedHeight) !gfxPrefs::WebGLDisableFailIfMajorPerformanceCaveat() && !HasAcceleratedLayers(gfxInfo); if (failIfMajorPerformanceCaveat) { - Nullable contextAttributes; + dom::Nullable contextAttributes; this->GetContextAttributes(contextAttributes); if (contextAttributes.Value().mFailIfMajorPerformanceCaveat) { return NS_ERROR_FAILURE; @@ -1182,8 +1193,6 @@ WebGLContext::UpdateLastUseIndex() static uint8_t gWebGLLayerUserData; -namespace mozilla { - class WebGLContextUserData : public LayerUserData { public: @@ -1222,8 +1231,6 @@ private: nsRefPtr mCanvas; }; -} // end namespace mozilla - already_AddRefed WebGLContext::GetCanvasLayer(nsDisplayListBuilder* builder, CanvasLayer* oldLayer, @@ -1283,7 +1290,7 @@ WebGLContext::GetCanvasLayer(nsDisplayListBuilder* builder, } void -WebGLContext::GetContextAttributes(Nullable& retval) +WebGLContext::GetContextAttributes(dom::Nullable& retval) { retval.SetNull(); if (IsContextLost()) @@ -1902,7 +1909,69 @@ WebGLContext::TexImageFromVideoElement(const TexImageTarget texImageTarget, return ok; } -size_t mozilla::RoundUpToMultipleOf(size_t value, size_t multiple) +void +WebGLContext::TexSubImage2D(GLenum rawTexImageTarget, GLint level, GLint xoffset, + GLint yoffset, GLenum format, GLenum type, + dom::Element* elt, ErrorResult* const out_rv) +{ + // TODO: Consolidate all the parameter validation + // checks. Instead of spreading out the cheks in multple + // places, consolidate into one spot. + + if (IsContextLost()) + return; + + if (!ValidateTexImageTarget(rawTexImageTarget, + WebGLTexImageFunc::TexSubImage, + WebGLTexDimensions::Tex2D)) + { + ErrorInvalidEnumInfo("texSubImage2D: target", rawTexImageTarget); + return; + } + + const TexImageTarget texImageTarget(rawTexImageTarget); + + if (level < 0) + return ErrorInvalidValue("texSubImage2D: level is negative"); + + const int32_t maxLevel = MaxTextureLevelForTexImageTarget(texImageTarget); + if (level > maxLevel) { + ErrorInvalidValue("texSubImage2D: level %d is too large, max is %d", + level, maxLevel); + return; + } + + WebGLTexture* tex = ActiveBoundTextureForTexImageTarget(texImageTarget); + if (!tex) + return ErrorInvalidOperation("texSubImage2D: no texture bound on active texture unit"); + + const WebGLTexture::ImageInfo& imageInfo = tex->ImageInfoAt(texImageTarget, level); + const TexInternalFormat internalFormat = imageInfo.EffectiveInternalFormat(); + + // Trying to handle the video by GPU directly first + if (TexImageFromVideoElement(texImageTarget, level, + internalFormat.get(), format, type, *elt)) + { + return; + } + + RefPtr data; + WebGLTexelFormat srcFormat; + nsLayoutUtils::SurfaceFromElementResult res = SurfaceFromElement(*elt); + *out_rv = SurfaceFromElementResultToImageSurface(res, data, &srcFormat); + if (out_rv->Failed() || !data) + return; + + gfx::IntSize size = data->GetSize(); + uint32_t byteLength = data->Stride() * size.height; + TexSubImage2D_base(texImageTarget.get(), level, xoffset, yoffset, size.width, + size.height, data->Stride(), format, type, data->GetData(), + byteLength, js::Scalar::MaxTypedArrayViewType, srcFormat, + mPixelStorePremultiplyAlpha); +} + +size_t +RoundUpToMultipleOf(size_t value, size_t multiple) { size_t overshoot = value + multiple - 1; return overshoot - (overshoot % multiple); @@ -1977,3 +2046,5 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebGLContext) // ToSupports() method. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMWebGLRenderingContext) NS_INTERFACE_MAP_END + +} // namespace mozilla diff --git a/dom/canvas/WebGLContext.h b/dom/canvas/WebGLContext.h index 7e67d4cdbc9c..a17210e32cfa 100644 --- a/dom/canvas/WebGLContext.h +++ b/dom/canvas/WebGLContext.h @@ -6,45 +6,40 @@ #ifndef WEBGLCONTEXT_H_ #define WEBGLCONTEXT_H_ +#include + +#include "GLDefs.h" #include "mozilla/Attributes.h" #include "mozilla/CheckedInt.h" +#include "mozilla/dom/HTMLCanvasElement.h" +#include "mozilla/dom/TypedArray.h" #include "mozilla/EnumeratedArray.h" +#include "mozilla/ErrorResult.h" +#include "mozilla/gfx/2D.h" #include "mozilla/LinkedList.h" #include "mozilla/UniquePtr.h" #include "mozilla/WeakPtr.h" - -#include "GLDefs.h" -#include "WebGLActiveInfo.h" -#include "WebGLContextUnchecked.h" -#include "WebGLFormats.h" -#include "WebGLObjectModel.h" -#include "WebGLRenderbuffer.h" -#include "WebGLTexture.h" -#include "WebGLShaderValidator.h" -#include "WebGLStrongTypes.h" -#include - -#include "nsTArray.h" #include "nsCycleCollectionNoteChild.h" - -#include "nsIDOMWebGLRenderingContext.h" #include "nsICanvasRenderingContextInternal.h" -#include "mozilla/dom/HTMLCanvasElement.h" -#include "nsWrapperCache.h" -#include "nsIObserver.h" -#include "nsIDOMEventListener.h" #include "nsLayoutUtils.h" - -#include "GLContextProvider.h" - -#include "mozilla/gfx/2D.h" +#include "nsTArray.h" +#include "nsWrapperCache.h" #ifdef XP_MACOSX #include "ForceDiscreteGPUHelperCGL.h" #endif -#include "mozilla/dom/TypedArray.h" -#include "mozilla/ErrorResult.h" +// Local +#include "WebGLContextUnchecked.h" +#include "WebGLFormats.h" +#include "WebGLObjectModel.h" +#include "WebGLStrongTypes.h" + +// Generated +#include "nsIDOMEventListener.h" +#include "nsIDOMWebGLRenderingContext.h" +#include "nsIObserver.h" + class nsIDocShell; @@ -108,6 +103,7 @@ class SourceSurface; namespace webgl { struct LinkedProgramInfo; +class ShaderValidator; } // namespace webgl WebGLTexelFormat GetWebGLTexelFormat(TexInternalFormat format); @@ -201,6 +197,10 @@ class WebGLContext public: WebGLContext(); +protected: + virtual ~WebGLContext(); + +public: MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLContext) NS_DECL_CYCLE_COLLECTING_ISUPPORTS @@ -208,7 +208,7 @@ public: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(WebGLContext, nsIDOMWebGLRenderingContext) - virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override = 0; + virtual JSObject* WrapObject(JSContext* cx, JS::Handle givenProto) override = 0; NS_DECL_NSIDOMWEBGLRENDERINGCONTEXT @@ -542,7 +542,7 @@ public: void PolygonOffset(GLfloat factor, GLfloat units); void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, - const Nullable& pixels, + const dom::Nullable& pixels, ErrorResult& rv); void RenderbufferStorage(GLenum target, GLenum internalFormat, GLsizei width, GLsizei height); @@ -563,7 +563,7 @@ public: GLenum dppass); void TexImage2D(GLenum texImageTarget, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, - GLenum type, const Nullable& pixels, + GLenum type, const dom::Nullable& pixels, ErrorResult& rv); void TexImage2D(GLenum texImageTarget, GLint level, GLenum internalFormat, GLenum format, GLenum type, dom::ImageData* pixels, @@ -640,73 +640,25 @@ public: void TexSubImage2D(GLenum texImageTarget, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, - const Nullable& pixels, + const dom::Nullable& pixels, ErrorResult& rv); void TexSubImage2D(GLenum texImageTarget, GLint level, GLint xoffset, GLint yoffset, GLenum format, GLenum type, dom::ImageData* pixels, ErrorResult& rv); + + void TexSubImage2D(GLenum rawTexImageTarget, GLint level, GLint xoffset, + GLint yoffset, GLenum format, GLenum type, + dom::Element* elt, ErrorResult* const out_rv); + // Allow whatever element types the bindings are willing to pass // us in TexSubImage2D template void TexSubImage2D(GLenum rawTexImageTarget, GLint level, GLint xoffset, GLint yoffset, GLenum format, GLenum type, - ElementType& elt, ErrorResult& rv) + ElementType& elt, ErrorResult& out_rv) { - // TODO: Consolidate all the parameter validation - // checks. Instead of spreading out the cheks in multple - // places, consolidate into one spot. - - if (IsContextLost()) - return; - - if (!ValidateTexImageTarget(rawTexImageTarget, - WebGLTexImageFunc::TexSubImage, - WebGLTexDimensions::Tex2D)) - { - ErrorInvalidEnumInfo("texSubImage2D: target", rawTexImageTarget); - return; - } - - const TexImageTarget texImageTarget(rawTexImageTarget); - - if (level < 0) - return ErrorInvalidValue("texSubImage2D: level is negative"); - - const int32_t maxLevel = MaxTextureLevelForTexImageTarget(texImageTarget); - if (level > maxLevel) { - ErrorInvalidValue("texSubImage2D: level %d is too large, max is %d", - level, maxLevel); - return; - } - - WebGLTexture* tex = ActiveBoundTextureForTexImageTarget(texImageTarget); - if (!tex) - return ErrorInvalidOperation("texSubImage2D: no texture bound on active texture unit"); - - const WebGLTexture::ImageInfo& imageInfo = tex->ImageInfoAt(texImageTarget, level); - const TexInternalFormat internalFormat = imageInfo.EffectiveInternalFormat(); - - // Trying to handle the video by GPU directly first - if (TexImageFromVideoElement(texImageTarget, level, - internalFormat.get(), format, type, elt)) - { - return; - } - - RefPtr data; - WebGLTexelFormat srcFormat; - nsLayoutUtils::SurfaceFromElementResult res = SurfaceFromElement(elt); - rv = SurfaceFromElementResultToImageSurface(res, data, &srcFormat); - if (rv.Failed() || !data) - return; - - gfx::IntSize size = data->GetSize(); - uint32_t byteLength = data->Stride() * size.height; - return TexSubImage2D_base(texImageTarget.get(), level, xoffset, yoffset, - size.width, size.height, data->Stride(), - format, type, data->GetData(), byteLength, - js::Scalar::MaxTypedArrayViewType, srcFormat, - mPixelStorePremultiplyAlpha); + TexSubImage2D(rawTexImageTarget, level, xoffset, yoffset, format, type, &elt, + &out_rv); } void Uniform1i(WebGLUniformLocation* loc, GLint x); @@ -917,7 +869,7 @@ public: void BufferData(GLenum target, WebGLsizeiptr size, GLenum usage); void BufferData(GLenum target, const dom::ArrayBufferView& data, GLenum usage); - void BufferData(GLenum target, const Nullable& maybeData, + void BufferData(GLenum target, const dom::Nullable& maybeData, GLenum usage); private: @@ -928,7 +880,7 @@ public: void BufferSubData(GLenum target, WebGLsizeiptr byteOffset, const dom::ArrayBufferView& data); void BufferSubData(GLenum target, WebGLsizeiptr byteOffset, - const Nullable& maybeData); + const dom::Nullable& maybeData); already_AddRefed CreateBuffer(); void DeleteBuffer(WebGLBuffer* buf); bool IsBuffer(WebGLBuffer* buf); @@ -1087,8 +1039,6 @@ private: // ----------------------------------------------------------------------------- // PROTECTED protected: - virtual ~WebGLContext(); - void SetFakeBlackStatus(WebGLContextFakeBlackStatus x) { mFakeBlackStatus = x; } diff --git a/dom/canvas/WebGLContextDraw.cpp b/dom/canvas/WebGLContextDraw.cpp index f78a0d71be55..bff2b2bf20a6 100644 --- a/dom/canvas/WebGLContextDraw.cpp +++ b/dom/canvas/WebGLContextDraw.cpp @@ -17,9 +17,7 @@ #include "WebGLVertexArray.h" #include "WebGLVertexAttribData.h" -using namespace mozilla; -using namespace mozilla::dom; -using namespace mozilla::gl; +namespace mozilla { // For a Tegra workaround. static const int MAX_DRAW_CALLS_SINCE_FLUSH = 100; @@ -748,7 +746,7 @@ WebGLContext::UnbindFakeBlackTextures() gl->fActiveTexture(LOCAL_GL_TEXTURE0 + mActiveTexture); } -WebGLContext::FakeBlackTexture::FakeBlackTexture(GLContext* gl, TexTarget target, GLenum format) +WebGLContext::FakeBlackTexture::FakeBlackTexture(gl::GLContext* gl, TexTarget target, GLenum format) : mGL(gl) , mGLName(0) { @@ -788,3 +786,5 @@ WebGLContext::FakeBlackTexture::~FakeBlackTexture() mGL->fDeleteTextures(1, &mGLName); } } + +} // namespace mozilla diff --git a/dom/canvas/WebGLContextExtensions.cpp b/dom/canvas/WebGLContextExtensions.cpp index a8f1a6bd9c91..bf62beabe70c 100644 --- a/dom/canvas/WebGLContextExtensions.cpp +++ b/dom/canvas/WebGLContextExtensions.cpp @@ -393,7 +393,7 @@ WebGLContext::EnableExtension(WebGLExtensionID ext) void WebGLContext::GetSupportedExtensions(JSContext* cx, - Nullable< nsTArray >& retval) + dom::Nullable< nsTArray >& retval) { retval.SetNull(); if (IsContextLost()) diff --git a/dom/canvas/WebGLContextFramebufferOperations.cpp b/dom/canvas/WebGLContextFramebufferOperations.cpp index 4cab00836f4c..0c132d03d282 100644 --- a/dom/canvas/WebGLContextFramebufferOperations.cpp +++ b/dom/canvas/WebGLContextFramebufferOperations.cpp @@ -9,7 +9,7 @@ #include "WebGLFramebuffer.h" #include "GLContext.h" -using namespace mozilla; +namespace mozilla { void WebGLContext::Clear(GLbitfield mask) @@ -250,6 +250,4 @@ WebGLContext::StencilMaskSeparate(GLenum face, GLuint mask) gl->fStencilMaskSeparate(face, mask); } - - - +} // namespace mozilla diff --git a/dom/canvas/WebGLContextGL.cpp b/dom/canvas/WebGLContextGL.cpp index ccb119353577..b5402deabb23 100644 --- a/dom/canvas/WebGLContextGL.cpp +++ b/dom/canvas/WebGLContextGL.cpp @@ -4,6 +4,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "WebGLContext.h" + +#include "WebGLActiveInfo.h" #include "WebGLContextUtils.h" #include "WebGLBuffer.h" #include "WebGLVertexAttribData.h" @@ -17,9 +19,10 @@ #include "WebGLExtensions.h" #include "WebGLVertexArray.h" -#include "nsString.h" #include "nsDebug.h" #include "nsReadableUtils.h" +#include "../../xpcom/base/nsRefPtr.h" +#include "nsString.h" #include "gfxContext.h" #include "gfxPlatform.h" @@ -49,7 +52,8 @@ #include "mozilla/dom/ToJSValue.h" #include "mozilla/Endian.h" -using namespace mozilla; +namespace mozilla { + using namespace mozilla::dom; using namespace mozilla::gfx; using namespace mozilla::gl; @@ -1023,7 +1027,7 @@ WebGLContext::GetActiveUniform(WebGLProgram* prog, GLuint index) void WebGLContext::GetAttachedShaders(WebGLProgram* prog, - Nullable>>& retval) + dom::Nullable>>& retval) { retval.SetNull(); if (IsContextLost()) @@ -1140,7 +1144,7 @@ WebGLContext::GetFramebufferAttachmentParameter(JSContext* cx, MakeContextCurrent(); - const WebGLFramebuffer::AttachPoint& fba = fb->GetAttachPoint(attachment); + const WebGLFBAttachPoint& fba = fb->GetAttachPoint(attachment); if (fba.Renderbuffer()) { switch (pname) { @@ -1972,7 +1976,7 @@ IsFormatAndTypeUnpackable(GLenum format, GLenum type) void WebGLContext::ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, - GLenum type, const Nullable &pixels, + GLenum type, const dom::Nullable& pixels, ErrorResult& rv) { if (IsContextLost()) @@ -2087,9 +2091,9 @@ WebGLContext::ReadPixels(GLint x, GLint y, GLsizei width, return; MOZ_ASSERT(srcFormat != LOCAL_GL_NONE); - TexType type = TypeFromInternalFormat(srcFormat); - isSourceTypeFloat = (type == LOCAL_GL_FLOAT || - type == LOCAL_GL_HALF_FLOAT); + TexType texType = TypeFromInternalFormat(srcFormat); + isSourceTypeFloat = (texType == LOCAL_GL_FLOAT || + texType == LOCAL_GL_HALF_FLOAT); } else { ClearBackbufferIfNeeded(); @@ -3407,7 +3411,8 @@ void WebGLContext::TexImage2D(GLenum rawTarget, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, - GLenum type, const Nullable &pixels, ErrorResult& rv) + GLenum type, const dom::Nullable& pixels, + ErrorResult& rv) { if (IsContextLost()) return; @@ -3608,7 +3613,7 @@ WebGLContext::TexSubImage2D(GLenum rawTarget, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, - const Nullable &pixels, + const dom::Nullable& pixels, ErrorResult& rv) { if (IsContextLost()) @@ -3684,7 +3689,7 @@ WebGLContext::RestoreContext() } WebGLTexelFormat -mozilla::GetWebGLTexelFormat(TexInternalFormat effectiveInternalFormat) +GetWebGLTexelFormat(TexInternalFormat effectiveInternalFormat) { switch (effectiveInternalFormat.get()) { case LOCAL_GL_RGBA8: return WebGLTexelFormat::RGBA8; @@ -3768,3 +3773,5 @@ WebGLContext::SampleCoverage(GLclampf value, WebGLboolean invert) { MakeContextCurrent(); gl->fSampleCoverage(value, invert); } + +} // namespace mozilla diff --git a/dom/canvas/WebGLContextReporter.cpp b/dom/canvas/WebGLContextReporter.cpp index 9f78046db833..d257d9662b4f 100644 --- a/dom/canvas/WebGLContextReporter.cpp +++ b/dom/canvas/WebGLContextReporter.cpp @@ -3,10 +3,11 @@ * 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/. */ +#include "WebGLBuffer.h" #include "WebGLContext.h" #include "WebGLMemoryTracker.h" -using namespace mozilla; +namespace mozilla { NS_IMPL_ISUPPORTS(WebGLObserver, nsIObserver) @@ -151,3 +152,5 @@ WebGLMemoryTracker::GetShaderSize() } return result; } + +} // namespace mozilla diff --git a/dom/canvas/WebGLContextState.cpp b/dom/canvas/WebGLContextState.cpp index b24a3ba82f45..72e0d820e819 100644 --- a/dom/canvas/WebGLContextState.cpp +++ b/dom/canvas/WebGLContextState.cpp @@ -15,8 +15,7 @@ #include "GLContext.h" #include "mozilla/dom/ToJSValue.h" -using namespace mozilla; -using namespace dom; +namespace mozilla { void WebGLContext::Disable(GLenum cap) @@ -353,7 +352,8 @@ WebGLContext::GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv) return JS::Int32Value(0); case LOCAL_GL_COMPRESSED_TEXTURE_FORMATS: { uint32_t length = mCompressedTextureFormats.Length(); - JSObject* obj = Uint32Array::Create(cx, this, length, mCompressedTextureFormats.Elements()); + JSObject* obj = dom::Uint32Array::Create(cx, this, length, + mCompressedTextureFormats.Elements()); if (!obj) { rv = NS_ERROR_OUT_OF_MEMORY; } @@ -419,7 +419,7 @@ WebGLContext::GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv) case LOCAL_GL_ALIASED_LINE_WIDTH_RANGE: { GLfloat fv[2] = { 0 }; gl->fGetFloatv(pname, fv); - JSObject* obj = Float32Array::Create(cx, this, 2, fv); + JSObject* obj = dom::Float32Array::Create(cx, this, 2, fv); if (!obj) { rv = NS_ERROR_OUT_OF_MEMORY; } @@ -431,7 +431,7 @@ WebGLContext::GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv) case LOCAL_GL_BLEND_COLOR: { GLfloat fv[4] = { 0 }; gl->fGetFloatv(pname, fv); - JSObject* obj = Float32Array::Create(cx, this, 4, fv); + JSObject* obj = dom::Float32Array::Create(cx, this, 4, fv); if (!obj) { rv = NS_ERROR_OUT_OF_MEMORY; } @@ -442,7 +442,7 @@ WebGLContext::GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv) case LOCAL_GL_MAX_VIEWPORT_DIMS: { GLint iv[2] = { 0 }; gl->fGetIntegerv(pname, iv); - JSObject* obj = Int32Array::Create(cx, this, 2, iv); + JSObject* obj = dom::Int32Array::Create(cx, this, 2, iv); if (!obj) { rv = NS_ERROR_OUT_OF_MEMORY; } @@ -454,7 +454,7 @@ WebGLContext::GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv) case LOCAL_GL_VIEWPORT: { GLint iv[4] = { 0 }; gl->fGetIntegerv(pname, iv); - JSObject* obj = Int32Array::Create(cx, this, 4, iv); + JSObject* obj = dom::Int32Array::Create(cx, this, 4, iv); if (!obj) { rv = NS_ERROR_OUT_OF_MEMORY; } @@ -468,7 +468,7 @@ WebGLContext::GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv) bool vals[4] = { bool(gl_bv[0]), bool(gl_bv[1]), bool(gl_bv[2]), bool(gl_bv[3]) }; JS::Rooted arr(cx); - if (!ToJSValue(cx, vals, &arr)) { + if (!dom::ToJSValue(cx, vals, &arr)) { rv = NS_ERROR_OUT_OF_MEMORY; } return arr; @@ -593,3 +593,5 @@ WebGLContext::GetStateTrackingSlot(GLenum cap) return nullptr; } + +} // namespace mozilla diff --git a/dom/canvas/WebGLContextUtils.cpp b/dom/canvas/WebGLContextUtils.cpp index 539bba9af891..1de6f9b92508 100644 --- a/dom/canvas/WebGLContextUtils.cpp +++ b/dom/canvas/WebGLContextUtils.cpp @@ -27,8 +27,6 @@ namespace mozilla { -using namespace gl; - bool IsGLDepthFormat(TexInternalFormat internalformat) { @@ -496,7 +494,7 @@ WebGLContext::GenerateWarning(const char* fmt, va_list ap) return; } - AutoJSAPI api; + dom::AutoJSAPI api; if (!api.Init(mCanvasElement->OwnerDoc()->GetScopeObject())) { return; } diff --git a/dom/canvas/WebGLContextUtils.h b/dom/canvas/WebGLContextUtils.h index 5535ee9fc696..62fc6390ee43 100644 --- a/dom/canvas/WebGLContextUtils.h +++ b/dom/canvas/WebGLContextUtils.h @@ -7,10 +7,12 @@ #define WEBGL_CONTEXT_UTILS_H_ #include "WebGLContext.h" -#include "WebGLStrongTypes.h" + #include "mozilla/Assertions.h" #include "mozilla/dom/BindingUtils.h" +#include "WebGLStrongTypes.h" + namespace mozilla { bool IsGLDepthFormat(TexInternalFormat webGLFormat); diff --git a/dom/canvas/WebGLContextValidate.cpp b/dom/canvas/WebGLContextValidate.cpp index c478897f8077..51292042c7c1 100644 --- a/dom/canvas/WebGLContextValidate.cpp +++ b/dom/canvas/WebGLContextValidate.cpp @@ -14,11 +14,13 @@ #include "mozilla/Preferences.h" #include "mozilla/Services.h" #include "nsIObserverService.h" +#include "WebGLActiveInfo.h" #include "WebGLBuffer.h" #include "WebGLContextUtils.h" #include "WebGLFramebuffer.h" #include "WebGLProgram.h" #include "WebGLRenderbuffer.h" +#include "WebGLSampler.h" #include "WebGLShader.h" #include "WebGLTexture.h" #include "WebGLUniformLocation.h" diff --git a/dom/canvas/WebGLContextVertices.cpp b/dom/canvas/WebGLContextVertices.cpp index 003cb6058fb5..90c4a8952f72 100644 --- a/dom/canvas/WebGLContextVertices.cpp +++ b/dom/canvas/WebGLContextVertices.cpp @@ -16,8 +16,7 @@ #include "WebGLVertexArray.h" #include "WebGLVertexAttribData.h" -using namespace mozilla; -using namespace dom; +namespace mozilla { void WebGLContext::VertexAttrib1f(GLuint index, GLfloat x0) @@ -306,7 +305,7 @@ WebGLContext::GetVertexAttrib(JSContext* cx, GLuint index, GLenum pname, vec[2] = mVertexAttrib0Vector[2]; vec[3] = mVertexAttrib0Vector[3]; } - JSObject* obj = Float32Array::Create(cx, this, 4, vec); + JSObject* obj = dom::Float32Array::Create(cx, this, 4, vec); if (!obj) { rv.Throw(NS_ERROR_OUT_OF_MEMORY); } @@ -410,3 +409,5 @@ WebGLContext::VertexAttribDivisor(GLuint index, GLuint divisor) gl->fVertexAttribDivisor(index, divisor); } + +} // namespace mozilla diff --git a/dom/canvas/WebGLExtensionBase.cpp b/dom/canvas/WebGLExtensionBase.cpp index b6f35e792698..6d2b4e9a120f 100644 --- a/dom/canvas/WebGLExtensionBase.cpp +++ b/dom/canvas/WebGLExtensionBase.cpp @@ -3,10 +3,9 @@ * 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/. */ -#include "WebGLContext.h" #include "WebGLExtensions.h" -using namespace mozilla; +namespace mozilla { WebGLExtensionBase::WebGLExtensionBase(WebGLContext* context) : WebGLContextBoundObject(context) @@ -28,3 +27,5 @@ NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLExtensionBase) NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLExtensionBase, AddRef) NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLExtensionBase, Release) + +} // namespace mozilla diff --git a/dom/canvas/WebGLExtensions.h b/dom/canvas/WebGLExtensions.h index 60eb30092a18..a474b5919a1b 100644 --- a/dom/canvas/WebGLExtensions.h +++ b/dom/canvas/WebGLExtensions.h @@ -6,14 +6,20 @@ #ifndef WEBGL_EXTENSIONS_H_ #define WEBGL_EXTENSIONS_H_ -#include "jsapi.h" +#include "mozilla/AlreadyAddRefed.h" #include "mozilla/Attributes.h" #include "nsWrapperCache.h" + #include "WebGLObjectModel.h" #include "WebGLTypes.h" namespace mozilla { +namespace dom { +template +class Sequence; +} // namespace dom + class WebGLContext; class WebGLShader; class WebGLQuery; @@ -43,12 +49,12 @@ protected: }; #define DECL_WEBGL_EXTENSION_GOOP \ - virtual JSObject* WrapObject(JSContext* cx, JS::Handle aGivenProto) override; + virtual JSObject* WrapObject(JSContext* cx, JS::Handle givenProto) override; #define IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionType, WebGLBindingType)\ JSObject* \ - WebGLExtensionType::WrapObject(JSContext* cx, JS::Handle aGivenProto) { \ - return dom::WebGLBindingType##Binding::Wrap(cx, this, aGivenProto); \ + WebGLExtensionType::WrapObject(JSContext* cx, JS::Handle givenProto) { \ + return dom::WebGLBindingType##Binding::Wrap(cx, this, givenProto); \ } class WebGLExtensionCompressedTextureATC diff --git a/dom/canvas/WebGLFormats.cpp b/dom/canvas/WebGLFormats.cpp index 35e070823494..efc4e0ddae22 100644 --- a/dom/canvas/WebGLFormats.cpp +++ b/dom/canvas/WebGLFormats.cpp @@ -5,6 +5,7 @@ #include "WebGLFormats.h" +#include "GLDefs.h" #include "mozilla/StaticMutex.h" namespace mozilla { diff --git a/dom/canvas/WebGLFramebuffer.cpp b/dom/canvas/WebGLFramebuffer.cpp index de5c5bcbc8d2..872e9237e54a 100644 --- a/dom/canvas/WebGLFramebuffer.cpp +++ b/dom/canvas/WebGLFramebuffer.cpp @@ -15,21 +15,21 @@ namespace mozilla { -WebGLFramebuffer::AttachPoint::AttachPoint(WebGLFramebuffer* fb, - FBAttachment attachmentPoint) +WebGLFBAttachPoint::WebGLFBAttachPoint(WebGLFramebuffer* fb, + FBAttachment attachmentPoint) : mFB(fb) , mAttachmentPoint(attachmentPoint) , mTexImageTarget(LOCAL_GL_NONE) { } -WebGLFramebuffer::AttachPoint::~AttachPoint() +WebGLFBAttachPoint::~WebGLFBAttachPoint() { MOZ_ASSERT(!mRenderbufferPtr); MOZ_ASSERT(!mTexturePtr); } bool -WebGLFramebuffer::AttachPoint::IsDeleteRequested() const +WebGLFBAttachPoint::IsDeleteRequested() const { return Texture() ? Texture()->IsDeleteRequested() : Renderbuffer() ? Renderbuffer()->IsDeleteRequested() @@ -37,14 +37,14 @@ WebGLFramebuffer::AttachPoint::IsDeleteRequested() const } bool -WebGLFramebuffer::AttachPoint::IsDefined() const +WebGLFBAttachPoint::IsDefined() const { return Renderbuffer() || (Texture() && Texture()->HasImageInfoAt(ImageTarget(), 0)); } bool -WebGLFramebuffer::AttachPoint::HasAlpha() const +WebGLFBAttachPoint::HasAlpha() const { MOZ_ASSERT(HasImage()); @@ -62,7 +62,7 @@ WebGLFramebuffer::AttachPoint::HasAlpha() const } GLenum -WebGLFramebuffer::GetFormatForAttachment(const WebGLFramebuffer::AttachPoint& attachment) const +WebGLFramebuffer::GetFormatForAttachment(const WebGLFBAttachPoint& attachment) const { MOZ_ASSERT(attachment.IsDefined()); MOZ_ASSERT(attachment.Texture() || attachment.Renderbuffer()); @@ -83,7 +83,7 @@ WebGLFramebuffer::GetFormatForAttachment(const WebGLFramebuffer::AttachPoint& at } TexInternalFormat -WebGLFramebuffer::AttachPoint::EffectiveInternalFormat() const +WebGLFBAttachPoint::EffectiveInternalFormat() const { const WebGLTexture* tex = Texture(); if (tex && tex->HasImageInfoAt(mTexImageTarget, mTexImageLevel)) { @@ -99,7 +99,7 @@ WebGLFramebuffer::AttachPoint::EffectiveInternalFormat() const } bool -WebGLFramebuffer::AttachPoint::IsReadableFloat() const +WebGLFBAttachPoint::IsReadableFloat() const { TexInternalFormat internalformat = EffectiveInternalFormat(); MOZ_ASSERT(internalformat != LOCAL_GL_NONE); @@ -110,7 +110,7 @@ WebGLFramebuffer::AttachPoint::IsReadableFloat() const } static void -UnmarkAttachment(WebGLFramebuffer::AttachPoint& attachment) +UnmarkAttachment(WebGLFBAttachPoint& attachment) { WebGLFramebufferAttachable* maybe = attachment.Texture(); if (!maybe) @@ -121,7 +121,7 @@ UnmarkAttachment(WebGLFramebuffer::AttachPoint& attachment) } void -WebGLFramebuffer::AttachPoint::SetTexImage(WebGLTexture* tex, TexImageTarget target, +WebGLFBAttachPoint::SetTexImage(WebGLTexture* tex, TexImageTarget target, GLint level) { mFB->InvalidateFramebufferStatus(); @@ -138,7 +138,7 @@ WebGLFramebuffer::AttachPoint::SetTexImage(WebGLTexture* tex, TexImageTarget tar } void -WebGLFramebuffer::AttachPoint::SetRenderbuffer(WebGLRenderbuffer* rb) +WebGLFBAttachPoint::SetRenderbuffer(WebGLRenderbuffer* rb) { mFB->InvalidateFramebufferStatus(); @@ -152,7 +152,7 @@ WebGLFramebuffer::AttachPoint::SetRenderbuffer(WebGLRenderbuffer* rb) } bool -WebGLFramebuffer::AttachPoint::HasUninitializedImageData() const +WebGLFBAttachPoint::HasUninitializedImageData() const { if (!HasImage()) return false; @@ -171,7 +171,7 @@ WebGLFramebuffer::AttachPoint::HasUninitializedImageData() const } void -WebGLFramebuffer::AttachPoint::SetImageDataStatus(WebGLImageDataStatus newStatus) +WebGLFBAttachPoint::SetImageDataStatus(WebGLImageDataStatus newStatus) { if (!HasImage()) return; @@ -191,7 +191,7 @@ WebGLFramebuffer::AttachPoint::SetImageDataStatus(WebGLImageDataStatus newStatus } bool -WebGLFramebuffer::AttachPoint::HasImage() const +WebGLFBAttachPoint::HasImage() const { if (Texture() && Texture()->HasImageInfoAt(mTexImageTarget, mTexImageLevel)) return true; @@ -203,7 +203,7 @@ WebGLFramebuffer::AttachPoint::HasImage() const } const WebGLRectangleObject& -WebGLFramebuffer::AttachPoint::RectangleObject() const +WebGLFBAttachPoint::RectangleObject() const { MOZ_ASSERT(HasImage(), "Make sure it has an image before requesting the rectangle."); @@ -285,7 +285,7 @@ WebGLContext::IsFormatValidForFB(GLenum sizedFormat) const } bool -WebGLFramebuffer::AttachPoint::IsComplete() const +WebGLFBAttachPoint::IsComplete() const { if (!HasImage()) return false; @@ -353,7 +353,7 @@ WebGLFramebuffer::AttachPoint::IsComplete() const } void -WebGLFramebuffer::AttachPoint::FinalizeAttachment(gl::GLContext* gl, +WebGLFBAttachPoint::FinalizeAttachment(gl::GLContext* gl, FBAttachment attachmentLoc) const { if (!HasImage()) { @@ -454,7 +454,7 @@ WebGLFramebuffer::FramebufferRenderbuffer(FBAttachment attachPointEnum, return; // `attachPoint` is validated by ValidateFramebufferAttachment(). - AttachPoint& attachPoint = GetAttachPoint(attachPointEnum); + WebGLFBAttachPoint& attachPoint = GetAttachPoint(attachPointEnum); attachPoint.SetRenderbuffer(rb); InvalidateFramebufferStatus(); @@ -481,13 +481,13 @@ WebGLFramebuffer::FramebufferTexture2D(FBAttachment attachPointEnum, } } - AttachPoint& attachPoint = GetAttachPoint(attachPointEnum); + WebGLFBAttachPoint& attachPoint = GetAttachPoint(attachPointEnum); attachPoint.SetTexImage(tex, texImageTarget, level); InvalidateFramebufferStatus(); } -WebGLFramebuffer::AttachPoint& +WebGLFBAttachPoint& WebGLFramebuffer::GetAttachPoint(FBAttachment attachPoint) { switch (attachPoint.get()) { @@ -581,7 +581,7 @@ WebGLFramebuffer::HasDefinedAttachments() const } static bool -IsIncomplete(const WebGLFramebuffer::AttachPoint& cur) +IsIncomplete(const WebGLFBAttachPoint& cur) { return cur.IsDefined() && !cur.IsComplete(); } @@ -631,7 +631,7 @@ WebGLFramebuffer::GetAnyRectObject() const } static bool -RectsMatch(const WebGLFramebuffer::AttachPoint& attachment, +RectsMatch(const WebGLFBAttachPoint& attachment, const WebGLRectangleObject& rect) { return attachment.RectangleObject().HasSameDimensionsAs(rect); @@ -839,7 +839,7 @@ void WebGLFramebuffer::EnsureColorAttachPoints(size_t colorAttachmentId) while (ColorAttachmentCount() < WebGLContext::kMaxColorAttachments) { GLenum nextAttachPoint = LOCAL_GL_COLOR_ATTACHMENT0 + ColorAttachmentCount(); - mMoreColorAttachments.AppendElement(AttachPoint(this, nextAttachPoint)); + mMoreColorAttachments.AppendElement(WebGLFBAttachPoint(this, nextAttachPoint)); } MOZ_ASSERT(ColorAttachmentCount() == WebGLContext::kMaxColorAttachments); @@ -941,20 +941,20 @@ WebGLFramebuffer::ValidateForRead(const char* info, TexInternalFormat* const out // Goop. JSObject* -WebGLFramebuffer::WrapObject(JSContext* cx, JS::Handle aGivenProto) +WebGLFramebuffer::WrapObject(JSContext* cx, JS::Handle givenProto) { - return dom::WebGLFramebufferBinding::Wrap(cx, this, aGivenProto); + return dom::WebGLFramebufferBinding::Wrap(cx, this, givenProto); } inline void -ImplCycleCollectionUnlink(mozilla::WebGLFramebuffer::AttachPoint& field) +ImplCycleCollectionUnlink(mozilla::WebGLFBAttachPoint& field) { field.Unlink(); } inline void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& callback, - mozilla::WebGLFramebuffer::AttachPoint& field, + mozilla::WebGLFBAttachPoint& field, const char* name, uint32_t flags = 0) { diff --git a/dom/canvas/WebGLFramebuffer.h b/dom/canvas/WebGLFramebuffer.h index 7e901c06d404..eeae53c1c825 100644 --- a/dom/canvas/WebGLFramebuffer.h +++ b/dom/canvas/WebGLFramebuffer.h @@ -7,12 +7,17 @@ #define WEBGL_FRAMEBUFFER_H_ #include "mozilla/LinkedList.h" +#include "mozilla/WeakPtr.h" #include "nsWrapperCache.h" + #include "WebGLObjectModel.h" #include "WebGLStrongTypes.h" +#include "WebGLRenderbuffer.h" +#include "WebGLTexture.h" namespace mozilla { +class WebGLFramebuffer; class WebGLRenderbuffer; class WebGLTexture; @@ -20,6 +25,72 @@ namespace gl { class GLContext; } // namespace gl +class WebGLFBAttachPoint +{ +public: + WebGLFramebuffer* const mFB; +private: + WebGLRefPtr mTexturePtr; + WebGLRefPtr mRenderbufferPtr; + FBAttachment mAttachmentPoint; + TexImageTarget mTexImageTarget; + GLint mTexImageLevel; + +public: + WebGLFBAttachPoint(WebGLFramebuffer* fb, FBAttachment attachmentPoint); + ~WebGLFBAttachPoint(); + + void Unlink() { + mRenderbufferPtr = nullptr; + mTexturePtr = nullptr; + } + + bool IsDefined() const; + bool IsDeleteRequested() const; + + TexInternalFormat EffectiveInternalFormat() const; + + bool HasAlpha() const; + bool IsReadableFloat() const; + + void Clear() { + SetRenderbuffer(nullptr); + } + + void SetTexImage(WebGLTexture* tex, TexImageTarget target, GLint level); + void SetRenderbuffer(WebGLRenderbuffer* rb); + + const WebGLTexture* Texture() const { + return mTexturePtr; + } + WebGLTexture* Texture() { + return mTexturePtr; + } + const WebGLRenderbuffer* Renderbuffer() const { + return mRenderbufferPtr; + } + WebGLRenderbuffer* Renderbuffer() { + return mRenderbufferPtr; + } + TexImageTarget ImageTarget() const { + return mTexImageTarget; + } + GLint MipLevel() const { + return mTexImageLevel; + } + + bool HasUninitializedImageData() const; + void SetImageDataStatus(WebGLImageDataStatus x); + + const WebGLRectangleObject& RectangleObject() const; + + bool HasImage() const; + bool IsComplete() const; + + void FinalizeAttachment(gl::GLContext* gl, + FBAttachment attachmentLoc) const; +}; + class WebGLFramebuffer final : public nsWrapperCache , public WebGLRefCountedObject @@ -32,72 +103,6 @@ class WebGLFramebuffer final public: MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLFramebuffer) - class AttachPoint - { - public: - WebGLFramebuffer* const mFB; - private: - WebGLRefPtr mTexturePtr; - WebGLRefPtr mRenderbufferPtr; - FBAttachment mAttachmentPoint; - TexImageTarget mTexImageTarget; - GLint mTexImageLevel; - - public: - AttachPoint(WebGLFramebuffer* fb, FBAttachment attachmentPoint); - ~AttachPoint(); - - void Unlink() { - mRenderbufferPtr = nullptr; - mTexturePtr = nullptr; - } - - bool IsDefined() const; - bool IsDeleteRequested() const; - - TexInternalFormat EffectiveInternalFormat() const; - - bool HasAlpha() const; - bool IsReadableFloat() const; - - void Clear() { - SetRenderbuffer(nullptr); - } - - void SetTexImage(WebGLTexture* tex, TexImageTarget target, GLint level); - void SetRenderbuffer(WebGLRenderbuffer* rb); - - const WebGLTexture* Texture() const { - return mTexturePtr; - } - WebGLTexture* Texture() { - return mTexturePtr; - } - const WebGLRenderbuffer* Renderbuffer() const { - return mRenderbufferPtr; - } - WebGLRenderbuffer* Renderbuffer() { - return mRenderbufferPtr; - } - TexImageTarget ImageTarget() const { - return mTexImageTarget; - } - GLint MipLevel() const { - return mTexImageLevel; - } - - bool HasUninitializedImageData() const; - void SetImageDataStatus(WebGLImageDataStatus x); - - const WebGLRectangleObject& RectangleObject() const; - - bool HasImage() const; - bool IsComplete() const; - - void FinalizeAttachment(gl::GLContext* gl, - FBAttachment attachmentLoc) const; - }; - const GLuint mGLName; private: @@ -106,11 +111,11 @@ private: GLenum mReadBufferMode; // No need to chase pointers for the oft-used color0. - AttachPoint mColorAttachment0; - AttachPoint mDepthAttachment; - AttachPoint mStencilAttachment; - AttachPoint mDepthStencilAttachment; - nsTArray mMoreColorAttachments; + WebGLFBAttachPoint mColorAttachment0; + WebGLFBAttachPoint mDepthAttachment; + WebGLFBAttachPoint mStencilAttachment; + WebGLFBAttachPoint mDepthStencilAttachment; + nsTArray mMoreColorAttachments; #ifdef ANDROID // Bug 1140459: Some drivers (including our test slaves!) don't @@ -148,7 +153,7 @@ public: FBStatus CheckFramebufferStatus() const; GLenum - GetFormatForAttachment(const WebGLFramebuffer::AttachPoint& attachment) const; + GetFormatForAttachment(const WebGLFBAttachPoint& attachment) const; bool HasDepthStencilConflict() const { return int(mDepthAttachment.IsDefined()) + @@ -159,25 +164,25 @@ public: size_t ColorAttachmentCount() const { return 1 + mMoreColorAttachments.Length(); } - const AttachPoint& ColorAttachment(size_t colorAttachmentId) const { + const WebGLFBAttachPoint& ColorAttachment(size_t colorAttachmentId) const { MOZ_ASSERT(colorAttachmentId < ColorAttachmentCount()); return colorAttachmentId ? mMoreColorAttachments[colorAttachmentId - 1] : mColorAttachment0; } - const AttachPoint& DepthAttachment() const { + const WebGLFBAttachPoint& DepthAttachment() const { return mDepthAttachment; } - const AttachPoint& StencilAttachment() const { + const WebGLFBAttachPoint& StencilAttachment() const { return mStencilAttachment; } - const AttachPoint& DepthStencilAttachment() const { + const WebGLFBAttachPoint& DepthStencilAttachment() const { return mDepthStencilAttachment; } - AttachPoint& GetAttachPoint(FBAttachment attachPointEnum); + WebGLFBAttachPoint& GetAttachPoint(FBAttachment attachPointEnum); void DetachTexture(const WebGLTexture* tex); @@ -191,7 +196,7 @@ public: void FinalizeAttachments() const; - virtual JSObject* WrapObject(JSContext* cx, JS::Handle aGivenProto) override; + virtual JSObject* WrapObject(JSContext* cx, JS::Handle givenProto) override; NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLFramebuffer) NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLFramebuffer) diff --git a/dom/canvas/WebGLFramebufferAttachable.cpp b/dom/canvas/WebGLFramebufferAttachable.cpp index 52050794c26d..fd92b80f8c36 100644 --- a/dom/canvas/WebGLFramebufferAttachable.cpp +++ b/dom/canvas/WebGLFramebufferAttachable.cpp @@ -5,15 +5,12 @@ #include "WebGLFramebufferAttachable.h" -#include "WebGLContext.h" #include "WebGLFramebuffer.h" -#include "WebGLRenderbuffer.h" -#include "WebGLTexture.h" namespace mozilla { void -WebGLFramebufferAttachable::MarkAttachment(const WebGLFramebuffer::AttachPoint& attachment) +WebGLFramebufferAttachable::MarkAttachment(const WebGLFBAttachPoint& attachment) { if (mAttachmentPoints.Contains(&attachment)) return; // Already attached. Ignore. @@ -22,7 +19,7 @@ WebGLFramebufferAttachable::MarkAttachment(const WebGLFramebuffer::AttachPoint& } void -WebGLFramebufferAttachable::UnmarkAttachment(const WebGLFramebuffer::AttachPoint& attachment) +WebGLFramebufferAttachable::UnmarkAttachment(const WebGLFBAttachPoint& attachment) { const size_t i = mAttachmentPoints.IndexOf(&attachment); if (i == mAttachmentPoints.NoIndex) { diff --git a/dom/canvas/WebGLFramebufferAttachable.h b/dom/canvas/WebGLFramebufferAttachable.h index b312229506b2..a65cf34fce61 100644 --- a/dom/canvas/WebGLFramebufferAttachable.h +++ b/dom/canvas/WebGLFramebufferAttachable.h @@ -6,22 +6,19 @@ #ifndef WEBGL_FRAMEBUFFER_ATTACHABLE_H_ #define WEBGL_FRAMEBUFFER_ATTACHABLE_H_ -#include "GLDefs.h" -#include "mozilla/WeakPtr.h" #include "nsTArray.h" -#include "WebGLFramebuffer.h" -#include "WebGLStrongTypes.h" namespace mozilla { +class WebGLFBAttachPoint; class WebGLFramebufferAttachable { - nsTArray mAttachmentPoints; + nsTArray mAttachmentPoints; public: // Track FBO/Attachment combinations - void MarkAttachment(const WebGLFramebuffer::AttachPoint& attachment); - void UnmarkAttachment(const WebGLFramebuffer::AttachPoint& attachment); + void MarkAttachment(const WebGLFBAttachPoint& attachment); + void UnmarkAttachment(const WebGLFBAttachPoint& attachment); void InvalidateStatusOfAttachedFBs() const; }; diff --git a/dom/canvas/WebGLMemoryTracker.cpp b/dom/canvas/WebGLMemoryTracker.cpp new file mode 100644 index 000000000000..b13d9d7c43bd --- /dev/null +++ b/dom/canvas/WebGLMemoryTracker.cpp @@ -0,0 +1,275 @@ +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* 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/. */ + +#include "WebGLMemoryTracker.h" + +#include "WebGLBuffer.h" +#include "WebGLContext.h" +#include "WebGLVertexAttribData.h" +#include "WebGLProgram.h" +#include "WebGLRenderbuffer.h" +#include "WebGLShader.h" +#include "WebGLTexture.h" +#include "WebGLUniformLocation.h" + +namespace mozilla { + +NS_IMPL_ISUPPORTS(WebGLObserver, nsIObserver) + +NS_IMETHODIMP +WebGLMemoryTracker::CollectReports(nsIHandleReportCallback* handleReport, + nsISupports* data, bool) +{ +#define REPORT(_path, _kind, _units, _amount, _desc) \ + do { \ + nsresult rv; \ + rv = handleReport->Callback(EmptyCString(), NS_LITERAL_CSTRING(_path), \ + _kind, _units, _amount, \ + NS_LITERAL_CSTRING(_desc), data); \ + NS_ENSURE_SUCCESS(rv, rv); \ + } while (0) + + REPORT("webgl-texture-memory", + KIND_OTHER, UNITS_BYTES, GetTextureMemoryUsed(), + "Memory used by WebGL textures.The OpenGL" + " implementation is free to store these textures in either video" + " memory or main memory. This measurement is only a lower bound," + " actual memory usage may be higher for example if the storage" + " is strided."); + + REPORT("webgl-texture-count", + KIND_OTHER, UNITS_COUNT, GetTextureCount(), + "Number of WebGL textures."); + + REPORT("webgl-buffer-memory", + KIND_OTHER, UNITS_BYTES, GetBufferMemoryUsed(), + "Memory used by WebGL buffers. The OpenGL" + " implementation is free to store these buffers in either video" + " memory or main memory. This measurement is only a lower bound," + " actual memory usage may be higher for example if the storage" + " is strided."); + + REPORT("explicit/webgl/buffer-cache-memory", + KIND_HEAP, UNITS_BYTES, GetBufferCacheMemoryUsed(), + "Memory used by WebGL buffer caches. The WebGL" + " implementation caches the contents of element array buffers" + " only.This adds up with the webgl-buffer-memory value, but" + " contrary to it, this one represents bytes on the heap," + " not managed by OpenGL."); + + REPORT("webgl-buffer-count", + KIND_OTHER, UNITS_COUNT, GetBufferCount(), + "Number of WebGL buffers."); + + REPORT("webgl-renderbuffer-memory", + KIND_OTHER, UNITS_BYTES, GetRenderbufferMemoryUsed(), + "Memory used by WebGL renderbuffers. The OpenGL" + " implementation is free to store these renderbuffers in either" + " video memory or main memory. This measurement is only a lower" + " bound, actual memory usage may be higher for example if the" + " storage is strided."); + + REPORT("webgl-renderbuffer-count", + KIND_OTHER, UNITS_COUNT, GetRenderbufferCount(), + "Number of WebGL renderbuffers."); + + REPORT("explicit/webgl/shader", + KIND_HEAP, UNITS_BYTES, GetShaderSize(), + "Combined size of WebGL shader ASCII sources and translation" + " logs cached on the heap."); + + REPORT("webgl-shader-count", + KIND_OTHER, UNITS_COUNT, GetShaderCount(), + "Number of WebGL shaders."); + + REPORT("webgl-context-count", + KIND_OTHER, UNITS_COUNT, GetContextCount(), + "Number of WebGL contexts."); + +#undef REPORT + + return NS_OK; +} + +NS_IMPL_ISUPPORTS(WebGLMemoryTracker, nsIMemoryReporter) + +StaticRefPtr WebGLMemoryTracker::sUniqueInstance; + +WebGLMemoryTracker* +WebGLMemoryTracker::UniqueInstance() +{ + if (!sUniqueInstance) { + sUniqueInstance = new WebGLMemoryTracker; + sUniqueInstance->InitMemoryReporter(); + } + return sUniqueInstance; +} + +WebGLMemoryTracker::WebGLMemoryTracker() +{ +} + +void +WebGLMemoryTracker::InitMemoryReporter() +{ + RegisterWeakMemoryReporter(this); +} + +WebGLMemoryTracker::~WebGLMemoryTracker() +{ + UnregisterWeakMemoryReporter(this); +} + +MOZ_DEFINE_MALLOC_SIZE_OF(WebGLBufferMallocSizeOf) + +int64_t +WebGLMemoryTracker::GetBufferCacheMemoryUsed() +{ + const ContextsArrayType& contexts = Contexts(); + int64_t result = 0; + for(size_t i = 0; i < contexts.Length(); ++i) { + for (const WebGLBuffer* buffer = contexts[i]->mBuffers.getFirst(); + buffer; + buffer = buffer->getNext()) + { + if (buffer->Content() == WebGLBuffer::Kind::ElementArray) { + result += buffer->SizeOfIncludingThis(WebGLBufferMallocSizeOf); + } + } + } + return result; +} + +MOZ_DEFINE_MALLOC_SIZE_OF(WebGLShaderMallocSizeOf) + +int64_t +WebGLMemoryTracker::GetShaderSize() +{ + const ContextsArrayType& contexts = Contexts(); + int64_t result = 0; + for(size_t i = 0; i < contexts.Length(); ++i) { + for (const WebGLShader* shader = contexts[i]->mShaders.getFirst(); + shader; + shader = shader->getNext()) + { + result += shader->SizeOfIncludingThis(WebGLShaderMallocSizeOf); + } + } + return result; +} + +/*static*/ int64_t +WebGLMemoryTracker::GetTextureMemoryUsed() +{ + const ContextsArrayType & contexts = Contexts(); + int64_t result = 0; + for(size_t i = 0; i < contexts.Length(); ++i) { + for (const WebGLTexture* texture = contexts[i]->mTextures.getFirst(); + texture; + texture = texture->getNext()) + { + result += texture->MemoryUsage(); + } + } + return result; +} + +/*static*/ int64_t +WebGLMemoryTracker::GetTextureCount() +{ + const ContextsArrayType & contexts = Contexts(); + int64_t result = 0; + for(size_t i = 0; i < contexts.Length(); ++i) { + for (const WebGLTexture* texture = contexts[i]->mTextures.getFirst(); + texture; + texture = texture->getNext()) + { + result++; + } + } + return result; +} + +/*static*/ int64_t +WebGLMemoryTracker::GetBufferMemoryUsed() +{ + const ContextsArrayType & contexts = Contexts(); + int64_t result = 0; + for(size_t i = 0; i < contexts.Length(); ++i) { + for (const WebGLBuffer* buffer = contexts[i]->mBuffers.getFirst(); + buffer; + buffer = buffer->getNext()) + { + result += buffer->ByteLength(); + } + } + return result; +} + +/*static*/ int64_t +WebGLMemoryTracker::GetBufferCount() +{ + const ContextsArrayType & contexts = Contexts(); + int64_t result = 0; + for(size_t i = 0; i < contexts.Length(); ++i) { + for (const WebGLBuffer* buffer = contexts[i]->mBuffers.getFirst(); + buffer; + buffer = buffer->getNext()) + { + result++; + } + } + return result; +} + +/*static*/ int64_t +WebGLMemoryTracker::GetRenderbufferMemoryUsed() +{ + const ContextsArrayType & contexts = Contexts(); + int64_t result = 0; + for(size_t i = 0; i < contexts.Length(); ++i) { + for (const WebGLRenderbuffer* rb = contexts[i]->mRenderbuffers.getFirst(); + rb; + rb = rb->getNext()) + { + result += rb->MemoryUsage(); + } + } + return result; +} + +/*static*/ int64_t +WebGLMemoryTracker::GetRenderbufferCount() +{ + const ContextsArrayType & contexts = Contexts(); + int64_t result = 0; + for(size_t i = 0; i < contexts.Length(); ++i) { + for (const WebGLRenderbuffer* rb = contexts[i]->mRenderbuffers.getFirst(); + rb; + rb = rb->getNext()) + { + result++; + } + } + return result; +} + +/*static*/ int64_t +WebGLMemoryTracker::GetShaderCount() +{ + const ContextsArrayType & contexts = Contexts(); + int64_t result = 0; + for(size_t i = 0; i < contexts.Length(); ++i) { + for (const WebGLShader* shader = contexts[i]->mShaders.getFirst(); + shader; + shader = shader->getNext()) + { + result++; + } + } + return result; +} + +} // namespace mozilla diff --git a/dom/canvas/WebGLMemoryTracker.h b/dom/canvas/WebGLMemoryTracker.h index 1c35cbef2fcb..2f4b63e6e9fa 100644 --- a/dom/canvas/WebGLMemoryTracker.h +++ b/dom/canvas/WebGLMemoryTracker.h @@ -8,17 +8,11 @@ #include "mozilla/StaticPtr.h" #include "nsIMemoryReporter.h" -#include "WebGLBuffer.h" -#include "WebGLContext.h" -#include "WebGLVertexAttribData.h" -#include "WebGLProgram.h" -#include "WebGLRenderbuffer.h" -#include "WebGLShader.h" -#include "WebGLTexture.h" -#include "WebGLUniformLocation.h" namespace mozilla { +class WebGLContext; + class WebGLMemoryTracker : public nsIMemoryReporter { NS_DECL_THREADSAFE_ISUPPORTS @@ -58,107 +52,23 @@ class WebGLMemoryTracker : public nsIMemoryReporter private: virtual ~WebGLMemoryTracker(); - static int64_t GetTextureMemoryUsed() { - const ContextsArrayType & contexts = Contexts(); - int64_t result = 0; - for(size_t i = 0; i < contexts.Length(); ++i) { - for (const WebGLTexture* texture = contexts[i]->mTextures.getFirst(); - texture; - texture = texture->getNext()) - { - result += texture->MemoryUsage(); - } - } - return result; - } + static int64_t GetTextureMemoryUsed(); - static int64_t GetTextureCount() { - const ContextsArrayType & contexts = Contexts(); - int64_t result = 0; - for(size_t i = 0; i < contexts.Length(); ++i) { - for (const WebGLTexture* texture = contexts[i]->mTextures.getFirst(); - texture; - texture = texture->getNext()) - { - result++; - } - } - return result; - } + static int64_t GetTextureCount(); - static int64_t GetBufferMemoryUsed() { - const ContextsArrayType & contexts = Contexts(); - int64_t result = 0; - for(size_t i = 0; i < contexts.Length(); ++i) { - for (const WebGLBuffer* buffer = contexts[i]->mBuffers.getFirst(); - buffer; - buffer = buffer->getNext()) - { - result += buffer->ByteLength(); - } - } - return result; - } + static int64_t GetBufferMemoryUsed(); static int64_t GetBufferCacheMemoryUsed(); - static int64_t GetBufferCount() { - const ContextsArrayType & contexts = Contexts(); - int64_t result = 0; - for(size_t i = 0; i < contexts.Length(); ++i) { - for (const WebGLBuffer* buffer = contexts[i]->mBuffers.getFirst(); - buffer; - buffer = buffer->getNext()) - { - result++; - } - } - return result; - } + static int64_t GetBufferCount(); - static int64_t GetRenderbufferMemoryUsed() { - const ContextsArrayType & contexts = Contexts(); - int64_t result = 0; - for(size_t i = 0; i < contexts.Length(); ++i) { - for (const WebGLRenderbuffer* rb = contexts[i]->mRenderbuffers.getFirst(); - rb; - rb = rb->getNext()) - { - result += rb->MemoryUsage(); - } - } - return result; - } + static int64_t GetRenderbufferMemoryUsed(); - static int64_t GetRenderbufferCount() { - const ContextsArrayType & contexts = Contexts(); - int64_t result = 0; - for(size_t i = 0; i < contexts.Length(); ++i) { - for (const WebGLRenderbuffer* rb = contexts[i]->mRenderbuffers.getFirst(); - rb; - rb = rb->getNext()) - { - result++; - } - } - return result; - } + static int64_t GetRenderbufferCount(); static int64_t GetShaderSize(); - static int64_t GetShaderCount() { - const ContextsArrayType & contexts = Contexts(); - int64_t result = 0; - for(size_t i = 0; i < contexts.Length(); ++i) { - for (const WebGLShader* shader = contexts[i]->mShaders.getFirst(); - shader; - shader = shader->getNext()) - { - result++; - } - } - return result; - } + static int64_t GetShaderCount(); static int64_t GetContextCount() { return Contexts().Length(); diff --git a/dom/canvas/WebGLObjectModel.h b/dom/canvas/WebGLObjectModel.h index 311458d36a96..fa489d7bc24a 100644 --- a/dom/canvas/WebGLObjectModel.h +++ b/dom/canvas/WebGLObjectModel.h @@ -7,7 +7,7 @@ #define WEBGLOBJECTMODEL_H_ #include "nsCycleCollectionNoteChild.h" -#include "nsICanvasRenderingContextInternal.h" + #include "WebGLTypes.h" namespace mozilla { diff --git a/dom/canvas/WebGLProgram.cpp b/dom/canvas/WebGLProgram.cpp index 709978b620d2..38da7316367d 100644 --- a/dom/canvas/WebGLProgram.cpp +++ b/dom/canvas/WebGLProgram.cpp @@ -6,7 +6,11 @@ #include "WebGLProgram.h" #include "GLContext.h" +#include "mozilla/CheckedInt.h" +#include "mozilla/dom/WebGL2RenderingContextBinding.h" #include "mozilla/dom/WebGLRenderingContextBinding.h" +#include "nsRefPtr.h" +#include "WebGLActiveInfo.h" #include "WebGLContext.h" #include "WebGLShader.h" #include "WebGLUniformLocation.h" @@ -67,12 +71,12 @@ ParseName(const nsCString& name, nsCString* const out_baseName, static void AddActiveInfo(WebGLContext* webgl, GLint elemCount, GLenum elemType, bool isArray, const nsACString& baseUserName, const nsACString& baseMappedName, - std::vector>* activeInfoList, + std::vector>* activeInfoList, std::map* infoLocMap) { - nsRefPtr info = new WebGLActiveInfo(webgl, elemCount, elemType, - isArray, baseUserName, - baseMappedName); + RefPtr info = new WebGLActiveInfo(webgl, elemCount, elemType, + isArray, baseUserName, + baseMappedName); activeInfoList->push_back(info); infoLocMap->insert(std::make_pair(info->mBaseUserName, info.get())); @@ -202,10 +206,10 @@ QueryProgramInfo(WebGLProgram* prog, gl::GLContext* gl) // By GLES 3, GetUniformLocation("foo[0]") should return -1 if `foo` is // not an array. Our current linux Try slaves return the location of `foo` // anyways, though. - std::string mappedName = baseMappedName.BeginReading(); - mappedName += "[0]"; + std::string mappedNameStr = baseMappedName.BeginReading(); + mappedNameStr += "[0]"; - GLint loc = gl->fGetUniformLocation(prog->mGLName, mappedName.c_str()); + GLint loc = gl->fGetUniformLocation(prog->mGLName, mappedNameStr.c_str()); if (loc != -1) isArray = true; } @@ -246,14 +250,17 @@ QueryProgramInfo(WebGLProgram* prog, gl::GLContext* gl) MOZ_CRASH("Failed to parse `mappedName` received from driver."); nsAutoCString baseUserName; - if (!prog->FindUniformBlockByMappedName(baseMappedName, &baseUserName, &isArray)) { + if (!prog->FindUniformBlockByMappedName(baseMappedName, &baseUserName, + &isArray)) + { baseUserName = baseMappedName; if (needsCheckForArrays && !isArray) { - std::string mappedName = baseMappedName.BeginReading(); - mappedName += "[0]"; + std::string mappedNameStr = baseMappedName.BeginReading(); + mappedNameStr += "[0]"; - GLuint loc = gl->fGetUniformBlockIndex(prog->mGLName, mappedName.c_str()); + GLuint loc = gl->fGetUniformBlockIndex(prog->mGLName, + mappedNameStr.c_str()); if (loc != LOCAL_GL_INVALID_INDEX) isArray = true; } @@ -277,8 +284,8 @@ QueryProgramInfo(WebGLProgram* prog, gl::GLContext* gl) //////////////////////////////////////////////////////////////////////////////// -webgl::LinkedProgramInfo::LinkedProgramInfo(WebGLProgram* aProg) - : prog(aProg) +webgl::LinkedProgramInfo::LinkedProgramInfo(WebGLProgram* prog) + : prog(prog) , fragDataMap(nullptr) { } @@ -300,6 +307,11 @@ WebGLProgram::WebGLProgram(WebGLContext* webgl) mContext->mPrograms.insertBack(this); } +WebGLProgram::~WebGLProgram() +{ + DeleteOnce(); +} + void WebGLProgram::Delete() { @@ -425,7 +437,7 @@ WebGLProgram::GetActiveAttrib(GLuint index) const return nullptr; } - nsRefPtr ret = activeList[index]; + RefPtr ret = activeList[index]; return ret.forget(); } @@ -446,7 +458,7 @@ WebGLProgram::GetActiveUniform(GLuint index) const return nullptr; } - nsRefPtr ret = activeList[index]; + RefPtr ret = activeList[index]; return ret.forget(); } @@ -627,7 +639,7 @@ WebGLProgram::GetActiveUniformBlockName(GLuint uniformBlockIndex, nsAString& ret void WebGLProgram::GetActiveUniformBlockParam(GLuint uniformBlockIndex, GLenum pname, - Nullable& retval) const + dom::Nullable& retval) const { retval.SetNull(); if (!IsLinked()) { @@ -663,7 +675,7 @@ WebGLProgram::GetActiveUniformBlockParam(GLuint uniformBlockIndex, GLenum pname, void WebGLProgram::GetActiveUniformBlockActiveUniforms(JSContext* cx, GLuint uniformBlockIndex, - Nullable& retval, + dom::Nullable& retval, ErrorResult& rv) const { if (!IsLinked()) { @@ -1013,7 +1025,7 @@ WebGLProgram::GetTransformFeedbackVarying(GLuint index) LinkInfo()->FindAttrib(varyingUserName, (const WebGLActiveInfo**) &info); MOZ_ASSERT(info); - nsRefPtr ret(info); + RefPtr ret(info); return ret.forget(); } @@ -1034,9 +1046,9 @@ WebGLProgram::FindUniformBlockByMappedName(const nsACString& mappedName, //////////////////////////////////////////////////////////////////////////////// JSObject* -WebGLProgram::WrapObject(JSContext* js, JS::Handle aGivenProto) +WebGLProgram::WrapObject(JSContext* js, JS::Handle givenProto) { - return dom::WebGLProgramBinding::Wrap(js, this, aGivenProto); + return dom::WebGLProgramBinding::Wrap(js, this, givenProto); } NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WebGLProgram, mVertShader, mFragShader) diff --git a/dom/canvas/WebGLProgram.h b/dom/canvas/WebGLProgram.h index 05e2dd74fde8..030bd84f8db4 100644 --- a/dom/canvas/WebGLProgram.h +++ b/dom/canvas/WebGLProgram.h @@ -7,22 +7,33 @@ #define WEBGL_PROGRAM_H_ #include -#include "mozilla/CheckedInt.h" -#include "mozilla/LinkedList.h" -#include "mozilla/dom/WebGL2RenderingContextBinding.h" -#include "nsString.h" -#include "nsWrapperCache.h" #include #include + +#include "mozilla/LinkedList.h" +#include "mozilla/RefPtr.h" +#include "mozilla/WeakPtr.h" +#include "nsString.h" +#include "nsWrapperCache.h" + #include "WebGLObjectModel.h" -#include "WebGLShader.h" + + +template class nsRefPtr; namespace mozilla { - +class ErrorResult; class WebGLActiveInfo; class WebGLProgram; +class WebGLShader; class WebGLUniformLocation; +namespace dom { +template struct Nullable; +class OwningUnsignedLongOrUint32ArrayOrBoolean; +template class Sequence; +} // namespace dom + namespace webgl { struct UniformBlockInfo final @@ -48,8 +59,8 @@ struct LinkedProgramInfo final MOZ_DECLARE_WEAKREFERENCE_TYPENAME(LinkedProgramInfo) WebGLProgram* const prog; - std::vector> activeAttribs; - std::vector> activeUniforms; + std::vector> activeAttribs; + std::vector> activeUniforms; // Needed for Get{Attrib,Uniform}Location. The keys for these are non-mapped // user-facing `GLActiveInfo::name`s, without any final "[0]". @@ -62,7 +73,7 @@ struct LinkedProgramInfo final // Needed for draw call validation. std::set activeAttribLocs; - explicit LinkedProgramInfo(WebGLProgram* aProg); + explicit LinkedProgramInfo(WebGLProgram* prog); bool FindAttrib(const nsCString& baseUserName, const WebGLActiveInfo** const out_activeInfo) const @@ -119,10 +130,6 @@ struct LinkedProgramInfo final } // namespace webgl -class WebGLShader; - -typedef nsDataHashtable CStringMap; - class WebGLProgram final : public nsWrapperCache , public WebGLRefCountedObject @@ -151,9 +158,9 @@ public: GLuint GetUniformBlockIndex(const nsAString& name) const; void GetActiveUniformBlockName(GLuint uniformBlockIndex, nsAString& name) const; void GetActiveUniformBlockParam(GLuint uniformBlockIndex, GLenum pname, - Nullable& retval) const; + dom::Nullable& retval) const; void GetActiveUniformBlockActiveUniforms(JSContext* cx, GLuint uniformBlockIndex, - Nullable& retval, + dom::Nullable& retval, ErrorResult& rv) const; already_AddRefed GetUniformLocation(const nsAString& name) const; void UniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) const; @@ -187,12 +194,10 @@ public: return Context(); } - virtual JSObject* WrapObject(JSContext* js, JS::Handle aGivenProto) override; + virtual JSObject* WrapObject(JSContext* js, JS::Handle givenProto) override; private: - ~WebGLProgram() { - DeleteOnce(); - } + ~WebGLProgram(); bool LinkAndUpdate(); diff --git a/dom/canvas/WebGLQuery.cpp b/dom/canvas/WebGLQuery.cpp index a17bd041630d..63c92861ef94 100644 --- a/dom/canvas/WebGLQuery.cpp +++ b/dom/canvas/WebGLQuery.cpp @@ -13,9 +13,9 @@ namespace mozilla { JSObject* -WebGLQuery::WrapObject(JSContext* cx, JS::Handle aGivenProto) +WebGLQuery::WrapObject(JSContext* cx, JS::Handle givenProto) { - return dom::WebGLQueryBinding::Wrap(cx, this, aGivenProto); + return dom::WebGLQueryBinding::Wrap(cx, this, givenProto); } WebGLQuery::WebGLQuery(WebGLContext* webgl) diff --git a/dom/canvas/WebGLQuery.h b/dom/canvas/WebGLQuery.h index 053e2f4d6a4b..46cd561c3efd 100644 --- a/dom/canvas/WebGLQuery.h +++ b/dom/canvas/WebGLQuery.h @@ -8,6 +8,7 @@ #include "mozilla/LinkedList.h" #include "nsWrapperCache.h" + #include "WebGLObjectModel.h" namespace mozilla { @@ -36,7 +37,7 @@ public: } // NS - virtual JSObject* WrapObject(JSContext* cx, JS::Handle aGivenProto) override; + virtual JSObject* WrapObject(JSContext* cx, JS::Handle givenProto) override; NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLQuery) NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLQuery) diff --git a/dom/canvas/WebGLRenderbuffer.cpp b/dom/canvas/WebGLRenderbuffer.cpp index d9583dcd57fd..05b6023a6f96 100644 --- a/dom/canvas/WebGLRenderbuffer.cpp +++ b/dom/canvas/WebGLRenderbuffer.cpp @@ -9,6 +9,7 @@ #include "mozilla/dom/WebGLRenderingContextBinding.h" #include "ScopedGLHelpers.h" #include "WebGLContext.h" +#include "WebGLStrongTypes.h" #include "WebGLTexture.h" namespace mozilla { @@ -41,9 +42,9 @@ NeedsDepthStencilEmu(gl::GLContext* gl, GLenum internalFormat) } JSObject* -WebGLRenderbuffer::WrapObject(JSContext* cx, JS::Handle aGivenProto) +WebGLRenderbuffer::WrapObject(JSContext* cx, JS::Handle givenProto) { - return dom::WebGLRenderbufferBinding::Wrap(cx, this, aGivenProto); + return dom::WebGLRenderbufferBinding::Wrap(cx, this, givenProto); } WebGLRenderbuffer::WebGLRenderbuffer(WebGLContext* webgl) diff --git a/dom/canvas/WebGLRenderbuffer.h b/dom/canvas/WebGLRenderbuffer.h index 440dfdba5590..40d235faa276 100644 --- a/dom/canvas/WebGLRenderbuffer.h +++ b/dom/canvas/WebGLRenderbuffer.h @@ -8,8 +8,10 @@ #include "mozilla/LinkedList.h" #include "nsWrapperCache.h" + #include "WebGLFramebufferAttachable.h" #include "WebGLObjectModel.h" +#include "WebGLStrongTypes.h" namespace mozilla { @@ -64,7 +66,7 @@ public: // Only handles a subset of `pname`s. GLint GetRenderbufferParameter(RBTarget target, RBParam pname) const; - virtual JSObject* WrapObject(JSContext* cx, JS::Handle aGivenProto) override; + virtual JSObject* WrapObject(JSContext* cx, JS::Handle givenProto) override; NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLRenderbuffer) NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLRenderbuffer) diff --git a/dom/canvas/WebGLSampler.cpp b/dom/canvas/WebGLSampler.cpp index 8f91968586b5..ed2695de31a8 100644 --- a/dom/canvas/WebGLSampler.cpp +++ b/dom/canvas/WebGLSampler.cpp @@ -39,9 +39,9 @@ WebGLSampler::GetParentObject() const } JSObject* -WebGLSampler::WrapObject(JSContext* cx, JS::Handle aGivenProto) +WebGLSampler::WrapObject(JSContext* cx, JS::Handle givenProto) { - return dom::WebGLSamplerBinding::Wrap(cx, this, aGivenProto); + return dom::WebGLSamplerBinding::Wrap(cx, this, givenProto); } diff --git a/dom/canvas/WebGLSampler.h b/dom/canvas/WebGLSampler.h index 8ab1387c9b05..a0d65358a271 100644 --- a/dom/canvas/WebGLSampler.h +++ b/dom/canvas/WebGLSampler.h @@ -28,7 +28,7 @@ public: void Delete(); WebGLContext* GetParentObject() const; - virtual JSObject* WrapObject(JSContext* cx, JS::Handle aGivenProto) override; + virtual JSObject* WrapObject(JSContext* cx, JS::Handle givenProto) override; private: diff --git a/dom/canvas/WebGLShader.cpp b/dom/canvas/WebGLShader.cpp index de311d679a0a..b7308213f75a 100644 --- a/dom/canvas/WebGLShader.cpp +++ b/dom/canvas/WebGLShader.cpp @@ -403,9 +403,9 @@ WebGLShader::ApplyTransformFeedbackVaryings(GLuint prog, // Boilerplate JSObject* -WebGLShader::WrapObject(JSContext* js, JS::Handle aGivenProto) +WebGLShader::WrapObject(JSContext* js, JS::Handle givenProto) { - return dom::WebGLShaderBinding::Wrap(js, this, aGivenProto); + return dom::WebGLShaderBinding::Wrap(js, this, givenProto); } size_t diff --git a/dom/canvas/WebGLShader.h b/dom/canvas/WebGLShader.h index 9afdbe93f8ca..9ce423c55192 100644 --- a/dom/canvas/WebGLShader.h +++ b/dom/canvas/WebGLShader.h @@ -6,10 +6,15 @@ #ifndef WEBGL_SHADER_H_ #define WEBGL_SHADER_H_ +#include +#include + #include "GLDefs.h" #include "mozilla/LinkedList.h" #include "mozilla/MemoryReporting.h" +#include "nsString.h" #include "nsWrapperCache.h" + #include "WebGLObjectModel.h" namespace mozilla { @@ -65,12 +70,12 @@ public: std::vector* out_mappedVaryings) const; // Other funcs - size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; + size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const; void Delete(); WebGLContext* GetParentObject() const { return Context(); } - virtual JSObject* WrapObject(JSContext* js, JS::Handle aGivenProto) override; + virtual JSObject* WrapObject(JSContext* js, JS::Handle givenProto) override; NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLShader) NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLShader) diff --git a/dom/canvas/WebGLShaderPrecisionFormat.cpp b/dom/canvas/WebGLShaderPrecisionFormat.cpp index 181964c3cb2e..f1590878b67e 100644 --- a/dom/canvas/WebGLShaderPrecisionFormat.cpp +++ b/dom/canvas/WebGLShaderPrecisionFormat.cpp @@ -11,11 +11,11 @@ namespace mozilla { bool -WebGLShaderPrecisionFormat::WrapObject(JSContext* aCx, - JS::Handle aGivenProto, - JS::MutableHandle aReflector) +WebGLShaderPrecisionFormat::WrapObject(JSContext* cx, + JS::Handle givenProto, + JS::MutableHandle reflector) { - return dom::WebGLShaderPrecisionFormatBinding::Wrap(aCx, this, aGivenProto, aReflector); + return dom::WebGLShaderPrecisionFormatBinding::Wrap(cx, this, givenProto, reflector); } } // namespace mozilla diff --git a/dom/canvas/WebGLShaderPrecisionFormat.h b/dom/canvas/WebGLShaderPrecisionFormat.h index 1b37dba22e22..49af0db21616 100644 --- a/dom/canvas/WebGLShaderPrecisionFormat.h +++ b/dom/canvas/WebGLShaderPrecisionFormat.h @@ -22,7 +22,7 @@ public: , mPrecision(precision) { } - bool WrapObject(JSContext* aCx, JS::Handle aGivenProto, JS::MutableHandle aReflector); + bool WrapObject(JSContext* cx, JS::Handle givenProto, JS::MutableHandle reflector); // WebIDL WebGLShaderPrecisionFormat API GLint RangeMin() const { diff --git a/dom/canvas/WebGLStrongTypes.h b/dom/canvas/WebGLStrongTypes.h index 10591e1a9fd0..2b5b3ea33d12 100644 --- a/dom/canvas/WebGLStrongTypes.h +++ b/dom/canvas/WebGLStrongTypes.h @@ -6,6 +6,8 @@ #ifndef WEBGL_STRONG_TYPES_H_ #define WEBGL_STRONG_TYPES_H_ +#include + #include "GLDefs.h" #include "mozilla/ArrayUtils.h" #include "mozilla/Assertions.h" diff --git a/dom/canvas/WebGLSync.cpp b/dom/canvas/WebGLSync.cpp index 42dfb9f3c5c8..ae021eace9d4 100644 --- a/dom/canvas/WebGLSync.cpp +++ b/dom/canvas/WebGLSync.cpp @@ -5,7 +5,9 @@ #include "WebGLSync.h" +#include "GLContext.h" #include "mozilla/dom/WebGL2RenderingContextBinding.h" +#include "WebGLContext.h" namespace mozilla { @@ -38,9 +40,9 @@ WebGLSync::GetParentObject() const // ------------------------------------------------------------------------- // IMPLEMENT NS JSObject* -WebGLSync::WrapObject(JSContext* cx, JS::Handle aGivenProto) +WebGLSync::WrapObject(JSContext* cx, JS::Handle givenProto) { - return dom::WebGLSyncBinding::Wrap(cx, this, aGivenProto); + return dom::WebGLSyncBinding::Wrap(cx, this, givenProto); } NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLSync) diff --git a/dom/canvas/WebGLSync.h b/dom/canvas/WebGLSync.h index 7a5ab083b8f5..9893d5a76a23 100644 --- a/dom/canvas/WebGLSync.h +++ b/dom/canvas/WebGLSync.h @@ -26,7 +26,7 @@ public: void Delete(); WebGLContext* GetParentObject() const; - virtual JSObject* WrapObject(JSContext* cx, JS::Handle aGivenProto) override; + virtual JSObject* WrapObject(JSContext* cx, JS::Handle givenProto) override; NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLSync) NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLSync) diff --git a/dom/canvas/WebGLTexture.cpp b/dom/canvas/WebGLTexture.cpp index 7a8828eb6723..3cc49b8fd2fd 100644 --- a/dom/canvas/WebGLTexture.cpp +++ b/dom/canvas/WebGLTexture.cpp @@ -19,8 +19,8 @@ namespace mozilla { JSObject* -WebGLTexture::WrapObject(JSContext* cx, JS::Handle aGivenProto) { - return dom::WebGLTextureBinding::Wrap(cx, this, aGivenProto); +WebGLTexture::WrapObject(JSContext* cx, JS::Handle givenProto) { + return dom::WebGLTextureBinding::Wrap(cx, this, givenProto); } WebGLTexture::WebGLTexture(WebGLContext* webgl, GLuint tex) diff --git a/dom/canvas/WebGLTexture.h b/dom/canvas/WebGLTexture.h index 3116af0e1b83..344d1d518342 100644 --- a/dom/canvas/WebGLTexture.h +++ b/dom/canvas/WebGLTexture.h @@ -7,11 +7,12 @@ #define WEBGL_TEXTURE_H_ #include + #include "mozilla/Assertions.h" #include "mozilla/CheckedInt.h" #include "mozilla/LinkedList.h" -#include "nsAlgorithm.h" #include "nsWrapperCache.h" + #include "WebGLFramebufferAttachable.h" #include "WebGLObjectModel.h" #include "WebGLStrongTypes.h" @@ -47,7 +48,7 @@ public: return Context(); } - virtual JSObject* WrapObject(JSContext* cx, JS::Handle aGivenProto) override; + virtual JSObject* WrapObject(JSContext* cx, JS::Handle givenProto) override; NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLTexture) NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLTexture) diff --git a/dom/canvas/WebGLTimerQuery.cpp b/dom/canvas/WebGLTimerQuery.cpp index e10fdfd495c5..52aa2561674f 100644 --- a/dom/canvas/WebGLTimerQuery.cpp +++ b/dom/canvas/WebGLTimerQuery.cpp @@ -14,14 +14,14 @@ namespace mozilla { JSObject* -WebGLTimerQuery::WrapObject(JSContext* cx, JS::Handle aGivenProto) +WebGLTimerQuery::WrapObject(JSContext* cx, JS::Handle givenProto) { - return dom::WebGLTimerQueryEXTBinding::Wrap(cx, this, aGivenProto); + return dom::WebGLTimerQueryEXTBinding::Wrap(cx, this, givenProto); } -WebGLTimerQuery::WebGLTimerQuery(WebGLContext* webgl, GLuint aName) +WebGLTimerQuery::WebGLTimerQuery(WebGLContext* webgl, GLuint name) : WebGLContextBoundObject(webgl) - , mGLName(aName) + , mGLName(name) , mTarget(LOCAL_GL_NONE) { } diff --git a/dom/canvas/WebGLTimerQuery.h b/dom/canvas/WebGLTimerQuery.h index 9f6205e9e18f..681adc337925 100644 --- a/dom/canvas/WebGLTimerQuery.h +++ b/dom/canvas/WebGLTimerQuery.h @@ -29,7 +29,7 @@ public: WebGLContext* GetParentObject() const; // NS - virtual JSObject* WrapObject(JSContext* cx, JS::Handle aGivenProto) override; + virtual JSObject* WrapObject(JSContext* cx, JS::Handle givenProto) override; const GLenum mGLName; @@ -37,7 +37,7 @@ public: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLTimerQuery) private: - explicit WebGLTimerQuery(WebGLContext* webgl, GLuint aName); + explicit WebGLTimerQuery(WebGLContext* webgl, GLuint name); ~WebGLTimerQuery(); GLenum mTarget; diff --git a/dom/canvas/WebGLTransformFeedback.cpp b/dom/canvas/WebGLTransformFeedback.cpp index 8aabc47a2d0c..a7c97ca4201b 100644 --- a/dom/canvas/WebGLTransformFeedback.cpp +++ b/dom/canvas/WebGLTransformFeedback.cpp @@ -45,9 +45,9 @@ WebGLTransformFeedback::GetParentObject() const } JSObject* -WebGLTransformFeedback::WrapObject(JSContext* cx, JS::Handle aGivenProto) +WebGLTransformFeedback::WrapObject(JSContext* cx, JS::Handle givenProto) { - return dom::WebGLTransformFeedbackBinding::Wrap(cx, this, aGivenProto); + return dom::WebGLTransformFeedbackBinding::Wrap(cx, this, givenProto); } diff --git a/dom/canvas/WebGLTransformFeedback.h b/dom/canvas/WebGLTransformFeedback.h index d373e4929287..7728e247bad7 100644 --- a/dom/canvas/WebGLTransformFeedback.h +++ b/dom/canvas/WebGLTransformFeedback.h @@ -26,7 +26,7 @@ public: void Delete(); WebGLContext* GetParentObject() const; - virtual JSObject* WrapObject(JSContext* cx, JS::Handle aGivenProto) override; + virtual JSObject* WrapObject(JSContext* cx, JS::Handle givenProto) override; const GLuint mGLName; diff --git a/dom/canvas/WebGLUniformLocation.cpp b/dom/canvas/WebGLUniformLocation.cpp index 14f7e774e66c..d4bb55f96780 100644 --- a/dom/canvas/WebGLUniformLocation.cpp +++ b/dom/canvas/WebGLUniformLocation.cpp @@ -321,9 +321,9 @@ WebGLUniformLocation::GetUniform(JSContext* js, WebGLContext* webgl) const //////////////////////////////////////////////////////////////////////////////// JSObject* -WebGLUniformLocation::WrapObject(JSContext* js, JS::Handle aGivenProto) +WebGLUniformLocation::WrapObject(JSContext* js, JS::Handle givenProto) { - return dom::WebGLUniformLocationBinding::Wrap(js, this, aGivenProto); + return dom::WebGLUniformLocationBinding::Wrap(js, this, givenProto); } NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLUniformLocation) diff --git a/dom/canvas/WebGLUniformLocation.h b/dom/canvas/WebGLUniformLocation.h index 13df4cd08535..cb281e34c73d 100644 --- a/dom/canvas/WebGLUniformLocation.h +++ b/dom/canvas/WebGLUniformLocation.h @@ -11,6 +11,7 @@ #include "nsCycleCollectionParticipant.h" // NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS #include "nsISupportsImpl.h" // NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING #include "nsWrapperCache.h" + #include "WebGLObjectModel.h" struct JSContext; @@ -32,13 +33,12 @@ public: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLUniformLocation) NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLUniformLocation) - virtual JSObject* WrapObject(JSContext* js, JS::Handle aGivenProto) override; + virtual JSObject* WrapObject(JSContext* js, JS::Handle givenProto) override; WebGLContext* GetParentObject() const { return mContext; } - const WeakPtr mLinkInfo; const GLuint mLoc; const WebGLActiveInfo* const mActiveInfo; diff --git a/dom/canvas/WebGLVertexArray.cpp b/dom/canvas/WebGLVertexArray.cpp index ab7abfd43470..5e0b295575f1 100644 --- a/dom/canvas/WebGLVertexArray.cpp +++ b/dom/canvas/WebGLVertexArray.cpp @@ -15,9 +15,9 @@ namespace mozilla { JSObject* -WebGLVertexArray::WrapObject(JSContext* cx, JS::Handle aGivenProto) +WebGLVertexArray::WrapObject(JSContext* cx, JS::Handle givenProto) { - return dom::WebGLVertexArrayObjectOESBinding::Wrap(cx, this, aGivenProto); + return dom::WebGLVertexArrayObjectOESBinding::Wrap(cx, this, givenProto); } WebGLVertexArray::WebGLVertexArray(WebGLContext* webgl) diff --git a/dom/canvas/WebGLVertexArray.h b/dom/canvas/WebGLVertexArray.h index 332fc5981861..2e3beb1c0f05 100644 --- a/dom/canvas/WebGLVertexArray.h +++ b/dom/canvas/WebGLVertexArray.h @@ -6,8 +6,10 @@ #ifndef WEBGL_VERTEX_ARRAY_H_ #define WEBGL_VERTEX_ARRAY_H_ +#include "nsTArray.h" #include "mozilla/LinkedList.h" #include "nsWrapperCache.h" + #include "WebGLBuffer.h" #include "WebGLObjectModel.h" #include "WebGLStrongTypes.h" @@ -48,7 +50,7 @@ public: return Context(); } - virtual JSObject* WrapObject(JSContext* cx, JS::Handle aGivenProto) override; + virtual JSObject* WrapObject(JSContext* cx, JS::Handle givenProto) override; NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLVertexArray) NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLVertexArray) diff --git a/dom/canvas/WebGLVertexArrayObject.cpp b/dom/canvas/WebGLVertexArrayObject.cpp index 71ec32e50ba5..4e6ac6f01dd1 100644 --- a/dom/canvas/WebGLVertexArrayObject.cpp +++ b/dom/canvas/WebGLVertexArrayObject.cpp @@ -6,7 +6,9 @@ #include "WebGLVertexArrayObject.h" +#include "GLContext.h" #include "mozilla/dom/WebGL2RenderingContextBinding.h" +#include "WebGLContext.h" namespace mozilla { namespace dom { diff --git a/dom/canvas/compiledtest/TestWebGLElementArrayCache.cpp b/dom/canvas/compiledtest/TestWebGLElementArrayCache.cpp index 3bc977ccc128..2d0c98b29cf6 100644 --- a/dom/canvas/compiledtest/TestWebGLElementArrayCache.cpp +++ b/dom/canvas/compiledtest/TestWebGLElementArrayCache.cpp @@ -13,8 +13,6 @@ #include "nscore.h" #include "nsTArray.h" -using namespace mozilla; - int gTestsPassed = 0; void @@ -65,7 +63,7 @@ GLType() } void -CheckValidate(bool expectSuccess, WebGLElementArrayCache& c, GLenum type, +CheckValidate(bool expectSuccess, mozilla::WebGLElementArrayCache& c, GLenum type, uint32_t maxAllowed, size_t first, size_t count) { uint32_t out_upperBound = 0; @@ -80,7 +78,8 @@ CheckValidate(bool expectSuccess, WebGLElementArrayCache& c, GLenum type, template void -CheckValidateOneTypeVariousBounds(WebGLElementArrayCache& c, size_t firstByte, size_t countBytes) +CheckValidateOneTypeVariousBounds(mozilla::WebGLElementArrayCache& c, size_t firstByte, + size_t countBytes) { size_t first = firstByte / sizeof(T); size_t count = countBytes / sizeof(T); @@ -101,7 +100,8 @@ CheckValidateOneTypeVariousBounds(WebGLElementArrayCache& c, size_t firstByte, s } } -void CheckValidateAllTypes(WebGLElementArrayCache& c, size_t firstByte, size_t countBytes) +void CheckValidateAllTypes(mozilla::WebGLElementArrayCache& c, size_t firstByte, + size_t countBytes) { CheckValidateOneTypeVariousBounds(c, firstByte, countBytes); CheckValidateOneTypeVariousBounds(c, firstByte, countBytes); @@ -120,7 +120,7 @@ CheckSanity() GLenum type = GLType(); - WebGLElementArrayCache c; + mozilla::WebGLElementArrayCache c; c.BufferData(data, numBytes); CheckValidate(true, c, type, 6, 0, 8); CheckValidate(false, c, type, 5, 0, 8); @@ -161,7 +161,7 @@ CheckUintOverflow() GLenum type = GLType(); - WebGLElementArrayCache c; + mozilla::WebGLElementArrayCache c; for(size_t i = 0; i < numElems; i++) data[i] = numElems - i; @@ -187,7 +187,7 @@ main(int argc, char* argv[]) CheckUintOverflow(); nsTArray v, vsub; - WebGLElementArrayCache b; + mozilla::WebGLElementArrayCache b; for (int maxBufferSize = 1; maxBufferSize <= 4096; maxBufferSize *= 2) { // See bug 800612. We originally had | repeat = min(maxBufferSize, 20) | @@ -229,3 +229,4 @@ main(int argc, char* argv[]) std::cerr << argv[0] << ": all " << gTestsPassed << " tests passed" << std::endl; return 0; } + diff --git a/dom/canvas/moz.build b/dom/canvas/moz.build index c3aac25ff42e..ca049a682cc1 100644 --- a/dom/canvas/moz.build +++ b/dom/canvas/moz.build @@ -76,7 +76,6 @@ UNIFIED_SOURCES += [ 'WebGLContextFramebufferOperations.cpp', 'WebGLContextGL.cpp', 'WebGLContextLossHandler.cpp', - 'WebGLContextReporter.cpp', 'WebGLContextState.cpp', 'WebGLContextUnchecked.cpp', 'WebGLContextUtils.cpp', @@ -113,6 +112,7 @@ UNIFIED_SOURCES += [ 'WebGLFormats.cpp', 'WebGLFramebuffer.cpp', 'WebGLFramebufferAttachable.cpp', + 'WebGLMemoryTracker.cpp', 'WebGLObjectModel.cpp', 'WebGLProgram.cpp', 'WebGLQuery.cpp', @@ -133,7 +133,9 @@ UNIFIED_SOURCES += [ 'WebGLVertexArrayGL.cpp', 'WebGLVertexArrayObject.cpp', ] + LOCAL_INCLUDES += [ + '../..', # Support `#include "mfbt/RefPtr.h"` '/js/xpconnect/wrappers', ] diff --git a/dom/canvas/nsICanvasRenderingContextInternal.h b/dom/canvas/nsICanvasRenderingContextInternal.h index ce83079380e0..240dbfc94cde 100644 --- a/dom/canvas/nsICanvasRenderingContextInternal.h +++ b/dom/canvas/nsICanvasRenderingContextInternal.h @@ -42,10 +42,10 @@ public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICANVASRENDERINGCONTEXTINTERNAL_IID) - void SetCanvasElement(mozilla::dom::HTMLCanvasElement* aParentCanvas) + void SetCanvasElement(mozilla::dom::HTMLCanvasElement* parentCanvas) { RemovePostRefreshObserver(); - mCanvasElement = aParentCanvas; + mCanvasElement = parentCanvas; AddPostRefreshObserverIfNecessary(); } @@ -93,24 +93,24 @@ public: NS_IMETHOD InitializeWithSurface(nsIDocShell *docShell, gfxASurface *surface, int32_t width, int32_t height) = 0; // Creates an image buffer. Returns null on failure. - virtual void GetImageBuffer(uint8_t** aImageBuffer, int32_t* aFormat) = 0; + virtual void GetImageBuffer(uint8_t** imageBuffer, int32_t* format) = 0; // Gives you a stream containing the image represented by this context. - // The format is given in aMimeTime, for example "image/png". + // The format is given in mimeTime, for example "image/png". // - // If the image format does not support transparency or aIncludeTransparency + // If the image format does not support transparency or includeTransparency // is false, alpha will be discarded and the result will be the image // composited on black. - NS_IMETHOD GetInputStream(const char *aMimeType, - const char16_t *aEncoderOptions, - nsIInputStream **aStream) = 0; - + NS_IMETHOD GetInputStream(const char *mimeType, + const char16_t *encoderOptions, + nsIInputStream **stream) = 0; + // This gets an Azure SourceSurface for the canvas, this will be a snapshot // of the canvas at the time it was called. - // If aPremultAlpha is provided, then it assumed the callee can handle - // un-premultiplied surfaces, and *aPremultAlpha will be set to false + // If premultAlpha is provided, then it assumed the callee can handle + // un-premultiplied surfaces, and *premultAlpha will be set to false // if one is returned. - virtual already_AddRefed GetSurfaceSnapshot(bool* aPremultAlpha = nullptr) = 0; + virtual already_AddRefed GetSurfaceSnapshot(bool* premultAlpha = nullptr) = 0; // If this context is opaque, the backing store of the canvas should // be created as opaque; all compositing operators should assume the @@ -125,27 +125,27 @@ public: // Return the CanvasLayer for this context, creating // one for the given layer manager if not available. - virtual already_AddRefed GetCanvasLayer(nsDisplayListBuilder* aBuilder, - CanvasLayer *aOldLayer, - LayerManager *aManager) = 0; + virtual already_AddRefed GetCanvasLayer(nsDisplayListBuilder* builder, + CanvasLayer *oldLayer, + LayerManager *manager) = 0; // Return true if the canvas should be forced to be "inactive" to ensure // it can be drawn to the screen even if it's too large to be blitted by // an accelerated CanvasLayer. - virtual bool ShouldForceInactiveLayer(LayerManager *aManager) { return false; } + virtual bool ShouldForceInactiveLayer(LayerManager *manager) { return false; } virtual void MarkContextClean() = 0; // Redraw the dirty rectangle of this canvas. NS_IMETHOD Redraw(const gfxRect &dirty) = 0; - NS_IMETHOD SetContextOptions(JSContext* aCx, JS::Handle aOptions) { return NS_OK; } + NS_IMETHOD SetContextOptions(JSContext* cx, JS::Handle options) { return NS_OK; } // return true and fills in the bounding rect if elementis a child and has a hit region. - virtual bool GetHitRegionRect(mozilla::dom::Element* aElement, nsRect& aRect) { return false; } + virtual bool GetHitRegionRect(mozilla::dom::Element* element, nsRect& rect) { return false; } // Given a point, return hit region ID if it exists or an empty string if it doesn't - virtual nsString GetHitRegion(const mozilla::gfx::Point& aPoint) { return nsString(); } + virtual nsString GetHitRegion(const mozilla::gfx::Point& point) { return nsString(); } // // shmem support diff --git a/gfx/gl/GLBlitHelper.cpp b/gfx/gl/GLBlitHelper.cpp index 53e7a14cd524..c72a1a34032d 100644 --- a/gfx/gl/GLBlitHelper.cpp +++ b/gfx/gl/GLBlitHelper.cpp @@ -6,6 +6,7 @@ #include "GLBlitHelper.h" #include "GLContext.h" +#include "GLScreenBuffer.h" #include "ScopedGLHelpers.h" #include "mozilla/Preferences.h" #include "ImageContainer.h" diff --git a/gfx/gl/GLContext.cpp b/gfx/gl/GLContext.cpp index 1c4fa209a6b3..cf5555ca7a1b 100644 --- a/gfx/gl/GLContext.cpp +++ b/gfx/gl/GLContext.cpp @@ -4,15 +4,17 @@ * 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/. */ +#include "GLContext.h" + #include #include #include #include #include -#include "GLContext.h" #include "GLBlitHelper.h" #include "GLReadTexImageHelper.h" +#include "GLScreenBuffer.h" #include "gfxCrashReporterUtils.h" #include "gfxUtils.h" @@ -2607,5 +2609,241 @@ GLContext::Readback(SharedSurface* src, gfx::DataSourceSurface* dest) } } +// Do whatever tear-down is necessary after drawing to our offscreen FBO, +// if it's bound. +void +GLContext::AfterGLDrawCall() +{ + if (mScreen) { + mScreen->AfterDrawCall(); + } + mHeavyGLCallsSinceLastFlush = true; +} + +// Do whatever setup is necessary to read from our offscreen FBO, if it's +// bound. +void +GLContext::BeforeGLReadCall() +{ + if (mScreen) + mScreen->BeforeReadCall(); +} + +void +GLContext::fBindFramebuffer(GLenum target, GLuint framebuffer) +{ + if (!mScreen) { + raw_fBindFramebuffer(target, framebuffer); + return; + } + + switch (target) { + case LOCAL_GL_DRAW_FRAMEBUFFER_EXT: + mScreen->BindDrawFB(framebuffer); + return; + + case LOCAL_GL_READ_FRAMEBUFFER_EXT: + mScreen->BindReadFB(framebuffer); + return; + + case LOCAL_GL_FRAMEBUFFER: + mScreen->BindFB(framebuffer); + return; + + default: + // Nothing we care about, likely an error. + break; + } + + raw_fBindFramebuffer(target, framebuffer); +} + +void +GLContext::fCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, + GLint y, GLsizei width, GLsizei height, GLint border) +{ + if (!IsTextureSizeSafeToPassToDriver(target, width, height)) { + // pass wrong values to cause the GL to generate GL_INVALID_VALUE. + // See bug 737182 and the comment in IsTextureSizeSafeToPassToDriver. + level = -1; + width = -1; + height = -1; + border = -1; + } + + BeforeGLReadCall(); + bool didCopyTexImage2D = false; + if (mScreen) { + didCopyTexImage2D = mScreen->CopyTexImage2D(target, level, internalformat, x, + y, width, height, border); + } + + if (!didCopyTexImage2D) { + raw_fCopyTexImage2D(target, level, internalformat, x, y, width, height, + border); + } + AfterGLReadCall(); +} + +void +GLContext::fGetIntegerv(GLenum pname, GLint* params) +{ + switch (pname) { + // LOCAL_GL_FRAMEBUFFER_BINDING is equal to + // LOCAL_GL_DRAW_FRAMEBUFFER_BINDING_EXT, + // so we don't need two cases. + case LOCAL_GL_DRAW_FRAMEBUFFER_BINDING_EXT: + if (mScreen) { + *params = mScreen->GetDrawFB(); + } else { + raw_fGetIntegerv(pname, params); + } + break; + + case LOCAL_GL_READ_FRAMEBUFFER_BINDING_EXT: + if (mScreen) { + *params = mScreen->GetReadFB(); + } else { + raw_fGetIntegerv(pname, params); + } + break; + + case LOCAL_GL_MAX_TEXTURE_SIZE: + MOZ_ASSERT(mMaxTextureSize>0); + *params = mMaxTextureSize; + break; + + case LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE: + MOZ_ASSERT(mMaxCubeMapTextureSize>0); + *params = mMaxCubeMapTextureSize; + break; + + case LOCAL_GL_MAX_RENDERBUFFER_SIZE: + MOZ_ASSERT(mMaxRenderbufferSize>0); + *params = mMaxRenderbufferSize; + break; + + case LOCAL_GL_VIEWPORT: + for (size_t i = 0; i < 4; i++) { + params[i] = mViewportRect[i]; + } + break; + + case LOCAL_GL_SCISSOR_BOX: + for (size_t i = 0; i < 4; i++) { + params[i] = mScissorRect[i]; + } + break; + + default: + raw_fGetIntegerv(pname, params); + break; + } +} + +void +GLContext::fReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, + GLenum type, GLvoid* pixels) +{ + BeforeGLReadCall(); + + bool didReadPixels = false; + if (mScreen) { + didReadPixels = mScreen->ReadPixels(x, y, width, height, format, type, pixels); + } + + if (!didReadPixels) { + raw_fReadPixels(x, y, width, height, format, type, pixels); + } + + AfterGLReadCall(); +} + +void +GLContext::fDeleteFramebuffers(GLsizei n, const GLuint* names) +{ + if (mScreen) { + // Notify mScreen which framebuffers we're deleting. + // Otherwise, we will get framebuffer binding mispredictions. + for (int i = 0; i < n; i++) { + mScreen->DeletingFB(names[i]); + } + } + + if (n == 1 && *names == 0) { + // Deleting framebuffer 0 causes hangs on the DROID. See bug 623228. + } else { + raw_fDeleteFramebuffers(n, names); + } + TRACKING_CONTEXT(DeletedFramebuffers(this, n, names)); +} + + +GLuint +GLContext::GetDrawFB() +{ + if (mScreen) + return mScreen->GetDrawFB(); + + GLuint ret = 0; + GetUIntegerv(LOCAL_GL_DRAW_FRAMEBUFFER_BINDING_EXT, &ret); + return ret; +} + +GLuint +GLContext::GetReadFB() +{ + if (mScreen) + return mScreen->GetReadFB(); + + GLenum bindEnum = IsSupported(GLFeature::framebuffer_blit) + ? LOCAL_GL_READ_FRAMEBUFFER_BINDING_EXT + : LOCAL_GL_FRAMEBUFFER_BINDING; + + GLuint ret = 0; + GetUIntegerv(bindEnum, &ret); + return ret; +} + +GLuint +GLContext::GetFB() +{ + if (mScreen) { + // This has a very important extra assert that checks that we're + // not accidentally ignoring a situation where the draw and read + // FBs differ. + return mScreen->GetFB(); + } + + GLuint ret = 0; + GetUIntegerv(LOCAL_GL_FRAMEBUFFER_BINDING, &ret); + return ret; +} + +bool +GLContext::InitOffscreen(const gfx::IntSize& size, const SurfaceCaps& caps) +{ + if (!CreateScreenBuffer(size, caps)) + return false; + + MakeCurrent(); + fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, 0); + fScissor(0, 0, size.width, size.height); + fViewport(0, 0, size.width, size.height); + + mCaps = mScreen->mCaps; + MOZ_ASSERT(!mCaps.any); + + UpdateGLFormats(mCaps); + + return true; +} + +bool +GLContext::IsDrawingToDefaultFramebuffer() +{ + return Screen()->IsDrawFramebufferDefault(); +} + } /* namespace gl */ } /* namespace mozilla */ diff --git a/gfx/gl/GLContext.h b/gfx/gl/GLContext.h index 1d22450e0438..874ac1585565 100644 --- a/gfx/gl/GLContext.h +++ b/gfx/gl/GLContext.h @@ -32,19 +32,17 @@ #define MOZ_GL_DEBUG 1 #endif -#include "mozilla/UniquePtr.h" +#include "../../mfbt/RefPtr.h" +#include "../../mfbt/UniquePtr.h" #include "GLDefs.h" #include "GLLibraryLoader.h" #include "nsISupportsImpl.h" #include "plstr.h" -#include "nsDataHashtable.h" -#include "nsHashKeys.h" #include "nsAutoPtr.h" #include "GLContextTypes.h" -#include "GLTextureImage.h" +//#include "GLTextureImage.h" #include "SurfaceTypes.h" -#include "GLScreenBuffer.h" #include "GLContextSymbols.h" #include "base/platform_thread.h" // for PlatformThreadId #include "mozilla/GenericRefCounted.h" @@ -62,13 +60,14 @@ namespace mozilla { } // namespace gfx namespace gl { - class GLContext; - class GLLibraryEGL; - class GLScreenBuffer; - class TextureGarbageBin; class GLBlitHelper; class GLBlitTextureImageHelper; + class GLContext; + class GLLibraryEGL; class GLReadTexImageHelper; + class GLScreenBuffer; + class SharedSurface; + class TextureGarbageBin; struct SurfaceCaps; } // namespace gl @@ -792,31 +791,19 @@ private: // Do whatever setup is necessary to draw to our offscreen FBO, if it's // bound. - void BeforeGLDrawCall() { - } + void BeforeGLDrawCall() { } // Do whatever tear-down is necessary after drawing to our offscreen FBO, // if it's bound. - void AfterGLDrawCall() - { - if (mScreen) { - mScreen->AfterDrawCall(); - } - mHeavyGLCallsSinceLastFlush = true; - } + void AfterGLDrawCall(); // Do whatever setup is necessary to read from our offscreen FBO, if it's // bound. - void BeforeGLReadCall() - { - if (mScreen) - mScreen->BeforeReadCall(); - } + void BeforeGLReadCall(); // Do whatever tear-down is necessary after reading from our offscreen FBO, // if it's bound. - void AfterGLReadCall() { - } + void AfterGLReadCall() { } // ----------------------------------------------------------------------------- @@ -854,32 +841,7 @@ public: AFTER_GL_CALL; } - void fBindFramebuffer(GLenum target, GLuint framebuffer) { - if (!mScreen) { - raw_fBindFramebuffer(target, framebuffer); - return; - } - - switch (target) { - case LOCAL_GL_DRAW_FRAMEBUFFER_EXT: - mScreen->BindDrawFB(framebuffer); - return; - - case LOCAL_GL_READ_FRAMEBUFFER_EXT: - mScreen->BindReadFB(framebuffer); - return; - - case LOCAL_GL_FRAMEBUFFER: - mScreen->BindFB(framebuffer); - return; - - default: - // Nothing we care about, likely an error. - break; - } - - raw_fBindFramebuffer(target, framebuffer); - } + void fBindFramebuffer(GLenum target, GLuint framebuffer); void fInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments) { BEFORE_GL_CALL; @@ -1041,29 +1003,8 @@ public: mHeavyGLCallsSinceLastFlush = true; } - void fCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) { - if (!IsTextureSizeSafeToPassToDriver(target, width, height)) { - // pass wrong values to cause the GL to generate GL_INVALID_VALUE. - // See bug 737182 and the comment in IsTextureSizeSafeToPassToDriver. - level = -1; - width = -1; - height = -1; - border = -1; - } - - BeforeGLReadCall(); - bool didCopyTexImage2D = false; - if (mScreen) { - didCopyTexImage2D = mScreen->CopyTexImage2D(target, level, internalformat, x, - y, width, height, border); - } - - if (!didCopyTexImage2D) { - raw_fCopyTexImage2D(target, level, internalformat, x, y, width, height, - border); - } - AfterGLReadCall(); - } + void fCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, + GLint y, GLsizei width, GLsizei height, GLint border); void fCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) { BeforeGLReadCall(); @@ -1238,7 +1179,7 @@ public: } private: - void raw_fGetIntegerv(GLenum pname, GLint *params) { + void raw_fGetIntegerv(GLenum pname, GLint* params) { BEFORE_GL_CALL; mSymbols.fGetIntegerv(pname, params); AFTER_GL_CALL; @@ -1246,72 +1187,19 @@ private: public: - void fGetIntegerv(GLenum pname, GLint *params) { - switch (pname) - { - // LOCAL_GL_FRAMEBUFFER_BINDING is equal to - // LOCAL_GL_DRAW_FRAMEBUFFER_BINDING_EXT, - // so we don't need two cases. - case LOCAL_GL_DRAW_FRAMEBUFFER_BINDING_EXT: - if (mScreen) { - *params = mScreen->GetDrawFB(); - } else { - raw_fGetIntegerv(pname, params); - } - break; - - case LOCAL_GL_READ_FRAMEBUFFER_BINDING_EXT: - if (mScreen) { - *params = mScreen->GetReadFB(); - } else { - raw_fGetIntegerv(pname, params); - } - break; - - case LOCAL_GL_MAX_TEXTURE_SIZE: - MOZ_ASSERT(mMaxTextureSize>0); - *params = mMaxTextureSize; - break; - - case LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE: - MOZ_ASSERT(mMaxCubeMapTextureSize>0); - *params = mMaxCubeMapTextureSize; - break; - - case LOCAL_GL_MAX_RENDERBUFFER_SIZE: - MOZ_ASSERT(mMaxRenderbufferSize>0); - *params = mMaxRenderbufferSize; - break; - - case LOCAL_GL_VIEWPORT: - for (size_t i = 0; i < 4; i++) { - params[i] = mViewportRect[i]; - } - break; - - case LOCAL_GL_SCISSOR_BOX: - for (size_t i = 0; i < 4; i++) { - params[i] = mScissorRect[i]; - } - break; - - default: - raw_fGetIntegerv(pname, params); - break; - } - } + void fGetIntegerv(GLenum pname, GLint* params); void GetUIntegerv(GLenum pname, GLuint *params) { fGetIntegerv(pname, reinterpret_cast(params)); } - void fGetFloatv(GLenum pname, GLfloat *params) { + void fGetFloatv(GLenum pname, GLfloat* params) { BEFORE_GL_CALL; mSymbols.fGetFloatv(pname, params); AFTER_GL_CALL; } - void fGetBooleanv(GLenum pname, realGLboolean *params) { + void fGetBooleanv(GLenum pname, realGLboolean* params) { BEFORE_GL_CALL; mSymbols.fGetBooleanv(pname, params); AFTER_GL_CALL; @@ -1604,20 +1492,8 @@ public: mHeavyGLCallsSinceLastFlush = true; } - void fReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) { - BeforeGLReadCall(); - - bool didReadPixels = false; - if (mScreen) { - didReadPixels = mScreen->ReadPixels(x, y, width, height, format, type, pixels); - } - - if (!didReadPixels) { - raw_fReadPixels(x, y, width, height, format, type, pixels); - } - - AfterGLReadCall(); - } + void fReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, + GLenum type, GLvoid* pixels); public: void fSampleCoverage(GLclampf value, realGLboolean invert) { @@ -2289,22 +2165,7 @@ public: TRACKING_CONTEXT(DeletedBuffers(this, n, names)); } - void fDeleteFramebuffers(GLsizei n, const GLuint* names) { - if (mScreen) { - // Notify mScreen which framebuffers we're deleting. - // Otherwise, we will get framebuffer binding mispredictions. - for (int i = 0; i < n; i++) { - mScreen->DeletingFB(names[i]); - } - } - - if (n == 1 && *names == 0) { - // Deleting framebuffer 0 causes hangs on the DROID. See bug 623228. - } else { - raw_fDeleteFramebuffers(n, names); - } - TRACKING_CONTEXT(DeletedFramebuffers(this, n, names)); - } + void fDeleteFramebuffers(GLsizei n, const GLuint* names); void fDeleteRenderbuffers(GLsizei n, const GLuint* names) { raw_fDeleteRenderbuffers(n, names); @@ -3359,40 +3220,11 @@ public: fBindFramebuffer(LOCAL_GL_READ_FRAMEBUFFER_EXT, fb); } - GLuint GetDrawFB() { - if (mScreen) - return mScreen->GetDrawFB(); + GLuint GetDrawFB(); - GLuint ret = 0; - GetUIntegerv(LOCAL_GL_DRAW_FRAMEBUFFER_BINDING_EXT, &ret); - return ret; - } + GLuint GetReadFB(); - GLuint GetReadFB() { - if (mScreen) - return mScreen->GetReadFB(); - - GLenum bindEnum = IsSupported(GLFeature::framebuffer_blit) - ? LOCAL_GL_READ_FRAMEBUFFER_BINDING_EXT - : LOCAL_GL_FRAMEBUFFER_BINDING; - - GLuint ret = 0; - GetUIntegerv(bindEnum, &ret); - return ret; - } - - GLuint GetFB() { - if (mScreen) { - // This has a very important extra assert that checks that we're - // not accidentally ignoring a situation where the draw and read - // FBs differ. - return mScreen->GetFB(); - } - - GLuint ret = 0; - GetUIntegerv(LOCAL_GL_FRAMEBUFFER_BINDING, &ret); - return ret; - } + GLuint GetFB(); private: void GetShaderPrecisionFormatNonES2(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision) { @@ -3452,7 +3284,7 @@ public: } protected: - nsRefPtr mSharedContext; + RefPtr mSharedContext; // The thread id which this context was created. PlatformThreadId mOwningThreadId; @@ -3492,22 +3324,7 @@ public: return thisShared == otherShared; } - bool InitOffscreen(const gfx::IntSize& size, const SurfaceCaps& caps) { - if (!CreateScreenBuffer(size, caps)) - return false; - - MakeCurrent(); - fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, 0); - fScissor(0, 0, size.width, size.height); - fViewport(0, 0, size.width, size.height); - - mCaps = mScreen->mCaps; - MOZ_ASSERT(!mCaps.any); - - UpdateGLFormats(mCaps); - - return true; - } + bool InitOffscreen(const gfx::IntSize& size, const SurfaceCaps& caps); protected: // Note that it does -not- clear the resized buffers. @@ -3598,12 +3415,10 @@ public: bool WorkAroundDriverBugs() const { return mWorkAroundDriverBugs; } - bool IsDrawingToDefaultFramebuffer() { - return Screen()->IsDrawFramebufferDefault(); - } + bool IsDrawingToDefaultFramebuffer(); protected: - nsRefPtr mTexGarbageBin; + RefPtr mTexGarbageBin; public: TextureGarbageBin* TexGarbageBin() { diff --git a/gfx/gl/SharedSurface.cpp b/gfx/gl/SharedSurface.cpp index 930a3c34e599..e5454d5964ea 100644 --- a/gfx/gl/SharedSurface.cpp +++ b/gfx/gl/SharedSurface.cpp @@ -9,6 +9,7 @@ #include "GLBlitHelper.h" #include "GLContext.h" #include "GLReadTexImageHelper.h" +#include "GLScreenBuffer.h" #include "nsThreadUtils.h" #include "ScopedGLHelpers.h" #include "SharedSurfaceGL.h" diff --git a/toolkit/components/telemetry/Telemetry.h b/toolkit/components/telemetry/Telemetry.h index f4e08ff83496..5cbc5321fde4 100644 --- a/toolkit/components/telemetry/Telemetry.h +++ b/toolkit/components/telemetry/Telemetry.h @@ -22,7 +22,7 @@ namespace HangMonitor { } // namespace HangMonitor namespace Telemetry { -#include "TelemetryHistogramEnums.h" +#include "mozilla/TelemetryHistogramEnums.h" enum TimerResolution { Millisecond,