| 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/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/threading/simple_thread.h" | 12 #include "base/threading/simple_thread.h" |
| 13 #include "cc/base/scoped_ptr_deque.h" | 13 #include "cc/base/scoped_ptr_deque.h" |
| 14 #include "cc/resources/raster_source.h" | 14 #include "cc/resources/raster_source.h" |
| 15 #include "cc/resources/texture_compress/texture_compress.h" |
| 15 #include "skia/ext/refptr.h" | 16 #include "skia/ext/refptr.h" |
| 16 #include "third_party/skia/include/core/SkCanvas.h" | 17 #include "third_party/skia/include/core/SkCanvas.h" |
| 17 #include "third_party/skia/include/core/SkSurface.h" | 18 #include "third_party/skia/include/core/SkSurface.h" |
| 18 | 19 |
| 19 namespace cc { | 20 namespace cc { |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 class TileTaskGraphRunner : public TaskGraphRunner, | 23 class TileTaskGraphRunner : public TaskGraphRunner, |
| 23 public base::DelegateSimpleThread::Delegate { | 24 public base::DelegateSimpleThread::Delegate { |
| 24 public: | 25 public: |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 InsertNodeForTask(graph, decode_task, priority, 0u); | 189 InsertNodeForTask(graph, decode_task, priority, 0u); |
| 189 | 190 |
| 190 graph->edges.push_back(TaskGraph::Edge(decode_task, raster_task)); | 191 graph->edges.push_back(TaskGraph::Edge(decode_task, raster_task)); |
| 191 } | 192 } |
| 192 | 193 |
| 193 InsertNodeForTask(graph, raster_task, priority, dependencies); | 194 InsertNodeForTask(graph, raster_task, priority, dependencies); |
| 194 } | 195 } |
| 195 | 196 |
| 196 static bool IsSupportedPlaybackToMemoryFormat(ResourceFormat format) { | 197 static bool IsSupportedPlaybackToMemoryFormat(ResourceFormat format) { |
| 197 switch (format) { | 198 switch (format) { |
| 199 case ATC: |
| 200 case ATC_IA: |
| 201 case DXT1: |
| 202 case DXT5: |
| 203 case ETC1: |
| 198 case RGBA_4444: | 204 case RGBA_4444: |
| 199 case RGBA_8888: | 205 case RGBA_8888: |
| 200 case BGRA_8888: | 206 case BGRA_8888: |
| 201 return true; | 207 return true; |
| 202 case ALPHA_8: | 208 case ALPHA_8: |
| 203 case LUMINANCE_8: | 209 case LUMINANCE_8: |
| 204 case RGB_565: | 210 case RGB_565: |
| 205 case ETC1: | |
| 206 case RED_8: | 211 case RED_8: |
| 207 return false; | 212 return false; |
| 208 } | 213 } |
| 209 NOTREACHED(); | 214 NOTREACHED(); |
| 210 return false; | 215 return false; |
| 211 } | 216 } |
| 212 | 217 |
| 213 // static | 218 // static |
| 214 void TileTaskWorkerPool::PlaybackToMemory(void* memory, | 219 void TileTaskWorkerPool::PlaybackToMemory(void* memory, |
| 215 ResourceFormat format, | 220 ResourceFormat format, |
| 216 const gfx::Size& size, | 221 const gfx::Size& size, |
| 217 int stride, | 222 int stride, |
| 218 const RasterSource* raster_source, | 223 const RasterSource* raster_source, |
| 219 const gfx::Rect& rect, | 224 const gfx::Rect& rect, |
| 220 float scale) { | 225 float scale) { |
| 221 DCHECK(IsSupportedPlaybackToMemoryFormat(format)) << format; | 226 DCHECK(IsSupportedPlaybackToMemoryFormat(format)) << format; |
| 222 | 227 |
| 228 if (IsFormatCompressed(format)) { |
| 229 SkBitmap bitmap; |
| 230 bitmap.allocN32Pixels(size.width(), size.height()); |
| 231 |
| 232 SkCanvas canvas(bitmap); |
| 233 raster_source->PlaybackToCanvas(&canvas, rect, scale); |
| 234 |
| 235 switch (format) { |
| 236 case ATC: |
| 237 texture_compress::CompressATC( |
| 238 reinterpret_cast<const uint8_t*>(bitmap.getPixels()), |
| 239 reinterpret_cast<uint8_t*>(memory), bitmap.width(), |
| 240 bitmap.height()); |
| 241 break; |
| 242 case ATC_IA: |
| 243 texture_compress::CompressATCIA( |
| 244 reinterpret_cast<const uint8_t*>(bitmap.getPixels()), |
| 245 reinterpret_cast<uint8_t*>(memory), bitmap.width(), |
| 246 bitmap.height()); |
| 247 break; |
| 248 case DXT1: |
| 249 texture_compress::CompressDXT1( |
| 250 reinterpret_cast<const uint8_t*>(bitmap.getPixels()), |
| 251 reinterpret_cast<uint8_t*>(memory), bitmap.width(), |
| 252 bitmap.height()); |
| 253 break; |
| 254 case DXT5: |
| 255 texture_compress::CompressDXT5( |
| 256 reinterpret_cast<const uint8_t*>(bitmap.getPixels()), |
| 257 reinterpret_cast<uint8_t*>(memory), bitmap.width(), |
| 258 bitmap.height()); |
| 259 break; |
| 260 case ETC1: |
| 261 texture_compress::CompressETC1( |
| 262 reinterpret_cast<const uint8_t*>(bitmap.getPixels()), |
| 263 reinterpret_cast<uint8_t*>(memory), bitmap.width(), |
| 264 bitmap.height()); |
| 265 break; |
| 266 default: |
| 267 NOTREACHED(); |
| 268 break; |
| 269 } |
| 270 return; |
| 271 } |
| 272 |
| 223 // Uses kPremul_SkAlphaType since the result is not known to be opaque. | 273 // Uses kPremul_SkAlphaType since the result is not known to be opaque. |
| 224 SkImageInfo info = | 274 SkImageInfo info = |
| 225 SkImageInfo::MakeN32(size.width(), size.height(), kPremul_SkAlphaType); | 275 SkImageInfo::MakeN32(size.width(), size.height(), kPremul_SkAlphaType); |
| 226 SkColorType buffer_color_type = ResourceFormatToSkColorType(format); | 276 SkColorType buffer_color_type = ResourceFormatToSkColorType(format); |
| 227 bool needs_copy = buffer_color_type != info.colorType(); | 277 bool needs_copy = buffer_color_type != info.colorType(); |
| 228 | 278 |
| 229 // Use unknown pixel geometry to disable LCD text. | 279 // Use unknown pixel geometry to disable LCD text. |
| 230 SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry); | 280 SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry); |
| 231 if (raster_source->CanUseLCDText()) { | 281 if (raster_source->CanUseLCDText()) { |
| 232 // LegacyFontHost will get LCD text and skia figures out what type to use. | 282 // LegacyFontHost will get LCD text and skia figures out what type to use. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 254 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the | 304 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the |
| 255 // bitmap data. There will be no need to call SkAlign4 once crbug.com/293728 | 305 // bitmap data. There will be no need to call SkAlign4 once crbug.com/293728 |
| 256 // is fixed. | 306 // is fixed. |
| 257 const size_t dst_row_bytes = SkAlign4(dst_info.minRowBytes()); | 307 const size_t dst_row_bytes = SkAlign4(dst_info.minRowBytes()); |
| 258 DCHECK_EQ(0u, dst_row_bytes % 4); | 308 DCHECK_EQ(0u, dst_row_bytes % 4); |
| 259 bool success = canvas->readPixels(dst_info, memory, dst_row_bytes, 0, 0); | 309 bool success = canvas->readPixels(dst_info, memory, dst_row_bytes, 0, 0); |
| 260 DCHECK_EQ(true, success); | 310 DCHECK_EQ(true, success); |
| 261 } | 311 } |
| 262 | 312 |
| 263 } // namespace cc | 313 } // namespace cc |
| OLD | NEW |