OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #ifndef WebGLSharedObject_h | 26 #ifndef WebGLSharedObject_h |
27 #define WebGLSharedObject_h | 27 #define WebGLSharedObject_h |
28 | 28 |
| 29 #include "core/dom/ScriptExecutionContext.h" |
29 #include "core/html/canvas/WebGLObject.h" | 30 #include "core/html/canvas/WebGLObject.h" |
| 31 #include "wtf/Deque.h" |
| 32 #include "wtf/HashMap.h" |
30 | 33 |
31 namespace WebCore { | 34 namespace WebCore { |
32 | 35 |
33 class GraphicsContext3D; | 36 class GraphicsContext3D; |
| 37 class WebGLAcquireSharedResourceCallback; |
34 class WebGLContextGroup; | 38 class WebGLContextGroup; |
35 class WebGLRenderingContext; | 39 class WebGLRenderingContext; |
| 40 class WebGLSharedObject; |
| 41 class WebGLAcquireSharedResourceRequest; |
36 | 42 |
37 // WebGLSharedObject the base class for objects that can be shared by multiple | 43 // WebGLSharedObject the base class for objects that can be shared by multiple |
38 // WebGLRenderingContexts. | 44 // WebGLRenderingContexts. |
39 class WebGLSharedObject : public WebGLObject { | 45 class WebGLSharedObject : public WebGLObject { |
40 public: | 46 public: |
| 47 enum AcquireMode { |
| 48 Unacquired = 0, |
| 49 ReadOnly = 1, |
| 50 Exclusive = 4, |
| 51 }; |
| 52 |
41 virtual ~WebGLSharedObject(); | 53 virtual ~WebGLSharedObject(); |
42 | 54 |
43 WebGLContextGroup* contextGroup() const { return m_contextGroup; } | 55 WebGLContextGroup* contextGroup() const { return m_contextGroup; } |
44 | 56 |
45 virtual bool isBuffer() const { return false; } | 57 virtual bool isBuffer() const { return false; } |
46 virtual bool isFramebuffer() const { return false; } | |
47 virtual bool isProgram() const { return false; } | 58 virtual bool isProgram() const { return false; } |
48 virtual bool isRenderbuffer() const { return false; } | 59 virtual bool isRenderbuffer() const { return false; } |
49 virtual bool isShader() const { return false; } | 60 virtual bool isShader() const { return false; } |
50 virtual bool isTexture() const { return false; } | 61 virtual bool isTexture() const { return false; } |
51 | 62 |
52 virtual bool validate(const WebGLContextGroup* contextGroup, const WebGLRend
eringContext*) const | 63 virtual const char* typeName() const = 0; |
53 { | 64 |
54 return contextGroup == m_contextGroup; | 65 bool validate(const char*, WebGLRenderingContext*, WebGLSharedObject::Acquir
eMode, bool, bool*) const; |
55 } | |
56 | 66 |
57 void detachContextGroup(); | 67 void detachContextGroup(); |
58 | 68 |
| 69 bool isLost() const |
| 70 { |
| 71 return !m_contextGroup; |
| 72 } |
| 73 bool isAcquiredForContext(const WebGLRenderingContext*, WebGLSharedObject::A
cquireMode, bool, bool*, const char**) const; |
| 74 bool hasBeenBoundInContextSinceLastAcquire(const WebGLRenderingContext*); |
| 75 void markAsBoundSinceLastAcquireForContext(const WebGLRenderingContext*); |
| 76 bool addAcquireRequest(WebGLRenderingContext*, WebGLSharedObject::AcquireMod
e, PassRefPtr<WebGLAcquireSharedResourceCallback>, long&); |
| 77 // cancels an acquire request. Returns true if id was found. |
| 78 bool cancelAcquireRequest(const WebGLRenderingContext*, long); |
| 79 bool release(WebGLRenderingContext*); |
| 80 |
| 81 void cancelAllPendingRequestsForContext(const WebGLRenderingContext*); |
| 82 |
59 protected: | 83 protected: |
60 WebGLSharedObject(WebGLRenderingContext*); | 84 WebGLSharedObject(WebGLRenderingContext*); |
61 | 85 |
62 virtual bool hasGroupOrContext() const | 86 virtual bool hasGroupOrContext() const |
63 { | 87 { |
64 return m_contextGroup; | 88 return m_contextGroup; |
65 } | 89 } |
66 | 90 |
67 virtual GraphicsContext3D* getAGraphicsContext3D() const; | 91 virtual GraphicsContext3D* getAGraphicsContext3D() const; |
68 | 92 |
69 private: | 93 private: |
| 94 friend class WebGLAcquireSharedResourceRequest; |
| 95 class DispatchCallbackTask : public ScriptExecutionContext::Task { |
| 96 public: |
| 97 DispatchCallbackTask(PassRefPtr<WebGLAcquireSharedResourceRequest> reque
st) |
| 98 : m_request(request) |
| 99 { |
| 100 } |
| 101 ~DispatchCallbackTask(); |
| 102 |
| 103 virtual void performTask(ScriptExecutionContext*); |
| 104 |
| 105 private: |
| 106 RefPtr<WebGLAcquireSharedResourceRequest> m_request; |
| 107 }; |
| 108 |
| 109 typedef HashMap<const WebGLRenderingContext*, bool> AcquireContextMap; |
| 110 typedef Deque<RefPtr<WebGLAcquireSharedResourceRequest> > AcquireRequestQueu
e; |
| 111 typedef Deque<RefPtr<WebGLAcquireSharedResourceRequest> > AcquireRequestList
; |
| 112 |
| 113 bool acquire(WebGLSharedObject::AcquireMode, const WebGLRenderingContext*); |
| 114 bool isRequestPending(const WebGLRenderingContext*); |
| 115 void processAcquireRequests(); |
| 116 void removePostedAcquireRequest(const WebGLRenderingContext*, long); |
| 117 static int generateAcquireRequestId(); |
| 118 |
70 WebGLContextGroup* m_contextGroup; | 119 WebGLContextGroup* m_contextGroup; |
| 120 |
| 121 WebGLSharedObject::AcquireMode m_acquireMode; |
| 122 |
| 123 // A map of contexts that currently have this resource acquired. |
| 124 // and whether or not it's been bound since last acquired. |
| 125 AcquireContextMap m_acquireContextMap; |
| 126 |
| 127 AcquireRequestQueue m_acquireRequestQueue; // requests that are waiting for
resources. |
| 128 AcquireRequestList m_acquireRequestPostedList; // requests what have had scr
ipt tasks posted but the script has not executed. |
71 }; | 129 }; |
72 | 130 |
| 131 class WebGLAcquireSharedResourceRequest : public RefCounted<WebGLAcquireSharedRe
sourceRequest> { |
| 132 public: |
| 133 static PassRefPtr<WebGLAcquireSharedResourceRequest> create(PassRefPtr<WebGL
SharedObject>, PassRefPtr<WebGLAcquireSharedResourceCallback>, WebGLSharedObject
::AcquireMode, WebGLRenderingContext*, long); |
| 134 ~WebGLAcquireSharedResourceRequest(); |
| 135 |
| 136 long id() const { return m_id; } |
| 137 WebGLRenderingContext* context() const { return m_context; } |
| 138 WebGLSharedObject::AcquireMode acquireMode() const { return m_acquireMode; } |
| 139 void cancel(); |
| 140 |
| 141 // Run the callback. |
| 142 void run(); |
| 143 |
| 144 private: |
| 145 WebGLAcquireSharedResourceRequest(PassRefPtr<WebGLSharedObject>, PassRefPtr<
WebGLAcquireSharedResourceCallback>, WebGLSharedObject::AcquireMode, WebGLRender
ingContext*, long); |
| 146 |
| 147 RefPtr<WebGLSharedObject> m_sharedObject; |
| 148 // This weak pointer is okay because on context destruction we remove all ou
tstanding requests. |
| 149 WebGLRenderingContext* m_context; |
| 150 long m_id; |
| 151 WebGLSharedObject::AcquireMode m_acquireMode; |
| 152 RefPtr<WebGLAcquireSharedResourceCallback> m_callback; |
| 153 }; |
| 154 |
| 155 |
73 } // namespace WebCore | 156 } // namespace WebCore |
74 | 157 |
75 #endif // WebGLSharedObject_h | 158 #endif // WebGLSharedObject_h |
OLD | NEW |