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/raster_buffer_provider.h" | 5 #include "cc/raster/raster_buffer_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "cc/base/scale_translate2d.h" |
10 #include "cc/playback/raster_source.h" | 11 #include "cc/playback/raster_source.h" |
11 #include "cc/raster/texture_compressor.h" | 12 #include "cc/raster/texture_compressor.h" |
12 #include "cc/resources/platform_color.h" | 13 #include "cc/resources/platform_color.h" |
13 #include "cc/resources/resource_format_utils.h" | 14 #include "cc/resources/resource_format_utils.h" |
14 #include "third_party/skia/include/core/SkCanvas.h" | 15 #include "third_party/skia/include/core/SkCanvas.h" |
15 #include "third_party/skia/include/core/SkSurface.h" | 16 #include "third_party/skia/include/core/SkSurface.h" |
16 | 17 |
17 namespace cc { | 18 namespace cc { |
18 | 19 |
19 RasterBufferProvider::RasterBufferProvider() {} | 20 RasterBufferProvider::RasterBufferProvider() {} |
(...skipping 24 matching lines...) Expand all Loading... |
44 | 45 |
45 // static | 46 // static |
46 void RasterBufferProvider::PlaybackToMemory( | 47 void RasterBufferProvider::PlaybackToMemory( |
47 void* memory, | 48 void* memory, |
48 ResourceFormat format, | 49 ResourceFormat format, |
49 const gfx::Size& size, | 50 const gfx::Size& size, |
50 size_t stride, | 51 size_t stride, |
51 const RasterSource* raster_source, | 52 const RasterSource* raster_source, |
52 const gfx::Rect& canvas_bitmap_rect, | 53 const gfx::Rect& canvas_bitmap_rect, |
53 const gfx::Rect& canvas_playback_rect, | 54 const gfx::Rect& canvas_playback_rect, |
54 const gfx::SizeF& scales, | 55 const ScaleTranslate2d& transform, |
55 sk_sp<SkColorSpace> dst_color_space, | 56 sk_sp<SkColorSpace> dst_color_space, |
56 const RasterSource::PlaybackSettings& playback_settings) { | 57 const RasterSource::PlaybackSettings& playback_settings) { |
57 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 58 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
58 "RasterBufferProvider::PlaybackToMemory"); | 59 "RasterBufferProvider::PlaybackToMemory"); |
59 | 60 |
60 DCHECK(IsSupportedPlaybackToMemoryFormat(format)) << format; | 61 DCHECK(IsSupportedPlaybackToMemoryFormat(format)) << format; |
61 | 62 |
62 // Uses kPremul_SkAlphaType since the result is not known to be opaque. | 63 // Uses kPremul_SkAlphaType since the result is not known to be opaque. |
63 SkImageInfo info = SkImageInfo::MakeN32(size.width(), size.height(), | 64 SkImageInfo info = SkImageInfo::MakeN32(size.width(), size.height(), |
64 kPremul_SkAlphaType, dst_color_space); | 65 kPremul_SkAlphaType, dst_color_space); |
65 | 66 |
66 // Use unknown pixel geometry to disable LCD text. | 67 // Use unknown pixel geometry to disable LCD text. |
67 SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry); | 68 SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry); |
68 if (raster_source->CanUseLCDText()) { | 69 if (raster_source->CanUseLCDText()) { |
69 // LegacyFontHost will get LCD text and skia figures out what type to use. | 70 // LegacyFontHost will get LCD text and skia figures out what type to use. |
70 surface_props = SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); | 71 surface_props = SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); |
71 } | 72 } |
72 | 73 |
73 if (!stride) | 74 if (!stride) |
74 stride = info.minRowBytes(); | 75 stride = info.minRowBytes(); |
75 DCHECK_GT(stride, 0u); | 76 DCHECK_GT(stride, 0u); |
76 | 77 |
77 switch (format) { | 78 switch (format) { |
78 case RGBA_8888: | 79 case RGBA_8888: |
79 case BGRA_8888: { | 80 case BGRA_8888: { |
80 sk_sp<SkSurface> surface = | 81 sk_sp<SkSurface> surface = |
81 SkSurface::MakeRasterDirect(info, memory, stride, &surface_props); | 82 SkSurface::MakeRasterDirect(info, memory, stride, &surface_props); |
82 raster_source->PlaybackToCanvas(surface->getCanvas(), canvas_bitmap_rect, | 83 raster_source->PlaybackToCanvas(surface->getCanvas(), canvas_bitmap_rect, |
83 canvas_playback_rect, scales, | 84 canvas_playback_rect, transform, |
84 playback_settings); | 85 playback_settings); |
85 return; | 86 return; |
86 } | 87 } |
87 case RGBA_4444: | 88 case RGBA_4444: |
88 case ETC1: { | 89 case ETC1: { |
89 sk_sp<SkSurface> surface = SkSurface::MakeRaster(info, &surface_props); | 90 sk_sp<SkSurface> surface = SkSurface::MakeRaster(info, &surface_props); |
90 // TODO(reveman): Improve partial raster support by reducing the size of | 91 // TODO(reveman): Improve partial raster support by reducing the size of |
91 // playback rect passed to PlaybackToCanvas. crbug.com/519070 | 92 // playback rect passed to PlaybackToCanvas. crbug.com/519070 |
92 raster_source->PlaybackToCanvas(surface->getCanvas(), canvas_bitmap_rect, | 93 raster_source->PlaybackToCanvas(surface->getCanvas(), canvas_bitmap_rect, |
93 canvas_bitmap_rect, scales, | 94 canvas_bitmap_rect, transform, |
94 playback_settings); | 95 playback_settings); |
95 | 96 |
96 if (format == ETC1) { | 97 if (format == ETC1) { |
97 TRACE_EVENT0("cc", | 98 TRACE_EVENT0("cc", |
98 "RasterBufferProvider::PlaybackToMemory::CompressETC1"); | 99 "RasterBufferProvider::PlaybackToMemory::CompressETC1"); |
99 DCHECK_EQ(size.width() % 4, 0); | 100 DCHECK_EQ(size.width() % 4, 0); |
100 DCHECK_EQ(size.height() % 4, 0); | 101 DCHECK_EQ(size.height() % 4, 0); |
101 std::unique_ptr<TextureCompressor> texture_compressor = | 102 std::unique_ptr<TextureCompressor> texture_compressor = |
102 TextureCompressor::Create(TextureCompressor::kFormatETC1); | 103 TextureCompressor::Create(TextureCompressor::kFormatETC1); |
103 SkPixmap pixmap; | 104 SkPixmap pixmap; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 case RGB_565: | 144 case RGB_565: |
144 case RED_8: | 145 case RED_8: |
145 case LUMINANCE_F16: | 146 case LUMINANCE_F16: |
146 return false; | 147 return false; |
147 } | 148 } |
148 NOTREACHED(); | 149 NOTREACHED(); |
149 return false; | 150 return false; |
150 } | 151 } |
151 | 152 |
152 } // namespace cc | 153 } // namespace cc |
OLD | NEW |