content/canvas/src/WebGLFramebufferAttachable.cpp

branch
TOR_BUG_9701
changeset 11
deefc01c0e14
equal deleted inserted replaced
-1:000000000000 0:f0d5e42cd633
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #include "WebGLContext.h"
7 #include "WebGLFramebufferAttachable.h"
8 #include "WebGLFramebuffer.h"
9 #include "WebGLRenderbuffer.h"
10 #include "WebGLTexture.h"
11
12 using namespace mozilla;
13
14 WebGLFramebufferAttachable::AttachmentPoint*
15 WebGLFramebufferAttachable::Contains(const WebGLFramebuffer* fb, GLenum attachment)
16 {
17 AttachmentPoint* first = mAttachmentPoints.begin();
18 AttachmentPoint* last = mAttachmentPoints.end();
19
20 for (; first != last; ++first) {
21 if (first->mFB == fb && first->mAttachment == attachment)
22 return first;
23 }
24
25 return nullptr;
26 }
27
28 void
29 WebGLFramebufferAttachable::AttachTo(WebGLFramebuffer* fb, GLenum attachment)
30 {
31 MOZ_ASSERT(fb);
32 if (!fb)
33 return;
34
35 if (Contains(fb, attachment))
36 return; // Already attached. Ignore.
37
38 mAttachmentPoints.append(AttachmentPoint(fb, attachment));
39 }
40
41 void
42 WebGLFramebufferAttachable::DetachFrom(WebGLFramebuffer* fb, GLenum attachment)
43 {
44 MOZ_ASSERT(fb);
45 if (!fb)
46 return;
47
48 AttachmentPoint* point = Contains(fb, attachment);
49 if (!point) {
50 MOZ_ASSERT(false, "Is not attached to FB");
51 return;
52 }
53
54 mAttachmentPoints.erase(point);
55 }
56
57 void
58 WebGLFramebufferAttachable::NotifyFBsStatusChanged()
59 {
60 AttachmentPoint* first = mAttachmentPoints.begin();
61 AttachmentPoint* last = mAttachmentPoints.end();
62 for ( ; first != last; ++first)
63 first->mFB->NotifyAttachableChanged();
64 }

mercurial