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 "content/browser/gpu/shader_disk_cache.h" |
6 | 6 |
7 #include "base/profiler/scoped_tracker.h" | |
8 #include "base/threading/thread_checker.h" | 7 #include "base/threading/thread_checker.h" |
9 #include "content/browser/gpu/gpu_process_host.h" | 8 #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 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 } | 252 } |
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 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | |
264 tracked_objects::ScopedTracker tracking_profile( | |
265 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
266 "422516 ShaderDiskReadHelper::OnOpComplete")); | |
267 | |
268 DCHECK(CalledOnValidThread()); | 262 DCHECK(CalledOnValidThread()); |
269 if (!cache_.get()) | 263 if (!cache_.get()) |
270 return; | 264 return; |
271 | 265 |
272 do { | 266 do { |
273 switch (op_type_) { | 267 switch (op_type_) { |
274 case OPEN_NEXT: | 268 case OPEN_NEXT: |
275 rv = OpenNextEntry(); | 269 rv = OpenNextEntry(); |
276 break; | 270 break; |
277 case OPEN_NEXT_COMPLETE: | 271 case OPEN_NEXT_COMPLETE: |
(...skipping 11 matching lines...) Expand all Loading... |
289 break; | 283 break; |
290 default: | 284 default: |
291 NOTREACHED(); // Invalid state for read helper | 285 NOTREACHED(); // Invalid state for read helper |
292 rv = net::ERR_FAILED; | 286 rv = net::ERR_FAILED; |
293 break; | 287 break; |
294 } | 288 } |
295 } while (rv != net::ERR_IO_PENDING); | 289 } while (rv != net::ERR_IO_PENDING); |
296 } | 290 } |
297 | 291 |
298 int ShaderDiskReadHelper::OpenNextEntry() { | 292 int ShaderDiskReadHelper::OpenNextEntry() { |
299 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | |
300 tracked_objects::ScopedTracker tracking_profile( | |
301 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
302 "422516 ShaderDiskReadHelper::OpenNextEntry")); | |
303 | |
304 DCHECK(CalledOnValidThread()); | 293 DCHECK(CalledOnValidThread()); |
305 // Called through OnOpComplete, so we know |cache_| is valid. | 294 // Called through OnOpComplete, so we know |cache_| is valid. |
306 op_type_ = OPEN_NEXT_COMPLETE; | 295 op_type_ = OPEN_NEXT_COMPLETE; |
307 if (!iter_) | 296 if (!iter_) |
308 iter_ = cache_->backend()->CreateIterator(); | 297 iter_ = cache_->backend()->CreateIterator(); |
309 return iter_->OpenNextEntry( | 298 return iter_->OpenNextEntry( |
310 &entry_, base::Bind(&ShaderDiskReadHelper::OnOpComplete, this)); | 299 &entry_, base::Bind(&ShaderDiskReadHelper::OnOpComplete, this)); |
311 } | 300 } |
312 | 301 |
313 int ShaderDiskReadHelper::OpenNextEntryComplete(int rv) { | 302 int ShaderDiskReadHelper::OpenNextEntryComplete(int rv) { |
314 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | |
315 tracked_objects::ScopedTracker tracking_profile( | |
316 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
317 "422516 ShaderDiskReadHelper::OpenNextEntryComplete")); | |
318 | |
319 DCHECK(CalledOnValidThread()); | 303 DCHECK(CalledOnValidThread()); |
320 // Called through OnOpComplete, so we know |cache_| is valid. | 304 // Called through OnOpComplete, so we know |cache_| is valid. |
321 if (rv == net::ERR_FAILED) { | 305 if (rv == net::ERR_FAILED) { |
322 iter_.reset(); | 306 iter_.reset(); |
323 op_type_ = ITERATION_FINISHED; | 307 op_type_ = ITERATION_FINISHED; |
324 return net::OK; | 308 return net::OK; |
325 } | 309 } |
326 | 310 |
327 if (rv < 0) | 311 if (rv < 0) |
328 return rv; | 312 return rv; |
329 | 313 |
330 op_type_ = READ_COMPLETE; | 314 op_type_ = READ_COMPLETE; |
331 buf_ = new net::IOBufferWithSize(entry_->GetDataSize(1)); | 315 buf_ = new net::IOBufferWithSize(entry_->GetDataSize(1)); |
332 return entry_->ReadData( | 316 return entry_->ReadData( |
333 1, | 317 1, |
334 0, | 318 0, |
335 buf_.get(), | 319 buf_.get(), |
336 buf_->size(), | 320 buf_->size(), |
337 base::Bind(&ShaderDiskReadHelper::OnOpComplete, this)); | 321 base::Bind(&ShaderDiskReadHelper::OnOpComplete, this)); |
338 } | 322 } |
339 | 323 |
340 int ShaderDiskReadHelper::ReadComplete(int rv) { | 324 int ShaderDiskReadHelper::ReadComplete(int rv) { |
341 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | |
342 tracked_objects::ScopedTracker tracking_profile( | |
343 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
344 "422516 ShaderDiskReadHelper::ReadComplete")); | |
345 | |
346 DCHECK(CalledOnValidThread()); | 325 DCHECK(CalledOnValidThread()); |
347 // Called through OnOpComplete, so we know |cache_| is valid. | 326 // Called through OnOpComplete, so we know |cache_| is valid. |
348 if (rv && rv == buf_->size()) { | 327 if (rv && rv == buf_->size()) { |
349 GpuProcessHost* host = GpuProcessHost::FromID(host_id_); | 328 GpuProcessHost* host = GpuProcessHost::FromID(host_id_); |
350 if (host) | 329 if (host) |
351 host->LoadedShader(entry_->GetKey(), std::string(buf_->data(), | 330 host->LoadedShader(entry_->GetKey(), std::string(buf_->data(), |
352 buf_->size())); | 331 buf_->size())); |
353 } | 332 } |
354 | 333 |
355 buf_ = NULL; | 334 buf_ = NULL; |
356 entry_->Close(); | 335 entry_->Close(); |
357 entry_ = NULL; | 336 entry_ = NULL; |
358 | 337 |
359 op_type_ = OPEN_NEXT; | 338 op_type_ = OPEN_NEXT; |
360 return net::OK; | 339 return net::OK; |
361 } | 340 } |
362 | 341 |
363 int ShaderDiskReadHelper::IterationComplete(int rv) { | 342 int ShaderDiskReadHelper::IterationComplete(int rv) { |
364 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | |
365 tracked_objects::ScopedTracker tracking_profile( | |
366 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
367 "422516 ShaderDiskReadHelper::IterationComplete")); | |
368 | |
369 DCHECK(CalledOnValidThread()); | 343 DCHECK(CalledOnValidThread()); |
370 // Called through OnOpComplete, so we know |cache_| is valid. | 344 // Called through OnOpComplete, so we know |cache_| is valid. |
371 iter_.reset(); | 345 iter_.reset(); |
372 op_type_ = TERMINATE; | 346 op_type_ = TERMINATE; |
373 return net::OK; | 347 return net::OK; |
374 } | 348 } |
375 | 349 |
376 ShaderDiskReadHelper::~ShaderDiskReadHelper() { | 350 ShaderDiskReadHelper::~ShaderDiskReadHelper() { |
377 if (entry_) { | 351 if (entry_) { |
378 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 352 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 const net::CompletionCallback& callback) { | 616 const net::CompletionCallback& callback) { |
643 if (entry_map_.empty()) { | 617 if (entry_map_.empty()) { |
644 return net::OK; | 618 return net::OK; |
645 } | 619 } |
646 cache_complete_callback_ = callback; | 620 cache_complete_callback_ = callback; |
647 return net::ERR_IO_PENDING; | 621 return net::ERR_IO_PENDING; |
648 } | 622 } |
649 | 623 |
650 } // namespace content | 624 } // namespace content |
651 | 625 |
OLD | NEW |