Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: cc/playback/raster_source.cc

Issue 2752523006: cc: Use SkCreateColorSpaceXformCanvas for color transforms (Closed)
Patch Set: Allow to link Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/playback/raster_source.h" 5 #include "cc/playback/raster_source.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/math_util.h" 10 #include "cc/base/math_util.h"
11 #include "cc/base/region.h" 11 #include "cc/base/region.h"
12 #include "cc/debug/debug_colors.h" 12 #include "cc/debug/debug_colors.h"
13 #include "cc/debug/traced_value.h" 13 #include "cc/debug/traced_value.h"
14 #include "cc/playback/display_item_list.h" 14 #include "cc/playback/display_item_list.h"
15 #include "cc/playback/image_hijack_canvas.h" 15 #include "cc/playback/image_hijack_canvas.h"
16 #include "cc/playback/skip_image_canvas.h" 16 #include "cc/playback/skip_image_canvas.h"
17 #include "skia/ext/analysis_canvas.h" 17 #include "skia/ext/analysis_canvas.h"
18 #include "third_party/skia/include/core/SkCanvas.h" 18 #include "third_party/skia/include/core/SkCanvas.h"
19 #include "third_party/skia/include/core/SkColorSpaceXformCanvas.h"
19 #include "third_party/skia/include/core/SkPictureRecorder.h" 20 #include "third_party/skia/include/core/SkPictureRecorder.h"
20 #include "ui/gfx/geometry/rect_conversions.h" 21 #include "ui/gfx/geometry/rect_conversions.h"
21 22
22 namespace cc { 23 namespace cc {
23 24
24 scoped_refptr<RasterSource> RasterSource::CreateFromRecordingSource( 25 scoped_refptr<RasterSource> RasterSource::CreateFromRecordingSource(
25 const RecordingSource* other, 26 const RecordingSource* other,
26 bool can_use_lcd_text) { 27 bool can_use_lcd_text) {
27 return make_scoped_refptr(new RasterSource(other, can_use_lcd_text)); 28 return make_scoped_refptr(new RasterSource(other, can_use_lcd_text));
28 } 29 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 raster_canvas->restore(); 81 raster_canvas->restore();
81 } 82 }
82 83
83 void RasterSource::PlaybackToCanvas(SkCanvas* raster_canvas, 84 void RasterSource::PlaybackToCanvas(SkCanvas* raster_canvas,
84 const PlaybackSettings& settings) const { 85 const PlaybackSettings& settings) const {
85 if (!settings.playback_to_shared_canvas) 86 if (!settings.playback_to_shared_canvas)
86 PrepareForPlaybackToCanvas(raster_canvas); 87 PrepareForPlaybackToCanvas(raster_canvas);
87 88
88 if (settings.skip_images) { 89 if (settings.skip_images) {
89 SkipImageCanvas canvas(raster_canvas); 90 SkipImageCanvas canvas(raster_canvas);
90 RasterCommon(&canvas, nullptr); 91 RasterCommon(&canvas, settings.target_color_space, nullptr);
91 } else if (settings.use_image_hijack_canvas) { 92 } else if (settings.use_image_hijack_canvas) {
92 const SkImageInfo& info = raster_canvas->imageInfo(); 93 const SkImageInfo& info = raster_canvas->imageInfo();
93 ImageHijackCanvas canvas(info.width(), info.height(), image_decode_cache_, 94 ImageHijackCanvas canvas(info.width(), info.height(), image_decode_cache_,
94 &settings.images_to_skip); 95 &settings.images_to_skip);
95 // Before adding the canvas, make sure that the ImageHijackCanvas is aware 96 // Before adding the canvas, make sure that the ImageHijackCanvas is aware
96 // of the current transform and clip, which may affect the clip bounds. 97 // of the current transform and clip, which may affect the clip bounds.
97 // Since we query the clip bounds of the current canvas to get the list of 98 // Since we query the clip bounds of the current canvas to get the list of
98 // draw commands to process, this is important to produce correct content. 99 // draw commands to process, this is important to produce correct content.
99 canvas.clipRect( 100 canvas.clipRect(
100 SkRect::MakeFromIRect(raster_canvas->getDeviceClipBounds())); 101 SkRect::MakeFromIRect(raster_canvas->getDeviceClipBounds()));
101 canvas.setMatrix(raster_canvas->getTotalMatrix()); 102 canvas.setMatrix(raster_canvas->getTotalMatrix());
102 canvas.addCanvas(raster_canvas); 103 canvas.addCanvas(raster_canvas);
103 104
104 RasterCommon(&canvas, nullptr); 105 RasterCommon(&canvas, settings.target_color_space, nullptr);
105 } else { 106 } else {
106 RasterCommon(raster_canvas, nullptr); 107 RasterCommon(raster_canvas, settings.target_color_space, nullptr);
107 } 108 }
108 } 109 }
109 110
110 namespace { 111 namespace {
111 112
112 bool CanvasIsUnclipped(const SkCanvas* canvas) { 113 bool CanvasIsUnclipped(const SkCanvas* canvas) {
113 if (!canvas->isClipRect()) 114 if (!canvas->isClipRect())
114 return false; 115 return false;
115 116
116 SkIRect bounds; 117 SkIRect bounds;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 canvas->save(); 190 canvas->save();
190 // Use clipRegion to bypass CTM because the rects are device rects. 191 // Use clipRegion to bypass CTM because the rects are device rects.
191 SkRegion interest_region; 192 SkRegion interest_region;
192 interest_region.setRect(interest_rect); 193 interest_region.setRect(interest_rect);
193 interest_region.op(opaque_rect, SkRegion::kDifference_Op); 194 interest_region.op(opaque_rect, SkRegion::kDifference_Op);
194 canvas->clipRegion(interest_region); 195 canvas->clipRegion(interest_region);
195 canvas->clear(background_color_); 196 canvas->clear(background_color_);
196 canvas->restore(); 197 canvas->restore();
197 } 198 }
198 199
199 void RasterSource::RasterCommon(SkCanvas* canvas, 200 void RasterSource::RasterCommon(SkCanvas* input_canvas,
201 const gfx::ColorSpace& target_color_space,
200 SkPicture::AbortCallback* callback) const { 202 SkPicture::AbortCallback* callback) const {
203 SkCanvas* raster_canvas = input_canvas;
204 // TODO(ccameron): This cannot link until SkCreateColorSpaceXformCanvas is
205 // marked as SK_API.
206 // std::unique_ptr<SkCanvas> color_transform_canvas;
207 // if (target_color_space.IsValid()) {
208 // color_transform_canvas = SkCreateColorSpaceXformCanvas(
209 // input_canvas, target_color_space.ToSkColorSpace());
210 // raster_canvas = color_transform_canvas.get();
211 // }
201 DCHECK(display_list_.get()); 212 DCHECK(display_list_.get());
202 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_); 213 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_);
203 for (int i = 0; i < repeat_count; ++i) 214 for (int i = 0; i < repeat_count; ++i)
204 display_list_->Raster(canvas, callback); 215 display_list_->Raster(raster_canvas, callback);
205 } 216 }
206 217
207 sk_sp<SkPicture> RasterSource::GetFlattenedPicture() { 218 sk_sp<SkPicture> RasterSource::GetFlattenedPicture() {
208 TRACE_EVENT0("cc", "RasterSource::GetFlattenedPicture"); 219 TRACE_EVENT0("cc", "RasterSource::GetFlattenedPicture");
209 220
210 SkPictureRecorder recorder; 221 SkPictureRecorder recorder;
211 SkCanvas* canvas = recorder.beginRecording(size_.width(), size_.height()); 222 SkCanvas* canvas = recorder.beginRecording(size_.width(), size_.height());
212 if (!size_.IsEmpty()) { 223 if (!size_.IsEmpty()) {
213 PrepareForPlaybackToCanvas(canvas); 224 PrepareForPlaybackToCanvas(canvas);
214 RasterCommon(canvas, nullptr); 225 // No target color space should be set for generating an SkPicture.
226 RasterCommon(canvas, gfx::ColorSpace(), nullptr);
215 } 227 }
216 228
217 return recorder.finishRecordingAsPicture(); 229 return recorder.finishRecordingAsPicture();
218 } 230 }
219 231
220 size_t RasterSource::GetMemoryUsage() const { 232 size_t RasterSource::GetMemoryUsage() const {
221 if (!display_list_) 233 if (!display_list_)
222 return 0; 234 return 0;
223 return display_list_->ApproximateMemoryUsage() + 235 return display_list_->ApproximateMemoryUsage() +
224 painter_reported_memory_usage_; 236 painter_reported_memory_usage_;
225 } 237 }
226 238
227 bool RasterSource::PerformSolidColorAnalysis(const gfx::Rect& content_rect, 239 bool RasterSource::PerformSolidColorAnalysis(const gfx::Rect& content_rect,
228 float contents_scale, 240 float contents_scale,
229 SkColor* color) const { 241 SkColor* color) const {
230 TRACE_EVENT0("cc", "RasterSource::PerformSolidColorAnalysis"); 242 TRACE_EVENT0("cc", "RasterSource::PerformSolidColorAnalysis");
231 243
232 gfx::Rect layer_rect = 244 gfx::Rect layer_rect =
233 gfx::ScaleToEnclosingRect(content_rect, 1.f / contents_scale); 245 gfx::ScaleToEnclosingRect(content_rect, 1.f / contents_scale);
234 246
235 layer_rect.Intersect(gfx::Rect(size_)); 247 layer_rect.Intersect(gfx::Rect(size_));
236 skia::AnalysisCanvas canvas(layer_rect.width(), layer_rect.height()); 248 skia::AnalysisCanvas canvas(layer_rect.width(), layer_rect.height());
237 canvas.translate(-layer_rect.x(), -layer_rect.y()); 249 canvas.translate(-layer_rect.x(), -layer_rect.y());
238 RasterCommon(&canvas, &canvas); 250 // No target color space should be set for solid color analysis (the
251 // resulting solid color will be known to be sRGB).
252 RasterCommon(&canvas, gfx::ColorSpace(), &canvas);
239 return canvas.GetColorIfSolid(color); 253 return canvas.GetColorIfSolid(color);
240 } 254 }
241 255
242 void RasterSource::GetDiscardableImagesInRect( 256 void RasterSource::GetDiscardableImagesInRect(
243 const gfx::Rect& layer_rect, 257 const gfx::Rect& layer_rect,
244 float contents_scale, 258 float contents_scale,
245 std::vector<DrawImage>* images) const { 259 std::vector<DrawImage>* images) const {
246 DCHECK_EQ(0u, images->size()); 260 DCHECK_EQ(0u, images->size());
247 display_list_->GetDiscardableImagesInRect(layer_rect, contents_scale, images); 261 display_list_->GetDiscardableImagesInRect(layer_rect, contents_scale, images);
248 } 262 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 use_image_hijack_canvas(true) {} 321 use_image_hijack_canvas(true) {}
308 322
309 RasterSource::PlaybackSettings::PlaybackSettings(const PlaybackSettings&) = 323 RasterSource::PlaybackSettings::PlaybackSettings(const PlaybackSettings&) =
310 default; 324 default;
311 325
312 RasterSource::PlaybackSettings::PlaybackSettings(PlaybackSettings&&) = default; 326 RasterSource::PlaybackSettings::PlaybackSettings(PlaybackSettings&&) = default;
313 327
314 RasterSource::PlaybackSettings::~PlaybackSettings() = default; 328 RasterSource::PlaybackSettings::~PlaybackSettings() = default;
315 329
316 } // namespace cc 330 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698