Chromium Code Reviews| 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/raster/tile_task_worker_pool.h" | 5 #include "cc/raster/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/playback/raster_source.h" | 10 #include "cc/playback/raster_source.h" |
| 11 #include "cc/raster/texture_compressor.h" | |
| 11 #include "skia/ext/refptr.h" | 12 #include "skia/ext/refptr.h" |
| 12 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
| 13 #include "third_party/skia/include/core/SkSurface.h" | 14 #include "third_party/skia/include/core/SkSurface.h" |
| 14 | 15 |
| 15 namespace cc { | 16 namespace cc { |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 class TaskSetFinishedTaskImpl : public TileTask { | 19 class TaskSetFinishedTaskImpl : public TileTask { |
| 19 public: | 20 public: |
| 20 explicit TaskSetFinishedTaskImpl( | 21 explicit TaskSetFinishedTaskImpl( |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 } | 135 } |
| 135 | 136 |
| 136 InsertNodeForTask(graph, raster_task, priority, dependencies); | 137 InsertNodeForTask(graph, raster_task, priority, dependencies); |
| 137 } | 138 } |
| 138 | 139 |
| 139 static bool IsSupportedPlaybackToMemoryFormat(ResourceFormat format) { | 140 static bool IsSupportedPlaybackToMemoryFormat(ResourceFormat format) { |
| 140 switch (format) { | 141 switch (format) { |
| 141 case RGBA_4444: | 142 case RGBA_4444: |
| 142 case RGBA_8888: | 143 case RGBA_8888: |
| 143 case BGRA_8888: | 144 case BGRA_8888: |
| 145 case ETC1: | |
| 144 return true; | 146 return true; |
| 145 case ALPHA_8: | 147 case ALPHA_8: |
| 146 case LUMINANCE_8: | 148 case LUMINANCE_8: |
| 147 case RGB_565: | 149 case RGB_565: |
| 148 case ETC1: | |
| 149 case RED_8: | 150 case RED_8: |
| 150 return false; | 151 return false; |
| 151 } | 152 } |
| 152 NOTREACHED(); | 153 NOTREACHED(); |
| 153 return false; | 154 return false; |
| 154 } | 155 } |
| 155 | 156 |
| 156 // static | 157 // static |
| 157 void TileTaskWorkerPool::PlaybackToMemory(void* memory, | 158 void TileTaskWorkerPool::PlaybackToMemory(void* memory, |
| 158 ResourceFormat format, | 159 ResourceFormat format, |
| 159 const gfx::Size& size, | 160 const gfx::Size& size, |
| 160 size_t stride, | 161 size_t stride, |
| 161 const RasterSource* raster_source, | 162 const RasterSource* raster_source, |
| 162 const gfx::Rect& canvas_bitmap_rect, | 163 const gfx::Rect& canvas_bitmap_rect, |
| 163 const gfx::Rect& canvas_playback_rect, | 164 const gfx::Rect& canvas_playback_rect, |
| 164 float scale) { | 165 float scale) { |
| 165 DCHECK(IsSupportedPlaybackToMemoryFormat(format)) << format; | 166 DCHECK(IsSupportedPlaybackToMemoryFormat(format)) << format; |
| 166 | 167 |
| 167 // 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. |
| 168 SkImageInfo info = | 169 SkImageInfo info = |
| 169 SkImageInfo::MakeN32(size.width(), size.height(), kPremul_SkAlphaType); | 170 SkImageInfo::MakeN32(size.width(), size.height(), kPremul_SkAlphaType); |
| 170 SkColorType buffer_color_type = ResourceFormatToSkColorType(format); | 171 bool needs_copy = IsResourceFormatCompressed(format) || |
|
reveman
2015/07/21 04:26:33
nit: s/needs_copy/needs_conversion/
The only form
| |
| 171 bool needs_copy = buffer_color_type != info.colorType(); | 172 ResourceFormatToSkColorType(format) != info.colorType(); |
| 172 | 173 |
| 173 // Use unknown pixel geometry to disable LCD text. | 174 // Use unknown pixel geometry to disable LCD text. |
| 174 SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry); | 175 SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry); |
| 175 if (raster_source->CanUseLCDText()) { | 176 if (raster_source->CanUseLCDText()) { |
| 176 // 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. |
| 177 surface_props = SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); | 178 surface_props = SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); |
| 178 } | 179 } |
| 179 | 180 |
| 180 if (!stride) | 181 if (!stride) |
| 181 stride = info.minRowBytes(); | 182 stride = info.minRowBytes(); |
| 182 DCHECK_GT(stride, 0u); | 183 DCHECK_GT(stride, 0u); |
| 183 | 184 |
| 184 if (!needs_copy) { | 185 if (!needs_copy) { |
| 185 skia::RefPtr<SkSurface> surface = skia::AdoptRef( | 186 skia::RefPtr<SkSurface> surface = skia::AdoptRef( |
| 186 SkSurface::NewRasterDirect(info, memory, stride, &surface_props)); | 187 SkSurface::NewRasterDirect(info, memory, stride, &surface_props)); |
| 187 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(surface->getCanvas()); | 188 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(surface->getCanvas()); |
| 188 raster_source->PlaybackToCanvas(canvas.get(), canvas_bitmap_rect, | 189 raster_source->PlaybackToCanvas(canvas.get(), canvas_bitmap_rect, |
| 189 canvas_playback_rect, scale); | 190 canvas_playback_rect, scale); |
| 190 return; | 191 return; |
| 191 } | 192 } |
| 192 | 193 |
| 193 skia::RefPtr<SkSurface> surface = | 194 skia::RefPtr<SkSurface> surface = |
| 194 skia::AdoptRef(SkSurface::NewRaster(info, &surface_props)); | 195 skia::AdoptRef(SkSurface::NewRaster(info, &surface_props)); |
| 195 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(surface->getCanvas()); | 196 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(surface->getCanvas()); |
| 196 raster_source->PlaybackToCanvas(canvas.get(), canvas_bitmap_rect, | 197 raster_source->PlaybackToCanvas(canvas.get(), canvas_bitmap_rect, |
| 197 canvas_playback_rect, scale); | 198 canvas_playback_rect, scale); |
| 198 | 199 |
| 199 SkImageInfo dst_info = | 200 scoped_ptr<TextureCompressor> texture_compressor; |
| 200 SkImageInfo::Make(info.width(), info.height(), buffer_color_type, | 201 switch (format) { |
| 201 info.alphaType(), info.profileType()); | 202 case ETC1: |
| 202 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the | 203 texture_compressor = |
| 203 // bitmap data. There will be no need to call SkAlign4 once crbug.com/293728 | 204 TextureCompressor::Create(TextureCompressor::kFormatETC1); |
|
reveman
2015/07/21 04:26:33
hm, I think we should assume that creating a textu
| |
| 204 // is fixed. | 205 break; |
| 205 const size_t dst_row_bytes = SkAlign4(dst_info.minRowBytes()); | 206 default: |
|
reveman
2015/07/21 04:26:33
Please explicitly list all formats here and add a
| |
| 206 DCHECK_EQ(0u, dst_row_bytes % 4); | 207 SkImageInfo dst_info = SkImageInfo::Make( |
| 207 bool success = canvas->readPixels(dst_info, memory, dst_row_bytes, 0, 0); | 208 info.width(), info.height(), ResourceFormatToSkColorType(format), |
| 208 DCHECK_EQ(true, success); | 209 info.alphaType(), info.profileType()); |
| 210 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the | |
| 211 // bitmap data. There will be no need to call SkAlign4 once | |
| 212 // crbug.com/293728 is fixed. | |
| 213 const size_t dst_row_bytes = SkAlign4(dst_info.minRowBytes()); | |
| 214 DCHECK_EQ(0u, dst_row_bytes % 4); | |
| 215 bool success = canvas->readPixels(dst_info, memory, dst_row_bytes, 0, 0); | |
| 216 DCHECK_EQ(true, success); | |
| 217 return; | |
| 218 } | |
| 219 | |
| 220 texture_compressor->Compress( | |
| 221 reinterpret_cast<const uint8_t*>(surface->peekPixels(nullptr, nullptr)), | |
| 222 reinterpret_cast<uint8_t*>(memory), size.width(), size.height(), | |
| 223 TextureCompressor::kQualityHigh); | |
| 209 } | 224 } |
| 210 | 225 |
| 211 } // namespace cc | 226 } // namespace cc |
| OLD | NEW |