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..fc6c2ddfaa921959a4482f9265ebc18c803d1955 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; |
| @@ -60,7 +75,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_format_(resource->format()) {} |
| void RunAnalysisOnThread(unsigned thread_index) { |
| TRACE_EVENT1("cc", |
| @@ -89,7 +105,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 +121,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 +129,24 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask { |
| PicturePileImpl* picture_clone = |
| picture_pile_->GetCloneForDrawingOnThread(thread_index); |
| - SkCanvas canvas(device); |
| + SkBitmap bitmap_32; |
|
reveman
2013/09/13 14:32:49
can we drop the _32 suffix here?
kaanb
2013/09/13 19:57:39
Done.
|
| + bitmap_32.setConfig(SkBitmap::kARGB_8888_Config, |
| + size.width(), |
| + size.height(), |
| + stride); |
|
reveman
2013/09/13 14:32:49
stride is not going to be correct here unless form
kaanb
2013/09/13 19:57:39
Done.
|
| + switch (texture_format_) { |
| + case ResourceProvider::RGBA_4444: |
| + bitmap_32.allocPixels(); |
| + break; |
| + case ResourceProvider::RGBA_8888: |
| + case ResourceProvider::BGRA_8888: |
| + case ResourceProvider::LUMINANCE_8: |
|
reveman
2013/09/13 14:32:49
Using SkBitmap::kARGB_8888_Config for LUMINANCE_8
kaanb
2013/09/13 19:57:39
Done.
|
| + bitmap_32.setPixels(buffer); |
| + break; |
| + } |
| + SkBitmapDevice device_32(bitmap_32); |
|
reveman
2013/09/13 14:32:49
drop _32?
kaanb
2013/09/13 19:57:39
Done.
|
| + SkCanvas canvas(&device_32); |
| skia::RefPtr<SkDrawFilter> draw_filter; |
| switch (raster_mode_) { |
| case LOW_QUALITY_RASTER_MODE: |
| @@ -149,14 +184,26 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask { |
| picture_clone->RasterToBitmap( |
| &canvas, content_rect_, contents_scale_, NULL); |
| } |
| + |
| + if (texture_format_ == ResourceProvider::RGBA_4444) { |
| + TRACE_EVENT0("cc", |
| + "RasterWorkerPoolTaskImpl::RunRasterOnThread::Downsample"); |
|
reveman
2013/09/13 14:32:49
If this is worth a trace event then I prefer if yo
kaanb
2013/09/13 19:57:39
Done.
|
| + SkBitmap bitmap_16; |
| + IdentityAllocator allocator(buffer); |
| + bitmap_32.copyTo(&bitmap_16, SkBitmap::kARGB_4444_Config, &allocator); |
| + } |
|
reveman
2013/09/13 14:32:49
This is currently hardcoded to only support RGBA_4
kaanb
2013/09/13 19:57:39
Done.
|
| + |
| 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 +236,7 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask { |
| int source_frame_number_; |
| RenderingStatsInstrumentation* rendering_stats_; |
| const RasterWorkerPool::RasterTask::Reply reply_; |
| + ResourceProvider::Format texture_format_; |
|
reveman
2013/09/13 14:32:49
I don't think you need this. You can get the forma
kaanb
2013/09/13 19:57:39
Done.
|
| DISALLOW_COPY_AND_ASSIGN(RasterWorkerPoolTaskImpl); |
| }; |