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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 NOTREACHED(); | 152 NOTREACHED(); |
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& canvas_bitmap_rect, |
| 163 const gfx::Rect& canvas_playback_rect, |
163 float scale) { | 164 float scale) { |
164 DCHECK(IsSupportedPlaybackToMemoryFormat(format)) << format; | 165 DCHECK(IsSupportedPlaybackToMemoryFormat(format)) << format; |
165 | 166 |
166 // Uses kPremul_SkAlphaType since the result is not known to be opaque. | 167 // Uses kPremul_SkAlphaType since the result is not known to be opaque. |
167 SkImageInfo info = | 168 SkImageInfo info = |
168 SkImageInfo::MakeN32(size.width(), size.height(), kPremul_SkAlphaType); | 169 SkImageInfo::MakeN32(size.width(), size.height(), kPremul_SkAlphaType); |
169 SkColorType buffer_color_type = ResourceFormatToSkColorType(format); | 170 SkColorType buffer_color_type = ResourceFormatToSkColorType(format); |
170 bool needs_copy = buffer_color_type != info.colorType(); | 171 bool needs_copy = buffer_color_type != info.colorType(); |
171 | 172 |
172 // Use unknown pixel geometry to disable LCD text. | 173 // Use unknown pixel geometry to disable LCD text. |
173 SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry); | 174 SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry); |
174 if (raster_source->CanUseLCDText()) { | 175 if (raster_source->CanUseLCDText()) { |
175 // LegacyFontHost will get LCD text and skia figures out what type to use. | 176 // LegacyFontHost will get LCD text and skia figures out what type to use. |
176 surface_props = SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); | 177 surface_props = SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); |
177 } | 178 } |
178 | 179 |
179 if (!stride) | 180 if (!stride) |
180 stride = info.minRowBytes(); | 181 stride = info.minRowBytes(); |
181 DCHECK_GT(stride, 0); | 182 DCHECK_GT(stride, 0); |
182 | 183 |
183 if (!needs_copy) { | 184 if (!needs_copy) { |
184 skia::RefPtr<SkSurface> surface = skia::AdoptRef( | 185 skia::RefPtr<SkSurface> surface = skia::AdoptRef( |
185 SkSurface::NewRasterDirect(info, memory, stride, &surface_props)); | 186 SkSurface::NewRasterDirect(info, memory, stride, &surface_props)); |
186 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(surface->getCanvas()); | 187 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(surface->getCanvas()); |
187 raster_source->PlaybackToCanvas(canvas.get(), rect, scale); | 188 raster_source->PlaybackToCanvas(canvas.get(), canvas_bitmap_rect, |
| 189 canvas_playback_rect, scale); |
188 return; | 190 return; |
189 } | 191 } |
190 | 192 |
191 skia::RefPtr<SkSurface> surface = | 193 skia::RefPtr<SkSurface> surface = |
192 skia::AdoptRef(SkSurface::NewRaster(info, &surface_props)); | 194 skia::AdoptRef(SkSurface::NewRaster(info, &surface_props)); |
193 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(surface->getCanvas()); | 195 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(surface->getCanvas()); |
194 raster_source->PlaybackToCanvas(canvas.get(), rect, scale); | 196 raster_source->PlaybackToCanvas(canvas.get(), canvas_bitmap_rect, |
| 197 canvas_playback_rect, scale); |
195 | 198 |
196 SkImageInfo dst_info = info; | 199 SkImageInfo dst_info = info; |
197 dst_info.fColorType = buffer_color_type; | 200 dst_info.fColorType = buffer_color_type; |
198 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the | 201 // 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 | 202 // bitmap data. There will be no need to call SkAlign4 once crbug.com/293728 |
200 // is fixed. | 203 // is fixed. |
201 const size_t dst_row_bytes = SkAlign4(dst_info.minRowBytes()); | 204 const size_t dst_row_bytes = SkAlign4(dst_info.minRowBytes()); |
202 DCHECK_EQ(0u, dst_row_bytes % 4); | 205 DCHECK_EQ(0u, dst_row_bytes % 4); |
203 bool success = canvas->readPixels(dst_info, memory, dst_row_bytes, 0, 0); | 206 bool success = canvas->readPixels(dst_info, memory, dst_row_bytes, 0, 0); |
204 DCHECK_EQ(true, success); | 207 DCHECK_EQ(true, success); |
205 } | 208 } |
206 | 209 |
207 } // namespace cc | 210 } // namespace cc |
OLD | NEW |