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

Side by Side Diff: content/browser/gpu/shader_disk_cache.cc

Issue 2465153002: gpu: Remove some GpuProcessHost dependency from shader cache. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « content/browser/gpu/shader_disk_cache.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/browser/gpu/shader_disk_cache.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/threading/thread_checker.h" 8 #include "base/threading/thread_checker.h"
9 #include "content/browser/gpu/gpu_process_host.h"
10 #include "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
11 #include "gpu/command_buffer/common/constants.h" 10 #include "gpu/command_buffer/common/constants.h"
12 #include "net/base/cache_type.h" 11 #include "net/base/cache_type.h"
13 #include "net/base/io_buffer.h" 12 #include "net/base/io_buffer.h"
14 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
15 14
16 namespace content { 15 namespace content {
17 16
18 namespace { 17 namespace {
19 18
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 65
67 DISALLOW_COPY_AND_ASSIGN(ShaderDiskCacheEntry); 66 DISALLOW_COPY_AND_ASSIGN(ShaderDiskCacheEntry);
68 }; 67 };
69 68
70 // ShaderDiskReadHelper is used to load all of the cached shaders from the 69 // ShaderDiskReadHelper is used to load all of the cached shaders from the
71 // disk cache and send to the memory cache. 70 // disk cache and send to the memory cache.
72 class ShaderDiskReadHelper 71 class ShaderDiskReadHelper
73 : public base::ThreadChecker, 72 : public base::ThreadChecker,
74 public base::RefCounted<ShaderDiskReadHelper> { 73 public base::RefCounted<ShaderDiskReadHelper> {
75 public: 74 public:
76 ShaderDiskReadHelper(base::WeakPtr<ShaderDiskCache> cache, int host_id); 75 using ShaderLoadedCallback = ShaderDiskCache::ShaderLoadedCallback;
76 ShaderDiskReadHelper(base::WeakPtr<ShaderDiskCache> cache,
77 const ShaderLoadedCallback& callback);
77 void LoadCache(); 78 void LoadCache();
78 79
79 private: 80 private:
80 friend class base::RefCounted<ShaderDiskReadHelper>; 81 friend class base::RefCounted<ShaderDiskReadHelper>;
81 82
82 enum OpType { 83 enum OpType {
83 TERMINATE, 84 TERMINATE,
84 OPEN_NEXT, 85 OPEN_NEXT,
85 OPEN_NEXT_COMPLETE, 86 OPEN_NEXT_COMPLETE,
86 READ_COMPLETE, 87 READ_COMPLETE,
87 ITERATION_FINISHED 88 ITERATION_FINISHED
88 }; 89 };
89 90
90 91
91 ~ShaderDiskReadHelper(); 92 ~ShaderDiskReadHelper();
92 93
93 void OnOpComplete(int rv); 94 void OnOpComplete(int rv);
94 95
95 int OpenNextEntry(); 96 int OpenNextEntry();
96 int OpenNextEntryComplete(int rv); 97 int OpenNextEntryComplete(int rv);
97 int ReadComplete(int rv); 98 int ReadComplete(int rv);
98 int IterationComplete(int rv); 99 int IterationComplete(int rv);
99 100
100 base::WeakPtr<ShaderDiskCache> cache_; 101 base::WeakPtr<ShaderDiskCache> cache_;
102 ShaderLoadedCallback shader_loaded_callback_;
101 OpType op_type_; 103 OpType op_type_;
102 std::unique_ptr<disk_cache::Backend::Iterator> iter_; 104 std::unique_ptr<disk_cache::Backend::Iterator> iter_;
103 scoped_refptr<net::IOBufferWithSize> buf_; 105 scoped_refptr<net::IOBufferWithSize> buf_;
104 int host_id_;
105 disk_cache::Entry* entry_; 106 disk_cache::Entry* entry_;
106 107
107 DISALLOW_COPY_AND_ASSIGN(ShaderDiskReadHelper); 108 DISALLOW_COPY_AND_ASSIGN(ShaderDiskReadHelper);
108 }; 109 };
109 110
110 class ShaderClearHelper 111 class ShaderClearHelper
111 : public base::RefCounted<ShaderClearHelper>, 112 : public base::RefCounted<ShaderClearHelper>,
112 public base::SupportsWeakPtr<ShaderClearHelper> { 113 public base::SupportsWeakPtr<ShaderClearHelper> {
113 public: 114 public:
114 ShaderClearHelper(scoped_refptr<ShaderDiskCache> cache, 115 ShaderClearHelper(scoped_refptr<ShaderDiskCache> cache,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 236 }
236 237
237 int ShaderDiskCacheEntry::IOComplete(int rv) { 238 int ShaderDiskCacheEntry::IOComplete(int rv) {
238 DCHECK(CalledOnValidThread()); 239 DCHECK(CalledOnValidThread());
239 // Called through OnOpComplete, so we know |cache_| is valid. 240 // Called through OnOpComplete, so we know |cache_| is valid.
240 cache_->EntryComplete(this); 241 cache_->EntryComplete(this);
241 op_type_ = TERMINATE; 242 op_type_ = TERMINATE;
242 return rv; 243 return rv;
243 } 244 }
244 245
245 ShaderDiskReadHelper::ShaderDiskReadHelper( 246 ShaderDiskReadHelper::ShaderDiskReadHelper(base::WeakPtr<ShaderDiskCache> cache,
246 base::WeakPtr<ShaderDiskCache> cache, 247 const ShaderLoadedCallback& callback)
247 int host_id)
248 : cache_(cache), 248 : cache_(cache),
249 shader_loaded_callback_(callback),
249 op_type_(OPEN_NEXT), 250 op_type_(OPEN_NEXT),
250 buf_(NULL), 251 buf_(NULL),
251 host_id_(host_id), 252 entry_(NULL) {}
252 entry_(NULL) {
253 }
254 253
255 void ShaderDiskReadHelper::LoadCache() { 254 void ShaderDiskReadHelper::LoadCache() {
256 DCHECK(CalledOnValidThread()); 255 DCHECK(CalledOnValidThread());
257 if (!cache_.get()) 256 if (!cache_.get())
258 return; 257 return;
259 OnOpComplete(net::OK); 258 OnOpComplete(net::OK);
260 } 259 }
261 260
262 void ShaderDiskReadHelper::OnOpComplete(int rv) { 261 void ShaderDiskReadHelper::OnOpComplete(int rv) {
263 DCHECK(CalledOnValidThread()); 262 DCHECK(CalledOnValidThread());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 1, 317 1,
319 0, 318 0,
320 buf_.get(), 319 buf_.get(),
321 buf_->size(), 320 buf_->size(),
322 base::Bind(&ShaderDiskReadHelper::OnOpComplete, this)); 321 base::Bind(&ShaderDiskReadHelper::OnOpComplete, this));
323 } 322 }
324 323
325 int ShaderDiskReadHelper::ReadComplete(int rv) { 324 int ShaderDiskReadHelper::ReadComplete(int rv) {
326 DCHECK(CalledOnValidThread()); 325 DCHECK(CalledOnValidThread());
327 // Called through OnOpComplete, so we know |cache_| is valid. 326 // Called through OnOpComplete, so we know |cache_| is valid.
328 if (rv && rv == buf_->size()) { 327 if (rv && rv == buf_->size() && !shader_loaded_callback_.is_null()) {
329 GpuProcessHost* host = GpuProcessHost::FromID(host_id_); 328 shader_loaded_callback_.Run(entry_->GetKey(),
330 if (host) 329 std::string(buf_->data(), buf_->size()));
331 host->LoadedShader(entry_->GetKey(), std::string(buf_->data(),
332 buf_->size()));
333 } 330 }
334 331
335 buf_ = NULL; 332 buf_ = NULL;
336 entry_->Close(); 333 entry_->Close();
337 entry_ = NULL; 334 entry_ = NULL;
338 335
339 op_type_ = OPEN_NEXT; 336 op_type_ = OPEN_NEXT;
340 return net::OK; 337 return net::OK;
341 } 338 }
342 339
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 if (!iter->second.empty()) { 504 if (!iter->second.empty()) {
508 iter->second.front()->Clear(); 505 iter->second.front()->Clear();
509 return; 506 return;
510 } 507 }
511 508
512 shader_clear_map_.erase(path); 509 shader_clear_map_.erase(path);
513 } 510 }
514 511
515 ShaderDiskCache::ShaderDiskCache(const base::FilePath& cache_path) 512 ShaderDiskCache::ShaderDiskCache(const base::FilePath& cache_path)
516 : cache_available_(false), 513 : cache_available_(false),
517 host_id_(0),
518 cache_path_(cache_path), 514 cache_path_(cache_path),
519 is_initialized_(false) { 515 is_initialized_(false) {
520 ShaderCacheFactory::GetInstance()->AddToCache(cache_path_, this); 516 ShaderCacheFactory::GetInstance()->AddToCache(cache_path_, this);
521 } 517 }
522 518
523 ShaderDiskCache::~ShaderDiskCache() { 519 ShaderDiskCache::~ShaderDiskCache() {
524 ShaderCacheFactory::GetInstance()->RemoveFromCache(cache_path_); 520 ShaderCacheFactory::GetInstance()->RemoveFromCache(cache_path_);
525 } 521 }
526 522
527 void ShaderDiskCache::Init() { 523 void ShaderDiskCache::Init() {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 return net::OK; 574 return net::OK;
579 available_callback_ = callback; 575 available_callback_ = callback;
580 return net::ERR_IO_PENDING; 576 return net::ERR_IO_PENDING;
581 } 577 }
582 578
583 void ShaderDiskCache::CacheCreatedCallback(int rv) { 579 void ShaderDiskCache::CacheCreatedCallback(int rv) {
584 if (rv != net::OK) { 580 if (rv != net::OK) {
585 LOG(ERROR) << "Shader Cache Creation failed: " << rv; 581 LOG(ERROR) << "Shader Cache Creation failed: " << rv;
586 return; 582 return;
587 } 583 }
588 helper_ = new ShaderDiskReadHelper(AsWeakPtr(), host_id_); 584 helper_ = new ShaderDiskReadHelper(AsWeakPtr(), shader_loaded_callback_);
589 helper_->LoadCache(); 585 helper_->LoadCache();
590 } 586 }
591 587
592 void ShaderDiskCache::EntryComplete(void* entry) { 588 void ShaderDiskCache::EntryComplete(void* entry) {
593 entry_map_.erase(entry); 589 entry_map_.erase(entry);
594 590
595 if (entry_map_.empty() && !cache_complete_callback_.is_null()) 591 if (entry_map_.empty() && !cache_complete_callback_.is_null())
596 cache_complete_callback_.Run(net::OK); 592 cache_complete_callback_.Run(net::OK);
597 } 593 }
598 594
(...skipping 14 matching lines...) Expand all
613 const net::CompletionCallback& callback) { 609 const net::CompletionCallback& callback) {
614 if (entry_map_.empty()) { 610 if (entry_map_.empty()) {
615 return net::OK; 611 return net::OK;
616 } 612 }
617 cache_complete_callback_ = callback; 613 cache_complete_callback_ = callback;
618 return net::ERR_IO_PENDING; 614 return net::ERR_IO_PENDING;
619 } 615 }
620 616
621 } // namespace content 617 } // namespace content
622 618
OLDNEW
« no previous file with comments | « content/browser/gpu/shader_disk_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698