Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: Source/core/html/canvas/WebGLSharedObject.h

Issue 17230006: Implement WEBGL_shared_resources Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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*);
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 bool validate(const char*, WebGLRenderingContext*, WebGLSharedObject::Acquir eMode, bool, bool*) const;
53 {
54 return contextGroup == m_contextGroup;
55 }
56 66
57 void detachContextGroup(); 67 void detachContextGroup();
58 68
69 bool isAcquiredForContext(const WebGLRenderingContext*, WebGLSharedObject::A cquireMode, bool, bool*, const char**) const;
70 bool hasBeenBoundInContextSinceLastAcquire(const WebGLRenderingContext*);
71 void markAsBoundSinceLastAcquireForContext(const WebGLRenderingContext*);
72 bool addAcquireRequest(WebGLRenderingContext*, WebGLSharedObject::AcquireMod e, PassRefPtr<WebGLAcquireSharedResourceCallback>, long&);
73 // cancels an acquire request. Returns true if id was found.
74 bool cancelAcquireRequest(const WebGLRenderingContext*, long);
75 bool release(WebGLRenderingContext*);
76
77 void processAcquireRequests();
78 void removePostedAcquireRequest(const WebGLRenderingContext*, long);
79
59 protected: 80 protected:
60 WebGLSharedObject(WebGLRenderingContext*); 81 WebGLSharedObject(WebGLRenderingContext*);
61 82
62 virtual bool hasGroupOrContext() const 83 virtual bool hasGroupOrContext() const
63 { 84 {
64 return m_contextGroup; 85 return m_contextGroup;
65 } 86 }
66 87
67 virtual GraphicsContext3D* getAGraphicsContext3D() const; 88 virtual GraphicsContext3D* getAGraphicsContext3D() const;
68 89
69 private: 90 private:
91 class DispatchCallbackTask : public ScriptExecutionContext::Task {
92 public:
93 DispatchCallbackTask(PassRefPtr<WebGLAcquireSharedResourceRequest> reque st)
94 : m_request(request)
95 {
96 }
97 ~DispatchCallbackTask();
98
99 virtual void performTask(ScriptExecutionContext*);
100
101 private:
102 RefPtr<WebGLAcquireSharedResourceRequest> m_request;
103 };
104
105 typedef HashMap<const WebGLRenderingContext*, bool> AcquireContextMap;
106 typedef Deque<RefPtr<WebGLAcquireSharedResourceRequest> > AcquireRequestQueu e;
107 typedef Deque<RefPtr<WebGLAcquireSharedResourceRequest> > AcquireRequestList ;
108
109 bool acquire(WebGLSharedObject::AcquireMode, const WebGLRenderingContext*);
110 bool isRequestPending(const WebGLRenderingContext*);
111
70 WebGLContextGroup* m_contextGroup; 112 WebGLContextGroup* m_contextGroup;
113
114 WebGLSharedObject::AcquireMode m_acquireMode;
115
116 // A map of contexts that currently have this resource acquired.
117 // and whether or not it's been bound since last acquired.
118 AcquireContextMap m_acquireContextMap;
119
120 AcquireRequestQueue m_acquireRequestQueue; // requests that are waiting for resources.
121 AcquireRequestList m_acquireRequestPostedList; // requests what have had scr ipt tasks posted but the script has not executed.
71 }; 122 };
72 123
124 class WebGLAcquireSharedResourceRequest : public RefCounted<WebGLAcquireSharedRe sourceRequest> {
125 public:
126 static PassRefPtr<WebGLAcquireSharedResourceRequest> create(PassRefPtr<WebGL SharedObject>, PassRefPtr<WebGLAcquireSharedResourceCallback>, WebGLSharedObject ::AcquireMode, WebGLRenderingContext*, long);
127 ~WebGLAcquireSharedResourceRequest();
128
129 long id() const { return m_id; }
130 WebGLRenderingContext* context() const { return m_context; }
131 WebGLSharedObject::AcquireMode acquireMode() const { return m_acquireMode; }
132 void cancel();
133
134 // Run the callback.
135 void run();
136
137 private:
138 WebGLAcquireSharedResourceRequest(PassRefPtr<WebGLSharedObject>, PassRefPtr< WebGLAcquireSharedResourceCallback>, WebGLSharedObject::AcquireMode, WebGLRender ingContext*, long);
139
140 RefPtr<WebGLSharedObject> m_sharedObject;
141 WebGLRenderingContext* m_context;
142 long m_id;
143 WebGLSharedObject::AcquireMode m_acquireMode;
144 RefPtr<WebGLAcquireSharedResourceCallback> m_callback;
145 };
146
147
73 } // namespace WebCore 148 } // namespace WebCore
74 149
75 #endif // WebGLSharedObject_h 150 #endif // WebGLSharedObject_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698