Index: cc/resources/raster_worker_pool.cc |
diff --git a/cc/resources/raster_worker_pool.cc b/cc/resources/raster_worker_pool.cc |
index bd917404510b475656a7ec59167617544b8d84de..ca26edd6a41f3c80da14e61d59b2d626d94b1c40 100644 |
--- a/cc/resources/raster_worker_pool.cc |
+++ b/cc/resources/raster_worker_pool.cc |
@@ -12,7 +12,9 @@ |
#include "base/threading/simple_thread.h" |
#include "cc/base/scoped_ptr_deque.h" |
#include "cc/resources/raster_source.h" |
+#include "skia/ext/refptr.h" |
#include "third_party/skia/include/core/SkCanvas.h" |
+#include "third_party/skia/include/core/SkSurface.h" |
namespace cc { |
namespace { |
@@ -194,52 +196,72 @@ void RasterWorkerPool::InsertNodesForRasterTask( |
InsertNodeForTask(graph, raster_task, priority, dependencies); |
} |
-// static |
-void RasterWorkerPool::PlaybackToMemory(void* memory, |
- ResourceFormat format, |
- const gfx::Size& size, |
- int stride, |
- const RasterSource* raster_source, |
- const gfx::Rect& rect, |
- float scale, |
- RenderingStatsInstrumentation* stats) { |
- SkBitmap bitmap; |
+static bool IsSupportedPlaybackToMemoryFormat(ResourceFormat format) { |
switch (format) { |
case RGBA_4444: |
- bitmap.allocN32Pixels(size.width(), size.height()); |
- break; |
case RGBA_8888: |
- case BGRA_8888: { |
- SkImageInfo info = |
- SkImageInfo::MakeN32Premul(size.width(), size.height()); |
- if (!stride) |
- stride = info.minRowBytes(); |
- bitmap.installPixels(info, memory, stride); |
- break; |
- } |
+ case BGRA_8888: |
+ return true; |
case ALPHA_8: |
case LUMINANCE_8: |
case RGB_565: |
case ETC1: |
- NOTREACHED(); |
- break; |
+ return false; |
} |
+ NOTREACHED(); |
+ return false; |
+} |
- SkCanvas canvas(bitmap); |
- raster_source->PlaybackToCanvas(&canvas, rect, scale, stats); |
+// static |
+void RasterWorkerPool::PlaybackToMemory(void* memory, |
+ ResourceFormat format, |
+ const gfx::Size& size, |
+ int stride, |
+ const RasterSource* raster_source, |
+ const gfx::Rect& rect, |
+ float scale) { |
+ DCHECK(IsSupportedPlaybackToMemoryFormat(format)) << format; |
+ // 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); |
- if (buffer_color_type != bitmap.colorType()) { |
- SkImageInfo dst_info = bitmap.info(); |
- dst_info.fColorType = buffer_color_type; |
- // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the |
- // bitmap data. There will be no need to call SkAlign4 once crbug.com/293728 |
- // is fixed. |
- const size_t dst_row_bytes = SkAlign4(dst_info.minRowBytes()); |
- DCHECK_EQ(0u, dst_row_bytes % 4); |
- bool success = bitmap.readPixels(dst_info, memory, dst_row_bytes, 0, 0); |
- DCHECK_EQ(true, success); |
+ bool needs_copy = buffer_color_type != info.colorType(); |
+ |
+ // TODO(danakj): Make a SkSurfaceProps with an SkPixelGeometry to enable or |
+ // disable LCD text. |
+ // TODO(danakj): Disable LCD text on Mac during layout tests: |
+ // https://cs.chromium.org#chromium/src/third_party/WebKit/Source/platform/fonts/mac/FontPlatformDataMac.mm&l=55 |
+ // TODO(danakj): On Windows when LCD text is disabled, ask skia to draw LCD |
+ // text offscreen and downsample it to AA text. |
+ // https://cs.chromium.org#chromium/src/third_party/WebKit/Source/platform/fonts/win/FontPlatformDataWin.cpp&l=86 |
+ SkSurfaceProps* surface_props = nullptr; |
+ |
+ if (!stride) |
+ stride = info.minRowBytes(); |
+ |
+ if (!needs_copy) { |
+ skia::RefPtr<SkSurface> surface = skia::AdoptRef( |
+ SkSurface::NewRasterDirect(info, memory, stride, surface_props)); |
+ skia::RefPtr<SkCanvas> canvas = skia::SharePtr(surface->getCanvas()); |
+ raster_source->PlaybackToCanvas(canvas.get(), rect, scale); |
+ return; |
} |
+ |
+ skia::RefPtr<SkSurface> surface = |
+ skia::AdoptRef(SkSurface::NewRaster(info, surface_props)); |
+ skia::RefPtr<SkCanvas> canvas = skia::SharePtr(surface->getCanvas()); |
+ raster_source->PlaybackToCanvas(canvas.get(), rect, scale); |
+ |
+ SkImageInfo dst_info = info; |
+ dst_info.fColorType = buffer_color_type; |
+ // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the |
+ // bitmap data. There will be no need to call SkAlign4 once crbug.com/293728 |
+ // is fixed. |
+ const size_t dst_row_bytes = SkAlign4(dst_info.minRowBytes()); |
+ DCHECK_EQ(0u, dst_row_bytes % 4); |
+ bool success = canvas->readPixels(dst_info, memory, dst_row_bytes, 0, 0); |
+ DCHECK_EQ(true, success); |
} |
} // namespace cc |