Index: cc/raster/tile_task_worker_pool.cc |
diff --git a/cc/raster/tile_task_worker_pool.cc b/cc/raster/tile_task_worker_pool.cc |
index d4549c757f050012d0282742adb2eb5146cd4ca8..b746d226803184aeff9e8c86be6e2f74378b2a94 100644 |
--- a/cc/raster/tile_task_worker_pool.cc |
+++ b/cc/raster/tile_task_worker_pool.cc |
@@ -8,6 +8,7 @@ |
#include "base/trace_event/trace_event.h" |
#include "cc/playback/display_list_raster_source.h" |
+#include "cc/raster/texture_compressor.h" |
#include "skia/ext/refptr.h" |
#include "third_party/skia/include/core/SkCanvas.h" |
#include "third_party/skia/include/core/SkSurface.h" |
@@ -44,11 +45,11 @@ bool IsSupportedPlaybackToMemoryFormat(ResourceFormat format) { |
case RGBA_4444: |
case RGBA_8888: |
case BGRA_8888: |
+ case ETC1: |
return true; |
case ALPHA_8: |
case LUMINANCE_8: |
case RGB_565: |
- case ETC1: |
case RED_8: |
case LUMINANCE_F16: |
return false; |
@@ -116,8 +117,6 @@ void TileTaskWorkerPool::PlaybackToMemory( |
// Uses kPremul_SkAlphaType since the result is not known to be opaque. |
SkImageInfo info = |
SkImageInfo::MakeN32(size.width(), size.height(), kPremul_SkAlphaType); |
- SkColorType buffer_color_type = ResourceFormatToSkColorType(format); |
- bool needs_copy = buffer_color_type != info.colorType(); |
// Use unknown pixel geometry to disable LCD text. |
SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry); |
@@ -130,31 +129,59 @@ void TileTaskWorkerPool::PlaybackToMemory( |
stride = info.minRowBytes(); |
DCHECK_GT(stride, 0u); |
- if (!needs_copy) { |
- skia::RefPtr<SkSurface> surface = skia::AdoptRef( |
- SkSurface::NewRasterDirect(info, memory, stride, &surface_props)); |
- AutoSkipImageCanvas canvas(surface->getCanvas(), include_images); |
- raster_source->PlaybackToCanvas(canvas, canvas_bitmap_rect, |
- canvas_playback_rect, scale); |
- return; |
- } |
- |
- skia::RefPtr<SkSurface> surface = |
- skia::AdoptRef(SkSurface::NewRaster(info, &surface_props)); |
- AutoSkipImageCanvas canvas(surface->getCanvas(), include_images); |
- // TODO(reveman): Improve partial raster support by reducing the size of |
- // playback rect passed to PlaybackToCanvas. crbug.com/519070 |
- raster_source->PlaybackToCanvas(canvas, canvas_bitmap_rect, |
- canvas_bitmap_rect, scale); |
- |
{ |
TRACE_EVENT0("cc", "TileTaskWorkerPool::PlaybackToMemory::ConvertPixels"); |
- SkImageInfo dst_info = |
- SkImageInfo::Make(info.width(), info.height(), buffer_color_type, |
- info.alphaType(), info.profileType()); |
- bool rv = surface->getCanvas()->readPixels(dst_info, memory, stride, 0, 0); |
- DCHECK(rv); |
+ switch (format) { |
+ case RGBA_8888: |
+ case BGRA_8888: { |
+ skia::RefPtr<SkSurface> surface = skia::AdoptRef( |
+ SkSurface::NewRasterDirect(info, memory, stride, &surface_props)); |
+ AutoSkipImageCanvas canvas(surface->getCanvas(), include_images); |
+ raster_source->PlaybackToCanvas(canvas, canvas_bitmap_rect, |
+ canvas_playback_rect, scale); |
+ return; |
+ } |
+ case RGBA_4444: |
+ case ETC1: { |
+ skia::RefPtr<SkSurface> surface = |
+ skia::AdoptRef(SkSurface::NewRaster(info, &surface_props)); |
+ AutoSkipImageCanvas canvas(surface->getCanvas(), include_images); |
+ // TODO(reveman): Improve partial raster support by reducing the size of |
+ // playback rect passed to PlaybackToCanvas. crbug.com/519070 |
+ raster_source->PlaybackToCanvas(canvas, canvas_bitmap_rect, |
+ canvas_bitmap_rect, scale); |
+ |
+ if (format == ETC1) { |
+ DCHECK_EQ(size.width() % 4, 0); |
+ DCHECK_EQ(size.height() % 4, 0); |
+ scoped_ptr<TextureCompressor> texture_compressor = |
+ TextureCompressor::Create(TextureCompressor::kFormatETC1); |
+ texture_compressor->Compress( |
+ reinterpret_cast<const uint8_t*>( |
+ surface->peekPixels(nullptr, nullptr)), |
+ reinterpret_cast<uint8_t*>(memory), size.width(), size.height(), |
+ TextureCompressor::kQualityHigh); |
+ } else { |
+ SkImageInfo dst_info = SkImageInfo::Make( |
+ info.width(), info.height(), ResourceFormatToSkColorType(format), |
+ info.alphaType(), info.profileType()); |
+ bool rv = |
+ surface->getCanvas()->readPixels(dst_info, memory, stride, 0, 0); |
+ DCHECK(rv); |
+ } |
+ return; |
+ } |
+ case ALPHA_8: |
+ case LUMINANCE_8: |
+ case RGB_565: |
+ case RED_8: |
+ case LUMINANCE_F16: |
+ NOTREACHED(); |
+ return; |
+ } |
+ |
+ NOTREACHED(); |
} |
} |