Chromium Code Reviews| Index: cc/resources/raster_worker_pool.cc |
| diff --git a/cc/resources/raster_worker_pool.cc b/cc/resources/raster_worker_pool.cc |
| index 15b8aa41133312b094cec77d073ab1c5c954e41f..c3eb54f910065c407734a926b9bd77431fa6a487 100644 |
| --- a/cc/resources/raster_worker_pool.cc |
| +++ b/cc/resources/raster_worker_pool.cc |
| @@ -11,13 +11,28 @@ |
| #include "cc/debug/devtools_instrumentation.h" |
| #include "cc/debug/traced_value.h" |
| #include "cc/resources/picture_pile_impl.h" |
| +#include "cc/resources/resource_provider.h" |
| #include "skia/ext/lazy_pixel_ref.h" |
| #include "skia/ext/paint_simplifier.h" |
| +#include "third_party/skia/include/core/SkBitmap.h" |
| namespace cc { |
| namespace { |
| +// Subclass of Allocator that takes a suitably allocated pointer and uses |
| +// it as the pixel memory for the bitmap. |
| +class IdentityAllocator : public SkBitmap::Allocator { |
| + public: |
| + explicit IdentityAllocator(void* buffer) : buffer_(buffer) {} |
| + virtual bool allocPixelRef(SkBitmap* dst, SkColorTable*) OVERRIDE { |
| + dst->setPixels(buffer_); |
| + return true; |
| + } |
| + private: |
| + void* buffer_; |
| +}; |
| + |
| // Flag to indicate whether we should try and detect that |
| // a tile is of solid color. |
| const bool kUseColorEstimator = true; |
| @@ -48,7 +63,8 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask { |
| int source_frame_number, |
| RenderingStatsInstrumentation* rendering_stats, |
| const RasterWorkerPool::RasterTask::Reply& reply, |
| - TaskVector* dependencies) |
| + TaskVector* dependencies, |
| + ResourceProvider::TextureType type) |
| : internal::RasterWorkerPoolTask(resource, dependencies), |
| picture_pile_(picture_pile), |
| content_rect_(content_rect), |
| @@ -60,7 +76,8 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask { |
| tile_id_(tile_id), |
| source_frame_number_(source_frame_number), |
| rendering_stats_(rendering_stats), |
| - reply_(reply) {} |
| + reply_(reply), |
| + texture_type_(type) {} |
| void RunAnalysisOnThread(unsigned thread_index) { |
| TRACE_EVENT1("cc", |
| @@ -89,7 +106,10 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask { |
| analysis_.is_solid_color &= kUseColorEstimator; |
| } |
| - bool RunRasterOnThread(SkBaseDevice* device, unsigned thread_index) { |
| + bool RunRasterOnThread(unsigned thread_index, |
| + void* buffer, |
| + gfx::Size size, |
| + int stride) { |
| TRACE_EVENT2( |
| benchmark_instrumentation::kCategory, |
| benchmark_instrumentation::kRunRasterOnThread, |
| @@ -102,7 +122,7 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask { |
| devtools_instrumentation::kRasterTask, layer_id_); |
| DCHECK(picture_pile_.get()); |
| - DCHECK(device); |
| + DCHECK(buffer); |
| if (analysis_.is_solid_color) |
| return false; |
| @@ -110,8 +130,21 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask { |
| PicturePileImpl* picture_clone = |
| picture_pile_->GetCloneForDrawingOnThread(thread_index); |
| - SkCanvas canvas(device); |
| + SkBitmap bitmap_32; |
| + bitmap_32.setConfig(SkBitmap::kARGB_8888_Config, |
| + size.width(), |
| + size.height(), |
| + stride); |
| + if (texture_type_ == ResourceProvider::RGBA_4444) { |
|
reveman
2013/09/12 15:57:39
please make this a switch statement. that way the
kaanb
2013/09/13 00:11:08
Done.
|
| + bitmap_32.allocPixels(); |
|
vangelis
2013/09/11 06:11:37
Is there some way we could avoid re-allocating thi
kaanb
2013/09/12 07:53:44
It may be difficult as this method could get calle
reveman
2013/09/12 15:57:39
you could keep an array of cached bitmaps based on
kaanb
2013/09/13 00:11:08
Okay.
|
| + } else if (texture_type_ == ResourceProvider::RGBA_8888) { |
| + bitmap_32.setPixels(buffer); |
| + } else { |
| + NOTREACHED(); |
| + } |
| + SkBitmapDevice device_32(bitmap_32); |
| + SkCanvas canvas(&device_32); |
| skia::RefPtr<SkDrawFilter> draw_filter; |
| switch (raster_mode_) { |
| case LOW_QUALITY_RASTER_MODE: |
| @@ -149,14 +182,24 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask { |
| picture_clone->RasterToBitmap( |
| &canvas, content_rect_, contents_scale_, NULL); |
| } |
| + |
| + if (texture_type_ == ResourceProvider::RGBA_4444) { |
| + SkBitmap bitmap_16; |
| + IdentityAllocator allocator(buffer); |
| + bitmap_32.copyTo(&bitmap_16, SkBitmap::kARGB_4444_Config, &allocator); |
| + } |
| + |
| return true; |
| } |
| // Overridden from internal::RasterWorkerPoolTask: |
| - virtual bool RunOnWorkerThread(SkBaseDevice* device, unsigned thread_index) |
| + virtual bool RunOnWorkerThread(unsigned thread_index, |
| + void* buffer, |
| + gfx::Size size, |
| + int stride) |
| OVERRIDE { |
| RunAnalysisOnThread(thread_index); |
| - return RunRasterOnThread(device, thread_index); |
| + return RunRasterOnThread(thread_index, buffer, size, stride); |
| } |
| virtual void CompleteOnOriginThread() OVERRIDE { |
| reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); |
| @@ -189,6 +232,7 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask { |
| int source_frame_number_; |
| RenderingStatsInstrumentation* rendering_stats_; |
| const RasterWorkerPool::RasterTask::Reply reply_; |
| + ResourceProvider::TextureType texture_type_; |
| DISALLOW_COPY_AND_ASSIGN(RasterWorkerPoolTaskImpl); |
| }; |
| @@ -379,7 +423,8 @@ RasterWorkerPool::RasterTask RasterWorkerPool::CreateRasterTask( |
| int source_frame_number, |
| RenderingStatsInstrumentation* rendering_stats, |
| const RasterTask::Reply& reply, |
| - Task::Set* dependencies) { |
| + Task::Set* dependencies, |
| + ResourceProvider::TextureType texture_type) { |
| return RasterTask( |
| new RasterWorkerPoolTaskImpl(resource, |
| picture_pile, |
| @@ -393,7 +438,8 @@ RasterWorkerPool::RasterTask RasterWorkerPool::CreateRasterTask( |
| source_frame_number, |
| rendering_stats, |
| reply, |
| - &dependencies->tasks_)); |
| + &dependencies->tasks_, |
| + texture_type)); |
| } |
| // static |