OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/resources/raster_worker_pool.h" | 5 #include "cc/resources/raster_worker_pool.h" |
6 | 6 |
7 #include "base/command_line.h" | |
7 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
8 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
9 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "base/strings/string_number_conversions.h" | |
12 #include "cc/base/switches.h" | |
10 #include "cc/debug/devtools_instrumentation.h" | 13 #include "cc/debug/devtools_instrumentation.h" |
11 #include "cc/debug/traced_value.h" | 14 #include "cc/debug/traced_value.h" |
12 #include "cc/resources/picture_pile_impl.h" | 15 #include "cc/resources/picture_pile_impl.h" |
13 #include "skia/ext/lazy_pixel_ref.h" | 16 #include "skia/ext/lazy_pixel_ref.h" |
14 #include "skia/ext/paint_simplifier.h" | 17 #include "skia/ext/paint_simplifier.h" |
15 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
16 | 19 |
17 namespace cc { | 20 namespace cc { |
18 | 21 |
22 const int kMinRasterThreads = 1; | |
23 const int kMaxRasterThreads = 64; | |
24 const int kDefaultNumRasterThreads = 1; | |
25 | |
19 namespace { | 26 namespace { |
20 | 27 |
21 // Subclass of Allocator that takes a suitably allocated pointer and uses | 28 // Subclass of Allocator that takes a suitably allocated pointer and uses |
22 // it as the pixel memory for the bitmap. | 29 // it as the pixel memory for the bitmap. |
23 class IdentityAllocator : public SkBitmap::Allocator { | 30 class IdentityAllocator : public SkBitmap::Allocator { |
24 public: | 31 public: |
25 explicit IdentityAllocator(void* buffer) : buffer_(buffer) {} | 32 explicit IdentityAllocator(void* buffer) : buffer_(buffer) {} |
26 virtual bool allocPixelRef(SkBitmap* dst, SkColorTable*) OVERRIDE { | 33 virtual bool allocPixelRef(SkBitmap* dst, SkColorTable*) OVERRIDE { |
27 dst->setPixels(buffer_); | 34 dst->setPixels(buffer_); |
28 return true; | 35 return true; |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 void RunOnOriginThread() const { | 319 void RunOnOriginThread() const { |
313 on_raster_finished_callback_.Run(this); | 320 on_raster_finished_callback_.Run(this); |
314 } | 321 } |
315 | 322 |
316 scoped_refptr<base::MessageLoopProxy> origin_loop_; | 323 scoped_refptr<base::MessageLoopProxy> origin_loop_; |
317 const Callback on_raster_finished_callback_; | 324 const Callback on_raster_finished_callback_; |
318 | 325 |
319 DISALLOW_COPY_AND_ASSIGN(RasterFinishedWorkerPoolTaskImpl); | 326 DISALLOW_COPY_AND_ASSIGN(RasterFinishedWorkerPoolTaskImpl); |
320 }; | 327 }; |
321 | 328 |
322 const char* kWorkerThreadNamePrefix = "CompositorRaster"; | |
323 | 329 |
324 } // namespace | 330 } // namespace |
325 | 331 |
326 namespace internal { | 332 namespace internal { |
327 | 333 |
328 RasterWorkerPoolTask::RasterWorkerPoolTask( | 334 RasterWorkerPoolTask::RasterWorkerPoolTask( |
329 const Resource* resource, TaskVector* dependencies) | 335 const Resource* resource, TaskVector* dependencies) |
330 : did_run_(false), | 336 : did_run_(false), |
331 did_complete_(false), | 337 did_complete_(false), |
332 was_canceled_(false), | 338 was_canceled_(false), |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
454 skia::LazyPixelRef* pixel_ref, | 460 skia::LazyPixelRef* pixel_ref, |
455 int layer_id, | 461 int layer_id, |
456 RenderingStatsInstrumentation* stats_instrumentation, | 462 RenderingStatsInstrumentation* stats_instrumentation, |
457 const Task::Reply& reply) { | 463 const Task::Reply& reply) { |
458 return Task(new ImageDecodeWorkerPoolTaskImpl(pixel_ref, | 464 return Task(new ImageDecodeWorkerPoolTaskImpl(pixel_ref, |
459 layer_id, | 465 layer_id, |
460 stats_instrumentation, | 466 stats_instrumentation, |
461 reply)); | 467 reply)); |
462 } | 468 } |
463 | 469 |
464 RasterWorkerPool::RasterWorkerPool(ResourceProvider* resource_provider, | 470 // static |
465 size_t num_threads) | 471 int RasterWorkerPool::num_raster_threads_ = kDefaultNumRasterThreads; |
reveman
2014/01/06 07:13:12
move this to anonymous namespace above.
sohanjg
2014/01/06 09:57:29
Done.
| |
466 : WorkerPool(num_threads, kWorkerThreadNamePrefix), | 472 void RasterWorkerPool::SetNumRasterThreads() { |
reveman
2014/01/06 07:13:12
the logic below should not be here. the idea is to
sohanjg
2014/01/06 09:57:29
Done.
| |
467 client_(NULL), | 473 RasterWorkerPool::num_raster_threads_ = kDefaultNumRasterThreads; |
474 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
475 if (command_line.HasSwitch(switches::kNumRasterThreads)) { | |
476 std::string string_value = | |
477 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); | |
478 int num_threads; | |
479 if (base::StringToInt(string_value, &num_threads) && | |
480 num_threads >= kMinRasterThreads && num_threads <= kMaxRasterThreads) | |
481 RasterWorkerPool::num_raster_threads_ = num_threads; | |
482 | |
483 LOG(WARNING) << "Failed to parse switch " << | |
484 switches::kNumRasterThreads << ": " << string_value; | |
485 } | |
486 } | |
487 | |
488 // static | |
489 int RasterWorkerPool::GetNumRasterThreads() { | |
490 return RasterWorkerPool::num_raster_threads_; | |
491 } | |
492 | |
493 RasterWorkerPool::RasterWorkerPool(ResourceProvider* resource_provider) | |
494 : client_(NULL), | |
468 resource_provider_(resource_provider), | 495 resource_provider_(resource_provider), |
469 weak_ptr_factory_(this) { | 496 weak_ptr_factory_(this) { |
470 } | 497 } |
471 | 498 |
472 RasterWorkerPool::~RasterWorkerPool() { | 499 RasterWorkerPool::~RasterWorkerPool() { |
473 } | 500 } |
474 | 501 |
475 void RasterWorkerPool::SetClient(RasterWorkerPoolClient* client) { | 502 void RasterWorkerPool::SetClient(RasterWorkerPoolClient* client) { |
476 client_ = client; | 503 client_ = client; |
477 } | 504 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
587 | 614 |
588 internal::GraphNode* decode_node = CreateGraphNodeForTask( | 615 internal::GraphNode* decode_node = CreateGraphNodeForTask( |
589 decode_task, priority, graph); | 616 decode_task, priority, graph); |
590 decode_node->add_dependent(raster_node); | 617 decode_node->add_dependent(raster_node); |
591 } | 618 } |
592 | 619 |
593 return raster_node; | 620 return raster_node; |
594 } | 621 } |
595 | 622 |
596 } // namespace cc | 623 } // namespace cc |
OLD | NEW |