OLD | NEW |
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 Loading... |
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 Query( |
32 | 32 QueryManager* manager, GLenum target, 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 void BeginQueryHelper(GLenum target, GLuint id) { |
| 94 manager_->BeginQueryHelper(target, id); |
| 95 } |
| 96 |
| 97 void EndQueryHelper(GLenum target) { |
| 98 manager_->EndQueryHelper(target); |
| 99 } |
| 100 |
| 101 private: |
| 102 friend class QueryManager; |
| 103 friend class QueryManagerTest; |
| 104 friend class base::RefCounted<Query>; |
| 105 |
85 uint32 submit_count() const { | 106 uint32 submit_count() const { |
86 return submit_count_; | 107 return submit_count_; |
87 } | 108 } |
88 | 109 |
89 void MarkAsDeleted() { | |
90 service_id_ = 0; | |
91 } | |
92 | |
93 // The manager that owns this Query. | 110 // The manager that owns this Query. |
94 QueryManager* manager_; | 111 QueryManager* manager_; |
95 | 112 |
96 // Service side query id. | |
97 GLuint service_id_; | |
98 | |
99 // The type of query. | 113 // The type of query. |
100 GLenum target_; | 114 GLenum target_; |
101 | 115 |
102 // The shared memory used with this Query. | 116 // The shared memory used with this Query. |
103 int32 shm_id_; | 117 int32 shm_id_; |
104 uint32 shm_offset_; | 118 uint32 shm_offset_; |
105 | 119 |
106 // Count to set process count do when completed. | 120 // Count to set process count do when completed. |
107 uint32 submit_count_; | 121 uint32 submit_count_; |
108 | 122 |
109 // True if in the Queue. | 123 // True if in the queue. |
110 bool pending_; | 124 bool pending_; |
| 125 |
| 126 // True if deleted. |
| 127 bool deleted_; |
111 }; | 128 }; |
112 | 129 |
113 QueryManager(); | 130 QueryManager( |
| 131 CommonDecoder* decoder, |
| 132 bool use_arb_occlusion_query2_for_occlusion_query_boolean); |
114 ~QueryManager(); | 133 ~QueryManager(); |
115 | 134 |
116 // Must call before destruction. | 135 // Must call before destruction. |
117 void Destroy(bool have_context); | 136 void Destroy(bool have_context); |
118 | 137 |
119 // Creates a Query for the given query. | 138 // Creates a Query for the given query. |
120 Query* CreateQuery(GLuint client_id, GLuint service_id); | 139 Query* CreateQuery( |
| 140 GLenum target, GLuint client_id, int32 shm_id, uint32 shm_offset); |
121 | 141 |
122 // Gets the query info for the given query. | 142 // Gets the query info for the given query. |
123 Query* GetQuery(GLuint client_id); | 143 Query* GetQuery(GLuint client_id); |
124 | 144 |
125 // Removes a query info for the given query. | 145 // Removes a query info for the given query. |
126 void RemoveQuery(GLuint client_id); | 146 void RemoveQuery(GLuint client_id); |
127 | 147 |
128 // Gets a client id for a given service id. | 148 // Returns false if any query is pointing to invalid shared memory. |
129 bool GetClientId(GLuint service_id, GLuint* client_id) const; | 149 bool BeginQuery(Query* query); |
130 | 150 |
131 // Adds to queue of queries waiting for completion. | 151 // Returns false if any query is pointing to invalid shared memory. |
132 void AddPendingQuery(Query* query, uint32 submit_count); | 152 bool EndQuery(Query* query, uint32 submit_count); |
133 | |
134 // Removes a query from the queue of pending queries. | |
135 void RemovePendingQuery(Query* query); | |
136 | 153 |
137 // Processes pending queries. Returns false if any queries are pointing | 154 // Processes pending queries. Returns false if any queries are pointing |
138 // to invalid shared memory. | 155 // to invalid shared memory. |
139 bool ProcessPendingQueries(CommonDecoder* decoder); | 156 bool ProcessPendingQueries(); |
140 | 157 |
141 // True if there are pending queries. | 158 // True if there are pending queries. |
142 bool HavePendingQueries(); | 159 bool HavePendingQueries(); |
143 | 160 |
144 private: | 161 private: |
145 void StartTracking(Query* query); | 162 void StartTracking(Query* query); |
146 void StopTracking(Query* query); | 163 void StopTracking(Query* query); |
147 | 164 |
| 165 // Wrappers for BeginQueryARB and EndQueryARB to hide differences between |
| 166 // ARB_occlusion_query2 and EXT_occlusion_query_boolean. |
| 167 void BeginQueryHelper(GLenum target, GLuint id); |
| 168 void EndQueryHelper(GLenum target); |
| 169 |
| 170 // Adds to queue of queries waiting for completion. |
| 171 // Returns false if any query is pointing to invalid shared memory. |
| 172 bool AddPendingQuery(Query* query, uint32 submit_count); |
| 173 |
| 174 // Removes a query from the queue of pending queries. |
| 175 // Returns false if any query is pointing to invalid shared memory. |
| 176 bool RemovePendingQuery(Query* query); |
| 177 |
| 178 // Used to validate shared memory. |
| 179 CommonDecoder* decoder_; |
| 180 |
| 181 bool use_arb_occlusion_query2_for_occlusion_query_boolean_; |
| 182 |
148 // Counts the number of Queries allocated with 'this' as their manager. | 183 // Counts the number of Queries allocated with 'this' as their manager. |
149 // Allows checking no Query will outlive this. | 184 // Allows checking no Query will outlive this. |
150 unsigned query_count_; | 185 unsigned query_count_; |
151 | 186 |
152 // Info for each query in the system. | 187 // Info for each query in the system. |
153 typedef base::hash_map<GLuint, Query::Ref> QueryMap; | 188 typedef base::hash_map<GLuint, Query::Ref> QueryMap; |
154 QueryMap queries_; | 189 QueryMap queries_; |
155 | 190 |
156 // Queries waiting for completion. | 191 // Queries waiting for completion. |
157 typedef std::deque<Query::Ref> QueryQueue; | 192 typedef std::deque<Query::Ref> QueryQueue; |
158 QueryQueue pending_queries_; | 193 QueryQueue pending_queries_; |
159 | 194 |
160 DISALLOW_COPY_AND_ASSIGN(QueryManager); | 195 DISALLOW_COPY_AND_ASSIGN(QueryManager); |
161 }; | 196 }; |
162 | 197 |
163 } // namespace gles2 | 198 } // namespace gles2 |
164 } // namespace gpu | 199 } // namespace gpu |
165 | 200 |
166 #endif // GPU_COMMAND_BUFFER_SERVICE_QUERY_MANAGER_H_ | 201 #endif // GPU_COMMAND_BUFFER_SERVICE_QUERY_MANAGER_H_ |
OLD | NEW |