content/canvas/src/WebGLFramebufferAttachable.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/src/WebGLFramebufferAttachable.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,64 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; 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 +#include "WebGLContext.h"
    1.10 +#include "WebGLFramebufferAttachable.h"
    1.11 +#include "WebGLFramebuffer.h"
    1.12 +#include "WebGLRenderbuffer.h"
    1.13 +#include "WebGLTexture.h"
    1.14 +
    1.15 +using namespace mozilla;
    1.16 +
    1.17 +WebGLFramebufferAttachable::AttachmentPoint*
    1.18 +WebGLFramebufferAttachable::Contains(const WebGLFramebuffer* fb, GLenum attachment)
    1.19 +{
    1.20 +    AttachmentPoint* first = mAttachmentPoints.begin();
    1.21 +    AttachmentPoint* last = mAttachmentPoints.end();
    1.22 +
    1.23 +    for (; first != last; ++first) {
    1.24 +        if (first->mFB == fb && first->mAttachment == attachment)
    1.25 +            return first;
    1.26 +    }
    1.27 +
    1.28 +    return nullptr;
    1.29 +}
    1.30 +
    1.31 +void
    1.32 +WebGLFramebufferAttachable::AttachTo(WebGLFramebuffer* fb, GLenum attachment)
    1.33 +{
    1.34 +    MOZ_ASSERT(fb);
    1.35 +    if (!fb)
    1.36 +        return;
    1.37 +
    1.38 +    if (Contains(fb, attachment))
    1.39 +        return; // Already attached. Ignore.
    1.40 +
    1.41 +    mAttachmentPoints.append(AttachmentPoint(fb, attachment));
    1.42 +}
    1.43 +
    1.44 +void
    1.45 +WebGLFramebufferAttachable::DetachFrom(WebGLFramebuffer* fb, GLenum attachment)
    1.46 +{
    1.47 +    MOZ_ASSERT(fb);
    1.48 +    if (!fb)
    1.49 +        return;
    1.50 +
    1.51 +    AttachmentPoint* point = Contains(fb, attachment);
    1.52 +    if (!point) {
    1.53 +        MOZ_ASSERT(false, "Is not attached to FB");
    1.54 +        return;
    1.55 +    }
    1.56 +
    1.57 +    mAttachmentPoints.erase(point);
    1.58 +}
    1.59 +
    1.60 +void
    1.61 +WebGLFramebufferAttachable::NotifyFBsStatusChanged()
    1.62 +{
    1.63 +    AttachmentPoint* first = mAttachmentPoints.begin();
    1.64 +    AttachmentPoint* last = mAttachmentPoints.end();
    1.65 +    for ( ; first != last; ++first)
    1.66 +        first->mFB->NotifyAttachableChanged();
    1.67 +}

mercurial