| 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/tile_task_worker_pool.h" | 5 #include "cc/resources/tile_task_worker_pool.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "cc/resources/raster_source.h" | 10 #include "cc/resources/raster_source.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 return false; | 153 return false; |
| 154 } | 154 } |
| 155 | 155 |
| 156 // static | 156 // static |
| 157 void TileTaskWorkerPool::PlaybackToMemory(void* memory, | 157 void TileTaskWorkerPool::PlaybackToMemory(void* memory, |
| 158 ResourceFormat format, | 158 ResourceFormat format, |
| 159 const gfx::Size& size, | 159 const gfx::Size& size, |
| 160 int stride, | 160 int stride, |
| 161 const RasterSource* raster_source, | 161 const RasterSource* raster_source, |
| 162 const gfx::Rect& rect, | 162 const gfx::Rect& rect, |
| 163 float scale) { | 163 const gfx::Vector2d& raster_offset, |
| 164 float scale, |
| 165 bool partial_update) { |
| 164 DCHECK(IsSupportedPlaybackToMemoryFormat(format)) << format; | 166 DCHECK(IsSupportedPlaybackToMemoryFormat(format)) << format; |
| 165 | 167 |
| 166 // Uses kPremul_SkAlphaType since the result is not known to be opaque. | 168 // Uses kPremul_SkAlphaType since the result is not known to be opaque. |
| 167 SkImageInfo info = | 169 SkImageInfo info = |
| 168 SkImageInfo::MakeN32(size.width(), size.height(), kPremul_SkAlphaType); | 170 SkImageInfo::MakeN32(size.width(), size.height(), kPremul_SkAlphaType); |
| 169 SkColorType buffer_color_type = ResourceFormatToSkColorType(format); | 171 SkColorType buffer_color_type = ResourceFormatToSkColorType(format); |
| 170 bool needs_copy = buffer_color_type != info.colorType(); | 172 bool needs_copy = buffer_color_type != info.colorType(); |
| 171 | 173 |
| 172 // Use unknown pixel geometry to disable LCD text. | 174 // Use unknown pixel geometry to disable LCD text. |
| 173 SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry); | 175 SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry); |
| 174 if (raster_source->CanUseLCDText()) { | 176 if (raster_source->CanUseLCDText()) { |
| 175 // LegacyFontHost will get LCD text and skia figures out what type to use. | 177 // LegacyFontHost will get LCD text and skia figures out what type to use. |
| 176 surface_props = SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); | 178 surface_props = SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); |
| 177 } | 179 } |
| 178 | 180 |
| 179 if (!stride) | 181 if (!stride) |
| 180 stride = info.minRowBytes(); | 182 stride = info.minRowBytes(); |
| 181 DCHECK_GT(stride, 0); | 183 DCHECK_GT(stride, 0); |
| 182 | 184 |
| 183 if (!needs_copy) { | 185 if (!needs_copy) { |
| 184 skia::RefPtr<SkSurface> surface = skia::AdoptRef( | 186 skia::RefPtr<SkSurface> surface = skia::AdoptRef( |
| 185 SkSurface::NewRasterDirect(info, memory, stride, &surface_props)); | 187 SkSurface::NewRasterDirect(info, memory, stride, &surface_props)); |
| 186 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(surface->getCanvas()); | 188 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(surface->getCanvas()); |
| 187 raster_source->PlaybackToCanvas(canvas.get(), rect, scale); | 189 canvas->translate(raster_offset.x(), raster_offset.y()); |
| 190 raster_source->PlaybackToCanvas(canvas.get(), rect, scale, partial_update); |
| 188 return; | 191 return; |
| 189 } | 192 } |
| 190 | 193 |
| 191 skia::RefPtr<SkSurface> surface = | 194 skia::RefPtr<SkSurface> surface = |
| 192 skia::AdoptRef(SkSurface::NewRaster(info, &surface_props)); | 195 skia::AdoptRef(SkSurface::NewRaster(info, &surface_props)); |
| 193 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(surface->getCanvas()); | 196 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(surface->getCanvas()); |
| 194 raster_source->PlaybackToCanvas(canvas.get(), rect, scale); | 197 canvas->translate(raster_offset.x(), raster_offset.y()); |
| 198 raster_source->PlaybackToCanvas(canvas.get(), rect, scale, partial_update); |
| 195 | 199 |
| 196 SkImageInfo dst_info = info; | 200 SkImageInfo dst_info = info; |
| 197 dst_info.fColorType = buffer_color_type; | 201 dst_info.fColorType = buffer_color_type; |
| 198 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the | 202 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the |
| 199 // bitmap data. There will be no need to call SkAlign4 once crbug.com/293728 | 203 // bitmap data. There will be no need to call SkAlign4 once crbug.com/293728 |
| 200 // is fixed. | 204 // is fixed. |
| 201 const size_t dst_row_bytes = SkAlign4(dst_info.minRowBytes()); | 205 const size_t dst_row_bytes = SkAlign4(dst_info.minRowBytes()); |
| 202 DCHECK_EQ(0u, dst_row_bytes % 4); | 206 DCHECK_EQ(0u, dst_row_bytes % 4); |
| 203 bool success = canvas->readPixels(dst_info, memory, dst_row_bytes, 0, 0); | 207 bool success = canvas->readPixels(dst_info, memory, dst_row_bytes, 0, 0); |
| 204 DCHECK_EQ(true, success); | 208 DCHECK_EQ(true, success); |
| 205 } | 209 } |
| 206 | 210 |
| 207 } // namespace cc | 211 } // namespace cc |
| OLD | NEW |