OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/browser/gpu/shader_disk_cache.h" | 5 #include "gpu/ipc/host/shader_disk_cache.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/threading/thread_checker.h" | 10 #include "base/threading/thread_checker.h" |
11 #include "gpu/command_buffer/common/constants.h" | 11 #include "gpu/command_buffer/common/constants.h" |
12 #include "net/base/cache_type.h" | 12 #include "net/base/cache_type.h" |
13 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
15 | 15 |
16 namespace content { | 16 namespace gpu { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 static const base::FilePath::CharType kGpuCachePath[] = | 20 static const base::FilePath::CharType kGpuCachePath[] = |
21 FILE_PATH_LITERAL("GPUCache"); | 21 FILE_PATH_LITERAL("GPUCache"); |
22 | 22 |
23 } // namespace | 23 } // namespace |
24 | 24 |
25 // ShaderDiskCacheEntry handles the work of caching/updating the cached | 25 // ShaderDiskCacheEntry handles the work of caching/updating the cached |
26 // shaders. | 26 // shaders. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 private: | 71 private: |
72 enum OpType { | 72 enum OpType { |
73 TERMINATE, | 73 TERMINATE, |
74 OPEN_NEXT, | 74 OPEN_NEXT, |
75 OPEN_NEXT_COMPLETE, | 75 OPEN_NEXT_COMPLETE, |
76 READ_COMPLETE, | 76 READ_COMPLETE, |
77 ITERATION_FINISHED | 77 ITERATION_FINISHED |
78 }; | 78 }; |
79 | 79 |
80 | |
81 void OnOpComplete(int rv); | 80 void OnOpComplete(int rv); |
82 | 81 |
83 int OpenNextEntry(); | 82 int OpenNextEntry(); |
84 int OpenNextEntryComplete(int rv); | 83 int OpenNextEntryComplete(int rv); |
85 int ReadComplete(int rv); | 84 int ReadComplete(int rv); |
86 int IterationComplete(int rv); | 85 int IterationComplete(int rv); |
87 | 86 |
88 ShaderDiskCache* cache_; | 87 ShaderDiskCache* cache_; |
89 ShaderLoadedCallback shader_loaded_callback_; | 88 ShaderLoadedCallback shader_loaded_callback_; |
90 OpType op_type_; | 89 OpType op_type_; |
(...skipping 11 matching lines...) Expand all Loading... |
102 scoped_refptr<ShaderDiskCache> cache, | 101 scoped_refptr<ShaderDiskCache> cache, |
103 const base::FilePath& path, | 102 const base::FilePath& path, |
104 const base::Time& delete_begin, | 103 const base::Time& delete_begin, |
105 const base::Time& delete_end, | 104 const base::Time& delete_end, |
106 const base::Closure& callback); | 105 const base::Closure& callback); |
107 ~ShaderClearHelper(); | 106 ~ShaderClearHelper(); |
108 | 107 |
109 void Clear(); | 108 void Clear(); |
110 | 109 |
111 private: | 110 private: |
112 enum OpType { | 111 enum OpType { TERMINATE, VERIFY_CACHE_SETUP, DELETE_CACHE }; |
113 TERMINATE, | |
114 VERIFY_CACHE_SETUP, | |
115 DELETE_CACHE | |
116 }; | |
117 | 112 |
118 void DoClearShaderCache(int rv); | 113 void DoClearShaderCache(int rv); |
119 | 114 |
120 ShaderCacheFactory* factory_; | 115 ShaderCacheFactory* factory_; |
121 scoped_refptr<ShaderDiskCache> cache_; | 116 scoped_refptr<ShaderDiskCache> cache_; |
122 OpType op_type_; | 117 OpType op_type_; |
123 base::FilePath path_; | 118 base::FilePath path_; |
124 base::Time delete_begin_; | 119 base::Time delete_begin_; |
125 base::Time delete_end_; | 120 base::Time delete_end_; |
126 base::Closure callback_; | 121 base::Closure callback_; |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 } | 364 } |
370 } | 365 } |
371 | 366 |
372 //////////////////////////////////////////////////////////////////////////////// | 367 //////////////////////////////////////////////////////////////////////////////// |
373 // ShaderCacheFactory | 368 // ShaderCacheFactory |
374 | 369 |
375 ShaderCacheFactory::ShaderCacheFactory( | 370 ShaderCacheFactory::ShaderCacheFactory( |
376 scoped_refptr<base::SingleThreadTaskRunner> cache_task_runner) | 371 scoped_refptr<base::SingleThreadTaskRunner> cache_task_runner) |
377 : cache_task_runner_(std::move(cache_task_runner)) {} | 372 : cache_task_runner_(std::move(cache_task_runner)) {} |
378 | 373 |
379 ShaderCacheFactory::~ShaderCacheFactory() { | 374 ShaderCacheFactory::~ShaderCacheFactory() {} |
380 } | |
381 | 375 |
382 void ShaderCacheFactory::SetCacheInfo(int32_t client_id, | 376 void ShaderCacheFactory::SetCacheInfo(int32_t client_id, |
383 const base::FilePath& path) { | 377 const base::FilePath& path) { |
384 DCHECK(CalledOnValidThread()); | 378 DCHECK(CalledOnValidThread()); |
385 client_id_to_path_map_[client_id] = path; | 379 client_id_to_path_map_[client_id] = path; |
386 } | 380 } |
387 | 381 |
388 void ShaderCacheFactory::RemoveCacheInfo(int32_t client_id) { | 382 void ShaderCacheFactory::RemoveCacheInfo(int32_t client_id) { |
389 DCHECK(CalledOnValidThread()); | 383 DCHECK(CalledOnValidThread()); |
390 client_id_to_path_map_.erase(client_id); | 384 client_id_to_path_map_.erase(client_id); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 void ShaderDiskCache::Cache(const std::string& key, const std::string& shader) { | 503 void ShaderDiskCache::Cache(const std::string& key, const std::string& shader) { |
510 if (!cache_available_) | 504 if (!cache_available_) |
511 return; | 505 return; |
512 | 506 |
513 auto shim = base::MakeUnique<ShaderDiskCacheEntry>(this, key, shader); | 507 auto shim = base::MakeUnique<ShaderDiskCacheEntry>(this, key, shader); |
514 shim->Cache(); | 508 shim->Cache(); |
515 auto* raw_ptr = shim.get(); | 509 auto* raw_ptr = shim.get(); |
516 entries_.insert(std::make_pair(raw_ptr, std::move(shim))); | 510 entries_.insert(std::make_pair(raw_ptr, std::move(shim))); |
517 } | 511 } |
518 | 512 |
519 int ShaderDiskCache::Clear( | 513 int ShaderDiskCache::Clear(const base::Time begin_time, |
520 const base::Time begin_time, const base::Time end_time, | 514 const base::Time end_time, |
521 const net::CompletionCallback& completion_callback) { | 515 const net::CompletionCallback& completion_callback) { |
522 int rv; | 516 int rv; |
523 if (begin_time.is_null()) { | 517 if (begin_time.is_null()) { |
524 rv = backend_->DoomAllEntries(completion_callback); | 518 rv = backend_->DoomAllEntries(completion_callback); |
525 } else { | 519 } else { |
526 rv = backend_->DoomEntriesBetween(begin_time, end_time, | 520 rv = |
527 completion_callback); | 521 backend_->DoomEntriesBetween(begin_time, end_time, completion_callback); |
528 } | 522 } |
529 return rv; | 523 return rv; |
530 } | 524 } |
531 | 525 |
532 int32_t ShaderDiskCache::Size() { | 526 int32_t ShaderDiskCache::Size() { |
533 if (!cache_available_) | 527 if (!cache_available_) |
534 return -1; | 528 return -1; |
535 return backend_->GetEntryCount(); | 529 return backend_->GetEntryCount(); |
536 } | 530 } |
537 | 531 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 | 568 |
575 int ShaderDiskCache::SetCacheCompleteCallback( | 569 int ShaderDiskCache::SetCacheCompleteCallback( |
576 const net::CompletionCallback& callback) { | 570 const net::CompletionCallback& callback) { |
577 if (entries_.empty()) { | 571 if (entries_.empty()) { |
578 return net::OK; | 572 return net::OK; |
579 } | 573 } |
580 cache_complete_callback_ = callback; | 574 cache_complete_callback_ = callback; |
581 return net::ERR_IO_PENDING; | 575 return net::ERR_IO_PENDING; |
582 } | 576 } |
583 | 577 |
584 } // namespace content | 578 } // namespace gpu |
OLD | NEW |