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

Side by Side Diff: gpu/command_buffer/service/query_manager.h

Issue 9694025: Add support for GL_COMMANDS_ISSUED_CHROMIUM fence like query. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_QUERY_MANAGER_H_ 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_QUERY_MANAGER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_QUERY_MANAGER_H_ 6 #define GPU_COMMAND_BUFFER_SERVICE_QUERY_MANAGER_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/hash_tables.h" 10 #include "base/hash_tables.h"
(...skipping 10 matching lines...) Expand all
21 namespace gles2 { 21 namespace gles2 {
22 22
23 // This class keeps track of the queries and their state 23 // This class keeps track of the queries and their state
24 // As Queries are not shared there is one QueryManager per context. 24 // As Queries are not shared there is one QueryManager per context.
25 class GPU_EXPORT QueryManager { 25 class GPU_EXPORT QueryManager {
26 public: 26 public:
27 class GPU_EXPORT Query : public base::RefCounted<Query> { 27 class GPU_EXPORT Query : public base::RefCounted<Query> {
28 public: 28 public:
29 typedef scoped_refptr<Query> Ref; 29 typedef scoped_refptr<Query> Ref;
30 30
31 Query(QueryManager* manager, GLuint service_id); 31 explicit Query(QueryManager* manager, GLenum target,
apatrick_chromium 2012/03/13 19:24:15 explicit is redundant
32 32 int32 shm_id, uint32 shm_offset);
33 void Initialize(GLenum target, int32 shm_id, uint32 shm_offset); 33 virtual ~Query();
34
35 bool IsInitialized() const {
36 return target_ != 0;
37 }
38
39 GLuint service_id() const {
40 return service_id_;
41 }
42 34
43 GLenum target() const { 35 GLenum target() const {
44 return target_; 36 return target_;
45 } 37 }
46 38
47 bool IsDeleted() const { 39 bool IsDeleted() const {
48 return service_id_ == 0; 40 return deleted_;
49 } 41 }
50 42
51 bool IsValid() const { 43 bool IsValid() const {
52 return target() && !IsDeleted(); 44 return target() && !IsDeleted();
53 } 45 }
54 46
47 bool pending() const {
48 return pending_;
49 }
50
55 int32 shm_id() const { 51 int32 shm_id() const {
56 return shm_id_; 52 return shm_id_;
57 } 53 }
58 54
59 uint32 shm_offset() const { 55 uint32 shm_offset() const {
60 return shm_offset_; 56 return shm_offset_;
61 } 57 }
62 58
63 bool pending() const { 59 // Returns false if shared memory for sync is invalid.
64 return pending_; 60 virtual bool Begin() = 0;
61
62 // Returns false if shared memory for sync is invalid.
63 virtual bool End(uint32 submit_count) = 0;
64
65 // Returns false if shared memory for sync is invalid.
66 virtual bool Process() = 0;
67
68 virtual void Destroy(bool have_context) = 0;
69
70 protected:
71 QueryManager* manager() const {
72 return manager_;
65 } 73 }
66 74
67 private: 75 void MarkAsDeleted() {
68 friend class QueryManager; 76 deleted_ = true;
69 friend class QueryManagerTest; 77 }
70 friend class base::RefCounted<Query>;
71 78
72 ~Query(); 79 // Returns false if shared memory for sync is invalid.
80 bool MarkAsCompleted(GLuint result);
73 81
74 void MarkAsPending(uint32 submit_count) { 82 void MarkAsPending(uint32 submit_count) {
75 DCHECK(!pending_); 83 DCHECK(!pending_);
76 pending_ = true; 84 pending_ = true;
77 submit_count_ = submit_count; 85 submit_count_ = submit_count;
78 } 86 }
79 87
80 void MarkAsCompleted() { 88 // Returns false if shared memory for sync is invalid.
81 DCHECK(pending_); 89 bool AddToPendingQueue(uint32 submit_count) {
82 pending_ = false; 90 return manager_->AddPendingQuery(this, submit_count);
83 } 91 }
84 92
93 private:
94 friend class QueryManager;
95 friend class QueryManagerTest;
96 friend class base::RefCounted<Query>;
97
85 uint32 submit_count() const { 98 uint32 submit_count() const {
86 return submit_count_; 99 return submit_count_;
87 } 100 }
88 101
89 void MarkAsDeleted() {
90 service_id_ = 0;
91 }
92
93 // The manager that owns this Query. 102 // The manager that owns this Query.
94 QueryManager* manager_; 103 QueryManager* manager_;
95 104
96 // Service side query id.
97 GLuint service_id_;
98
99 // The type of query. 105 // The type of query.
100 GLenum target_; 106 GLenum target_;
101 107
102 // The shared memory used with this Query. 108 // The shared memory used with this Query.
103 int32 shm_id_; 109 int32 shm_id_;
104 uint32 shm_offset_; 110 uint32 shm_offset_;
105 111
106 // Count to set process count do when completed. 112 // Count to set process count do when completed.
107 uint32 submit_count_; 113 uint32 submit_count_;
108 114
109 // True if in the Queue. 115 // True if in the queue.
110 bool pending_; 116 bool pending_;
117
118 // True if deleted.
119 bool deleted_;
111 }; 120 };
112 121
113 QueryManager(); 122 explicit QueryManager(CommonDecoder* decoder);
114 ~QueryManager(); 123 ~QueryManager();
115 124
116 // Must call before destruction. 125 // Must call before destruction.
117 void Destroy(bool have_context); 126 void Destroy(bool have_context);
118 127
119 // Creates a Query for the given query. 128 // Creates a Query for the given query.
120 Query* CreateQuery(GLuint client_id, GLuint service_id); 129 Query* CreateQuery(
130 GLenum target, GLuint client_id, int32 shm_id, uint32 shm_offset);
121 131
122 // Gets the query info for the given query. 132 // Gets the query info for the given query.
123 Query* GetQuery(GLuint client_id); 133 Query* GetQuery(GLuint client_id);
124 134
125 // Removes a query info for the given query. 135 // Removes a query info for the given query.
126 void RemoveQuery(GLuint client_id); 136 void RemoveQuery(GLuint client_id);
127 137
128 // Gets a client id for a given service id. 138 // Returns false if any query is pointing to invalid shared memory.
129 bool GetClientId(GLuint service_id, GLuint* client_id) const; 139 bool BeginQuery(Query* query);
130 140
131 // Adds to queue of queries waiting for completion. 141 // Returns false if any query is pointing to invalid shared memory.
132 void AddPendingQuery(Query* query, uint32 submit_count); 142 bool EndQuery(Query* query, uint32 submit_count);
133
134 // Removes a query from the queue of pending queries.
135 void RemovePendingQuery(Query* query);
136 143
137 // Processes pending queries. Returns false if any queries are pointing 144 // Processes pending queries. Returns false if any queries are pointing
138 // to invalid shared memory. 145 // to invalid shared memory.
139 bool ProcessPendingQueries(CommonDecoder* decoder); 146 bool ProcessPendingQueries();
140 147
141 private: 148 private:
142 void StartTracking(Query* query); 149 void StartTracking(Query* query);
143 void StopTracking(Query* query); 150 void StopTracking(Query* query);
144 151
152 // Adds to queue of queries waiting for completion.
153 // Returns false if any query is pointing to invalid shared memory.
154 bool AddPendingQuery(Query* query, uint32 submit_count);
155
156 // Removes a query from the queue of pending queries.
157 // Returns false if any query is pointing to invalid shared memory.
158 bool RemovePendingQuery(Query* query);
159
160 // Used to validate shared memory.
161 CommonDecoder* decoder_;
162
145 // Counts the number of Queries allocated with 'this' as their manager. 163 // Counts the number of Queries allocated with 'this' as their manager.
146 // Allows checking no Query will outlive this. 164 // Allows checking no Query will outlive this.
147 unsigned query_count_; 165 unsigned query_count_;
148 166
149 // Info for each query in the system. 167 // Info for each query in the system.
150 typedef base::hash_map<GLuint, Query::Ref> QueryMap; 168 typedef base::hash_map<GLuint, Query::Ref> QueryMap;
151 QueryMap queries_; 169 QueryMap queries_;
152 170
153 // Queries waiting for completion. 171 // Queries waiting for completion.
154 typedef std::deque<Query::Ref> QueryQueue; 172 typedef std::deque<Query::Ref> QueryQueue;
155 QueryQueue pending_queries_; 173 QueryQueue pending_queries_;
156 174
157 DISALLOW_COPY_AND_ASSIGN(QueryManager); 175 DISALLOW_COPY_AND_ASSIGN(QueryManager);
158 }; 176 };
159 177
160 } // namespace gles2 178 } // namespace gles2
161 } // namespace gpu 179 } // namespace gpu
162 180
163 #endif // GPU_COMMAND_BUFFER_SERVICE_QUERY_MANAGER_H_ 181 #endif // GPU_COMMAND_BUFFER_SERVICE_QUERY_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698