| 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 #include "gpu/command_buffer/service/query_manager.h" | 5 #include "gpu/command_buffer/service/query_manager.h" |
| 6 | 6 |
| 7 #include "base/atomicops.h" | 7 #include "base/atomicops.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 , public base::SupportsWeakPtr<AsyncPixelTransfersCompletedQuery> { | 172 , public base::SupportsWeakPtr<AsyncPixelTransfersCompletedQuery> { |
| 173 public: | 173 public: |
| 174 AsyncPixelTransfersCompletedQuery( | 174 AsyncPixelTransfersCompletedQuery( |
| 175 QueryManager* manager, GLenum target, int32 shm_id, uint32 shm_offset); | 175 QueryManager* manager, GLenum target, int32 shm_id, uint32 shm_offset); |
| 176 | 176 |
| 177 virtual bool Begin() OVERRIDE; | 177 virtual bool Begin() OVERRIDE; |
| 178 virtual bool End(uint32 submit_count) OVERRIDE; | 178 virtual bool End(uint32 submit_count) OVERRIDE; |
| 179 virtual bool Process() OVERRIDE; | 179 virtual bool Process() OVERRIDE; |
| 180 virtual void Destroy(bool have_context) OVERRIDE; | 180 virtual void Destroy(bool have_context) OVERRIDE; |
| 181 | 181 |
| 182 protected: | |
| 183 virtual ~AsyncPixelTransfersCompletedQuery(); | |
| 184 | |
| 185 static void MarkAsCompletedThreadSafe( | 182 static void MarkAsCompletedThreadSafe( |
| 186 uint32 submit_count, const AsyncMemoryParams& mem_params) { | 183 uint32 submit_count, const AsyncMemoryParams& mem_params) { |
| 187 DCHECK(mem_params.shared_memory); | 184 DCHECK(mem_params.shared_memory); |
| 188 DCHECK(mem_params.shared_memory->memory()); | 185 DCHECK(mem_params.shared_memory->memory()); |
| 189 void *data = static_cast<int8*>(mem_params.shared_memory->memory()) + | 186 void *data = static_cast<int8*>(mem_params.shared_memory->memory()) + |
| 190 mem_params.shm_data_offset; | 187 mem_params.shm_data_offset; |
| 191 QuerySync* sync = static_cast<QuerySync*>(data); | 188 QuerySync* sync = static_cast<QuerySync*>(data); |
| 192 | 189 |
| 193 // Need a MemoryBarrier here to ensure that upload completed before | 190 // Need a MemoryBarrier here to ensure that upload completed before |
| 194 // submit_count was written to sync->process_count. | 191 // submit_count was written to sync->process_count. |
| 195 base::subtle::MemoryBarrier(); | 192 base::subtle::MemoryBarrier(); |
| 196 sync->process_count = submit_count; | 193 sync->process_count = submit_count; |
| 197 } | 194 } |
| 195 |
| 196 protected: |
| 197 virtual ~AsyncPixelTransfersCompletedQuery(); |
| 198 |
| 198 }; | 199 }; |
| 199 | 200 |
| 200 AsyncPixelTransfersCompletedQuery::AsyncPixelTransfersCompletedQuery( | 201 AsyncPixelTransfersCompletedQuery::AsyncPixelTransfersCompletedQuery( |
| 201 QueryManager* manager, GLenum target, int32 shm_id, uint32 shm_offset) | 202 QueryManager* manager, GLenum target, int32 shm_id, uint32 shm_offset) |
| 202 : Query(manager, target, shm_id, shm_offset) { | 203 : Query(manager, target, shm_id, shm_offset) { |
| 203 } | 204 } |
| 204 | 205 |
| 205 bool AsyncPixelTransfersCompletedQuery::Begin() { | 206 bool AsyncPixelTransfersCompletedQuery::Begin() { |
| 206 return true; | 207 return true; |
| 207 } | 208 } |
| 208 | 209 |
| 209 bool AsyncPixelTransfersCompletedQuery::End(uint32 submit_count) { | 210 bool AsyncPixelTransfersCompletedQuery::End(uint32 submit_count) { |
| 210 AsyncMemoryParams mem_params; | 211 AsyncMemoryParams mem_params; |
| 211 // Get the real shared memory since it might need to be duped to prevent | 212 // Get the real shared memory since it might need to be duped to prevent |
| 212 // use-after-free of the memory. | 213 // use-after-free of the memory. |
| 213 Buffer buffer = manager()->decoder()->GetSharedMemoryBuffer(shm_id()); | 214 Buffer buffer = manager()->decoder()->GetSharedMemoryBuffer(shm_id()); |
| 214 if (!buffer.shared_memory) | 215 if (!buffer.shared_memory) |
| 215 return false; | 216 return false; |
| 216 mem_params.shared_memory = buffer.shared_memory; | 217 mem_params.shared_memory = buffer.shared_memory; |
| 217 mem_params.shm_size = buffer.size; | 218 mem_params.shm_size = buffer.size; |
| 218 mem_params.shm_data_offset = shm_offset(); | 219 mem_params.shm_data_offset = shm_offset(); |
| 219 mem_params.shm_data_size = sizeof(QuerySync); | 220 mem_params.shm_data_size = sizeof(QuerySync); |
| 220 | 221 |
| 221 // Ask AsyncPixelTransferDelegate to run completion callback after all | 222 // Ask AsyncPixelTransferDelegate to run completion callback after all |
| 222 // previous async transfers are done. No guarantee that callback is run | 223 // previous async transfers are done. No guarantee that callback is run |
| 223 // on the current thread. | 224 // on the current thread. |
| 224 manager()->decoder()->GetAsyncPixelTransferManager()->AsyncNotifyCompletion( | 225 manager()->decoder()->GetAsyncPixelTransferManager()->AsyncNotifyCompletion( |
| 225 mem_params, | 226 mem_params, |
| 226 base::Bind(AsyncPixelTransfersCompletedQuery::MarkAsCompletedThreadSafe, | 227 base::Bind(&AsyncPixelTransfersCompletedQuery::MarkAsCompletedThreadSafe, |
| 227 submit_count)); | 228 submit_count)); |
| 228 | |
| 229 return AddToPendingTransferQueue(submit_count); | 229 return AddToPendingTransferQueue(submit_count); |
| 230 } | 230 } |
| 231 | 231 |
| 232 bool AsyncPixelTransfersCompletedQuery::Process() { | 232 bool AsyncPixelTransfersCompletedQuery::Process() { |
| 233 QuerySync* sync = manager()->decoder()->GetSharedMemoryAs<QuerySync*>( | 233 QuerySync* sync = manager()->decoder()->GetSharedMemoryAs<QuerySync*>( |
| 234 shm_id(), shm_offset(), sizeof(*sync)); | 234 shm_id(), shm_offset(), sizeof(*sync)); |
| 235 if (!sync) | 235 if (!sync) |
| 236 return false; | 236 return false; |
| 237 | 237 |
| 238 // Check if completion callback has been run. sync->process_count atomicity | 238 // Check if completion callback has been run. sync->process_count atomicity |
| 239 // is guaranteed as this is already used to notify client of a completed | 239 // is guaranteed as this is already used to notify client of a completed |
| 240 // query. | 240 // query. |
| 241 if (sync->process_count != submit_count()) | 241 if (sync->process_count != submit_count()) |
| 242 return true; | 242 return true; |
| 243 | 243 |
| 244 UnmarkAsPending(); | 244 UnmarkAsPending(); |
| 245 return true; | 245 return true; |
| 246 } | 246 } |
| 247 | 247 |
| 248 void AsyncPixelTransfersCompletedQuery::Destroy(bool /* have_context */) { | 248 void AsyncPixelTransfersCompletedQuery::Destroy(bool /* have_context */) { |
| 249 if (!IsDeleted()) { | 249 if (!IsDeleted()) { |
| 250 MarkAsDeleted(); | 250 MarkAsDeleted(); |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 | 253 |
| 254 AsyncPixelTransfersCompletedQuery::~AsyncPixelTransfersCompletedQuery() { | 254 AsyncPixelTransfersCompletedQuery::~AsyncPixelTransfersCompletedQuery() { |
| 255 } | 255 } |
| 256 | 256 |
| 257 /////////////////// |
| 258 class AsyncReadPixelsCompletedQuery |
| 259 : public QueryManager::Query |
| 260 , public base::SupportsWeakPtr<AsyncReadPixelsCompletedQuery> { |
| 261 public: |
| 262 AsyncReadPixelsCompletedQuery( |
| 263 QueryManager* manager, GLenum target, int32 shm_id, uint32 shm_offset); |
| 264 |
| 265 virtual bool Begin() OVERRIDE; |
| 266 virtual bool End(uint32 submit_count) OVERRIDE; |
| 267 virtual bool Process() OVERRIDE; |
| 268 virtual void Destroy(bool have_context) OVERRIDE; |
| 269 |
| 270 protected: |
| 271 void Complete(); |
| 272 virtual ~AsyncReadPixelsCompletedQuery(); |
| 273 }; |
| 274 |
| 275 AsyncReadPixelsCompletedQuery::AsyncReadPixelsCompletedQuery( |
| 276 QueryManager* manager, GLenum target, int32 shm_id, uint32 shm_offset) |
| 277 : Query(manager, target, shm_id, shm_offset) { |
| 278 } |
| 279 |
| 280 bool AsyncReadPixelsCompletedQuery::Begin() { |
| 281 return true; |
| 282 } |
| 283 |
| 284 bool AsyncReadPixelsCompletedQuery::End(uint32 submit_count) { |
| 285 manager()->decoder()->WaitForReadPixels( |
| 286 base::Bind(&AsyncReadPixelsCompletedQuery::Complete, |
| 287 AsWeakPtr())); |
| 288 |
| 289 return AddToPendingTransferQueue(submit_count); |
| 290 } |
| 291 |
| 292 void AsyncReadPixelsCompletedQuery::Complete() { |
| 293 MarkAsCompleted(1); |
| 294 } |
| 295 |
| 296 bool AsyncReadPixelsCompletedQuery::Process() { |
| 297 return !pending(); |
| 298 } |
| 299 |
| 300 void AsyncReadPixelsCompletedQuery::Destroy(bool /* have_context */) { |
| 301 if (!IsDeleted()) { |
| 302 MarkAsDeleted(); |
| 303 } |
| 304 } |
| 305 |
| 306 AsyncReadPixelsCompletedQuery::~AsyncReadPixelsCompletedQuery() { |
| 307 } |
| 308 |
| 309 |
| 257 class GetErrorQuery : public QueryManager::Query { | 310 class GetErrorQuery : public QueryManager::Query { |
| 258 public: | 311 public: |
| 259 GetErrorQuery( | 312 GetErrorQuery( |
| 260 QueryManager* manager, GLenum target, int32 shm_id, uint32 shm_offset); | 313 QueryManager* manager, GLenum target, int32 shm_id, uint32 shm_offset); |
| 261 | 314 |
| 262 virtual bool Begin() OVERRIDE; | 315 virtual bool Begin() OVERRIDE; |
| 263 virtual bool End(uint32 submit_count) OVERRIDE; | 316 virtual bool End(uint32 submit_count) OVERRIDE; |
| 264 virtual bool Process() OVERRIDE; | 317 virtual bool Process() OVERRIDE; |
| 265 virtual void Destroy(bool have_context) OVERRIDE; | 318 virtual void Destroy(bool have_context) OVERRIDE; |
| 266 | 319 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 case GL_COMMANDS_ISSUED_CHROMIUM: | 391 case GL_COMMANDS_ISSUED_CHROMIUM: |
| 339 query = new CommandsIssuedQuery(this, target, shm_id, shm_offset); | 392 query = new CommandsIssuedQuery(this, target, shm_id, shm_offset); |
| 340 break; | 393 break; |
| 341 case GL_LATENCY_QUERY_CHROMIUM: | 394 case GL_LATENCY_QUERY_CHROMIUM: |
| 342 query = new CommandLatencyQuery(this, target, shm_id, shm_offset); | 395 query = new CommandLatencyQuery(this, target, shm_id, shm_offset); |
| 343 break; | 396 break; |
| 344 case GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM: | 397 case GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM: |
| 345 query = new AsyncPixelTransfersCompletedQuery( | 398 query = new AsyncPixelTransfersCompletedQuery( |
| 346 this, target, shm_id, shm_offset); | 399 this, target, shm_id, shm_offset); |
| 347 break; | 400 break; |
| 401 case GL_ASYNC_READ_PIXELS_COMPLETED_CHROMIUM: |
| 402 query = new AsyncReadPixelsCompletedQuery( |
| 403 this, target, shm_id, shm_offset); |
| 404 break; |
| 348 case GL_GET_ERROR_QUERY_CHROMIUM: | 405 case GL_GET_ERROR_QUERY_CHROMIUM: |
| 349 query = new GetErrorQuery(this, target, shm_id, shm_offset); | 406 query = new GetErrorQuery(this, target, shm_id, shm_offset); |
| 350 break; | 407 break; |
| 351 default: { | 408 default: { |
| 352 GLuint service_id = 0; | 409 GLuint service_id = 0; |
| 353 glGenQueriesARB(1, &service_id); | 410 glGenQueriesARB(1, &service_id); |
| 354 DCHECK_NE(0u, service_id); | 411 DCHECK_NE(0u, service_id); |
| 355 query = new AllSamplesPassedQuery( | 412 query = new AllSamplesPassedQuery( |
| 356 this, target, shm_id, shm_offset, service_id); | 413 this, target, shm_id, shm_offset, service_id); |
| 357 break; | 414 break; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 bool QueryManager::EndQuery(Query* query, uint32 submit_count) { | 633 bool QueryManager::EndQuery(Query* query, uint32 submit_count) { |
| 577 DCHECK(query); | 634 DCHECK(query); |
| 578 if (!RemovePendingQuery(query)) { | 635 if (!RemovePendingQuery(query)) { |
| 579 return false; | 636 return false; |
| 580 } | 637 } |
| 581 return query->End(submit_count); | 638 return query->End(submit_count); |
| 582 } | 639 } |
| 583 | 640 |
| 584 } // namespace gles2 | 641 } // namespace gles2 |
| 585 } // namespace gpu | 642 } // namespace gpu |
| OLD | NEW |