Chromium Code Reviews| 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 |
| 55 static bool IntToAcquireMode(unsigned, AcquireMode*); | |
|
Ken Russell (switch to Gerrit)
2013/06/19 03:51:24
nit: I think Blink naming convention is intToAcqui
greggman
2013/06/21 19:54:21
Done.
| |
| 56 | |
| 43 WebGLContextGroup* contextGroup() const { return m_contextGroup; } | 57 WebGLContextGroup* contextGroup() const { return m_contextGroup; } |
| 44 | 58 |
| 45 virtual bool isBuffer() const { return false; } | 59 virtual bool isBuffer() const { return false; } |
| 46 virtual bool isFramebuffer() const { return false; } | |
| 47 virtual bool isProgram() const { return false; } | 60 virtual bool isProgram() const { return false; } |
| 48 virtual bool isRenderbuffer() const { return false; } | 61 virtual bool isRenderbuffer() const { return false; } |
| 49 virtual bool isShader() const { return false; } | 62 virtual bool isShader() const { return false; } |
| 50 virtual bool isTexture() const { return false; } | 63 virtual bool isTexture() const { return false; } |
| 51 | 64 |
| 52 virtual bool validate(const WebGLContextGroup* contextGroup, const WebGLRend eringContext*) const | 65 virtual const char* typeName() const = 0; |
| 53 { | 66 |
| 54 return contextGroup == m_contextGroup; | 67 bool validate(const char*, WebGLRenderingContext*, WebGLSharedObject::Acquir eMode, bool, bool*) const; |
| 55 } | |
| 56 | 68 |
| 57 void detachContextGroup(); | 69 void detachContextGroup(); |
| 58 | 70 |
| 71 bool isAcquiredForContext(const WebGLRenderingContext*, WebGLSharedObject::A cquireMode, bool, bool*, const char**) const; | |
| 72 bool hasBeenBoundInContextSinceLastAcquire(const WebGLRenderingContext*); | |
| 73 void markAsBoundSinceLastAcquireForContext(const WebGLRenderingContext*); | |
| 74 bool addAcquireRequest(WebGLRenderingContext*, WebGLSharedObject::AcquireMod e, PassRefPtr<WebGLAcquireSharedResourceCallback>, long&); | |
| 75 // cancels an acquire request. Returns true if id was found. | |
| 76 bool cancelAcquireRequest(const WebGLRenderingContext*, long); | |
| 77 bool release(WebGLRenderingContext*); | |
| 78 | |
| 79 void processAcquireRequests(); | |
| 80 void removePostedAcquireRequest(const WebGLRenderingContext*, long); | |
| 81 | |
| 59 protected: | 82 protected: |
| 60 WebGLSharedObject(WebGLRenderingContext*); | 83 WebGLSharedObject(WebGLRenderingContext*); |
| 61 | 84 |
| 62 virtual bool hasGroupOrContext() const | 85 virtual bool hasGroupOrContext() const |
| 63 { | 86 { |
| 64 return m_contextGroup; | 87 return m_contextGroup; |
| 65 } | 88 } |
| 66 | 89 |
| 67 virtual GraphicsContext3D* getAGraphicsContext3D() const; | 90 virtual GraphicsContext3D* getAGraphicsContext3D() const; |
| 68 | 91 |
| 69 private: | 92 private: |
| 93 class DispatchCallbackTask : public ScriptExecutionContext::Task { | |
| 94 public: | |
| 95 DispatchCallbackTask(PassRefPtr<WebGLAcquireSharedResourceRequest> reque st) | |
| 96 : m_request(request) | |
| 97 { | |
| 98 } | |
| 99 ~DispatchCallbackTask(); | |
| 100 | |
| 101 virtual void performTask(ScriptExecutionContext*); | |
| 102 | |
| 103 private: | |
| 104 RefPtr<WebGLAcquireSharedResourceRequest> m_request; | |
| 105 }; | |
| 106 | |
| 107 typedef HashMap<const WebGLRenderingContext*, bool> AcquireContextMap; | |
| 108 typedef Deque<RefPtr<WebGLAcquireSharedResourceRequest> > AcquireRequestQueu e; | |
| 109 typedef Deque<RefPtr<WebGLAcquireSharedResourceRequest> > AcquireRequestList ; | |
| 110 | |
| 111 bool acquire(WebGLSharedObject::AcquireMode, const WebGLRenderingContext*); | |
| 112 bool isRequestPending(const WebGLRenderingContext*); | |
| 113 | |
| 70 WebGLContextGroup* m_contextGroup; | 114 WebGLContextGroup* m_contextGroup; |
| 115 | |
| 116 WebGLSharedObject::AcquireMode m_acquireMode; | |
| 117 | |
| 118 // A map of contexts that currently have this resource acquired. | |
| 119 // and whether or not it's been bound since last acquired. | |
| 120 AcquireContextMap m_acquireContextMap; | |
| 121 | |
| 122 AcquireRequestQueue m_acquireRequestQueue; // requests that are waiting for resources. | |
| 123 AcquireRequestList m_acquireRequestPostedList; // requests what have had scr ipt tasks posted but the script has not executed. | |
| 71 }; | 124 }; |
| 72 | 125 |
| 126 class WebGLAcquireSharedResourceRequest : public RefCounted<WebGLAcquireSharedRe sourceRequest> { | |
| 127 public: | |
| 128 static PassRefPtr<WebGLAcquireSharedResourceRequest> create(PassRefPtr<WebGL SharedObject>, PassRefPtr<WebGLAcquireSharedResourceCallback>, WebGLSharedObject ::AcquireMode, WebGLRenderingContext*, long); | |
| 129 ~WebGLAcquireSharedResourceRequest(); | |
| 130 | |
| 131 long id() const { return m_id; } | |
| 132 WebGLRenderingContext* context() const { return m_context; } | |
| 133 WebGLSharedObject::AcquireMode acquireMode() const { return m_acquireMode; } | |
| 134 void cancel(); | |
| 135 | |
| 136 // Run the callback. | |
| 137 void run(); | |
| 138 | |
| 139 private: | |
| 140 WebGLAcquireSharedResourceRequest(PassRefPtr<WebGLSharedObject>, PassRefPtr< WebGLAcquireSharedResourceCallback>, WebGLSharedObject::AcquireMode, WebGLRender ingContext*, long); | |
| 141 | |
| 142 RefPtr<WebGLSharedObject> m_sharedObject; | |
| 143 WebGLRenderingContext* m_context; | |
|
Ken Russell (switch to Gerrit)
2013/06/19 03:51:24
How about a comment: // Weak, but context is kept
greggman
2013/06/21 19:54:21
Done.
| |
| 144 long m_id; | |
| 145 WebGLSharedObject::AcquireMode m_acquireMode; | |
| 146 RefPtr<WebGLAcquireSharedResourceCallback> m_callback; | |
| 147 }; | |
| 148 | |
| 149 | |
| 73 } // namespace WebCore | 150 } // namespace WebCore |
| 74 | 151 |
| 75 #endif // WebGLSharedObject_h | 152 #endif // WebGLSharedObject_h |
| OLD | NEW |