1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/src/WebGLFramebuffer.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,201 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef WEBGLFRAMEBUFFER_H_ 1.10 +#define WEBGLFRAMEBUFFER_H_ 1.11 + 1.12 +#include "WebGLObjectModel.h" 1.13 + 1.14 +#include "nsWrapperCache.h" 1.15 + 1.16 +#include "mozilla/LinkedList.h" 1.17 + 1.18 +namespace mozilla { 1.19 + 1.20 +class WebGLFramebufferAttachable; 1.21 +class WebGLTexture; 1.22 +class WebGLRenderbuffer; 1.23 +namespace gl { 1.24 + class GLContext; 1.25 +} 1.26 + 1.27 +class WebGLFramebuffer MOZ_FINAL 1.28 + : public nsWrapperCache 1.29 + , public WebGLRefCountedObject<WebGLFramebuffer> 1.30 + , public LinkedListElement<WebGLFramebuffer> 1.31 + , public WebGLContextBoundObject 1.32 +{ 1.33 +public: 1.34 + WebGLFramebuffer(WebGLContext* context); 1.35 + 1.36 + ~WebGLFramebuffer() { 1.37 + DeleteOnce(); 1.38 + } 1.39 + 1.40 + struct Attachment 1.41 + { 1.42 + // deleting a texture or renderbuffer immediately detaches it 1.43 + WebGLRefPtr<WebGLTexture> mTexturePtr; 1.44 + WebGLRefPtr<WebGLRenderbuffer> mRenderbufferPtr; 1.45 + GLenum mAttachmentPoint; 1.46 + GLenum mTexImageTarget; 1.47 + GLint mTexImageLevel; 1.48 + mutable bool mNeedsFinalize; 1.49 + 1.50 + Attachment(GLenum aAttachmentPoint = LOCAL_GL_COLOR_ATTACHMENT0) 1.51 + : mAttachmentPoint(aAttachmentPoint) 1.52 + , mNeedsFinalize(false) 1.53 + {} 1.54 + 1.55 + bool IsDefined() const { 1.56 + return Texture() || Renderbuffer(); 1.57 + } 1.58 + 1.59 + bool IsDeleteRequested() const; 1.60 + 1.61 + bool HasAlpha() const; 1.62 + bool IsReadableFloat() const; 1.63 + 1.64 + void SetTexImage(WebGLTexture* tex, GLenum target, GLint level); 1.65 + void SetRenderbuffer(WebGLRenderbuffer* rb); 1.66 + 1.67 + const WebGLTexture* Texture() const { 1.68 + return mTexturePtr; 1.69 + } 1.70 + WebGLTexture* Texture() { 1.71 + return mTexturePtr; 1.72 + } 1.73 + const WebGLRenderbuffer* Renderbuffer() const { 1.74 + return mRenderbufferPtr; 1.75 + } 1.76 + WebGLRenderbuffer* Renderbuffer() { 1.77 + return mRenderbufferPtr; 1.78 + } 1.79 + GLenum TexImageTarget() const { 1.80 + return mTexImageTarget; 1.81 + } 1.82 + GLint TexImageLevel() const { 1.83 + return mTexImageLevel; 1.84 + } 1.85 + 1.86 + bool HasUninitializedImageData() const; 1.87 + void SetImageDataStatus(WebGLImageDataStatus x); 1.88 + 1.89 + void Reset() { 1.90 + mTexturePtr = nullptr; 1.91 + mRenderbufferPtr = nullptr; 1.92 + } 1.93 + 1.94 + const WebGLRectangleObject& RectangleObject() const; 1.95 + 1.96 + bool HasImage() const; 1.97 + bool IsComplete() const; 1.98 + 1.99 + void FinalizeAttachment(gl::GLContext* gl, GLenum attachmentLoc) const; 1.100 + }; 1.101 + 1.102 + void Delete(); 1.103 + 1.104 + bool HasEverBeenBound() { return mHasEverBeenBound; } 1.105 + void SetHasEverBeenBound(bool x) { mHasEverBeenBound = x; } 1.106 + GLuint GLName() { return mGLName; } 1.107 + 1.108 + void FramebufferRenderbuffer(GLenum target, 1.109 + GLenum attachment, 1.110 + GLenum rbtarget, 1.111 + WebGLRenderbuffer* wrb); 1.112 + 1.113 + void FramebufferTexture2D(GLenum target, 1.114 + GLenum attachment, 1.115 + GLenum textarget, 1.116 + WebGLTexture* wtex, 1.117 + GLint level); 1.118 + 1.119 +private: 1.120 + void DetachAttachment(WebGLFramebuffer::Attachment& attachment); 1.121 + void DetachAllAttachments(); 1.122 + const WebGLRectangleObject& GetAnyRectObject() const; 1.123 + Attachment* GetAttachmentOrNull(GLenum attachment); 1.124 + 1.125 +public: 1.126 + bool HasDefinedAttachments() const; 1.127 + bool HasIncompleteAttachments() const; 1.128 + bool AllImageRectsMatch() const; 1.129 + GLenum PrecheckFramebufferStatus() const; 1.130 + GLenum CheckFramebufferStatus() const; 1.131 + 1.132 + bool HasDepthStencilConflict() const { 1.133 + return int(mDepthAttachment.IsDefined()) + 1.134 + int(mStencilAttachment.IsDefined()) + 1.135 + int(mDepthStencilAttachment.IsDefined()) >= 2; 1.136 + } 1.137 + 1.138 + size_t ColorAttachmentCount() const { 1.139 + return mColorAttachments.Length(); 1.140 + } 1.141 + const Attachment& ColorAttachment(size_t colorAttachmentId) const { 1.142 + return mColorAttachments[colorAttachmentId]; 1.143 + } 1.144 + 1.145 + const Attachment& DepthAttachment() const { 1.146 + return mDepthAttachment; 1.147 + } 1.148 + 1.149 + const Attachment& StencilAttachment() const { 1.150 + return mStencilAttachment; 1.151 + } 1.152 + 1.153 + const Attachment& DepthStencilAttachment() const { 1.154 + return mDepthStencilAttachment; 1.155 + } 1.156 + 1.157 + const Attachment& GetAttachment(GLenum attachment) const; 1.158 + 1.159 + void DetachTexture(const WebGLTexture* tex); 1.160 + 1.161 + void DetachRenderbuffer(const WebGLRenderbuffer* rb); 1.162 + 1.163 + const WebGLRectangleObject& RectangleObject() const; 1.164 + 1.165 + WebGLContext* GetParentObject() const { 1.166 + return Context(); 1.167 + } 1.168 + 1.169 + void FinalizeAttachments() const; 1.170 + 1.171 + virtual JSObject* WrapObject(JSContext* cx) MOZ_OVERRIDE; 1.172 + 1.173 + NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLFramebuffer) 1.174 + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLFramebuffer) 1.175 + 1.176 + // mask mirrors glClear. 1.177 + bool HasCompletePlanes(GLbitfield mask); 1.178 + 1.179 + bool CheckAndInitializeAttachments(); 1.180 + 1.181 + bool CheckColorAttachmentNumber(GLenum attachment, const char* functionName) const; 1.182 + 1.183 + void EnsureColorAttachments(size_t colorAttachmentId); 1.184 + 1.185 + Attachment* AttachmentFor(GLenum attachment); 1.186 + void NotifyAttachableChanged() const; 1.187 + 1.188 +private: 1.189 + mutable GLenum mStatus; 1.190 + 1.191 + GLuint mGLName; 1.192 + bool mHasEverBeenBound; 1.193 + 1.194 + // we only store pointers to attached renderbuffers, not to attached textures, because 1.195 + // we will only need to initialize renderbuffers. Textures are already initialized. 1.196 + nsTArray<Attachment> mColorAttachments; 1.197 + Attachment mDepthAttachment, 1.198 + mStencilAttachment, 1.199 + mDepthStencilAttachment; 1.200 +}; 1.201 + 1.202 +} // namespace mozilla 1.203 + 1.204 +#endif